﻿
    var xmlhttp;
    function loadXMLDoc(){  
            if ( !sonValidosCampos()) return false;
            xmlhttp=null;
            // code for Mozilla, etc.
            if (window.XMLHttpRequest)
              {
              xmlhttp=new XMLHttpRequest()
              }
            // code for IE
            else if (window.ActiveXObject)
              {
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
              }
            if (xmlhttp!=null)
              {
              //var idRequest=document.getElementById("txtXMLRequest").value;
              
              var idRequest= "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
                                    "<REQ REQUERIMIENTO=\"ENVOYER\">"+
                                    "<PARAM NAME=\"NOM\" VALUE=\""+document.getElementById("nombres").value+"\"/>"+
                                    "<PARAM NAME=\"APP\" VALUE=\""+document.getElementById("apellido").value+"\"/>"+
                                    "<PARAM NAME=\"EMA\" VALUE=\""+document.getElementById("email").value+"\"/>"+
                                    "<PARAM NAME=\"TLF\" VALUE=\""+document.getElementById("telefono").value+"\"/>"+
                                    "<PARAM NAME=\"COM\" VALUE=\""+document.getElementById("comentario").value+"\"/>"+
                                    "<PARAM NAME=\"DNI\" VALUE=\""+document.getElementById("dni").value+"\"/>"+
                                    "</REQ>";              
              xmlhttp.onreadystatechange=state_Change
              xmlhttp.open("POST","../web_builder.aspx",true)
              xmlhttp.send(idRequest)
              }
            else
              {
              alert("Your browser does not support XMLHTTP.")
              }
              
              return false;
    }

    function state_Change()
    {
    // if xmlhttp shows "loaded"
    if (xmlhttp.readyState==4)      
      // if "OK"
      if (xmlhttp.status==200){                
       // document.getElementById("comentario").value=xmlhttp.responseText;        
        alert('Gracias por interesarse por nosotros, nos estaremos poniendo en contacto con usted.');
        document.getElementById("cleaner").click();
        }
      else        
        alert("Problem retrieving XML data"+xmlhttp.responseText) ;             
    }
    
    
   
        
function validarEntero() {
    if (event.keyCode < 48 || event.keyCode > 57 ) 
    event.returnValue = false;
}
function sonValidosCampos(){
    var emailBool= js_verify();
    var dniBool=esTextoNumerico(document.getElementById('dni'),false,'DNI',8);
    
    var nomb= ValidarStr(trim(document.getElementById('nombres').value));
    var appll= ValidarStr(trim(document.getElementById('apellido').value));
    var coment= ValidarStr(trim(document.getElementById('comentario').value));
    var telf= ValidarStr(trim(document.getElementById('telefono').value));
    var dni= ValidarStr(trim(document.getElementById('dni').value));
    var email= ValidarStr(trim(document.getElementById('email').value));
    
    document.getElementById('nombres').value=trim(nomb);
    document.getElementById('apellido').value=trim(appll);
    var str='';
    var salida=true;
    if (email =='') str+='Ingrese un mail\n';else if (!emailBool )  str+='Email incorrecto.\n';  
    if (dni =='') str+='Ingrese su DNI\n';else if (!dniBool ) str+='DNI incorrecto\n'; 
    if (nomb=='') str+='Ingrese su Nombre\n';
    if (appll =='') str+='Ingrese su Apellido\n';
    if (telf=='') str+='Ingrese su teléfono\n';
    if (coment =='') str+='Ingrese un comentario\n';        
    if (str!= '') {alert(str); salida=false;}
    return salida;
}

function esTextoNumerico(poTexto, pbVacio, psTitulo, numCaracteres) {
//poTexto: texto ingresado
	if (pbVacio == true){
		if (trim(poTexto.value) == "" ){
			alert("Debe ingresar n?mero de " + psTitulo);
			poTexto.focus();
			return false;
		}
	}
	if (trim(poTexto.value) != ""){
		if (isNaN(poTexto.value) || poTexto.value.length != numCaracteres){                        
			poTexto.focus();
			return false;
		}
	}
	return true;
}


function ValidarStr(psCadena){
	var sValido = "ABCDEFGHIJKLMNOPQRSTUVWYXZ áéíóúÁÉÍÓÚabcdefghijklmnopqrstuvwxyz";
	for (i = 0 ; i < psCadena.length; i++){	
		if (sValido.indexOf(psCadena.substring(i,i+1),0) == -1){
			psCadena = psCadena.replace(psCadena.substring(i,i+1)," ");
		} 
	}	
	return psCadena;
}
function trim(cadena) { 
    return ( String(cadena).replace(/[\s]/g,"") ); 
}

function js_verify(){
var reEmail = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/;
var emails = document.getElementById('email').value; 
valido = true;
    if (!reEmail.test(emails) )
        valido=false;                 
if (!valido)   {
document.getElementById('email').value=''; return false;}
return true;
}
     
