var color_0;
var color_1;
var color_2;
var color_3;
var color_4;
var color_5;
var color_6;
var color_7;
var color_8;
var color_9;
var color_10;
var color_11;
var color_12;
var color_13;
var color_14;
var td = "style=\"font-family:verdana;font-size:8pt;color:" + color_2 + "\"";
var Office_ID;
var Geography_ID;
var poid;
var vdays;
var drule;
var fflag = true;
var rflag = true;
var	qsAction = "http://www.RealTimeRental.com/rrv10/visitor/search.asp";
var	qsMethod = "post";
//var StartDate;
//var StartYear;
//var StartMonth;
//var StartDay;
//var StartDayOfWeek;
//var EndDate;
//var EndYear;
//var EndMonth;
//var EndDay;
//var EndDayOfWeek;
var CurDate = new Date();
var CurYear = CurDate.getFullYear();
var CurMonth = CurDate.getMonth();
var CurDay = CurDate.getDate();
var CurDayOfWeek = CurDate.getDay();
var CurStartDay;
var CurYearOnly = false;
var DateLimit = new Date();
var FirstStartDay;
var FirstStartDate;
var FirstStartMonth;
var FirstStartYear;
var FirstStartDayOfWeek;
var UseSpecificDates;
var UseBeds = false;
var UseAdults = false;
var	UseKids = false
var UseSmoking = false;
var UseRates = false;
var UseCat = false;
var UseProp = false;
var LimitToNumberDays = 0;
var PropString = "";
var AltDefinition = 0;
var FormTitle = CurYear.toString() + " Availability Search";
var Months_Long = new Array("January","Februray","March","April","May","June","July","August","September","October","November","December");
var Months_Short = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var Weekdays_Long = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Sat","Sun");
var RuleStartDate;
var RuleEndDate;
var StayStartDate;
var StayEndDate;
var FirstPass = true;
var CanSelectDates = true;//true or false, lets calendar dates to be selected (true if current date within rule date range. false otherwise)
var weekdays_Short = new Array("Su","Mo","Tu","We","Th","Fr","Sa");
//
var ifssd = new Date();// init first stay start date
var ilssd = new Date();//init last stay start date
var ifsed = new Date();//init first stay end date
var ilsed = new Date();//init last stay end date
var RuleArray = new Array(10);
var RuleArray1 = new Array(16);
for (i = 0; i < RuleArray1.length; i++)
{
	if (i == 3)
	{
		RuleArray1[i] = "";
	}
	else
	{
		RuleArray1[i] = 0;
	}
}
for (i = 0; i < RuleArray.length; i++)
{
	RuleArray[i] = new Array(15);
	for (j = 0; j < 15; j++)
	{
		if ((i != 0) && ( j == 0))
			RuleArray[i][j] = ""
		else
			RuleArray[i][j] = RuleArray1[j];
	}
}
var RuleStr = "";
var RuleCount;
var calHtm;
var qshlp = "";
var qskS0 = "";
var qshR0 = "";
var qshR1 = "";
var qshM0 = "";
var qshM1 = "";
var qshC0 = "";
var qshC1 = "";
var qshCM0 = "";
var qshCM1 = "";
var qshsb = "";
var iDate = new Date();
var UseCalendar = false;
var UseLocation = false;
var MultiRule = false;
var sRuleDate =  new Date()
var eRuleDate = new Date();
var sRuleLimit = false;
var eRuleLimit = false;
var RuleLimits = false;
var RuleYearOnly = false;
var sRuleYear = 0;
var sRuleMonth = 0;
var sRuleDay = 0;
var sRuleDayOfWeek = 0;
var eRuleYear = 0;
var eRuleMonth = 0;
var eRuleDay = 0;
var eRuleDayOfWeek = 0;
var rIndex = 0;
var aflag;
var oflag;
var tGeographyID = 0;
var tOfficeID = 0;
var tpoid = "";
var taflag = 1;
var toflag = 1;
var trates = 0;
var rates = 0;	//0 = default(min, max imputs, 1 = min=max text imput, 2= drop down range select
var tucal = null;
var ucal = null;
var C1 = "";
var C2 = "";
var C3 = "";
var C4 = "";
var C5 = "";
var C6 = "";
var C7 = "";
var C8 = "";
var C9 = "";
var C10 = "";
var C11 = "";
var C12 = "";
var C13 = "";	
var C14 = "";

