// JavaScript Document
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;
}



//******************************************************************
// DEBUT gestion du formulaire qui emule les sessions
//******************************************************************
function PassVar(val)
	{
	var obj = document.forms.varses
	obj.action=val
	obj.submit()
	}


function supprimeChamp(obj,val)
{
	for (i=0;i<obj.length ;i++ )
	{
		 var pos = obj[i]
		// alert(pos.name)
		
		 if (pos.name==val)
		 {
			 //alert("on supprime "&pos.name)
			 obj.removeChild(obj[i]);
		 }
	}

}


function addChamForm(val)
	{
	
	//WriteVarTab=array("transParam","transPanier","transAdresse","transProcess","etape1","etape2","transIdUsr","coord")
	var obj = document.forms[val]
	var obj2 =document.forms.varses
	
	
	
	
	
	var input = document.createElement("input");
  	input.type = 'hidden';
 	input.name = 'transParam';
	input.value = obj2.transParam.value
	supprimeChamp(obj,input.name)
	obj.appendChild(input);
	
	var input = document.createElement("input");
  	input.type = 'hidden';
 	input.name = 'transPanier';
	input.value = obj2.transPanier.value
	supprimeChamp(obj,input.name)
	obj.appendChild(input);
	
	var input = document.createElement("input");
  	input.type = 'hidden';
 	input.name = 'transAdresse';
	input.value = obj2.transAdresse.value
	supprimeChamp(obj,input.name)
	obj.appendChild(input);
	
	var input = document.createElement("input");
  	input.type = 'hidden';
 	input.name = 'transProcess';
	input.value = obj2.transProcess.value
	supprimeChamp(obj,input.name)
	obj.appendChild(input);
	
	var input = document.createElement("input");
  	input.type = 'hidden';
 	input.name = 'etape1';
	input.value = obj2.etape1.value
	supprimeChamp(obj,input.name)
	obj.appendChild(input);
	
	var input = document.createElement("input");
  	input.type = 'hidden';
 	input.name = 'etape2';
	input.value = obj2.etape2.value
	supprimeChamp(obj,input.name)
	obj.appendChild(input);
	
	var input = document.createElement("input");
  	input.type = 'hidden';
 	input.name = 'transIdUsr';
	input.value = obj2.transIdUsr.value
	supprimeChamp(obj,input.name)
	obj.appendChild(input);
	
	var input = document.createElement("input");
  	input.type = 'hidden';
 	input.name = 'coord';
	input.value = obj2.coord.value
	supprimeChamp(obj,input.name)
	obj.appendChild(input);
	
	var input = document.createElement("input");
  	input.type = 'hidden';
 	input.name = 'proj';
	input.value = obj2.proj.value
	supprimeChamp(obj,input.name)
	obj.appendChild(input);
	
	var input = document.createElement("input");
  	input.type = 'hidden';
 	input.name = 'codix';
	input.value = obj2.codix.value
	supprimeChamp(obj,input.name)
	obj.appendChild(input);

	}
	
function setProcess(val)
	{
	var obj2 =document.forms.varses
	obj2.transProcess.value = val
	}

function PutInSession(champ,val)
	{
	
	var obj2 =document.forms.varses
	obj2[champ].value = val
	}













//******************************************************************
// FIN gestion du formulaire qui emule les sessions
//******************************************************************




//var xhr = null; 
/*
function getXhr()
{
    if(window.XMLHttpRequest)
	 	{
	 
		return(new XMLHttpRequest())
		}
	else if(window.ActiveXObject)
	  { 
	  try{
			
		 return(new ActiveXObject("Msxml2.XMLHTTP"))
		 } 
		 catch (e) 
		 {
		
		return(ActiveXObject("Microsoft.XMLHTTP"));
		 }
	  }
	else 
	  {
	  alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	  xhr = false; 
	  } 
}
*/

/*
//version initiale

function ShowPage(obj,data)
{

var loadname=MM_findObj("loader"+obj.name.substr(5))

//getXhr();
var xhr = getXhr();
//alert(xhr)
xhr.onreadystatechange = function()
    {
     if(xhr.readyState == 4 && xhr.status == 200)
     {
     //alert(arrondir(xhr.responseText)+" €")
	 obj.prix.value = arrondir(xhr.responseText)+" €";
	 obj.prix.style.display="inline"
	 loadname.style.display="none"
	 //document.getElementById('page').innerHTML=xhr.responseText;
     }
    }
xhr.open("POST","Scripts/CalculProd.asp",true);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1");
//document.location.href = "Scripts/CalculProd.asp?"+data
//alert(data)
xhr.send(data);

obj.prix.style.display="none"
loadname.style.display="inline"

}
*/

