function debug(msg) {
	//alert (msg);
	return;
}
var timer = {
  time: 0,
  now: function(){ return (new Date()).getTime(); },
  start: function(){ this.time = this.now(); },
  since: function(){ return this.now()-this.time; }
}
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
var domQueue = new Array();
var domReady = false;
// -------------------------------------------------------------------------------------
document.observe("dom:loaded", function() {
  domReady==true;
  for (var a=0;a<domQueue.length;a++){
	var func = domQueue[a];
	try{
		func();
	} catch (err) {
		addLoadEvent(func);
	}
  }
});
//-------------------------------------------------------------------------------------
//
// Ajax AbortRequest function
//
Ajax.Request.prototype.abort = function() {
    // prevent and state change callbacks from being issued
    this.transport.onreadystatechange = Prototype.emptyFunction;
    // abort the XHR
    this.transport.abort();
    // update the request counter
    Ajax.activeRequestCount--;
};
// -------------------------------------------------------------------------------------

function Browser(){
  this.dom = document.getElementById?1:0;
  this.ie4 = (document.all && !this.dom)?1:0;
  this.ns4 = (document.layers && !this.dom)?1:0;
  this.ns6 = (this.dom && !document.all)?1:0;
  this.ie5 = (this.dom && document.all)?1:0;
  this.ok = this.dom || this.ie4 || this.ns4;
  this.platform = navigator.platform;
}
var browser = new Browser();

var stop_api = false;
// -------------------------------------------------------------------------------------
function addLoadEvent(func) {	// attach events onload 
	if (!func) return false;
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}
}
// -------------------------------------------------------------------------------------
function addUnLoadEvent(func) {	// attach events unload 
	if (!func) return false;
	var oldunonload = window.onunload;
	if (typeof window.onunload != 'function'){
    	window.onunload = func;
	} else {
		window.onunload = function(){
		oldunonload();
		func();
		}
	}
}
// -------------------------------------------------------------------------------------

function addDomLoadEvent(func) {	// attach events onload 
	if (!func) return false;
	if (domReady==true) {
		eval (func);
	} else {
		domQueue.push(func);
	}
}
// -------------------------------------------------------------------------------------
var t;
function toggleSelect(id,forceClose){ //open / close settings boxes
	clearTimeout(t);
	var selects = $$('.select');
	for (a=0;a<selects.length;a++) {
		if (selects[a].id != id&& BFhasClassName(selects[a],'active')) {
		Effect.BlindUp(selects[a].id, { duration: .3 });
		BFremoveClassName(selects[a],'active');
		}
	}
	if (id=='none') return false;
	var element = $(id);
	if (BFhasClassName(element,'active')  || forceClose==true){
		Effect.toggle(id,'blind',{ duration: .3 });
	} else {
		element.style.display="none";
		BFaddClassName(element,'active');
		Effect.toggle(id,'blind',{ duration: .3 }); 
		t = window.setTimeout("Effect.toggle("+id+",'blind',{ duration: .3 })",5000);
	}
	return false;
}
// -------------------------------------------------------------------------------------
function createDialog() {
	if ($('systemDialog')) return true;
	var dialog = makeElement('div',{id:'systemDialog',innerhtml:'<div id="sysDialogInner"><span style="color:#aaa; font-size: 8pt;">Loading...</span></div>', style:'display:none;'});
	var winSize = document.viewport.getDimensions();
	var winOffset = document.viewport.getScrollOffsets();
	dialog.style.left = (winSize.width/2-325)+'px';
	dialog.style.top = (winOffset.top+150)+'px';
	document.body.appendChild(dialog);
	$('systemDialog').appear();
	var fnc = function(e) {if (e.keyCode==27) closeDialog();}
	Event.observe(document, 'keyup', fnc);
	if (browser.ie5){
		var dialogSize = $('systemDialog').getDimensions();
		var iframe= makeElement('iframe',{src:"about:blank", frameBorder:"0",scrolling:"no",id:"dialogIframe"});
		document.body.appendChild(iframe);
		$('dialogIframe').style.display="none";
		$('dialogIframe').style.position="absolute";
		$('dialogIframe').style.zIndex="9999";
		$('dialogIframe').style.left = (winSize.width/2-325)+'px';
		$('dialogIframe').style.top = (winOffset.top+150)+'px';
	}
}
// -------------------------------------------------------------------------------------
function  closeDialog(){
	if (!$('systemDialog')) return;
	$('systemDialog').parentNode.removeChild($('systemDialog'));
	var fnc = function(e) {if (e.keyCode==27) closeDialog();}
	Event.stopObserving(document, 'keyup', fnc); 
	if (browser.ie5 && $('dialogIframe')) {
		document.body.removeChild($('dialogIframe'));
	}
}
// -------------------------------------------------------------------------------------
function updateDialog(data) {
	if (!$('systemDialog')) createDialog();
	$('sysDialogInner').update(data);
	var size = $('systemDialog').getDimensions()
	if (browser.ie5 && $('dialogIframe')) {
		$('dialogIframe').width = size.width+'px';
		$('dialogIframe').height = size.height+'px';
		$('dialogIframe').style.display='block';
	}
}
// -------------------------------------------------------------------------------------
var conts = null;
var tabs = null;
function OLDopenTab(id){ // selecting tab && open tab window 
	try{
	if (conts==null) {conts = $$('.subpage .spg');}
	var clength = conts.length;
	for (a=0;a<clength;a++){
		if (conts[a].id != id) {
			BFremoveClassName(conts[a],'active'); 
		} else {BFaddClassName(conts[a],'active');}
	}
	if (tabs==null) tabs = $$('.subpage .tabs li');	
	var tlength = tabs.length;
	for (a=0;a<tlength;a++){
		if (tabs[a].id != 't_'+id) {
			tabs[a].className='';
		} else {tabs[a].className='active';}
	}
	
	} catch (err) {
		debug (err);
	}
	return true;

}
// -------------------------------------------------------------------------------------
function openTab(id){ // selecting tab && open tab window 
	try{
		var elements = $$('#cont .spg', '#main .subpage .tabs li');
		for(var a=0;a<elements.length;a++){
			BFremoveClassName(elements[a],'active');
			if (elements[a].id==id || elements[a].id=='t_'+id) 
				BFaddClassName(elements[a],'active');
		}
	} catch (err) {
		debug (err);
	}
	return true;

}

