	
	function VerifyDate(nMonth, nDay, nYear)
{
	var sDate = nMonth + "/" + nDay + "/" + nYear;
	
	var dDate = new Date(sDate);
	var nMonth2 = dDate.getMonth() + 1;
	
	if (nMonth2 == nMonth)
		return true;
	else
		return false;
}
	
	
	
		function addToArray(ar, str)
	{
		var l;
		l = ar[0] + 1;
		ar[l] = str;
		ar[0] = l;
	}
	
	function makeArray()
	{
		array = new Object();
		array[0] = 0;
		return array;
	}

	var dayNames = makeArray();
	addToArray(dayNames, "Sun");
	addToArray(dayNames, "Mon");
	addToArray(dayNames, "Tue");
	addToArray(dayNames, "Wed");
	addToArray(dayNames, "Thu");
	addToArray(dayNames, "Fri");
	addToArray(dayNames, "Sat");

	function ResetDays()
	{
		var cboDay = document.SearchForm.SearchNav_cboDayList;
		while (cboDay.length < 31)
		{
			oNewOption = new Option(cboDay.length + 1, cboDay.length + 1);
			cboDay.options[cboDay.length] = oNewOption;
		}
	}
	
	function RefreshDaysInMonth()
	{
		var nMonth;
		var nYear;
		var nTotalDays;
		var nDay;
		var cboMonth = document.SearchForm.SearchNav_cboMonthList;
		var cboYear = document.SearchForm.SearchNav_cboYearList;
		var cboDay = document.SearchForm.SearchNav_cboDayList;
		nMonth = cboMonth.options[cboMonth.selectedIndex].value;
		nYear = cboYear.options[cboYear.selectedIndex].value;
		nDay = cboDay.options[cboDay.selectedIndex].value;
		
		
		
		var dToday = new Date()
		var sThisYear = dToday.getFullYear();
		var sThisMonth = dToday.getMonth();
		if (nYear == sThisYear && 
		(sThisMonth == "11" || sThisMonth == "12") &&
		(nMonth == "1" || nMonth == "2")
		)
		{
				// Search is probably for January or February of next year
				nYear = cboYear.options[cboYear.selectedIndex+1].value;
				cboYear.selectedIndex = "1";
		}
		
		nTotalDays = cboDay.length;
		
		var nSelectedIndex = cboDay.selectedIndex;
		
		var rnow = new Date(nYear,nMonth-1,nDay);
		var rday = rnow.getDay()+1;
		//alert(rday)
		document.SearchForm.SearchNav_txtDayofWeek.value = dayNames[rday]

		var oNewOption;
		while (VerifyDate(nMonth,nTotalDays + 1,nYear))
		{
			oNewOption = new Option(nTotalDays + 1,nTotalDays + 1);			
			cboDay.options[nTotalDays] = oNewOption;
			nTotalDays = cboDay.length;
		}
		
		while (!VerifyDate(nMonth,nTotalDays,nYear))
		{
			cboDay.remove(nTotalDays - 1);
			nTotalDays = cboDay.length;			
		}
		
		if (nSelectedIndex >= cboDay.length)
		{
			cboDay.selectedIndex = cboDay.length - 1;
		}
		
		
		
	}
	
	
	function RefreshDaysInMonthProfile()
	{	
		var nMonth;
		var nYear;
		var nTotalDays;
		var nDay;
						
		var cboMonth = document.SearchForm.RestaurantProfile_cboMonthList;
		var cboYear = document.SearchForm.RestaurantProfile_cboYearList;
		var cboDay = document.SearchForm.RestaurantProfile_cboDayList;		
		
		nMonth = cboMonth.options[cboMonth.selectedIndex].value;
		nYear = cboYear.options[cboYear.selectedIndex].value;
		nDay = cboDay.options[cboDay.selectedIndex].value;
		
		nTotalDays = cboDay.length;
		
		var nSelectedIndex = cboDay.selectedIndex;
				
		var rnow = new Date(nYear,nMonth-1,nDay);
		var rday = rnow.getDay()+1;
		document.SearchForm.RestaurantProfile_txtDayofWeek.value = dayNames[rday]

		var oNewOption;
		while (VerifyDate(nMonth,nTotalDays + 1,nYear))
		{
			oNewOption = new Option(nTotalDays + 1,nTotalDays + 1);
			
			cboDay.options[nTotalDays] = oNewOption;
			nTotalDays = cboDay.length;
		}
		
		while (!VerifyDate(nMonth,nTotalDays,nYear))
		{
			cboDay.remove(nTotalDays - 1);
			nTotalDays = cboDay.length;
		}
		
		if (nSelectedIndex >= cboDay.length)
		{
			cboDay.selectedIndex = cboDay.length - 1;
		}
		
		// akash: update the search module information also..		
		synchWithSearchModule();
	}
	
	// when a date in the search pages changes - update the restaurant profile pages..
	function synchWithRestaurantProfilePage()
	{
		try
		{
			// update month in Search module..
			if(document.SearchForm.RestaurantProfile_cboMonthList != null)
			{
				document.SearchForm.RestaurantProfile_cboMonthList.selectedIndex = document.SearchForm.SearchNav_cboMonthList.selectedIndex;
			}
			
			// update year in Search module..
			if(document.SearchForm.RestaurantProfile_cboYearList != null)
			{
				document.SearchForm.RestaurantProfile_cboYearList.selectedIndex = document.SearchForm.SearchNav_cboYearList.selectedIndex;
			}
			
			// update date in Search module..
			if(document.SearchForm.RestaurantProfile_cboDayList != null)
			{
				document.SearchForm.RestaurantProfile_cboDayList.selectedIndex = document.SearchForm.SearchNav_cboDayList.selectedIndex;
			}
			
			// update day of week..
			if(document.SearchForm.RestaurantProfile_txtDayofWeek != null)
			{
				document.SearchForm.RestaurantProfile_txtDayofWeek.value = document.SearchForm.SearchNav_txtDayofWeek.value;
			}
			
			// update time in Search module..
			if(document.SearchForm.RestaurantProfile_cboHourList != null)
			{
				document.SearchForm.RestaurantProfile_cboHourList.selectedIndex = document.SearchForm.SearchNav_cboHourList.selectedIndex;
			}

			// update time in Search module..
			if(document.SearchForm.RestaurantProfile_cboMinuteList != null)
			{
				document.SearchForm.RestaurantProfile_cboMinuteList.selectedIndex = document.SearchForm.SearchNav_cboMinuteList.selectedIndex;
			}
			
			// update meridian in Search module..
			if(document.SearchForm.RestaurantProfile_cboMeridianList != null)
			{
				document.SearchForm.RestaurantProfile_cboMeridianList.selectedIndex = document.SearchForm.SearchNav_cboMeridianList.selectedIndex;
			}
			
			// update partysize in search module..
			if(document.SearchForm.RestaurantProfile_cboPartySize != null)
			{
				document.SearchForm.RestaurantProfile_cboPartySize.selectedIndex = document.SearchForm.SearchNav_cboPartySize.selectedIndex;
			}
		}
		catch(ex)
		{
		}
	}
		
	
	// When the date in the restaurant profile changes - update the
	// date in the search module also..
	function synchWithSearchModule()
	{
		try
		{
				
			// update month in Search module..
			if(document.SearchForm.SearchNav_cboMonthList != null)
			{
				document.SearchForm.SearchNav_cboMonthList.selectedIndex = document.SearchForm.RestaurantProfile_cboMonthList.selectedIndex;
			}
			
			// update year in Search module..
			if(document.SearchForm.SearchNav_cboYearList != null)
			{
				document.SearchForm.SearchNav_cboYearList.selectedIndex = document.SearchForm.RestaurantProfile_cboYearList.selectedIndex;
			}
			
			// update date in Search module..
			if(document.SearchForm.SearchNav_cboDayList != null)
			{
				document.SearchForm.SearchNav_cboDayList.selectedIndex = document.SearchForm.RestaurantProfile_cboDayList.selectedIndex;
			}
			
			// update time in Search module..
			if(document.SearchForm.SearchNav_cboHourList != null)
			{
				document.SearchForm.SearchNav_cboHourList.selectedIndex = document.SearchForm.RestaurantProfile_cboHourList.selectedIndex;
			}			
			// update time in Search module..
			if(document.SearchForm.SearchNav_cboMinuteList != null)
			{
				document.SearchForm.SearchNav_cboMinuteList.selectedIndex = document.SearchForm.RestaurantProfile_cboMinuteList.selectedIndex;
			}			
			
			// update day of week..
			if(document.SearchForm.SearchNav_txtDayofWeek != null)
			{
				document.SearchForm.SearchNav_txtDayofWeek.value = document.SearchForm.RestaurantProfile_txtDayofWeek.value;
			}
			
			// update meridian in Search module..
			if(document.SearchForm.SearchNav_cboMeridianList != null)
			{
				document.SearchForm.SearchNav_cboMeridianList.selectedIndex = document.SearchForm.RestaurantProfile_cboMeridianList.selectedIndex;
			}
			
			// update partysize in search module..
			if(document.SearchForm.SearchNav_cboPartySize != null)
			{
				document.SearchForm.SearchNav_cboPartySize.selectedIndex = document.SearchForm.RestaurantProfile_cboPartySize.selectedIndex;
			}
		}
		catch(ex)
		{
		}
	}


	function saveValues() 
	{
		var UserDateTime=(document.SearchForm.SearchNav_cboMonthList.value + "/" + document.SearchForm.SearchNav_cboDayList.value + "/" + document.SearchForm.SearchNav_cboYearList.value + " " + document.SearchForm.SearchNav_cboHourList.value + ":" + document.SearchForm.SearchNav_cboMinuteList.value + " " + document.SearchForm.SearchNav_cboMeridianList.value)
		var str = document.SearchForm.SearchNav_cboPartySize.value + "|" + UserDateTime
		
		UserDateTime = new Date(UserDateTime)
		document.cookie="r4=" + str
		+ ";path=/;"
		//+ ";expires=" + UserDateTime.toGMTString() + 
	}


	/******************************************
	The following is a split function for Javascript 1.0
	it returns its values in an array....
	******************************************/
	function mySplit(str, ch)
	{
		
		anArray = makeArray();
		if (str != "")		//navigator 2 bug workaround?
		{
		start = 0
		end = 0
		i=0
		//anArray = makeArray();
		while (str.indexOf(ch) != -1)
			{
			end = str.indexOf(ch)
			strTemp = (str.substring(start, end))
			addToArray(anArray, strTemp)
			str = str.substring(end+1, str.length)
			i += 1
			}
			addToArray(anArray, str)
		}
		return anArray
	}

	function clearValues() {
 		document.cookie="r4=";
		}
	/******************************************************
	function findCookie(str) -- finds and returns the specified cookie's value... 
	******************************************************/
	function findCookie(str)
		{
		var cookieValue = ""
		var pos = document.cookie.indexOf(str)
			if (pos > -1)
			{
			var start = pos + str.length + 1
			var end = document.cookie.indexOf(";", pos)
			if (end == -1)
				{
				end = document.cookie.length
				}
			cookieValue = document.cookie.substring(start, end)
			}
			return cookieValue;
		}
		
	/******************************************************
	function retrieve() -- retrieves the user's previous values for this page...
	******************************************************/
	function retrieve()
	{
		try
		{	
			var remValue = ""
			var pos = document.cookie.indexOf("=");
					
			if (pos != -1)
			{
				var rem = findCookie("r4")
				valuesArray = mySplit(rem, "|");
				
				if ((valuesArray[1] != null) && (valuesArray[1]!=""))
				{
					str = valuesArray[1];
					if (str.length < 3) {
						document.SearchForm.SearchNav_cboPartySize.value = valuesArray[1];
					}
				}				
				

				
				if ((valuesArray[2] != null) && (valuesArray[2] != ""))
				{
					var UserDateTime=new Date(valuesArray[2]);
					var ServerDateTime=new Date(document.SearchForm.SearchNav_txtHidServerTime.value);
					
					if (ServerDateTime > UserDateTime)
					{
						UserDateTime.setMonth(ServerDateTime.getMonth())
						UserDateTime.setDate(ServerDateTime.getDate())
						if (ServerDateTime.getHours() <= 19)
						{
							UserDateTime.setHours(19)
						}
						else
						{
							UserDateTime.setHours(ServerDateTime.getHours()+1)
						}
						UserDateTime.setMinutes(0)
					}
					document.SearchForm.SearchNav_cboMonthList.value = UserDateTime.getMonth()+1;
					document.SearchForm.SearchNav_cboDayList.value = UserDateTime.getDate();
					document.SearchForm.SearchNav_cboYearList.value = UserDateTime.getYear();
					var hour = UserDateTime.getHours();
					var minute = UserDateTime.getMinutes();
					document.SearchForm.SearchNav_cboMeridianList.selectedIndex = 1;
					
					if (hour == 12) {
						hour = hour;
					}
					else if (hour == 0) {
						hour = 12;
						document.SearchForm.SearchNav_cboMeridianList.selectedIndex = 0;
					}
					else if (hour > 12) {
						hour = hour - 12;
					}
					else {
						document.SearchForm.SearchNav_cboMeridianList.selectedIndex = 0;
					}
					
					if (minute == "0")
					{
						minute = "00";
					}
					
					
					//var UserTime = hour + ":00";
					//if (UserDateTime.getMinutes() != 0) {
					//	UserTime = hour + ":" + UserDateTime.getMinutes();
					//}
					document.SearchForm.SearchNav_cboHourList.value = hour;
					document.SearchForm.SearchNav_cboMinuteList.value = minute;
				}
			}
			RefreshDaysInMonth()
		}
		catch(ex)
		{
		}		
	}

