﻿/* MENU-VERTI */
function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("menu-vertical").getElementsByTagName("DIV");
		if(el.style.display == "none"){
			for (var i=0; i<ar.length; i++){
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{el.style.display = "none";}
	}
}
function ChangeClass(menu, newClass) { 
	if (document.getElementById){ 
		document.getElementById(menu).className = newClass;
	} 
} 
var moz = (document.implementation && document.implementation.createDocument); var ie = (window.ActiveXObject);
function LoadPage(page){
	url=page;
	document.location.href=page;
	var t = url.lastIndexOf('?url=')
	if(t==-1){document.location.href='?url='+page;}
	else{document.location.href=page;}
}
document.onselectstart = new Function("return true");
/* END MENU-VERTI */

/*CONNEXION FORM*/
function ControleConn(){
	document.getElementById('ConnMsg').innerHTML='';
	if(document.frmConn.login){
		if(document.frmConn.login.value=='' || document.frmConn.code.value==''){
			document.getElementById('ConnMsg').innerHTML="Erreur dans la saisie de votre email ou de votre code"
			return false;
		}
	}
	return true;
}
function videConn(){
	document.getElementById('ConnMsg').innerHTML='';
}
function _CtrlCheckStreet(val){
	document.getElementById('invoicedBloc').style.display = val==1 ? 'block' : 'none';
}
function _CtrlCheckDelivery(val){
	document.getElementById('livraison_txt2').style.display = val==1 ? 'block' : 'none';
	document.getElementById('Deliverycountry').style.display = val==1 ? 'block' : 'none';
}
/*END COnnexion Form*/
/*LOST FORM*/
function ControleLost(){
	var email  = new RegExp("^[a-zA-Z0-9_\\-\\.]{3,}@[a-zA-Z0-9\\-_]{2,}\\.[a-zA-Z]{2,4}$", "g");
	if (!email.test(document.frmLost.login.value)){return false;}
return true;
}
/*END COnnexion Form*/
/* DELIVERY Form*/
function CtrlDelivery(){
	var vf=0;
	for (var rad=0;rad<3;rad++){
		if(document.frmDelivery.livraison[rad]){
			if(document.frmDelivery.livraison[rad].checked==true){
				switch(parseInt(rad)){
				case 2 :
					if (document.getElementById('livraison_txt'+rad).innerHTML == ""){
					vf++;
					}
					if(document.getElementById('Deliverycountry').value==0){
						vf++;
					}
				}
				document.frmDelivery.delivery.value=rad+'|'+document.getElementById('livraison_txt'+rad).innerHTML;
			}
		}
	}
	if(vf>0) alert("Des renseignements n'ont pas été correctement saisis !");
	return vf == 0 ? true : false;
}
/*End Delivery Form*/
/*freight form*/
function CtrlFreight(){
	var vf=0;
	rad=document.frmFreight.envoi.length;
	switch(isNaN(rad)){
		case true : 
			if(document.frmFreight.envoi.checked==false){vf++;}break;
		case false : 
		vf=rad;
		for(i=0;i<rad;i++){if(document.frmFreight.envoi[i].checked==true){vf=0;break;}}break;
	}
	return vf == 0 ? true : false;
	//alert(vf)
	//return false;
}
/*end freight form*/
/*Pay form*/
function CtrlPayment(){
	var vf=0;
	radpay=document.frmPay.mdp.length;
	switch(isNaN(radpay)){
		case true : 
			if(document.frmPay.mdp.checked==false){vf++;}break;
		case false : 
		vf=radpay;
		for(i=0;i<radpay;i++){if(document.frmPay.mdp[i].checked==true){vf=0;break;}}break;
	}
	return vf == 0 ? true : false;
	//alert(vf)
	//return false;
}
/*end Pay form*/


