

function crear_ajax() {
	var ajax_obj=null;
	if (window.XMLHttpRequest) { ajax_obj=new XMLHttpRequest(); } // Mozilla
	else if (window.ActiveXObject) { // IE
		try { ajax_obj= new ActiveXObject("Msxml2.XMLHTTP"); } 
		catch (e1) {
			try { ajax_obj = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) {}
			}
	} 
	return ajax_obj;
}

function do_ajax(target, stringValores, url, extra) {
	var canal = crear_ajax();
	if (!canal) { alert ("Su navegador no es compatible con esta aplicación"); return; }
	canal.open("GET", url + "?timestamp=" + new Date().getTime() + "&" + stringValores, true);
	canal.send(null);
	canal.onreadystatechange=function(){ 
		if(canal.readyState==4 && canal.status==200){  
			document.getElementById(target).innerHTML = canal.responseText;  //con esto escribo los datos en el id seleccionado
			if (typeof(extra) != "undefined") eval(extra);
		}	
	}
}
function ValidarCamposFormularioRedHidricos()
{
	if( document.all['txtNombre'].value=='')
	{
  		alert('Debe ingresar el apellido y nombre del solicitante. los campos marcados con * son obligatorios'); 
		return false; 
 	}


       if( document.all['txtEmpresa'].value=='')
          {
             alert('Debe ingresar la empresa/organizmo/universidad'); 
 	 		return false; 	
          }
	 if( document.all['txtTelefono'].value=='')
          {
             alert('Debe ingresar el teléfono/fax'); 
       		return false; 
          }
	 

      if( document.all['txtEmail'].value=='')
          {
             alert('Debe ingresar el email'); 
					return false; 
          }

      if( document.all['txtNaturalezaProyecto'].value=='')
          {
             alert('Debe ingresar nombre/naturaleza del proyecto'); 
     		return false; 
          }
	  if( document.all['txtCodigoEstacion'].value=='')
          {
             alert('Debe ingresar el código de la estación'); 
					return false; 
          }
      
      if( document.all['txtRio'].value=='')
          {
             alert('Debe ingresar el río'); 
             		return false; 
          }
          
      if( document.all['txtLugar'].value=='')
          {
             alert('Debe ingresar el lugar'); 
					return false; 	
          }
          
      if( document.all['txtVariable'].value=='')
          {
             alert('Debe ingresar la variable'); 
					return false; 	
          }
         
      if( document.all['txtPeriodo'].value=='')
          {
             alert('Debe ingresar el período'); 
					return false; 
          }
          // parte 2
               
     
          
      
          
    if( document.all['txtAcepto'].checked==false)
    {
    	alert("DEBE ACEPTAR LOS TERMINOS Y CONDICIONES");
				return false; 	
    	
    }
return true; 
	
}


function validaContacto()
{

if( document.all['txtNombre'].value=='')
    {
     alert('Debe ingresar el apellido y nombre del solicitante. los campos marcados con * son obligatorios'); 
     return false; 
       }

if( document.all['txtOrga'].value=='')
    {
     alert('Ingrese la organizacion'); 
     return false; 
       }

if( document.all['txtFax'].value=='')
    {
     alert('Ingrese el telefono/Fax'); 
     return false; 
       }

if( document.all['txtEmail'].value=='')
    {
     alert('Ingrese el email '); 
     return  false; 
       }

return true; 	
	
}

function sendContacto(ubicacion,valor )
{
var stringValores ="txtNombre=" +document.getElementById('Nombre').value +"&txtOrga="+document.getElementById('Orga').value +"&txtDireccion=" +document.getElementById('Dir').value 	+ "&txtLocalidad=" + document.getElementById('local').value + "&txtCodigo=" + document.getElementById('cp').value + "&txtFax=" + document.getElementById('telefono').value
+  "&txtEmail=" + document.getElementById('Email').value  + "&txtMotivo=" + document.getElementById('motivo').value ;

if (validaContacto()==true) 
{

 var url = "contacto.php" ;
 do_ajax(ubicacion, stringValores, url);
 alert("Mail enviado Exitosamente"); 
 formElement = document.getElementById("F1");
 alert( formElement.childNodes.item(1).value ) ;

}

}

