

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){  
			if (typeof(extra) != "undefined") eval(extra);
		}	
	}
}
function validarCampoEnviaCorreoContactoPrensa()
{
 
     if( document.all['txtnombre'].value==''  )
     {
            alert('Ingrese el nombre'); 
            document.all['txtNombre'].focus();
            return false; 
     }
     
     if( /[0-9]/.test(document.all['txtnombre'].value) ) 
        {
         alert('el nombre es Invalido'); 
         document.all['txtNombre'].focus();
        return false;       
        }
  
     if( document.all['txtCorreo'].value==''  )
     {
            alert('Ingrese el email'); 
            return false; 
     }
      if( !(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test( document.all['txtCorreo'].value)) )
    {
         alert('El email es invalido'); 
         document.all['txtCorreo'].focus();
         return false; 
         
  
    }
    if( document.all['txtMedioEmpresa'].value=='')
    {
       document.all['txtMedioEmpresa'].value=''           
    }    
    if( document.all['txtTelefono'].value=='')
    {
       document.all['txtTelefono'].value=''           
    }    
   if( document.all['txtCorreo'].value=='')
    {
       document.all['txtCorreo'].value=''           
    }
   if( document.all['txtAsunto'].value=='')
    {
       document.all['txtAsunto'].value=''           
    }
 
return true; 
}

function cleanCamposContactoPrensa()
{
     document.all['txtnombre'].value='';
     document.all['txtMedioEmpresa'].value='';
     document.all['txtTelefono'].value='';
     document.all['txtCorreo'].value='';
     document.all['txtAsunto'].value='';
     document.all['txtComentario'].value='' ;  
}


function get(ubicacion,valor){

var stringValores="txtnombre="+document.getElementById('idNombre').value  +"&txtMedioEmpresa="
 +document.getElementById('idMedioEmpresa').value 
 + "&txtTelefono="+document.getElementById('idTelefono').value  
 + "&txtCorreo="+document.getElementById('idCorreo').value + "&txtAsunto="+document.getElementById('idAsunto').value 
 + "&txtComentario="+document.getElementById('idComentario').value ; 

if (validarCampoEnviaCorreoContactoPrensa()==true) 
{
 
  var url = "envio.php" ;
	
	do_ajax(ubicacion, stringValores, url);
	alert("Mail enviado Exitosamente"); 
	cleanCamposContactoPrensa();
}
}


function validarEnvioCorreoContacto()
{
   
  if( document.all['txtNombre'].value=='') 
    {
     alert('Debe ingresar el nombre'); 
     return false; 
    }
  if( /[0-9]/.test(document.all['txtNombre'].value) ) 
  {
   alert('el nombre es Invalido'); 
   document.all['txtNombre'].focus();
   return false;       
     
  }
  if( document.all['txtCorreo'].value=='')
    {
     alert('Debe ingresar el nombre'); 
     return false; 
    }
    
    if( !(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test( document.all['txtCorreo'].value)) )
    {
         alert('El email es invalido'); 
         document.all['txtCorreo'].focus();
         return false; 
         
  
    }
 
return true; 
} 
function limpiar()
{
  document.all['txtNombre'].value='';
  document.all['txtTelefono'].value='';
  document.all['txtCorreo'].value='';
  document.all['txtAsunto'].value='';
  document.all['txtComentario'].value='';
}

function getContacto(ubicacion,valor){


var stringValores="txtNombre="+document.getElementById('idnombre').value  
 +"&txtTelefono="+document.getElementById('idTelefono').value 
 + "&txtCorreo="+document.getElementById('idCorreo').value  
 + "&txtAsunto="+document.getElementById('idAsunto').value
 + "&txtComentario="+document.getElementById('idComentario').value ;

if (validarEnvioCorreoContacto()==true) 
{
 
  var url = "envioContacto.php" ;
	
	do_ajax(ubicacion, stringValores, url);
	alert("Mail enviado Exitosamente"); 
	limpiar(); 
}

}

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)
} 
