NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
NS6 = (!IE4 && document.getElementById) ? 1 : 0;

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function iniciar0() {
	MM_preloadImages('img/idioma_es_on.gif','img/idioma_en_on.gif','img/idioma_fr_on.gif','img/idioma_de_on.gif','img/idioma_it_on.gif');
	MM_preloadImages('img/cab_es.gif','img/cab_en.gif','img/cab_de.gif','img/cab_fr.gif','img/cab_it.gif');
	MM_preloadImages('img/es/btn_inicio_es_on.gif','img/es/btn_ofertas_es_on.gif','img/es/btn_reservas_es_on.gif','img/es/btn_catalogo_es_on.gif','img/es/btn_clientes_es_on.gif','img/es/btn_noticias_es_on.gif','img/es/btn_admin_es_on.gif');
}
function iniciar1() {
	MM_preloadImages('img/idioma_es_on.gif','img/idioma_en_on.gif','img/idioma_fr_on.gif','img/idioma_de_on.gif','img/idioma_it_on.gif');
	MM_preloadImages('img/cab_es.gif','img/cab_en.gif','img/cab_de.gif','img/cab_fr.gif','img/cab_it.gif');
	MM_preloadImages('img/es/btn_inicio_es_on.gif','img/es/btn_ofertas_es_on.gif','img/es/btn_reservas_es_on.gif','img/es/btn_catalogo_es_on.gif','img/es/btn_clientes_es_on.gif','img/es/btn_noticias_es_on.gif','img/es/btn_admin_es_on.gif');
}
function iniciar2() {
	MM_preloadImages('img/idioma_es_on.gif','img/idioma_en_on.gif','img/idioma_fr_on.gif','img/idioma_de_on.gif','img/idioma_it_on.gif');
	MM_preloadImages('img/cab_es.gif','img/cab_en.gif','img/cab_de.gif','img/cab_fr.gif','img/cab_it.gif');
	MM_preloadImages('img/es/btn_inicio_es_on.gif','img/es/btn_ofertas_es_on.gif','img/es/btn_reservas_es_on.gif','img/es/btn_catalogo_es_on.gif','img/es/btn_clientes_es_on.gif','img/es/btn_noticias_es_on.gif','img/es/btn_admin_es_on.gif');
}
function iniciar3() {
	MM_preloadImages('img/idioma_es_on.gif','img/idioma_en_on.gif','img/idioma_fr_on.gif','img/idioma_de_on.gif','img/idioma_it_on.gif');
	MM_preloadImages('img/cab_es.gif','img/cab_en.gif','img/cab_de.gif','img/cab_fr.gif','img/cab_it.gif');
	MM_preloadImages('img/es/btn_inicio_es_on.gif','img/es/btn_ofertas_es_on.gif','img/es/btn_reservas_es_on.gif','img/es/btn_catalogo_es_on.gif','img/es/btn_clientes_es_on.gif','img/es/btn_noticias_es_on.gif','img/es/btn_admin_es_on.gif');
}
function iniciar4() {
	MM_preloadImages('img/idioma_es_on.gif','img/idioma_en_on.gif','img/idioma_fr_on.gif','img/idioma_de_on.gif','img/idioma_it_on.gif');
	MM_preloadImages('img/cab_es.gif','img/cab_en.gif','img/cab_de.gif','img/cab_fr.gif','img/cab_it.gif');
	MM_preloadImages('img/es/btn_inicio_es_on.gif','img/es/btn_ofertas_es_on.gif','img/es/btn_reservas_es_on.gif','img/es/btn_catalogo_es_on.gif','img/es/btn_clientes_es_on.gif','img/es/btn_noticias_es_on.gif','img/es/btn_admin_es_on.gif');
}
function iniciar5() {
	MM_preloadImages('img/idioma_es_on.gif','img/idioma_en_on.gif','img/idioma_fr_on.gif','img/idioma_de_on.gif','img/idioma_it_on.gif');
	MM_preloadImages('img/cab_es.gif','img/cab_en.gif','img/cab_de.gif','img/cab_fr.gif','img/cab_it.gif');
	MM_preloadImages('img/es/btn_inicio_es_on.gif','img/es/btn_ofertas_es_on.gif','img/es/btn_reservas_es_on.gif','img/es/btn_catalogo_es_on.gif','img/es/btn_clientes_es_on.gif','img/es/btn_noticias_es_on.gif','img/es/btn_admin_es_on.gif');
}

function chidio(qui) {
	document.configurar.idioma.value=qui;
	document.configurar.submit();
}

function veroferta(edi,acomod,periodo,aon) {
	switch (aon) {
		case 1:document.configurar.action="ofertas_fichaa.php";break;
		case 2:document.configurar.action="ofertas_fichab.php";break;
	}
	document.configurar.p_codedi.value=edi;
	document.configurar.p_periodo.value=periodo;
	document.configurar.p_acomod.value=acomod;
	document.configurar.submit();
}

