sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("SPAN");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" over";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" over";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

Util = new function () {
	this.countChar = function (str,chr) {
		var _len = str.length;
		var _result = 0;
		for (var _i = 0; _i < _len; _i++) {
			if (str.charAt(_i) == chr) {
				_result++;
			}
		}
		return _result;
	}
	
	this.countNonASCII = function (str) {
		var _len = str.length;
		var _result = 0;
		for (var _i = 0; _i < _len; _i++) {
			if (str.charCodeAt(_i) > 127) {
				_result++;
			}
		}
		return _result;
	}
	
	this.isValidName = function (str) {
		var _len = str.length;
		var _result = 0;
		for (var _i = 0; _i < _len; _i++) {
			if ((str.charCodeAt(_i) < 97 || str.charCodeAt(_i) > 122) && 
					(str.charCodeAt(_i) < 65 || str.charCodeAt(_i) > 90)) {
				_result++;
			}
		}
		return _result;
	}
	
	this.isValidCyrillicName = function (str) {
		var _len = str.length;
		var _result = 0;
		for (var _i = 0; _i < _len; _i++) {
			if ((str.charAt(_i) < 'เภ' || str.charAt(_i) > 'แ?') && 
					(str.charAt(_i) < 'เ?' || str.charAt(_i) > 'เ') &&
					str.charCodeAt(_i)!=32) {
				_result++;
			}
		}
		return _result;
	}
	
	this.countWhiteSpaces = function (str) {
		var _len = str.length;
		var _result = 0;
		for (var _i = 0; _i < _len; _i++) {
			if (str.charCodeAt(_i) < 33) {
				_result++;
			}
		}
		return _result;
	}
	
	this.countNonDigits = function (str) {
		var _len = str.length;
		var _result = 0;
		for(var _i = 0; _i < _len; _i++) {
			if ((str.charCodeAt(_i) < 48) || (str.charCodeAt(_i) > 57)) {
				_result++;
			}
		}
		return _result;
	}
	
	this.isInteger = function (n) {
		return (!isNaN(n) && (Math.ceil(n) == Math.floor(n)));
	}
	
	this.isNatural = function (n) {
		return this.isInteger(n) && (n >= 0);
	}
	
	this.isPositiveNumber = function (n) {
		return (!isNaN(n) && (n > 0));
	}
	
	this.isPositiveInteger = function (n) {
		return this.isInteger(n) && (n > 0);
	}
	
	this.trimLeft = function (str) {
		var _len = str.length;
		var _i;
		var _result = new String(str);
		if (_len < 1) {
			return _result;
		}
		for (_i = 0; _i < _len; _i++) {
			if ((str.charCodeAt(_i) > 32) || (str.charCodeAt(_i) < -1)) {
				break;
			}
		}
		if (_i < 1) {
			return _result;
		}
		_result = _result.substring(_i,_len);
		return _result;
	}
	
	this.trimRight = function (str) {
		var _len = str.length;
		var _i;
		var _result = new String(str);
		if (_len < 1) {
			return _result;
		}
		for (_i = 0; _i < _len; _i++) {
			if ((str.charCodeAt(_len - _i - 1) > 32) || (str.charCodeAt(_i) < -1)) {
				break;
			}
		}
		if (_i < 1) {
			return _result;
		}
		_result = _result.substring(0,_len - _i);
		return _result;
	}
	
	this.trim = function (str) {
		var _result = this.trimLeft(str);
		if (_result.length > 0) {
			_result = this.trimRight(_result);
		}
		return _result;
	}
	
	this.isBlank = function (str) {
		return (str == null) || (this.trimLeft(str).length == 0);
	}
	
	this.isEmail = function (str) {
		var _str = new String(this.trim(str));
		if (this.countWhiteSpaces(_str) > 0) {
			return false;
		}
		if (this.countNonASCII(_str) > 0) {
			return false;
		}
		if ((_str.length < 6) || (this.countChar(_str,"@") != 1)) {
			return false;
		}
		var leftPart = _str.substring(0,_str.indexOf("@"));
		var rightPart = _str.substr(_str.indexOf("@") + 1);
		return ((leftPart.length > 0) && (rightPart.length > 3)
			&& (this.countChar(rightPart,".") > 0)
			&& (rightPart.charAt(rightPart.length - 1) != ".")
			&& (rightPart.charAt(0) != "."));
	}
	
	this.isPhoneNumber = function (str) {
		var _len = str.length;
		var _result = true;
		var _code;
		if (_len < 1) {
			return false;
		}
		for(var _i = 0; _i < _len ; _i++) {
			_code = str.charCodeAt(_i);
			if(
				(_code == 32) // space
				|| ((_code >= 48) && (_code <= 57)) // digits
				|| (_code == 43) // plus sign
				|| (_code == 45) // minus sign
				) {
				continue;
			}
			_result = false;
			break;
		}
		return _result;
	}
	
	this.isUrl = function (str) {
		var _str = new String(this.trim(str));
		if (this.countWhiteSpaces(_str) > 0) {
			return false;
		}
		if (this.countChar(_str,".") < 1) {
			return false;
		}
		return true;
	}
	
	this.fillLeft = function (s,c,l) {
		if (s.length >= l) {
			return new String(s);
		}
		var result = "";
		for (var i = 0; i < (l - s.length); i++) {
			result += c;
		}
		return result + s;
	}
	
	this.fillRight = function (s,c,l) {
		if (s.length >= l) {
			return new String(s);
		}
		var result = "";
		for (var i = 0; i < (l - s.length); i++) {
			result += c;
		}
		return s + result;
	}
	
	/*
	 * Function call onFocus="textFocus(this);" onBlur="textBlur(this);"
	 */
	this.textFocus = function (el, val) {
		if (val) {
			el.defaultValue = val;
			if (el.value == val) {
				el.value = "";
			}
		} else if (el.value != "") {
			el.defaultValue = el.value;
			el.value = "";
		}
	}
	
	this.textBlur = function (el, val) {
		if (val) {
			el.defaultValue = val;
		}
		if (el.value == "") {
			el.value = el.defaultValue;
		}
	}
		
	this.findXCoord = function (evt) {
		if (evt.x) {
			return evt.x;
		}
		if (evt.pageX) {
			return evt.pageX;
		}
	}
	
	this.findYCoord = function (evt) {
		if (evt.y) {
			return evt.y;
		}
		if (evt.pageY) {
			return evt.pageY;
		}
		return null;
	}
		
	this.getElementInAllB = function (str) {
		if (document.layers) {
			return document.layers[str];
		} else if (document.getElementById) {
			return document.getElementById(str);
		} else if (document.all) {
			return document.all[str];
		}
		return null;
	}
	
	this.findFormElement = function (theForm, name) {
		for (var i = 0; i < theForm.elements.length; i++) {
			var el = theForm.elements[i];
			if ((el.name == name) || (el.id == name)) {
				return el;
			}
		}
		return null;
	}
	
/*  แ?แ?เฮเมแ? เยแ?เฯเหแ?เยเภเห แ?แ?เหเฯ เรเฮแ?แ?เศเอเศแ?   */	
	this.buildUrl = function (link) {
		if ((link == 'http://hotels.pososhok.ru/eng/bookhotels/bookhotels.php?action=popup&page=info') || (link == 'http://hotels.pososhok.ru/bookhotels/bookhotels.php?action=popup&page=info')) {
			return link;
		}
		else {
			if (link.charAt(0) == '/') {
				return link;
			}
			var p = BASE_URL.indexOf(";jsession");
			if (p == -1) {
				return BASE_URL + link;
			}
			return BASE_URL.substr(0, p) + link + BASE_URL.substr(p, BASE_URL.length);
		}
	}
}