//
// * OfficeSetting(office_id, ucal) ******************* ucal is optional param to override UseCalendar setting
//
function OfficeSettings(oid, ucal)
{
	switch (oid)
	{
		case 1465:
			color_0 = "#024a8f";
			color_1 = "#244b76";
			color_2 = "#b6cfe9";
			color_3 = "#e0ebf6";
			color_4 = "#013464";
			color_5 = "#eeeeee";
			color_6 = "#333333";
			color_7 = "#ffe84d";
			color_8 = "#ffffff";
			color_9 = "#cccccc";
			color_10 = "#a5c7de";
			color_11 = "#28611d";
			color_12 = "#fdffef";
			color_13 = "#660000";
			color_14 = "#000000";
			body = " link=\"" + color_11 + "\" alink=\"" + color_11 + "\" vlink=\"" + color_11 + "\" bgcolor=\"" + color_12 + "\"";
			if (AltDefinition == 1)
			{
				RuleArray[0][0] = 3;
				RuleArray[0][1] = 2;
				RuleArray[0][2] = -1;
				RuleArray[0][3] = "Apr/May/June: 2 Day";
				RuleArray[0][4] = 1;
				RuleArray[0][5] = 1;
				RuleArray[0][6] = 3;
				RuleArray[0][7] = 12;
				RuleArray[0][8] = 2007;
				RuleArray[0][9] = 5;
				RuleArray[0][10] = 24;
				RuleArray[0][11] = 2007;
				RuleArray[0][12] = 1;
				RuleArray[0][13] = 0;
				RuleArray[0][14] = "Availability Search";
				RuleArray[0][15] = 1;
				RuleArray[1][0] = 0;
				RuleArray[1][1] = 3;
				RuleArray[1][2] = -1;
				RuleArray[1][3] = "Apr/May/June: 3 Day";
				RuleArray[1][4] = 1;
				RuleArray[1][5] = 1;
				RuleArray[1][6] = 3;
				RuleArray[1][7] = 12;
				RuleArray[1][8] = 2007;
				RuleArray[1][9] = 5;
				RuleArray[1][10] = 24;
				RuleArray[1][11] = 2007;
				RuleArray[1][12] = 1;
				RuleArray[1][13] = 0;
				RuleArray[1][15] = 1;
				RuleArray[2][0] = 1;
				RuleArray[2][1] = 4;
				RuleArray[2][2] = -1;
				RuleArray[2][3] = "Apr/May/June: 4 Day";
				RuleArray[2][4] = 1;
				RuleArray[2][5] = 1;
				RuleArray[2][6] = 3;
				RuleArray[2][7] = 12;
				RuleArray[2][8] = 2007;
				RuleArray[2][9] = 5;
				RuleArray[2][10] = 24;
				RuleArray[2][11] = 2007;
				RuleArray[2][12] = 1;
				RuleArray[2][13] = 0;
				RuleArray[2][15] = 1;
				rIndex = 0;
			}
			else
			{
				RuleArray[0][0] = 5;
				RuleArray[0][1] = 7;
				RuleArray[0][2] = 6;
				RuleArray[0][3] = "Summer Family Weekly";
				RuleArray[0][4] = 1;
				RuleArray[0][5] = 1;
				RuleArray[0][6] = 5;
				RuleArray[0][7] = 16;
				RuleArray[0][8] = 2007;
				RuleArray[0][9] = 8;
				RuleArray[0][10] = 1;
				RuleArray[0][11] = 2007;
				RuleArray[0][12] = 1;
				RuleArray[0][13] = 0;
				RuleArray[0][14] = "Availability Search";
				RuleArray[0][15] = -1;
				RuleArray[1][0] = "";
				RuleArray[1][1] = 2;
				RuleArray[1][2] = -1;
				RuleArray[1][3] = "Apr/May/June: 2 Day";
				RuleArray[1][4] = 1;
				RuleArray[1][5] = 1;
				RuleArray[1][6] = 3;
				RuleArray[1][7] = 12;
				RuleArray[1][8] = 2007;
				RuleArray[1][9] = 5;
				RuleArray[1][10] = 24;
				RuleArray[1][11] = 2007;
				RuleArray[1][12] = 1;
				RuleArray[1][13] = 0;
				RuleArray[1][15] = 1;
				RuleArray[2][0] = 1;
				RuleArray[2][1] = 3;
				RuleArray[2][2] = -1;
				RuleArray[2][3] = "Apr/May/June: 3 Day";
				RuleArray[2][4] = 1;
				RuleArray[2][5] = 1;
				RuleArray[2][6] = 3;
				RuleArray[2][7] = 12;
				RuleArray[2][8] = 2007;
				RuleArray[2][9] = 5;
				RuleArray[2][10] = 24;
				RuleArray[2][11] = 2007;
				RuleArray[2][12] = 1;
				RuleArray[2][13] = 0;
				RuleArray[2][15] = 1;
				RuleArray[3][0] = 0;
				RuleArray[3][1] = 4;
				RuleArray[3][2] = -1;
				RuleArray[3][3] = "Apr/May/June: 4 Day";
				RuleArray[3][4] = 1;
				RuleArray[3][5] = 1;
				RuleArray[3][6] = 3;
				RuleArray[3][7] = 12;
				RuleArray[3][8] = 2007;
				RuleArray[3][9] = 5;
				RuleArray[3][10] = 24;
				RuleArray[3][11] = 2007;
				RuleArray[3][12] = 1;
				RuleArray[3][13] = 0;
				RuleArray[3][15] = 1;
				RuleArray[4][0] = 0;
				RuleArray[4][1] = 2;
				RuleArray[4][2] = -1;
				RuleArray[4][3] = "Labor Day & September Rentals";
				RuleArray[4][4] = 1;
				RuleArray[4][5] = 1;
				RuleArray[4][6] = 8;
				RuleArray[4][7] = 1;
				RuleArray[4][8] = 2007;
				RuleArray[4][9] = 11;
				RuleArray[4][10] = 1;
				RuleArray[4][11] = 2007;
				RuleArray[4][12] = 1;
				RuleArray[4][13] = 0;
				RuleArray[4][15] = 0;
				rIndex = 0;
			}
			UseCalendar = false;
			break;
		default:
			color_0 = "#024a8f";
			color_1 = "#244b76";
			color_2 = "#b6cfe9";
			color_3 = "#e0ebf6";
			color_4 = "#013464";
			color_5 = "#eeeeee";
			color_6 = "#333333";
			color_7 = "#ffe84d";
			color_8 = "#ffffff";
			color_9 = "#cccccc";
			color_10 = "#a5c7de";
			color_11 = "#28611d";
			color_12 = "#fdffef";
			color_13 = "#660000";
			color_14 = "#000000";
			body = " link=\"" + color_13 + "\" alink=\"" + color_13 + "\" vlink=\"" + color_13 + "\" background=\"../images/sand3.jpg\""
			RuleArray[0][0] = 0;
			RuleArray[0][1] = 7;
			RuleArray[0][2] = 6;
			RuleArray[0][15] = -1;
			UseCalendar = true;
			rIndex = 0;
			break;
	}
	if (RuleArray[0][14] != "")
		FormTitle = RuleArray[0][14];
	if (ucal >= 0)
	{
		if (ucal == 0)
			UseCalendar = false
		else
			UseCalendar = true;
	}
	if (RuleArray[1][0] != "")
		UseLocation = true
	else
		UseLocation = false;
	qshlp = "font-family:verdana;font-size:10pt;color:" + color_1 + ";text-decoration:none";
	qshS0 = "font-family:verdana;font-size:10pt;color:" + color_1 + ";text-decoration:none";
	qshS1 = "font-family:verdana;font-size:8 pt;color:" + color_6 + ";text-decoration.none"
	qshR0 = "font-family:verdana;font-size:10pt;background-color:" + color_2 + ";color:" + color_1 + ";border-bottom:1px solid " + color_8 + ";text-decoration:none";
	qshR1 = "font-family:verdana;font-size:10pt;background-color:" + color_2 + ";color:" + color_1 + ";border-bottom:1px solid " + color_8 + ";font-weight:bold;text-decoration:none";
	qshM0 = "font-family:verdana;font-size:10pt;background-color:" + color_1 + ";color:" + color_2 + ";border-bottom:1px solid " + color_8 + ";text-decoration:none";
	qshM1 ="font-family:verdana;font-size:10pt;background-color:" + color_1 + ";color:" + color_2 + ";border-bottom:1px solid " + color_8 + ";font-weight:bold;text-decoration:none";
	qshC0 = "font-family:verdana;font-size:10pt;background-color:" + color_2 + ";color:" + color_12 + ";border-bottom:1px " + color_8 + ";text-decoration:none";
	qshC1 = "font-family:verdana;font-size:10pt;background-color:" + color_2 + ";color:" + color_12 + ";border-bottom:1px solid " + color_8 + ";font-weight:bold;text-decoration:none";
	qshCM0 = "font-family:verdana;font-size:10pt;background-color:" + color_1 + ";color:" + color_12 + ";border-bottom:1px solid " + color_8 + ";text-decoration:none";
	qshCM1 = "font-family:verdana;font-size:10pt;background-color:" + color_1 + ";color:" + color_12 + ";font-weight:bold;text-decoration:none";
	qshsb = "border-left:3px double " + color_9 + ";border-top:3px double " + color_9 + ";border-right:3px double " + color_6 + ";border-bottom:3px double " + color_6 + ";background-color:" + color_5 + ";color:" + color_11 + ";font-size:8pt";
	if (RuleArray[0][0] > 0)
	{
		MultiRule = true;
			RuleStr = RuleStr + "<tr><td style=\"" + qshS0 + "\" align=\"center\">Select the Rental Type</td></tr><tr><td style=\"" + qshS0 + "\" align=\"center\"><select style=\"" + qshS1 + "\"  name=\"rOption\" id=\"rOption\" value=\"\"onChange=\"ResetInitialDates()\"></select>";
		RuleStr = RuleStr + "</select></td></tr>"
	}	
	for (i = 1; i <= 13;i++)
		eval("if (C" + i.toString() + " != \"\") color_" + i.toString() + " = C" + i.toString());
}
//
// *** WriteStyles() ************************************
//
function WriteStyles()
{
	window.self.document.write("\
		<style>\
			.hnqs{\
				font-family:verdana;\
				font-size:8pt;\
				color:" + color_1 + ";\
				text-decoration:none;\
			}\
			.hnqs1{\
				font-family:verdana;\
				font-size:8pt;\
				color:" + color_11 + ";\
				text-decoration:none;\
			}\
			.hnqs2{\
				font-family:verdana;\
				text-aign:center;\
				font-size:10pt;\
				color:" + color_11 + ";\
				text-decoration:none;\
			}\
			.hnqs3{\
				font-family:verdana;\
				text-align:center;\
				padding-right:5px;\
				padding-left:5px;\
				font-size:8pt;\
				color:" + color_11 + ";\
				text-decoration:none;\
				border:1px solid " + color_11 + ";\
			}\
			.hnmn{\
				font-family:verdana;\
				font-size:8pt;\
				color:" + color_14 + ";\
			}\
			.norm{\
				font-family:verdana;\
				font-size:8pt;\
				color:" + color_6 + ";\
			}\
		</style>\
	");
}
	