function veroferta2(aon) {
	switch (aon) {
		case 1:document.configurar.action="ofertas_fichaa.php";break;
		case 2:document.configurar.action="ofertas_fichab.php";break;
		case 3:document.configurar.action="ofertas_fichac.php";break;
	}
	document.configurar.submit();
}

function veredi(qui, aon) {
	switch (aon) {
		case 1:document.configurar.action="catalogo_ficha.php";break;
		case 2:document.configurar.action="catalogo_fichab.php";break;
		case 3:document.configurar.action="catalogo_fichac.php";break;
		case 4:document.configurar.action="catalogo_fichad.php";break;
		case 5:document.configurar.action="catalogo_ficha.php";break;
	}
	document.configurar.p_codedi.value=qui;
	document.configurar.submit();
}

function veredi2(aon) {
	switch (aon) {
		case 1:document.configurar.action="catalogo_ficha.php";break;
		case 2:document.configurar.action="catalogo_fichab.php";break;
		case 3:document.configurar.action="catalogo_fichac.php";break;
		case 4:document.configurar.action="catalogo_fichad.php";break;
		case 5:document.configurar.action="catalogo_fichae.php";break;
	}
	document.configurar.submit();
}

function anar_cap(file) {
	document.configurar.action = file;
	document.configurar.submit();
}

function change_pag(num) {
	document.configurar.p_numpag.value = num;
	document.configurar.submit();
}

function change_par(nompar, valpar, sometre) {
	document.getElementById(nompar).value = valpar;
	//alert(nompar+"\nacomod="+document.configurar.p_acomod.value+"datmes="+document.configurar.p_datmes.value+"\nacomod="+document.getElementById("p_acomod").value+"datmes="+document.getElementById("p_datmes").value);
	if (sometre) document.configurar.submit();
}

function updatecat() {
	Refer1=document.buscadoredis.p_tipoalo;
	Refer2=document.buscadoredis.p_categ;
	totaltipo = categories.length;
	totalcat = Refer2.length;
	for (i=1;i<totalcat;i++) {
		var remChld = Refer2.options[1];
		Refer2.removeChild(remChld);
	}
	tipo = Refer1[Refer1.selectedIndex].value;
	for (i=0,i2=1;i<totaltipo;i++) {
		if (categories[i][0]==tipo) {
			Refer2.options[i2] = new Option(categories[i][2],categories[i][1]);
			if (categories[i][3]) Refer2.options.selectedIndex=i2;
			i2++;
		}
	}
}


// FERNANDO: 22-06-2007
// Cada vez que se cambia un país, se actualzia la lista de destino y zonas.
function updatecontry(nomform) {

	Refer1=eval("document."+nomform+".p_pais");
	Refer2=eval("document."+nomform+".p_desti");
	Refer3=eval("document."+nomform+".p_zona");

	totalzonestur = destinostur.length;
	total2 = Refer2.length;
	tipo = Refer1[Refer1.selectedIndex].value;

	// Borramos todos los elementos de la lista de destinos.
	for (i=1;i<total2;i++) {
		var remChld = Refer2.options[1];
		Refer2.removeChild(remChld);
	}

	// Recargamos los nuevos destinos.
	for (i=0,i2=1;i<totalzonestur;i++) {
		if (destinostur[i][0]==tipo) {
			Refer2.options[i2] = new Option(destinostur[i][2],destinostur[i][1]);
			if (destinostur[i][3]) Refer2.options.selectedIndex=i2;
			i2++;
		}
	}

	// Actualizamos ahora las zonas.
	updatezones(nomform);
}
// FIN CAMBIO


function updatezones(nomform) {
	
	Refer1=eval("document."+nomform+".p_desti");
	Refer2=eval("document."+nomform+".p_zona");
	totalzonestur = zonestur.length;
	total2 = Refer2.length;
	tipo = Refer1[Refer1.selectedIndex].value;
	
	for (i=1;i<total2;i++) {
		var remChld = Refer2.options[1];
		Refer2.removeChild(remChld);
	}
	for (i=0,i2=1;i<totalzonestur;i++) {
		
		if (zonestur[i][0]==tipo) {			
			Refer2.options[i2] = new Option(zonestur[i][2],zonestur[i][1]);
			if (zonestur[i][3]) Refer2.options.selectedIndex=i2;
			i2++;
		}
	
	}
}


function clearformbus()  {
	document.buscadoredis.reset();
	document.buscadoredis.p_edificio.value="";
	document.buscadoredis.p_tipoalo.selectedIndex=0;
	document.buscadoredis.p_desti.selectedIndex=0;
	for (i=0;i<document.buscadoredis.p_totalserv.value;i++) {
		Refer= eval("document.buscadoredis.p_serv"+i);
		Refer.checked = false;
	}
}