/* MSG FORM */
function ControlMsg(){
	var vf=0;
	document.ff.name.className="Inputnormal";
	if(document.ff.name.value==''){
		document.ff.name.className="Inputrequired";
		vf++;
	}
	document.ff.msg.className="Inputnormal";
	if(document.ff.msg.value==''){
		document.ff.msg.className="Inputrequired";
		vf++;
	}
	document.ff.email.className="Inputnormal";
	var email  = new RegExp("^[a-zA-Z0-9_\\-\\.]{3,}@[a-zA-Z0-9\\-_]{2,}\\.[a-zA-Z]{2,4}$", "g");
	if (!email.test(document.ff.email.value)){
		document.ff.email.className="Inputrequired";
		vf++;
	}
	document.ff.captchacode.className="Inputnormal";
	if (document.ff.captchacode.value==''){
		document.ff.captchacode.className="Inputrequired";
		vf++;
	}
	if (vf>0){
		document.location.href='#ConnMsg';
		document.getElementById('ConnMsg').innerHTML = "Des renseignements n'ont pas été correctement saisis !"
	}
	return vf == 0 ? true : false
}
/* END MSG FORM */
/* CAPTCHA OBJ */
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}
/* END CAPTCHA OBJ */
/* Account Form */
function CtrlAccount(){
var vf=0;
//var step=document.getElementById('etape').value;
	document.frmAccount.lastname.className="Inputnormal";
	if(document.frmAccount.lastname.value==''){
		document.frmAccount.lastname.className="Inputrequired";
		vf++;
	}
	document.frmAccount.firstname.className="Inputnormal";
	if(document.frmAccount.firstname.value==''){
		document.frmAccount.firstname.className="Inputrequired";
		vf++;
	}
	document.frmAccount.street.className="Inputnormal";
	if(document.frmAccount.street.value==''){
		document.frmAccount.street.className="Inputrequired";
		vf++;
	}
	document.frmAccount.zip.className="Inputnormal";
	if(document.frmAccount.zip.value==''){
		document.frmAccount.zip.className="Inputrequired";
		vf++;
	}
	document.frmAccount.city.className="Inputnormal";
	if(document.frmAccount.city.value==''){
		document.frmAccount.city.className="Inputrequired";
		vf++;
	}
	document.frmAccount.phone.className="Inputnormal";
	if(document.frmAccount.phone.value==''){
		document.frmAccount.phone.className="Inputrequired";
		vf++;
	}
	document.frmAccount.email.className="Inputnormal";
	document.frmAccount.emailC.className="Inputnormal";
	if(document.frmAccount.email.value==document.frmAccount.emailC.value){
		var email  = new RegExp("^[a-zA-Z0-9_\\-\\.]{3,}@[a-zA-Z0-9\\-_]{2,}\\.[a-zA-Z]{2,4}$", "g");
		if (!email.test(document.frmAccount.email.value)){
			document.frmAccount.email.className="Inputrequired";
			document.frmAccount.emailC.className="Inputrequired";
			vf++;
		}
	}
	else{
		document.frmAccount.email.className="Inputrequired";
		document.frmAccount.emailC.className="Inputrequired";
		vf++;
	}
	if (document.frmAccount.pwd){
		document.frmAccount.pwd.className="Inputnormal";
		if(document.frmAccount.pwd.value==''){
			document.frmAccount.pwd.className="Inputrequired";
			vf++;
		}
	}
	 /*ctrl facturation*/
	document.frmAccount.lastnameF.className="Inputnormal";
	document.frmAccount.streetF.className="Inputnormal";
	document.frmAccount.zipF.className="Inputnormal";
	document.frmAccount.cityF.className="Inputnormal";
	document.frmAccount.captchacode.className="Inputnormal";
	for(i=0;i<2;i++) var rd = document.frmAccount.invoiceStreet[0].checked==true ? 0 : 1; 
	if(rd==1){
		if(document.frmAccount.lastnameF.value==''){
			document.frmAccount.lastnameF.className="Inputrequired";
			vf++;
		}
		if(document.frmAccount.streetF.value==''){
			document.frmAccount.streetF.className="Inputrequired";
			vf++;
		}
		if(document.frmAccount.zipF.value==''){
			document.frmAccount.zipF.className="Inputrequired";
			vf++;
		}
		if(document.frmAccount.cityF.value==''){
			document.frmAccount.cityF.className="Inputrequired";
			vf++;
		}
	}
	if (document.frmAccount.captchacode.value==''){
		document.frmAccount.captchacode.className="Inputrequired";
		vf++;
	}
	if(vf>0){
		//alert("Des renseignements n'ont pas été correctement saisis !");
		document.location.href='#ConnMsg';
		document.getElementById('ConnMsg').innerHTML = "Des renseignements n'ont pas été correctement saisis !"
	}
	return vf == 0 ? true : false;
}
/* END Account Form*/
function getXhr(){
	var xhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur 
	alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	xhr = false; 
	} 
	return xhr
} 
/* HISTO FORM*/
function openDocument(_id){
	window.open("invoice/document.asp?id="+_id,null,"width=800px,height=500px,scrollbars=1,location=0,menubar=0,directories=0,status=0,toolbar=0")
}
function displayLine(_id){
	document.getElementById('block'+_id).style.display=document.getElementById('block'+_id).style.display=='none' ? 'block' : 'none';
}
/*END HISTO FORM*/