//
// ***GetParms(args)
//
function GetParms(args)
{
	var nargs = args.length;
	var targs;
	var itemArray;
	var poidarray;
	var nindex;
	if (nargs > 0)
	{
		targs = parseInt(args[0]);
		
		if (targs == -1)//arg list ie. "arg1=val", "arg2=val"...
		{
		}
		else
		{
			tGeographyID = args[0];
			if (nargs > 1)
			{
				tOfficeID = args[1];
				if (nargs > 2)
				{
					tpoid = args[2];
					nindex = tpoid.indexOf('|');
					if (nindex != -1)
					{
						if (nindex == 0)
						{
							tpoid = "";
						}
						else
						{
							AltDefinition = 1;
							tpoid = tpoid.substr(0,nindex);
						}
					}
					if (nargs > 3)
					{
						taflag = args[3];
						if (nargs > 4)
						{
							toflag = args[4];
							if (nargs > 5)
							{
								tucal = args[5];
								if (nargs > 6)
								{
									trates = args[6];
								}	
							}
						}
					}
				}
			}
		}
		if (tucal == null)
			ucal = -1
		else
		{
			ucal = parseInt(tucal);
			if (ucal != 0)
				ucal = 1;
		}
		Geography_ID = parseInt(tGeographyID);
		Office_ID = parseInt(tOfficeID);
		poid = tpoid;
		aflag = (taflag == null) ? true : (parseInt(taflag) == 0) ? false : true;
		oflag = true;
		UseSmoking = (parseInt(toflag) & 1) == 1;
		UseBeds = (parseInt(toflag) & 2) == 2;
		UseAdults = (parseInt(toflag) & 4) == 4;
		UseKids = (parseInt(toflag) & 8) == 8;
		UseRates = (parseInt(toflag) & 16) == 16;
		UseCat = (parseInt(toflag) & 32) == 32;
		UseProp = (parseInt(toflag) & 64) == 64;
	}
	if (trates == null)
		rates = 0; //default
	else
		rates = parseInt(trates);
}

