// JavaScript Document
function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function limpiar(){
	document.cliente.nombre.focus(); 
} 

function validarDatos() {
	if (document.cliente.nombre.value == "")   { 
		alert("Por favor ingrese su nombre"); 
		document.cliente.nombre.focus(); 
		return false;
 	} 
    
	if (document.cliente.nombre.value.length < 10)   { 
		alert("Por favor ingrese su nombre completo"); 
		document.cliente.nombre.focus(); 
		return false;
 	} 

	if ( (document.cliente.casa.value == "") && (document.cliente.oficina.value == "") && (document.cliente.celular.value == "") && (document.cliente.mail.value== "") ) { 
		alert("Por favor ingrese por lo menos un numero telefonico o su e-mail, son datos requeridos para poder comunicarnos con usted"); 
  		document.cliente.casa.focus();
		return false; 
	} 
		
	if(!document.cliente.mail=="")  {
	   var s = document.cliente.mail.value;
         //var filter=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
  	  // var filter=/^[A-Za-z][][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
           var filter=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;
	   if (s.length == 0 ) 
	   		return true;
       if (filter.test(s)) 
  	   		return true;
  	   else {
  			alert("Ingrese una direcci\u00f3n de correo v\u00e1lida");
 			document.cliente.mail.focus();
 			return false;
 	  }
	}
}


var nav = window.Event ? true : false;
function aceptaNum(evt) {
	var key = nav ? evt.which : evt.keyCode;
    return (key==127 || key<32 || key ==45 || key ==40 || key ==41 || (key >= 48 && key <= 57));
}


function enviarDatos( ){	
	if (validarDatos()) {
		recibirDatos();
	}  else  {              
 	  return false;      
	}
}

if(window.attachEvent)
    window.attachEvent("onload",setListeners);
  
  function setListeners(){
    inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
      inputList[i].attachEvent("onpropertychange",restoreStyles);
      inputList[i].style.backgroundColor = "";
    }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
      selectList[i].attachEvent("onpropertychange",restoreStyles);
      selectList[i].style.backgroundColor = "";
    }
  }

  function restoreStyles(){
    if(event.srcElement.style.backgroundColor != "" && event.srcElement.style.backgroundColor != "ffffff"){
      event.srcElement.style.backgroundColor = "ffffff"; /* color of choice for AutoFill */
      document.all['googleblurb'].style.display = "block";
    }
  }

function recibirDatos(){
  //  return validar();	
  
    divResultado = document.getElementById('mensaje');
	nombre = document.cliente.nombre.value;
	casa = document.cliente.casa.value;
	celular = document.cliente.celular.value;
	oficina = document.cliente.oficina.value;
	mail = document.cliente.mail.value;
    comentario = document.cliente.comentario.value;
	
	ajax=objetoAjax();
	ajax.open("POST", "fileadmin/formularios/registroCliente.php", true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divResultado.innerHTML = ajax.responseText
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("nombre="+nombre+"&casa="+casa+"&celular="+celular+"&oficina="+oficina+"&mail="+mail+"&comentario="+comentario);
	document.cliente.reset()

}

