function creaAjax(){
         var objetoAjax=false;
         try {
          /*Para navegadores distintos a internet explorer*/
          objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
          try {
                   /*Para explorer*/
                   objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
                   }
                   catch (E) {
                   objetoAjax = false;
          }
         }

         if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
          objetoAjax = new XMLHttpRequest();
         }
         return objetoAjax;
}
      



function FAjaxurl (capa,valores,url)
{
          var ajax=creaAjax();
          var capaContenedora = document.getElementById(capa);
         ajax.open ('POST', url, true);
         ajax.onreadystatechange = function() {
         if (ajax.readyState==1) {
                          capaContenedora.innerHTML="<div style=\"background:url(main_bg.jpg);width:203px; height:225px;\"><img src=\"load.gif\" border=\"0\" style=\"margin-top:60px; margin-left:80px;\"> <div style=\"width:203px; height:25px;font-size:10px;margin-top:15px; color:#000000;font-family:Verdana, Sans-Serif;\" align=\"center\">Comprobando disponibilidad ...</div></div>";
						
         }
         else if (ajax.readyState==4){
                   if(ajax.status==200)
                   {
                        document.getElementById(capa).innerHTML=ajax.responseText;
                   }
                   else if(ajax.status==404)
                                             {

                            capaContenedora.innerHTML = "La direccion no existe";
                                             }
                           else
                                             {
                            capaContenedora.innerHTML = "Error: ".ajax.status;
                                             }
                                    }
                  }
		 ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		 ajax.send(valores);
         return;
}              
function nif() {
  
if(document.formrese.avisolegal.checked==false)
{
alert('Debe aceptar el aviso legal para continuar');	
}
else if(document.formrese.telf.value=="" || document.formrese.telf.value.length!=9)
{
alert('Debe introducir un telefono de 9 cifras para continuar');	
}
else if(document.formrese.cliente.value=="")
{
alert('Debe introducir un nombre de cliente continuar');	
}
else if(!validarEmail(document.formrese.email.value))
{
alert('Debe introducir un email correcto para continuar');	
}
else
{
FAjaxurl('todo','cliente='+document.formrese.cliente.value+'&email='+document.formrese.email.value+'&telf='+document.formrese.telf.value+'&hora='+document.formrese.hora.value+'&idrestaurante='+document.formrese.idrestaurante.value+'&npax='+document.formrese.pax.value+'&idreserva='+document.formrese.idreserva.value+'&comentarios='+document.formrese.comentarios.value+'&news='+document.formrese.newsletter.value,'newconf.php');
}

}


function fst ()
{
	
if(document.form1.dps1.value=="")
{
alert("Debe escoger una fecha para continuar");	
}
else
{
FAjaxurl('todo','idres='+document.form1.idrest.value+'&fecha='+document.form1.dps1.value,'newonlineres.php');
}


}




function stfriend()
{
FAjaxurl('todo','idres='+document.form1.idrest.value+'&info='+document.form1.newsc.value,'stfriend.php');
}


function snpax()
{
	if(document.formsesion.idsesion.value=="")
	{
	alert("Tienes que seleccionar el tipo");
	return false;	
	}
	else if(document.formsesion.pax.value==0)
	{
	alert("Tienes que seleccionar el numero de personas");
	return false;
	}
	else
	{
FAjaxurl('todo','pax='+document.formsesion.pax.value+'&sesion='+document.formsesion.idsesion.value+'&idres='+document.formsesion.idrestaurante.value+'&fecha='+document.formsesion.fecha.value,'sthora.php');	
	}
}

function sendamigo()
{
if(!validarEmail(document.formrese1.email.value))
{
alert('Debe introducir un email correcto para continuar');	
}
else
{
FAjaxurl('todo','comentarios='+document.formrese1.comentarios.value+'&email='+document.formrese1.email.value+'&idres='+document.formrese1.idres.value,'stamigo.php');	
}

}



function snpax2()
{
	if(document.formhora.idsesion.value=="")
	{
	alert("Tienes que seleccionar el horario");
	return false;	
	}
	else if(document.formhora.pax.value==0)
	{
	alert("Tienes que seleccionar el numero de personas");
	return false;
	}
	else
	{
FAjaxurl('todo','pax='+document.formhora.pax.value+'&sesion='+document.formhora.idsesion.value+'&idres='+document.formhora.idrestaurante.value+'&fecha='+document.formhora.fecha.value,'newonlineres.php');	
	}
}



function sethora (hora,boton,i){
	


document.formhora.hora_llegada.value = hora	;
boton.style.background='#F25509';
boton.style.color='#000000';

FAjaxurl('todo','pax='+document.formhora.pax.value+'&sesion='+document.formhora.idsesion.value+'&fecha='+document.formhora.fecha.value+'&idres='+document.formhora.idrestaurante.value+'&hora='+hora,'stdatos.php');	

}


function snpax3()
{

FAjaxurl('todo','pax='+document.formrese.pax.value+'&sesion='+document.formrese.idsesion.value+'&idres='+document.formrese.idrestaurante.value+'&fecha='+document.formrese.fecha.value+'&idreserva='+document.formrese.idreserva.value+'&del=1','sthora.php');	

}


 function validarEmail(valor) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
return true
} else {
return false;
}
}