function hideshowdos(which) {
	if (!(NS6 ||IE4)) {return;}
	else {
		if (document.getElementById) oWhich = eval ("document.getElementById('" + which + "')");
		else oWhich = eval ("document.all." + which);
	}
	window.focus();
	if (oWhich.style.display=="none") oWhich.style.display=""; else oWhich.style.display="none";
}

function mhabit(maxhab) {
	if (!(NS6 ||IE4)) {return;}
	else {
		itm = document.reservador.p_numhab.value;
		for (i1=0;i1<maxhab;i1++) {
			if (document.getElementById) oWhich = eval ("document.getElementById('hab" + i1 + "')");
			else oWhich = eval ("document.all.hab" + i1);
			if (i1<itm) oWhich.style.display=""; else oWhich.style.display="none";
		}
	}
}

function mspbedn_old(quihab, maxnin) { // Funció vella amb selects per edat
	ref = eval("document.reservador.p_h"+quihab+"nn");
	itm = ref.value;
	for (i1=0;i1<maxnin;i1++) {
		ref2 =  eval("document.reservador.p_h"+quihab+"nen"+i1)
		total = ref2.length;
		if (i1 >= itm) {
			if (total > 1 ) {
				for (i2=1;i2<total;i2++) {
					var remChld = ref2.options[1];
					ref2.removeChild(remChld);
				}
				ref2[0] = new Option("-","");
				ref2.selectedIndex = 0;
			}
		}
		else {
			if (total == 1 ) {
				for (i2=0;i2<18;i2++) {
					ref2[i2] = new Option(i2,i2);
				}
				ref2.selectedIndex = 0;
			}
		}
	}
}

function mspbedn(quihab, maxnin) { // Funció nova amb inputs
	ref = eval("document.reservador.p_h"+quihab+"nn");
	itm = ref.value;

	for (i1=0;i1<maxnin;i1++) {
		ref2 =  eval("document.reservador.p_h"+quihab+"nen"+i1)
		ref2txt = document.getElementById("txtp_h"+quihab+"nen"+i1)
		if (i1 >= itm) {
			ref2.value = "";
			ref2.style.display = "none";
			ref2txt.style.display = "none";
			ref2.disabled = true;
		}
		else {
			if (ref2.value=="") {
				ref2.style.display = "";
				ref2txt.style.display = "";
				ref2.disabled = false;
			}
		}
	}
}


function IsNumeric(sText) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) IsNumber = false;
	}
	return IsNumber;
}

meses = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
function checkDate(lafecha) {
	var fecha = new String(lafecha);
	cad2=fecha.split('/');
	if (cad2.length!=3) return 0;
	if (!IsNumeric(cad2[0])||!IsNumeric(cad2[1])||!IsNumeric(cad2[2])) return 0;
	var myDateStr = cad2[0] + ' ' + meses[cad2[1]-1] + ' ' + cad2[2] +" 12:00:00";
	var myDate = new Date( myDateStr );
	var myDate_string = myDate.toGMTString();
	var myDate_array = myDate_string.split( ' ' );
	if ( myDate_array[2] != meses[cad2[1]-1] ) return 0;
	else return 1;
}

function compare(Dat1,Dat2) {
	var d1,d2;
	d1=Dat1.split('/');
	d2=Dat2.split('/');

	var Date1 = new Date(d1[2],d1[1]-1,d1[0]);
	var Date2 = new Date(d2[2],d2[1]-1,d2[0]);
	if (Date1 > Date2) return 1;
	else return 0;
}


function difdies(Dat1,Dat2) {
	var d1, d2;
	d1=Dat1.split('/');
	d2=Dat2.split('/');

	var Date1 = new Date(d1[2],d1[1]-1,d1[0]);
	var Date2 = new Date(d2[2],d2[1]-1,d2[0]);
	return (Date2-Date1);
}

function sumdies(Dat1,dif) {
	var d1,d2;
	d1=Dat1.split('/');
	var Date1 = new Date(d1[2],d1[1]-1,eval(d1[0])+eval(dif), 12, 0 , 0);
	if (Date1.getMonth() > 8) d2 = Date1.getDate()+"/"+(Date1.getMonth()+1)+"/"+eval(Date1.getYear()+1900*NS6);
	else d2 = Date1.getDate()+"/0"+(Date1.getMonth()+1)+"/"+eval(Date1.getYear()+1900*NS6);
	return d2;
}

