// Verif Form Inscription

function duplic(obj){
	if(obj.id=='nom_client') $("nom_livr_client").value = obj.value;
	if(obj.id=='prenom_client') $("prenom_livr_client").value = obj.value;
	if(obj.id=='adresse_factu_client') $("adresse_livr_client").value = obj.value;
	if(obj.id=='compl_adresse_factu_client') $("compl_adresse_livr_client").value = obj.value;
	if(obj.id=='cp_factu_client') $("cp_livr_client").value = obj.value;
	if(obj.id=='ville_factu_client') $("ville_livr_client").value = obj.value;
}

function ctrlchamp(obj){
	obj.setAttribute("autocomplete","on");	
	var theid=$(obj).id;
	if($(theid+'ctrl')!= null){
		var texte,p,i,l,t,c;
		l=trim($(obj).value).length;
		t=$(obj).value;
		coul1 = '#1A7917';
		coul2 = '#cc0000';
		
		switch(theid){
			case 'userw':
				if(l<4){i='avisko.gif';p='<b>'+t+'</b> Cet identifiant est trop court (4 caractères minimum)';c=coul2;}
				else if(texte = file('config/ajax.php?req=2&pseudo='+escape(t)))
				switch(texte){
					case '1':i='avisko.gif';p='<b>'+t+'</b> Cet identifiant est déjà pris';c=coul2;break;
					case "\n2":
					case '2':i='avisok.gif';p='<b>'+t+'</b> Cet identifiant est libre! Vous pouvez continuer...';c=coul1;break;
					case '3':i='avisko.gif';p='<b>'+t+'</b> Désolé, l&acute;identifiant ne doit ni contenir de point ni d&acute;espace ni de caractère &amp;...';c=coul2;break;
				}
				break;
			case 'nom_client':if(l<2){i='avisko.gif';p="Please type your name.";c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}break;
			case 'prenom_client':if(l<2){i='avisko.gif';p="Please type your first name.";c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}break;
			case 'adresse_factu_client':if(l<10){i='avisko.gif';p="Please type your address.";c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}break;
			/*case 'cp_factu_client':if(l<5 || !IsNumeric(t)){i='avisko.gif';p="Please type your postcode.";c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}break;*/
			case 'cp_factu_client':if(l<5 ){i='avisko.gif';p="Please type your postcode.";c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}break;
			case 'ville_factu_client':if(l<2){i='avisko.gif';p='Please seize your city.';c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}	break;
			case 'tel_client':if(l<10 || !IsTel(t,true)){i='avisko.gif';p="Phone invalid. Please type again it.";c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}break;
			case 'mdp_client':if(!ValInMinMax(t,6,10)){i='avisko.gif';p="Password too course or too length (6 to 10 characters)";c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}break;
			case 'mdp2_client':if(t!=$('mdp_client').value||l<4){i='avisko.gif';p="You did not enter 2 times the same password or the entered password is too course";c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}break;
			case 'email_client3':if(!verifMail('inscription','email_client3')){i='avisko.gif';p='Invalid e-mail. Please seize again it';c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}break;
			case 'email2_client':if(t!=$('email_client3').value||l<4){i='avisko.gif';p='The addresses e-mail are not identical';c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}break;
			case 'parrain_client':if(t!='' && t!="L'email de votre parrain"){if(!verifMail('inscription','parrain_client')){i='avisko.gif';p='Email invalide. Veuillez le ressaisir.';c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}}break;
			case 'mention':if($(obj).checked==false){i='avisko.gif';p='You must accept the sale terms.';c=coul2;}else{if(t!=''){i='avisok.gif';p='Ok';c=coul1;}}break;
			case 'pays':if(trim($('idpays').value)==''||$('idpays').value=='null'){i='avisko.gif';p='Please choose your country in the list proposed.';c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;}break;
		}
		// -- TEST DES FILLEULS
		var reg= /filleul/;
		if(reg.test(theid)){
			if(t!='' && t!="Email filleul"){
				if(!verifMail('inscription',theid)){i='avisko.gif';p='Invalid e-mail. Please seize again it';c=coul2;}else{i='avisok.gif';p='Ok';c=coul1;};
			}else{
				i='avisok.gif';p='Ok';c=coul1;
			}
		}
			
		if(p!=undefined){
			if(theid=='parrain_client'){
				if(t!="L'email de votre parrain" && t!=''){
					$(theid+'ctrl').innerHTML='<span style="color:'+c+'"><img src="http://www.cave-des-grands-vins.com/vin-cru-classe/'+i+'" align="middle" />&nbsp;'+p+'</span>';
				}else{
					$(theid+'ctrl').innerHTML='';
				}
			}else{
				if(reg.test(theid)){
					if(t=='' || t=="Email filleul"){
						$(theid+'ctrl').innerHTML='';
					}else{
						$(theid+'ctrl').innerHTML='<span style="color:'+c+'"><img src="http://www.cave-des-grands-vins.com/vin-cru-classe/'+i+'" align="middle" />&nbsp;'+p+'</span>';
					}
				}else{
					$(theid+'ctrl').innerHTML='<span style="color:'+c+'"><img src="http://www.cave-des-grands-vins.com/vin-cru-classe/'+i+'" align="middle" />&nbsp;'+p+'</span>';
				}
			}
			if($(obj).parentNode.className!="border0check"){
				if(c=='#1A7917'){
					$(obj).parentNode.className="input_form_div";
				}else{
					$(obj).parentNode.className="input_form_div_over";
				}
			}
		}
	}
}
function resetform(obj){
	var tab_ele = obj.elements;
	for(i=0;i<tab_ele.length;i++){
		if($(tab_ele[i].id+'ctrl')!=undefined) $(tab_ele[i].id+'ctrl').innerHTML='';
	}
}
function focusblur(obj){
	obj.focus();
	obj.blur();
	obj.focus();
}
function verifform(){
	resetColor();
	var d=$("inscription");
	if(trim(d.nom_client.value)==''){myalert=new alertbox({focusel:'nom_client'});focusblur(d.nom_client);myalert.alert("Please type your name.");return (false);}
	if(trim(d.prenom_client.value)==''){myalert=new alertbox({focusel:'prenom_client'});focusblur(d.prenom_client);myalert.alert("Please type your first name.");return (false);}
	if(trim(d.adresse_factu_client.value).length<10){myalert=new alertbox({focusel:'adresse_factu_client'});focusblur(d.adresse_factu_client);myalert.alert("Please type your address.");return (false);}
	/*if(trim(d.cp_factu_client.value).length<5 || !IsNumeric(d.cp_factu_client.value)){myalert=new alertbox({focusel:'cp_factu_client'});focusblur(d.cp_factu_client);myalert.alert("Please type your postcode.");return (false);}*/
	if(trim(d.cp_factu_client.value).length<5){myalert=new alertbox({focusel:'cp_factu_client'});focusblur(d.cp_factu_client);myalert.alert("Please type your postcode.");return (false);}
	if(trim(d.ville_factu_client.value)==''){myalert=new alertbox({focusel:'ville_factu_client'});focusblur(d.ville_factu_client);myalert.alert("Please seize your city.");return (false);}
	if(trim(d.tel_client.value).length<10 || !IsTel(d.tel_client.value,true)){myalert=new alertbox({focusel:'tel_client'});focusblur(d.tel_client);myalert.alert("Phone invalid. Please type again it..");return (false);}
	if(!ValInMinMax(trim(d.mdp_client.value),6,10)){myalert=new alertbox({focusel:'mdp_client'});focusblur(d.mdp_client);myalert.alert("Password too course or too length (6 to 10 characters)");return (false);}
	if(d.mdp_client.value!=d.mdp2_client.value){myalert=new alertbox({focusel:'mdp2_client'});d.mdp_client.value="";d.mdp2_client.value="";focusblur(d.mdp_client);myalert.alert("You did not enter 2 times the same password or the entered password is too course.");return (false);}
	if(!verifMail('inscription','email_client3')){myalert=new alertbox({focusel:'email_client3'});focusblur(d.email_client3);d.email_client3.select();myalert.alert("Invalid e-mail. Please seize again it");return (false);}
	if(trim(d.email_client3.value)!=trim(d.email2_client.value)){myalert=new alertbox({focusel:'email_client3'});focusblur(d.email2_client);d.email_client3.select();myalert.alert("Invalid e-mail. Please seize again it");return (false);}
	//d.parrain_client.disabled=false;
	//if(d.parrain_client.value!="" && d.parrain_client.value!="L'email de votre parrain"){if(!verifMail('inscription','parrain_client')){d.parrain_client.parentNode.className="input_form_div_over";d.parrain_client.select();myalert.alert("L'email de votre parrain que vous avez saisi est invalide. Veuillez recommencer.");return (false);}}
	var i=1;
	/*
    for(i=1;i<=6;i++){
		if($('filleul'+i).value=="Email filleul"){
			$('filleul'+i).value='';
		}else{
			if($('filleul'+i).value!=''){
				if(!verifMail('inscription','filleul'+i)){myalert=new alertbox({focusel:'filleul'+i});focusblur($('filleul'+i));$('filleul'+i).select();myalert.alert("Invalid e-mail. Please seize again it");return (false);};
			}
		}
	}
    */
	//if(d.parrain_client.value=="L'email de votre parrain")d.parrain_client.value="";
	if(d.mention.checked==false){d.mention.select();myalert=new alertbox({focusel:'mention'});focusblur(d.mention);myalert.alert("You must accept the sale terms.");return (false);}
	$('date_client').value = $('s_annee_date_client').value+"-"+$('s_mois_date_client').value+"-"+$('s_jour_date_client').value;
	return true;
}
function file(fichier){
	if(window.XMLHttpRequest)				// FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject)			// IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);
	xhr_object.open("GET", fichier, false);
	xhr_object.send(null);
	if(xhr_object.readyState == 4) return(xhr_object.responseText);
	else return(false);
}
function resetColor(){
	var d=$("inscription");
}
