// JavaScript Document
function validaforminmuebles(Form) {  
        if( Form.operacion.value == "0" ) {  
                alert("Debe seleccionar la operación.");  
                return false; 
        } else {  
			if( Form.tipoinmueble.value == 0 ) {  
					alert("Debe seleccionar el tipo de inmueble");  
					return false;  
			} else {  
				if( vacio(Form.titulo.value) == false  ) {  
						alert("Debe ingresar el título del aviso");  
						return false;  
				} else {  
						//alert("OK")  
						//cambiar la linea siguiente por return true para que ejecute la accion del formulario  
						return true;  
				}
			}
		}
  
} 

function validaformlogin(Form) {  
          
        if( vacio(Form.username.value) == false ) {  
                alert("Debe introducir nombre de usuario."); 
                return false;  
        } else {  
			if( vacio(Form.password.value) == false ) {  
					alert("Debe introducir password");  
					return false;  
			} else {  
					//alert("OK")  
					//cambiar la linea siguiente por return true para que ejecute la accion del formulario  
					return true;  
			}
		}
  
} 

function validaformregistro(Form) {  
        if(comprobarTodos(Form)== false){  
        	texto= "Debe ingresar toda la información.";
        }else{
			//alert("ingreso toda la información.");
			if(comprobarPass(Form)== false ){
				texto=" * Las contraseñas ingresadas no son iguales\n";
			} else {
				texto = "";
			}
			if ( validar_email(Form.email.value) == true){
				texto = texto + "";
			} else {
				//alert ("El email ingresado no es válido")
				texto = texto + " * El email ingresado no es válido\n";
			}
		}
		if (texto== ""){
			return true;
		} else {
			alert (texto);
			return false;
		}
} 

function validaformcontacto(Form) {  
		//alert ("comprueblo contactar")
        if(comprobarTodosContacto(Form)== false) 
		{  
        	texto= "Los campos con \"*\" son datos obligatorios";
        }  else {
			//alert("ingreso toda la información.")	
			if ( validar_email(Form.email.value) == true)
			{
				texto = texto + "";
			} else {
				//alert ("El email ingresado no es válido")
				texto = texto + " - El email ingresado no es válido";
			}
		}
			
		
		if (texto== "")
		{
			return true;
		} else {
			alert (texto);
			return false;
		}
  
} 

function validaforminmomiliaria(Form) {  
        if( vacio(Form.nombre.value) == false  ) {  
                alert("Debe ingresar el nombre de la Inmobiliaria.");  
                return false; 
        } else {  
			if( vacio(Form.nombre.value) == false  ) {  
					alert("Debe ingresar un número de teléfono");  
					return false;  
			} else {  
				if( Form.pais.value == 0 ) {  
						alert("Debe seleccionar el país");  
						return false;  
				} else {  
						//alert("OK")  
						//cambiar la linea siguiente por return true para que ejecute la accion del formulario  
						return true;  
				}
			}
		}
  
} 

function vacio(campo) 
{  
        for ( i = 0; i < campo.length; i++ ) {  
                if ( campo.charAt(i) != " " ) {  
                        return true;  
                }  
        }  
        return false;  
}

function validar_email(campo)
{  
	//alert ("estoy por validar email")
    if ((campo.indexOf ('@', 0) == -1)||(campo.length < 5)) 
	{
    	//alert("Escriba una dirección de correo válida")
    	return false;
  	} else {
		return true;
	}
}

function comprobarTodos(Form)
{
	//alert ("estoy en comprobar todos");
	if( vacio(Form.nombre.value) == false || vacio(Form.username.value) == false || vacio(Form.email.value) == false || vacio(Form.password1.value) == false || vacio(Form.password2.value) == false ){
		//alert("Debe iiiiingresar toda la información.");
		return false;  
	}  else {
		return true;
	}
}

function comprobarTodosContacto(Form)
{
	if( vacio(Form.nombre.value) == false || vacio(Form.email.value) == false || vacio(Form.mensaje.value) == false ) 
	{
		//alert("Debe ingresar toda la información.")
		return false;  
	}  else {
		return true;
	}
}

function comprobarPass(Form)
{
	//alert("Estoy comprobando el pass");
	if( Form.password1.value == Form.password2.value )
	{
		//alert ("los pass son iguales")
		return true;
	} else {
		//alert("Las contraseñas ingresadas no son iguales");
		return false;
	}
}