function revisa_radlist(nomform,lalistarad) {
	var error="",i=1,i2,ok=true,habok,sortir,ref,acok = true,lastvalue="",elvalue,elvalues;
	var lalista = lalistarad.split('/');
	var tl = lalista.length - 1;
	for (;i<tl;i++) {
		habok = false;
		for (sortir=false,i2=0;!sortir && !habok;i2++) {
			ref = (eval("document."+nomform+"."+lalista[i]+"[i2]" ));
			if (!ref && !i2) ref = (eval("document."+nomform+"."+lalista[i]));
			if (!ref) sortir = true; // Hem examinat tots
			else {
				if (ref.checked) {
					elvalues = ref.value.split('_');
					if (elvalues.length > 1) {
						elvalue = (elvalues[1].split(":"))[0];
					}
					else elvalue = "A";
					if (lastvalue=="") lastvalue = elvalue;
					else {
						if (lastvalue != elvalue) acok = false;
					}
					habok=true;
				}
			}
		}

		if (!habok) {error += errors[9]+" "+i+".\n";ok=false;}
	}
	if (!acok) {error += errors[10];ok=false;}
	if (!ok) {alert(error);return (false);}
	ref = eval("document."+nomform+".p_regimen");
	switch (lastvalue) {
		case "0":ref.value="T";break;
		case "1":ref.value="C";break;
		case "2":ref.value="M";break;
		case "3":ref.value="D";break;
	}
	return(true);
}

function revisapwd(nomform, revisarlog) {
	var error="";
	if (revisarlog==1) {
		ref0 = (eval("document."+nomform+".agenlog"));
		if (ref0.value.length < 5) error += errors[21];
	}
	if (revisarlog==2) {
		qui = (eval("document."+nomform+".qui.value"));
		if (!qui) return(true);
		ref1 = (eval("document."+nomform+".pwd"+qui+"_1"));
		ref2 = (eval("document."+nomform+".pwd"+qui+"_2"));
	}
	else {
		ref1 = (eval("document."+nomform+".pwd1"));
		ref2 = (eval("document."+nomform+".pwd2"));
	}
	if (ref1.value.length < 5) error += errors[19];
	else {
		if (ref1.value != ref2.value) error += errors[20];
	}
	if (error!="") {alert(error);return (false);}
	return(true);
}

function Cancelar_Reserva(id_reserva,localizador,gastos,dias,origen) {
	if (dias < 7) {
		alert("Para la cancelación de esta reserva debe ponerse en contacto con SIDERES.");
	}
	else {
		mensaje_confirmacion = 'Ha elegido usted cancelar la reserva con localizador '+localizador+'.\n\n';
		if (gastos != 0) mensaje_confirmacion +='Los gastos por cancelación de está reserva serán de '+gastos+' €.\n\n\n';
		else mensaje_confirmacion += '\n';
		mensaje_confirmacion +='Si está seguro de continuar con la cancelación pulse el botón ACEPTAR.\n';
		mensaje_confirmacion +='De lo contrario, pulse el botón CANCELAR.\n';

		if (confirm(mensaje_confirmacion)) window.location = 'reservas_admincancelar.php?id='+id_reserva+'&origen='+origen;
	}

}



// -------------------------------------------------------------------------------------------------------------------
// FERNANDO... para pintar bonitos los precios :)
// 15/05/2008
// -------------------------------------------------------------------------------------------------------------------
function FormatNumerico(Valor, SepMil, SepDec, NumDec) {
	//Comprobamos si viene con decimales y separamos el valor entero y el decimal
	var ValorEntero;
	var ValorEntero2 = "";
	var ValorDecimal = "";
	var arrayNum = Valor.toString().split(".");

	ValorEntero = arrayNum[0].toString();
	if (arrayNum.length == 2) {
		ValorDecimal = arrayNum[1].toString();
		ValorDecimal = ValorDecimal.substring(0,NumDec)
	} else
	ValorDecimal = "";

	for (var con = ValorDecimal.length; con < NumDec; con++) ValorDecimal += "0";


	//Formateamos la parte entera con separador de millar pasado por par metros
	for (con = ValorEntero.length - 3; con > -1; con -= 3)
	ValorEntero2 = ValorEntero.substring(con,con+3) + SepMil + ValorEntero2;

	//A¤adimos el resto de la cifra si lo hubiera calculando el resto (m¢dulo) de la divisi¢n entre 3
	if (ValorEntero.length % 3 > 0)
	ValorEntero2 = ValorEntero.substring(0,ValorEntero.length%3) + SepMil + ValorEntero2;

	//Eliminamos el £ltimo caracter
	if(SepMil)
	ValorEntero2 = ValorEntero2.substring(0,ValorEntero2.length-1);

	//Devolvemos el n£mero formateado seg£n el n£mero de decimales pasado por par metros
	if (NumDec>0)
	return ValorEntero2 + SepDec + ValorDecimal;
	else
	return ValorEntero2;
}

