// JavaScript Document

function CallzoomDivPos(xpos) {
	var newImg = new Image();
	newImg.src = $('zoomerref').src;
	var width = newImg.width;
	return ((480-parseInt(width))/2);
}

function CallzoomDivPosY(height) {
	return ((269-parseInt(height))/2);
}

function no_accent(my_string) {
	var new_string = String (my_string);
	new_string = new_string.replace(/(&#x40|&#064;|@|&commat;|&#x41|&#065;|A|&#x61|&#097;|&#xC0|&#192;|À|&Agrave;|&#xC1|&#193;|Á|&Aacute;|&#xC2|&#194;|Â|&Acirc;|&#xC3|&#195;|Ã|&Atilde;|&#xC4|&#196;|Ä|&Auml;|&#xC5|&#197;|Å|&Aring;|&#xE0|&#224;|à|&agrave;|&#xE1|&#225;|á|&aacute;|&#xE2|&#226;|â|&acirc;|&#xE3|&#227;|ã|&atilde;|&#xE4|&#228;|ä|&auml;|&#xE5|&#229;|å|&aring;)/gi,'a');
	new_string = new_string.replace(/(&#xC7|&#199;|Ç|&Ccedil;|&#xE7|&#231;|ç|&ccedil;)/gi,'c');
	new_string = new_string.replace(/(&#xD0|&#208;|Ð|&ETH;)/gi,'d');
	new_string = new_string.replace(/(&#x45;|&#069;|E|&#x65;|&#101;|&#xC8;|&#200;|È|&Egrave;|&#xC9;|&#201;|É|&Eacute;|&#xCA;|&#202;|Ê|&Ecirc;|&#xCB;|&#203;|Ë|&Euml;|&#xE8;|&#232;|è|&egrave;|&#xE9;|&#233;|é|&eacute;|&#xEA;|&#234;|ê|&ecirc;|&#xEB;|&#235;|ë|&euml;)/gi,'e');
	new_string = new_string.replace(/(&#x49|&#073;|I|&#x69|&#105;|&#xCC|&#204;|Ì|&Igrave;|&#xCD|&#205;|Í|&Iacute;|&#xCE|&#206;|Î|&Icirc;|&#xCF|&#207;|Ï|&Iuml;|&#xEC|&#236;|ì|&igrave;|&#xED|&#237;|í|&iacute;|&#xEE|&#238;|î|&icirc;|&#xEF|&#239;|ï|&iuml;)/gi,'i');
	new_string = new_string.replace(/(&#x4E|&#078;|N|&#x6E|&#110;|&#xD1|&#209;|Ñ|&Ntilde;|&#xF1|&#241;|ñ|&ntilde;)/gi,'n');
	new_string = new_string.replace(/(&#x4F|&#079;|O|&#x6F|&#111;|&#xD2|&#210;|Ò|&Ograve;|&#xD3|&#211;|Ó|&Oacute;|&#xD4|&#212;|Ô|&Ocirc;|&#xD5|&#213;|Õ|&Otilde;|&#xD6|&#214;|Ö|&Ouml;|&#xF2|&#242;|ò|&ograve;|&#xF3|&#243;|ó|&oacute;|&#xF4|&#244;|ô|&ocirc;|&#xF5|&#245;|õ|&otilde;|&#xF6|&#246;|ö|&ouml;|&#xF8|&#248;|ø|&oslash;)/gi,'o');
	new_string = new_string.replace(/(&#x55|&#085;|U|&#x75|&#117;|&#xD9|&#217;|Ù|&Ugrave;|&#xDA|&#218;|Ú|&Uacute;|&#xDB|&#219;|Û|&Ucirc;|&#xDC|&#220;|Ü|&Uuml;|&#xF9|&#249;|ù|&ugrave;|&#xFA|&#250;|ú|&uacute;|&#xFB|&#251;|û|&ucirc;|&#xFC|&#252;|ü|&uuml;)/gi,'u');
	new_string = new_string.replace(/(&#x59|&#089;|Y|&#x79|&#121;|&#xDD|&#221;|Ý|&Yacute;|&#xFD|&#253;|ý|&yacute;|&#xFF|&#255;|ÿ|&yuml;)/gi,'y');
	new_string = new_string.replace(/(&#xC6|&#198;|Æ|&AElig;|&#xE6|&#230;|æ|&aelig;)/gi,'ae');
	new_string = new_string.replace(/(&#x8C|&#140;|Œ|&OElig;|&#x9C|&#156;|œ|&oelig;)/gi,'oe');
	return new_string;
}

function rawurlencode (str) {
	str = (str+'').toString();
	return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
	replace(/\)/g, '%29').replace(/\*/g, '%2A');
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='lang/chglang.asp?lang="+selObj.options[selObj.selectedIndex].value+"&url="+document.location.href+"'");
	if (restore) selObj.selectedIndex=0;
}
function MM_jumpMenuDev(targ,selObj,restore){ //v3.0
	eval(targ+".location='/?devise="+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function doSearchFormEnter() {
	if (window.event.keyCode == 13 && document.getElementById('searchKeyWords').value!='') {
		doSearchForm();
	}
}

function doSearchForm(textealerte) {
	var champ = document.getElementById('searchKeyWords');
	if (champ.value=="")
	{
		alert(textealerte);
		champ.focus();
	}
	else
		{
			$('formrecherche').action='showContentPE_Search.asp?strSearchWords=' + champ.value;
			$('formrecherche').submit();
		}
	}
	function copyDataAdrLiv() {
		if (document.getElementById( 'identique' ).checked == true) {
			if (window.document.form1.genre[0].checked == true)
			window.document.form1.genref[0].checked = true;
			if (window.document.form1.genre[1].checked == true)
			window.document.form1.genref[1].checked = true;
			if (window.document.form1.genre[2].checked == true)
			window.document.form1.genref[2].checked = true;
			document.getElementById( 'nomf' ).value = document.getElementById( 'nom' ).value;
			document.getElementById( 'prenomf' ).value = document.getElementById( 'prenom' ).value;
			document.getElementById( 'entreprisef' ).value = document.getElementById( 'entreprise' ).value;
			document.getElementById( 'ruef' ).value = document.getElementById( 'rue' ).value;
			document.getElementById( 'codepf' ).value = document.getElementById( 'codep' ).value;
			document.getElementById( 'villef' ).value = document.getElementById( 'ville' ).value;
			document.getElementById( 'statef' ).value = document.getElementById( 'state' ).value;

			var paysValue = document.form1.pays[document.form1.pays.selectedIndex].value;
			var i=0;
			var pTrouv = false;
			while( (i < document.form1.pays.length) && (!pTrouv) )
			{
				if(document.form1.pays[i].value == paysValue)
				{
					document.form1.paysf[i].selected = true;
					pTrouv = true;
				}
				i++
			}

			document.getElementById( 'telf' ).value = document.getElementById( 'tel' ).value;
			document.getElementById( 'emailf' ).value = document.getElementById( 'email' ).value;
		}
		else {
			window.document.form1.genref[0].checked = false;
			window.document.form1.genref[1].checked = false;
			window.document.form1.genref[2].checked = false;
			document.getElementById( 'nomf' ).value = "";
			document.getElementById( 'prenomf' ).value = "";
			document.getElementById( 'entreprisef' ).value = "";
			document.getElementById( 'ruef' ).value = "";
			document.getElementById( 'codepf' ).value = "";
			document.getElementById( 'villef' ).value = "";
			document.getElementById( 'statef' ).value = "";
			document.form1.paysf[0].selected = true;
			document.getElementById( 'telf' ).value = "";
			document.getElementById( 'emailf' ).value = "";
		}
	}
	//------------------------------------------------------------------------------
	function multiClass(eltId) {
		arrLinkId = new Array('_1','_2','_3','_4','_5');
		intNbLinkElt = new Number(arrLinkId.length);
		arrClassLink = new Array('current','ghost');
		strContent = new String()
		for (i=0; i<intNbLinkElt; i++) {
			strContent = "menu"+arrLinkId[i];
			if ( arrLinkId[i] == eltId ) {
				document.getElementById(arrLinkId[i]).className = arrClassLink[0];
				document.getElementById(strContent).className = 'on header';
			} else {
				document.getElementById(arrLinkId[i]).className = arrClassLink[1];
				document.getElementById(strContent).className = 'off header';
			}
		}
	}
	//------------------------------------------------------------------------------
	function creerFenetre(cUrl,cNom,cDescription)
	{
		var xWin = window.open(cUrl,cNom,cDescription)
		window.refresh
	}
	//------------------------------------------------------------------------------
	function IsEmailValid(email)
	{
		// Utilise la fonction de validation de l'email en asp
		/* url='/includes/ajax/testemail.asp?emailtest=' + email;
		EmailOk = false;

		new Ajax.Request(url,
		{
		method: 'get',
		asynchronous:false,
		onSuccess : function(transport) {
		if (transport.responseText=='True'){
		EmailOk = true;
		} else {
		EmailOk = false;
		}
		}

		}
		);

		return EmailOk */

		// Modif Simon
		validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
		// search email text for regular exp matches
		if (email.search(validRegExp) == -1) {
			return false;
		}
		return true;
	}
	//------------------------------------------------------------------------------
	function getYear(d) {
		return (d < 1000) ? d + 1900 : d;
	}
	function isDate (year, month, day) {
		month = month - 1;
		var tempDate = new Date(year,month,day);
		if ( (getYear(tempDate.getYear()) == year) &&
		(month == tempDate.getMonth()) &&
		(day == tempDate.getDate()) )
		return true;
		else
			return false
		}
		//------------------------------------------------------------------------------
		var xhr_object = null;

		function SendGetRequest(aCod,colID,quant,prix,dec) {
			if ( window.XMLHttpRequest ) {
				xhr_object = new XMLHttpRequest();
			} else if ( window.ActiveXObject ) {
				xhr_object = new ActiveXObject( 'Microsoft.XMLHTTP' );
			} else {
				alert( 'Votre navigateur ne supporte pas les objets XMLHTTPRequest...' );
				return;
			}
			xhr_object.open('POST','updateQuant.asp',false);
			xhr_object.setRequestHeader("Content-type","application/x-www-form-urlencoded");

			xhr_object.onreadystatechange = CallBackRequest;
			xhr_object.send("aCod="+aCod+"&couleur="+colID+"&quant="+quant+"&prix="+prix+"&dec="+dec);
		}

		function CallBackRequest() {
			if ( xhr_object.readyState == 4 ) {
				var param = xhr_object.responseText;
				//alert(param);
				var caddy = param.substring(param.indexOf("caddy=",0),param.indexOf("&prixT",0));
				caddy = caddy.substring(6,caddy.length);
				var prixT = param.substring(param.indexOf("prixT=",0),param.indexOf("&prixTotal",0));
				prixT = prixT.substring(6,prixT.length);
				var prixTotal = param.substring(param.indexOf("prixTotal=",0),param.indexOf("&dec",0));
				prixTotal = prixTotal.substring(10,prixTotal.length);
				var dec = param.substring(param.indexOf("dec=",0),param.indexOf("&aCod",0));
				dec = dec.substring(4,dec.length);
				var aCod = param.substring(param.indexOf("aCod=",0),param.indexOf("&prixpers",0));
				aCod = aCod.substring(5,aCod.length);
				var prixpers = param.substring(param.indexOf("prixpers=",0),param.indexOf("&prixU",0));
				prixpers = prixpers.substring(9,prixpers.length);
				var prixU = param.substring(param.indexOf("prixU=",0),param.length);
				prixU = prixU.substring(6,prixU.length);

				dec = parseInt(dec);
				prixT = parseFloat(prixT)
				prixT = prixT.toFixed(dec);
				prixpers = parseFloat(prixpers)
				prixpers = prixpers.toFixed(dec);
				prixTotal = parseFloat(prixTotal)
				prixTotal = prixTotal.toFixed(dec);
				prixU = parseFloat(prixU)
				prixU = prixU.toFixed(dec);

				//document.getElementById( 'caddy' ).innerHTML = caddy;
				document.getElementById( 'caddyTitle' ).innerHTML = caddy;
				document.getElementById( 'upPrixT'+aCod ).innerHTML = prixT;
				document.getElementById( 'upPrixTotal' ).innerHTML = prixTotal;
				document.getElementById( 'prixU' ).innerHTML = prixU;
				if (prixpers > 0)
				document.getElementById( 'prixPers' ).innerHTML = prixpers;
			}
		}
		//------------------------------------------------------------------------------
		var upT_object = null;

		function updateTotalV(code,dec) {
			if ( window.XMLHttpRequest ) {
				upT_object = new XMLHttpRequest();
			} else if ( window.ActiveXObject ) {
				upT_object = new ActiveXObject( 'Microsoft.XMLHTTP' );
			} else {
				alert( 'Votre navigateur ne supporte pas les objets XMLHTTPRequest...' );
				return;
			}
			upT_object.open('POST','upCheckOutT.asp',false);
			upT_object.setRequestHeader("Content-type","application/x-www-form-urlencoded");

			upT_object.onreadystatechange = CallBackUpdateTotal;
			upT_object.send("code="+code+"&dec="+dec);
		}

		function CallBackUpdateTotal() {
			if ( upT_object.readyState == 4 ) {
				var param = upT_object.responseText;
				//alert(param);
				var prixTotal = param.substring(param.indexOf("prixTotal=",0),param.indexOf("&dec",0));
				prixTotal = prixTotal.substring(10,prixTotal.length);
				var dec = param.substring(param.indexOf("dec=",0),param.length);
				dec = dec.substring(4,dec.length);

				dec = parseInt(dec);
				//prixTotal = parseFloat(prixTotal)
				//prixTotal = prixTotal.toFixed(dec);
				if ( prixTotal != -1 ) {
					document.getElementById( 'upPrixTotal' ).innerHTML = prixTotal;
				}
			}
		}

		function SendNLForm(textealerte,elem) {
			var email = document.getElementById(elem);
			if ((email.value=="")||!(IsEmailValid(email.value)))
			{
				alert(textealerte);
				email.focus();
			}
			else
				{
					document.location.href='newsletter_addmember.asp?email='+email.value;
				}
			}

			function SelectTabs(idtab,nolocation)
			{
				if ($('infos-produit')){
					var links = $('infos-produit').getElementsByTagName("a");

					for (var i = 0; i < links.length; i++) {
						letabs=links[i].href.substr(links[i].href.indexOf("#") + 1);
						document.getElementById(letabs).style.display = "none";
						$(letabs+'-lnk').className = $(letabs+'-lnk').className.replace("active", "");
					}
					$(idtab+'-lnk').className += " active";
					$(idtab).style.display = "block";
					if (nolocation!=true) {
						window.location.hash="#" + idtab;
						pageTracker._trackEvent('Fiche produit', idtab );
					}
				}
			}

			function FORM_GetRadioChecked(form,id){
				/**
				*   Fonction renvoyant la valeur la valeur d'un radio-groupe
				*
				*   @param   str/objet DOM      form
				*                                    Le formulaire, son id, ou même simplement l'élément
				*                                    quelconque contenant le groupe radio
				*   @param   str                  id
				*                                    Identifiant du nom du groupe radio (attribut 'name')
				*
				*@returns     null si aucun bouton radio n'est utilisé / sinon la valeur choisie
				*/
				var valeur=null;

				// Si il n'y en a qu'un le selectionne automatiquement
				$(form).select('[name="'+id+'"]').each(function(o){if (o.checked) valeur=o.value;});
				return valeur;
			}

			function SelectTaille (aTaille) {
				$('ATaille').value=aTaille;
			}

			function Ajoute_Panier(texte) {
				// Si il n'y en a qu'une couleur la selectionne automatiquement

				var valeurunique=null;
				couleurselectionnee=FORM_GetRadioChecked('artForm','couleur');
				if ($('idcouleursel') && $('idmatsel')) {
					if ($('idcouleursel').value>0 && $('idmatsel').value>0)	 {
						couleurselectionnee=1;
					}
				}

				if (!couleurselectionnee && $('IsTaille').value=='n') {
					$('contenu-ajax').style.display = 'block';
					new Ajax.Updater('contenu-ajax', '/includes/ajax/confirm_add_caddy.asp',
					{	method: 'post', evalScripts: true,
						onSuccess: function() {
							$('contenu-ajax').style.display = 'block';
						}
					});
				} else if ($('IsTaille').value=='y' && $('ATaille').value=='') {
					$('contenu-ajax').style.display = 'block';
					new Ajax.Updater('contenu-ajax', '/includes/ajax/confirm_add_caddy.asp',
					{	method: 'get', evalScripts: true,
						parameters:'IsATaille=y',
						onSuccess: function() {
							$('contenu-ajax').style.display = 'block';
						}
					});
				} else {
					var donneesForm = $('artForm').serialize();

					new Ajax.Updater('contenu-ajax', '/dynamicModule/eCommerce/addCaddy.asp',
					{	method: 'post', parameters: donneesForm + '&ajax=1', evalScripts: true,
						onSuccess: function() {
							$('contenu-ajax').style.display = 'block';
						}
					});

					new Ajax.Updater('apercu-panier', '/includes/ajax/apercu-panier.asp?ajax=1');
				}
				$('liboxhm').style.display = 'block';
			}

			function ConfirmVirement() {
				new Ajax.Updater('contenu-ajax', '/includes/ajax/confirmvirement.asp', {
					onSuccess: function() {
						$('contenu-ajax').style.display = 'block';
					}
				});
				$('liboxhm').style.display = 'block';
			}

			function ConfirmCheque() {
				new Ajax.Updater('contenu-ajax', '/includes/ajax/confirmcheque.asp', {
					onSuccess: function() {
						$('contenu-ajax').style.display = 'block';
					}
				});
				$('liboxhm').style.display = 'block';
			}

			function Uncheck() {
				$$('.radiopaiement').each(function(ele) {
					if ($(ele)) {
						$(ele).checked = false;
					}
				});
			}
			function Check(elemid) {
				Uncheck();
				elemid.checked = true;
				$('callactionpaiement').value = elemid.value;
			}
			function PaiementProcess() {
				var paiementaction = $('callactionpaiement').value;
				if (paiementaction!='') {
					// Action JS
					if (paiementaction.substr(0, 6) == '__js__') {
						eval(paiementaction.replace('__js__', ''));
					}
					// Action Url
					if (paiementaction.substr(0, 7) == '__url__') {
						this.location.href = paiementaction.replace('__url__', '');
					}
				} else {
					ChoixPaiementObligatoire();
				}
			}

			function ChoixPaiementObligatoire() {
				new Ajax.Updater('contenu-ajax', '/includes/ajax/choisissezmodepaiement.asp', {
					onSuccess: function() {
						$('contenu-ajax').style.display = 'block';
					}
				});
				$('liboxhm').style.display = 'block';
			}

			function Continuer_Achats()
			{
				//Effect.SlideUp('result-ajax');
				$('result-ajax').style.display = 'none';
				$('liboxhm').style.display = 'none';
				setTimeout("$('contenu-ajax').hide()", 1000);
			}

			// ###############################
			// Popup     #####################
			// ###############################
			var myfenetre= null;
			function popup_centre(chemin,nom_fenetre,largeur,hauteur,proprietes_autres)
			{
				if (myfenetre!=null && !myfenetre.closed)
				{
					myfenetre.close();
				}

				w = screen.width;
				h = screen.height;

				if (largeur>0 && hauteur>0)
				{
					leftPos = (w-largeur)/2;
					topPos = (h-hauteur)/2;

					if (proprietes_autres!="")
					{
						proprietes_autres=proprietes_autres+',';
					}

					proprietes_autres=proprietes_autres + 'width=' + largeur + ',height=' + hauteur + ',top=' + topPos + ',left='+leftPos;
				}


				myfenetre=window.open(chemin,nom_fenetre,proprietes_autres);
				myfenetre.focus();
			}

			function PreviewFdp(idpays) {
				new Ajax.Updater('estimfdppays', '/includes/ajax/estimation_fdp.asp',
				{
					method: 'post',
					parameters:'stock='+$('estimstock').value+'&poids='+$('estimpoids').value+'&idp='+idpays,
					evalScripts: true,
					onSuccess: function() {

					}
				});
				new Ajax.Updater('updtprice', '/includes/ajax/estimation_fdpcaddytotal.asp',
				{
					method: 'post',
					parameters:'',
					evalScripts: true,
					onSuccess: function() {

					}
				});
			}