function get(ubicacion,valor){
//	var stringValores="valor="+valor+"&valor2="+document.getElementById('Email').value; //aca pongo los parametros que quiero recibir del otro lado
var stringValores="txtNombre="+document.getElementById('idNombre').value  +"&txtEmpresa="
 +document.getElementById('idEmpresa').value + "&txtDireccion="+document.getElementById('idDireccion').value + 
 "&txtLocalidad="+document.getElementById('idLocalidad').value + "&txtCodigoPostal="+document.getElementById('idCp').value + "&txtprovincia="+document.getElementById('idprov').value + "&txtPais=" +document.getElementById('idPais').value
 + "&txtTelefono="+document.getElementById('idTel').value + "&txtEmail="+document.getElementById('idMail').value
 + "&txtNaturalezaProyecto="+document.getElementById('idNat').value + "&txtCodigoEstacion="+document.getElementById('idCod').value + "&txtRio="+document.getElementById('idRio').value +"&txtLugar="+document.getElementById('idLugar').value  + "&txtVariable=" +document.getElementById('idVar').value +"&txtPeriodo="+document.getElementById('idPer').value
 + "&txtObservaciones="+document.getElementById('idOb').value +"&txtCodigoEstacion1=" +document.getElementById('idCod2').value + "&txtRio1="+document.getElementById('idRio2').value + "&txtLugar1="+document.getElementById('idLugar2').value
 + "&txtVariable1="+ document.getElementById('idVar2').value +"&txtPeriodo1="+ document.getElementById('idPer2').value
 + "&txtObservaciones1="+ document.getElementById('idOb2').value +"&txtCodigoEstacion2=" +document.getElementById('idCod3').value + "&txtRio2=" +document.getElementById('idRio3').value + "&txtLugar2="+document.getElementById('idLugar3').value + "&txtVariable2=" +document.getElementById('idVar3').value + "&txtPeriodo2="+document.getElementById('idPer3').value + "&txtObservaciones2=" + document.getElementById('idOb3').value; 


if (ValidarCamposFormularioRedHidricos()==true) 
{
    var url = "Sendmail.aspx" ;
	//alert (url + stringValores);
	do_ajax(ubicacion, stringValores, url);
	alert("Mail enviado Exitosamente"); 
formElement = document.getElementById("F1");
   alert( formElement.childNodes.item(1).value ) ;
	
}

	

	
}


function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}

function traerDatos(tipoDato)
{
	// Obtendo la capa donde se muestran las respuestas del servidor
	var capa=document.getElementById("demoArr");
	// Creo el objeto AJAX
	var ajax=nuevoAjax();
	// Coloco el mensaje "Cargando..." en la capa
	capa.innerHTML="Cargando...";
	// Abro la conexión, envío cabeceras correspondientes al uso de POST y envío los datos con el método send del objeto AJAX
	ajax.open("POST", "ejemplo_basico_xmlhttprequest_post_proceso.php", true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("d="+tipoDato);

	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==4)
		{
			// Respuesta recibida. Coloco el texto plano en la capa correspondiente
			capa.innerHTML=ajax.responseText;
		}
	}
}
 
 function getFormAsString(formName){
 	
 	//Setup the return String
 	returnString ="";
 	
  	//Get the form values
 	formElements=document.forms[formName].elements;
 	
 	//loop through the array , building up the url
 	//in the form /strutsaction.do&name=value
 	
 	for ( var i=formElements.length-1; i>=0; --i ){
 		//we escape (encode) each value
 		returnString=returnString+"&"+escape(formElements[i].name)+"="+escape(formElements[i].value);
 	}
 	
 	//return the values
 	return returnString; 
 }

function retrieveURL(url,nameOfFormToPost) {
    
    //get the (form based) params to push up as part of the get request
    url=url+getFormAsString(nameOfFormToPost);
    
    //Do the Ajax call
    if (window.XMLHttpRequest) { // Non-IE browsers
      req = new XMLHttpRequest();
      req.onreadystatechange = processStateChange;
      try {
      	req.open("POST", url, true); //was get
      } catch (e) {
        alert("Problem Communicating with Server\n"+e);
      }
      req.send(null);
    } else if (window.ActiveXObject) { // IE
      
      req = new ActiveXObject("Microsoft.XMLHTTP");
      if (req) {
        req.onreadystatechange = processStateChange;
        req.open("POST", url, true);
        req.send();
      }
    }
  }
 


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 Posting(){
 ajax=objetoAjax();
 ajax.open("POST", "Sendmail.php",true);
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   //divResultado.innerHTML = ajax.responseText
   alert('se envio');
  }
 }
 
 
 ajax.send(null)
} 

function contactoPost(){
 ajax=objetoAjax();
 ajax.open("POST", "contacto.php",true);
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   alert('se envio');
  }
 }
 
 
 ajax.send(null)
} 