/*
function ShowPage(obj,data)
{
//
var loadname=MM_findObj("loader"+obj.name.substr(5))

//getXhr();
var xhr = getXhr();
//alert(xhr)
xhr.onreadystatechange = function()
    {
     if(xhr.readyState == 4 && xhr.status == 200)
     {
     //alert(arrondir(xhr.responseText)+" €")
	 obj.prix.value = arrondir(xhr.responseText)+" €";
	 obj.prix.style.display="inline"
	 loadname.style.display="none"
	 //document.getElementById('page').innerHTML=xhr.responseText;
     }
    }
xhr.open("POST","Scripts/CalculProd.asp",true);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1");
//document.location.href = "Scripts/CalculProd.asp?"+data
//alert(data)
xhr.send(data);

obj.prix.style.display="none"
loadname.style.display="inline"

}
*/




function interAjax(a)
	{
	
	var obj = MM_findObj(a);
	
	var tt=""	
	var cal = 0
	if(obj)
	{
	   
	   var champs = obj.getElementsByTagName("select" );
	   for(var i=0, n=champs.length; i<n; i++) {
		tt=tt+"&"+(champs[i].getAttribute("name")+"="+champs[i].value);
	   	//cal = cal + parseFloat(champs[i].getAttribute("value"))
	   }
	   var champs = obj.getElementsByTagName("input");
	   for(var i=0, n=champs.length; i<n; i++)
	   {
		if(champs[i].getAttribute("type") == "hidden")
			{
			tt=tt+"&"+(champs[i].getAttribute("name")+"="+champs[i].value);
			//tt=tt+"&"+(champs[i].getAttribute("name")+"="+champs[i].value);
			}
		
	   }
	   
	}
	//obj.prix.value = cal
	tt="Prod="+a+tt+"&sortie=1"
	//alert(tt)
	
	
	if(a == "Fprod1")
		{
		//alert('toto')
		tt=tt+"&Qte="+obj.Qte.value
		getPrice1(obj,tt)	
		}
	if(a == "Fprod2")
		{
		getPrice2(obj,tt)	
		//getPrice1(obj,tt)	
		}
	
	
	
	//ShowPage(obj,tt)
	
	}

/*
function GetArticles(a)
	{
	var obj = MM_findObj(a);
	var email = document.forms[a].email.value
	var nom = document.forms[a].nom.value
	var num = document.forms[a].num.value
	
	
	alert(email+)
	
	
	
	
}
*/

/*
function UpdatePanier(data)
	{
	
	//getXhr();
	//alert(data)
	
	var xhr = getXhr();
	xhr.onreadystatechange = function()
		{
		 if(xhr.readyState == 4 && xhr.status == 200)
		 {
			//alert(ds1.getXPath())
		 	ds1.loadData()
		 	ds3.loadData()
		 //AffichePanier(xhr.responseText)
		
		//alert(xhr.responseText)
		
		 }
		}
	
	xhr.open("POST","Scripts/Panier.asp",true);
	xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1");
	//alert(data)
	xhr.send(data);
	//window.open("Scripts/Panier.asp?"+data)
	//document.location.href = "Scripts/Panier.asp?"+data
		
	}
*/



function DelInBasket(val)
	{
	//hidehall()
	var tt=""		
	tt=tt+"Func=DelProduct&Ref="+val	
	UpdatePanier(tt)	
	}

function UpdateQte(val)
	{
		//alert(val)
		hidehall()
		var temp = "qte"+val
		//alert(document.getElementById(temp).value)
		
		var tt=""
		tt=tt+"Func=UpdateQte&Id="+val+"&qte="+document.getElementById(temp).value
		//alert(tt)
		UpdatePanier(tt)
	}

function Updatelicence(ref,obj)
	{
	hidehall()
	var tt=""
	tt=tt+"Func=Updatelicence&Ref="+ref+"&Lic="+obj.value
	//alert(tt)
	UpdatePanier(tt)
	//alert(ref+" - "+obj.value)
	
	}

function PutInBasket(a)
	{
	var obj = MM_findObj(a);
	var tt=""	
	var cal = 0
	if(obj) {
	   var champs = obj.getElementsByTagName("select" );
	   for(var i=0, n=champs.length; i<n; i++) {
		tt=tt+"&"+(champs[i].getAttribute("name")+"="+escape(champs[i].value));
	   	
		//escape(champs[i].value));
		//cal = cal + parseFloat(champs[i].getAttribute("value"))
	   }
	   
	   var champs = obj.getElementsByTagName("input");
	   for(var i=0, n=champs.length; i<n; i++) {
		
		if(champs[i].getAttribute("type") == "hidden")
			{
			tt=tt+"&"+(champs[i].getAttribute("name")+"="+escape(champs[i].value));
			//escape(champs[i].value));
			}
	   }
	   
	}
	//alert(escape(obj.libelle.value))
	
	if(a=="Fprod2")
		{
		//VerifProd2(val)
		//alert(document.Fprod2.param.value)
		VerifProd2(document.Fprod2.param.value)
		tt=tt+"&Qte=1&Func=AddProduct"	
		
		}
	else
		{
		tt=tt+"&Qte="+escape(obj.Qte.value)+"&Func=AddProduct"	
		}
	
	tt="Prod="+a+tt
	
	//alert(tt)
	UpdatePanier(tt)
	
	}