PopupUtil = new function () {
	this.showTicket = function (url) {
		var wndName = "ticketWnd";
		var w = 650;
		var h = 500;
		var l = (screen.availWidth - w) / 2;
		var t = (screen.availHeight - h) / 2;
		var wndFeatures = "toolbar=no,location=no,directories=no,status=no,menubar=1,scrollbars=yes,resizable=yes,top="
			+ t + ",left=" + l + ",width=" + w + ",height=" + h;
		var popupWnd = window.open("", wndName, wndFeatures);
		popupWnd.focus();
		popupWnd = window.open(url, wndName, wndFeatures);
	}
	
	this.open = function (file, pop, w, h) {
	    if (w == null) {
	        w = 550;
	    }
	    if (h == null) {
	        h = 500;
	    }
	    var popupWnd = window.open(Util.buildUrl(file), pop,
			"width=" + w + ",height=" + h
			+ ",resizable=1,scrollbars=yes,left=50,top=50");
        popupWnd.focus();
	}
	this.showDetails = function (url) {
		var popupWnd=window.open(url,'popup','width=900,height=700,top=100,left=100,scrollbars=yes');
		popupWnd.focus();
	}
	this.showMap = function (hotelName,address,coords) {
		var mapWnd=window.open('/pososhok/hotelMap.jsp?hotelName='+hotelName+'&addressURL='+address,'map','width=900,height=700,top=140,left=140,scrollbars=yes');
		mapWnd.focus();
	}
}

