// JavaScript Document
<!--

function nav() {
	
   var w = document.goForm.selectedCity.selectedIndex;
   //alert (w);
   var url_add = document.goForm.selectedCity.options[w].value;
   //alert (url_add);
   window.location.href = url_add;
}
function book() {
	
   var x = document.hostelForm.selectedHostel.selectedIndex;
   var url_book = document.hostelForm.selectedHostel.options[x].value;
   window.location.href = url_book;
}

function hostelCheck(type) {
	
	var city = document.hostelForm.selectedCity.value; 
	var country = document.hostelForm.country.value;    	
	var year = document.hostelForm.selYear.options[document.hostelForm.selYear.selectedIndex].value; 
	var month = document.hostelForm.selMonth.options[document.hostelForm.selMonth.selectedIndex].value;
	var day = document.hostelForm.selDay.options[document.hostelForm.selDay.selectedIndex].value;
	var nights = document.hostelForm.numNights.value; 
	var id = document.hostelForm.id.value; 
	var name = document.hostelForm.name.value; 
	
	urlCity = city.toLowerCase();
	urlCountry = country.toLowerCase();
	urlCity = urlCity.replace(/[ ]/g,'-'); 
	urlCountry = urlCountry.replace(/[ ]/g,'-'); 
	
	//alert (urlCountry + '/' + urlCity + '/' + year + '/' + month + '/' + day + '/' + nights + '/' + id + '.html');
	
	if (type == 'book') { 
	
		window.location.href = 'http://www.urbanlowdown.com/hostels/' + urlCountry + '/' + urlCity + '/' + year + '/' + month + '/' + day + '/' + nights + '/';
		//'http://www.urbanlowdown.com/hostels/' + urlCountry + '/' + urlCity + '/' + year + '/' + month + '/' + day + '/' + nights + '/';
	}
	
	else if (type == 'rebook') {
		
		window.location.href = 'http://www.urbanlowdown.com/hostels/' + urlCountry + '/' + urlCity + '/' + year + '/' + month + '/' + day + '/' + nights + '/' + id + '/' + name + '.html';
		
	//'http://www.urbanlowdown.com/hostels/' + urlCountry + '/' + urlCity + '/' + year + '/' + month + '/' + day + '/' + nights + '/' + id + '.html';
	}
}

function sideHostel() { 
	
	var city = document.hostelForm.selectedCity.value; 
	var country = document.hostelForm.country.value;    	
	var year = document.hostelForm.selYear.value; 
	var month = document.hostelForm.selMonth.value;
	var day = document.hostelForm.selDay.value;
	var nights = document.hostelForm.numNights.value; 
	var id = document.hostelForm.id.value; 
	
	urlCity = city.toLowerCase();
	urlCountry = country.toLowerCase();
	urlCity = urlCity.replace(/[ ]/g,'-'); 
	urlCountry = urlCountry.replace(/[ ]/g,'-'); 
		
	window.location.href = 'http://www.urbanlowdown.com/hostels/' + urlCountry + '/' + urlCity + '/' + year + '/' + month + '/' + day + '/' + nights + '/';

}
	
function newHostel() { 
	
	var city = document.changeHostel.city.value; 
	var country = document.changeHostel.country.value;    	
	var year = document.changeHostel.selYear.value; 
	var month = document.changeHostel.selMonth.value;
	var day = document.changeHostel.selDay.value;
	var nights = document.changeHostel.numNights.value; 
	var nameId = document.changeHostel.id.value.split("|");
	var id = nameId[0]; 
	var name = nameId[1]; 
	
	urlCity = city.toLowerCase();
	urlCountry = country.toLowerCase();
	urlCity = urlCity.replace(/[ ]/g,'-'); 
	urlCountry = urlCountry.replace(/[ ]/g,'-'); 
		
	window.location.href = 'http://www.urbanlowdown.com/hostels/' + urlCountry + '/' + urlCity + '/' + year + '/' + month + '/' + day + '/' + nights + '/' + id + '/' + name + '.html';

}

function newCity() { 
	
	var city = document.changeCity.city.value; 
	var country = document.changeCity.country.value; 
	var year = document.changeHostel.selYear.value; 
	var month = document.changeHostel.selMonth.value;
	var day = document.changeHostel.selDay.value;
	var nights = document.changeHostel.numNights.value; 

	urlCity = city.toLowerCase();
	urlCountry = country.toLowerCase();
	urlCity = urlCity.replace(/[ ]/g,'-'); 
	urlCountry = urlCountry.replace(/[ ]/g,'-'); 
		
	window.location.href = 'http://www.urbanlowdown.com/hostels/' + urlCountry + '/' + urlCity + '/' + year + '/' + month + '/' + day + '/' + nights + '/';

}

