/* 
| -= Path =- ~/js/General.js
| -= Date =- 23/08/2008
| -= Mod. =-
| -= Dev. =- Alexandre JOLY <alexandre.joly@bsmt.fr>
| -= Copy =- Copyright 2008 Bishamonten Technologies
| -= Lic. =- GPL V 3.0 (cf ~/licence.txt)
*/

var Mouse_X; // Variable globale Position X de la Mouse
var Mouse_Y; // Variable globale Position Y de la Mouse

document.onmousemove = WhereMouse;

function ShowInfoBulles(Id){

	document.getElementById(Id).style.visibility = 'visible';
	document.getElementById(Id).style.display    = 'block';
	
	document.getElementById("Coin"+Id).style.visibility = 'visible';
	document.getElementById("Coin"+Id).style.display    = 'block';
}

function HideInfoBulles(Id){

	document.getElementById(Id).style.visibility = 'hidden';
	document.getElementById(Id).style.display    = 'none';
	
	document.getElementById("Coin"+Id).style.visibility = 'hidden';
	document.getElementById("Coin"+Id).style.display    = 'none';
}

function ShowBulles( DivToShow ){

	document.getElementById(DivToShow).style.visibility = 'visible';
	document.getElementById(DivToShow).style.display    = 'block';
	document.getElementById(DivToShow).style.visibility = 'visible';
	document.getElementById(DivToShow).style.display    = 'block';
	document.getElementById(DivToShow).style.position   = 'absolute';
	document.getElementById(DivToShow).style.zIndex     = '525';
	document.getElementById(DivToShow).style.left       = Mouse_X-127+'px';
	document.getElementById(DivToShow).style.top        = Mouse_Y+15+'px';

}

function HideBulles( DivToShow ){
	
	document.getElementById(DivToShow).style.visibility = 'hidden';
	document.getElementById(DivToShow).style.display    = 'none';
}

function WhereMouse( e ){
  var DocRef;    // Variable pour IE uniquement

  // L'Ã©vÃ©nement est passÃ©e Ã  la fonction
  // donc tous sauf IEâ€¦
  if( e){                     // Dans ce cas on obtient directement la position dans la page
    Mouse_X = e.pageX;
    Mouse_Y = e.pageY;
  }
  else{                      // Dans ce cas on obtient la position relative Ã  la fenÃªtre d'affichage
    Mouse_X = event.clientX;
    Mouse_Y = event.clientY;

    //-- Il faut traiter le CAS des DOCTYPE sous IE
    if( document.documentElement && document.documentElement.clientWidth) // Donc DOCTYPE
      DocRef = document.documentElement;   // Dans ce cas c'est documentElement qui est rÃ©fÃ¨rence
    else
      DocRef = document.body;                    // Dans ce cas c'est body qui est rÃ©fÃ¨rence

    //-- On rajoute la position liÃ©e aux ScrollBars
    Mouse_X += DocRef.scrollLeft;
    Mouse_Y += DocRef.scrollTop;
  }
}

function ListeDepartement(IsSelect){

	// La ou sera affiche la liste de produit
	var ShowIn = 'ListeDepartement';

	var CateSelect = document.getElementById("Pays").value;

	var xhr; 
	try {
		xhr = new XMLHttpRequest();
	}
	catch(e){
		xhr = new ActiveXObject('Microsoft.XMLHTTP');
	}

	xhr.onreadystatechange  = function(){
	
		if(xhr.readyState  == 4)
		{
			if(xhr.status  == 200) 
				document.getElementById(ShowIn).innerHTML = xhr.responseText; 
			else 
				document.getElementById(ShowIn).innerHTML ="Error code " + xhr.status;
		}
	};
	
	document.getElementById(ShowIn).innerHTML = "<p style=\"margin: 10px 0 0 0; text-align: left; font-weight: bold;\"><img src=\"images/loading.gif\" /><br />Loading...</p>";
	
	var data = "CodePays="+CateSelect+"&IsSelect="+IsSelect;
	var LD_URL = "index.php?p=4&"+data;
	xhr.open("GET", LD_URL,  true);
	xhr.setRequestHeader("Content-Type", "text/html; charset=UTF-8");
	xhr.send(null);
}

function MasquerAfficher(Id){

	if( document.getElementById(Id).style.visibility == 'visible' ){
	
	document.getElementById(Id).style.visibility = 'hidden';
		document.getElementById(Id).style.display    = 'none';
	}
	else{
	

		document.getElementById(Id).style.visibility = 'visible';
		document.getElementById(Id).style.display    = 'block';
	}
}

//-- Fonction pour faire un affichage en direct du prix du produit en fonction de l'options choisie
function CalculerPrix(IdProduit){
	
	//-- On récupe le prix d'origine
	var ListeDesOptions = document.getElementById("ListeOptionsAfficher"+IdProduit).value;

	var LesOptions = ListeDesOptions.split('-');
	
	var PrixAvecOptions = parseFloat(document.getElementById("PrixDepart"+IdProduit).value);
	var MontantOption = '';
	
	for( i=0;i< (LesOptions.length -1) ;i++ ){
		
		//-- On récupère l'id de l'option sélectionné	
		
		var liste =  document.getElementById("opt-"+IdProduit+""+LesOptions[i]);
		var selectedValue = liste.options[liste.selectedIndex].value;

		MontantOption += "-"+document.getElementById("opt-"+IdProduit+""+LesOptions[i]+"-"+selectedValue).value;
	}
	
	// La ou sera affiche la liste de produit
	var ShowIn = 'PrixProduit'+IdProduit;

	var xhr; 
	try {
		xhr = new XMLHttpRequest();
	}
	catch(e){
		xhr = new ActiveXObject('Microsoft.XMLHTTP');
	}

	xhr.onreadystatechange  = function(){
	
		if(xhr.readyState  == 4)
		{
			if(xhr.status  == 200) 
				document.getElementById(ShowIn).innerHTML = xhr.responseText; 
			else 
				document.getElementById(ShowIn).innerHTML ="Error code " + xhr.status;
		}
	};
	
	document.getElementById(ShowIn).innerHTML = "<p style=\"margin: 10px 0 0 0; text-align: left; font-weight: bold;\">Loading...</p>";
	
	var data = "ListeMontantOptions="+MontantOption+"&PrixDefaut="+PrixAvecOptions+"&OpeReduc="+document.getElementById("opereduc"+IdProduit).value+"&ValeurReduc="+document.getElementById("valeurreduc"+IdProduit).value;
	var LD_URL = "index.php?p=4&"+data;
	xhr.open("GET", LD_URL,  true);
	xhr.setRequestHeader("Content-Type", "text/html; charset=UTF-8");
	xhr.send(null);
	
	
	
	document.getElementById(ShowIn).innerHTML = PrixAvecOptions;
}

<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->


function IsOnLoadBody(){


}

function ShowElement(IdToShow){
	
	if( $("#"+IdToShow).css('display') != "block" )
		$("#"+IdToShow).show('normal');
	
	else
		$("#"+IdToShow).hide('fast');
}