function Form_seDate()
{
	GetParms(arguments)
	OfficeSettings(Office_ID,ucal);
	WriteStyles();
	window.self.document.write("\
	<form name=\"QuickSearch\" id=\"QuickSearch\" action=\"\" method=\"\">\
	<input type=\"hidden\" name=\"GeographyID\" value=\"" + Geography_ID +"\">\
	<input type=\"hidden\" name=\"OfficeID\" value=\"" + Office_ID +"\">\
	<input type=\"hidden\" name=\"poid\" value=\"" + poid +"\">\
	<input type=\"hidden\" name=\"total_sleeps\">\
	<input type=\"hidden\" name=\"AS\" value=\"1\">\
	<input type=\"hidden\" name=\"start_date\">\
	<input type=\"hidden\" name=\"end_date\">\
	<input type=\"hidden\" name=\"Query1\" value=\"1\">\
	<input type=\"hidden\" name=\"noparams\" value=\"1\">\
	<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" bgcolor=\"" + color_12 + "\">");
	if (MultiRule)
	{
		if (RuleArray[2][0] == 1)
			window.self.document.write("\
			<tr><td class=\"hnqs2\" align=\"left\">" + FormTitle + "</td></tr>\
			<tr><td class=\"hnmn\" align=\"left\"><select class=\"hnmn\" name=\"rOption\" id=\"rOption\" value=\"\" onChange=\"ResetInitialDates()\"></select>");
		else
			window.self.document.write("\
			<tr><td class=\"hnqs\" align=\"left\">Select the Rental Type</td></tr>\
			<tr><td class=\"hnmn\" align=\"left\"><select class=\"hnmn\" name=\"rOption\" id=\"rOption\" value=\"\" onChange=\"ResetInitialDates()\"></select>");
	}
	window.self.document.write("\
	<tr><td class=\"hnqs\">Check-In Date</td></tr>\
	<tr><td class=\"hnmn\"><select class=\"hnmn\" name=\"sMonth\" id=\"sMonth\" value=\"\" onChange=\"ResetStartDate()\"></select>&nbsp;<select class=\"hnmn\" name=\"sDay\" id=\sDay\" value=\"\" onChange=\"ResetStartDate()\"></select>&nbsp;<select class=\"hnmn\" name=\"sYear\" id=\sYear\" value=\"\" onChange=\"ResetStartDate()\"></select>&nbsp;<input type=\"submit\" class=\"submitButton\" value=\"Search\" name=\"submit\" onClick=\"SendIt()\"></td></tr>\
	<tr><td class=\"hnmn\"<input type=\"hidden\" name=\"eMonth\" id=\"eMonth\" value=\"\">&nbsp;<input type=\"hidden\" name=\"eDay\" id=\eDay\" value=\"\">&nbsp;<input type=\"hidden\" name=\"eYear\" id=\"eYear\" value=\"\">");
	//window.self.document.write("<input type=\"hidden\" name=\"flexdates\" id=\"flexdates\" value=\"1\">");
	window.self.document.write("</td></tr>");
	window.self.document.write("<tr><td class=\"hnqs\"><input type=\"checkbox\" name=\"flexdates\" id=\"flexdates\">My dates are flexible.</td></tr>");
	window.self.document.write("<tr><td colspan=\"2\" class=\"hnqs\"><br><u>*OR*</u> find this Property ID<br><br><input type=\"text\" name=\"pid\" value=\"\">&nbsp;<input type=\"button\" class=\"submitButton\" value=\"View\" onClick=\"ViewThis()\"></td></tr>");
	window.self.document.write("</table></form><br>");
	window.self.document.close();
	rIndex = 0;
	ResetInitialDates();
	fflag = false;
}

