// JavaScript Document

var now = new Date(); //now hace falta en los calendarios

now.setDate(now.getDate());

var sTomorrow = new Date();

sTomorrow.setDate(sTomorrow.getDate() + 1);



function enviaramigo() {

	document.location.href="http://www.eligehoteles.com/enviaramigo.htm?" + document.location.href;

}

function mailnobot(nm,dm)

{

   mailurl = "mailto:" + nm + "@" + dm;

   window.location = mailurl;

}

function agregar(){

   if ((navigator.appName=="Microsoft Internet Explorer") && 

         (parseInt(navigator.appVersion)>=4)) {

      var url="http://www.tarifasdehoteles.com/"; 

      var titulo="Central de Reservas de Hoteles Internacional - Grupo Elige Hoteles";

      window.external.AddFavorite(url,titulo);

   } else { 

      //if(navigator.appName == "Netscape") 

      //   alert("Presione Crtl+D para agregar este sitio a sus Bookmarks"); 

	  if(navigator.appName == "Netscape")

		window.sidebar.addPanel("Central de Reservas de Hoteles Internacional - Grupo Elige Hoteles", "http://www.tarifasdehoteles.com/","");

   }

}

function Right(str, n)

/***

		IN: str - the string we are RIGHTing

			n - the number of characters we want to return



		RETVAL: n characters from the right side of the string

***/

{

		if (n <= 0)     // Invalid bound, return blank string

		   return "";

		else if (n > String(str).length)   // Invalid bound, return

		   return str;                     // entire string

		else { // Valid bound, return appropriate substring

		   var iLen = String(str).length;

		   return String(str).substring(iLen, iLen - n);

		}

}

/*a partir de aquí la función AJAX de carga de ciudades de ña base de datos*/

function CrearObjetoAjax(){		//Creacion del objeto AJAX

	if(typeof(XMLHttpRequest) != 'undefined'){

		try{

			var satelite = new XMLHttpRequest();

		}catch(e){ }

	}else{

		try{

			var satelite = new ActiveXObject('Microsoft.XMLHTTP');

		}catch(e){

			var satelite = new ActiveXObject('Msxml2.XMLHTTP');

		}

	}

	return satelite;

}

var ajax_ciudades= CrearObjetoAjax();

function cerrar(){
	setTimeout("ocultarHoteles()", 300);
}
function quitarCapa(o){

	if(o.value.length>0){

		document.getElementById('divciudades').style.visibility = "visible";

		var camino="xmlrpc/GetCities.php?destino=" + o.value;

		ajax_ciudades.open('get',camino,true);

		ajax_ciudades.onreadystatechange = writeCities;

		ajax_ciudades.send(null);

	} else {

		document.getElementById('divciudades').style.visibility = "hidden";

		document.getElementById('divciudades').innerHTML="";

	}

	//alert(o.value.length);

}

function writeCities(){

	if(ajax_ciudades.readyState == 4) {	

		if (ajax_ciudades.status == 200) {

			var txtCiudades = ajax_ciudades.responseText;

			document.getElementById('divciudades').innerHTML=txtCiudades;

		}

	}

}


var ajax_hoteles= CrearObjetoAjax();

function cargahoteles(o,id_idioma){
	
	if(o.value.length>=1){
	
		document.getElementById('divhoteles').style.visibility = "visible";
		document.getElementById('divhoteles').style.display = "block";
		var tipo_alojamiento=document.getElementById('seleccionAlojamiento').value;

		var camino="xmlrpc/GetHoteles.php?destino=" + o.value+"&id_idioma="+id_idioma+"&id_alojamiento="+tipo_alojamiento;

		ajax_hoteles.open('get',camino,true);

		ajax_hoteles.onreadystatechange = writeHoteles;

		ajax_hoteles.send(null);

	} else {
		

		document.getElementById('divhoteles').style.visibility = "hidden";

		document.getElementById('divhoteles').innerHTML="";

	}

	//alert(o.value.length);

}

function writeHoteles(){

	if(ajax_hoteles.readyState == 4) {	

		if (ajax_hoteles.status == 200) {

			var txtHoteles = ajax_hoteles.responseText;

			document.getElementById('divhoteles').innerHTML=txtHoteles;

		}

	}

}


function ocultarHoteles(){
		if(chiv==0){
			document.getElementById('divhoteles').style.visibility = "hidden";
		}
}

function habilitarHoteles(){
	chiv=0;
	document.getElementById('divhoteles').style.visibility = "visible";
}

//////////////////por localidad///////////////////
function CrearObjetoAjax(){		//Creacion del objeto AJAX

	if(typeof(XMLHttpRequest) != 'undefined'){

		try{

			var satelite = new XMLHttpRequest();

		}catch(e){ }

	}else{

		try{

			var satelite = new ActiveXObject('Microsoft.XMLHTTP');

		}catch(e){

			var satelite = new ActiveXObject('Msxml2.XMLHTTP');

		}

	}

	return satelite;

}

var ajax_ciudades= CrearObjetoAjax();

function cerrar2(){
	setTimeout("ocultarLocalidades()", 300);
}
function quitarCapa(o){

	if(o.value.length>3){

		document.getElementById('divciudades').style.visibility = "visible";

		var camino="xmlrpc/GetCities.php?destino=" + o.value;

		ajax_ciudades.open('get',camino,true);

		ajax_ciudades.onreadystatechange = writeCities;

		ajax_ciudades.send(null);

	} else {

		document.getElementById('divciudades').style.visibility = "hidden";

		document.getElementById('divciudades').innerHTML="";

	}

	//alert(o.value.length);

}