// -------------------------------------------------------------------------------------
function styleTable(hasClass) { // adding hover to "styled
	if (!hasClass || hasClass=='') hasClass = 'styled';
	var trs = $$('table.styled tbody tr');
	for (b=0; b<trs.length;b++){
		trs[b].onmouseover = function () {BFaddClassName(this,'hover');}
		trs[b].onmouseout = function () {BFremoveClassName(this,'hover');}
	}
}
// -------------------------------------------------------------------------------------
function BFhasClassName(element, className) {
    var elementClassName = element.className;
    return (elementClassName.length > 0 && (elementClassName == className ||
      new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
}
// -------------------------------------------------------------------------------------
function BFaddClassName(element, className) {
    if (!BFhasClassName(element,className))
      element.className += (element.className ? ' ' : '') + className;
    return element;
}
// -------------------------------------------------------------------------------------
function BFremoveClassName(element, className) {
    element.className = element.className.replace(
      new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip();
	  return element.className;
    return element;
}
// -------------------------------------------------------------------------------------
function openAdvSearch (){ // open advanced search on city page
	$('s_adv').addClassName("active");
	$('s_basic').removeClassName("active");
	$('adv_search').style.display="none";
	$('adv_search').addClassName("active");
	$('adv_search').appear();
}
// -------------------------------------------------------------------------------------
function closeAdvSearch(){ // close advanced search on city page
	$('s_adv').removeClassName("active");
	$('s_basic').addClassName("active");
	$('adv_search').fade();
}
// -------------------------------------------------------------------------------------
function setMode(mode,opt){ // open advanced search on city page
	var elements = $$('#pricediv .tabs li', '.mode');
	for(var a=0;a<elements.length;a++){
		BFremoveClassName(elements[a],'active');
		if (BFhasClassName(elements[a],mode)) BFaddClassName(elements[a],'active');
	}
	//if (opt) { createCookie(opt.key, opt.value, 365); }
}
// -------------------------------------------------------------------------------------
function charCount(id, words, chars){ // count chars and words
	if (!words) words = "words";
	if (!chars) chars = "chars";
	if ($F(id).length>0) {
		var warr = $(id).value.split(/[\s,\.-:;]+/)
		var upd ='<small>'
		upd+= ' '+words+': '+warr.length;
		upd+= ' '+chars+': '+$F(id).length; 
		upd+='</small>';
	}
	else var upd =''
	$('counter-'+id).update( upd );	
}
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
function changeCurrency(fireElement) {
	try{ 
		if (fireElement.innerHTML){
			var fire = fireElement.innerHTML.match(/([^<]+)<em>([^<]*)<\/em>/i);
			var newCurrency = fire[2];
			var old = $$('#select_currency li.active');	
			old[0].className = '';
			fireElement.parentNode.className='active';
			window.setTimeout(function() { $('chcrrncy').update("(" +newCurrency+ ") " +fire[1]).pulsate({pulses: 2, duration:1});}, 500);
			//createCookie('currency', newCurrency, 0);
			data = 'currency='+newCurrency;
			api('update','settings', data);
			toggleSelect('select_currency',true);
		} else {
			var newCurrency = fireElement;
		}
		updateCurrency(newCurrency);
	} catch (err){
		debug(err);
	}
}
function chngCurrency(fireElement) {
	var fire = fireElement.innerHTML.match(/([^<]+)<em>([^<]*)<\/em>/i);
	var newCurrency = fire[2];
	//createCookie('currency', newCurrency, 365);
	data = {'currency': newCurrency}
	api('update_return','settings', data);
	updateCurrency(newCurrency);
	closeDialog();
}
/*
function OLDupdateCurrency(newCurrency) {
	try{
	var b = null;
	if ($('prices')) {
		var tds = $$('#prices tbody td[title]', '#popular_hotels tbody td[title]', '#prices td .ovrvw span[title]');
		for (a=0; a<tds.length;a++) {
			var original = tds[a].title.match(/([\d\.\,]+) (\w{3})/i);
			if (original[1] && original[2]) {
				var newAmount = convertCurrency(original[1],original[2],newCurrency);
				if (newAmount) {
					if (tds[a].firstChild.tagName == 'A'){					
						tds[a].firstChild.innerHTML = newAmount+" "+newCurrency.toUpperCase();
					b=1;
					} else {
						tds[a].innerHTML = newAmount+" "+newCurrency.toUpperCase();
					}
				}
			}

		}
	}
	if ($('price')) {
		var amount = eval($$('#price div p b'));
		var currency = $$('#price div p small');
		var oldPrice = $$("#price div p");
		var tmp = oldPrice[0].title.split(" ");
		if ((tmp[0] && tmp[1])){
			newAmount = convertCurrency(tmp[0], tmp[1], newCurrency);
			if(newAmount) {
				oldPrice[0].innerHTML = '<small>'+newCurrency.toUpperCase()+'</small>'+
				'<b>'+newAmount+'</b>';
			}
		}
	}
	if ($('city')) {
		var tds = $$('#city #search_result .lead span[title]','#city #search_result .offers .provlink span[title]');
		for (a=0; a<tds.length;a++) {
			var original = tds[a].title.match(/([\d\.\,]+) (\w{3})/i);
			if (original[1] && original[2]) {
				if (original[1].match(/\./)) {
					var newAmount = convertCurrency(original[1],original[2],newCurrency);
				} else {
					var newAmount = Math.round(convertCurrency(original[1],original[2],newCurrency));
				}
				if (newAmount) tds[a].innerHTML = newAmount+" "+newCurrency.toUpperCase();
			}
		}
	}
	data = {'currency': newCurrency};
	} catch (err) {
		//alert (b)
	}
}
*/
// -------------------------------------------------------------------------------------
function updateCurrency(newCurrency){
	showLoading();
	var old_href = window.location.href.split('#');
	var new_href = old_href[0].replace(/[&\?]currency=\w{3}/,'');
	window.location.href = new_href+(new_href.match(/\?/)?'&':'?')+'currency='+newCurrency+(old_href[1]?'#'+old_href[1]:'');
}
// -------------------------------------------------------------------------------------
function convertCurrency(amount,oldCurrency,newCurrency) {
	amount = amount.toString().replace(/,/,'');
	oldCurrency = oldCurrency.toLowerCase();
	newCurrency = newCurrency.toLowerCase();
	if (oldCurrency == newCurrency) { 
		result = eval(amount);
	}else if (currencyRates[oldCurrency+"_"+newCurrency]) {
		var result = eval(amount*(1/currencyRates[oldCurrency+"_"+newCurrency]));
	} else if (currencyRates[newCurrency+"_"+oldCurrency]) {
		var result = eval(amount*(currencyRates[newCurrency+"_"+oldCurrency]));
	} else {
		return false;
	}
	if (browser.ie5){
		if (result>=10000) return Math.round(result);
		return result.toFixed(2);
	} else {
		if (result>=10000) result = Math.round(result);
		var res = result.toFixed(2).toString().split(/\./);
		var rres = res[0].split(/(\d{1,3})?(\d{3})*(\d{3})$/).join(',').replace(/,{2,5}/,',').replace(/^,/,'').replace(/,$/,'');
		if (result>=10000) return rres;
		return rres+'.'+res[1];
	}
}
// -------------------------------------------------------------------------------------
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
// -------------------------------------------------------------------------------------
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
// -------------------------------------------------------------------------------------
function eraseCookie(name) {
	createCookie(name,"",-1);
}
// -------------------------------------------------------------------------------------
function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}
// -------------------------------------------------------------------------------------
function preloadImage(imgSrc){
		imgPreload = new Image();
		imgPreload.src = imgSrc;
}
// -------------------------------------------------------------------------------------
function loadUri(){
	var url = location.href;
	if (url.include('#') && !url.endsWith('#')) {
		var goToReview = false;
		var newurl = url.split('#');
		if (newurl[1].include('&')) {
			var vars = newurl[1].split('&');
			for (a=0;a<vars.length;a++) {
				var v=vars[a].split('=');
				if (v[0] == 'page') { 
				switch (v[1]) {
/*				
					case 'prices': 	
						if (newurl[1].match("checkin")) {
							show_prices = true;
							offers_shown = false;
							getOffersOnly(newurl[1]);
							var d = newurl[1].split("&");
							d.each(function(m) {
								f = m.split('=');
								if ($(f[0])) {
									var el = $(f[0]);
									switch (el.tagName.toLowerCase()){
										case 'input':
											el.value=f[1];
										break
										case 'select':
											setDropDown(f[0], f[1]);
										break;
									}
								}
							});
						}
					break;

					case 'hotels':
						if (newurl[1].match("checkin")) {
							show_prices = true;
							offers_shown = false;
		//					getLocationOffers(newurl[1].replace(/page=\w+&/,'')+'&id='+location_id);
							var d = newurl[1].split("&");
							d.each(function(m) {
								f = m.split('=');
								if ($(f[0])) {
									var el = $(f[0]);
									switch (el.tagName.toLowerCase()){
										case 'input':
											el.value=f[1];
										break
										case 'select':
											setDropDown(f[0], f[1]);
										break;
									}
								}
							});
						}

					break;
				case 'around': 	
*/					
					case 'map':						
						loadScript(); 
					break;
					
					case 'photos':
						if (img = newurl[1].match(/\&view=(\d+)/i)) {
							var open_image=img[1];
						} else {
							var open_image = 1;
						}
					break;
					case 'reviews':
						if ($('review') && $('review').value != '') goToReview = true;
					break;
				}
				openTab(v[1]);}
			}
		} else if(newurl[1].include('=')) {
			var v=newurl[1].split('=');
				if (v[0] == 'page') { 
				switch (v[1]) {
					//case 'prices': getOffersOnly();  break;
					case 'map': 
						loadScript(); 
						if (typeof(window.center)=='object') getNearestHotels1();
					break;
					case 'around': 	
						loadScript(); 
					break;
					case 'photos':
						if (img = newurl[1].match(/\&view=(\d+)/i)) {
							var open_image = img[1];
						} else {
							var open_image = 1;
						}
					break;
					case 'reviews':
						if ($('review') && $('review').value != '') goToReview = true;
					break;
				}
			openTab(v[1]);}
		}
		if (goToReview && $('add_review')) {
			Effect.ScrollTo('add_review', {duration:0.5});
		}
		if (open_image){
			addLoadEvent(Gallery.showImage(open_image));
		}
	}

}
// -------------------------------------------------------------------------------------
function getNearestHotels1() {
	if (map!=null){
		getNearestHotels();
	}
}
// -------------------------------------------------------------------------------------
function getOffers(params){
	$('toffers').update('<tr class="notices"><td colspan="10"><span>'+TXT_updating_offers+'</span></td></tr>');
	api('get','prices',params);
}
/*
function getOffers(){
	openTab('prices');
	if (checking_process==true) {
		showMessage("error", txt_CHECKING_IN_PROGRESS);
		return;
	}
	show_prices = true;
	offers_shown = false;
	var params = getOffersOnly();
	var params = params.replace(new RegExp(/&p_hotel=\d+/),'');

	if (params!=false) {
		window.location.href='#page=prices&'+params;
	}
	$('price').style.display="none";
}
// -------------------------------------------------------------------------------------
function getOffersOnly(params){
	if (!show_prices || offers_shown) return ;
	if (checking_process==true) {
		return;
	}
		$('search_proc_bar').addClassName('toggle');

		has_offers = false;
		checking_process = true;
		var date = new Date();
		start_time = date.getTime();
		
//	setProgressBar(0);
	if (!params) params = post($('chkinout'));
	if (!$('avsearch')) {
		var insert_into = $('ins');
		insert_into.update('<a href="?location='+location_id+'&avsearch">'+txt_SEARCH_RESULTS+'</a> &raquo; ');
		insert_into.appear();
	}
	
	if ($('popular_hotels')) {
		var loader1 = document.createElement('div');
		loader1.style.textAlign = 'center';
		var tmp1 = document.createElement('img');
			tmp1.src= './bs/designs/default/images/ajax-loader.gif';
			loader1.appendChild(tmp1);
		loader1.title='Loading...';
		loader1.id="popular_hotels_loader";
		$('popular_hotels').innerHTML = '';
		$('popular_hotels').appendChild	(loader1);
	}
	var loader = document.createElement('div');
	loader.style.textAlign = 'center';
	loader.title='Loading...';
	loader.id="offers_loader";
	var tmp = document.createElement('img');
		tmp.src= './bs/designs/default/images/ajax-loader.gif';
		loader.appendChild(tmp);
	$('prices').appendChild(loader);

	if (params != old_params) {
		$('srch_results').addClassName('hidden');
		old_params = params;
		startTimer();
	}
	trs = [];
	params = params+'&p_hotel='+hotel_id;
	offers_shown=true;
	params+='&id='+location_id;
	api('get','rates',params);
	return params;
}
function closeProcessBox(){
	checking_process=false; 
	$('search_proc_bar').removeClassName('toggle');
	$('msg').update('<h2>'+txt_SELECT_DATES_FOR_SEARCH+'</h2>');
	if(has_offers==true) {
		$('search_proc_bar').fade();
	}
}
// -------------------------------------------------------------------------------------
function getLocationOffers(params){
try{
	if (checking_process==true) {
		showMessage("error", txt_CHECKING_IN_PROGRESS);
		return;
	}
	checking_process = true;
	if (!params) params = post($('chkinout'));
	if (!$('avsearch')) {
		var insert_into = $('ins');
		insert_into.replace(' &raquo; <span id="avsearch" style="display:none;">'+txt_SEARCH_RESULTS+'</span>');
		$('chngme').update('<a href="?location='+$('loc_inp').value+'">'+$('chngme').innerHTML+'</a>');
		$('avsearch').appear();
	}
	searchParams = '#page=prices&'+params;
	if ($('msg')) {
		$('search_result').removeChild($('msg'));
	}
	var loader = document.createElement('div');
	loader.style.textAlign = 'center';
	loader.title='Loading...';
	loader.id="offers_loader";
	var tmp = document.createElement('img');
		tmp.src= './bs/designs/default/images/ajax-loader.gif';
		loader.appendChild(tmp);
	$('tbd').update();
	$('search_result').appendChild(loader);
	$('paging').update();
	
	if (params!=false) {
		window.location.href='#page=hotels&'+params;
		old_params = params;
		searchParams = '#page=prices&'+params;
		startTimer();
	}
	params+='&id='+location_id;
	api('get','locationrates',params);
	offers_shown=true;
	return params;
} catch (err){
	debug (err);
}
}
// -------------------------------------------------------------------------------------
function stopLocationSearch() {
	checking_process=false;
	$('search_proc_bar').fade(); 
	if (browser.ie5) $$('#basic_search select').each(function (f) { f.style.visibility='visible';});
	return false
}
*/
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
var time = null;
function startTimer() {
	var date = new Date();
	time = null;
	time = date.getTime();
	window.setTimeout("restartTimer()",100);
}
// -------------------------------------------------------------------------------------
function restartTimer() {
	if (!window.checking_process) return;
	var date = new Date();
	var diff = date.getTime()-time;
	if (checking_process==true) {
		if (diff/1000<40) {
			$('progress_indicator').innerHTML = (Math.floor((100/40000)*diff))+' %';
			$('progress_indicator').title = (Math.floor((100/40000)*diff))+' %';
			window.setTimeout("restartTimer()",800);
		} else {
			if (has_offers==false) {
				if ($('msg')) $('msg').update('<h2>'+txt_NO_ROOMS+'</h2>');
				$('search_proc_bar').removeClassName('toggle').show();
				if ($('popular_hotels')) { $('popular_hotels').innerHTML ='<div class="alert">'+txt_NO_AVALIABLE_HOTELS+'</div>'; }
			} else {
				stopLocationSearch();
			}
			time = null;
			checking_process=false;
		}
	}
}
// -------------------------------------------------------------------------------------
function api(action, what, data, delay){
	if (stop_api == true) {stop_api = false; Loader.hide(); removeProgressBar();return false; }
	window.setTimeout (function() {
		Loader.show('Loading...');
		var params='action='+action+'&what='+what;
		if(data) {
			params +="&"+ data;
		}
		var def = Math.random();
		params='in=main&op=api&'+params;
		params+='&rrr='+def;
		var url=base_url+'index.php';
		var MyAjax = new Ajax.Request(
			url,
			{
				encoding: 'UTF-8',
				method: 'post',
				parameters: params,
				onComplete: loadContent
			});
	}, delay*1000);
}
// -------------------------------------------------------------------------------------
function loadContent(received) {
	Loader.hide();
	try {
		if (received.responseXML){
			var xmldoc = received.responseXML; 
			if (xmldoc.getElementsByTagName("JavaScript")){
				var js = xmldoc.getElementsByTagName("JavaScript")[0].firstChild.nodeValue;
				if (js) eval(js);				
			} 
		}
	} catch (err){
		//debug(err);
	}
}
// -------------------------------------------------------------------------------------
function changeLanguage() {
	var url=location.href;
	var vars = post($('add_review_form'));
	var frm = document.createElement("form");
	frm.id="temp_data";
	frm.method="post";
	frm.action="#page=reviews";
	var inp = document.createElement("textArea");
	inp.id="post_data";
	inp.name="post_data";
	frm.appendChild(inp);
	document.body.appendChild(frm);
	$('post_data').innerHTML=vars;
	$('temp_data').submit();
}
// -------------------------------------------------------------------------------------
function openBox(id){
	var boxes = $$('.box');
	for (a=0;a<boxes.length;a++){
		if (BFhasClassName(boxes[a],'active')) {
			BFremoveClassName(boxes[a],'active');
		}
		if (boxes[a].id==id) {BFaddClassName(boxes[a],'active')};
	}
	return false;
}
// -------------------------------------------------------------------------------------
function showMessage(type,message){
	if ($('messageWindow')) var msgWin = $('messageWindow');
	else {
		var msgWin = makeElement('div',{id:'messageWindow'});
		document.body.appendChild(msgWin);
	}
	debug(type+'\n\n'+message);
}
// -------------------------------------------------------------------------------------
var Loader = {
	init: function() { // collecting thumbnail information
		var loader = document.createElement('div');
		loader.id="loader";
		loader.innerHTML = 'Loading...';
		document.body.appendChild(loader);
	},
	show: function(text) {
		if (!$('loader')) Loader.init();
		var loader = $('loader');
		if (text) loader.innerHTML = text;
		loader.style.display = 'block';
	},
	hide: function() {
		$('loader').style.display = 'none';
	}
}
// -------------------------------------------------------------------------------------
function post(forma) {
	return forma.serialize();
}
// -------------------------------------------------------------------------------------
function set_errorfiled(name,message){
	var el = document.getElementById(name);
	el.className = 'formError';
	var em = document.createElement('em');
	em.innerHTML = ' '+message;
	em.className = 'errMsg';
	el.parentNode.appendChild(em);
	//el.innerHTML = el.innerHTML+'<em>'+message+'</em>';
}

// -------------------------------------------------------------------------------------
function showProgressBar(parentElement, indicator) {
	if (!parentElement) { parentElement='prices'};
	if (!$('progressBar')) {
		var div = document.createElement('div');
		div.onclick=function() {stop_api=true;}
		div.onmouseover = function() {$('progressTxt').addClassName('hover').innerHTML = txt_STOP;}
		div.onmouseout = function() {$('progressTxt').removeClassName('hover').innerHTML= $('progressTxt').title;}
		div.style.cursor="pointer";
		var div1 = document.createElement('div');
		var em = document.createElement('em');
		var span = document.createElement('span');
		span.id="progressInner";
		div.id='progressBar';
		div1.appendChild(span);
		div.appendChild(div1);
		em.id = 'progressTxt';
		div.appendChild(em);
		$(parentElement).appendChild(div);
	} else {
		$('progressBar').style.display = 'block';
	}
	if (!$('actInd')) {
		if (!indicator) indicator="#t_prices b";
		var img=' <img src="http://static3.bookingspot.com/progress.gif" id="actInd" alt="*" />';
		var parent = $$(indicator);
		parent[0].innerHTML=parent[0].innerHTML+img;
	}
	var progressBar = $('progressBar');
	setProgressBar(0);
}
// -------------------------------------------------------------------------------------
function setProgressBar(percents) {
	if (percents>100)  {
		percents = 100;
		removeProgressBar();
	}
	var progressInner = $('progressInner');
	var progressTxt = $('progressTxt');
	progressTxt.innerHTML = percents+" %";
	progressTxt.title = percents+" %";
	progressInner.style.width=percents+"%";
}
// -------------------------------------------------------------------------------------
function setProgressIndicator(percents) {
	var progressTxt = $('progress_indicator');
	progressTxt.innerHTML = percents+" %";
	progressTxt.title = percents+" %";
}
// -------------------------------------------------------------------------------------
function removeProgressBar() {
	var progressBar = $('progressBar');
	progressBar.style.display = "none";
	if($('actInd')) {$('actInd').parentNode.removeChild($('actInd'));}
	checking_process = false;
}
// -------------------------------------------------------------------------------------
function toggleOffers(prov){
	var provider = 'rp_'+prov;
	try {
		if ($(provider).hasClassName('active')){
			$(provider).update(trs[provider]);
		} else {
			if (!trs[provider]) {
				trs[provider] = $(provider).innerHTML;
			}
			$$('#'+provider+' .ovrvw')[0].replace(HTML_row_replace);
		}
		var els = $$('#brief_offers .'+prov);
		for (a=0; a<els.length;a++){
			if (BFhasClassName(els[a],'active')) {
				BFremoveClassName(els[a],'active');
			} else {
				BFaddClassName(els[a],'active');
			}
		}
	} catch (err){
		debug(err);
	}	
}
// -------------------------------------------------------------------------------------
function getNearestObjects(data) {
	bounds = new GLatLngBounds();
	var loader = '<img src="http://static3.bookingspot.com/ajax-loader.gif" />';
	switch(data.type) {
	case 'hotel':
		$('tbdm').update('<tr><td colspan="3">'+loader+'</td></tr>');
		api('hotels','getObjects', 'lat='+data.lat+'&lon='+data.lng+'&limit='+data.limit);
	break;
	case 'hotels_location':
		$('p_cities_results').update(loader);
		api('hotels_location', 'getObjects', 'location='+data.location_id+'&limit='+data.limit);
	break;
	}
}
// -------------------------------------------------------------------------------------
function makeElement(tag,opt){
	var e = document.createElement(tag);
	if(typeof(opt)=='object') {
		for (n in opt) {
			switch (n.toLowerCase()) {
				case 'innertext':
					var txt = document.createTextNode(opt[n]);
					e.appendChild(txt);
				break;
				case 'innerhtml':
					e.innerHTML=opt[n];
				break;
				case 'classname':
					e.className = opt[n]
				break;
				default:
					e.setAttribute(n,opt[n]);
				break;
			}
		}
	}
	return e;
}
// -------------------------------------------------------------------------------------
function buildOffersTable(container,data){
	addUnLoadEvent(function () { hotelsOnMap=null;hotelsOnMapMarkers=null;listedHotels=null;hotelData=null;});
try{
	$(container).update();
	eval(data);
	var total = hotelData.length;
	var b=0; 
	if (container=='tbdm') { 
		hotelsOnMap = []; hotelsOnMapMarkers = [];
	} else {
		listedHotels = [];
	}
	if (total>0) {
		var r=hotelData;
		for (var a=0; a<total;a++){
			var tr=makeElement('tr');
			
			if (r[a].dist){
				var td0 = makeElement('td',{'className':'nm',innerText:(a+1),'rowSpan':2});
				
			}
			var td1 = makeElement('td',{className:'ph', 'rowSpan':2});
			var a1 = makeElement('a',{href:r[a].url});
			a1.appendChild(makeElement('img',{className:'thumb',src:r[a].thumb.replace(/150x150/,'100x100'),alt:r[a].name}));
			a1.style.height="";
			td1.appendChild(a1);
			var td2 = makeElement('td',{className:'rt'});
			var div2 = makeElement('div',{className:'rating'});
			var span2 = makeElement('span',{className:'s'+r[a].stars, innerText: r[a].stars+' '+txt_STARS});
			div2.appendChild(span2);
			td2.appendChild(div2);
			var td3 = makeElement('td',{className:'dsc'});
			var h3 = makeElement('h4',{innerhtml:'<a href="'+r[a].url+'">'+r[a].name+'</a>'});
			var addr3 = makeElement('address',{innerText:r[a].address});
			var a3_2 = makeElement('em',{innerHTML:'<a href="#page=map" class="maplink" onclick="'+(r[a].dist?'showHotel('+b+');':'mapHotel('+b+');')+'"><span>'+txt_MAP+'</span></a>'});
			var div3 = makeElement('div',{className:'desc', innerText:r[a].description?r[a].description:''});
			var a3_3 = makeElement('a',{className:'more',href:r[a].url,innerText:txt_READ_MORE});
			div3.appendChild(a3_3);
			var tr_offers = makeElement('tr');
			var td_offers = makeElement('td',{className:'offers','colSpan':'2',innerHTML:r[a].price.replace(/{#}/,searchParams)});
			td3.appendChild(h3);
			td3.appendChild(addr3);
			td3.appendChild(a3_2);
			if (r[a].dist) {
				var a3_21 = makeElement('span',{className:'distance',innerText:' '+r[a].dist});
				td3.appendChild(a3_21);
			}
			td3.appendChild(div3);
			if (td0) {
				tr.appendChild(td0);
			}
			tr_offers.appendChild(td_offers);
			tr.appendChild(td1);
			tr.appendChild(td2);
			tr.appendChild(td3);
			$(container).appendChild(tr);
			$(container).appendChild(tr_offers);
			if (r[a].dist){
				hotelsOnMap[b++] = {
					lat: r[a].lat,
					lng: r[a].lng,
					name: r[a].name,
					address: r[a].address,
					distNum: r[a].distNum,
					stars: r[a].stars,
					img: r[a].thumb,
					url: r[a].url
				}
			} else {
				listedHotels[b++] = {
					lat: r[a].lat,
					lng: r[a].lng,
					name: r[a].name,
					address: r[a].address,
					distNum: r[a].distNum,
					stars: r[a].stars,
					img: r[a].thumb,
					url: r[a].url
				}
			}

		}
		if (hotelsOnMap.length>0) {
			for(c=0;c<hotelsOnMap.length;c++){
				var marker = createMarker(hotelsOnMap,c,'nearHotel');
				map.addOverlay(marker);
				hotelsOnMapMarkers[c] = gmarkers.length-1;
			}
		}
	}
} catch (err) {
	debug(err);
}
}
// -------------------------------------------------------------------------------------
function clone(obj){
    if(obj == null || typeof(obj) != 'object')
        return obj;
    var temp = obj.constructor();
    for(var key in obj)
        temp[key] = clone(obj[key]);
    return temp;
}
// -------------------------------------------------------------------------------------
var Tooltip = Class.create();
Tooltip.prototype = {
	initialize: function(el, options) {
		this.el = $(el);
		this.initialized = false;
		this.setOptions(options);
		
		this.showEvent = this.show.bindAsEventListener(this);
		this.hideEvent = this.hide.bindAsEventListener(this);
		this.updateEvent = this.update.bindAsEventListener(this);
		Event.observe(this.el, "mouseover", this.showEvent );
		Event.observe(this.el, "mouseout", this.hideEvent );
		
		this.content = this.el.title;
		this.el.title = "";

		this.el.descendants().each(function(el){
			if(Element.readAttribute(el, 'alt'))
				el.alt = "";
		});
		addUnLoadEvent(function () { Tooltip=null;});
	},
	setOptions: function(options) {
		this.options = {
			backgroundColor: '#FFFFA6',
			borderColor: '#E1C000',
			textColor: '',
			textShadowColor: '',
			maxWidth: 250,
			align: "left",
			delay: 150,
			mouseFollow: true,
			opacity: .85,
			appearDuration: .25,
			hideDuration: .25
		};
		Object.extend(this.options, options || {});
	},
	show: function(e) {
		this.xCord = Event.pointerX(e);
		this.yCord = Event.pointerY(e);
		if(!this.initialized)
			this.timeout = window.setTimeout(this.appear.bind(this), this.options.delay);
	},
	hide: function(e) {
		if(this.initialized) {
			this.appearingFX.cancel();
			if(this.options.mouseFollow)
				Event.stopObserving(this.el, "mousemove", this.updateEvent);
			new Effect.Fade(this.tooltip, {duration: this.options.hideDuration, afterFinish: function() { Element.remove(this.tooltip) }.bind(this) });
		}
		this._clearTimeout(this.timeout);
		
		this.initialized = false;
	},
	update: function(e){
		this.xCord = Event.pointerX(e);
		this.yCord = Event.pointerY(e);
		this.setup();
	},
	appear: function() {
		this.tooltip = Builder.node("div", {className: "ttooltip", style: "display: none;" }, [
			Builder.node("div", {className:"xtop"}, [
				Builder.node("div", {className:"xb1", style:"background-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb2", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb3", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb4", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"})
			]),
			Builder.node("div", {className: "xboxcontent", style: "background-color:" + this.options.backgroundColor + 
				"; border-color:" + this.options.borderColor + 
				((this.options.textColor != '') ? "; color:" + this.options.textColor : "") + 
				((this.options.textShadowColor != '') ? "; text-shadow:2px 2px 0" + this.options.textShadowColor + ";" : "")}, this.content), 
			Builder.node("div", {className:"xbottom"}, [
				Builder.node("div", {className:"xb4", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb3", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb2", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb1", style:"background-color:" + this.options.borderColor + ";"})
			]),
		]);
		document.body.insertBefore(this.tooltip, document.body.childNodes[0]);
		
		Element.extend(this.tooltip);
		this.options.width = this.tooltip.getWidth();
		this.tooltip.style.width = this.options.width + 'px';
		
		this.setup();
		
		if(this.options.mouseFollow)
			Event.observe(this.el, "mousemove", this.updateEvent);
			
		this.initialized = true;
		this.appearingFX = new Effect.Appear(this.tooltip, {duration: this.options.appearDuration, to: this.options.opacity });
	},
	setup: function(){
		if(this.options.width > this.options.maxWidth) {
			this.options.width = this.options.maxWidth;
			this.tooltip.style.width = this.options.width + 'px';
		}
			
		if(this.xCord + this.options.width >= Element.getWidth(document.body)) {
			this.options.align = "right";
			this.xCord = this.xCord - this.options.width + 20;
		}
		
		this.tooltip.style.left = this.xCord - 7 + "px";
		this.tooltip.style.top = this.yCord + 6 + "px";
	},
	_clearTimeout: function(timer) {
		clearTimeout(timer);
		clearInterval(timer);
		return null;
	}
};


// -------------------------------------------------------------------------------------
function secRequest(hotel_id,hash){
	api('make','secondary_request','hotel_id='+hotel_id+'&hash='+hash+'&loc_id='+location_id);
}
// -------------------------------------------------------------------------------------
function prepareLink(element){
	element.onclick = function(){ 
		var anchor = this.href.split("#"); 
		$$('#search_result table')[0].setOpacity(.3);
		api('get','locationrates',anchor[1],0);
		Effect.ScrollTo('main', {duration:0});
		return true;
	}

}
// -------------------------------------------------------------------------------------
function chkState(id){
	var has_checked = false;
	var has_unchecked = false;
	$$('#'+id+' input[type=checkbox]').each (function (el) { 
		if (el.id==id+'_all' || el.disabled==true) return;
		if (el.checked) {
			has_checked=true;
		} else {
			has_unchecked=true;
		}
	});
	if (has_checked==true && has_unchecked==false) {
		$(id+'_all').checked=true;
	} else if (has_unchecked==true) {
		$(id+'_all').checked=false;
	}
}
// -------------------------------------------------------------------------------------
function toggleState(id){
	if ($(id+'_all').checked==true){ var check=true; } else { var check=false;}
	$$('#'+id+' input[type=checkbox]').each (function (el) { 
		if (el.id==id+'_all' || el.disabled==true) return;
		el.checked=check;
	});
}
// -------------------------------------------------------------------------------------
var gallery_initialized=false;
var Gallery = {
	init: function() {
		addUnLoadEvent(function () { Gallery=null; } );
		if (gallery_initialized==true) return;
		gallery_initialized = true;
		this.thumbSize = 112.5;
		this.thumbSizeReal = 113.5;
		if (!$('photos')) return;
		this.anch = new Array();
		$('bigimgcont').style.width="500px";
		$('bigimgcont').style.height="500px";
		this.bigImageContentHeight = $('bigimgcont').getHeight();
		this.it=$$('#thumbs a');
		this.container=$('thumbs');
		this.bigImage = $('big_img').firstDescendant().firstDescendant().firstDescendant();
		this.bigPrev = $('prev_img').firstDescendant();
		this.bigNext = $('next_img').firstDescendant();
		this.provLink = $('img_provider');
		//this.providerLink = this.provLink.href.replace('XXXX','');
		this.bigImage.style.width='';
		this.bigImage.style.height='';
		this.anch[0] = [];
		this.totalImages=this.it.length;
		for (a=1; a<=this.totalImages;a++){			
			var aa=a-1;
			this.anch[a] = [];
			var img = this.it[aa].href;
				var thumb_src = this.it[aa].getAttribute('thumb');
				var new_href ="#page=photos&view="+(this.it[aa].id.replace("t_",""));
			this.it[aa].href = new_href;
			this.it[aa].onclick = function () {	Gallery.showImage(this.id.replace("t_",""));}
			
			if (a==1) {  this.anch[a][0] = this.totalImages; 
			   } else {  this.anch[a][0] = a-1;	} 			
			if (this.totalImages<=a) { this.anch[a][1]=1; 
			   } else {  this.anch[a][1]=a+1; }
			
			this.anch[a][2] = new_href;
			this.anch[a][3] = img;
			this.anch[a][4] = thumb_src;
			this.anch[a][5] = (this.it[aa].firstDescendant().getAttribute('alt')).split('|');
			// anch[] index:  0 - prevous image; 1 - next image; 2 - current href ; 3 - current image src; 4- thumb  src; 5 - provider
		}
		this.outerWidth = $('outerthumbs').getWidth();
		this.visWidth = this.outerWidth-4;	
		this.maxThumbs = 8;
		this.container.style.width=(this.thumbSize*this.totalImages)+"px";
	},
	showThumbs : function (curr_id) {
		if (curr_id<=this.maxThumbs) {
			var startFrom = 1;
			var endTo = (this.maxThumbs+curr_id)<this.totalImages?this.maxThumbs+curr_id:this.totalImages;
		} else {
			var startFrom = (curr_id-this.maxThumbs);
			var endTo = curr_id+this.maxThumbs<this.totalImages?(curr_id+this.maxThumbs):this.totalImages;
		}
		for (var a=startFrom; a<=endTo;a++) {
			if (this.it[a-1].firstDescendant().src.match(/spacer.gif$/)) this.it[a-1].firstDescendant().src=this.anch[a][4];
		}
	},
	showImage: function (curr_id) {
		this.init();
		curr_id=parseInt(curr_id);
		var anch = this.anch;
		var imgSrc = anch[curr_id][3];
		var oldWidth = this.bigImage.width;
		var oldHeight = this.bigImage.height;
		var bigImage = this.bigImage;
		this.bigImage.src = "bs/designs/default/images/spacer.gif";
		this.bigImage.style.width = oldWidth;
		this.bigImage.style.height = oldHeight;
		var resizeDuration = this.resizeDuration;
		var imgPreload = new Image();
		var prov = anch[curr_id][5];
		this.provLink.innerHTML = prov[0];
		//this.provLink.href = this.providerLink+prov[1];
		var bigImageContentHeight = this.bigImageContentHeight;
		imgPreload.onload=function(){
			var newWidth = imgPreload.width;
			var newHeight = imgPreload.height;
			if (bigImageContentHeight<newHeight) {
				bigImage.style.marginTop = 0;
				bigImage.style.height = bigImageContentHeight+"px";
				bigImage.style.width = 'auto';
			}else {
				bigImage.style.marginTop = Math.round((bigImageContentHeight-newHeight)/2)+"px";
				bigImage.style.height = newHeight+"px";
				bigImage.style.width = newWidth+"px"
			}
			bigImage.src = imgSrc;
			preloadImage(anch[anch[curr_id][1]][3]);
			preloadImage(anch[anch[curr_id][0]][3]);
		}
		bigImage.src = imgSrc;
		this.bigImage.parentNode.parentNode.href = anch[anch[curr_id][1]][2];
		this.bigImage.parentNode.parentNode.onclick = function() {Gallery.showImage(anch[curr_id][1]);location.href=anch[anch[curr_id][1]][2]; return false;}
		this.bigNext.onclick = function() {Gallery.showImage(anch[curr_id][1]);location.href=anch[anch[curr_id][1]][2]; return false;}
		this.bigNext.href = anch[anch[curr_id][1]][2];
		this.bigPrev.onclick = function() {Gallery.showImage(anch[curr_id][0]);location.href=anch[anch[curr_id][0]][2]; return false;}
		this.bigPrev.href = anch[anch[curr_id][0]][2];

		imgPreload.src = imgSrc;
		if ((Math.round((-this.container.offsetLeft+this.thumbSize)/this.thumbSize)>curr_id) || ((Math.round((-this.container.offsetLeft+this.visWidth)/this.thumbSize))<curr_id)){
			this.moveTo(Math.round((curr_id*this.thumbSize+this.container.offsetLeft)-(this.thumbSize*this.maxThumbs/2)));
		}else{
			this.showThumbs(curr_id);
		}
		this.it.each(function(f) { f.removeClassName('active');});
		this.it[curr_id-1].addClassName('active');
		last_image = curr_id;
	},
	moveTo: function (direction) {
		var direct = false;
		var scroll = this.visWidth;
		if (direction=='left') {
			var xcoord= scroll; 
			if (this.container.offsetLeft+xcoord>0) xcoord=0-this.container.offsetLeft;
			var add = -this.thumbSize*this.maxThumbs;
		} else if (direction=='right') {
			var xcoord = -scroll;
			if ($('outerthumbs').scrollWidth-20 - scroll<0) xcoord = 0;
			var add = this.thumbSize*this.maxThumbs;
		} else {
			direction = parseInt(direction);
			var xcoord = -direction;
			direct = true;
			var add = direction;
		}
		new Effect.Move(this.container, { x: xcoord, y: 0, transition: Effect.Transitions.sinoidal });
		var curr_thumb  = Math.round((-this.container.offsetLeft+add)/this.thumbSize)+1 ;
		if (curr_thumb>this.totalImages) curr_thumb=this.totalImages;
		this.showThumbs(curr_thumb);
	},
	showNextImg: function(){
	},
	showPrevImg: function(){
		
	},
	moveLeft : function() {
		this.moveTo('left');
	},
	moveRight: function(){
		this.moveTo('right');
	}
	
}
// -------------------------------------------------------------------------------------
var Calendar = {
	init: function (settings) {
		addUnLoadEvent(function () { Calendar=null; } );
		var defaultSettings = {
			language: 'en',
			monthsFull: ['January','February','March','April','May','June','July','August','September','October','November','December'],
			monthsShort: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
			weekDayFull: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
			weekDayShort: ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],
			weekDaySingle: ['S','M','T','W','T','F','S'],
			txt_today: 'Today',
			txt_close: 'Close',
			startOfWeek: 1,
			md: [31,28,31,30,31,30,31,31,30,31,30,31],
			dayNames: ['sun',,,,,'fri','sat'],
			disableBefore: false,
			disableAfter: false,
			container: 'calendar',
			dateFormat: 'YYYY-MM-DD',
			nextDateOffset: 2,
			preserveDate: false,
			containerStyle: {background: '#ddd', border: 'solid 1px #aaa' }
		}
		this.today = new Date();
		this.set = Object.extend(defaultSettings,settings);
		if (this.set.startOfWeek>1)this.set.startOfWeek=1;
		if (navigator.appName=="Microsoft Internet Explorer"){
			this.isIE = true;
//			var iframe = makeElement('iframe',{src:'about:blank', frameBorder:0, scrolling:'no',id:'iframe',style:'position: absolute; width: 0; height: 0; display:none; z-index:9999;'});
//			document.body.insertBottom(iframe);

			document.write('<iframe src="about:blank" frameBorder="0" scrolling="no" id="iframe" style="position: absolute; width: 0; height: 0; display:none;"></iframe>');
		}

	},
	
	createCalendar: function(y,m) {
		//m --;
		var d = new Date(y,m,1);
		this.currentMonth = m;
		this.currentYear = y;
		
		var md = this.set.md;
		if (d.getFullYear()%4==0) md[1] = 29;
		
		var sDay = d.getDay();
		var mDays = md[m];
		var arr = new Array();
		var elem = new Array();
		var b=0;
		elem.push('<div class="cl"><span onclick="Calendar.hide();" style="cursor: pointer;" class="btn">'+this.set.txt_close+'</span></div>');
		elem.push('<div class="h"><span class="arr l" onclick="Calendar.setMonth(-1);" style="cursor:pointer">&lt;&lt;</span> '+(this.set.monthsFull[d.getMonth()])+' '+d.getFullYear()+' <span class="arr r" onclick="Calendar.setMonth(+1);" style="cursor:pointer">&gt;&gt;</span></div>');
		var dayOfWeek = this.set.startOfWeek;
		for (var a=0;a<7;a++) {
			var dayClassName = new Array();
			dayClassName.push(this.set.dayNames[dayOfWeek]);
			dayClassName.push('dn');
			arr.push('<li class="'+dayClassName.join(" ")+'">'+this.set.weekDayShort[dayOfWeek]+'</li>');
			if (++dayOfWeek>6) dayOfWeek=0;
		}
		if (this.set.startOfWeek!=sDay) { for(var a=this.set.startOfWeek;a<(sDay==0?7:sDay);a++) {arr.push('<li class="empt"></li>');}}
		dayOfWeek = sDay;
		for (a=1;a<=mDays;a++) {
			var dayClassName = new Array();
			dayClassName.push(this.set.dayNames[dayOfWeek]);
			var thisDate = new Date(this.currentYear,this.currentMonth,a);
			if (this.currentYear == this.today.getFullYear() && this.currentMonth == this.today.getMonth() && a == this.today.getDate()) dayClassName.push('today');
			if (this.currentYear == this.currentValue.getFullYear() && this.currentMonth == this.currentValue.getMonth() && a == this.currentValue.getDate()) dayClassName.push('cval');
			if ((this.noSelectBefore!=false && 
				(this.currentYear<this.noSelectBefore.getFullYear() ||
				(this.currentYear<=this.noSelectBefore.getFullYear() && this.currentMonth<this.noSelectBefore.getMonth()) || 
				(this.currentYear<=this.noSelectBefore.getFullYear() && this.currentMonth<=this.noSelectBefore.getMonth() && a<=this.noSelectBefore.getDate()))
			) || (this.set.disableBefore==true && 
				(this.currentYear<this.today.getFullYear() ||
				(this.currentYear<=this.today.getFullYear() && this.currentMonth<this.today.getMonth()) || 
				(this.currentYear<=this.today.getFullYear() && this.currentMonth<=this.today.getMonth() && a<this.today.getDate()))
			)){
				dayClassName.push('del');
				arr.push('<li class="'+dayClassName.join(' ')+'">'+a+'</li>'); 
			} else {
				arr.push('<li onclick="Calendar.selectDate('+this.currentYear+','+(this.currentMonth+1)+','+a+',this);" onmouseover="Calendar.mouseOver(this);" onmouseout="Calendar.mouseOut(this);" style="cursor:pointer" class="'+dayClassName.join(' ')+'">'+a+'</li>'); 
			}
			if (++dayOfWeek>6) dayOfWeek=0;
		}
		elem.push('<ul class="cal '+this.set.className+'">'+arr.join('')+'</ul>');
		elem.push('<div style="clear:both;cursor:pointer;" class="todaybtn" onclick="Calendar.goToday()">'+this.set.txt_today+': '+this.dateToStr(this.today)+'</div>');
		this.container.innerHTML = elem.join('');
		if (this.shadow) {
			this.shadow.style.width = $(this.container).getWidth() + 'px';
			this.shadow.style.height = $(this.container).getHeight() + 'px';
		}
	},
	setMonth: function (val) {
		var month = this.currentMonth+1;
		if (val<0) { month=month-1;	if (month<1) { month=12; year = this.currentYear-1; } else year = this.currentYear; } 
		else  { month=month+1;	if (month>12) { month=1; year = this.currentYear+1; } else year = this.currentYear;}
		this.createCalendar(year, month-1);
		$(this.container).blur();
	},
	mouseOver: function (element){
		BFaddClassName(element,'hover');
	},
	mouseOut: function (element){
		BFremoveClassName(element,'hover');
	},
	selectDate: function (y,m,d,element){	
		var bbf = this.dateToStr(y,m,d);
		$(this.input).value = bbf;

		if (this.syncElement) {$(this.syncElement).value=bbf;}		
		if (this.nextOpen!==false) {
			var oldValue = this.strToDate($(this.nextOpen).value);
			if (!this.set.preserveDate ||
				(y>oldValue.getFullYear() ||
				(y>=oldValue.getFullYear() && m>oldValue.getMonth()+1) || 
				(y>=oldValue.getFullYear() && m>=oldValue.getMonth()+1 && d>=oldValue.getDate()))
			) {
				$(this.nextOpen).value = this.nextDate(y,m,d,this.set.nextDateOffset);
			}
			var dd = $(this.nextOpen);
			var bbb = [];
			for(a in dd){ 
				bbb.push(a+' :\n\t'+dd[a]);
			}
			//alert (bbb.join('\n'));
			$(this.nextOpen).focus();
		} else this.hide();

	},
	nextDate: function(y,m,d,days){
		if (!days) days=this.set.nextDateOffset;
		var md = this.set.md; if (y%4==0) md[1] = 29;
		d = d+days;
		if (d>md[m-1]) { 
			d = d-md[m-1]; m++; 
			if (m>11) {	y++; m=0;}
		}
		return this.dateToStr(y,m,d);
	},
	goToday: function() {
		this.createCalendar(this.today.getFullYear(), this.today.getMonth());
	},
	dateToStr: function (y,m,d) {
		if (typeof(y)!='object'){
			var date = new Date(y,m-1,d);
		} else var date = y;
		var year = date.getFullYear();
		var month = (date.getMonth()<9)?'0'+(date.getMonth()+1):(date.getMonth()+1);
		var day = date.getDate()<10?'0'+date.getDate():date.getDate();
		return this.set.dateFormat.replace(/Y+/i,year).replace(/M+/i,month).replace(/D+/i,day);
		
	},
	strToDate: function(string){
		var splitter = this.set.dateFormat.match(/[\-\.\,]/);
		var str = string.split(splitter);
		var names = this.set.dateFormat.split(splitter);
		var dates = {};
		for (a=0;a<names.length;a++){ dates[names[a].toLowerCase().substring(0,1)]=str[a];}
		if (!isNaN(dates.y) && !isNaN(dates.m) && !isNaN(dates.d)) var newDate = new Date(dates.y,dates.m-1,dates.d); 
		else  var newDate = this.today;
		return newDate;
	},
	show: function(element,bro,sis,syncElement) {
		this.input = $(element.name);
		this.input.setAttribute("AutoComplete","off");
		if ($(syncElement)!==null) this.syncElement= syncElement;
		try{
			if ($(this.set.container)) this.container = $(this.set.container);
			else {
				this.container = makeElement('div',{ id:this.set.container, style:"display: none;"});
				this.container.style.position = "absolute";
				this.container.style.zIndex = "11000";
				document.body.insertBefore(this.container,document.body.childNodes[0]);
			}
			if (bro) { this.noSelectBefore = this.strToDate($(bro).value);} else this.noSelectBefore = false;
			
			if (sis) { this.nextOpen = sis; } else this.nextOpen=false;
			var xy = this.input.cumulativeOffset();
			var size = this.input.getDimensions();
			this.container.style.top=(xy[1]+size.height)+'px';
			this.container.style.left=xy[0]+'px';
			this.currentValue=this.strToDate(this.input.value);
			this.createCalendar(this.currentValue.getFullYear(),this.currentValue.getMonth());
			if (this.isIE){
				var oldd = $(this.container).style.display;
				$(this.container).style.display="block";
				$(this.container).style.zIndex=11000;
				iFrame=$('iframe');
				iFrame.style.left =$(this.container).offsetLeft + 'px';
				iFrame.style.top =$(this.container).offsetTop + 'px';
				iFrame.style.width =$(this.container).offsetWidth + 'px';
				iFrame.style.height =$(this.container).offsetHeight+'px';
				$(this.container).style.display=oldd;
				iFrame.show();
				iFrame.style.zIndex=10999;
				iFrame.style.position="absolute";
				iFrame.style.zIndex = 10999;

			} else {
				if (!this.shadow){
					this.shadow = makeElement('div',{id:'calendar_shadow',style:'position: absolute; background: #000;'});
					this.shadow.setOpacity(0.5);
					document.body.appendChild(this.shadow);
				}
				if (this.shadow){
					var oldd = $(this.container).style.display;
					$(this.container).style.display="block";
					$(this.container).style.zIndex=10000;
					this.shadow.style.left = ($(this.container).offsetLeft +5)+ 'px';
					this.shadow.style.top = ($(this.container).offsetTop +5)+ 'px';
					this.shadow.style.width = $(this.container).getWidth() + 'px';
					this.shadow.style.height = $(this.container).getHeight() + 'px';
					$(this.container).style.display=oldd;
					this.shadow.show();
					this.shadow.style.zIndex = 9999;
					this.shadow.show();
				}
			}
			$(this.container).show();
			document.onkeydown = function(e){ 
				if (!e) e = window.event;
				var key	= e.keyCode || e.wich;
				if (key==27 || key==13){
					Calendar.hide(); 
				}
			};


		} catch (err) {
			alert(err.message);
		}

	},
	hide: function() {
		if (this.shadow) this.shadow.hide();
		$(this.container).hide();
		document.onkeydown=function(){} 
		document.onclick = function(){}
		if (this.isIE) {
			$('iframe').style.display="none";
		}
	}
}
// -------------------------------------------------------------------------------------
function setDropDown(element,value){
	var opt = $$('#'+element+' option');
	for(a=0;a<opt.length;a++) {
		if (opt[a].value+''==value+'') {
			opt[a].selected=true; 
		} else {
			opt[a].selected=false;
		}
		if ($('select'+element)) $('select'+element).update(value);
	}

}
// -------------------------------------------------------------------------------------
function  getNearestHotels(obj) {
	if (checking_process_map==true) {
		confirm ("do you want to stop current search?");
		return;
	}
	if (!obj) {
		var obj = new Object;
		obj.lat = lastLat;
		obj.lng = lastLng;
		obj.limit = $('num_hotels').value;
	}
	checking_process_map = true;
	var params = post($('m_chkinout'));
	params += '&lat='+obj.lat;
	params += '&lng='+obj.lng;
	params += '&limit='+obj.limit;
	api('get','getNerarestHotels',params);
}
// -------------------------------------------------------------------------------------
var autocomp = null;
var autoComplete = {

	init: function(el, options) {
		this.el = $(el);
		this.type = null;
		this.value = this.el.value;
		this.userText = this.el.value;
		this.requestSent = false;
		this.def = {
			minChars:		1,
			className:		'autocomplete',
			listClassName:	'autocompletelist',
			showNoResultMsg:true,
			noResultMsg:	'Sorry. no results... ',
			closeNoResultTime: 2000,
			opacity:		1,
			maxFetch:		10,
			maxEntries:		10,
			timeout:		5, 
			delay: 			.3,
			minWidth:		100,
			maxWidth:		300,
			maxHeight:		400,
			typeTimeout: 	600,
			container: 		this.el,
			link:			true,
			data:			null,
			topDomain: 		null,
			getSizeFrom:	this.el
		}
		Object.extend(this.def, options || {});
		this.selectedIndex = false;
		this.urls = new Array();
		var p = this;
		this.el.onkeyup = function(e){ p.onKeyUp(e); }
		this.el.onkeypress = function(e){ p.onKeyPress(e); }
		var posParent = this.el.getOffsetParent();
		if (posParent.tagName!='BODY') this.posElement = posParent.cumulativeOffset(); else this.posElement = [0,0];

		if (navigator.appName=="Microsoft Internet Explorer"){
			this.isIE = true;
			if (!$('iframe')) {
//			var iframe = makeElement('iframe',{src:'about:blank', frameBorder:0, scrolling:'no',id:'iframe',style:'position: absolute; width: 0; height: 0; display:none; z-index:9999;'});
//			alert (iframe);
//			document.body.insertBottom(iframe);
			document.write('<iframe src="about:blank" frameBorder="0" scrolling="no" id="iframe" style="position: absolute; width: 0; height: 0; display:none;"></iframe>');
			}
		}
	},
	
	prepare: function (element,options) {
		var p = this;
		var elements = new Array();
		var f = $(element);
		f.setAttribute("AutoComplete","off"); 
		var oldfocus = f.onfocus;
		var oldblur = f.onfocus;
		f.onfocus = function() {autoComplete.init(f, options); if (typeof(oldfocus)=='function') oldfocus();
			//$$('#'+p.el.form.id+' input[type=radio]').each( function(r){ if (r.checked) p.type = r.value;});
		}
		f.onblur = function() {autoComplete.hideSuggestions(); if (typeof(oldblur)=='function') oldblur();}
		addUnLoadEvent(function () { autoComplete=null;});
	},
	
	showSuggestions: function (){
		this.clearTimer();
		if ($(this.el.id+'_'+this.def.listClassName)) $(this.el.id+'_'+this.def.listClassName).show();
		if (this.isIE) { 
			$('iframe').show();
		}
	},	
	
	hideSuggestions: function (now){
		try{
			this.selectedIndex = false;
			if ($(this.el.id+'_'+this.def.listClassName)!=null) {
				var p = this;
				var listName = p.el.id+'_'+p.def.listClassName;
				p.timeoutId = setTimeout( function () { 
					if($(listName)) $(listName).hide();
					if (p.isIE) { $('iframe').hide(); }
				}, now?0:p.def.typeTimeout);
			}
			
 		} catch (err){
		}

	},
	
	setHighlightedValue: function (id) {
		if (id==null) id = this.selectedIndex;
		if (this.def.link) {
			//if (this.urls[id].url) window.location.href = this.urls[id].url;
			//else 
			window.location.href = this.urls[id].href;
		} else if (id!==false) {
			if (this.def.setId) this.def.setId.value = this.urls[id].id;
			this.el.value = this.urls[id].title;
			this.closeSuggestions();
		} else {
			this.hideSuggestions(true);
		}
		//return false;
	},
	
	changeHighlight: function (ind) {
		var list = $$('#'+this.el.id+'_'+this.def.listClassName+' li');
		if (this.selectedIndex===false) { selectedIndex = 0 }
		else if (ind<0) { if (this.selectedIndex>0) selectedIndex = this.selectedIndex-1;} 
		else if (ind>0){ if (this.selectedIndex<list.length-1) selectedIndex = this.selectedIndex+1;}
		else {selectedIndex = this.selectedIndex;}
		this.setHighlight(selectedIndex);
	},
	
	setHighlight: function (index) {
		try {
			this.selectedIndex = parseInt(index);
			var list = $$('#'+this.el.id+'_'+this.def.listClassName+' li');
			for (var a=0; a<list.length;a++) {
				if (a==index) { 
					BFaddClassName(list[a],'hover');
					//this.el.value = this.urls[this.selectedIndex].title;
				} else {
					BFremoveClassName(list[a],'hover');
				}
			}
		} catch (err){
			debug (err);
		}
	},
	
	onKeyPress: function (e) {
	  	if (!e) e = window.event; 	
	  	var key = e.keyCode || e.wich;	  
	    switch(key){
	      case Event.KEY_RETURN:	if (this.selectedIndex!==false){ this.setHighlightedValue(); Event.stop(e);} break;
	      case Event.KEY_ESC:  		this.hideSuggestions(true); this.el.value = this.value; Event.stop(e); this.stopRequest(); break;
	      case Event.KEY_TAB:  		this.setHighlightedValue(); break;
	    } 
		return true;
	},
	onKeyUp: function (e) {
		this.clearTimer();
		var p = this;
	  	if (!e) e = window.event; 	var key = e.keyCode || e.wich;
	  	if (key == Event.KEY_UP){
			p.changeHighlight(-1); Event.stop(e);
		} else if (key == Event.KEY_DOWN) {
			p.showSuggestions();
			p.changeHighlight(1); Event.stop(e);
	  	} else if (key == Event.KEY_LEFT || key == Event.KEY_RIGHT) {
		} else if ((key<32 && key!=8) || key==91 || key==92 || key==93 || key==144) {
			this.stopRequest();
		} else {
			if (this.def.setId) this.def.setId.value = '';
			this.value = this.el.value;
			if (this.def.data==null){
					p.closeSuggestions();
					this.timeoutId = setTimeout( function () { p.getSuggestions(p.el.value);}, p.def.typeTimeout);
			} else {
					this.timeoutId = setTimeout( function () { p.filterSuggestions(p.el.value);}, 0);
			}
			this.id = null;
		}
		return true;
	},
	
	filterSuggestions: function (data) {
		data = data.toLowerCase();
		if(data.length<this.def.minChars) {
			this.closeSuggestions();
			return;
		}
		this.search = data;
		var ad = this.def.data;
		var adl = ad.length;
		var pattern = new RegExp(data,'i');
		var result = [];
		var b = 0;
		var dd =0;
		this.urls = [];
		var location_url = '';
		for (a=0;a<adl;a++) {
			if (b>this.def.maxEntries) continue;
			if (ad[a][1].match(pattern)) { 
				result.push({id:ad[a][0],n:ad[a][1],t:'l',i:'',url:location_url}); 
				b++;
			}
		}
		if (result.length<1) {
			this.showNoResults();
		} else {
			var htmlData = this.createSuggestions(result);
			this.insertList(htmlData);
		}
		return	;
	},
	
	getSuggestions: function (data) {
		this.stopRequest();
		this.closeSuggestions();
		if (data.match(/^[\s _\.\-,_\`\'\";:><?\/\d]+$/) || data=='') { return false; }
		if (this.def.type){ 
			var type = this.def.type;
		} else {
			var type; $$('#'+this.el.form.id+' input[type=radio]').each( function(r){ if (r.checked) type = r.value;});
		}
		this.search = data;
		BFaddClassName(this.el,'process');
		this.type = type;
		this.urls = [];
		var params='in=main&op=api&what=autocomplete&action='+type+'&search='+data;
		params += '&obj='+this.el.id;
		var url=base_url+'index.php';
		autocomp = this;
		var MyAjax = new Ajax.Request(
			url,
			{
				encoding: 'UTF-8',
				method: 'post',
				parameters: params,
				onComplete: autocomp.loadContent
			});
		this.requestSent = MyAjax;
	},
	
	loadContent: function(received) {
		this.requestSent = false;
		for (a in autocomp) {
			this[a] = autocomp[a];
		}
		BFremoveClassName(this.el,'process');
		autocomp = null;
		try {
			var raw = received.responseText;
			var b=0;
			if (raw !='') {
				data = eval(raw);
				this.closeSuggestions();
				var htmlData = this.createSuggestions(data);
				this.appendList(htmlData);
			} else if (this.def.showNoResultMsg) {
				this.showNoResults();
			}
		} catch (err){
//			debug(err);
		}
	},

	stopRequest: function(){
		if (this.requestSent) {
			this.requestSent.abort();
			BFremoveClassName(this.el,'process');
		}
	},
	
	showNoResults: function() 
	{
		this.closeSuggestions();
		var htmlData = makeElement('div', {innerText:this.def.noResultMsg});
		BFaddClassName(htmlData,'notice');
		this.appendList(htmlData);
		var p=this;
		p.timeoutId = setTimeout( function () { p.closeSuggestions();}, p.def.closeNoResultTime);	
	},
	
	clearSuggestions: function () 
	{
		this.el.value='';
	},
	
	closeSuggestions: function () 
	{
		try {
		this.selectedIndex = false;
		if ($(this.el.id+'_'+this.def.listClassName)) $(this.el.id+'_'+this.def.listClassName).remove();
		if (this.isIE) { 
			$('iframe').hide();
		}
		} catch (err){
//			debug(err);
		}
	},
	
	appendList: function(data) 
	{
		this.closeSuggestions();
		var minWidth = this.def.getSizeFrom.getWidth();
		var height = this.def.getSizeFrom.getHeight();
		var left = this.def.getSizeFrom.cumulativeOffset().left - this.posElement[0];
		var top = this.def.getSizeFrom.cumulativeOffset().top - this.posElement[1];
		var div = makeElement('div',{id:this.el.id+'_'+this.def.listClassName});
		BFaddClassName(div,this.def.listClassName);
		div.style.position = "absolute";
		div.style.left = left+'px';
		div.style.top=(top+height)+'px';
		if (this.def.opacity && this.def.opacity<1) div.setOpacity(this.def.opacity);
		new Insertion.After(this.el,div);
		div.appendChild(data);
		$(this.el.id+'_'+this.def.listClassName).zIndex = 1000;
		if ($(this.el.id+'_'+this.def.listClassName).getWidth() < minWidth) $(this.el.id+'_'+this.def.listClassName).style.width = minWidth+'px';
 		if (this.isIE) {
			iFrame=$('iframe');
			iFrame.style.left =this.def.getSizeFrom.cumulativeOffset().left + 'px';
			iFrame.style.top =(this.def.getSizeFrom.cumulativeOffset().top+height) + 'px';
			iFrame.style.width =div.offsetWidth + 'px';
			iFrame.style.height =div.offsetHeight+'px';
			iFrame.style.position="absolute";
			iFrame.style.zIndex = $(this.el.id+'_'+this.def.listClassName).style.zIndex-1;
			iFrame.show();
		} 
//		$(this.el.id+'_'+this.def.listClassName).style.zIndex=11001;
	},
	
	insertList: function(data) 
	{
		if ($(this.el.id+'_'+this.def.listClassName)) {
			var div = $(this.el.id+'_'+this.def.listClassName);
			div.update(data);
			if (div.getWidth() < minWidth) div.style.width = minWidth+'px';
			div.zIndex = 1000;
			if (this.isIE) {
				var minWidth = this.def.getSizeFrom.getWidth();
				var height = this.def.getSizeFrom.getHeight();
				iFrame=$('iframe');
				iFrame.style.left = this.def.getSizeFrom.cumulativeOffset().left + 'px';
				iFrame.style.top = (this.def.getSizeFrom.cumulativeOffset().top+height) + 'px';
				iFrame.style.width = div.offsetWidth + 'px';
				iFrame.style.height = div.offsetHeight + 'px';
				iFrame.style.position = "absolute";
				iFrame.style.zIndex = div.style.zIndex - 1;
				iFrame.show();
			} 
			div.show();
		} else {
			this.appendList(data);
		}
	},
	
	createSuggestions: function(data) 
	{
		if (data.length<this.def.minChars) return;
		var list = [];
		var search = '/('+this.search.replace(/[\s \.\-]+/g,'|')+')/ig';
		list = makeElement('ul');
		for (var a=0;a<data.length;a++) {
			var li = makeElement('li',{innerHTML:'<span class="a" onmouseover="autoComplete.setHighlight('+a+');" onmouseout="autoComplete.setHighlight();" onclick="autoComplete.setHighlightedValue('+a+');">'+data[a].n.replace(eval(search),'<em>$&</em>')+(data[a].i?'<small>'+(data[a].i.replace(eval(search),'<em>$&</em>'))+'</small>':'')+'</span>'});
			list.appendChild(li);
			this.urls.push({id:data[a].id,title:data[a].n+(data[a].i?', '+data[a].i:''),href:base_url+site_lang+'/'+(data[a].t=='l'?'location':'hotel')+'/'+data[a].id+'.html', url:data[a].url?data[a].url:false});
		}
		return list;
	},
	
	clearTimer: function () 
	{
		clearTimeout(this.timeoutId);
	}
};

// -------------------------------------------------------------------------------------
function toggleOrderBox() {
	var box = $('orderBox');
	if(box.style.display=='none') {
		box.style.zIndex='300';
		Effect.toggle(box,'blind',{ duration: .3 }); 		
		document.body.onclick=function() {
			toggleOrderBox();
		}
	}
	else {
		Effect.toggle(box,'blind',{ duration: .3 }); 
		document.body.onclick=function() {}
	}
	return false;
}
// -------------------------------------------------------------------------------------
function toggleLimitBox() {
	var box = $('limitBox');
	if(box.style.display=='none') {
		Effect.toggle(box,'blind',{ duration: .3 }); 
		
		document.body.onclick=function() {
			toggleLimitBox();
		}
	}
	else {
		//box.style.display='none';
		Effect.toggle(box,'blind',{ duration: .3 }); 
		document.body.onclick=function() {}
	}
	return false;
}
// -------------------------------------------------------------------------------------
function showNearbyHotels(element){
	$$('#search_result .nearhotelsrow').each(function(f){ f.show();});
	element.parentNode.parentNode.removeChild(element.parentNode);
}
// -------------------------------------------------------------------------------------
function setFilter(type,value) { 
	var currentUrl = window.location;
	var regex = new RegExp('&'+type+'=\d+');
	var newUrl = currentUrl.match(regex);
	window.location = newUrl;
	return false;
}
// -------------------------------------------------------------------------------------
function getPriceDlg(el,hotelId) {
	if(!$('getPriceDlg')){
		alert('No dialog');
		return;
	}
	var d = $('getPriceDlg');
}
// -------------------------------------------------------------------------------------
function showLoading(){
	try{
		var div = $('loaderDiv');
		div.show();
		centerToScreen(div);	
		var docSize = document.body.getDimensions();
		var overlay = $('loaderoverlay');
		overlay.show();
		overlay.style.top='0px';
		overlay.style.left='0px';
		overlay.style.width = docSize.width+'px';
		overlay.style.height = docSize.height+'px';
		overlay.style.zIndex = '10000';
		overlay.style.position="absolute";
		overlay.style.background="none";
	} catch (err) {
	}
}
// -------------------------------------------------------------------------------------
function getPriceDlg(element,hotelId,locationId){
	var div = $('bookingDiv');
	//div.show();
	centerToScreen(div);
	$('bookingLocation').value=locationId;
	$('bookingHotel').value=hotelId;
}
// -------------------------------------------------------------------------------------
function centerToScreen(div){
	var divSize = div.getDimensions();
	var docScroll = document.viewport.getScrollOffsets(); 
	var docSize = document.viewport.getDimensions(); 
	
	div.style.position = "absolute";
	div.style.top = docScroll.top+(docSize.height/2-divSize.height/2)+'px';
	div.style.left = docScroll.left+(docSize.width/2-divSize.width/2)+'px';;
}
// -------------------------------------------------------------------------------------
function closeBookingDiv(){
	$('bookingDiv').style.left="-3000px";
}
// -------------------------------------------------------------------------------------
function getHotelRates() {
	closeBookingDiv();
	showLoading();
}
// -------------------------------------------------------------------------------------
function addLoading(){
	var elems = $$('a.ld,.pgng>a, .pgng .rpp li a');
	for(a=0;a<elems.length;a++) {
		elems[a].observe('click',function(){showLoading()});
	}
}
// -------------------------------------------------------------------------------------
var postDelay = null;
function submitForm(forma,delay){
	clearTimeout(postDelay);
	postDelay = window.setTimeout (function() { 
		showLoading();
		$(forma).submit();
	}, (delay?0:2000));
}
// -------------------------------------------------------------------------------------
function markChecked(element,group){
	submitForm('filterform');
}
// -------------------------------------------------------------------------------------
function clearFilter(type) {
	switch (type){
		case 'all':
			$$('#filterbar #pricerng input[type=hidden]').each(function(f){ f.value=''; });
			$$('#filterbar #featfilter input[type=checkbox]').each(function(f){ f.checked=false; });
			$$('#filterbar #starsfilter input[type=checkbox]').each(function(f){ f.checked=false; });
			$('maxrange').value='';
			$('hotelname').value='';
		break;
		case 'distance':
			$('maxrange').value='';
		break;
		case 'price':
			$$('#filterbar #pricerng input[type=hidden]').each(function(f){ f.value=''; });
		break;
		case 'features':
			$$('#filterbar #featfilter input[type=checkbox]').each(function(f){ f.checked=false; });
		break;
		case 'stars':
			$$('#filterbar #starsfilter input[type=checkbox]').each(function(f){ f.checked=false; });
		break;
		case 'name':
			$('hotelname').value='';
		break;
	}
	submitForm('filterform',true);
}
// -------------------------------------------------------------------------------------
function fixLines() {
	$('search_result').style.height="auto";
	var d1 = $('filterbar').getDimensions();
	var d2 = $('search_result').getDimensions();
	if (d1.height>=d2.height) {$('search_result').style.height = (d1.height+10)+'px';}
}
// -------------------------------------------------------------------------------------
function markChecked(current,set) {
	elements = $$('#'+set+'filter input[type=checkbox]');
	var remove_all=false;
	var has_checked =false;
	if (current.id.replace(/\w+_/,'')=='0') { 
		if (current.checked==true) remove_all=true;
	} else {
		if (current.checked==true) $(set+'_0').checked=false;
	}
	elements.each(function(f){
		if (remove_all && f.id.replace(/\w+_/,'')!='0') f.checked=false;
		if (f.checked==true) has_checked=true;
	});
	if (has_checked==false && remove_all==false) {
		$(set+'_0').checked=true;
	}
	submitForm('filterform');
}
// -------------------------------------------------------------------------------------
//addDomLoadEvent(Custom.init);
addDomLoadEvent(Calendar.init({disableBefore:true}));
//addDomLoadEvent(styleTable);
addDomLoadEvent(loadUri);
addDomLoadEvent(addLoading);