function SetRuleDateLimits(rIndex)
{
	var tsRuleLimit = RuleArray[rIndex][4];//enforce start rule 0, 1 - no, yes
	var teRuleLimit = RuleArray[rIndex][5];//enforce rule end date 0, 1 - no, yes
	var tsYear = RuleArray[rIndex][8];//rule start date year
	var tsMonth = RuleArray[rIndex][6];//rule start date month
	var tsDay = RuleArray[rIndex][7];//rule start date day
	var tsDayOfWeek = 0;//rule start day of week
	var teYear = RuleArray[rIndex][11];//rule end date year
	var teMonth = RuleArray[rIndex][9];//rule end date month
	var teDay = RuleArray[rIndex][10];//rule end date day
	var teDayOfWeek = 0;//rule end date day of week
	var tCurYearOnly = RuleArray[rIndex][12];//restrict rule to current year only 0, 1 - no, yes
	var tUseSpecificDates = RuleArray[rIndex][13]//use start and end dates as specific search stary start end date
	sRuleYear = tsYear;
	sRuleMonth = tsMonth;
	sRuleDay = tsDay;
	eRuleYear = teYear;
	eRuleMonth = teMonth;
	eRuleDay = teDay;
	vdays = RuleArray[rIndex][1];//number of days in rule stay period
	drule = RuleArray[rIndex][2];//number of day of week stay period applies 0 - 6, -1: sun - sa, any day
	if (tCurYearOnly > 0)
	{
		RuleYearOnly = true;
		CurYearOnly = true;
	}
	else
	{
		RuleYearOnly = false;
		CurYearOnly = false;
	}
	if (tUseSpecificDates > 0)
		UseSpecificDates = true
	else
		UseSpecificDates = false;
		
	if (tsRuleLimit > 0)
	{
		sRuleLimit = true;
		sRuleDate.setFullYear(tsYear,tsMonth,tsDay);
		sRuleDayOfWeek = sRuleDate.getDay();
	}
	if (teRuleLimit > 0)
	{
		eRuleLimit = true;
		eRuleDate.setFullYear(teYear,teMonth,teDay);
		eRuleDayOfWeek = eRuleDate.getDay();
	}
	RuleLimits = sRuleLimit || eRuleLimit;
	RuleStartDate = sRuleDate;
	RuleEndDate = eRuleDate;
}

function ResetInitialDates()
{
	// here we get selected rule,set date parameters according to the rule selected and build calendar dropdowns and calendar display
	var tIndex;
	if (rflag)
	{
		rIndex = 0;
		tIndex = rIndex;
	}
	else
	{
		fflag = true;
		tIndex = rIndex;
		rIndex = QuickSearch.rOption.selectedIndex;
		QuickSearch.rOption.options[tIndex].selected = false;
		QuickSearch.rOption.options[rIndex].selected = true;
		QuickSearch.rOption.selectedIndex = rIndex;
	}
	SetRuleDateLimits(rIndex);
	SetInitialDates();
	MakeSelects(ifssd);
}

function SetInitialDates()
{
	var tsRuleLimit = sRuleLimit;
	var teRuleLimit = eRuleLimit;
	var tsYear = sRuleYear;
	var tsMonth = sRuleMonth;
	var tsDay = sRuleDay;
	var tsDayOfWeek = sRuleDayOfWeek;
	var teYear = eRuleYear;
	var teMonth = eRuleMonth;
	var teDay = eRuleDay;
	var teDayOfWeek = eRuleDayOfWeek;
	var tRuleYearOnly = RuleYearOnly;
	CanSelectDates = true;
	RuleCount = RuleArray[0][0];
	CurDate = new Date();
	CurYear = CurDate.getFullYear();
	CurMonth = CurDate.getMonth();
	CurDay = CurDate.getDate();
	CurDayOfWeek = CurDate.getDay();
	DateLimit.setFullYear((CurYear + 3),11,31);
	var tfssd = new Date();
	if (sRuleLimit)
		ifssd = sRuleDate
	else
		ifssd = FirstValidStayStartDate(CurDate);
	if (eRuleLimit)
		ilssd = eRuleDate
	else
		ilssd = LastValidStayStartDate(DateLimit);
	if (CurDate > ifssd)
	{
		tfssd = NextValidStayStartDate(CurDate);
		if (tfssd <= ilssd)
			ifssd = tfssd
		else
		{
			ifssd = ilssd;
			CanSelectDates = false;
		}
	}
	ifsed = newDate(ifssd,vdays);
	ilsed = newDate(ilssd,vdays);
}

