//PRUEBA
function agregar_alert(campo, alerta, len){
	
	
	if(len == 1)
		var texto =  "Debe completar los campos obligatorios.";
	
	if(len == 2)
		var texto = "You must complete the required fields.";
	
	if(len == 3)
		var texto = "Voc\xEA deve completar os campos obrigat\xF3rios.";

    if(campo.value=="")
        alerta = texto;
    
	

    return alerta;
  
}


function validar_campos(){
    var alerta  = "";



 	var len = document.getElementById('len').value;
	
	var nombre = document.getElementById('visitorname');
    alerta = agregar_alert(nombre, alerta, len);
	
	var apellido = document.getElementById('visitorsurname');
    alerta = agregar_alert(apellido, alerta, len);
	  
	  
	  
	var notas = document.getElementById('notes');
    alerta = agregar_alert(notas, alerta, len);
	  

	var email = document.getElementById('visitormail');
    alerta = validar_email(email, alerta, len);
    
 

	if(alerta==""){
		document.formu.submit();
        return true;
 		}
	else{
        alert(alerta);
        return false;
 		}
	
}
	
	
function validar_email(campo, alerta, len){
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   
   	if (!filter.test(campo.value) ) {
		
		if(len == 1)
			var alerta =  "Por favor ingrese un email v\xE1lido.\n";
	
		if(len == 2)
			var alerta = "Please enter a valid email.\n";
	
		if(len == 3)
			var alerta = "Por favor insira um email v\xE1lido.\n";
		
				
           
        }
        
        return alerta;
}    
    
function validar_igualdad_email(email, v_email, alerta){
	if(email.value!=v_email.value){
		alerta+= "No coincide la validacion del mail \n";
	}
	return alerta;
}


function verificar_numerico(campo, minimo, nombre ,alerta){

    if(campo.value=="" || campo.value.length < minimo){
        alerta += "El campo "+ nombre +" es obligatorio ("+minimo+" digitos)\n";

    }else{
        if(isNaN(campo.value)){
            alerta += "El campo "+ nombre + " debe ser numerico \n";
         }
    }

    return alerta;
}
// ---------------------------------------------------
//  HABILITA / DESHABILITA LIST DE CIUDADES Y ESTADOS
// --------------------------------------------------- 

function activa(){

	var valorpais = document.getElementById("pais");
	var txtpais   = valorpais.options[valorpais.selectedIndex].text;
	
	//alert(txtpais);
	
	//funciona
	//document.getElementById('estado').disabled=false;
	
	
	if(txtpais == "Mexico"){
		document.getElementById('estado_geografico').disabled=false;
		document.getElementById('ciudad').disabled=false;
		}
	else{
		document.getElementById('estado_geografico').disabled=true;
		document.getElementById('ciudad').disabled=true;
	}
}

/*
function bloquea(){
	document.getElementById('estado').disabled=true;
	document.getElementById('ciudad').disabled=true;
	{
*/








function recarga(){

	//var fomulario = document.form1;

	var nombre = document.getElementById('nombre');
    var apellido = document.getElementById('apellido');

	var lada_telefono = document.getElementById('lada_telefono');
	var telefono = document.getElementById('telefono');
    
	var proveedor_celular = document.getElementById("proveedor_celular");
	var procel = proveedor_celular.options[proveedor_celular.selectedIndex].text;
	
	
	var lada_celular = document.getElementById('lada_celular');
	var celular = document.getElementById('celular');

	var ciudad = document.getElementById("ciudad");
	var valorciudad = ciudad.options[ciudad.selectedIndex].value;

	var pais = document.getElementById("pais");
	var valorpais = pais.options[pais.selectedIndex].value;

	var email = document.getElementById('email');
    var v_email = document.getElementById('email2');
    var clave = document.getElementById('clave');

	var estado = document.getElementById("estado_geografico");
	var valestado = estado.options[estado.selectedIndex].value;

	var pais = document.getElementById("pais");
	var valpais = pais.options[pais.selectedIndex].text;
	
	//alert(valpais);

	var nuevo_action = 'formulario.php?nombre=' + nombre.value + '&apellido=' + apellido.value + '&lada_telefono=' + lada_telefono.value + '&telefono=' + telefono.value + '&procel=' + procel + '&lada_celular=' + lada_celular.value + '&celular=' + celular.value + '&ciudad=' + valorciudad.value + '&email=' + email.value + '&email2=' + v_email.value + '&clave=' + clave.value + '&id_est=' + valestado + '&pais=' + valpais;

	location.href=nuevo_action;


}
