// JavaScript Document
	//FUNCIONES ENCARGADAS DE LAS VALIDACIONES DE CAMPO
	
	
	function Trim(string) 
	{ 
	return string.replace(/(^\s*)|(\s*$)/g,''); 
	} 



	function ValidarBusq(form){
	patron=/^[0-9]*$/;
	if(isNaN(parseInt(form.PrecioMinimo.value)) || patron.test(form.PrecioMinimo.value)==0){
	alert('Write a number');
	form.PrecioMinimo.focus();return;
	}
	if(isNaN(parseInt(form.PrecioMaximo.value)) || patron.test(form.PrecioMaximo.value)==0){
	alert('Write a number');
	form.PrecioMaximo.focus();return;
	}
	
  
	form.submit();
  }

	function ValidarMember(form)
	{
	if (form.Nombre.value == "")
	{ alert("Please, enter your Name"); form.Nombre.focus(); return; }
	if (form.Titulo.value == "")
	{ alert("Please, enter the Title"); form.Titulo.focus(); return; }
	if (form.Agente.value == "")
	{ alert("Please, select an Agent"); form.Agente.focus(); return; }
	if (form.Email.value.indexOf('@', 0) == -1 ||
	form.Email.value.indexOf('.', 0) == -1)
	{ alert("Invalid E-mail"); form.Email.focus(); return; }
	form.submit();
	}
	
	
	function Validar(form)
	{
	if (Trim(form.Nombre.value) == "")
	{ alert("Please, enter the Name of the Property"); form.Nombre.focus(); return false; }
	if (Trim(form.Titulo.value) == "")
	{ alert("Please, enter the Title of the Property"); form.Titulo.focus(); return false; }
	if (Trim(form.Codigo.value) == "")
	{ alert("Please, enter the MLS#"); form.Codigo.focus(); return false; }
	if (Trim(form.DescripcionPeq.value) == "")
	{ alert("Please, enter the Brief Description of the Property"); form.DescripcionPeq.focus(); return false; }
	if (Trim(form.Ubicacion.value) == "")
	{ alert("Please, enter the Address of the Property"); form.Ubicacion.focus(); return false; }
	if (Trim(form.Tipo.value) == "")
	{ alert("Please, enter the Type of Property"); form.Tipo.focus(); return false; }
	if (Trim(form.Precio.value) == "")
	{ alert("Please, enter the Price of Property"); form.Precio.focus(); return false; }
	if (Trim(form.AreaTerreno.value) == "")
	{ alert("Please, enter the Square Feet of Property"); form.AreaTerreno.focus(); return false; }
	if (Trim(form.CantidadBanos.value) == "")
	{ alert("Please, enter the Bathrooms of Property"); form.CantidadBanos.focus(); return false; }
	if (Trim(form.CantidadCuartos.value) == "")
	{ alert("Please, enter the Bedrooms of Property"); form.CantidadCuartos.focus(); return false; }
	
	//form.submit();
	}

	
	function mensage(men)
	{
		alert(men);
	}
	function v_campos(campo,tipo)
	{
	var isValid = false;
	if(campo.value!="")
	{
		switch(tipo)
		{
			case "cd":
				isValid = v_String(campo.value);break;
			case "nu":
				isValid = !isNaN(parseInt(campo.value));break;
			case "fe":
				isValid = v_Date(campo.value);break;
			case "id":
				isValid = v_Identification(campo.value);break;
			case "te":
				isValid = v_Phone(campo.value);break;
			case "em":
				isValid = v_Email(campo.value);break;
			case "cl":
				isValid = v_Ciclo(campo.value);break;
			default: isValid = false;break;
		}
		if(isValid == false)
		{
			alert("Please ! Enter data in the correct format");
			campo.value="";
			campo.focus()

		}
	}
}

function v_String(campo)
{
	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚabcdefghijklmnñopqrstuvwxyzáéíóú ";
	var checkStr = campo;
	var allValid = true; 
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i); 
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
				break;
			if (j == checkOK.length) { 
				allValid = false; 
				break; 
    			}
	}
	return allValid;
}

function v_Identification(campo)
{
	var allValid = false;
	if(parseInt(campo.length) == 11)
	{
		var idp=campo.split("-");
		if(idp[0].length == 1 && isNaN(parseInt(idp[0]))==false && parseInt(idp[0])>0 && parseInt(idp[0])<=8 && idp[1].length == 4 && isNaN(parseInt(idp[1]))==false && parseInt(idp[1])>-1 && parseInt(idp[1])<=9999 && idp[2].length == 4 && isNaN(parseInt(idp[2]))==false && parseInt(idp[2])>-1 && parseInt(idp[2])<=9999)
			allValid = true;
	}
	return allValid;
}

function v_Date(campo)
{
	if(campo!="")
	{
		anyo=campo.split("-")[0];
		mes=campo.split("-")[1];
		dia=campo.split("-")[2];
		if((isNaN(dia)==true) || (isNaN(mes)==true) || (isNaN(anyo)==true) )
		{
			return false;
		}
		else
		{
			if(parseInt(mes)==2 && (parseInt(anyo)%4)==0 && (parseInt(anyo)%100)!=0 && (parseInt(anyo)%400)!=0)
				febrero=29;
			else
				febrero=28;
			if ((mes<1) || (mes>12))
				return false;
			if ((mes==2) && ((dia<1) || (dia>febrero)))
				return false;
			if (((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) || (mes==10) || (mes==12)) && ((dia<1) || (dia>31))||((mes==4) || (mes==6) || (mes==9) || (mes==11)) && ((dia<1) || (dia>30)))
				return false;
			if ((anyo<1900) || (anyo>parseInt(new Date().getFullYear())))
				return false;
			else
				return true;
		}
	}
}

function v_Phone(campo)
{
	var allValid = false;
	if(campo.length == 8)
	{
		var idp=campo.split("-");
		if(idp[0].length == 3 && isNaN(parseInt(idp[0]))==false && parseInt(idp[0])>200 && parseInt(idp[0])<=999 && idp[1].length == 4 && isNaN(parseInt(idp[1]))==false && parseInt(idp[1])>-1 && parseInt(idp[1])<=9999)
			allValid = true;
	}
	return allValid;
}

function v_Email(campo)
{
	var allValid = true; 
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz12345667890_@.";
	var checkStr = campo;
	for (i = 0; i < checkStr.length; i++)
	{
		ch = checkStr.charAt(i); 
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
				break;
			if (j == checkOK.length)
			{ 
				allValid = false; 
				break; 
   			}
	}
	if(allValid == true && campo.indexOf("@",0)!=-1 && campo.indexOf(".")!=-1 && (campo.lastIndexOf("@") < campo.lastIndexOf(".")))
	{
		allValid = true;
		if(campo.indexOf("_",0)!=-1)
		{
			if (campo.lastIndexOf("_") < campo.lastIndexOf("@"))
				allValid = true;
			else
				allValid = false;
		}
	}
	else
		allValid = false;
	return allValid;
}
//FUNCION ENCARGADA DE VALIDAR QUE TODOS LOS CAMPOS HAYAN SIDO COMPLETADOS
function envia(formulario)
{
	var allValid=true;
	var i = 0;
	for(i=0;i<=formulario.elements.length-1;i++)
	{
		if(formulario.elements[i].value=="")
		{
			if(formulario.elements[i].name != "FormFieldList")
			{
				allValid = false;
				alert("Favor Completar Todos Los Campos con los Valores Correspondientes");
				break;
			}
		}
	}
	return allValid;
}





	