//validar correo
function validarEmail(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
    return (true);
  } else {  
    return (false);
  }
}

function Validar_passw(){

	if(document.frm_pass.txt_emailconf.value==""){
  		alert("Le champ email est obligatoire");
 		document.frm_pass.txt_emailconf.focus();
 		return false;
 	}
 
 
 	if(validarEmail(document.frm_pass.txt_emailconf.value))
	{
	   //return (true);
	}else{
		alert("Ingrese Email Correcto")
		document.frm_pass.txt_emailconf.focus();
		return(false);
	}
	
	document.frm_pass.submit();
	
}
function validaPrix(){

		if(document.formNewPrix.txtSucri.value==0){
		alert("Le champ Libellé est obligatoire");
		document.formNewPrix.txtSucri.focus();
		return false;
		}
		if(document.formNewPrix.txtPrecioHT.value==""){
		alert("Le champ Prix HT est obligatoire");
		document.formNewPrix.txtPrecioHT.focus();
		return false;
		}
		if(document.formNewPrix.txtPrecio.value==""){
		alert("Le champ Prix TTC est obligatoire");
		document.formNewPrix.txtPrecio.focus();
		return false;
		}
		if(document.formNewPrix.txtPeriodo.value==""){
		alert("Le champ Mois est obligatoire");
		document.formNewPrix.txtPeriodo.focus();
		return false;
		}
	}
	
function validarNumero(e){
tecla_codigo = (document.all) ? e.keyCode : e.which;
if(tecla_codigo==8)return true;
patron =/[0-9\-]/;
tecla_valor = String.fromCharCode(tecla_codigo);
return patron.test(tecla_valor);
}

function validarNumero2(e){
tecla_codigo = (document.all) ? e.keyCode : e.which;
if(tecla_codigo==8)return true;
patron =/[0-9.]/;
tecla_valor = String.fromCharCode(tecla_codigo);
return patron.test(tecla_valor);
}

function validaEnterprise(){
		valorweb=document.formNewReg.web.value;
		especial=document.formNewReg.especial.value;
		/*if(document.formNewReg.cboFonction.value==0){
		alert("Le champ Fonction est obligatoire");
		document.formNewReg.cboFonction.focus();
		return false;
		}*/
		/*if(document.formNewReg.cboActividad.value==0){
		alert("Le champ Activity est obligatoire");
		document.formNewReg.cboActividad.focus();
		return false;
		}*/
		/*if(document.formNewReg.cboRegion.value==0){
		alert("Le champ Region est obligatoire");
		document.formNewReg.cboRegion.focus();
		return false;
		}*/
		/*txtN="txtName";
		text=document.getElementById("txtName").value + "," + txtN;*/
		if(document.formNewReg.txtName.value==""){
		alert("Le champ Nom est obligatoire");
		document.formNewReg.txtName.focus();
		return false;
		}/*else if(document.formNewReg.txtName.value!=""){
			alert(document.formNewReg.txtName.value);
			jsrsExecute("./include/validate_text.php",end_validate_text,"confirmar",text);
			}*/
			
		/*txtA="txtAdress";
		textA=document.getElementById("txtAdress").value + "," + txtA;*/
		/*if(document.formNewReg.txtAdress.value==""){
		alert("Le champ Address est obligatoire");
		document.formNewReg.txtAdress.focus();
		return false;
		}*//*else if(document.formNewReg.txtAdress.value!=""){
			alert(document.formNewReg.txtAdress.value);
			jsrsExecute("./include/validate_text.php",end_validate_text,"confirmar",textA);
			}*/
		/*if(document.formNewReg.txtAdress2.value==""){
		alert("ingrese Address2");
		document.formNewReg.txtAdress2.focus();
		return false;
		}*/
		if(especial==1){
				if(document.formNewReg.descripcion.value==""){
					alert("Le champ Description est obligatoire");
					document.formNewReg.descripcion.focus();
					return false;
				}	
		}
		
		if(document.formNewReg.txtVille.value==""){
		alert("Le champ Ville est obligatoire");
		document.formNewReg.txtVille.focus();
		return false;
		}
		/*if(document.formNewReg.txtTel.value==""){
		alert("Le champ Telephone est obligatoire");
		document.formNewReg.txtTel.focus();
		return false;
		}*/
		if(document.formNewReg.cboActividad.value==""){
		alert("Le champ Activité est obligatoire");
		document.formNewReg.cboActividad.focus();
		return false;
		}
		
		
		//cpostal=document.getElementById("txtCodpost").value;
		cpostal=document.formNewReg.txtCodpost.value;
		
		if(document.formNewReg.txtCodpost.value==""){
		alert("Le champ Code Postal est obligatoire");
		//alert("asdsadasdsa");
		document.formNewReg.txtCodpost.focus();
		return false;
		}else if(document.formNewReg.txtCodpost.value.length <5){
			
			alert("Code postal incorrect!");
			document.getElementById("txtCodpost").select();
			return false;
		}else{
				if(valorweb==1){
     				jsrsExecute("./include/validate_cpostal.php",end_validate_cpostal,"confirmar",cpostal);
				}else{
					//alert('hola');
					//alert(cpostal);
					jsrsExecute("../../../include/validate_cpostal.php",end_validate_cpostal,"confirmar",cpostal);	
				}
  		}
		
		/*textName=document.getElementById("txtName").value;
		textAd=document.getElementById("txtAdress").value;
		textVi=document.getElementById("txtVille").value;
		textEf=document.getElementById("txtEff").value;
		textAc=document.getElementById("cboActividad").value;
		cadena=textName+","+textAd+","+textVi+","+textEf+","+textAc;
		//cadena=textName + textAd + textVi + textEf + textAc
		alert(cadena);
		if(cadena!=""){
			jsrsExecute("./include/validate_text.php",end_validate_text,"confirmar",cadena);
		}*/
		//document.formNewReg.submit();
	}