DateUtil = new function () {
	this.MSEC_PER_MINUTE = 1000 * 60;
	this.MSEC_PER_HOUR = this.MSEC_PER_MINUTE * 60;
	this.MSEC_PER_DAY = this.MSEC_PER_HOUR * 24;
	// statndard minimal OUT date for calendars
	this.STANDARD_MIN_OUT_DATE = new Date();
	// statndard minimal stay for calendars (in days)
	this.STANDARD_MIN_STATE = 0;
	
	var utcHours = this.STANDARD_MIN_OUT_DATE.getHours()
			+ this.STANDARD_MIN_OUT_DATE.getTimezoneOffset() / 60;
	if (utcHours >= 15) {
		this.STANDARD_MIN_OUT_DATE.setTime(this.STANDARD_MIN_OUT_DATE.getTime()
			+ this.MSEC_PER_HOUR * (48 - utcHours));
	} else {
		this.STANDARD_MIN_OUT_DATE.setTime(this.STANDARD_MIN_OUT_DATE.getTime()
			+ this.MSEC_PER_HOUR * 12);
	}
	
	this.checkInOutDates = function (outDateStr, inDateStr, fmt, isOneWay) {
		isOneWay = (isOneWay == true);
		var msecPerDay = 24 * 60 * 60 * 1000;
		var currDT = new Date();
		currDT.setHours(0);
		currDT.setMinutes(0);
		currDT.setSeconds(0);
		currDT.setMilliseconds(0);
		var outDT = Date.parseDate(outDateStr, fmt);
		if (outDT == null) {
			return Resources.ERR_INVALID_OUT_DATE;
		}
		if ((outDT.getTime() - currDT.getTime()) < msecPerDay) {
			return Resources.ERR_OUT_DATE_TOO_SMALL;
		}
		if (isOneWay) {
			return null;
		}
		var inDT = Date.parseDate(inDateStr, fmt);
		if (inDT == null) {
			return Resources.ERR_INVALID_IN_DATE;
		}
		if ((inDT.getTime() - outDT.getTime()) < msecPerDay) {
			return Resources.ERR_INVALID_OUT_IN_INTERVAL;
		}
		if ((outDT.getTime() - currDT.getTime()) >= 331 * msecPerDay) {
			return Resources.ERR_OUT_DATE_TOO_BIG;
		}
		if ((inDT.getTime() - currDT.getTime()) >= 331 * msecPerDay) {
			return Resources.ERR_IN_DATE_TOO_BIG;
		}
		return null;
	};
	
	this.checkInsuranceDates = function (outDateStr, inDateStr, fmt) {
		var msecPerDay = 24 * 60 * 60 * 1000;
		var currDT = new Date();
		currDT.setHours(0);
		currDT.setMinutes(0);
		currDT.setSeconds(0);
		currDT.setMilliseconds(0);
		var outDT = Date.parseDate(outDateStr, fmt);
		if (outDT == null) {
			return Resources.ERR_INVALID_START_INSURANCE_DATE;
		}
		if ((outDT.getTime() - currDT.getTime()) < msecPerDay) {
			return Resources.ERR_OUT_DATE_TOO_SMALL;
		}
		var inDT = Date.parseDate(inDateStr, fmt);
		if (inDT == null) {
			return Resources.ERR_INVALID_END_INSURANCE_DATE;
		}
		if ((inDT.getTime() - outDT.getTime()) < msecPerDay) {
			return Resources.ERR_INVALID_START_END_INSURANCE_INTERVAL;
		}
		return null;
	};
	/*
	 * Compares two dates and returns: -1 if date1 earlier date2, 0 if date1 equals date2 and 1 if date1 later date2.
	 * date1 and date2 are objects of type Date
	 */
	this.compareDates = function (date1,date2) {
		var dateInt1 = date1.getTime();
		var dateInt2 = date2.getTime();
		if (dateInt1 == dateInt2) {
			return 0;
		} else if (dateInt1 < dateInt2) {
			return -1;
		} else {
			return 1;
		}
	};
	
	this.isLeapYear = function (year) {
		if (year % 4 != 0) {
			return false;
		} else if (year % 400 == 0) {
			return true;
		} else if (year % 100 != 0) {
			return true;
		} else {
			return false;
		}
	};
	
	this.getDaysInMonth = function (month,year) {
		if ((month < 1) || (month > 12)) {
			return 0;
		}
		var _daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		var _result = _daysInMonth[month - 1];
		if ((month == 2) && this.isLeapYear(year)) {
			_result++;
		}
		return _result;
	};
	
	this.isCorrectDate = function (year,month,day) {
		if (!Util.isNatural(year) || !Util.isNatural(month)
				|| !Util.isNatural(day)) {
			return false;
		}
		if ((year < 1) || (month < 1) || (month > 12) || (day < 1)) {
			return false;
		}
		var _daysInMonth = this.getDaysInMonth(month,year);
		if (day > _daysInMonth) {
			return false;
		}
		return true;
	};
	
	/**
	 *  Tries to identify the date represented in a string.  If successful it also
	 *  calls this.setDate which moves the calendar to the given date.
	 */
	this.isValidDateString = function (str, fmt) {
		return str == Date.parseDate(str, fmt).print(fmt);
	};
	
	this.isOutDateEnabled = function (date) {
		var diff = date.getTime() - this.STANDARD_MIN_OUT_DATE.getTime()
		+ this.MSEC_PER_DAY;
		return (diff >= 0) && (diff <= 331 * this.MSEC_PER_DAY);
	}
	
	this.isInDateEnabled = function (outDate, date) {
		if (outDate == null) {
			outDate = this.STANDARD_MIN_OUT_DATE;
		}
		var diff = date.getTime() - outDate.getTime()
		- this.STANDARD_MIN_STATE * this.MSEC_PER_DAY;
		return (diff >= 0) && (diff <= 331 * this.MSEC_PER_DAY);
	}
	
	this.isCheckInDateEnabled = function (date) {
		var diff = date.getTime() - this.STANDARD_MIN_OUT_DATE.getTime()
			+ this.MSEC_PER_DAY;
		return (diff >= 0) && (diff <= 331 * this.MSEC_PER_DAY);
	}
	
	this.isCheckOutDateEnabled = function (inDate, date) {
		if (inDate == null) {
			inDate = this.STANDARD_MIN_OUT_DATE;
		}
		var diff = date.getTime() - inDate.getTime()
			- this.STANDARD_MIN_STATE * this.MSEC_PER_DAY;
		return (diff >= 0) && (diff <= 30 * this.MSEC_PER_DAY);
	}
}

CalendarRestrictions = function (minDateStr, maxDateStr, fmt) {
	this.minDate = Date.parseDate(minDateStr, fmt);
	this.maxDate = Date.parseDate(maxDateStr, fmt);
	this.disabledDates = new Array();
	
	this.isDateEnabled = function (date) {
		var result = (date.getTime() >= this.minDate.getTime())
			&& (date.getTime() <= this.maxDate.getTime());
		if (!result) {
			return false;
		}
		for (var i = 0; i < this.disabledDates.length; i++) {
			if (date.getTime() == this.disabledDates[i].getTime()) {
				return false;
			}
		}
		return true;
	};
	
	this.addDisabledDates = function (datesStr, fmt) {
		var p = this.disabledDates.length;
		for (var i = 0; i < datesStr.length; i++) {
			this.disabledDates[p + i] =
				Date.parseDate(datesStr[i], fmt);
		}
	}
	
	this.getFirstEnabledDate = function(startDate) {
		var dt = (startDate == null) ? new Date(this.minDate.getTime()) : startDate;
		while (!this.isDateEnabled(dt)) {
			if (dt.getTime() > this.maxDate.getTime()) {
				return null;
			}
			dt.setDate(dt.getDate() + 1);
		}
		return dt;
	}
}

