//****************************************************************************************
//** FUNCIONES PARA FORMULARIOS                                                                       
//****************************************************************************************

//busca caracteres que no sean espacio en blanco en una cadena  
function vacio(q) {   
        for ( i = 0; i < q.length; i++ ) {   
                if ( q.charAt(i) != " " ) {   
                        return true   
                }   
        }   
        return false   
}   

//valida formato email usando expresiones regulares
function validar_email(txt){   
       
    //expresion regular   
        var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/   
        //devuelve verdadero si validacion OK, y falso en caso contrario   
        return b.test(txt)   
} 

// dice si cadena es url (http://... ) o no                                 
function url(cadena)   
  {                                    // DECLARACION DE CONSTANTES   
    var http = "http://";              // protocolo HTTP   
                                       // DECLARACION DE VARIABLES   
    var es_url;                        // cadena es url o no   
    if(cadena.length <= 7)             // INICIO   
      es_url = false;                  // no cabe "http://*"   
    else  
      es_url = http.indexOf(cadena.substring(0, 7)) != - 1; // lee "http://*"   
    return(es_url);   
  }   


//valida que el campo no este vacio y no tenga solo espacios en blanco   

function ValidarForm(f) {   
        
		if( vacio(f.nombre.value) == false ) {   
                document.getElementById("div_err").innerHTML = "Debe ingresar su Nombre"; 
                return false   
        }

		if( vacio(f.apellido.value) == false ) {   
                document.getElementById("div_err").innerHTML = "Debe ingresar su Apellido ";  
                return false   
        } 
		if( vacio(f.empresa.value) == false ) {   
                document.getElementById("div_err").innerHTML = "Debe ingresar su Empresa ";  
                return false   
        } 
		
		if( vacio(f.telefono.value) == false ) {   
                document.getElementById("div_err").innerHTML = "Debe ingresar su Telefono";    
                return false   
        } 
        
		if( validar_email(f.email.value) == false ) {   
                document.getElementById("div_err").innerHTML = "La direccion de E-mail no es valida";   
                return false   
        }

        return true   
          
} 