function FirstValidStayStartDate(tdate)
{
	var ndate = new Date();
	var tdow = tdate.getDay();
	if ((drule == -1) || (drule == tdow))
		ndate = tdate
	else
	{
		if (drule > tdow)
			ndate = newDate(tdate,(drule - tdow))
		else
			ndate = newDate(tdate,(7 - tdow + drule));
	}
	return ndate;
}

function NextValidStayStartDate(tdate)
{
	var ndate = new Date();
	var tdow = tdate.getDay();
	if (drule == tdow)
		ndate = newDate(tdate,7)
	else
	{
		if (drule == -1)
			ndate = newDate(tdate,1)
		else
		{
			if (drule > tdow)
				ndate = newDate(tdate,(drule - tdow))
			else
				ndate = newDate(tdate,(7 - tdow + drule));
		}
	}
	return ndate;
}

function LastValidStayStartDate(tdate)
{
	var ndate = new Date();
	var tdow = tdate.getDay();	
	var ntdate = new Date();
	var tntdate = new Date();
	tdow = tdate.getDay();
	if (drule == -1)//any day
		ndate = newDate(tdate,(0 - vdays))
	else
	{
		if (drule = tdow)
			ndate = newDate(tdate,-7)
		else
		{
			if (drule > tdow)
				ntdate = newDate(tdate,(0 - (7 - (drule - tdow))))
			else
				ntdate = newDate(tdate,(0 - (tdow - drule)));
			tntdate = newDate(ntdate,vdays);
			if (tntdata <= tdate)
				ndate = ntdate
			else
				ndate = newDate(ntdate,-7);
		}
	}
	return ndate;
}

function newDate(tdate,days)
{
	var tyear = tdate.getFullYear();
	var tmonth = tdate.getMonth();
	var tday = tdate.getDate();
	var nday;
	var nmonth = tmonth;
	var nyear = tyear;
	var tDaysInMonth = DaysInMonth(tmonth,tyear);
	var mflag = false;
	var rdate;
	if (days >= 0)
	{
		if (tday + days > tDaysInMonth)
		{
			nday = days - (tDaysInMonth - tday);
			mflag = true;
		}
		else
		{
			nday = tday + days;
		}
		if (mflag)
		{
			if (tmonth == 11)
			{
				nmonth = 0;
				nyear = tyear + 1;
			}
			else
			{
				nmonth = nmonth + 1;
			}
		}
	}
	else
	{
		if ((tday + days) < 1)
		{
			mflag = true
		}
		else
		{
			nday = tday + days;
		}
		if (mflag)
		{
			if (tmonth == 0)
			{
				tmonth = 11;
				tyear = tyear - 1;
			}
			else
			{
				tmonth = tmonth - 1;
			}
			tDaysInMonth = DaysInMonth(tmonth,tyear);
			nday = tDaysInMonth + days + 1;	
		}
	}
	rdate = new Date(nyear,nmonth,nday);
	return rdate;
}

function DaysInMonth(iMonth,iYear)
{
	var tdays;
	if ((iMonth == 8) || (iMonth == 3) || (iMonth == 5) || (iMonth == 10))
		tdays = 30
	else
	{
		if (iMonth == 1)
		{
			if (isLeapYear(iYear))
				tdays = 29
			else
				tdays = 28;
		}
		else
			tdays = 31;
	}
	return tdays;
}

function MakeSelects(tStartDate)
{
	//initial build start with current date use rule set
	//default anydate for any month
	//1 saturday
	if (fflag)
	{
		//we have StartDate and EndDate now build Select Menus 0 for StartDate, 1 for EndDate
		if (MultiRule && rflag)
		{
			BuildRuleSelect();
			rflag = false;
		}
		BuildDateSelect(tStartDate,0);
	}
}

function ResetStartDate()
{
	//a change has been made on start date menus redefine StartDate and EndDate
	var tsYear = QuickSearch.sYear[QuickSearch.sYear.selectedIndex].value;
	var tsMonth = QuickSearch.sMonth[QuickSearch.sMonth.selectedIndex].value;
	var tsDay = QuickSearch.sDay[QuickSearch.sDay.selectedIndex].value;
	var tDay = 1;
	var teDay;
	var tsDate = new Date();
	var teDate = new Date();
	var rFlag = false;
	var tdow;
	var teDay;
	var tDate = new Date();
	var ttDate = new Date();
	var tsDate = new Date();
	var teDate = new Date();
	var rFlag = false;
	tDate.setFullYear(tsYear,tsMonth,tsDay);
	if (tDate < ifssd)
		tDate = ifssd
	else
		if (tDate > ilssd)
			tDate = ilssd;
	tdow = tDate.getDay();
	if ((drule != -1) && (drule != tdow)) // need to adjust start day to a valid day, we move upwards toward ilssd
	{
		ttDate = newDate(tDate,(tDate.getDate() + (drule - tdow) + vdays));
		if (ttDate > ilssd)
			tDate = ilssd
		else
			tDate = ttDate;
	}
	tsYear = tDate.getFullYear();
	tsMonth = tDate.getMonth();
	tsDay = tDate.getDate();
	ResetCurDate();//make sure we have currect real date and real current start date for current date
	// get select year, month, day
	// set tsday = 1 for 1st of the month
	tsDate.setFullYear(tsYear,tsMonth,tsDay);
	//get first legitimate start day for this new date
	//tsDay = FirstStartDayInMonth(tsDate);
	//get last legitimate start date for this new date
	BuildDateSelect(tsDate,0);
}