GeoNavigator = new function () {
	this.dataElement = null;
	
	this.show = function (theForm, pointType, event) {
		//this.dataElement = theForm.elements[pointType];
		this.dataElement = Util.findFormElement(theForm, pointType);
		this.showWnd(event);
	}
	
	this.setPoint = function (value) {
		if (this.dataElement != null) {
			this.dataElement.value = value;
		}
	}
	
	this.showWnd = function (event) {
		var geoNav = document.getElementById("geoNavDiv");
		if (event.pageX == null && event.clientX != null ) { 
    		var html = document.documentElement
   			var body = document.body
 
    		event.pageX = event.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)
		    event.pageY = event.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)
		}
		if (event.pageX != null) {
			geoNav.style.left = event.pageX - 150 + "px";
			geoNav.style.top = event.pageY + "px";
		} else {
			geoNav.style.left = event.x - 150 + document.body.scrollLeft + "px";
			geoNav.style.top = event.y + document.body.scrollTop + "px";
		}
		geoNav.style.display = "block";
		document.getElementById("geoNavFrame").src =
			"geoNavigator.do?pattern=" + encodeURIComponent(this.dataElement.value);
	}
	
	this.closeWindow = function (windowRef) {
		if ((windowRef.opener != null) && (windowRef.opener != self)) {
			windowRef.opener.GeoNavigator.hideWnd(windowRef);
		} else {
			parent.GeoNavigator.hideWnd();
		}
	}
	
	this.hideWnd = function (windowRef) {
		if (windowRef != null) {
			windowRef.close();
		} else  {
			document.getElementById("geoNavDiv").style.display = "none";
			document.getElementById("geoNavFrame").src = "about:blank";
		}
	}
}
HotelGeoNavigator = new function () {
	this.theForm = null;
	this.countrySelect = null;
	this.citySelect = null;
	this.locationSelect = null;
	this.selCity = null;
	this.selCityText = null;
	this.isCountryClicked=false;
	
	this.show = function (theForm, country,city,isCountryClicked,location) {
		this.theForm = theForm;
		this.countrySelect = Util.findFormElement(theForm, country);
		this.citySelect = Util.findFormElement(theForm, city);
		this.isCountryClicked=isCountryClicked;
		this.locationSelect = Util.findFormElement(theForm, location);
		this.showWnd();
	}
	
	this.showChange = function (theForm, country,city,isCountryClicked,location) {
		this.theForm = theForm;
		this.countrySelect = Util.findFormElement(theForm, country);
		this.citySelect = Util.findFormElement(theForm, city);
		this.isCountryClicked=isCountryClicked;
		this.locationSelect = Util.findFormElement(theForm, location);
		this.showWndChange();
	}
		
	this.setPoint = function (country, city) {
		this.selCity=city.options[city.selectedIndex].value;
		this.selCityText=city.options[city.selectedIndex].text;
		this.updateCityList(country.options[country.selectedIndex].value);
		this.updateLocationList(city.options[city.selectedIndex].value);
		var i=0;
		var contains=false;
		for(i=0;i<this.countrySelect.options.length;i++) {
			if (this.countrySelect.options[i].value==country.options[country.selectedIndex].value) {
				contains=true;
				break;
			}	
		}	
		if (!contains) {
			this.countrySelect.options[this.countrySelect.options.length] = new Option(country.options[country.selectedIndex].text, country.options[country.selectedIndex].value, false, false);
		}	
		this.countrySelect.value=country.options[country.selectedIndex].value;
		this.citySelect.value=city.options[city.selectedIndex].value;
	}
	
	/*this.setPointChange = function (country, city) {
		this.selCity=city.options[city.selectedIndex].value;
		this.selCityText=city.options[city.selectedIndex].text;
		this.updateCityList(country.options[country.selectedIndex].value);
		this.updateLocationList(city.options[city.selectedIndex].value);
		var i=0;
		var contains=false;
		for(i=0;i<this.countrySelect.options.length;i++) {
			if (this.countrySelect.options[i].value==country.options[country.selectedIndex].value) {
				contains=true;
				break;
			}	
		}	
		if (!contains) {
			this.countrySelect.options[this.countrySelect.options.length] = new Option(country.options[country.selectedIndex].text, country.options[country.selectedIndex].value, false, false);
		}	
		this.countrySelect.value=country.options[country.selectedIndex].value;
		this.citySelect.value=city.options[city.selectedIndex].value;
		
	}*/
	
	this.showWnd = function () {
		var geoNav = document.getElementById("geoNavDiv");
//		geoNav.style.left = event.pageX - 100 + "px";
//		geoNav.style.top = event.pageY + "px";
		/*if (event.pageX != null) {
			geoNav.style.left = event.pageX - 100 + "px";
			geoNav.style.top = event.pageY + "px";
		} else {
			geoNav.style.left = event.x - 100 + document.body.scrollLeft + "px";
			geoNav.style.top = event.y + document.body.scrollTop + "px";
		}*/
	    var l = 0;
	    var t = 0;
	    var elm=null;
	    if (this.isCountryClicked)
	    	elm=this.countrySelect;
	    else elm=this.citySelect;
	    while (elm)
	    {
	        l += elm.offsetLeft;
	        t += elm.offsetTop;
	        elm = elm.offsetParent;
	    }

	    geoNav.style.left = l + "px";
		geoNav.style.top = t + "px";

		geoNav.style.display = "block";
		document.getElementById("geoNavFrame").src = "hotelGeoNavigator.do?mappingName=showForm";
	}
	
	this.showWndChange = function () {
		var geoNav = document.getElementById("geoNavDiv");
		
		var l = 0;
	    var t = 0;
	    var elm=null;
	    if (this.isCountryClicked)
	    	elm=this.countrySelect;
	    else elm=this.citySelect;
	    while (elm)
	    {
	        l += elm.offsetLeft;
	        t += elm.offsetTop;
	        elm = elm.offsetParent;
	    }

	    geoNav.style.left = l + "px";
		geoNav.style.top = t + "px";

		geoNav.style.display = "block";
		document.getElementById("geoNavFrame").src = "hotelGeoNavigator.do?mappingName=showFormChange";
	}
	
	this.closeWindow = function (windowRef) {
		if ((windowRef.opener != null) && (windowRef.opener != self)) {
			windowRef.opener.HotelGeoNavigator.hideWnd(windowRef);
		} else {
			parent.HotelGeoNavigator.hideWnd();
		}
	}
	
	this.hideWnd = function (windowRef) {
		if (windowRef != null) {
			windowRef.close();
		} else  {
			document.getElementById("geoNavDiv").style.display = "none";
			document.getElementById("geoNavFrame").src = "about:blank";
		}
	}
	
	this.updateCityList = function updateCityList(countryId) {
		
		var citySelect1=this.citySelect;
		var city1=this.selCity;
		var city1Text=this.selCityText;

		if (countryId == null || countryId=='-1') {
			this.citySelect.options.length = 0;
			alert('countryId=null');
			return;
	    }
		this.citySelect.options.length = 0;
		this.citySelect.options[this.citySelect.options.length] = new Option("เศเฤเลแ? เวเภเรแ?แ?เวเสเภ", "", false, true);
		try {
	    /*var theForm = document.forms[0];
	    for (var i = 0; i < theForm.elements.length; i++) {
	        var elm = theForm.elements[i];
	        if (elm.name.indexOf("hotelStaying") != -1) {
	            if (elm.name.indexOf("location") != -1) {
	                elm.disabled = false;
	            }
	        }
	    }    */

	    dojo.xhrPost({
	        content : {countryId : countryId},
	        handleAs : 'json',
	        sync : false,
	        'url' : './hotelStayingCity.jsp',
	        load : function(result) {
	        	citySelect1.options.length = 0;
	        	citySelect1.options[0]=new Option('เ?แ?เมเลแ?เศแ?เล เรเฮแ?เฮเฤ', '-1', false, true); 
	            if (result.status == 'success') {
	                var data = result.data;
	                var contains=false;
	                for (var i = 0; i < data.length; i++) {
	                    var pair = data[i];
	                    citySelect1.options[citySelect1.options.length] = new Option(pair.name, pair.code, false, false);
	                    if (city1==pair.code) {
	        				contains=true;
	        			}
	                }
	        		if (!contains) {
	        			citySelect1.options[citySelect1.options.length] = new Option(city1Text, city1, false, false);
	        		}	
	        		citySelect1.options[citySelect1.options.length] = new Option('เ?เฮเหเอแ?เษ แ?เฯเศแ?เฮเส', '-2', false, false);
	                citySelect1.value=city1;
	            } else if (result.status == 'error') {
	                for (var l = 0; l < result.errors.length; l++) {
	                    var e = result.errors[l];
	                    alert('ERROR: ' + e.name + '\n\n' + e.stacktrace);
	                }
	            } else {
	                alert('Undefined status: ' + result.status);
	            }
	        }
	    });
		} finally {
			citySelect1.value=city1;
			//summaSelect.disabled=false;
		}
		citySelect1.value=city1;
	}
	this.updateLocationList = function updateLocationList(cityId) {
		var locationSelect1=this.locationSelect;
		if (cityId == null || cityId=='-1') {
			locationSelect.options.length = 0;
			return;
	    }
		this.locationSelect.options.length = 0;
		this.locationSelect.options[this.locationSelect.options.length] = new Option("เศเฤเลแ? เวเภเรแ?แ?เวเสเภ", "", false, true);
		try {
	    /*var theForm = document.forms[0];
	    for (var i = 0; i < theForm.elements.length; i++) {
	        var elm = theForm.elements[i];
	        if (elm.name.indexOf("hotelStaying") != -1) {
	            if (elm.name.indexOf("location") != -1) {
	                elm.disabled = false;
	            }
	        }
	    }    */

	    dojo.xhrPost({
	        content : {cityId : cityId},
	        handleAs : 'json',
	        sync : false,
	        'url' : './hotelStayingLocation.jsp',
	        load : function(result) {
	        	locationSelect1.options.length = 0;
	            if (result.status == 'success') {
	                var data = result.data;
	                locationSelect1.options[0]=new Option('เ? เหแ?เมเฮเฬ แ?เภเษเฮเอเล', '-1', false, true); 
	                for (var i = 0; i < data.length; i++) {
	                    var pair = data[i];
	                    locationSelect1.options[locationSelect1.options.length] = new Option(pair.name, pair.code, false, pair.selected==true);
	                }
	            } else if (result.status == 'error') {
	                for (var l = 0; l < result.errors.length; l++) {
	                    var e = result.errors[l];
	                    alert('ERROR: ' + e.name + '\n\n' + e.stacktrace);
	                }
	            } else {
	                alert('Undefined status: ' + result.status);
	            }
	        }
	    });
		} finally {
			//summaSelect.disabled=false;
		}
	}
}



