function nuevoXMLHTTPRequest()
{
	var xmlhttp=false;
 	try 
	{
		/*objeto xmlhttprequest para versiones nuevas del explorer*/
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	}
	catch (e)
	{
 		try 
		{
			/*objeto xmlhttprequest para explorer de versiones antiguas*/
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		}
		catch (E)
		{
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		/*objeto xmlhttprequest para cualquier browser que no sea explorer*/
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function CargarConAjax(IdCarga,Parametros,Direccion)
{  
  document.getElementById(IdCarga).innerHTML = '<div align="center" class="cargando" ><img  src="img/gifs/ProgressQuena.gif" alt "LOGOKAHUI"> <br> <strong>Cargando...</strong></div>' ;
 
  var xtrMenu = nuevoXMLHTTPRequest();
  
  if (trim(Parametros) == '') {
    Parametros = 'funcion=pagina&pagina='+Direccion;
  }

  xtrMenu.open ('GET', 'php/controls.php?'+Parametros, true);
  xtrMenu.onreadystatechange = function ()
  {   
	if (xtrMenu.readyState == 4)
	{    
		var sTexto = xtrMenu.responseText.toString();
		
		if (Direccion=='') {
		  return document.getElementById(IdCarga).innerHTML = sTexto;
		}
		else
		{	
		  if (sTexto == ''){
		    window.location = Direccion ;
		  }
		  else {
		    return document.getElementById(IdCarga).innerHTML = sTexto;
		  }
		}
	  	
	}
  }  
  xtrMenu.send (null);

}

function CambiaImg(sId,sImg)
{
	return document.getElementById(sId).src = sImg ;	
}

function GrabarVisita(sId)
{
  if (DatosValidos()) {
    sParametros='funcion=GrabaVisita&Nombre='+document.getElementById('vNombre').value ;
    sParametros=sParametros+'&email='+document.getElementById('vemail').value ;
    sParametros=sParametros+'&Lugar='+document.getElementById('vLugar').value ;
    sParametros=sParametros+'&Comentario='+document.getElementById('vComentario').value ;
    
    CargarConAjax(sId,sParametros,'visitas.html');
  }
}

function trim(s)
{ 
	return s.replace( /^\s*/, "" ).replace( /\s*$/, "" ); 
} 

function DatosValidos()
{  
  var bCorrecto = true;
  var bCamposVacios = false;

  if (trim(document.getElementById("vNombre").value) == "") {
    document.getElementById("lblnombre").innerHTML = '*';
    bCamposVacios = true;
  }
  else {
    document.getElementById("lblnombre").innerHTML = '';
  }
  
  if (trim(document.getElementById("vemail").value) == "") {
    document.getElementById("lblemail").innerHTML = '*';
    bCamposVacios = true;
  }
  else {
    document.getElementById("lblemail").innerHTML = '';
  }

  if (trim(document.getElementById("vLugar").value) == "") {
    document.getElementById("lbllugar").innerHTML = '*';
    bCamposVacios = true;
  }
  else {
    document.getElementById("lbllugar").innerHTML = '';
  }

  if (trim(document.getElementById("vComentario").value) == "") {
    document.getElementById("lblcomentario").innerHTML = '*';
    bCamposVacios = true;
  }
  else {
    document.getElementById("lblcomentario").innerHTML = '';
  }

  if (bCamposVacios) {
    bCorrecto = false;
    document.getElementById("error").innerHTML = 'Son necesarios los campos marcados con "*"';
  }
  else {
    document.getElementById("error").innerHTML = '';
 /*   
    var sRestriccion = new RegExp("/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+\.([a-zA-Z0-9_-]+)+$");
    var sEmail = document.getElementById("vemail").innerHTML;

    if (!sEmail.match(sRestriccion)) {
      bCorrecto = false;
      document.getElementById("error").innerHTML = 'e-mail incorrecto';
      document.getElementById("lblemail").innerHTML = '*';
    }    
 */
  } 

  return bCorrecto;
}

function MostrarDemo(URL,Nombre)
{	
	 window.open(URL,Nombre,"width=388,height=570,scrollbars=SI") ;
}
