function testObligatoire(champ){
	zap_list = new Array("adresse","prenom","ville","fax");
	for (n=0;n<zap_list.length;n++){
		if (zap_list[n]==champ){
			return false;
		}	
	}
	return true;
}

function Check(id){
myForm = document.getElementById(id);
	ret = true;
	for (i=0;i<myForm.elements.length;i++){
		champ = myForm.elements.item(i);
		tag = champ.tagName ;
		test =champ.name ;
		zap =   test.substring(0,test.indexOf('_o'));
		//alert(test + ' ' + test.indexOf('_o') + ' ' + zap + ' ' + testObligatoire(zap));
		if ((test.indexOf('_o')> 0)&&(testObligatoire(zap))){
			current = champ.name;
			switch (tag){
				case "INPUT" :
					if (champ.value.length == 0){
						writetag('error_'+champ.id, '<span class="erreur">Champ obligatoire</span>');
						ret = false;
					}
					else {
						if(test=="mail_o" || test=="email_o"){
							if (champ.value.length > 0 && !verifEmail(champ)) {
								ret = false;
							}
						}
						else {					
							writetag('error_'+champ.id, '<span class="obligatoire">Champ obligatoire</span>');
						}
					}
					break;
				case "TEXTAREA" :
					if (champ.value.length == 0){
						writetag('error_'+champ.id, '<span class="erreur">Champ obligatoire</span>');
						ret = false;
					}
					else {
						writetag('error_'+champ.id, '<span class="obligatoire">Champ obligatoire</span>');
					}
					break;
				case  "SELECT" :
					if(champ.options[champ.selectedIndex].value =='0' || champ.options[champ.selectedIndex].value =='-1'){
						writetag('error_'+champ.id, '<span class="erreur">Champ obligatoire</span>');
						ret = false;
					}else writetag('error_'+champ.id, '<span class="obligatoire">Champ obligatoire</span>');
					break;
				}
			}
		}
	//if (ret == true) alert ('partie ...');
	//else ('pas partie ...');
	//ret = false;
	return ret;
}


function check_devis(id){
	writetag('error_general', '');
	myForm = document.getElementById(id);
	ret = true;
	var list_erreur = '';
	var nom_champ_tmp = '';
	for (i=0;i<myForm.elements.length;i++){
		champ = myForm.elements.item(i);
		tag = champ.tagName ;
		test =champ.name ;
		if (test.indexOf('_o')> 0){
			writetag('error_'+champ.id, '');
			current = champ.name;
			switch (tag){
				case "INPUT" :
					if (champ.value.length == 0){						
						if (test=="nom_o")		nom_champ_tmp = 'nom';
						if (test=="prenom_o")	nom_champ_tmp = 'pr&eacute;nom';
						if (test=="email_o")	nom_champ_tmp = 'email';
						if (test=="society_o")	nom_champ_tmp = 'societ&eacute;';
						if (test=="adresse_o")	nom_champ_tmp = 'adresse';
						if (test=="cp_o")		nom_champ_tmp = 'code postal';
						if (test=="ville_o")	nom_champ_tmp = 'ville';
						writetag('error_'+champ.id, '<span class="erreur"><img src="images/expo/croix.gif" alt="Veuillez remplir le champ" /> Veuillez remplir le champ '+nom_champ_tmp+'</span>');
						if (ret==false)list_erreur = list_erreur+', ';												
						list_erreur = list_erreur+nom_champ_tmp;
						ret = false;
					}
					else {
						if(test=="mail_o" || test=="email_o"){
							if (champ.value.length > 0 && !verifEmail(champ)) {
								if (ret==false)list_erreur = list_erreur+', ';												
								list_erreur = list_erreur+'email';
								ret = false;
							}
						}
						else {					
							writetag('error_'+champ.id, '');
						}
						
						if (test=="cp_o"){							
							if (document.getElementById('pays_o').value == 47 ){
								if (isNaN(champ.value)){
									if (ret==false)list_erreur = list_erreur+', ';												
									list_erreur = list_erreur+'code postal';
									writetag('error_cp_o', '<span class="erreur"><img src="images/expo/croix.gif" alt="Veuillez remplir le champ" /> Votre code postal est invalide</span>');
									ret = false;
								}else if(champ.value.length != '5'){
									if (ret==false)list_erreur = list_erreur+', ';												
									list_erreur = list_erreur+'code postal';
									writetag('error_cp_o', '<span class="erreur"><img src="images/expo/croix.gif" alt="Veuillez remplir le champ" /> Votre code postal est invalide</span>');
									ret = false;			
								}
							}
						}
		
					}
					break;
				
				case  "SELECT" :
					if(champ.options[champ.selectedIndex].value =='' || champ.options[champ.selectedIndex].value =='-1'){		
								
						if (test=="civ_o")	nom_champ_tmp = 'civilit&eacute;';
						if (test=="pays_o") nom_champ_tmp = 'pays';
						if (test=="etat_pays_o") nom_champ_tmp = 'etat';				
						if (ret==false)list_erreur = list_erreur+', ';												
						list_erreur = list_erreur+nom_champ_tmp;
						writetag('error_'+champ.id, '<span class="erreur"><img src="images/expo/croix.gif" alt="Veuillez remplir le champ" /> Veuillez remplir le champ '+nom_champ_tmp+'</span>');
						ret = false;
					}
					break;
			}
		}
	}
	
	if (ret==false) writetag('error_general', '<span class="erreur"><img src="images/expo/exclamation-b0101f.gif" alt="" /> Veuillez correctement remplir les champs '+list_erreur+'</span>');
	
	if (ret && !(document.getElementById('information1').checked || document.getElementById('information2').checked)) {
		ret= false;
		alert('Veuillez choisir de recevoir ou non des offres promotionnelles sur votre adresse e-mail!') ;			
	}

	
	if (ret && !myForm.condition.checked){
		ret= false;
		alert('Vous devez accepter les Conditions Générales de Vente pour valider votre demande !');
	}	
	
	return ret; 
}