Splash = new function () {
	this.playCount = 0;
	
	this.play = function () {
		var search_splash = document.getElementById('searchSplash');
		search_splash.style.top = document.body.scrollTop
			+ document.body.clientHeight / 2 - 150 / 2
			+ (Math.random() - 0.5) * 5;
		search_splash.style.left = document.body.scrollLeft
			+ document.body.clientWidth / 2 - 250 / 2
			+ (Math.random() - 0.5) * 5;
		if (this.playCount < 30) {
			this.playCount++;
			setTimeout("Splash.play()", 40);
		} else {
			this.playCount = 0;
			setTimeout("Splash.play()", 6000);
		}
	}
	
	this.show = function () {
		var search_splash = document.getElementById('searchSplash');
		search_splash.style.display = 'block';
		search_splash.style.top = document.body.scrollTop
			+ document.body.clientHeight / 2 - 150 / 2;
		search_splash.style.left = document.body.scrollLeft
			+ document.body.clientWidth / 2 - 250 / 2;
		setTimeout("Splash.play()",3000);
		return;
	}
	
	this.hide = function () {
		var search_splash = document.getElementById('searchSplash');
		if (search_splash != null) {
			search_splash.style.display = 'none';
		}
	}
}


DomUtil = new function () {
	this.findParent = function (node, name, id) {
		if (node == null) {
			return null;
		}
		if (node.nodeName == name) {
			if (id == null) {
				return node;
			} else if (node.getAttribute("id") == id) {
				return node;
			}
		}
		return this.findParent(node.parentNode, name, id);
	}
	
	this.findChild = function (node, name, id) {
		if (node == null) {
			return null;
		}
		var children = node.childNodes;
		for (var i = 0; i < children.length; i++) {
			var result = children.item(i);
			if (result.nodeName == name) {
				//alert("node=" + result.nodeName + ", id=" + result.getAttribute("id"));
				if (id == null) {
					return result;
				} else if (result.getAttribute("id") == id) {
					return result;
				}
			}
			result = this.findChild(result, name, id);
			if (result != null) {
				return result;
			}
		}
		return null;
	}
	
	this.visitNodes = function (parent, nodeName, callback) {
		if (parent == null) {
			return;
		}
		var children = parent.childNodes;
		var idx = -1;
		for (var i = 0; i < children.length; i++) {
			var child = children.item(i);
			if (child.nodeName == nodeName) {
				idx++;
				callback(child, idx);
			}
			this.visitNodes(child, nodeName, callback);
		}
	}
}

