function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()

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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function open_bon_commande() {
	MM_openBrWindow('bon_de_commande.php','bondecommande','scrollbars=yes,width=600,height=500');
}
function forget_password() { 
	MM_openBrWindow('mot_de_passe_oublier.php','forgetpassord','scrollbars=yes,width=360,height=180');
}

function showproduit(codeprd,prix){
	document.DATA.idProduitToAdd.value = codeprd;
	MM_swapImage('produit','','../interrupteurs_140x140/'+codeprd+'.jpg',1);
	MM_swapImage('addpanier','','../fr_boutique/cliquer_pour_ajouter_au_panier.gif',1);
	PG_Write_Prix(prix);
}

function PG_Write_Prix(prix){
	document.getElementById("prixproduit").innerHTML = prix+" &euro;";
	/*
	p = MM_findObj("prixproduit");
	alert(p)
	p.wref=bw.dom||bw.ie4?p.evnt:bw.ns4?p.css.document:0;		
	if (bw.ns4){p.wref.write(prix);p.wref.close()}
	else p.wref.innerHTML = prix
	*/
}

function addProduitToPanier(){
	if(document.DATA.idProduitToAdd.value!=""){
		document.DATA.submit();
	}	
}

function recalculerPanier(){
	document.DATA.PGACTION.value = "RECALCULERPANIER" ;
	document.DATA.submit();
}

function validerPanier(){
	document.DATA.PGACTION.value = "VALIDERPANIER" ;
	document.DATA.submit();
}



function nouveauClient(){
	document.DATA.PGACTION.value = "NOUVEAUCLIENT" ;
	document.DATA.submit();
}

function accesPaiement(){
	document.DATA.PGACTION.value = "ETAPE4" ;
	document.DATA.submit();
}

function vadidLivraison(){
	obj = document.DATA.cgv;
	for(i=0;i<=obj.length;i++){
		if(obj[i].checked){
			if(obj[i].value=="oui"){
				document.DATA.PGACTION.value = "VALIDPAIEMENT" ;
				document.DATA.submit();	
			}else{
				 var haut=(screen.height-370)/2;
				var gauche=(screen.width-220)/2;
				MM_openBrWindow('choix_cgv.php','choix_cgv','top='+haut+',left='+gauche+',width=370,height=220');				
			}
			break;
		}
	}	
}

function avecOuSansTransport(){
	document.DATA.PGACTION.value = "CHANGETRANSPORT";
	if(document.DATA.islivraison.checked){
		document.DATA.PGTRANSPORT.value = "0" ;
	}else{
		document.DATA.PGTRANSPORT.value = "1" ;
	}
	document.DATA.submit();
}

function compteEditCoordonnes(){
 	document.DATA.PGACTION.value = "EDIT_FORM";
    document.DATA.submit();
}
function compteModifyCoordonnes(){
 	document.DATA.PGACTION.value = "MODIFY";
    document.DATA.submit();
}

function ModifierAdresseFacturation(){
	document.DATA.isAdrFac.value = "2";
	document.DATA.submit();
}
function ModifierAdresseLivraison(){
	document.DATA.isAdrLiv.value = "2";
	document.DATA.submit();
}

function valideChoixPaiment(){
	cb = document.DATA.choixpaiment[0].checked;

	if(cb){
		document.PaymentRequest.submit();
	}else{
		document.DATA.action = "panier_paiement_valide.php";
		document.DATA.submit();	
	}
}

function relopagepaiment(obj){
	document.DATA.PGACTION.value="CHANGEMODEPAIEMENT";
	document.DATA.typePaiement.value=obj.value;
	document.DATA.submit();
}

function identificationClient(){
	email = document.DATA.email.value;
	pass = document.DATA.password.value;
	if(echeck(email) && pass!="" ){
		document.DATA.PGACTION.value = "IDENTIFICATIONCLIENT" ;
		document.DATA.submit();
	}else{
		alertIdentification(email,pass)
	}
}

function identificationBandeauHaut(){
	email = document.haut.email.value;
	pass = document.haut.password.value;

	if( email=="Votre email"){
		document.haut.submit();
	}else if( echeck(email) && pass!=""){
		document.haut.submit();
	}else{
		alertIdentification(email,pass)
	}
	
}


function alertIdentification(email,pass){
	msg1 = "";
	msg2 = "";
	if(!echeck(email)){
		msg1 = "Merci de saisir votre adresse e-mail complète.\n Exemple : contact@parisgang.com";
	}
	
	if(pass==""){
		msg2 = "\nMerci de saisir un mot de passe";	
	}
	alert(msg1 + msg2)	
}

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		//alert("Invalid E-mail ID")
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		//alert("Invalid E-mail ID")
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert("Invalid E-mail ID")
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		//alert("Invalid E-mail ID")
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//alert("Invalid E-mail ID")
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		//alert("Invalid E-mail ID")
		return false
	}
	if (str.indexOf(" ")!=-1){
		//alert("Invalid E-mail ID")
		return false
	}
	return true					
}