var basePath = "/";
function _Elem(ID){ return document.getElementById(ID); }
function trimAll(sString){	while (sString.substring(0,1) == ' ')	{	sString = sString.substring(1, sString.length);	}	while (sString.substring(sString.length-1, sString.length) == ' ')	{	sString = sString.substring(0,sString.length-1);	}return sString;}
function checkSearch(value,Refvalue,lang){	if(value==Refvalue || trimAll(value).length==0)	{		alert(_textAlert['Word2search']);	return false;	}	else	{		window.location=""+basePath+"produits/recherche.php?checkfor="+value;	}}
function update_qte(id, val) {	quantite = document.panier.quantite.value;	quantite = 	parseInt(quantite) + parseInt(val);	if (quantite < 1) { quantite = 1; }	if (quantite > 99) { quantite = 99; }	document.panier.quantite.value = quantite;}
function verif_qte(quantite){	if(isNaN(quantite)){quantite = 1; }	if (quantite < 1) { quantite = 1; }	if (quantite > 99) { quantite = 99; }	document.panier.quantite.value = quantite;}
function Add2Caddie(prod_id,Q){window.location=""+basePath+"outils/caddie_ajout.php?id="+prod_id+"&qte="+Q+"&src="+escape(window.location.href);}
function updateCaddie(value,lang){	if(value<=0 || value=="" || isNaN(value))	{	alert(_textAlert['notnull']);	window.location = this.window.location;	}	else if(value>99)	{	alert(_textAlert['notnull']);	window.location = this.window.location;	}	else	{	document.EditPanier.action='updatecaddie.php';	document.EditPanier.submit();	}}
function remove_id(value){	document.EditPanier.action='removeidcaddie.php?id='+value+'';	document.EditPanier.submit();}
function explode(chaine,separateur){var tableau = new Array();var test = "";var j=0;	for(i=0;i<chaine.length;i++)	{		if(chaine.substring(i,i+1)!=separateur)		{		test+=chaine.substring(i,i+1);		} 		else			{		tableau[j] = test;		test = "";		j++;		}	}if(i==chaine.length){tableau[j++] = test;}	return tableau;}
function chargePanLimit(array,lang){var xns = 0;	for (i=0;i<array.length;i++)	{	var TypePanH = array[i][0];	var SuiteVal = array[i][1];	var CurrentVal = array[i][2];	var tableauVal = new Array();	var test = "";	var k=0;		for(l=0;l<SuiteVal.length;l++)		{			if(SuiteVal.substring(l,l+1)!=',')			{			test+=SuiteVal.substring(l,l+1);			} 			else				{			tableauVal[k] = test;			test = "";			k++;			}		}		if(l==SuiteVal.length)	{	tableauVal[k++] = test;	}			for(j=0;j<tableauVal.length;j++)		{			if(eval(CurrentVal)>eval(tableauVal[j]) && eval(CurrentVal)<eval(tableauVal[j+1]))			{			alert(_textAlert['AchatMalin_'+TypePanH+'_A']+" "+eval(tableauVal[j+1]-CurrentVal)+" "+_textAlert['AchatMalin_'+TypePanH+'_B']+" "+eval(CurrentVal-tableauVal[j]));			xns++;			}		}		}		if(xns>0)	{	return false;	}	return true;}
function HomePage(obj,lang){	if (document.all) {		obj.style.behavior='url(#default#homepage)';		obj.setHomePage('http://www.4patshop.com/');		return false;	} else {		alert(_textAlert['Set2HomePage']);	}}
function addFav(lang){	if (document.all) {	window.external.AddFavorite(location.href, document.title);	} else {		alert(_textAlert['Add2signet']);	}}
function log_in(login,passwd,lang){	if(login.length==0)	{	alert(_textAlert['loginnotnull']);	document.login.email.focus();	document.login.email.style.background='#adb583';	return false;	}	if(login.indexOf("@")==-1||login.indexOf(".")==-1||login.length<5)	{	alert(_textAlert['loginnotvalid']);	document.login.email.focus();	document.login.email.style.background='#adb583';	return false;	}	if(passwd.length==0)	{	alert(_textAlert['passwdnotnull']);	document.login.passwd.focus();	document.login.passwd.style.background='#adb583';	return false;	}	document.login.action='../outils/login.php';	document.login.submit();}
function checkNouvCLient(lang) {	var login = _Elem('PinkLoginEmail');	var pass  = _Elem('nouvCliPasswd');	var myForm = _Elem('nouvClient');	if(login.value.length==0)	{	alert(_textAlert['loginnotnull']);	login.focus();	login.style.background='#BAA395';	return false;	}	if(login.value.indexOf("@")==-1||login.value.indexOf(".")==-1||login.value.length<5)	{	alert(_textAlert['loginnotvalid']);	login.focus();	login.style.background='#BAA395';	return false;	}	if(pass.value.length == 0)	{	alert(_textAlert['passwdnotnull']);	pass.focus();	pass.style.background='#BAA395';	return false;	}	if(pass.value.length < 6)	{	alert(_textAlert['mdp_tooshort']);	pass.focus();	pass.style.background='#BAA395';	return false;	}	myForm.submit();}
function showHide (myId) {	var tmp = _Elem(myId);	if ( tmp.style.display != 'none' ) {		tmp.style.display = 'none';	} else {		tmp.style.display = '';	}}
function showHideProd (myId) {	var tmp = _Elem(myId);	if ( tmp.style.display != 'none' ) {		tmp.style.display = 'none';	} else {		tmp.style.display = '';	}}
function showHideCat (myId,pathToImg) {	var sp = _Elem('s'+myId);	var im = _Elem('i'+myId);	if ( sp.style.display != 'none' ) {		sp.style.display = 'none';		im.src = pathToImg+'expand.gif';	} else {		sp.style.display = '';		im.src = pathToImg+'collapse.gif';	}}
function copyFactToLivr () {	var field2Copy = new Array() ;	var i = 1 ;	field2Copy[i++] = Array ('Fcivilite', 'Lcivilite');	field2Copy[i++] = Array ('Fprenom', 'Lprenom');	field2Copy[i++] = Array ('Fnom', 'Lnom');	field2Copy[i++] = Array ('Fsociete', 'Lsociete');	field2Copy[i++] = Array ('Frue1', 'Lrue1');	field2Copy[i++] = Array ('Frue2', 'Lrue2');	field2Copy[i++] = Array ('Fzip', 'Lzip');	field2Copy[i++] = Array ('Fville', 'Lville');	field2Copy[i++] = Array ('Fpays', 'Lpays');	copyForm(field2Copy);}
function copyForm(field2Copy){	for (i=1; i < field2Copy.length; i++) {		var src = _Elem(field2Copy[i][0]);		var dst = _Elem(field2Copy[i][1]);		dst.value = src.value;	}}
function EditCommande(id) {	self.location = "index.php?MCMOD=editCommande&commande_id="+id+"&retour="+self.location;}
function CreateCommande(bq,cgv,lang){	if(bq==0)	{	alert(_textAlert['NoBq']);	document.EditPanier.PaiementType.focus();	return false;	}		if(cgv==true)	{ 	document.EditPanier.action=""+basePath+"outils/CreateCommande.php"; 	document.EditPanier.submit();	}	else		{	alert(_textAlert['NoCgv']);	}return false;}/* paiement en ligne */
function encode64(input) {  var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";   var output = "";   var chr1, chr2, chr3;   var enc1, enc2, enc3, enc4;   var i = 0;   do {      chr1 = input.charCodeAt(i++);      chr2 = input.charCodeAt(i++);      chr3 = input.charCodeAt(i++);      enc1 = chr1 >> 2;      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);      enc4 = chr3 & 63;      if (isNaN(chr2)) {         enc3 = enc4 = 64;      } else if (isNaN(chr3)) {         enc4 = 64;      }      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +          keyStr.charAt(enc3) + keyStr.charAt(enc4);   } while (i < input.length);      return output;}
function paiementParSolde(follow){	window.location=""+basePath+"outils/vpbs.php?"+follow; }
function paiementEnLigne(follow, isnew)
{
	if(isnew!=null)
	{
		url = ""+basePath+"outils/bplc_new.php?"+follow;
	}
	else
	{
		url = ""+basePath+"outils/bplc_new.php?"+follow;
	}
	openLiteWin(url,1024,800,150,150,'full');
}
function paiementEnLignePPL(sold,credit,lang,follow){
		var a = credit;
		var b = new Number(a.replace(',','.'));
		var stop = 0;
		if(isNaN(b))
		{
			alert (_textAlert['NANb']);
			document.EditSolde.credit.value=sold.toFixed(2);
			document.EditSolde.credit.focus();
			stop++;
			return false;
		}
		var c = b.toFixed(2);
		if(sold<0)
		{
			sold_a = -sold;
			if(c<sold_a)
			{
				alert (_textAlert['CreditInsuffisantA']+sold_a+_textAlert['CreditInsuffisantB']);
				document.EditSolde.credit.value=sold_a.toFixed(2);
				document.EditSolde.credit.focus();
				stop++;
				return false;
			}
		}

		if(c<5)
		{
			alert (_textAlert['CreditInsuffisantC']);
			document.EditSolde.credit.value=Math.abs(c);
			document.EditSolde.credit.focus();
			stop++;
			return false;
		}

		if(stop==0)
		{
			montant = c;
			url = ""+basePath+"outils/bplc_new?"+follow;
			window.location=url;
		}
}
/**********************************************************************************/
function checkMail(mail){	if(mail.indexOf("@")==-1||mail.indexOf(".")==-1||mail.length<5)	{		return false;	}	return true;}
function VerifFormCourrier(myForm,lang){	with (myForm) {		var msg = _textAlert['introSupport'];		var nbError = 0 ;		var focObj = 0 ;		if (! checkMail(email.value) ) {			nbError += 1 ;			msg += "\n"+_textAlert['emailError'];			if (focObj == 0) focObj = email;			email.className = 'SupportInputError';		} else { email.className = 'SupportInput'; }		if ( nom.value.length == 0 ) {			nbError += 1 ;			msg += "\n"+_textAlert['nomVide'];			if (focObj == 0) focObj = nom;			nom.className = 'SupportInputError';		} else { nom.className = 'SupportInput'; }		if ( sujet.value.length == 0 ) {			nbError += 1 ;			msg += "\n"+_textAlert['sujetVide'];			if (focObj == 0) focObj = sujet;			sujet.className = 'SupportInputError';		} else { sujet.className = 'SupportInput'; }		if ( texte.value.length == 0 ) {			nbError += 1 ;			msg += "\n"+_textAlert['texteVide'];			if (focObj == 0) focObj = texte;			texte.className = 'SupportTextareaError';		} else { texte.className = 'SupportTextarea'; }	}	if (nbError > 0) {		alert (msg);		focObj.focus();	} else { myForm.submit(); }}
function VerifFormReco(myForm,lang) {with (myForm) {		var msg = _textAlert['introSupport'];		var nbError = 0 ;		var focObj = 0 ;		if ( expNom.value.length == 0 ) {			nbError += 1 ;			msg += "\n"+_textAlert['nomVide'];			if (focObj == 0) focObj = expNom;			expNom.className = 'SupportInputError';		} else { expNom.className = 'SupportInput'; }		if (! checkMail(expEmail.value) ) {			nbError += 1 ;			msg += "\n"+_textAlert['emailError'];			if (focObj == 0) focObj = expEmail;			expEmail.className = 'SupportInputError';		} else { expEmail.className = 'SupportInput'; }		if ( destNom.value.length == 0 ) {			nbError += 1 ;			msg += "\n"+_textAlert['destNomVide'];			if (focObj == 0) focObj = destNom;			destNom.className = 'SupportInputError';		} else { destNom.className = 'SupportInput'; }		if (! checkMail(destEmail.value) ) {			nbError += 1 ;			msg += "\n"+_textAlert['destEmailError'];			if (focObj == 0) focObj = destEmail;			destEmail.className = 'SupportInputError';		} else { destEmail.className = 'SupportInput'; }	}	if (nbError > 0) {		alert (msg);		focObj.focus();	} else { myForm.submit(); }}
function AddToNewsliste(lang) {	var emel = _Elem('InputNewsletterEmail');	if ( ! checkMail (emel.value ) ) {		alert (_textAlert['loginnotvalid']);		emel.focus();	} else {		window.location= basePath+"outils/ajout_newsliste.php?email="+emel.value;	}}
function goCat(value) {	window.location= basePath+"categories/?id="+value;}
function getCenterWin(width,height){	if (document.body)	{	 var larg = (document.body.clientWidth);	 var haut = (document.body.clientHeight);	}	else	{	 var larg = (window.innerWidth);	 var haut = (window.innerHeight);	}	var myTop = Math.round((haut - height) / 2);	var myLeft =Math.round((larg - width) / 2);	var tmp = Array;	tmp['top'] = myTop;	tmp['left'] = myLeft;	tmp['width'] = width;	tmp['height'] = height;	return tmp;}
function divOpen(url,top,left,width,height) {	var myDiv = _Elem("overPopup");	var myPop = _Elem("myPopup");	myDiv.style.top = top+"px" ;	myDiv.style.left = left+"px";	myDiv.style.width = width+"px";	myDiv.style.height = height+"px";	myPop.width = width;	myPop.height = height;	myPop.src = url;	myDiv.style.visibility = '';	myDiv.style.display = '';}
function hidePopup() {	var myDiv = _Elem("overPopup");	var myPop = _Elem("myPopup");	myDiv.style.visibility = 'hidden';	myDiv.style.display= 'none';	myPop.width = 1;	myPop.height = 1;	myDiv.style.width = "1px"; 	myDiv.style.height = "1px";	myPop.src = 'about:blank';	myDiv.style.top = "1px"; 	myDiv.style.left = "1px";}
function lireCGA(lang){	var myParam = getCenterWin(600,400);	divOpen("cga.html",myParam['top'], myParam['left'], myParam['width'], myParam['height']); 	var myPop = _Elem("myPopup");	myPop.scrolling='auto';}
function vote4Product(prodId,vote) {	var myParam = getCenterWin(200,120);	divOpen (basePath+"outils/vote4product.php?id="+prodId+"&vote="+vote, myParam['top'], myParam['left'], myParam['width'], myParam['height']);}
function checkPass(len,path,lang) {	var pass1 = _Elem('pass1');	var pass2 = _Elem('pass2');	var passBtn = _Elem('passBtn');	var passBtnDiv = _Elem('bid-valide');	var passImg = _Elem('passImg');	var passMsg = _Elem('passMsg');	if ((pass1.value == pass2.value) && (pass1.value.length >= len)) {		passBtn.disabled = false;		passBtnDiv.style.display = '';		passImg.src = path+"ok.gif";		passMsg.value = _textAlert['mdp_ok'];	} else {		if (pass1.value != pass2.value) {			passMsg.value = _textAlert['mdp_notmatch'];		}		if (pass1.value.length < len ) {			passMsg.value = _textAlert['mdp_tooshort'];		}		passBtnDiv.style.display = 'none';		passBtn.disabled = true;		passImg.src = path+"off.gif";	}}
function inscrivezVous(){	showHide('testPink');	showHide('testGreen');}
function goFormAff(lang) {	var cb = _Elem ('accepte');	if (cb.checked == true) {		cb.form.submit();	} else { alert (_textAlert['must_accept_cga']); }} function isUrl(s) {	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;	return regexp.test(s);}
function checkAddSite(lang) {	var myForm = _Elem('formNouveauSite');	with (myForm) {		if (isUrl(url.value)) {			submit();		} else {			alert (_textAlert['valid_url']);			url.focus();		}	}}var zoomRatio = 3;
function preview(zoom) {	debug = false;	var dvPr = _Elem('dvPreview');	var myForm= _Elem('editSite');	var nbProd = myForm.nb_produits.value ; 	var orient = myForm.orientation.value ;	var style  = myForm.template_id.value ;	var variant= myForm.template_style.value ;	if (debug) alert('avant effacement'); 	dvPr.innerHTML = '';	if (debug) alert('apres effacement');	if (zoom != zoomRatio) {		if (debug) alert('reaffectation du zoom');		zoomRatio = zoom;		var dvSize = 120 * zoomRatio;		dvPr.style.width = dvSize;		dvPr.style.height = dvSize;		if (zoom == 1) {			if (debug) alert ('zoom = 1');			dvPr.style.top = '0px';			dvPr.style.left = '0px';			dvPr.style.backgroundImage = 'url('+basePath+'samples/fond120.jpg)';			mySize = 11;			imgSize = 8 * zoomRatio;			if (debug) alert('fin zoom = 1');		} else {			if (debug) alert('zoom != 1');			dvPr.style.top = '-240';			dvPr.style.left = '-30';			dvPr.style.backgroundImage = 'url('+basePath+'samples/fond360.jpg)';			myLeft = 300;			myTop = 60;			mySize = 42;			imgSize = 28;			if (debug) alert('fin zoom != 1');		}	}	var fontSize = 3 * zoomRatio;	var fl = '';	var bgColor = _TabColor[style]['fond'];	var fgColor = _TabColor[style]['bord'];	if (orient == 'HOR' ) {		if (debug) alert('orient == hor');				myLeft = 0;				myTop = 0;				fl = 'float: left;';				if (zoom == 1) {				dX = 15 ; dY = 0 ;				} else { dX = 45 ; dY = 0; }		if (debug) alert('fin orient == hor');			} else {				myLeft = 100*zoomRatio;				myTop = 28*zoomRatio;				if (zoom == 1) {				dX = 0 ; dY = 15 ;				} else { dX = 0 ; dY = 45; }			}	var tmp = '';	for (i=1 ; i <= nbProd; i++){		tmp += '<div align="center" style="margin: 1px; position: absolute; left:'+myLeft+'; top:'+myTop+'; font-size:'+fontSize+'px; width:'+mySize+'px; height:'+mySize+'px; '+fl+' border: 1px '+variant+' '+fgColor+'; background: '+bgColor+'"><img src="'+basePath+'samples/prod'+i+'.jpg" width="'+imgSize+'" height="'+imgSize+'"><br><div align="right">Acheter&nbsp;</div></div>';		myTop = myTop + dY; 		myLeft = myLeft + dX;	}	if (debug) alert ('avant change html');dvPr.innerHTML = tmp ;	if (debug) alert ('apres change html')}
function checkCredit (myForm) {	return (myForm.comm.value > 0) ;}
function Send2Friend(prod_id,url,lang){window.location=basePath+"outils/send2friend.php?prod_id="+prod_id+"&back="+url;}
function relancer(num_affaire) {	window.location=basePath+"support/support.php?send=relance&num_affaire="+num_affaire;}
function nouvQuest() {	window.location=basePath+"support/support.php";}
function register(){	window.location.href="/moncompte/index.php?MCMOD=register";	}
function confirmAddr(typeAlert,cid){

	switch(typeAlert)
	{
		case 'print': var alerte=_textAlert['confirmAddrPrint']; break;
		case 'paieLine': case 'paieSold': var alerte=_textAlert['confirmAddrPaieLine']; break;
		default : var alerte=_textAlert['confirmAddrPrintPaie']; break;
	}

	var tmpString="";
	 tmpString+=alerte+"\n\n";
	 tmpString+=$('#societe').val()+"\n";
	 tmpString+=$('#civ_abr').val()+' '+$('#nom').val()+"\n";
	 tmpString+=$('#rue1').val()+"\n";
	 tmpString+=($('#rue2').val()!="")?"\n"+$('#rue2').val()+"\n":"";
	 tmpString+=$('#code_postal').val()+' '+$('#ville').val()+"\n";
	 tmpString+=$('#pays_name').val()+"\n\n";
	 tmpString+=_textAlert['confirmAddrConf'];

	if(confirm(tmpString))
	{
		var queryString = $('#confirmAddrForm').serialize();
		var url = "/outils/setObj.php?obj=confirmAddr&cid="+cid+"&"+queryString;
		$('#uid').load(url);
	}
}