function arrondir(resultat) {
     // resultat = Math.round(resultat*100)/100;
     resultat = resultat.replace(",",".")
	// alert(resultat)
	 return Doformat(resultat,2," ")
}



function Doformat(valeur,decimal,separateur) {
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}

function Redirect(val)
	{
	//document.location.href=val
	PassVar(val)
	}

function TestLoggin()
	{
	
	
	var obj = MM_findObj("TopLogin");
	document.formLog.login.value = obj.value
	var obj = MM_findObj("TopPassword");
	document.formLog.password.value = obj.value
	document.formLog.TestLog.value = "ok"
	addChamForm('formLog')	
	//alert(document.formLog.transParam.value)
	document.formLog.submit()
	
	//alert(obj.value)
	}

function Deconnect()
	{
	
	
	PutInSession("transPanier","")
	PutInSession("transAdresse","")
	PutInSession("transProcess","")
	PutInSession("etape1","")
	PutInSession("etape2","")
	PutInSession("transIdUsr","")
	PutInSession("transParam","")
	document.formLog.TestLog.value = "deconnect"
	addChamForm('formLog')	
	document.formLog.submit()
	}


function echo(val)
{
document.write(val+"<br>");
}

function test()
{
alert('toto')	
}

onscroll = function()
	{
	if(document.getElementById('Walert1') && document.getElementById('Walert2'))
		{
		document.getElementById('Walert1').style.top = document.documentElement.scrollTop+"px"
		document.getElementById('Walert2').style.top = (Math.round(document.documentElement.clientHeight*40/100))+"px"
		}
	}

function getTotalHeight() {

  // firefox is ok
  var height = document.documentElement.scrollHeight;

  // now IE 7 + Opera with "min window"
  if(document.documentElement.clientHeight > height ) {
    height  = document.documentElement.clientHeight;
  }
  // last for safari
  if(document.body.scrollHeight > height) {
    height = document.body.scrollHeight;
  }
  return height;
}

function openAlert(contenu,titre,L,H)
	{
	var L=(L==null)?260:L
	var H=(H==null)?86:H
	var titre=(titre==null)?"Attention":titre
	var contenu=(contenu==null)?"":contenu
	
	var Ltitre = L-70;
	var Hcentre = H-18;
	
	var tt=""
	
	
	tt+="<div style=\"float:left; position:relative; left:50%; margin-left:-"+(Math.round((L+16)/2))+"px\";width:"+(L+16)+"px\">"
		tt+="<!--[if lte IE 6.5]><iframe class=\"Ifrm\"></iframe><![endif]-->"
		tt+="<div style=\"float:left; width:"+(L+16)+"px\">"
			tt+="<div class=\"Whg\"></div>"
			tt+="<div class=\"Wh\" style=\"width:"+L+"px\">"
				tt+="<div class=\"Wclose\" onclick=\"closeAlert()\">"
					tt+="Fermer X"
				tt+="</div>"
				tt+="<div  class=\"Wtitre\" style=\"width:"+Ltitre+"px\">"
					tt+=titre
				tt+="</div>"
			tt+="</div>"
			tt+="<div class=\"Whd\"></div>"
		tt+="</div>"
		
		tt+="<div style=\"float:left; clear:both\"; width:"+(L+16)+"px\">"
			tt+="<div class=\"Wmg\" style=\"height:"+H+"px\"></div>"
			tt+="<div class=\"Wm\" style=\"width:"+L+"px; height:"+Hcentre+"px\">"
				tt+=contenu
			tt+="</div>"
			tt+="<div class=\"Wmd\" style=\"height:"+H+"px\"></div>"
		tt+="</div>"
		
		tt+="<div style=\"float:left;clear:both\"; width:"+(L+16)+"px\">"
			tt+="<div class=\"Wbg\"></div>"
			tt+="<div class=\"Wb\" style=\"width:"+L+"px\"></div>"
			tt+="<div class=\"Wbd\"></div>"
		tt+="</div>"
	tt+="</div>"
	
	//alert(tt)
	document.getElementById("Walert1").innerHTML = "<div><!--[if lte IE 6.5]><iframe class=\"Ifrm\"></iframe><![endif]--></div>"
	document.getElementById("Walert2").innerHTML = tt
	document.getElementById('Walert2').style.visibility='visible'
	document.getElementById('Walert1').style.visibility='visible'
	document.getElementById('Walert2').style.display='inline'
	document.getElementById('Walert1').style.display='inline'
	document.getElementById('Walert1').style.height=getTotalHeight()
	}

function closeAlert()
	{
	document.getElementById('Walert2').style.visibility='hidden'
	document.getElementById('Walert1').style.visibility='hidden'
	document.getElementById('Walert2').style.display='none'
	document.getElementById('Walert1').style.display='none'
	
	}



