		function zeroPad(num,count)
		{ 
			var numZeropad = num + "";
			while(numZeropad.length < count) {	
				numZeropad = "0" + numZeropad; 
			}
			return numZeropad;
		}

		var monthnames = new Array;
		monthnames[1]="January";
		monthnames[2]="February";
		monthnames[3]="March";
		monthnames[4]="April";
		monthnames[5]="May";
		monthnames[6]="June";
		monthnames[7]="July";
		monthnames[8]="August";
		monthnames[9]="September";
		monthnames[10]="October";
		monthnames[11]="November";
		monthnames[12]="December";

		function toggleRateCalendar(hid,num)
		{
			if (document.getElementById("ratecal_"+hid+"_"+num))
			{
				$("#ratecal_"+hid+"_Show"+num).slideToggle("slow");
				if ( document.getElementById("ratecal_"+hid+"_Img"+num).src.search("ratecal_closed.gif") > 0 )
				{
					document.getElementById("ratecal_"+hid+"_Img"+num).src = "http://www.juicyhotels.com/images/ratecal_open.gif";
				}
				else
				{
					document.getElementById("ratecal_"+hid+"_Img"+num).src = "http://www.juicyhotels.com/images/ratecal_closed.gif";
				}
			}
		}
		function showRateDetails(hid, num)
		{
			var sfx = "_" + hid + "_" + num;
			$("#ratecontents_"+hid+" div.contentcontainer").hide();
			$("#tabcontainer_"+hid+" div").removeClass("curr");
			$("#tab"+sfx).addClass("curr");
			$("#contents"+sfx).show();
			$("#tab"+sfx+" a").blur();
			$("#ratepopup").hide();
		}
		
		function showRateCalendar(hid, num)
		{
			var sfx = "_" + hid + "_" + num;
			var calhtml = $("#cal"+sfx).html();
			var pos = $("#rates_"+hid).offset();
			var h = $("#cal"+sfx).css("height");
	
			if ($("#ratepopup").css("display") == "none")
			{
				$("#ratepopup").html(calhtml);
				$("#ratepopup").css({"top": (pos.top-237)+"px", "height": h});
			}
			$("#ratepopup").slideToggle("fast");
			if ($("#ratecal_"+hid+"_Img"+num).attr("src").search("ratecal_right_closed.gif") > 0)
			{
				$("#ratecal_"+hid+"_Img"+num).attr("src", "http://www.juicyhotels.com/images/ratecal_right_open.gif");
			}
			else
			{
				$("#ratecal_"+hid+"_Img"+num).attr("src", "http://www.juicyhotels.com/images/ratecal_right_closed.gif");
			}
		}

		var curFld = '';
		var curHid = 0;
		var curNum = 0;
		
		function showRateCalendarEdit(hid, num, fld)
		{
			var sfx = "_" + hid + "_" + num;
			var calhtml = $("#cal"+sfx).html();
			var pos = $("#rate"+fld+sfx).offset();
			var h = $("#cal"+sfx).css("height");

			if ($("#ratepopup").css("display") != "none")
			{
				if (curFld == fld && curHid == hid & curNum == num)
				{
					// We are closing by pressing cal icon again
					$("#ratepopup").slideToggle("fast");
					curFld = '';
					curHid = 0;
					curNum = 0;

					return;
				}
			}
			
			$("#ratepopup").hide();
			if ($("#ratepopup").css("display") == "none")
			{
				$("#ratepopup").html(calhtml);
				$("#ratepopup").css({"left": (pos.left+20), "top": (pos.top)+"px", "height": h});
			}
			$("#ratepopup").slideToggle("fast");
//			if ($("#ratecal_"+hid+"_Img"+num).attr("src").search("ratecal_right_closed.gif") > 0)
//			{
//				$("#ratecal_"+hid+"_Img"+num).attr("src", "http://www.juicyhotels.com/images/ratecal_right_open.gif");
//			}
//			else
//			{
//				$("#ratecal_"+hid+"_Img"+num).attr("src", "http://www.juicyhotels.com/images/ratecal_right_closed.gif");
//			}

			curFld = fld;
			curHid = hid;
			curNum = num;
		}

		function loadAjaxRates(hid, num)
		{
						indate = document.getElementById("datein").value;
						nights = document.getElementById("nights").value;
						rooms = document.getElementById("NumberofRooms").value;
						children = document.getElementById("NumberofChildren").value;
						adults = document.getElementById("NumberofAdults").value;
						currency = document.getElementById("s_currency").value;
						if (indate == '')
						{
							datein = '';
							dateout = '';
						}
						else
						{
							parts=indate.split("/");
							dateobj = new Date(monthnames[parseInt(parts[0])] + " " + parts[1] + ", " + parts[2]);
							datein = dateobj.getFullYear() + "-" + zeroPad(parseInt(dateobj.getMonth())+1,2) + "-" + zeroPad(dateobj.getDate(),2);
							outdateobj = new Date(dateobj.getFullYear(), dateobj.getMonth(), 0 + dateobj.getDate() + parseInt(nights));
							dateout = outdateobj.getFullYear() + "-" + zeroPad(parseInt(outdateobj.getMonth())+1,2) + "-" + zeroPad(outdateobj.getDate(),2);
						}

            loadRoomRateAjax(datein,dateout,rooms,adults,children,currency,hid,"detShowa"+num);
		}

		function reloadAjaxRates(hid,num,divname)
		{
			var sfx = "_" + hid + "_" + num;

			var startd = $("#cki"+sfx).val();
			var endd = $("#cko"+sfx).val();

		if (document.getElementById('NumberofRooms')) {
			rooms = document.getElementById("NumberofRooms").value;
		} else {
			rooms =1;
		}
		if (document.getElementById('NumberofChildren')) {
			children = document.getElementById("NumberofChildren").value;
		} else {
			children=0;
		}
		if (document.getElementById('NumberofAdults')) {
			adults = document.getElementById("NumberofAdults").value;
		} else {
			adults=1;
		}
		if (document.getElementById('s_currency')) {
			currency = document.getElementById("s_currency").value;
		} else {
			currency='USD';
		}

      loadRoomRateAjax(startd,endd,rooms,adults,children,currency,hid,divname);
		}


