function swapImg(){
   Arr_Arg=swapImg.arguments;
   Arr_Arg[0].src=Arr_Arg[1];
}

/****   PRELOAD IMAGES  ****/

var image= new Array();

function preLoad(){	
  	var Hd=document; 
  	if(Hd.images){ 
  		if(!Hd.Hp){ 
			Hd.Hp=new Array();
		}
   		var Hi;
		var Hj=Hd.Hp.length;
		var Ha=preLoad.arguments; 
		for(Hi=0; Hi<Ha.length; Hi++){
   			 if (Ha[Hi].indexOf("#")!=0){ 
			 	Hd.Hp[Hj]=new Image; Hd.Hp[Hj++].src=Ha[Hi];
			}		
		}
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0	
 	var myWin = window.open(theURL,'fiche',features);
	myWin.focus();
}


/***********************************************
* Detect if client has logged in before starting to order
***********************************************/

function clientLoginDetect(){
	if(jsClientId &&(jsClientId!='')){
		return true;		
	}else{
		alert("veuillez vous identifier avant de commencer votre commande");
		window.location.replace("panier-bio-login.php");
	}
}


function orderItem(imgNum){	
		var clientLogged = clientLoginDetect();
		if((clientLogged==true)&&(imgNum!="")){	
			//alert(imgNum);
			var addButton = document.getElementById(imgNum);
			addButton.style.visibility='visible';	
		}
}


function AJAXaddProduct(client_id,prodId,prodPrice,grams){
	var nom = "";
	var np = document.forms['form1'].elements['quant' + prodId].value;
	if((grams==100)||(grams==1000)){
		if((np<100)&&(np>0)){
			np=100;	
			document.forms['form1'].elements['quant' + prodId].value = "100";
		}
		var ppg = prodPrice/grams;
		var totp = (np*ppg);
	}else{
		var totp = (np*prodPrice);
	}
	
	if((totp.toFixed(2)=="NaN")||(np==0)||(np=="0")||(np=="")){
			document.forms['form1'].elements['quant' + prodId].value = "";
			document.forms['form1'].elements['out' + prodId].value = "";
	}else{			
			document.forms['form1'].elements['out' + prodId].value = totp.toFixed(2);
			//document.forms['form1'].elements['_DO_ORDER'].blur();
	}
	
	
	var handlerFunc = function(t) {
		//alert(t.responseText);
	}
		
	var errFunc = function(t) {
		//alert('Error ' + t.status + ' -- ' + t.statusText);
	}
		
	//alert(jsClientId);
		
	new Ajax.Request('ajax_commande_inserter.php', {parameters:'client_id=' + jsClientId + '&pr_id=' + prodId + '&pr_quantite=' +  np, onSuccess:handlerFunc, onFailure:errFunc});
	
	var addButton = document.getElementById("img"+prodId);
	addButton.style.visibility='hidden';	
}









function def(){
	//alert("defocus");
	document.forms['form1'].elements['_DO_ORDER'].blur();
}



function checkrequired(which, txt){
	var pass=true
	if (document.images){
		for (i=0;i<which.length;i++){
			var tempobj=which.elements[i]
			if (tempobj.name.substring(0,2)=="r_"){
				if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.value=="")){
					//alert("nope");
					pass=false
					break
				}
			}	
			
			if(document.forms['formulaire'].pr_vol){
				if((document.forms['formulaire'].pr_vol.value=='')&&(document.forms['formulaire'].unite_id.value=='')){
					pass=false
					break	
				}
			}
		}
	}
	if (!pass){
		alert("Champs obligatoires : " + txt + " ! \n Veuillez vrifier ces champs")
		return false
	}else{
		return true
	}
}