function dynamicSelect(id1, id2) {
	// Browser and feature tests to see if there is enough W3C DOM support
	var agt = navigator.userAgent.toLowerCase();
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_mac = (agt.indexOf("mac") != -1);
	if (!(is_ie && is_mac) && document.getElementById && document.getElementsByTagName) {
		// Obtain references to both select boxes
		var sel1 = document.getElementById(id1);
		var sel2 = document.getElementById(id2);
		// Clone the dynamic select box
		var clone = sel2.cloneNode(true);
		// Obtain references to all cloned options 
		var clonedOptions = clone.getElementsByTagName("option");
		// Onload init: call a generic function to display the related options in the dynamic select box
		refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		// Onchange of the main select box: call a generic function to display the related options in the dynamic select box
		sel1.onchange = function() {
			refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		};
	}
}

function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
	// Delete all options of the dynamic select box
	while (sel2.options.length) {
		sel2.remove(0);
	}
	// Create regular expression objects for "select" and the value of the selected option of the main select box as class names
	var pattern1 = /( |^)(select)( |$)/;
	var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
	// Iterate through all cloned options
	for (var i = 0; i < clonedOptions.length; i++) {
		// If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box
		if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
			// Clone the option from the hidden option pool and append it to the dynamic select box
			sel2.appendChild(clonedOptions[i].cloneNode(true));
		}
	}
}

/*	dynamicCSS.js v1.0 <http://www.bobbyvandersluis.com/articles/dynamicCSS.php>
	Copyright 2005 Bobby van der Sluis
	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

function createStyleRule(selector, declaration) {
	if (!document.getElementsByTagName || !(document.createElement || document.createElementNS)) return;
	var agt = navigator.userAgent.toLowerCase();
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_iewin = (is_ie && (agt.indexOf("win") != -1));
	var is_iemac = (is_ie && (agt.indexOf("mac") != -1));
	if (is_iemac) return; // script doesn't work properly in IE/Mac
	var head = document.getElementsByTagName("head")[0]; 
	var style = (typeof document.createElementNS != "undefined") ?  document.createElementNS("http://www.w3.org/1999/xhtml", "style") : document.createElement("style");
	if (!is_iewin) {
		var styleRule = document.createTextNode(selector + " {" + declaration + "}");
		style.appendChild(styleRule); // bugs in IE/Win
	}
	style.setAttribute("type", "text/css");
	style.setAttribute("media", "screen"); 
	head.appendChild(style);
	if (is_iewin && document.styleSheets && document.styleSheets.length > 0) {
		var lastStyle = document.styleSheets[document.styleSheets.length - 1];
		if (typeof lastStyle.addRule == "object") { // bugs in IE/Mac and Safari
			lastStyle.addRule(selector, declaration);
		}
	}
}

/*	DOM manipulation functions;
	Can only be used after a page has fully loaded
*/

function setElementStyleById(id, propertyName, propertyValue) {
	if (!document.getElementById) return;
	var el = document.getElementById(id);
	if (el) el.style[propertyName] = propertyValue;
}

function setElementStyle(element, propertyName, propertyValue) {
	if (!document.getElementsByTagName) return;
	var el = document.getElementsByTagName(element);
	for (var i = 0; i < el.length; i++) {
		el[i].style[propertyName] = propertyValue;
	}
}

function setElementStyleByClassName(cl, propertyName, propertyValue) {
	if (!document.getElementsByTagName) return;
	var re = new RegExp("(^| )" + cl + "( |$)");
	var el = document.all ? document.all : document.getElementsByTagName("body")[0].getElementsByTagName("*"); // fix for IE5.x
	for (var i = 0; i < el.length; i++) {
		if (el[i].className && el[i].className.match(re)) {
			el[i].style[propertyName] = propertyValue;
		}
	}
}

var slidingPanels = new Array();

