//-----------------------------------------------------------------------

function fill_select(id) {
	elm = document.getElementById('alo_habitacion' + id);
	//valores_usados = '';

	elm.options.length = 0;

	// creo una cadena que contiene los items seleccionados de select's anteriores
	for (i = id-1; i > 0; --i)
	{
		select_anterior = document.getElementById('alo_habitacion' + i);
		// si no encontro el select o si no tiene nada seleccionado continuo
		if (!select_anterior || select_anterior.selectedIndex == -1)
			continue;
		//valores_usados += select_anterior.options[select_anterior.selectedIndex].value + ';';
		for( j=0; j< select_anterior.options.length; j++)
		{
			if( j != select_anterior.selectedIndex )
				elm.options[elm.options.length] = new Option(select_anterior.options[j].value, j, false );
		}
	}

	// cargo en el select los tipos de room que no estan dentro de la cadena.
	/*for (i in room_types) 	{
		if (valores_usados.indexOf(i + ';') != -1)
			continue;
		elm.options[elm.options.length] = new Option(room_types[i], i, (i=='DB') ?true:false);
	}*/
}

//-----------------------------------------------------------------------
function change_select(obj, url) {
	var obj = document.getElementById(obj);

	obj.length=0;
	obj[0] = new Option("Actualizando...","");
	var e = document.createElement("script");
	e.setAttribute('type', 'text/javascript');
	e.setAttribute('src', url);

	document.getElementsByTagName("head")[0].appendChild(e);

	return true;
}

//-----------------------------------------------------------------------
function change_city(country) {
	var value = '';
	var url = '';
	url = "includes/select_cities.js.php?cnt="+country+"&field=sh_city";
	change_select('sh_city', url);
}

//-----------------------------------------------------------------------
function switch_opc(obj, display) {
	if(document.getElementById) {
		var sec = document.getElementById(obj);
		if (display) {
			sec.style.display = "block";
		} else {
			sec.style.display = "none";
		}
	}
}

//-----------------------------------------------------------------------
function add_room () {
	if (curroom < 5) {
		curroom = curroom + 1;
		switch_opc('room_'+curroom, true);
		//fill_select(curroom);
	}
	if (curroom == 5) {
		switch_opc('room_new', false);
	}
}

//-----------------------------------------------------------------------
function setcantrooms (value, id) {

	var rooms = document.getElementById('alo_rooms'+id);
	var cots = document.getElementById('alo_cunas'+id);
	var childage0 = document.getElementById('alo_room_child'+id);

	var t_age = document.getElementById('childage');

	if (value == "") {
		rooms.value = "";
		cots.value = "";
	} else {
		// ponemos predeterminado
		if (rooms.value == "") {
			rooms.value = "1";
		}

		// agrego childage
		if (value == 'TB+1' || value == 'DB+1') {
			childage0.style.visibility = "visible";
		} else {
			childage0.style.visibility = "hidden";
		}
	}

	// controlo titulos
	var childage = document.getElementsByName('rm_childage0[]');
	var used = false;
	for (i = 0; i < childage.length; i++) 	{
		if (childage[i].style.visibility == "visible") {
			var used = true;
			break;
		}
	}
	if (used) {
		t_age.innerHTML = "<div align=\"left\">Edad del ni&ntilde;o</div>";
	} else {
		t_age.innerHTML = "&nbsp;";
	}
}

//-----------------------------------------------------------------------
function mostrar_progreso() {
	inputs = document.getElementsByTagName('INPUT');
	selects = document.getElementsByTagName('SELECT');

	for (i = 0; i < inputs.length; i++)
		inputs[i].style.display = 'none';

	for (i = 0; i < selects.length; i++)
		selects[i].style.display = 'none';

	document.getElementById('progreso').style.display = 'block';
}


//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
function c(e)
{
	try
	{
		img = null;
		for (i in e.childNodes)
			if (e.childNodes[i].nodeName == 'IMG') img = e.childNodes[i];

		if(img.src.match(/\.off\./))
			img.src = img.src.replace(/\.off\./, '.on.');
		else
			img.src = img.src.replace(/\.on\./, '.off.');
	}
	catch(err)
	{return;}
}

