	var fixedX = -1
	var fixedY = -1//y position (-1 if to appear below control)

	var startAt = 0 // 0 - sunday ; 1 - monday
	var showWeekNumber = 0	// 0 - don't show; 1 - show
	var showToday = 0		// 0 - don't show; 1 - show
	var imgDir = "/images/"	// directory for images ... e.g. var imgDir="/img/"

	var gotoString = "Go To Current Month"
	var todayString = "Today is"
	var weekString = "Wk"
	var scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically."
	var scrollRightMessage = "Click to scroll to next month. Hold mouse button to scroll automatically."
	var selectMonthMessage = "Click to select a month."
	var selectYearMessage = "Click to select a year."
	var selectDateMessage = "Select [date] as date." // do not replace [date], it will be replaced by date.

	var	crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue, ctlNow, dateFormat, nStartingYear

	var	bPageLoaded=false
	//var	ie=document.all
	//var	dom=document.getElementById

	//var	ns4=document.layers
	var	today =	new	Date()
	var	dateNow	 = today.getDate()
	var	monthNow = today.getMonth()
	var	yearNow	 = today.getFullYear()
	var	imgsrc = new Array("drop1.jpg","drop2.jpg","left1.gif","left2.gif","right1.gif","right2.gif")
	var	img	= new Array()
	var	monthName =	new	Array()
	var dayName = new Array()
	//to get the position of the year month and date base on the locale
	var dayIndex=1
	var monthIndex=0
	var yearIndex=2
	var yearDigit=4
	var endMonthSelected, endYearSelected, endDaySelected

	var mEnd = new Array (31,0,31,30,31,30,31,31,30,31,30,31)

	function constructMonthDayStyle()
	{
		monthName[0] = "янв";
		monthName[1] = "фев";
		monthName[2] = "мар";
		monthName[3] = "апр";
		monthName[4] = "май";
		monthName[5] = "июн";
		monthName[6] = "июл";
		monthName[7] = "авг";
		monthName[8] = "сен";
		monthName[9] = "окт";
		monthName[10] = "ноя";
		monthName[11] = "дек";
		
		dayName[0] = "Пн";
		dayName[1] = "Вт";
		dayName[2] = "Ср";
		dayName[3] = "Чт";
		dayName[4] = "Пт";
		dayName[5] = "Сб";
		dayName[6] = "Вс";
		
			startAt = "1"
	}

	function HolidayRec (d, m, y, desc)
	{
		this.d = d
		this.m = m
		this.y = y
		this.desc = desc
	}

	var HolidaysCounter = 0
	var Holidays = new Array()

	function fire()
	{
		if(!document.getElementById("calendar").contains(document.activeElement) && !document.getElementById("selectMonth").contains(document.activeElement) && !document.getElementById("selectYear").contains(document.activeElement))
			hideCalendar();
	}
	function addHoliday (d, m, y, desc)
	{
		Holidays[HolidaysCounter++] = new HolidayRec ( d, m, y, desc )
	}

	//if (dom)
	//{
		for	(i=0;i<imgsrc.length;i++)
		{
			img[i] = new Image
			img[i].src=imgDir+imgsrc[i]
		}
		document.write ("<div id='calendar' ondeactivate='fire()' style='position:absolute;visibility:hidden;'><table width="+((showWeekNumber==1)?250:220)+" style='color:back;font-family:arial;font-size:11px;border: 1px solid #f0bd00;font-family:Arial; font-size:11px; background-color: #623d00'><tr><td id='calendarHeader'><table width='"+((showWeekNumber==1)?248:218)+"'><tr><td style='padding:2px;font-family:arial; font-size:11px;'><font color='#ffffff'><B><span id='caption'></span></B></font></td><td align=right><a href='javascript:hideCalendar()'><IMG SRC='"+imgDir+"close.gif' BORDER='0' ALT='Close the Calendar'></a></td></tr></table></td></tr><tr><td style='padding:5px' bgcolor=#9f6900><span id='content'></span></td></tr>")

		if (showToday==1)
		{
			document.write ("<tr bgcolor=#f0f0f0><td style='padding:5px' align=center><span id='lblToday'></span></td></tr>")
		}

		document.write ("</table></div><div id='selectMonth' style='position:absolute;visibility:hidden;'></div><div id='selectYear'	style='position:absolute;visibility:hidden;'></div>");
	//}

	var	styleAnchor="text-decoration:none;color:black;"
	var	styleLightBorder="border: solid 1px #ffffff;"

	function swapImage(srcImg, destImg){
		//if (ie)	{ document.getElementById(srcImg).setAttribute("src",imgDir + destImg) }
		document.getElementById(srcImg).setAttribute("src",imgDir + destImg)
	}

	function init()
	{
			crossobj = document.getElementById("calendar").style;
			hideCalendar()
			crossMonthObj=document.getElementById("selectMonth").style
			crossYearObj=document.getElementById("selectYear").style
			monthConstructed=false;
			yearConstructed=false;

			if (showToday==1)
			{
				document.getElementById("lblToday").innerHTML =	todayString + " <a  onmousemove='window.status=\""+gotoString+"\"' onmouseout='window.status=\"\"' title='"+gotoString+"' style='"+styleAnchor+"' href='javascript:monthSelected=monthNow;yearSelected=yearNow;constructCalendar();'>"+dayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)]+", " + dateNow + " " + monthName[monthNow].substring(0,3)	+ "	" +	yearNow	+ "</a>"
			}

			sHTML1="<span id='spanLeft'	style='border: solid 1px #FFFFFF;cursor:pointer' onmouseover='swapImage(\"changeLeft\",\"left2.gif\");this.style.borderColor=\"white\";window.status=\""+scrollLeftMessage+"\"'  onclick='javascript:decMonth()' onmouseout='clearInterval(intervalID1);swapImage(\"changeLeft\",\"left1.gif\");this.style.borderColor=\"white\";window.status=\"\"' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<IMG id='changeLeft' SRC='"+imgDir+"left1.gif' BORDER=0>&nbsp</span>&nbsp;"
			sHTML1+="<span id='spanRight' style='border: solid 1px#FFFFFF;cursor:pointer'	onmouseover='swapImage(\"changeRight\",\"right2.gif\");this.style.borderColor=\"white\";window.status=\""+scrollRightMessage+"\"'  onmouseout='clearInterval(intervalID1);swapImage(\"changeRight\",\"right1.gif\");this.style.borderColor=\"white\";window.status=\"\"' onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<IMG id='changeRight' SRC='"+imgDir+"right1.gif' BORDER=0>&nbsp</span>&nbsp"
			sHTML1+="<span id='spanMonth' style='border: solid 1px #FFFFFF;cursor:pointer'	onmouseover='swapImage(\"changeMonth\",\"drop2.jpg\");this.style.borderColor=\"white\";window.status=\""+selectMonthMessage+"\"'  onmouseout='swapImage(\"changeMonth\",\"drop1.jpg\");this.style.borderColor=\"white\";window.status=\"\"' onclick='popUpMonth()'></span>&nbsp;"
			sHTML1+="<span id='spanYear' style='border: solid 1px #FFFFFF;cursor:pointer' onmouseover='swapImage(\"changeYear\",\"drop2.jpg\");this.style.borderColor=\"white\";window.status=\""+selectYearMessage+"\"'	 onmouseout='swapImage(\"changeYear\",\"drop1.jpg\");this.style.borderColor=\"white\";window.status=\"\"'	onclick='popUpYear()'></span>&nbsp;"
			document.getElementById("caption").innerHTML  =	sHTML1

			bPageLoaded=true
			return fixedX;
			return fixedY;
		//}
	}

	function hideCalendar()	{
		crossobj.visibility="hidden"
		if (crossMonthObj != null){crossMonthObj.visibility="hidden"}
		if (crossYearObj !=	null){crossYearObj.visibility="hidden"}
		if(document.getElementById("iframe1") != null)
	     	   document.getElementById("iframe1").style.visibility="hidden";

		enableFields(true);

	}

	function padZero(num) {
		return (num	< 10)? '0' + num : num ;
	}

	function constructDate(d,m,y)
	{
		sTmp = dateFormat
		sTmp = sTmp.replace	("dd","<e>")
		sTmp = sTmp.replace	("d","<d>")
		sTmp = sTmp.replace	("<e>",padZero(d))
		sTmp = sTmp.replace	("<d>",d)
		sTmp = sTmp.replace	("mmm","<o>")
		sTmp = sTmp.replace	("mm","<n>")
		sTmp = sTmp.replace	("m","<m>")
		sTmp = sTmp.replace	("<m>",m+1)
		sTmp = sTmp.replace	("<n>",padZero(m+1))
		sTmp = sTmp.replace	("<o>",monthName[m])
		sTmp = sTmp.replace 	("yyyy",y)
		sTmp = sTmp.replace ("yy",padZero(y % 100))
		return sTmp
	}

	function closeCalendar() {
		var	sTmp
		hideCalendar();
		if (window.clearLinks != null)
			clearLinks();
		/*** Here for merci ***/
		/*** Also add a if..else for checking the start date sleceted ***/
		if ((document.hotelSearchForm.checkInDate.value =="")&&(vperValue == "end"))
		{
			alert('XXX');
		}
		else if (vperValue != "end")
		{
			if (yearSelected/4 == parseInt(yearSelected/4))
			{
				mEnd[1] = 29;
			}
			else
			{
				mEnd[1] = 28;
			}
			if (dateSelected == mEnd[monthSelected])
			{
				sDateSelected = 1
				if(monthSelected == 11)
				{
					sMonthSelected = 0;
					sYearSelected = yearSelected + 1;
				}
				else
				{
					sMonthSelected = monthSelected + 1
					sYearSelected = yearSelected;
				}
				ctlToPlaceValue.value =	constructDate(dateSelected,monthSelected,yearSelected)
			}
			else
			{
				ctlToPlaceValue.value =	constructDate(dateSelected,monthSelected,yearSelected)
			}
			checkingInOutDate();
		}
		else
		{
			ctlToPlaceValue.value =	constructDate(dateSelected,monthSelected,yearSelected)
		}

		enableFields(true);
	}

	/*** Month Pulldown	***/

	function StartDecMonth()
	{
		intervalID1=setInterval("decMonth()",80)
	}

	function StartIncMonth()
	{
		intervalID1=setInterval("incMonth()",80)
	}

	function incMonth () {
		monthSelected++
		if (monthSelected>11) {
			monthSelected=0
			yearSelected++
		}
		constructCalendar()
	}

	function decMonth () {
		monthSelected--
		if (monthSelected<0) {
			monthSelected=11
			yearSelected--
		}
		constructCalendar()
	}

	function minMonth() {
		nStartingMonth = nStartingMonth % 12

		if(Math.abs(nStartingMonth) > 0){
			for	(i=0; i<5; i++){
				newMonth = (i+nStartingMonth)-1
					if (newMonth != Math.abs(newMonth)) {
						var newMonthArray = new Array(11,10,9,8,7,6,5,4,3,2,1,0)
						var newMonth = Math.abs(newMonth) -1 % 12
							txtMonth = "&nbsp;"	+ monthName[newMonthArray[newMonth]] + "&nbsp;"
						} else {
							newMonth = newMonth % 12
							txtMonth = "&nbsp;"	+ monthName[newMonth] + "&nbsp;"

					}
						document.getElementById("m"+i).innerHTML = txtMonth
				}
			} else {
				return false;
		}
			nStartingMonth --;
	}

	function addMonth() {
		if(monthSelected > 11){
			return false;
		} else {
			nStartingMonth = nStartingMonth % 12
				if(nStartingMonth < 7){
					for	(i=0; i<5; i++){
							newMonth = (i+nStartingMonth)+1
								newMonth = newMonth % 12
								txtMonth = "&nbsp;"	+ monthName[newMonth] + "&nbsp;"
								document.getElementById("m"+i).innerHTML = txtMonth
						}
				} else {
					return false;
				}
			}
			nStartingMonth ++;
	}

	function selectMonth(nMonth) {
			monthSelected=parseInt(nMonth+nStartingMonth);
			if(monthSelected == 12){
			   monthSelected=parseInt(nMonth+nStartingMonth);
			}
		monthConstructed=false;
		constructCalendar();
		popDownMonth();
	}

	function constructMonth() {
		popDownYear()
		sHTML =	""
		if (!monthConstructed) {
			sHTML =	"<tr><td align='center'	onmouseover='this.style.backgroundColor=\"#1E8AD2\"'  onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer'	onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"minMonth()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"

			j =	0

			nStartingMonth = monthSelected-2; //monthSelected-2
			if (nStartingMonth == -2) {
				nStartingMonth = 0;
			} else if (nStartingMonth == -1) {
				nStartingMonth = 1;
			} else {
				nStartingMonth = monthSelected-2;
			}
			if ((monthSelected == 0)||(monthSelected == 1)) {

				for	(i=monthSelected; i<=(monthSelected+4); i++) {
								sName =monthName[i];

								if (i==monthSelected){
									sName =	"<B>" + sName +	"</B>"
								}

								sHTML += "<tr><td id='m" + j + "' onmouseover='this.style.backgroundColor=\"#1E8AD2\"'  onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='monthConstructed=false;selectMonth("+j+");constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
								j ++;

					}
		} else if (monthSelected == 11){
				for	(i=(monthSelected-4); i<=(monthSelected); i++) {
								sName =monthName[i];
								nStartingMonth = monthSelected - 4;
								if (i==monthSelected){
									sName =	"<B>" + sName +	"</B>"
								}
								sHTML += "<tr><td id='m" + j + "' onmouseover='this.style.backgroundColor=\"#1E8AD2\"'  onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer;' onclick='monthConstructed=false;selectMonth("+j+");constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
								j ++;

					}
		} else if (monthSelected == 10){
				for	(i=(monthSelected-3); i<=(monthSelected+1); i++) {
								sName =monthName[i];
								nStartingMonth = monthSelected - 3;
								if (i==monthSelected){
									sName =	"<B>" + sName +	"</B>"
								}
								sHTML += "<tr><td id='m" + j + "' onmouseover='this.style.backgroundColor=\"#1E8AD2\"'  onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer;' onclick='monthConstructed=false;selectMonth("+j+");constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
								j ++;

					}
		} else {

				for	(i=(monthSelected-2); i<=(monthSelected+2); i++) {
								sName =monthName[i];

								if (i==monthSelected){
									sName =	"<B>" + sName +	"</B>"
								}
								sHTML += "<tr><td id='m" + j + "' onmouseover='this.style.backgroundColor=\"#1E8AD2\"'  onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer;' onclick='monthConstructed=false;selectMonth("+j+");constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
								j ++;

					}
				}

				sHTML += "<tr><td align='center' onmouseover='this.style.backgroundColor=\"#1E8AD2\"'  onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"addMonth()\",30)'	onmouseup='clearInterval(intervalID2)'>+</td></tr>"

				document.getElementById("selectMonth").innerHTML	= "<table width=44 style='font-family:arial; font-size:11px; border: solid 1px #ffffff;'	bgcolor='#62AEE0' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear()\",100)' cellspacing=0>"	+ sHTML	+ "</table>"
				monthConstructed = true
			}
	}


	function popUpMonth() {
		constructMonth()
		crossMonthObj.zIndex=20 
		//crossMonthObj.visibility = (dom||ie)? "visible"	: "show"
		crossMonthObj.visibility = "visible"
		crossMonthObj.left = (parseInt(crossobj.left) + 50)+"px"
		crossMonthObj.top = (parseInt(crossobj.top) + 26)+"px"
	}

	function popDownMonth()	{
		crossMonthObj.visibility= "hidden"
		setIFrameSize();
	}

	/*** Year Pulldown ***/

	function incYear() {
		for	(i=0; i<5; i++){
			newYear	= (i+nStartingYear)+1
			if (newYear==yearSelected)
			{ txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;" }
			else
			{ txtYear =	"&nbsp;" + newYear + "&nbsp;" }
			document.getElementById("y"+i).innerHTML = txtYear
		}
		nStartingYear ++;
	}

	function decYear() {
		for	(i=0; i<5; i++){
			newYear	= (i+nStartingYear)-1
			if (newYear==yearSelected)
			{ txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;" }
			else
			{ txtYear =	"&nbsp;" + newYear + "&nbsp;" }
			document.getElementById("y"+i).innerHTML = txtYear
		}
		nStartingYear --;
	}

	function selectYear(nYear) {
		yearSelected=parseInt(nYear+nStartingYear);
		yearConstructed=false;
		constructCalendar();
		popDownYear();
	}


	function constructYear() {
		popDownMonth()
		sHTML =	""
		if (!yearConstructed) {

			sHTML =	"<tr><td align='center'	onmouseover='this.style.backgroundColor=\"#1E8AD2\"'   onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer'	onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"

			j =	0
			nStartingYear =	yearSelected-2
			for	(i=(yearSelected-2); i<=(yearSelected+2); i++) {
				sName =	i;
				if (i==yearSelected){
					sName =	"<B>" +	sName +	"</B>"
				}

				sHTML += "<tr><td id='y" + j + "' onmouseover='this.style.backgroundColor=\"#1E8AD2\"'  onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
				j ++;
			}

			sHTML += "<tr><td align='center' onmouseover='this.style.backgroundColor=\"#1E8AD2\"'  onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)'	onmouseup='clearInterval(intervalID2)'>+</td></tr>"

			document.getElementById("selectYear").innerHTML	= "<table width=44 style='font-family:arial; font-size:11px; border: solid 1px #ffffff;'	bgcolor='#62AEE0' onmouseover='clearTimeout(timeoutID2)'  onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear()\",100)' cellspacing=0>"	+ sHTML	+ "</table>"

			yearConstructed	= true
		}
	}

	function popDownYear() {
		clearInterval(intervalID1)
		clearTimeout(timeoutID1)
		clearInterval(intervalID2)
		clearTimeout(timeoutID2)
		crossYearObj.visibility= "hidden"
		setIFrameSize();
	}

	function popUpYear() {
		var	leftOffset

		constructYear()
		crossYearObj.zIndex=20;
		//crossYearObj.visibility	= (dom||ie)? "visible" : "show"
		crossYearObj.visibility	= "visible";
		leftOffset = parseInt(crossobj.left) + document.getElementById("spanYear").offsetLeft
		//if (ie)
		//{
			leftOffset += 6
		//}

		crossYearObj.left = leftOffset+"px"
		crossYearObj.top = (parseInt(crossobj.top) + 26)+"px"
	}

	/*** calendar ***/

	function WeekNbr(n) {
		var P3D=259200000, P7D=604800000, y=n.getFullYear(), y=(y<1000?1900+y:y);
		var s=Math.floor((Date.UTC(y,n.getMonth(),n.getDate())+P3D)/P7D);
		tmp=new Date(s*P7D); j=tmp.getFullYear(); j=(j<1000?1900+j:j);
		return 1+s-Math.floor((Date.UTC(j,0,4)+P3D)/P7D)
	}

	//this is the function to extra the short of portion of year base on the date format pass in
	//example date format is dd-mm-yy, this function will return the year in yyyy
	function getYearPrefix()
	{
		if(yearDigit==2)
		{
			strYear = yearNow.toString()
			len = strYear.length-2
			return strYear.substr(0,len)
		}
		else
			return ""
	}

	function constructCalendar ()
	{
		var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31)
		var dateMessage
		var	startDate =	new	Date (yearSelected,monthSelected,1)
		var endDate

		if (monthSelected==1)
		{
			endDate	= new Date (yearSelected,monthSelected+1,1);
			endDate	= new Date (endDate	- (24*60*60*1000));
			numDaysInMonth = endDate.getDate()
		}
		else
		{
			numDaysInMonth = aNumDays[monthSelected];
		}

		datePointer	= 0
		dayPointer = startDate.getDay() - startAt

		if (dayPointer<0)
		{
			dayPointer = 6
		}

		sHTML =	"<table	 id='calTable' border=0 style='font-family:verdana;font-size:10px;'><tr>"

		if (showWeekNumber==1)
		{
			sHTML += "<td width=27><b>" + weekString + "</b></td><td width=1 rowspan=7 bgcolor='#d0d0d0' style='padding:0px'><img src='"+imgDir+"divider.gif' ></td>"
		}

		for	(i=0; i<7; i++)	{
			sHTML += "<td width='27' align='right'><B>"+ dayName[i]+"</B></td>"
		}
		sHTML +="</tr><tr>"

		if (showWeekNumber==1)
		{
			sHTML += "<td align=right>" + WeekNbr(startDate) + "&nbsp;</td>"
		}

		for	( var i=1; i<=dayPointer;i++ )
		{
			sHTML += "<td>&nbsp;</td>"
		}

		for	( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
		{
			dayPointer++;
			sHTML += "<td align=right height=13>"
			sStyle=styleAnchor
			if ((datePointer==odateSelected) &&
				(monthSelected==omonthSelected)	&& (yearSelected==oyearSelected))
			{ sStyle+=styleLightBorder }

			sHint = ""
			for (k=0;k<HolidaysCounter;k++)
			{
				if ((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1)))
				{
					if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0)))
					{
						sStyle+="background-color:#FFDDDD;"
						sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc
					}
				}
			}

			var regexp= /\"/g
			sHint=sHint.replace(regexp,"&quot;")

			dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected))+"\"'  onmouseout='window.status=\"\"' ";
			if (vperValue == "end")
			{
				dateNow = endDaySelected;
				monthNow = endMonthSelected;
				yearNow = endYearSelected;
			}
			else
			{
				//var today = new Date();
				dateNow = today.getDate();
				monthNow = today.getMonth();
				yearNow = today.getFullYear();
			}

			if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow)&&(vperValue!="end"))
			{
				sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer+";closeCalendar();' ><font color=#FFFF00>&nbsp;" + datePointer + "</font>&nbsp;</a>";
			}
			else if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow)&&(vperValue=="end"))
			{
				sHTML += "&nbsp;<font color=#FFFFFF>" + datePointer + "</font>&nbsp;";
			}
			else if	(dayPointer % 7 == (startAt * -1)+1)
			{
				if ((yearSelected < yearNow))
				{
					sHTML += "&nbsp;<font color=#FFFFFF>" + datePointer + "</font>&nbsp;";
				}
				else if ((monthSelected < monthNow)&&(yearSelected <= yearNow))
				{
					sHTML += "&nbsp;<font color=#FFFFFF>" + datePointer + "</font>&nbsp;";
				}
				else if ((datePointer < dateNow)&&(monthSelected <= monthNow)&&(yearSelected <= yearNow))
				{
					sHTML += "&nbsp;<font color=#FFFFFF>" + datePointer + "</font>&nbsp;";
				}
				else
				{
					sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'>&nbsp;<font color=#333333>" + datePointer + "</font>&nbsp;</a>"
				}
			}
			else
			{
				if ((yearSelected < yearNow))
				{
					sHTML += "&nbsp;<font color=#FFFFFF>" + datePointer + "</font>&nbsp;";
				}
				else if ((monthSelected < monthNow)&&(yearSelected <= yearNow))
				{
					sHTML += "&nbsp;<font color=#FFFFFF>" + datePointer + "</font>&nbsp;";
				}
				else if ((datePointer < dateNow)&&(monthSelected <= monthNow)&&(yearSelected <= yearNow))
				{
					sHTML += "&nbsp;<font color=#FFFFFF>" + datePointer + "</font>&nbsp;";
				}
				else
				{
					sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</a>";
				}
			}

			sHTML += ""
			if ((dayPointer+startAt) % 7 == startAt)
			{
				sHTML += "</tr><tr>"
				if ((showWeekNumber==1)&&(datePointer<numDaysInMonth))
				{
					sHTML += "<td align=right>" + (WeekNbr(new Date(yearSelected,monthSelected,
					+1))) + "&nbsp;</td>"
				}
			}
		}
		document.getElementById("content").innerHTML   = sHTML
		document.getElementById("spanMonth").innerHTML = "&nbsp;" +	monthName[monthSelected] + "&nbsp;<IMG id='changeMonth' SRC='"+imgDir+"drop1.jpg' BORDER=0>"
		document.getElementById("spanYear").innerHTML =	"&nbsp;" + yearSelected	+ "&nbsp;<IMG id='changeYear' SRC='"+imgDir+"drop1.jpg' BORDER=0>"
	}

	function setupFebDay(year)
	{
		if (year/4 == parseInt(year/4))
			mEnd[1] = 29;
		else
			mEnd[1] = 28;
	}

	function popUpI18NCalendar(ctl,	ctl2, vper)
	{
		var	leftpos=0
		var	toppos=0

		constructMonthDayStyle();

		setupHotelDate();

		if (bPageLoaded)
		{
			if ( crossobj.visibility == "hidden" )
			{
				ctlToPlaceValue	= ctl2
				vperValue = vper
				dateFormat='dd.mm.yy';

				if ((document.hotelSearchForm.checkInDate.value!="")&&(vper=="end"))
				{
					startDate = document.hotelSearchForm.checkInDate.value;

					date = parseDate(startDate);

					if(date == null || isNaN(date))
					{
						alert('Пожалуйста введите даты в дд.мм.гг формате');

						return;
					}
					endMonthSelected = monthSelected = date.getMonth();
					endDaySelected = dateSelected = date.getDate();
					endYearSelected = yearSelected = date.getFullYear();

					setupFebDay(endYearSelected);
					if (endDaySelected == mEnd[monthSelected])
					{
						if(monthSelected == 11)
						{
							dateSelected = 0;
							monthSelected = 0;
							yearSelected = yearSelected + 1;
						}
						else
						{
							dateSelected = 0;
							monthSelected = monthSelected + 1;
						}
					}
				}
				else if ((document.hotelSearchForm.checkInDate.value=="")&&(vper=="end"))
				{
					alert('Введите дату заезда');
					return false;

				}
				else
				{
					dateSelected = dateNow;
					monthSelected =	monthNow;
					yearSelected = yearNow;

					if(document.hotelSearchForm.checkInDate.value!="")
					{
						startDate = document.hotelSearchForm.checkInDate.value;

						date = parseDate(startDate);

						if(date == null || isNaN(date))
						{
							alert('Пожалуйста введите даты в дд.мм.гг формате');
							return;
						}

						dateSelected = date.getDate();
						yearSelected = date.getFullYear();
						monthSelected = date.getMonth();
					}
				}

				odateSelected = dateSelected
				omonthSelected = monthSelected
				oyearSelected = yearSelected

				aTag = ctl
				do
				{
					aTag = aTag.offsetParent;
					leftpos	+= aTag.offsetLeft;
					toppos += aTag.offsetTop;
				} while(aTag.tagName!="BODY");

				crossobj.left =	(fixedX==-1 ? ctl.offsetLeft	+ leftpos :	fixedX)+"px"
				crossobj.top = (fixedY==-1 ?	ctl.offsetTop +	toppos + ctl.offsetHeight +	2 :	fixedY)+"px"

				//begin calendar construction function
				constructCalendar (1, monthSelected, yearSelected);
				
				if(document.getElementById("iframe1") != null)
				{	
					setIFrameSize();
					//document.getElementById("iframe1").style.width=230;
					//document.getElementById("iframe1").style.height=160;
					document.getElementById("iframe1").style.left=crossobj.left; 
					document.getElementById("iframe1").style.top=crossobj.top;
					document.getElementById("iframe1").style.visibility="visible";
					crossobj.zIndex=10; 
				}
				
				//crossobj.visibility=(dom||ie)? "visible" : "show"
				//document.getElementById("calendar").setActive()
				document.getElementById("calendar").style.visibility = "visible"
			}
			else
			{
				hideCalendar()
				if (ctlNow!=ctl) {popUpI18NCalendar(ctl, ctl2, 'dd.mm.yy')}
			}
			ctlNow = ctl
		}
	}

	function formatYear(/*year string*/ year)
	{

		if(year.length <= 2)
		{
			strYear = yearNow.toString();
			len = strYear.length-2;
			return (strYear.substr(0,2)+year);
		}
		return parseInt(year, 10);
	}

	function setupHotelDate()
	{
		if(document.getElementsByName("earliestHotelDate"))
		{
			var hotelDate = document.getElementsByName("earliestHotelDate")[0].value;

			if((hotelDate !=null)&& (hotelDate.length > 0))
			{
				var tempSplit = hotelDate.split("/");

				today = new Date(tempSplit[2],tempSplit[0]-1,tempSplit[1]);
				//today.setDate(tempSplit[1]);
				//today.setMonth(tempSplit[0]-1);
				//today.setFullYear(tempSplit[2]);

				dateNow	 = today.getDate()
				monthNow = today.getMonth()
				yearNow	 = today.getFullYear()
			}
		}
	}

	/* @param date in string */
	function parseDate(date)
	{
		dateFormat='dd.mm.yy';

		if(typeof date != "string")
			return null;

		var iMonth = dateFormat.indexOf("m");
		var iDay = dateFormat.indexOf("d");
		var iYear = dateFormat.indexOf("yy");

		var dateSeperator = new Array();

		if(iYear == 0)
		{
		//alert("iYear == 0");
			dateSeperator[0] = 'y';
			if(iDay < iMonth)
			{
				dateSeperator[1] = 'd';
				dateSeperator[2] = 'm';
			}
			else
			{
				dateSeperator[1] = 'm';
				dateSeperator[2] = 'd';
			}
		}

		if(iMonth == 0)
		{
		//alert("iMonth == 0");
			dateSeperator[0] = 'm';
			if(iDay < iYear)
			{
				dateSeperator[1] = 'd';
				dateSeperator[2] = 'y';
			}
			else
			{
				dateSeperator[1] = 'y';
				dateSeperator[2] = 'd';
			}
		}

		if(iDay == 0)
		{
		//alert("iDay == 0");
			dateSeperator[0] = 'd';
			if(iMonth < iYear)
			{
				dateSeperator[1] = 'm';
				dateSeperator[2] = 'y';
			}
			else
			{
				dateSeperator[1] = 'y';
				dateSeperator[2] = 'm';
			}
		}

		var pos = 0;
		var iSep = 0;
		var s = "";
		//var d = new Date();
		var myday
		var mymon
		var myyear
		var dateValue = 0;
		while(pos < date.length)
		{
			var c = date.charAt(pos);
            //alert("c:"+c+isNaN(c));
			if(isNaN(c))
			{
				if(!isNaN(s))
				{
					var i = parseInt(s, 10);
                    //alert("i:"+i);
					if(pos != iSep)
					{
						if(dateSeperator[iSep] == 'y')
						{
							//d.setFullYear(formatYear(s));
							myyear = formatYear(s);
						}
						else if(dateSeperator[iSep] == 'm')
						{
						//alert("month: "+i);
							if(i > 12)
								return null;

							//trim the white space if there is any
							s = s.replace(/^\s*|\s*$/g,"");
							
							if(s.length > 2)
								return null;
							//d.setMonth(i-1);
							mymon = i-1;
						}
						else
						{
							dateValue = i;
							
							if(dateValue > 31)
								return null;

							//d.setDate(i);
							myday = i;

						}
						iSep++;
						pos++; //consume this date value;
						s = "";
						continue;
					}
					else
					{
						return null;
					}
				} // end of isNaN(s)
				else
				{
					return null;
				}
			}
            // end of if (isNaN(c))
			s += c;
			pos++;
		}// end of while

		if(iSep == 2)
		{
			var i = parseInt(s, 10);
			if(dateSeperator[iSep] == 'y')
			{
				//d.setFullYear(formatYear(s));
				myyear = formatYear(s);
			}
			else if(dateSeperator[iSep] == 'm')
			{
				if(i > 12)
					return null;
				if(s.length > 2)
					return null;
				//d.setMonth(i);
				mymon = i;
			}
			else
			{
				if(i > 31)
					return null;
				//d.setDate(i);
				myday = i;
			}
		}
		//if(d.getFullYear() < 2000 || d.getFullYear() > 3000)
		if(myyear < 2000 || myyear > 3000)
			return null;
		//setupFebDay(d.getFullYear());
		setupFebDay(myyear);


		if(dateValue > mEnd[mymon])
			return null;
		
		if(myyear == null || mymon== null || myday==null)
			return null;
		rDate = new Date(myyear,mymon,myday);
//		alert("month:"+d.getMonth()+"day:"+d.getDate()+"year:"+d.getFullYear());
		//rDate.setFullYear(d.getFullYear(), d.getMonth(), d.getDate());

		return rDate;
	}

	function compareDate(strStartDate, strEndDate)
	{
		startDate = parseDate(strStartDate);
		endDate = parseDate(strEndDate);
		dateFormat='dd.mm.yy';

		if(startDate == null || endDate == null)
		{
			alert('Пожалуйста введите даты в дд.мм.гг формате');
			return false;
		}

		if(startDate > endDate)
			return 1;
		else if (startDate < endDate)
			return -1;
		else
			return 0;
	}

	// This function hide heavy components on the HotelSearch page
	function enableFields(enable)
	{
		rateLimit = document.getElementById("rateLimit");
	        features = document.getElementById("features");
		selectedFeatures = document.getElementById("fea2");

	        if(rateLimit)
		{
	            rateLimit.style.visibility =  (enable == true ? 'visible' : 'hidden');
		}

	        if(features)
		{
	            features.style.visibility = (enable == true ? 'visible' : 'hidden');
		}

	        if(selectedFeatures)
		{
	            selectedFeatures.style.visibility =  (enable == true ? 'visible' : 'hidden');
		}

		enableRadio();
	}


	function enableRadio()
	{
	    var s = document.hotelSearchForm.availabilitySort;

	    if (s != null)
	    {
	    if((document.hotelSearchForm.checkInDate.value != "") && (document.hotelSearchForm.checkOutDate.value != ""))
	    {
			for(i=0; i < s.length; i++)
	        {
				s[i].disabled = false;
	        }
	    }
	    else
	    {
			for(i=0; i < s.length; i++)
	        {
				s[i].disabled = true;
	        }
		}
	    }
		checkingInOutDate();
	}


	function checkingInOutDate()
	{
		if ((document.hotelSearchForm.checkOutDate.value!="")&&
				(document.hotelSearchForm.checkInDate.value!=""))
		{
			if(compareDate(document.hotelSearchForm.checkInDate.value,
				document.hotelSearchForm.checkOutDate.value) > -1)
			{
				alert("Будьте внимательны, дата выезда дожна быть позже чем дата заезда!");
				document.hotelSearchForm.checkOutDate.value = "";
			}
		}
	}

	function valI18NDates(form)
	{
		dateFormat='dd.mm.yy';

		setupHotelDate();

		var date1 = null;
		var date2 = null;

		if(document.hotelSearchForm.checkInDate)
		{
			date1 = document.hotelSearchForm.checkInDate.value;

			d1 = parseDate(date1);

			if(d1 == null && (date1.length > 0) )
			{
				alert('Пожалуйста введите даты в дд.мм.гг формате');
				return false;
			}
		}

		if(document.hotelSearchForm.checkOutDate)
		{
			date2 = document.hotelSearchForm.checkOutDate.value;

			d2 = parseDate(date2);

			if(date2.length > 0)
			{
				if(d2 != null)
				{
					var year2 = d2.getFullYear();
					var day2= d2.getDate();
					var month2 = d2.getMonth();
				}
				else
				{
					alert('Пожалуйста введите даты в дд.мм.гг формате');
					return false;
				}
			}
		}

 		if((document.hotelSearchForm.checkInDate)&&(document.hotelSearchForm.checkOutDate))
 		{
			if(d1 != null)
			{
				var year1 = d1.getFullYear();
				var day1 = d1.getDate();
				var month1 = d1.getMonth();
			}
		}

		if((date1 != null) && (date1.length > 0) && (date2 != null) && (date2.length > 0))
		{
			//var today = new Date();
			var now = today.getDate();
			var checkInDate = new Date(d1);
			var checkOutDate = new Date(d2);


			if(isNaN(checkInDate)||isNaN(checkOutDate))
			{
				alert('Пожалуйста введите даты в дд.мм.гг формате');
				return false;
			}

			if(checkInDate < today)
			{
				alert('Дата заезда должна быт меньше даты выезда');
				return false;
			}
			else if (checkInDate < today || checkInDate > checkOutDate)
			{
				alert('Дата выезда должна быть больше даты заезда');
				return false;
			} else {
				return true;
				//document.forms.hotelSearchForm.submit();
			}
		}
		else
		{
			return true;
		}
	}
	
	function setIFrameSize(){
		if(document.getElementById("iframe1") != null){
			if (document.getElementById("calTable").rows.length == 7){
				document.getElementById("iframe1").style.width=228;
				if(dayPointer > 35){
					document.getElementById("iframe1").style.height=160;
				}
				else{
					document.getElementById("iframe1").style.height=150;
				}
			} else {
				document.getElementById("iframe1").style.width=228;
				document.getElementById("iframe1").style.height=145;
			}
		}
	}

	function submitSelectedLocale()
	{
		document.hotelSearchForm.action = "https://karyonres.travel/listHotels.do?action=SelectLocale";
		document.hotelSearchForm.submit();
	}

	function showCalender(ctrl)
	{
		ctrl.select();
		init();
		constructMonthDayStyle();
		popUpI18NCalendar(ctrl, ctrl, 'start')
	}


	function checkUseChildCategories()
	{
		var useChildCategories = document.forms[1].useChildCategories.value;
		if (useChildCategories == 'true'){
			showChildCategoryStatus();
		}else{
			var onStatus = "inline";
			var offStatus = "none";
			setNavigationStatus(onStatus, offStatus);
		}
	}


	function showChildCategoryStatus()
	{
		var numChildCategories = document.forms[1].numChildCategories.value;
		var totalChild =  document.getElementById('numberOfChildren').selectedIndex;

		if (totalChild != 0) {
			var onStatus = "inline";
			var offStatus = "none";
		} else {
			var onStatus = "none";
			var offStatus = "inline";

			for (var i=0; i<numChildCategories; i++){
				document.getElementById('under_' + i).selectedIndex = "0";

			}
		}

		document.getElementById('childCategories').style.display = onStatus;
		document.getElementById('star').style.display = onStatus;
		totalSelect();
	}



	function totalSelect(){
		var numChildCategories = document.forms[1].numChildCategories.value;
		var totalChild =  document.getElementById('numberOfChildren').selectedIndex;
		var sumChildCategories = 0;

		for (var i=0; i<numChildCategories; i++)
			sumChildCategories += parseInt(document.getElementById('under_' + i).value);

		if((totalChild == sumChildCategories) || totalChild == 0){
			var onStatus = "inline";
			var offStatus = "none";
		} else {
			var onStatus = "none";
			var offStatus = "inline";
		}
		clearLinks();
		setNavigationStatus(onStatus, offStatus);

	}

	function setNavigationStatus(onStatus, offStatus)
	{
			if (document.getElementById('searchOn') && document.getElementById('searchOff')) {
				document.getElementById('searchOn').style.display = onStatus;
				document.getElementById('searchOff').style.display = offStatus;
			}

			var linkStatus = document.getElementsByTagName('tr');
			for(i=0; i<linkStatus.length; i++){
			if(linkStatus[i].className == "link"){
				if (document.forms[1].onload.value == "true")
					linkStatus[i].style.display = onStatus;
			}
			if(linkStatus[i].className == "text"){
				linkStatus[i].style.display = offStatus;
			}
		}
	}

	function clearLinks()
	{
			var linkStatus = document.getElementsByTagName('tr');
			for(i=0; i<linkStatus.length; i++){
			if(linkStatus[i].className == "link"){
				linkStatus[i].style.display = "none";
			}
			if(linkStatus[i].className == "text"){
				linkStatus[i].style.display = "none";
			}
		}
	}

	function submitWithDifferentAction(form,action){
	  
		form.action =  action;
		if (validateHotelSearchFormWithDates(form) == true)
			form.submit();
	}

	function viewSpecialRates(index){
		
		document.getElementById('specialRates_' + index).style.display = "inline";
		document.getElementById('viewRates_' + index).style.display = "none";
		document.getElementById('properties[' + index + '].hasQualifiedRatePlanCodesOpen').value = 'true';
		
	}
function OnSubmitForm()
{
	inDate = document.hotelSearchForm.checkInDate.value.split('.');
	inDate = inDate[1]+'/'+inDate[0]+'/'+inDate[2];
	outDate = document.hotelSearchForm.checkOutDate.value.split('.');
	outDate = outDate[1]+'/'+outDate[0]+'/'+outDate[2];
	url = 'http://sv-hotel.ru/bronir/';
	document.location.href = url;
	return false;
}
