//24.03.10 JCRZ Validaciones del formulario de contacto

     //Variables Globales 
        //Teclas
        var BackSpace = 8;
        var Tab = 9;
        var Enter = 13;
        var Esc = 27;
        var Supr = 46; //para FireFox y otros menos IE
        var Fechaizq = 37; //para FireFox y otros menos IE
        var Fechader = 39; //para FireFox y otros menos IE
        var Espacio = 32; //para FireFox y otros menos IE
        var NMay = 209; //Ñ para FireFox y otros menos IE
        var NMin = 241; //n para FireFox y otros menos IE
        var Espacio = 32; //para FireFox y otros menos IE
        var Barra = 47; //para FireFox y otros menos IE


    //24.03.10 JCRZ Validamos los datos capturados
    function ValidarFormulario()
    {
        //Obtenemos los valores capturados
        var Nombre = document.getElementById("txtnombre");
        var Tel = document.getElementById("txttel");
        var Correo = document.getElementById("txtcorreo");
        var Ciudad = document.getElementById("txtciudad");
        var Comentarios = document.getElementById("txtcometario");
        
        Nombre.value = trim(Nombre.value);
        if (Nombre.value.length == 0)
        {
            alert ('Campo Nombre es Requerido.');
            Nombre.focus();
            return false;
        }
        
        Tel.value = trim(Tel.value);
		if (Tel.value.length == 0)
        {
            alert ('Campo Telefono es Requerido.');
            Tel.focus();
            return false;
        }
            
        Correo.value = trim(Correo.value);
        if (Correo.value.length == 0)
        {
            alert ('Campo Correo es Requerido.');
            Correo.focus();
            return false;
        }
        else
        {
           if (ValidaEmail(Correo.value)== false)
           {
                alert ('Formato de Correo incorrecto.'); 
                return false;
           }
        }
        
        Ciudad.value = trim(Ciudad.value);
        if (Ciudad.value.length == 0)
        {
            alert ('Campo Ciudad es Requerido.');
            Ciudad.focus();
            return false;
        }
        
        //Comentarios.value = trim(Comentarios.value);
        
        return true;
        
        
    }
    
    //24.03.10 JCRZ Limpiamos el formulario
    function LimpiarFormulario()
    {
        //Obtenemos los valores capturados
        document.getElementById("txtnombre").value="";
        document.getElementById("txttel").value="";
        document.getElementById("txtcorreo").value="";
        document.getElementById("txtciudad").value="";
        document.getElementById("txtcomentario").value="";
        
        document.getElementById("txtnombre").focus();
    }

    //24.03.10 JCRZ Funcion para validar la cuenta de correo
    function ValidaEmail(valor)
    {
        re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
        if(!re.exec(valor))    {
            return false;
        }else{
            return true;
        }
    }
    
    //23.03.10 JCRZ - funcion que quita los espacion al inicio y fin de la cadena
    function trim(cadena)
    {
        for(i=0; i<cadena.length; )
        {
            if(cadena.charAt(i)==" ")
                cadena=cadena.substring(i+1, cadena.length);
            else
                break;
        }

        for(i=cadena.length-1; i>=0; i=cadena.length-1)
        {
            if(cadena.charAt(i)==" ")
                cadena=cadena.substring(0,i);
            else
                break;
        }
        
       return cadena;
    }
    
   //23.03.10 JCRZ Funcion para limitar el area de texto de un campo tipo textarea
   function maxcaracteres(obj)
   {
        var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
        if (obj.getAttribute && obj.value.length>mlength)
        {
             obj.value=obj.value.substring(0,mlength);
             alert ('Solo Se Permiten como Maximo 250 Caracteres');
             
        }
             
   }
   
   //24.03.10 JCRZ - funcion que solo permite numeros en un textbox probado en FireFox e IE
    function SoloNumEnteros(e)
    {
        var evento = e || window.event;          // tipo de evento
        var tecla = evento.which || evento.keyCode;   //validamos si es IE u otro
        var caracter = String.fromCharCode(tecla); //Obtenemos el codigo corespondiente a la tecla
    
        //Validamos si es IE
        var ie = navigator.userAgent.toLowerCase().indexOf('msie')!=-1;
    
        //validamos si es IE
        if(ie)
        {
             //Validamos que la tecla se permitida y sea numero
            if (tecla == BackSpace || tecla == Tab || tecla == Enter || tecla == Esc || tecla == Espacio || /\d/.test(caracter))
                return true; 
            else
                return false; 
        }
        else
        {
           //Validamos que la tecla se permitida y sea numero
           if ( (tecla == Supr && evento.charCode!= Supr) || (tecla == Fechaizq && evento.charCode!= Fechaizq) || (tecla == Fechader && evento.charCode!= Fechader) || tecla == BackSpace || tecla == Tab || tecla == Enter || tecla == Esc || tecla == Espacio || /\d/.test(caracter))
                return true; 
            else
                return false; 
                
            /*NOTA: se utiliza en algunas condiciones el charCode por que en firefox el keyCode de (tecla SUPR y el Punto) es 46 
            por eso se valida que el codeChar sea diferente para que solo acepte caracteres admitidos */
        }
       
    }