function loadRoomRateAjax(startDate,endDate,rooms,addults,children,currency,hotelID,Ratediv){
	showAjaxLoader(Ratediv);
	var str = 'startDate='+startDate+'&endDate='+endDate+'&rooms='+rooms+'&addults='+addults+'&children='+children+'&currency='+currency+'&hotelID='+hotelID;
	ajaxRequest('http://www.juicyhotels.com/includes/rete_ajax.php?'+str+'&rand='+Math.floor(Math.random()),Ratediv);
}

		function hideAjaxRates(hid, num)
		{
			if ($("#ratepopup").css("display") != "none")
			{
				$("#ratepopup").slideToggle("fast");
			}
			curFld = '';
			curHid = 0;
			curNum = 0;
		}
		
		function selectDay(hid, num, d, donly)
		{
			var sfx = "_" + hid + "_" + num;

			$("#check"+curFld+sfx).html(d);
			
			parts=d.split("/");
			dateobj = new Date(monthnames[parseInt(parts[0])] + " " + parts[1] + ", " + parts[2]);
			ymd = dateobj.getFullYear() + "-" + zeroPad(parseInt(dateobj.getMonth())+1,2) + "-" + zeroPad(dateobj.getDate(),2);

			if (curFld == 'in')
			{
				$("#cki"+sfx).val(ymd);
				var cout = $("#cko"+sfx).val();
				if (cout < ymd)
				{
					// user picked a checkin date after the checkout
					$("#cko"+sfx).val('');
					$("#checkout"+sfx).html('');
				}
			}
			else
			{
				$("#cko"+sfx).val(ymd);
				var cin = $("#cki"+sfx).val();
				if (cin > ymd)
				{
					// user picked a checkin date after the checkout
					$("#cki"+sfx).val('');
					$("#checkin"+sfx).html('');
				}
			}
			
			var workd = $("#cki"+sfx).val();
			parts=workd.split("-");
			startd = parts[2]*1;
			var workd = $("#cko"+sfx).val();
			parts=workd.split("-");
			endd = parts[2]*1;

			$('#ratepopup div').removeClass("inrange");
			
			for(i=startd; i<endd; i++)
			{
				$('#calday'+sfx+'_'+i).addClass("inrange");
			}			
			
			$("#ratepopup").slideToggle("fast");
			$("#cal"+sfx).html($("#ratepopup").html());
			$("#again"+sfx).show();
		}
		
		function adjustOtherDate(thisdate)
		{
			var dt = $('#'+thisdate).val();
			var otherdate = thisdate;
			if (thisdate.substr(0,3) == 'cki')
			{
				otherdate = thisdate.replace('cki', 'cko');
			}
			else
			{
				otherdate = thisdate.replace('cko', 'cki');
			}
			var odt = $('#'+otherdate).val();
			if (odt == '')
			{
				$('#'+otherdate).val(dt);
			}
		}