function check_email() {
	if (xmlhttp_check_email.readyState==4) {
		if (xmlhttp_check_email.status==200) {
			writetag('error_email_o', xmlhttp_check_email.responseText);
		} 
		else {
			/*alert("Problem retrieving XML data on check_email(),statut : "+xmlhttp_check_email.status);*/
		}
	}
	else
		writetag('error_email_o', '<div class="erreur"><img src=\"images/loading.gif\" alt=\"En cours\" width=\"15\" />En cours...</div>');
	
}

var xmlhttp_check_email;

function verifEmail(email) {
	if (email.value.length == 0) {
		return false;
	}
	writetag('error_'+email.id, '');
	xmlhttp_check_email = createXMLHttpRequest();
	if (xmlhttp_check_email!=null) {
			xmlhttp_check_email.onreadystatechange = check_email;
			xmlhttp_check_email.open("GET",'/expo/?p=10&sp=13&email='+escape(email.value),true);
			xmlhttp_check_email.send(null);
	}
	var modele = /^[a-z0-9\-_\.]+@[a-z0-9.-]{2,}[.][a-z]{2,5}$/i;
	if (!modele.test(email.value)){
		return false;
	}
	return true;
}


function displayCountryState() {
	if (xmlhttp_lcs.readyState == 4) {
		if (xmlhttp_lcs.status == 200) {
			writetag('country_state_list', xmlhttp_lcs.responseText);
			if (xmlhttp_lcs.responseText!='') {
			document.getElementById('country_state_list').style.display = 'block';
			} else {
			document.getElementById('country_state_list').style.display = 'none';
			}
		} 
		else {
			/*alert("Problem retrieving XML data on ***,statut : "+xmlhttp_lcs.status);*/
		}
	}
	else {
		writetag('country_state_list', '<img src=\"images/loading.gif\" alt=\"En cours\" width=\"15\" />En cours...');
	}
}

function loadCountryState(id_country,id_etat) {
	if (id_etat!=null) {
		var req_etat = '&id_etat='+id_etat;
		} else {
		var req_etat = '';
		}
		
	xmlhttp_lcs = createXMLHttpRequest();
	if (xmlhttp_lcs!=null) {	
			xmlhttp_lcs.onreadystatechange = displayCountryState;
			xmlhttp_lcs.open("GET",'/expo/?p=10&sp=22&id_country='+id_country+req_etat);
			xmlhttp_lcs.send(null);
	}
}

function loadCountryState19(id_country,id_etat) {
	if (id_etat!=null) {
		var req_etat = '&id_etat='+id_etat;
		} else {
		var req_etat = '';
		}

	xmlhttp_lcs = createXMLHttpRequest();
	if (xmlhttp_lcs!=null) {	
			xmlhttp_lcs.onreadystatechange = displayCountryState;
			xmlhttp_lcs.open("GET",'/expo/?p=19&sp=3&id_country='+id_country+req_etat);
			xmlhttp_lcs.send(null);
	}
}


