/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

Comportamiento reservacion-en.js

version: 1.1

author: Miguel Behr L.

email: miguelbehr@gmail.com

–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

var xmlHttp

var xml = null;

var root="http://www.latortuga.com.ec/";

//var root="http://pegasus:8080/cabanas-la-tortuga/";



function resetNombre(){

	if(document.getElementById("Nombre").value=="Completo"){

		document.getElementById("Nombre").value="";

	}

}

function sendASK()

{
	var nombre_r=document.getElementById("nombre_r").value;

	var diain=document.getElementById("diain").value;

	var mesin=document.getElementById("mesin").value;
	
	var yearin=document.getElementById("yearin").value;

	var diaout=document.getElementById("diaout").value;

	var mesout=document.getElementById("mesout").value;
	
	var yearout=document.getElementById("yearout").value;

	var adultos=document.getElementById("txtadultos").value;

	var ninos=document.getElementById("txtninos").value;

	var payopt=document.getElementById("payopt").value;

	var email=document.getElementById("txtemailask").value;

	var comentario=document.getElementById("txtcomentariosask").value;

		

	if(email!=""){		

		xmlHttp=GetXmlHttpObject()

		if (xmlHttp==null)

		{

			alert ("Browser does not support HTTP Request");

			return;

		}

		document.getElementById("mensaje-formulario").style.display="block";

		document.getElementById("mensaje-formulario").className="mensaje";

		document.getElementById("mensaje-formulario").innerHTML="Please wait...";

		var url=root+"_functions/reservacion.php";		

		

		url=url+"?nombre_r="+nombre_r;
		
		url=url+"&diain="+diain;

		url=url+"&mesin="+mesin;
		
		url=url+"&yearin="+yearin;

		url=url+"&diaout="+diaout;

		url=url+"&mesout="+mesout;
		
		url=url+"&yearout="+yearout;

		url=url+"&ninos="+ninos;

		url=url+"&adultos="+adultos;

		url=url+"&payopt="+payopt;

		url=url+"&email="+email;

		url=url+"&comentario="+comentario;

			

		xmlHttp.onreadystatechange=stateChanged;

		xmlHttp.open("GET",url,true);

		xmlHttp.send(null);

		

			

	}else{

		document.getElementById("mensaje-formulario").style.display="block";

		document.getElementById("mensaje-formulario").className="mensaje-error";

		document.getElementById("mensaje-formulario").innerHTML="You must fill required fields.";

	}

}

function stateChanged() 

