function valVacios(nombre, email, email1, phone)
{  
	bandera = false
	if (nombre == ""){
	//alert('Los datos * son obligatorios')
		document.getElementById('nameRequired').style.display = 'block';
		bandera = false
	}  
	if (phone == ""){
		document.getElementById('phoneRequired').style.display = 'block';
		bandera = false
	}
	if (email == ""){
		document.getElementById('emailRequired').style.display = 'block';
		bandera = false
	}
	if (nombre != ""){
		document.getElementById('nameRequired').style.display = 'none';
		if (phone != ""){
			document.getElementById('phoneRequired').style.display = 'none';
			if (email != ""){
				document.getElementById('emailRequired').style.display = 'none';
				bandera = true
			}
		}
	}
return bandera
}

function validarPhone(phone)
{
	band = false
	
	if( phone.length < 10 ) {
	  	document.getElementById('phoneInvalid').style.display = 'block';
		band = false
	}
	else{
		document.getElementById('phoneInvalid').style.display = 'none';
		
		switch(phone.length){
			case 10:
				if( !(/^\d{10}$/.test(phone)) ){
					document.getElementById('phoneNotvalid').style.display = 'block';
					band = false
				}
				else{
					document.getElementById('phoneNotvalid').style.display = 'none';
					band = true
				}
				break;
			case 11:
			  	if( !(/^\d{11}$/.test(phone)) ){
					document.getElementById('phoneNotvalid').style.display = 'block';
					band = false
				}
				else{
					document.getElementById('phoneNotvalid').style.display = 'none';
					band = true
				}
				break;
			case 12:
			  	if( !(/^\d{12}$/.test(phone)) ){
					document.getElementById('phoneNotvalid').style.display = 'block';
					band = false
				}
				else{
					document.getElementById('phoneNotvalid').style.display = 'none';
					band = true
				}
				break;
			case 13:
			  	if( !(/^\d{13}$/.test(phone)) ){
					document.getElementById('phoneNotvalid').style.display = 'block';
					band = false
				}
				else{
					document.getElementById('phoneNotvalid').style.display = 'none';
					band = true
				}
				break;
			case 14:
			  	if( !(/^\d{14}$/.test(phone)) ){
					document.getElementById('phoneNotvalid').style.display = 'block';
					band = false
				}
				else{
					document.getElementById('phoneNotvalid').style.display = 'none';
					band = true
				}
				break;
			case 15:
			  	if( !(/^\d{15}$/.test(phone)) ){
					document.getElementById('phoneNotvalid').style.display = 'block';
					band = false
				}
				else{
					document.getElementById('phoneNotvalid').style.display = 'none';
					band = true
				}
				break;
			case 16:
			  if( !(/^\d{16}$/.test(phone)) ){
					document.getElementById('phoneNotvalid').style.display = 'block';
					band = false
				}
				else{
					document.getElementById('phoneNotvalid').style.display = 'none';
					band = true
				}
				break;
			default:
				band = false
		}
		
	}
	return band
}

function valEmail(email)
{    
    bandera1 = false
    var re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    if (!re.test(email)){
    	document.getElementById('emailNoValido').style.display = 'block';
    	bandera1 = false
    }
    else{
    	document.getElementById('emailNoValido').style.display = 'none';
    	bandera1 = true
    }
return bandera1
}

function comparaEmail(email1, email2)
{
    bandera2 = false
    if (email1 != email2){
        document.getElementById('emailDiferentes').style.display = 'block';
        bandera2 = false
    }
    else {
        document.getElementById('emailDiferentes').style.display = 'none';
        bandera2 = true
    }
return bandera2
}

//Funcion Valida los datos del formulario
function validar(name, email1, email2, phone)
{
	
	valVacios(name, email1, email2, phone)
	if (bandera){
		validarPhone(phone)
		if (band){
			valEmail(email1)
			if (bandera1){
				comparaEmail(email1, email2)
				if (bandera2 & bandera & bandera1 & band){
					return true
				}
				else {
					return false
				}
			}
			else {return false}
		}
		else {return false}
	}
	else{
		return false
	}
}

//*** Este Codigo permite Validar que sea un campo Numerico
function Solo_Numerico(variable)
{	
    Numer=parseInt(variable);
    if (isNaN(Numer)){
        return "";
    }
return Numer;
}
    		
function valNumero(Control, countfield){
    //Control.value=Solo_Numerico(Control.value);
    validar_tenDigits(Control);
    phoneCounter(Control, countfield);
}

//Valida que se cumpla con el criterio de 10 digitos en el campo del telefono
function validar_tenDigits(phone)
{	
	//alert(phone.value.length);
	if (phone.value.length < 10) {
		document.getElementById('phoneTen').style.display = '';
		//alert('Cumple < 10, se muestra el texto <span>');
	}
	else
	{
		document.getElementById('phoneTen').style.display = 'none';
		//alert('No cumple, se oculta el texto <span>');
	}

}

function phoneCounter(phone, countfield)
{
	if (phone.value.length > 10)
	{
		phone.value = phone.value.substring(0, 16);
	}
	else
	{
		countfield.value = 10 - phone.value.length;
	}
}
