// detect le type de navigateur
var ttNS4 = (document.layers) ? 1 : 0;           // the old Netscape 4
var ttIE4 = (document.all) ? 1 : 0;              // browser wich uses document.all
var ttDOM = (document.getElementById) ? 1 : 0;   // DOM-compatible browsers
if (ttDOM) { // if DOM-compatible, set the others to false
  ttNS4 = 0;
	ttIE4 = 0;
}

// FAVORIS



function favoris() {
if ( navigator.appName != 'Microsoft Internet Explorer' )
{ window.sidebar.addPanel("Cmaboul","http://www.cmaboul.com/",""); }
else { window.external.AddFavorite("http://www.cmaboul.com/","Cmaboul"); } }

// QUANTITES

function plusmoins(id, val) {
	quantite = document.form[id].value;
	quantite = parseInt(quantite) + parseInt(val);
	if (quantite < 1) { quantite = 1; }
	if (quantite > 99) { quantite = 99; }
	document.form[id].value = quantite;
}

// COULEURS PCMEZ

function display_color(id,val) {
	IMG = document.getElementById(id);
	IMG.src = val;
}

function setPreview(val){
  IMG = document.getElementById('preview');
  IMG.src = val;
}

// ESCAMOTAGES

function hide() {
	for (var i = 1; i<=10; i++) {
			if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
		}
 	document.getElementById('caddie').style.display='none';
}

addToStart(hide);
function cache(id) {
	document.getElementById(id).style.display='none';
}

function caddie(id) {
	var d = document.getElementById(id);
	if (d.style.display=='none') {
		d.style.display='block';
	}
	else {
		d.style.display='none';
	}
}


function montre(id) {
	var d = document.getElementById(id);
	if (d.style.display=='none') {
		
		for (var i = 1; i<=10; i++) {
			if ((document.getElementById('smenu'+i)) && ('smenu'+i != id)) {
				document.getElementById('smenu'+i).style.display='none';
			}
		}
		d.style.display='block';
	}
	else {
		d.style.display='none';
	}
}

// POP UPS REELLES

var newWin = null;
function closeWin(){
	if (newWin != null){
		if(!newWin.closed)
		newWin.close();
	}
}

function popUp(strURL,strType,strHeight,strWidth) {
	closeWin();
	var strOptions="";
	if (strType=="console") strOptions="resizable,scrollbars,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	newWin = window.open(strURL, 'newWin', strOptions);
	newWin.focus();
}

// POP UPS CSS

function unpopall()
{
    var myAs = document.getElementsByTagName('a');
    for (var a = 0; a < myAs.length; ++a) {
 // Si le lien a une classe de type pop
        if (myAs[a].className == 'pop') {
 // on extrait l'id de la popup à partir du href
            var pop = document.getElementById(myAs[a].href.substring(myAs[a].href.lastIndexOf('#') + 1));
 // si la popup existe on l'affiche (display block)
            if (pop) {       
                pop.style.display = 'none';
            }
        }
    }
}

function unselect()
{
   var mySs = document.getElementsByTagName('select');
   for (var a = 0; a < mySs.length; ++a) {
      mySs[a].style.display = 'none';
   }
}

function reselect()
{
   var mySs = document.getElementsByTagName('select');
   for (var a = 0; a < mySs.length; ++a) {
      mySs[a].style.display = 'block';
   }
}

function pop()
{    var myAs = document.getElementsByTagName('a');
// Check if browser does support dynamic content and dhtml
		

    for (var a = 0; a < myAs.length; ++a) {
 // Si le lien a une classe de type pop
        if (myAs[a].className == 'pop') {
 // on extrait l'id de la popup à partir du href
            var pop = document.getElementById(myAs[a].href.substring(myAs[a].href.lastIndexOf('#') + 1));
 // si la popup existe on l'affiche (display block)
            if (pop) {       
                pop.style.display = 'none';
					 /*var windowHeight = getWindowHeight();*/
					 
                myAs[a].onclick = function() {
                    thisPopup = document.getElementById(this.href.substring(this.href.lastIndexOf('#') + 1));
                    unpopall();
                    unselect();
						  elemHeight = thisPopup.offsetHeight ;
						 /* thisPopup.style.top = (((window.innerHeight)/2) - (elemHeight/2)) + 'px';*/
						 
						 
						 movePopup(thisPopup, 0, document.documentElement.scrollTop - 150);
						  
                    thisPopup.style.display = (thisPopup.style.display == 'none') ? 'block' : 'none';
                    return false;
                };
  // on efface la popup en cliquant sur le bouton ou la fenêtre
                pop.onclick = function()
                {
                    this.style.display = 'none';
                    reselect();
                };
            }
        }
    }
}

addToStart(pop);


function movePopup(popup, posX, posY) {
    if (ttDOM || ttIE4) {
        popup.style.left	=	posX + "px";
        popup.style.top  =	posY + "px";
    } else if (ttNS4) {
        popup.left = posX;
        popup.top  = posY;
    }
}
/*function getWindowHeight() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
		}*/

/*function setFooter() {
  if (document.getElementById) {
     var windowHeight = getWindowHeight();
     if (windowHeight > 0) {
         var footerElement = document.getElementById('haut');
         if (windowHeight - 25 >= 0) {
          if ((document.all) && (navigator.appVersion.indexOf("Mac",0)<0)) {
                footerElement.style.position = 'absolute';
                footerElement.style.top = (document.body.scrollTop + windowHeight - 25) + 'px';
                }
          else {
                footerElement.style.position = 'fixed';
                footerElement.style.top = (windowHeight - 25) + 'px';
                }
         }
         else {
            footerElement.style.position = 'static';
         }
     }
  }
}*/

/*function setElement() {
	var windowHeight = getWindowHeight();
	var elems = document.getElementsByTagName("div");
	for ( var i = 0; ( elem = elems[i] ); i++ ) {
		if (elem.className == 'popphoto') {
			elemHeight = document.body.clientHeight;
			elem.top = windowHeight/2 - elemHeight/2;
		}
	}
}*/

/*addToStart(setElement);*/

/*window.onresize = function() {
        setElement();
}
window.onscroll = function() {
        setElement();
}*/

//Merci a Alsacreations et Ibilab pour ces scripts
