
//----------------------------------------------------------------------------|
//             FUNCIN QUE VALIDA EL FORMULARIO DE CONTACTANOS                 |
//----------------------------------------------------------------------------|
var prefijo = "ctl00_ContentPlaceHolder1_";
function whiteControls(control)
{
    control = prefijo + control;
	if(document.getElementById(control).value == "Campo obligatorio" || document.getElementById(control).value == "formato: nombre@dominio.sub" ||  document.getElementById(control).value == "Sólo numeros" || document.getElementById(control).value == "desde" || document.getElementById(control).value == "Hasta"  )
	document.getElementById(control).value = "";
	document.getElementById(control).style.backgroundColor='white';
	document.getElementById(control).style.color='black';
	document.getElementById(control).className="tdpersona";
		
}
function onbluresTexto(control)
{
    var cont = prefijo + control;
			document.getElementById(cont).style.backgroundColor='white';
			document.getElementById(cont).style.color='black';
			document.getElementById(cont).className="tdpersona";
			document.getElementById(prefijo + "lblErrors").innerHTML = "";
}

function onblurOptions()
{
    document.getElementById(prefijo + "lblErrors").innerHTML = "";
}

function validarContactanos()
{
	
var validaMail = /^[0-9a-zA-Z]([0-9a-zA-Z\._-]{0,30})([0-9a-zA-Z]{1})@([0-9a-zA-Z]{1})([0-9a-zA-Z\._-]{1,15})(\.[0-9a-zA-Z]{2,3})$/;
	
			var Nombres = ""
		var Etiquetas = ""
		var Errores = ""
		var j = 0	
		Etiquetas = "txtNombre|txtApellidos|txtEmail|txtMovil|txtNumDormitorios|txtDesde|txtHasta"
		Nombres = Nombres.split("|")
		Etiquetas = Etiquetas.split("|")
		
		
	for (j=0;j<Etiquetas.length;j++)
	{
	    if (document.getElementById(prefijo + Etiquetas[j]).value == "" || document.getElementById(prefijo+Etiquetas[j]).value == "Campo obligatorio")
		{
		    document.getElementById(prefijo+Etiquetas[j]).style.backgroundColor = '#faf5c2';
		    document.getElementById(prefijo + Etiquetas[j]).style.color = "#FF0000";
		    document.getElementById(prefijo + Etiquetas[j]).value = "Campo obligatorio";
		    document.getElementById(prefijo + Etiquetas[j]).focus();
			return false;	
		}				
	}
	
	for (i=0;i<Etiquetas.length;i++ )
	{
	    if (Errores != "" && document.getElementById(prefijo + Etiquetas[i]).value == "")	
		{
		    document.getElementById(prefijo + Etiquetas[i]).value = "Campo obligatorio";
		    document.getElementById(prefijo + Etiquetas[i]).focus();
		    document.getElementById(prefijo + Etiquetas[i]).style.backgroundColor = '#faf5c2';
			//document.getElementById("div_"+ parseInt(i+1)).style.backgroundColor='#fcf69a';
		    document.getElementById(prefijo + Etiquetas[i]).style.color = "#FF0000"; 
			return false;				
		}
		if (i == 2 && document.getElementById(prefijo + Etiquetas[i]).value != "")	
		{
		    if (!validaMail.test(document.getElementById(prefijo + Etiquetas[i]).value))						
				{
				    document.getElementById(prefijo + Etiquetas[i]).value = "formato: nombre@dominio.sub";
				    document.getElementById(prefijo + Etiquetas[i]).focus();
				    document.getElementById(prefijo + Etiquetas[i]).style.backgroundColor = '#faf5c2';
				    document.getElementById(prefijo + Etiquetas[i]).style.color = "#FF0000"; 
				return false;	
				}	 
		}
	}



	if (objAPY.radioCheckValue(prefijo + "cblProducto", false).length == 0)
	{
	    document.getElementById(prefijo + "lblErrors").innerHTML = "Seleccione al menos un tipo de vivienda.";
		return false;
	}
	
	
	
/*	
	//Validamos que se teclee el nombre del contacto
	if (objAPY.Trim(document.getElementById('txtNombre').value).length==0 )
	{
		alert("Teclee su nombre por favor.");
		document.getElementById('txtNombre').focus();
		return false;
	}
	
	//Validamos que se teclee sus apellidos
	if (objAPY.Trim(document.getElementById('txtApellidos').value).length==0 )
	{
		alert("Por favor teclee sus apellidos.");
		document.getElementById('txtApellidos').focus();
		return false;
	}
	
	//Validamos que se teclee el mail del contacto
	if (objAPY.Trim(document.getElementById('txtEmail').value).length==0 )
	{
		alert("Teclee su dirección de correo electrónico.");
		document.getElementById('txtEmail').focus();
		return false;
	}
	
	
	if(!objAPY.validaEmail(document.getElementById('txtEmail').value))
	{
		alert("El formato del e-mail es incorrecto.");
		document.getElementById('txtEmail').focus();
		return false;
	}
	
	//Validamos que seleccione al menos un producto
	if(objAPY.radioCheckValue("cblProducto", false).length==0)
	{
		alert("Pro favor seleccione al menos un producto de la lista.");
		return false;
	}
	
	//Validamos que seleccione al menos un tipo de apartamento
	if(objAPY.radioCheckValue("cblDormitorios", false).length==0)
	{
		alert("Pro favor seleccione al menos un tipo de apartamento de la lista.");
		return false;
	}
	
	//Validamos que seleccione al menos un producto
	if(objAPY.radioCheckValue("rblPrecios", true).length==0)
	{
		alert("Pro favor seleccione al menos un precio de la lista.");
		return false;
	}*/
	
	//Si todas las validaciones son correctas, entonces regresamos verdadero
	return true;
}

//----------------------------------------------------------------------------|
//             FUNCION QUE GUARDA DATOS EN EL FORMULARIO RESPECTIVO           |
//----------------------------------------------------------------------------|
function guardarDatosFormulario(frmNombre)
{
	var frmValidado;
	switch(frmNombre)
	{
		case "Contactanos":				frmValidado = validarContactanos();				break;
	}

	if (frmValidado)
		document.forms[0].submit();
		//__doPostBack('btnGuardarNet','');
}

function validaNumeros(numero){
    if (!/^([0-9])*$/.test(numero)){
		alert("N\xfamero no v\xe1lido");
      }
  }