//////////////////// --- From RestaurantProfile Page --- //////////////////////////
	function ProfileRefreshDaysInMonth()
	{
		var nMonth;
		var nYear;
		var nTotalDays;
		var nDay;
		var cboMonth = document.SearchForm.RestaurantProfile_cboMonthList;
		var cboYear = document.SearchForm.RestaurantProfile_cboYearList;
		var cboDay = document.SearchForm.RestaurantProfile_cboDayList;
		nMonth = cboMonth.options[cboMonth.selectedIndex].value;
		nYear = cboYear.options[cboYear.selectedIndex].value;
		nDay = cboDay.options[cboDay.selectedIndex].value;
		
		nTotalDays = cboDay.length;
		
		var nSelectedIndex = cboDay.selectedIndex;
		
		var rnow = new Date(nYear,nMonth-1,nDay);
		var rday = rnow.getDay()+1;
		//alert(rday)
		document.SearchForm.RestaurantProfile_txtDayofWeek.value = dayNames[rday]

		var oNewOption;
		while (VerifyDate(nMonth,nTotalDays + 1,nYear))
		{
			oNewOption = new Option(nTotalDays + 1,nTotalDays + 1);
			
			cboDay.options[nTotalDays] = oNewOption;
			nTotalDays = cboDay.length;
			
			
		}
		
		while (!VerifyDate(nMonth,nTotalDays,nYear))
		{
			cboDay.remove(nTotalDays - 1);
			nTotalDays = cboDay.length;
			
		}
		if (nSelectedIndex >= cboDay.length)
			cboDay.selectedIndex = cboDay.length - 1;
	}


	

	/******************************************************
	function Profileretrieve() -- retrieves the user's previous values for this page...
	******************************************************/
	function Profileretrieve()
	{
		var remValue = ""
		var pos = document.cookie.indexOf("=");
				
		if (pos != -1)
		{
			var rem = findCookie("r4")
			valuesArray = mySplit(rem, "|")
			
			if ((valuesArray[1] != null) && (valuesArray[1]!=""))
			{
				str = valuesArray[1];
				if (str.length < 3) {
					document.SearchForm.RestaurantProfile_cboPartySize.value = valuesArray[1];
				}
			}
			if ((valuesArray[2] != null) && (valuesArray[2] != ""))
			{
				var UserDateTime=new Date(valuesArray[2])
				document.SearchForm.RestaurantProfile_cboMonthList.value = UserDateTime.getMonth()+1;
				document.SearchForm.RestaurantProfile_cboDayList.value = UserDateTime.getDate();
				document.SearchForm.RestaurantProfile_cboYearList.value = UserDateTime.getYear();
				var hour = UserDateTime.getHours();
				var minute = UserDateTime.getMinutes();
				document.SearchForm.RestaurantProfile_cboMeridianList.selectedIndex = 1;
				if (hour > 12) {
					hour = hour - 12;
				}
				else {
					document.SearchForm.RestaurantProfile_cboMeridianList.selectedIndex = 0;
				}
				//var UserTime = hour + ":00";
				//if (UserDateTime.getMinutes() != 0) {
				//	UserTime = hour + ":" + UserDateTime.getMinutes();
				//}
				document.SearchForm.RestaurantProfile_cboHourList.value = hour;
				document.SearchForm.RestaurantProfile_cboMinuteList.value = minute;
			}
		}
		ProfileRefreshDaysInMonth()
		
	}
	function Mid(str, start, len)
    {
            // Make sure start and len are within proper bounds
            if (start < 0 || len > 0) return "";

            var iEnd, iLen = String(str).length;
            if (start + len > iLen)
                    iEnd = iLen;
            else
                    iEnd = start + len;

            return String(str).substring(start,iEnd);
    }