function isLeapYear(year)
{
	//1. Years divisible by four are leap years, unless...
	//2. Years also divisible by 100 are not leap years, except...
	//3. Years divisible by 400 are leap years.
	var leapFlag = false;
	if (year % 4 == 0)
	{
		if (year % 100 != 0)
			leapFlag = true
		else
		{
			if (year % 400 == 0)
				leapFlag = true
			else
				leapFlag = false;
		}
	}
	else
		leapFlag = false;
	if (leapFlag && (year % 4000 == 0))
		leapFlag = false;
	return leapFlag;
}


function BuildRuleSelect()
{
	var item;
	QuickSearch.rOption.options.length = 0;
	for (i = 0; i < RuleCount;i++)
	{
		item = new Option;
		item.color = color_14
		item.value = i;
		item.text = RuleArray[i][3];					
		QuickSearch.rOption.options[QuickSearch.rOption.options.length] = item;
		if (i == rIndex)
			QuickSearch.rOption.options[i].selected = true;
	}
}

function ResetCurDate()
{
	var tDate = new Date();
	var tsDate
	var tYear = tDate.getFullYear();
	var tMonth = tDate.getMonth();
	var tDay = tDate.getDate();
	var tDayOfWeek = tDate.getDay();
	CurYear = tYear;
	CurMonth = tMonth;
	CurDay = tDay;
	CurDayOfWeek = tDayOfWeek;
	CurDate.setFullYear(CurYear,CurMonth,CurDay);
}

function BuildDateSelect(tdate, calSelect)
{
	// BuildDateSelect creates drop down date selections month, day, year according to date passed and the type of select menu (0 = stay START, 1 = stay END)
	// if StayStart select the date range is InitFirstStayStartDate (ifssd) - InitLastStayStartDate (ilssd) and Selected date is passed date (tdate) 
	// if StayEnd select the date range is InitFirstStayEndDate (ifsed) - InitLastStayEndDate (ilsed) and Selected date is passed date (tdate)
	// if CanSelectDates is false then the calendars are disabled a blank option is is displayed with a -1 return value which will mean ignore change request
	//
	// rebuilding select menus depends on whether the change is by A: change in select menu, B change in calendar. Then was the change due to select or view:
	// we will assume rule. day is selected otherwise it is a view change. the only item marked selected is according to the Selected Date Or in the case of 
	// Not CanSelectDates, the blank option which is ignored
	//
	// the selects are build according to what the current StartDate or EndDate is
	var tYear = tdate.getFullYear();//year passed
	var tMonth = tdate.getMonth();//month passes
	var tDaysInMonth = DaysInMonth(tMonth,tYear);//number of days in passed month
	var tDay = tdate.getDate();//day of month passed
	var toption;
	var tYearLimit = DateLimit.getFullYear();
	var tMonthLimit = 11;
	var tDayLimit = tDaysInMonth;
	var tmpDate = new Date();
	var tmpYear;
	var tmpMonth = 0;
	var tIndex = 0;
	var tsDay = 0;
	var tDayOffset = 7;
	var tmpSYear;
	var tmpEYear;
	var tmpSMonth = 0;
	var tmpEMonth = 11;
	var tmpSDay = 1;
	var tmpEDay = 31;
	if (drule == -1)
		tDayOffset = 1;
	//year select
	QuickSearch.sYear.options.length = 0
	if (CanSelectDates)
	{
		if (calSelect == 0)
		{
			tmpSYear = ifssd.getFullYear();
			tmpEYear = ilssd.getFullYear();
		}
		else
		{
			tmpSYear = ifsed.getFullYear();
			tmpEYear = ilsed.getFullYear();
		}
		for (i = 0;(tmpSYear + i) <= tmpEYear;i++)
		{
			toption = new Option();
			toption.value = tmpSYear + i;
			toption.text = (tmpSYear + i).toString();
			QuickSearch.sYear.options[QuickSearch.sYear.options.length] = toption
			if ((tmpSYear + i) == tYear)
			{
				QuickSearch.sYear.selectedIndex = i;
				QuickSearch.sYear.options[i].selected = true;
			}
		}
	}
	else
	{
		toption = new Option();
		toption.value = -1;
		toption.text = "";
		QuickSearch.sYear.options[QuickSearch.sYear.options.length] = toption;
		QuickSearch.sYear.selectedIndex = 0;
		QuickSearch.sYear.options[0].selected = true;
	}
	//month select
	QuickSearch.sMonth.options.length = 0
	if (CanSelectDates)
	{
		if (tYear == ifssd.getFullYear())
		{
			tmpSMonth = ifssd.getMonth();
			if (tYear == ilssd.getFullYear())
				tmpEMonth = ilssd.getMonth()
			else
				tmpEMonth = 11;
		}
		else
		{
			if (tYear == ilssd.getFullYear())
			{
				if (ifssd.getFullYear() == ilssd.getFullYear())
					tmpSMonth = ifssd.getMonth()
				else
					tmpSMonth = 0;
				tmpEMonth = ilssd.getMonth();
			}
			else
			{
				tmpSMonth = 0;
				tmpEMonth = 11;
			}
		}
		for (i = tmpSMonth; i <= tmpEMonth; i++)
		{
			toption = new Option();
			toption.value = i;
			toption.text = Months_Short[i];
			QuickSearch.sMonth.options[QuickSearch.sMonth.options.length] = toption;
			if (i == tMonth)
			{
				QuickSearch.sMonth.options[(QuickSearch.sMonth.options.length - 1)].selected = true;
				QuickSearch.sMonth.selectedIndex = (QuickSearch.sMonth.options.length - 1);
			}
		}
	}
	else
	{
		toption = new Option();
		toption.value = -1;
		toption.text = "";
		QuickSearch.sMonth.options[QuickSearch.sMonth.options.length] = toption;
		QuickSearch.SMonth.selectedIndex = 0;
		QuickSearch.sMonth.options[0].selected = true;
	}
	//day select
	QuickSearch.sDay.options.length = 0
	if (CanSelectDates)
	{
		tmpSDay = FirstStartDayInMonth(tdate)
		tmpEDay = LastStartDayInMonth(tdate)
		for (i = tmpSDay; i <= tmpEDay; i = i + tDayOffset)
		{
			toption = new Option;
			toption.value = i;
			toption.text = i.toString();
			QuickSearch.sDay.options[QuickSearch.sDay.options.length] = toption;
			if (i == tDay)
			{
				QuickSearch.sDay.options[(QuickSearch.sDay.options.length - 1)].selected = true;
				QuickSearch.sDay.selectedIndex = (QuickSearch.sDay.options.length - 1);
			}
		}
	}
	else
	{
		toption = new Option();
		toption.value = -1;
		toption.text = "";
		QuickSearch.sDay.options[QuickSearch.sMonth.options.length] = toption;
		QuickSearch.SDay.selectedIndex = 0;
		QuickSearch.sDay.options[0].selected = true;
	}
}