/*function validate_cpostal(ruta){
		if(ruta==1){
			jsrsExecute("./include/validate_cpostal.php",end_validate_cpostal,"confirmar",cpostal);
		}else{
			jsrsExecute("../../include/validate_cpostal.php",end_validate_cpostal,"confirmar",cpostal);	
		}
}*/

function validaContact(){
	
		if(document.formcontact.cboCivilite.value==0){
		alert("Le champ Civilite est obligatoire");
		document.formcontact.cboCivilite.focus();
		return false;
		}
		
		/*if(document.formcontact.cboLanguage.value==0){
		alert("Le champ Language est obligatoire");
		document.formcontact.cboLanguage.focus();
		return false;
		}*/
		
		if(document.formcontact.txtName.value==""){
		alert("Le champ Nom est obligatoire");
		document.formcontact.txtName.focus();
		return false;
		}
		if(document.formcontact.txtLastname.value==""){
		alert("Le champ Prenom est obligatoire");
		document.formcontact.txtLastname.focus();
		return false;
		}
		if(document.formcontact.txtTel.value==""){
		alert("Le champ Telephone est obligatoire");
		document.formcontact.txtTel.focus();
		return false;
		}
		
		if(document.formcontact.cboFonction.value==0){
		alert("Le champ Fonction est obligatoire");
		document.formcontact.cboFonction.focus();
		return false;
		}
		
		
		if(document.formcontact.txtEmail.value==""){
		alert("Le champ Email est obligatoire");
		document.formcontact.txtEmail.focus();
		return false;
		}
		if(document.formcontact.txtEmail1.value==""){
		alert("Le champ Conf. Email est obligatoire");
		document.formcontact.txtEmail1.focus();
		return false;
		}
		if(document.formcontact.txtPass.value==0){
		alert("Le champ Mot de passe est obligatoire");
		document.formcontact.txtPass.focus();
		return false;
		}
		if(document.formcontact.txtPass1.value==0){
		alert("Le champ Conf. Mot de passe est obligatoire");
		document.formcontact.txtPass1.focus();
		return false;
		}
		
		if(validarEmail(document.formcontact.txtEmail.value)){
			//return true;
			}else{
				alert("Le champ Email correct");
				document.formcontact.txtEmail.focus();
				return false;
				}
		if(validarEmail(document.formcontact.txtEmail1.value)){
			//return true;
			}else{
				alert("Le champ Email correct");
				document.formcontact.txtEmail1.focus();
				return false;
				}
		if(document.formcontact.txtEmail.value!=document.formcontact.txtEmail1.value){
				alert("Le champ Email correct");
				document.formcontact.txtEmail1.focus();
				return false;
			}
		if(document.formcontact.txtPass.value!=document.formcontact.txtPass1.value){
				alert("Le champ Conf. Mot de Passe correct");
				document.formcontact.txtPass1.focus();
				return false;
			}
				
		
}
function end_validate_text(vari){
		vari=vari.split(",");
		ok=vari[0];
		txtVar=vari[1];
		
		form=document.formNewReg;
		if(ok==1){
			alert("text incorrect!");
			if(txtVar==0){
					txtName=txtVar
					document.getElementById("txtName").select();
			}else if(txtVar==1){
					txtAdress=txtVar
					document.getElementById("txtAdress").select();
			}else if(txtVar==2){
					txtVille=txtVar
					document.getElementById("txtVille").select();
			}else if(txtVar==3){
					txtEff=txtVar
					document.getElementById("txtEff").select();
			}else if(txtVar==3){
					cboActividad=txtVar
					document.getElementById("cboActividad").select();
			}
			//document.getElementById("txtName").select();
			return false;
			
		}else{
			form.submit();
		}	
}
function end_validate_cpostal(ok){
		form=document.formNewReg;
		//cpostal=document.getElementById("txtCodpost").value;
		if(ok==1){
			//form.action="include/process_annuaire.php";
			form.submit();
		}else{
			alert("Code postal incorrect!");
			//document.formNewReg.txtCodpost.select();
			document.getElementById("txtCodpost").select();
			return false;
		}
}
//funcion q permite validar q l 2caracter sea letra
function validarAlphanumerico(e,comodin){
	tecla = (document.all) ? e.keyCode : e.which;
	if(comodin==1){
		//ajouter_enterprise.php
		cpostal="txtCodpost";
	}else if(comodin==2){
		cpostal="txtCpostal";
	}
		
	if(document.getElementById(cpostal).value.length==0){
	if ((tecla>=48 && tecla<=57) || (tecla==8)) return true;
	alfa = /[A-Z]\D/; 
	text = String.fromCharCode(tecla);	
	return alfa.test(text);
	}else if(document.getElementById(cpostal).value.length==1){
			
			if ((tecla>=65 && tecla<=122) || (tecla>=48 && tecla<=57)) return true;
			alfa = /[A-Z]\D/; 
			text = String.fromCharCode(tecla);	
			return alfa.test(text);
			
	}else if(document.getElementById(cpostal).value.length==2){
			if (tecla>=48 && tecla<=57) return true;
				alfa = /[A-Z]\D/; 
				text = String.fromCharCode(tecla);	
				return alfa.test(text);
	}else if(document.getElementById(cpostal).value.length==3){
			if (tecla>=48 && tecla<=57) return true;
				alfa = /[A-Z]\D/; 
				text = String.fromCharCode(tecla);	
				return alfa.test(text);
	}else if(document.getElementById(cpostal).value.length==4){
			if (tecla>=48 && tecla<=57) return true;
				alfa = /[A-Z]\D/; 
				text = String.fromCharCode(tecla);	
				return alfa.test(text);
	}
	
}

function validate_code_numeric_admin(e,valor){
	tecla = (document.all) ? e.keyCode : e.which;
	if(valor==1){
		cpostal="txtTel";
	}else{
		cpostal="txtFax";	
	}
	
	if(document.getElementById(cpostal).value.length>=0){
	if ((tecla>=48 && tecla<=57) || (tecla==8)) return true;
	alfa = /[A-Z]\D/; 
	text = String.fromCharCode(tecla);	
	return alfa.test(text);
	}
}