function writeCities(){

	if(ajax_ciudades.readyState == 4) {	

		if (ajax_ciudades.status == 200) {

			var txtCiudades = ajax_ciudades.responseText;

			document.getElementById('divciudades').innerHTML=txtCiudades;

		}

	}

}


var ajax_Localidades= CrearObjetoAjax();

function cargaLocalidades(o,id_idioma){
	
	if(o.value.length>=3){
	
		document.getElementById('divLocalidades').style.visibility = "visible";
		document.getElementById('divLocalidades').style.display = "block";
		var tipo_alojamiento=document.getElementById('seleccionAlojamiento').value;

		var camino="xmlrpc/GetLocalidades.php?destino=" + o.value;

		ajax_Localidades.open('get',camino,true);

		ajax_Localidades.onreadystatechange = writeLocalidades;

		ajax_Localidades.send(null);

	} else {
		

		document.getElementById('divLocalidades').style.visibility = "hidden";

		document.getElementById('divLocalidades').innerHTML="";

	}

	//alert(o.value.length);

}

function writeLocalidades(){

	if(ajax_Localidades.readyState == 4) {	

		if (ajax_Localidades.status == 200) {

			var txtLocalidades = ajax_Localidades.responseText;

			document.getElementById('divLocalidades').innerHTML=txtLocalidades;

		}

	}

}


function ocultarLocalidades(){
		
			document.getElementById('divLocalidades').style.visibility = "hidden";
		
}

function habilitarLocalidades(){
	
	document.getElementById('divLocalidades').style.visibility = "visible";
}
////////////fin por localidades//////////

function abreventana(url,nombre,propiedades) {

  window.open(url,nombre,propiedades);

}

function aleatorio(inferior,superior){
    		numPosibilidades = superior - inferior
    		aleat = Math.random() * numPosibilidades
    		aleat = Math.round(aleat)
    		return parseInt(inferior) + aleat
} 
function youtubealeatorio(num_youtube){
	switch( num_youtube) {
		case 1 : {return '<object><param name="movie" value="http://www.youtube.com/v/Ic6O8H2t2iY&hl=en&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/Ic6O8H2t2iY&hl=en&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" class="svideosportada"></embed></object>';break;}
		case 2 : {return '<object><param name="movie" value="http://www.youtube.com/v/L8QbcN60eCs&hl=en&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/L8QbcN60eCs&hl=en&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" class="svideosportada"></embed></object>';break;}
		case 3 : {return '<object><param name="movie" value="http://www.youtube.com/v/6MJeDCtbPYI&hl=en&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/6MJeDCtbPYI&hl=en&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" class="svideosportada"></embed></object>';break;}
		case 4 : {return '<object><param name="movie" value="http://www.youtube.com/v/hgXLa_8Aggc&hl=en&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/hgXLa_8Aggc&hl=en&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" class="svideosportada"></embed></object>';break;}
		case 5 : {return '<object><param name="movie" value="http://www.youtube.com/v/nSqI9_pmqOc&hl=en&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/nSqI9_pmqOc&hl=en&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" class="svideosportada"></embed>	</object>';break;}
		case 6 : {return '<object><param name="movie" value="http://www.youtube.com/v/qpG3_yXoeC0&hl=en&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/qpG3_yXoeC0&hl=en&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" class="svideosportada"></embed></object>';break;}
		case 7 : {return '<object><param name="movie" value="http://www.youtube.com/v/ANFbLXSeT1M&hl=en&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ANFbLXSeT1M&hl=en&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" class="svideosportada"></embed></object>';break;}
		case 8 : {return '<object><param name="movie" value="http://www.youtube.com/v/WC5HZ00MgkU&hl=en&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/WC5HZ00MgkU&hl=en&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" class="svideosportada"></embed>	</object>';break;}
		case 9 : {return '<object><param name="movie" value="http://www.youtube.com/v/DqeoNKmCzmM&hl=en&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/DqeoNKmCzmM&hl=en&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" class="svideosportada"></embed></object>';break;}
		case 10 : {return '<object><param name="movie" value="http://www.youtube.com/v/q7KGJWdJ4ZI&hl=en&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/q7KGJWdJ4ZI&hl=en&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" class="svideosportada"></embed></object>';break;}
 		
  	default: { return '<object><param name="movie" value="http://www.youtube.com/v/q7KGJWdJ4ZI&hl=en&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/q7KGJWdJ4ZI&hl=en&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" class="svideosportada"></embed></object>'; }
	}
	
}


var slideCache = new Array();
function RunSlideShow(pictureName,imageFiles,displaySecs)
{
	var imageSeparator = imageFiles.indexOf(";");
	var nextImagen = imageFiles.substring(0,imageSeparator);
	if (document.all)
	{
		document.getElementById(pictureName).style.filter="blendTrans(duration=2)";
		document.getElementById(pictureName).filters.blendTrans.Apply();
	}
	document.getElementById(pictureName).src = nextImagen;
	if (document.all)
	{
		document.getElementById(pictureName).filters.blendTrans.Play();
	}
	var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length)+ ';' + nextImagen;
	setTimeout("RunSlideShow('"+pictureName+"','"+futureImages+"',"+displaySecs+")",displaySecs*1000);
	// cambio de imagen.
	imageSeparator = futureImages.indexOf(";");
	nextImagen = futureImages.substring(0,imageSeparator);
	if (slideCache[nextImagen] == null) {
		slideCache[nextImagen] = new Image;
		slideCache[nextImagen].src = nextImagen;
	}
}
/*Funcion para eliminar las opciones de Pamplona(ciudad) y Tudela(ciudad) del menu de seleccion
si se ha elegido el tipo de alojamiento Hoteles rurales*/