function FirstStartDayInMonth(tdate)
{
	var ndate = new Date();
	ndate.setFullYear(tdate.getFullYear(),tdate.getMonth(),1);
	var tday;
	var tdow = ndate.getDay();
	if ((tdate.getFullYear() == ifssd.getFullYear()) && (tdate.getMonth() == ifssd.getMonth()))
		tday = ifssd.getDate()
	else
	{
		if ((drule == -1) || (drule == tdow))
			tday = 1
		else
		{
			if (drule > tdow)
				tday = 1 + (drule - tdow)
			else
				tday = 1 + (7 - (tdow - drule));
		}
	}
	return tday;
}

function LastStartDayInMonth(tdate)
{
	var ndate = new Date();
	var ntdate = new Date();
	var tday;
	var tdow;
	var tdays = DaysInMonth(tdate.getMonth(),tdate.getFullYear());
	ndate.setFullYear(tdate.getFullYear(),tdate.getMonth(),tdays);
	tdow = ndate.getDay();
	if ((drule == -1) || (drule == tdow))
		tday = tdays
	else
	{
		if (drule > tdow)
			tday = tdays - (7 - (drule - tdow))
		else
			tday = tdays - (tdow - drule);
	}
	return tday;
}

function ViewThis()
{
	document.location.href="http://realtimerental.com/rrv10/visitor/pview_new.asp?poid="+poid+"&GeographyID="+Geography_ID+"&pid="+QuickSearch.pid.value;
}

function SendIt()
{
	var tsYear = parseInt(QuickSearch.sYear[QuickSearch.sYear.selectedIndex].value);
	var tsMonth = parseInt(QuickSearch.sMonth[QuickSearch.sMonth.selectedIndex].value);
	var tsDay = parseInt(QuickSearch.sDay[QuickSearch.sDay.selectedIndex].value);
	var tsDate = new Date();
	tsDate.setFullYear(tsYear,tsMonth,tsDay);
	tsMonth = tsMonth + 1;
	var teDate = newDate(tsDate,vdays);
	var teYear = teDate.getFullYear();
	var teMonth = teDate.getMonth() + 1;
	var teDay = teDate.getDate();
	QuickSearch.action = qsAction;
	QuickSearch.method = qsMethod;
	QuickSearch.start_date.value = tsMonth.toString() + "/" + tsDay.toString() + "/" + tsYear.toString();
	QuickSearch.end_date.value = teMonth.toString() + "/" + teDay.toString() + "/" + teYear.toString();
	//alert(QuickSearch.start_date.value + " " + QuickSearch.end_date.value);
	return true;
}