// Achica la imagen si desproporcionar
function imageresize(objimage, maxpix) {

	tempimage = new Image();
	tempimage.src = objimage.src;

	var height = tempimage.height; // Alto
	var width = tempimage.width;	// Ancho
	var info = width+'x'+height+' pxs.';

	if (width > maxpix || height > maxpix) { // Controlo si es reamente más grande que los pxs máximos
		if (width > height) {
			// Es más ancha
			height = (maxpix*height)/width;
			width = maxpix;
		} else {
			// Es más alta
			width = (maxpix*width)/height;
			height = maxpix;
		}
		info += ' (Red)' ;
	} else {
		/*
		// Es mas chica
		if (width < maxpix || height < maxpix) {
			if (width > height) {
				// Es más ancha
				height = (maxpix*height)/width;
				width = maxpix;
			} else {
				// Es más alta
				width = (maxpix*width)/height;
				height = maxpix;
			}
			info += ' (Red)'
		}
		*/
	}

	objimage.height = height;
	objimage.width = width;
}
/*
function emubox(action, src, pxwidth, pxheight) {

	var objbox = document.getElementById("emubox");
	var objbox_src = document.getElementById("emubox_src");

	// Dejo en blanco el iframe y oculto
	objbox.style.visibility = "hidden";

	if (action == "open") {
		// Abro o cambio
		objbox_src.src = "box_white.html";

		var layerpos = document.getElementById("emubox_pos");
		var scrwidth = layerpos.offsetLeft;
		var scrheight = layerpos.offsetTop;

		objbox.style.width = pxwidth;
		objbox.style.height = pxheight;
		objbox.style.top = parseInt((scrheight-pxheight)/2);
		objbox.style.left = parseInt((scrwidth-pxwidth)/2);

		objbox.style.visibility = "visible";
		objbox_src.src = src;
	}
}

// control de popups!
function openbox(url,name,features) {

	winPopup = window.open(url,name,features);

	if (winPopup == 'failed' || winPopup == null) {

		winPopup = 'bloqueado';
	} else {
		winPopup = 'ok';
	}

	if (winPopup == 'bloqueado') {
		// Tiene popups killers
		aryfeatures = features.split(",");
		// ancho
		arytemp = aryfeatures[0].split("=");
		pxwidth = parseInt(arytemp[1]);
		// alto
		arytemp = aryfeatures[1].split("=");
		pxheight = parseInt(arytemp[1]);

		emubox('open', url, pxwidth, pxheight);
	}
}
*/
/*
// Abre un box de browser *** VIEJO ***
function openbox(url,name,features) {
	window.open(url,name,features);
}
*/

// Abre popup del envio por email
function openboxmail(section, urlvariables) {
	var url;
	url = 'box_mail.php?body='+section+'&'+urlvariables;
	features = 'width=300,height=210';
	window.open(url, 'MailBox', features);
}

// Abre popup del envio de consulta por email
function openboxconsulta(section, urlvariables) {
	var url;
	url = 'box_consulta.php?body='+section+'&'+urlvariables;
	features = 'width=500,height=290';
	window.open(url, 'MailConsulta', features);
}

// Abre popup del envio por email
function sendprint(section, urlvariables) {
	var url;
	url = 'box_print.php?body='+section+'&'+urlvariables;
	features = 'width=650,height=500,scrollbars=yes,resizable=yes';
	window.open(url, 'Print', features);
}

// Abre la ventana de chat
function openboxchat(){
	var url = "box_chat.php";
	window.open(url,'ChatBox','width=310,height=459');

}

function emubox(action, src, pxwidth, pxheight) {

	var objbox = document.getElementById("emubox");
	var objbox_src = document.getElementById("emubox_src");

	// Dejo en blanco el iframe y oculto
	objbox.style.visibility = "hidden";

	if (action == "open") {
		// Abro o cambio
		objbox_src.src = "box_white.html";

		var layerpos = document.getElementById("emubox_pos");
		var scrwidth = layerpos.offsetLeft;
		var scrheight = layerpos.offsetTop;

		objbox.style.width = pxwidth;
		objbox.style.height = pxheight;
		objbox.style.top = parseInt((scrheight-pxheight)/2);
		objbox.style.left = parseInt((scrwidth-pxwidth)/2);

		objbox.style.visibility = "visible";
		objbox_src.src = src;
	}
}

function openbox(url,name,features) {

	winPopup = window.open(url,name,features);

	if (winPopup == 'failed' || winPopup == null) {

		winPopup = 'bloqueado';
	} else {
		winPopup = 'ok';
	}

	if (winPopup == 'bloqueado') {
		// Tiene popups killers
		aryfeatures = features.split(",");
		// ancho
		arytemp = aryfeatures[0].split("=");
		pxwidth = parseInt(arytemp[1]);
		// alto
		arytemp = aryfeatures[1].split("=");
		pxheight = parseInt(arytemp[1]);

		emubox('open', url, pxwidth, pxheight);
	}
}