SearchUtil = new function () {
	this.validateRouteSegment = function (theForm, idx) {
		var startPoint = Util.findFormElement(theForm, "routeSegment[" + idx + "].startPoint");
		var endPoint = Util.findFormElement(theForm, "routeSegment[" + idx + "].endPoint");
		var dateStr = Util.findFormElement(theForm, "routeSegment[" + idx + "].dateStr");
		if ((startPoint == null) || (endPoint == null) || (dateStr == null)) {
			return null;
		}
		if (Util.isBlank(startPoint.value)) {
			alert(Resources.ERR_INVALID_START_POINT);
			startPoint.focus();
			return false;
		}
		if (Util.isBlank(endPoint.value)) {
			alert(Resources.ERR_INVALID_END_POINT);
			endPoint.focus();
			return false;
		}
		if (startPoint.value == endPoint.value) {
			alert(Resources.ERR_INVALID_START_END_POINTS);
			endPoint.focus();
			return false;
		}
		if (!DateUtil.isValidDateString(dateStr.value, Resources.DATE_FORMAT)) {
			alert(Resources.ERR_INVALID_OUT_DATE);
			dateStr.focus();
			return false;
		}
		return true;
	}
	
	this.doSearch = function (theForm) {
		var idx = 0;
		while (true) {
			var validationResult = this.validateRouteSegment(theForm, idx);
			if (validationResult == null) {
				break;
			}
			if (validationResult == false) {
				return false;
			}
			idx++;
		}
		if ((theForm.routeType != null) && ((theForm.routeType.value == "1")
				|| ((theForm.routeType[0] != null)
				&& theForm.routeType[0].checked))) {
			if (!DateUtil.isValidDateString(theForm.returnDateStr.value,
					Resources.DATE_FORMAT)) {
				alert(Resources.ERR_INVALID_IN_DATE);
				theForm.returnDateStr.focus();
				return false;
			}
		}
		if ((theForm.searchMode != null) && ((theForm.searchMode.value == "2")
				|| ((theForm.searchMode[1] != null)
				&& theForm.searchMode[1].checked))
				&& (theForm.returnDateStr != null)) {
			var datesCheckResult = DateUtil.checkInOutDates(
				theForm["routeSegment[0].dateStr"].value,
				theForm.returnDateStr.value, Resources.DATE_FORMAT,
				!isRoundTrip(theForm));
			if (datesCheckResult != null) {
				alert(datesCheckResult);
				return false;
			}
		}
//hide search button
		var searchbutton = 'search-button';
		var sbutton = document.getElementById(searchbutton);
		sbutton.style.display = 'none';
//end hide search button
//		Splash.show();
		return true;
		function isRoundTrip(theForm) {
			return (theForm.routeType != null) && ((theForm.routeType.value == 1)
				|| ((theForm.routeType[0] != null)
				&& theForm.routeType[0].checked));
		}
	}
	
	this.airVendorsChanged = function (theForm, forceSelection) {
		theForm.anyAirVendor[0].checked = !forceSelection;
		theForm.anyAirVendor[1].checked = forceSelection;
		if (forceSelection) {
			var selectedCount = 0;
			var opts = theForm.airVendors.options;
			var optLen = opts.length;
			for (var i = 0; i < optLen; i++) {
				if (opts[i].selected) {
					selectedCount++;
				}
				if (selectedCount > 3) {
					break;
				}
			}
			if (selectedCount == 0) {
				opts[0].selected = true;
			}
		}
	}
	
	this.routeSegmentDateChanged = function (field) {
		var theForm = field.form;
		if (!DateUtil.isValidDateString(field.value, Resources.DATE_FORMAT)) {
			return;
		}
		if (!theForm.returnDateStr) {
			return;
		}
		var outDate = Date.parseDate(field.value, Resources.DATE_FORMAT);
		if (!DateUtil.isValidDateString(theForm.returnDateStr.value,
				Resources.DATE_FORMAT)) {
			outDate.setDate(outDate.getDate() + 7);
			theForm.returnDateStr.value = outDate.print(Resources.DATE_FORMAT);
			return;
		}
		var inDate = Date.parseDate(theForm.returnDateStr.value,
				Resources.DATE_FORMAT);
		if (inDate.getTime() <= outDate.getTime()) {
			outDate.setDate(outDate.getDate() + 7);
			theForm.returnDateStr.value = outDate.print(Resources.DATE_FORMAT);
		}
	}
	
	this.policyStartDateChanged = function (index,field) {
		var theForm = field.form;
		if (!DateUtil.isValidDateString(field.value, Resources.DATE_FORMAT)) {
			return;
		}
		if (!theForm['policy['+index+'].endDate']) {
			return;
		}
		var outDate = Date.parseDate(field.value, Resources.DATE_FORMAT);
		if (!DateUtil.isValidDateString(theForm['policy['+index+'].endDate'].value,
				Resources.DATE_FORMAT)) {
			outDate.setDate(outDate.getDate() + 7);
			theForm['policy['+index+'].endDate'].value = outDate.print(Resources.DATE_FORMAT);
			return;
		}
		var inDate = Date.parseDate(theForm['policy['+index+'].endDate'].value,
			Resources.DATE_FORMAT);
		if (inDate.getTime() <= outDate.getTime()) {
			outDate.setDate(outDate.getDate() + 7);
			theForm['policy['+index+'].endDate'].value = outDate.print(Resources.DATE_FORMAT);
		}
	}
	
	this.hotelStayingDateChanged = function (field) {
		var theForm = field.form;
		if (!DateUtil.isValidDateString(field.value, Resources.DATE_FORMAT)) {
			return;
		}
		var inDate = Date.parseDate(field.value, Resources.DATE_FORMAT);
		if (!DateUtil.isValidDateString(theForm.checkOutDateStr_0.value,
				Resources.DATE_FORMAT)) {
			inDate.setDate(inDate.getDate() + 1);
			theForm.checkOutDateStr_0.value = inDate.print(Resources.DATE_FORMAT);
			theForm.nightsCount_0.value=1;
			return;
		}
		var outDate = Date.parseDate(theForm.checkOutDateStr_0.value,
			Resources.DATE_FORMAT);
		if (outDate.getTime() <= inDate.getTime()) {
			inDate.setDate(inDate.getDate() + 1);
			theForm.checkOutDateStr_0.value = inDate.print(Resources.DATE_FORMAT);
			theForm.nightsCount_0.value=1;
		}
		else {
			theForm.nightsCount_0.value=(outDate.getTime()-inDate.getTime())/(1000*60*60*24);
		}	
	}
	
	this.updateSegmentBoxes = function () {
		var children =
			Util.getElementInAllB("routeSegment_0").parentNode.childNodes;
		var idx = -1;
		for (var i = 0; i < children.length; i++) {
			var child = children.item(i);
			var id =
				(child.getAttribute != null) ? child.getAttribute("id") : null;
			if (("DIV" == child.nodeName) && (id != null)
					&& (id.indexOf("routeSegment_") == 0)) {
				idx++;
				if (idx > 0) {
					this.updateSegmentBox(child, idx);
				}
			}
		}
	}

	this.updateSegmentBox = function (node, idx) {
		node.setAttribute("id", "routeSegment_" + idx);
		var removeRouteSegmentBoxNode =
			DomUtil.findChild(node, "SPAN", "removeRouteSegmentBox");
		DomUtil.findChild(removeRouteSegmentBoxNode, "A").setAttribute("href",
				"javascript:SearchUtil.deleteRouteSegment('routeSegment_"
				+ idx + "')");
		removeRouteSegmentBoxNode.style.display =
			document.all ? "block" : "block";
		var replaceIdxFunc = function(nd) {
			if (nd.name != null) {
				nd.name = nd.name.replace(
					/routeSegment\[\d+\]/g, "routeSegment[" + idx + "]");
			}
			if (nd.id != null) {
				nd.id = nd.id.replace(/\[\d+\]/g, "[" + idx + "]");
			}
		};
		DomUtil.visitNodes(node, "INPUT", replaceIdxFunc);
		DomUtil.visitNodes(node, "SELECT", replaceIdxFunc);
		DomUtil.visitNodes(node, "A", replaceIdxFunc);
		DomUtil.visitNodes(node, "A", function(nd) {
			if (nd.id == "geoNav[" + idx + "].startPoint") {
				nd.onclick = function(event) {
					GeoNavigator.show(DomUtil.findParent(nd, "FORM"),
						"routeSegment[" + idx + "].startPoint",
						document.all ? window.event : event);
				}
			} else if (nd.id == "geoNav[" + idx + "].endPoint") {
				nd.onclick = function(event) {
					GeoNavigator.show(DomUtil.findParent(nd, "FORM"),
						"routeSegment[" + idx + "].endPoint",
						document.all ? window.event : event);
				}
			}
		});
		DomUtil.visitNodes(node, "INPUT", function(nd) {
			if (nd.id != null) {
				nd.id = nd.id.replace(/dateStr_\d+/g, "dateStr_" + idx);
			}
		});
		DomUtil.visitNodes(node, "IMG", function(nd) {
			if (nd.id != null) {
				nd.id = nd.id.replace(/dateTrigger_\d+/g, "dateTrigger_" + idx);
			}
		});
		Calendar.setup({
			inputField  : "dateStr_" + idx,
			ifFormat    : Resources.DATE_FORMAT,
			button      : "dateTrigger_" + idx,
			firstDay    : 1,
			electric    : false,
			cache       : true,
			disableFunc : isRouteSegmentDateDisabled
		});
	}
	
	this.addRouteSegment = function () {
		var src = Util.getElementInAllB("routeSegment_0");
		var dest = src.cloneNode(true);
		DomUtil.visitNodes(dest, "INPUT", function(nd) {
			nd.value = "";
		});
		src.parentNode.insertBefore(dest,
			Util.getElementInAllB("returnDateBox"));
		this.updateSegmentBoxes();
	}
	
	this.deleteRouteSegment = function (segmentId) {
		var routeSegmentBoxNode = Util.getElementInAllB(segmentId);
		if (routeSegmentBoxNode == null) {
			return;
		}
		routeSegmentBoxNode.parentNode.removeChild(routeSegmentBoxNode);
		this.updateSegmentBoxes();
	}
	
	this.deleteAllRouteSegments = function () {
		var idx = 1;
		var doUpdate = false;
		while (true) {
			var routeSegmentBoxNode =
				Util.getElementInAllB("routeSegment_" + idx);
			if (routeSegmentBoxNode == null) {
				break;
			}
			routeSegmentBoxNode.parentNode.removeChild(routeSegmentBoxNode);
			doUpdate = true;
			idx++;
		};
		if (doUpdate) {
			this.updateSegmentBoxes();
		}
	}
	
	this.routeTypeChanged = function (theForm) {
		if (theForm.routeType[0].checked) {
			// RT
			theForm.searchMode[0].disabled = false;
			Util.getElementInAllB("tariffModeBox").style.display =
				document.all ? "block" : "table-row";
			theForm.returnDateStr.disabled = false;
			if (theForm.returnTimeInterval != null) {
				theForm.returnTimeInterval.disabled = false;
			}
			{
				var elm = Util.getElementInAllB("returnDateBox");
				if (elm != null) {
					elm.style.display = "block";
				}
			}
			{
				var elm = Util.getElementInAllB("newRouteSegmentBox");
				if (elm != null) {
					elm.style.display = "none";
				}
			}
			this.deleteAllRouteSegments();
//change style class
		var passengersbox = 'passengers-box';
		var chpassclass = document.getElementById(passengersbox);
		chpassclass.className = 'form-col1';
//end change style class
		} else if (theForm.routeType[1].checked) {
			// OW simple
			theForm.searchMode[0].disabled = false;
			Util.getElementInAllB("tariffModeBox").style.display =
				document.all ? "block" : "table-row";
			theForm.returnDateStr.disabled = true;
			if (theForm.returnTimeInterval != null) {
				theForm.returnTimeInterval.disabled = true;
			}
			{
				var elm = Util.getElementInAllB("returnDateBox");
				if (elm != null) {
					elm.style.display = "none";
				}
			}
			{
				var elm = Util.getElementInAllB("newRouteSegmentBox");
				if (elm != null) {
					elm.style.display = "none";
				}
			}
			this.deleteAllRouteSegments();
//change style class
		var passengersbox = 'passengers-box';
		var chpassclass = document.getElementById(passengersbox);
		chpassclass.className = 'form-col2';
//end change style class
		} else {
			// OW complex
			if (theForm.searchMode[0].checked) {
				theForm.searchMode[1].checked = true;
			}
			theForm.searchMode[0].disabled = true;
			Util.getElementInAllB("tariffModeBox").style.display = "none";
			theForm.returnDateStr.disabled = true;
			if (theForm.returnTimeInterval != null) {
				theForm.returnTimeInterval.disabled = true;
			}
			{
				var elm = Util.getElementInAllB("returnDateBox");
				if (elm != null) {
					elm.style.display = "none";
				}
			}
			{
				var elm = Util.getElementInAllB("newRouteSegmentBox");
				if (elm != null) {
					elm.style.display = "block";
				}
			}
//change style class
		var passengersbox = 'passengers-box';
		var chpassclass = document.getElementById(passengersbox);
		chpassclass.className = 'form-col1';
//end change style class
		}
	}
}
//Hide submit button after once pressed
function hidesubmitbutton(hideClass,item) {
	item.className = hideClass;
}