{ 		

	if(xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")

	{		

		if(xmlHttp.status == 200){		

			xml = xmlHttp.responseXML;			

			ManejarRespuestas()

		}					

	}else{		

	}	

}

function ManejarRespuestas(){

	document.getElementById("mensaje-formulario").innerHTML=xml.getElementsByTagName("mensaje")[0].childNodes[0].nodeValue;

	document.getElementById("mensaje-formulario").className=xml.getElementsByTagName("class")[0].childNodes[0].nodeValue;

	if(xml.getElementsByTagName("estado")[0].childNodes[0].nodeValue=="OK")

	{

		document.getElementById("form-reservacion").reset();

	}

	if(xml.getElementsByTagName("mensaje")[0].childNodes[0].nodeValue=="Thanks.")

	{

		document.getElementById("mensaje-formulario").innerHTML="Thank you for your interest!<br />			    <a href=\"javascript:sendASK();\">ask again</a>";

		

		document.getElementById("btnsendreservacion").style.display="none";

	}



}



function enviarSolicitud(){

	var nombre_r=document.getElementById("nombre_r").value;
			
	var diain=document.getElementById("diain").value;

	var mesin=document.getElementById("mesin").value;
	
	var yearin=document.getElementById("yearin").value;

	var diaout=document.getElementById("diaout").value;

	var mesout=document.getElementById("mesout").value;
	
	var yearout=document.getElementById("yearout").value;

	var adultos=document.getElementById("txtadultos").value;

	var ninos=document.getElementById("txtninos").value;

	var payopt=document.getElementById("payopt").value;

	var email=document.getElementById("txtemailask").value;

	var comentario=document.getElementById("txtcomentariosask").value;

		

	if(email!=""){		

		xmlHttp=GetXmlHttpObject()

		if (xmlHttp==null)

		{

			alert ("Browser does not support HTTP Request");

			return;

		}

		document.getElementById("mensaje-formulario").style.display="block";

		document.getElementById("mensaje-formulario").className="mensaje";

		document.getElementById("mensaje-formulario").innerHTML="Por favor espere...";

		var url=root+"_functions/reservacion-es.php";		

		

		url=url+"?nombre_r="+nombre_r;
		
		url=url+"&diain="+diain;

		url=url+"&mesin="+mesin;
		
		url=url+"&yearin="+yearin;

		url=url+"&diaout="+diaout;

		url=url+"&mesout="+mesout;
		
		url=url+"&yearout="+yearout;

		url=url+"&ninos="+ninos;

		url=url+"&adultos="+adultos;

		url=url+"&payopt="+payopt;

		url=url+"&email="+email;

		url=url+"&comentario="+comentario;

			

		xmlHttp.onreadystatechange=stateChangedEs;

		xmlHttp.open("GET",url,true);

		xmlHttp.send(null);

	}else{

		document.getElementById("mensaje-formulario").style.display="block";

		document.getElementById("mensaje-formulario").className="mensaje-error";

		document.getElementById("mensaje-formulario").innerHTML="Debe llenar los campos requeridos.";

	}

}

function stateChangedEs() 

{ 		

	if(xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")

	{		

		if(xmlHttp.status == 200){		

			xml = xmlHttp.responseXML;			

			ManejarRespuestasEs()

		}					

	}else{		

	}	

}

function ManejarRespuestasEs(){

	document.getElementById("mensaje-formulario").innerHTML=xml.getElementsByTagName("mensaje")[0].childNodes[0].nodeValue;

	document.getElementById("mensaje-formulario").className=xml.getElementsByTagName("class")[0].childNodes[0].nodeValue;

	if(xml.getElementsByTagName("estado")[0].childNodes[0].nodeValue=="OK")

	{

		document.getElementById("form-reservacion").reset();

	}

	if(xml.getElementsByTagName("mensaje")[0].childNodes[0].nodeValue=="Thanks.")

	{

		document.getElementById("mensaje-formulario").innerHTML="Gracias por su interes!<br />			    <a href=\"javascript:enviarSolicitud();\">consulte de nuevo</a>";

		

		document.getElementById("btnsendreservacion").style.display="none";

	}



}

/*******************************************/

function showTerms(){

	mostrarFondo();

    if(document.getElementById("terminos")!=null){

        document.getElementById("terminos").style.display="block";

    }

	ocultarOpcionesForumulario();

        

}

function showPolicy(){

	mostrarFondo();

    if(document.getElementById("politicas")!=null){

        document.getElementById("politicas").style.display="block";

    }

	ocultarOpcionesForumulario();

        

}



/*********************************************/



function mostrarFondo(){

        var arrayPageSize = getPageSize();        

        document.getElementById("fondo").style.display="block";

        document.getElementById("fondo").style.height=arrayPageSize[1]+"px";

}

function ocultarFondo()

{

	mostrarOpcionesForumulario();

	document.getElementById("fondo").style.display="none";

	document.getElementById("fondo").style.height="0px";

}

function ocultar(){

    ocultarFondo();

    if(document.getElementById("mapa")!=null){

        document.getElementById("mapa").style.display="none";

    }

	if(document.getElementById("terminos")!=null){

        document.getElementById("terminos").style.display="none";

    }

	if(document.getElementById("politicas")!=null){

        document.getElementById("politicas").style.display="none";

    }

}

function getPageSize(){

	

	var xScroll, yScroll;

	

	if (window.innerHeight && window.scrollMaxY) {	

		xScroll = document.body.scrollWidth;

		yScroll = window.innerHeight + window.scrollMaxY;

	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac

		xScroll = document.body.scrollWidth;

		yScroll = document.body.scrollHeight;

	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari

		xScroll = document.body.offsetWidth;

		yScroll = document.body.offsetHeight;

	}

	

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer

		windowWidth = self.innerWidth;

		windowHeight = self.innerHeight;

	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode

		windowWidth = document.documentElement.clientWidth;

		windowHeight = document.documentElement.clientHeight;

	} else if (document.body) { // other Explorers

		windowWidth = document.body.clientWidth;

		windowHeight = document.body.clientHeight;

	}	

	

	// for small pages with total height less then height of the viewport

	if(yScroll < windowHeight){

		pageHeight = windowHeight;

	} else { 

		pageHeight = yScroll;

	}



	// for small pages with total width less then width of the viewport

	if(xScroll < windowWidth){	

		pageWidth = windowWidth;

	} else {

		pageWidth = xScroll;

	}



	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

	return arrayPageSize;

}



function ocultarOpcionesForumulario(){
	
	if(document.getElementById("nombre_r")!=null){

		document.getElementById("nombre_r").style.display="none";

	}
	if(document.getElementById("yearout")!=null){

		document.getElementById("yearout").style.display="none";

	}
		if(document.getElementById("yearin")!=null){

		document.getElementById("yearin").style.display="none";

	}
	if(document.getElementById("mesout")!=null){

		document.getElementById("mesout").style.display="none";

	}

		if(document.getElementById("mesin")!=null){

		document.getElementById("mesin").style.display="none";

	}

	if(document.getElementById("mesout")!=null){

		document.getElementById("mesout").style.display="none";

	}

	if(document.getElementById("diain")!=null){

		document.getElementById("diain").style.display="none";

	}

	if(document.getElementById("diaout")!=null){

		document.getElementById("diaout").style.display="none";

	}

	if(document.getElementById("payopt")!=null){

		document.getElementById("payopt").style.display="none";

	}

}

function mostrarOpcionesForumulario(){
	
	if(document.getElementById("yearin")!=null){

		document.getElementById("yearin").style.display="inline";

	}

	if(document.getElementById("yearout")!=null){

		document.getElementById("yearout").style.display="inline";

	}

	if(document.getElementById("mesin")!=null){

		document.getElementById("mesin").style.display="inline";

	}

	if(document.getElementById("mesout")!=null){

		document.getElementById("mesout").style.display="inline";

	}

	if(document.getElementById("diain")!=null){

		document.getElementById("diain").style.display="inline";

	}

	if(document.getElementById("diaout")!=null){

		document.getElementById("diaout").style.display="inline";

	}

	if(document.getElementById("payopt")!=null){

		document.getElementById("payopt").style.display="inline";

	}

}


















