// JavaScript Document

function cambiarIdioma() {
	$('id0').value = $F('select_idioma');
	$('site_form').submit();
}

function set_section(le1, id1, le2, id2, le3, id3, le4, id4) {

	$('le1').value = (le1 != undefined ? le1 : $F('le1')); 	
	$('id1').value = (id1 != undefined ? id1 : $F('id1')); 	
	$('le2').value = (le2 != undefined ? le2 : $F('le2')); 	
	$('id2').value = (id2 != undefined ? id2 : $F('id2')); 	
	$('le3').value = (le3 != undefined ? le3 : $F('le3')); 	
	$('id3').value = (id3 != undefined ? id3 : $F('id3')); 	
	$('le4').value = (le4 != undefined ? le4 : $F('le4')); 	
	$('id4').value = (id4 != undefined ? id4 : $F('id4')); 	
	
	$('site_form').submit();	
		
	
}

function openReserva(url) {
	window.open(url, 'reservas', 'toolbar=no, menubar=no, resizable=no, width=800, height=400, scrollbars=yes');
}

function initSite() {
	
	initLightbox();
	simplePreload('img/book-bg-over.gif','img/contactoOver.gif','img/homeOver.gif');	
	//$('select_idioma').onchange = cambiarIdioma;
}

	function simplePreload() { 
		var args = simplePreload.arguments;
		document.imageArray = new Array(args.length);
		for(var i=0; i<args.length; i++){
			document.imageArray[i] = new Image;
			document.imageArray[i].src = args[i];
		}
	}

Event.observe(window, 'load', initSite, false);

function hide_anchor(e, visible) {

	if (e.className=="selected") return 0;
	var as = e.getElementsByTagName("A");	
	if(visible) {
		as[0].style.backgroundColor = "#0084CB";
	} else {
		as[0].style.background="none";
	}

}

function show_desc() {
	$("main_desc").style.overflow="visible";	
}

function destinos_by_region(id_region, id_idioma,seccion) {
	
	if(id_region == 0) {top.location.href ="index.php?id0="+id_idioma + "&le1=2";}
	$("sel_destino_loading").style.display = "block";
	$("div_sel_destino").style.display = "none";
	
	switch(seccion) {
		case 2:
			var url = "funciones/destinos_por_region_fn.php?rnd="+Math.random();
			break;
		case 6:
			var url = "funciones/destinos_por_region_actividades_fn.php?rnd="+Math.random();
			break;		
		case 7:
			var url = "funciones/destinos_por_region_hostels_fn.php?rnd="+Math.random();
			break;		
	}
	var pars = "id_region=" + id_region + "&id_idioma=" + id_idioma;
	
	new Ajax.Request(url, {
					 parameters:pars, 
					 method:"post", 
					 onComplete: function(req) {
						 $("sel_destino_loading").style.display = "none";
						 //alert(req.responseText);
						 var jsn = JSON.parse(req.responseText);
						 if (jsn.has_errors !=0 ) {
							alert(jsn.msg);
						 } else {
							//alert(jsn.combo.length);
							while( $("sel_destino").options.length>0) {
								$("sel_destino").remove(0);
								
							}
							for(var i=0; i < jsn.combo.length; i++) {
								var opt = document.createElement("OPTION")
								opt.value =jsn.combo[i].value;
								opt.text = jsn.combo[i].texto;
								if(document.all){ //IEca
									$("sel_destino").add(opt)
								}else{
									$("sel_destino").appendChild(opt)
								}  								
							}
							$("div_sel_destino").style.display = "block";
						 }
					 }
					 });
}

function destinos_by_region(id_region, id_idioma,seccion) {
	
	if(id_region == 0) {return 0;}//top.location.href ="index.php?id0="+id_idioma + "&le1=2";
	$("sel_destino_loading").style.display = "block";
	$("div_sel_destino").style.display = "none";
	
	switch(seccion) {
		case 2:
			var url = "funciones/destinos_por_region_fn.php?rnd="+Math.random();
			break;
		case 6:
			var url = "funciones/destinos_por_region_actividades_fn.php?rnd="+Math.random();
			break;		
		case 7:
			var url = "funciones/destinos_por_region_hostels_fn.php?rnd="+Math.random();
			break;	
		case 8:
			var url = "funciones/destinos_por_region_galerias_fn.php?rnd="+Math.random();
			break;				
	}
	var pars = "id_region=" + id_region + "&id_idioma=" + id_idioma;
	
	new Ajax.Request(url, {
					 parameters:pars, 
					 method:"post", 
					 onComplete: function(req) {
						 $("sel_destino_loading").style.display = "none";
						 //alert(req.responseText);
						 var jsn = JSON.parse(req.responseText);
						 if (jsn.has_errors !=0 ) {
							alert(jsn.msg);
						 } else {
							//alert(jsn.combo.length);
							while( $("sel_destino").options.length>0) {
								$("sel_destino").remove(0);
								
							}
							for(var i=0; i < jsn.combo.length; i++) {
								var opt = document.createElement("OPTION")
								opt.value =jsn.combo[i].value;
								opt.text = jsn.combo[i].texto;
								if(document.all){ //IEca
									$("sel_destino").add(opt)
								}else{
									$("sel_destino").appendChild(opt)
								}  								
							}
							$("div_sel_destino").style.display = "block";
						 }
					 }
					 });
}

function setRegion(idioma, region) {
	document.location.href = "region.php?lang="+idioma+"&rgn="+region;
}

function showGallery(idioma,region) {
	document.location.href = "region_galeria.php?idioma="+idioma+"&rgn="+region;
}