function SlidingPanel(panelID)
{
	this.panel = sp_getObj(panelID);
	if (!this.panel)
		return;
	this.id = slidingPanels.length;

	if (uA.IE) { // hack to init IE's filter rendering engine
		var dummy = document.createElement('div');
		dummy.style.position = 'absolute';
		dummy.style.top = 0;
		dummy.style.left = 0;
		dummy.style.width = '1px';
		dummy.style.height = '1px';
		dummy.style.filter = 'alpha(opacity=50)';
		this.panel.appendChild(dummy);
	} 

	this.icon = null;
	this.label = null;
	this.duration = 500;
	this.fade = true;
	this.restHeight = this.panel.style.height ? this.panel.style.height : 'auto';
	this.open = !(sp_getStyle(this.panel).display == 'none');
	this.animation = {now:(this.open ? 1.0 : 0.0), from:0.0, to:0.0, duration:0};
	if (this.open)
		this.height = this.panel.offsetHeight;
	else { // workaround to get panel height when hidden
		this.panel.style.display = 'block';
		this.height = this.panel.offsetHeight;
		this.panel.style.display = 'none';
	}

	this.slide = function() {
		if (this.open) {
			this.height = this.panel.offsetHeight;
			if (this.animation.timer != null) {
				clearInterval(this.animation.timer);
				this.animation.timer = null;
			}

			var starttime = (new Date).getTime() - 13;

			this.animation.duration = this.duration;
			this.animation.starttime = starttime;
			this.animation.timer = setInterval ("sp_slide('" + this.id + "')", 13);
			this.animation.from = this.animation.now;
			this.animation.to = 0.0;
			sp_slide(this.id);
		}
		else { // workaround to get panel height when hidden
			this.panel.style.display = 'block';
			this.panel.style.height = this.restHeight;
			this.height = this.panel.offsetHeight;
			this.panel.style.height = '1px';
			this.panel.style.display = 'none';
			
			if (this.animation.timer != null) {
				clearInterval (this.animation.timer);
				this.animation.timer  = null;
			}
	 
			var starttime = (new Date).getTime() - 13;
	 
			this.animation.duration = this.duration;
			this.animation.starttime = starttime;
			this.animation.timer = setInterval ("sp_slide('" + this.id + "')", 13);
			this.animation.from = this.animation.now;
			this.animation.to = 1.0;
			sp_slide(this.id);
		}
		this.open = !this.open;
	};
	
	this.setSlideDuration = function(duration) {
		this.duration = duration;
	};
	
	this.setLabel = function(labelID, textWhenOpen, textWhenClosed) {
		var label = sp_getObj(labelID);
		if (!label)
			return;
		this.label = {label:label, textWhenOpen:textWhenOpen, textWhenClosed:textWhenClosed};
	};

	this.setIcon = function(iconID, iconWhenOpen, iconWhenClosed) {
		var icon = sp_getObj(iconID);
		if (!icon)
			return;
		this.icon = {icon:icon, iconWhenOpen:iconWhenOpen, iconWhenClosed:iconWhenClosed};
	};

	this.setFade = function(fade) {
		this.fade = fade;
	};

	slidingPanels[this.id] = this;
	return this;
}

function sp_slide(id) { // visualizes a scrolling animation
	var T,
		ease,
		time = (new Date).getTime(),
		newHeight;

	T = sp_clampTo(time-slidingPanels[id].animation.starttime, 0, slidingPanels[id].animation.duration);
	if (T >= slidingPanels[id].animation.duration) {
		clearInterval (slidingPanels[id].animation.timer);
		slidingPanels[id].animation.timer = null;
		slidingPanels[id].animation.now = slidingPanels[id].animation.to;
		
		if (slidingPanels[id].label) {
			slidingPanels[id].label.label.innerHTML = slidingPanels[id].animation.now ? slidingPanels[id].label.textWhenOpen : slidingPanels[id].label.textWhenClosed;
		}
		if (slidingPanels[id].icon) {
			slidingPanels[id].icon.icon.src = slidingPanels[id].animation.now ? slidingPanels[id].icon.iconWhenOpen : slidingPanels[id].icon.iconWhenClosed;
		}
	}
	else {
		ease = 0.5 - (0.5 * Math.cos(Math.PI * T / slidingPanels[id].animation.duration));
		slidingPanels[id].animation.now = sp_computeNextFloat (slidingPanels[id].animation.from, slidingPanels[id].animation.to, ease);
	}
	
	var sPstyle = slidingPanels[id].panel.style;
	sPstyle.display = slidingPanels[id].animation.now ? 'block' : 'none';
	sPstyle.overflow = 'hidden';
	if (slidingPanels[id].fade) {
		if (uA.IE)
			sPstyle.filter = 'alpha(opacity=' + Math.round(slidingPanels[id].animation.now*100) + ')';
		else if (uA.Gecko)
			sPstyle.MozOpacity = slidingPanels[id].animation.now < 1 ? slidingPanels[id].animation.now : 0.99; // to avoid flickering
		else if (uA.Safari)
			sPstyle.opacity = slidingPanels[id].animation.now;
	}
	newHeight = Math.round(slidingPanels[id].animation.now*slidingPanels[id].height);
	sPstyle.height = (uA.IE ? sp_clampTo(newHeight, 1, newHeight) : newHeight) + 'px'; // IE dislikes a height of 0
	if (slidingPanels[id].animation.now == 1.0) {
		sPstyle.height = slidingPanels[id].restHeight;
	}
}

function sp_getStyle(obj)
{
	if ('getComputedStyle' in window && !uA.Safari)
		return getComputedStyle(obj, '');
	else if (document.body.currentStyle)
		return obj.currentStyle;
	else
		return obj.style;
}

function sp_getObj(id)
{
	return (document.getElementById ? document.getElementById(id) : document.all[id]);
}

function sp_clampTo(value, min, max) { // constrains a value between two limits
	return value < min ? min : value > max ? max : value;
}

function sp_computeNextFloat (from, to, ease) { // self explaining
	return from + (to - from) * ease;
}

uA = new Object();
uA.IE = navigator.appName.indexOf('Microsoft') != -1;
uA.Gecko = navigator.userAgent.indexOf('Gecko') != -1 && navigator.userAgent.indexOf('Safari') == -1;
uA.Safari = navigator.userAgent.indexOf('Safari') != -1;


//-->