
	/*
		This function determines if the Check Rates & Availability module should be displayed
		author: cstat481
	*/
	function checkToDisplayForm()
	{
		var bookable = 'true';
		
		if(bookable == 'true')
		{
			return 'true';
		}
		else 
		{
			return 'false';
		}
	}
	/*
		This function determines if values were passed in the cookie
		and then reads the present values for corporateCode and groupCode
		author: cstat481
	*/
	function checkCookieValues()
	{
		
		var nameEQ = "FormInfoCookie";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++)
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			{
				if (c.indexOf(nameEQ) == 0)
				{
							
					var cookieValue = c.substring(0,c.length);
					var values = cookieValue.split("|");
					cookieValues = true;
									
					var clusterCodeCookie = values[5];
					if(clusterCodeCookie != 'null' && clusterCodeCookie != '')
					{
						corporateCode = clusterCodeCookie;
					}				
					
					var groupCodeCookie = values[6];
					if(groupCodeCookie != 'null' && groupCodeCookie != '')
					{
						groupCode = groupCodeCookie;
					}
	
				}
			}
	
		}
		return null;
	
	}

	/*
		This function sets cookie values when the find button is pressed
		author: 
	*/
	function saveDataInCookieAndValidate(myForm, vsObjectMap)
	{
		setVDataCookieFromFormNoSubmit(myForm, vsObjectMap);
		var submit = validate();
		if(submit)
		{
		return true;
		}
		else
		{
		return false;
		}
	}
	
	/*
		This function validates form submittal
		author: 
	*/
	function validate()
	{
		var pageId = '';
		var pageIdSpecials = '';
		
		var objForm = document.fullRatesCalloutForm;
		var corporateCode = objForm.corporateCode.value;
		var groupCode = objForm.groupCode.value;
		var clusterCode = objForm.clusterCode;
		var submit = false;
		
		var objClusterSell = objForm.clusterSell;
		objClusterSell.value = false;
	
		if(document.fullRatesCalloutForm.corporateCode.value != null)
		{
			document.fullRatesCalloutForm.corporateCode.value 
				= document.fullRatesCalloutForm.corporateCode.value.toUpperCase();
		}
	
		if (clusterCode != null && clusterCode.checked != null && clusterCode.checked == true)
		{
			objClusterSell.value = true;
		}
		if(corporateCode.value != null) 
		{
			objClusterSell.value = true;
		}
	
		submit = validateMRNumForCorpCode();
	
		if(submit)
		{
	
			if(clusterCode != null &&
				clusterCode.checked == true)
			{
				corporateCode = "";
				groupCode = "";
			}

			
			if (pageId != pageIdSpecials)
			{
				submit = validateForm();
			}
			else
			{
				var offerStartDate = '';
				var offerEndDate = '';
				var rewardsOffers = '';
				var subCat = '';
	
				if(validateForm() == true)
				{
					submit =  ValidateOfferDates(offerStartDate, offerEndDate, rewardsOffers, subCat);
				}
			}
		}
		return submit;
	}

	/*
		This function validates the entered Rewards Number for the entered corporateCode
		author: 
	*/
	function validateMRNumForCorpCode()
	{
		var submit = true;	
	
		if(document.fullRatesCalloutForm.corporateCode != null &&
			(document.fullRatesCalloutForm.corporateCode.value == 'M11' || document.fullRatesCalloutForm.corporateCode.value == 'm11'))
		{
			if(document.fullRatesCalloutForm.marriottRewardsNumber == null || document.fullRatesCalloutForm.marriottRewardsNumber.value == '')
			{
				alert("Please enter a Marriott Rewards Number");
				document.fullRatesCalloutForm.marriottRewardsNumber.focus();
				var submit = false;
			}
		}
		return submit;
	}
			
	/*
		This function validates the check in and check out dates before submittal
		author: 
	*/
	function ValidateStayDates()
	{
	
		if (!IsValidDateString(document.fullRatesCalloutForm.elements['checkInDate'].value))
		{
			alert("Check In Date is not valid.");
			return false;
		}
	
		if (!IsValidDateString(document.fullRatesCalloutForm.elements['checkOutDate'].value))
		{
			alert("Check Out Date is not valid.");
			return false;
		}
	
		if (!IsDateAfter(document.fullRatesCalloutForm.elements['checkInDate'].value, document.fullRatesCalloutForm.elements['checkOutDate'].value))
		{
			alert("Check Out Date must be a date after the Check In Date.  Please verify your selection criteria.");
			return false;
		}
	
		var curDate = new Date()
		var curMonth = curDate.getMonth() + 1;
		var curDay = curDate.getDate() - 1;
	
		var formattedDate = curMonth + "/" + curDay + "/" + curDate.getFullYear()
	
		if (!IsDateAfter(formattedDate, document.fullRatesCalloutForm.elements['checkInDate'].value)) 
		{
			alert("Check In Date occurs in the past.");
			return false;
		}
	
		var kDate = new Date();
		// add 357 days to current day and substarct current week day from it.
		kDate.setTime(curDate.getTime() + (357 * 86400000) - ((curDate.getDay()) * 86400000));
	
		var ciDate = new Date(document.fullRatesCalloutForm.elements['checkInDate'].value);
		var coDate = new Date(document.fullRatesCalloutForm.elements['checkOutDate'].value);
	
		if (ciDate.getTime() >=  kDate.getTime() ||coDate.getTime() > kDate.getTime() ) 
		{
			alert("Dates occur beyond inventory period.");
			return false;
		}
			
		return true;
	}

	/*
		This function determines the query string values for Enrich Group
		author: cstat481
	*/
	function getQueryStringValues()
	{
		var qString = document.location.search;
		var corporateString = "corporateCode=";
		var groupString = "groupCode=";
		var clusterString = "clusterCode=";
		
		
		var corporateLocale = qString.indexOf(corporateString);

		if (corporateLocale > 0)
		{
			corporateCode = qString.substring(corporateLocale + corporateString.length,corporateLocale + corporateString.length + 3);
			qsValues = true;
		}
		
		// IPMI00024270
		// If both corporate code and cluster code are present in the query string, corporate code takes precedence.  So check if 
		// corporatecode is not empty and then map the querystring value of clustercode to corporatecode.
		if (corporateCode == null || corporateCode =='' || corporateCode.length <= 0)
		{
			var clusterLocale = qString.indexOf(clusterString);
			if (clusterLocale > 0)
			{
				corporateCode = qString.substring(clusterLocale + clusterString.length,clusterLocale + clusterString.length + 3);
				qsValues = true;
			}
		}

		var groupLocale = qString.indexOf(groupString);

		if (groupLocale > 0)
		{
			groupCode = qString.substring(groupLocale + groupString.length, groupLocale + groupString.length + 7);
			qsValues = true;
		}
	}

	/*
		This function determines if the link is coming from ResLink in group tools
		author: cstat481 - not used, maybe later
	*/
	function checkEnrichQueryString()
	{
		var qString = document.location.search;
		
		var resLink = qString.indexOf("app=resvlink");

		if (resLink > 0)
		{
			return true;		
		}

	}

	/*
		This function creates the EnrichCookie
		author: cstat481
	*/
	function writeEnrichCookie(corporateCode, groupCode)
	{

		var name = "EnrichCookie";
		var fullRatesObject = document.fullRatesCalloutForm;
		var value = "|" + corporateCode + "|" + groupCode + "|";	
		document.cookie = name + '=' + value + '; path=/';
	}

	/*
		This function determines if values were passed in the cookie
		and then reads the present values for corporateCode and groupCode
		author: cstat481
	*/
	function checkEnrichCookieValues()
	{
		
		var nameEQ = "EnrichCookie";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++)
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			{
				if (c.indexOf(nameEQ) == 0)
				{
							
					var cookieValue = c.substring(0,c.length);
					var values = cookieValue.split("|");
					cookieValues = true;
									
					var clusterCodeCookie = values[1];
					if(clusterCodeCookie != 'null' && clusterCodeCookie != '')
					{
						corporateCode = clusterCodeCookie;
					}				
					
					var groupCodeCookie = values[2];
					if(groupCodeCookie != 'null' && groupCodeCookie != '')
					{
						groupCode = groupCodeCookie;
					}
	
				}
			}
	
		}
		return null;
	}


	if (checkToDisplayForm() == 'true'){

		var corporateCodeQS = '';
		var groupCodeQS = '';		
		var vsObjectMap = {};
		vsObjectMap["checkInDateMonth"] = new vsObject("name", "value", "", "", "");
		vsObjectMap["checkInDateDay"] = new vsObject("name", "value", "", "", "");
		vsObjectMap["checkInDate"] = new vsObject("name", "value", "", "", "");
		vsObjectMap["numberOfGuests"] = new vsObject("name", "value", "", "", "");
		vsObjectMap["roomCount"] = new vsObject("name", "value", "", "", "");
		vsObjectMap["marriottRewardsNumber"] = new vsObject("name", "value", "", "", "");
		vsObjectMap["corporateCode"] = new vsObject("name", "value", "", "", "");
		vsObjectMap["groupCode"] = new vsObject("name", "value", "", "", "");

		//Set variables
		var groupCode = '';
		var corporateCode = '';
		var cookieValues = false;
		var qsValues = false;
			
		getQueryStringValues();

		if (qsValues)
		{
			writeEnrichCookie(corporateCode, groupCode);
		}
		
		if (!qsValues)
		{
			checkCookieValues();
			if (!cookieValues)
			{
				checkEnrichCookieValues();
			}
		}


function DoAllThese() {
return saveDataInCookieAndValidate(this.form, vsObjectMap); 
firstTracker._trackPageview('/reservations/marriott_com');
secondTracker._trackPageview('/reservations/marriott_com ');
}

document.write('<form method="get" name="fullRatesCalloutForm" action="http://marriott.com/reservation/availabilitySearch.mi" target="_blank" Style="margin-top:2px; margin-bottpm:-5px;" onsubmit="return validate();">');
document.write('<input type="hidden" name="clusterSell" value="false"/>');
document.write('<input type="hidden" name="propertyCode" value="YYJMC">');
document.write('<input type="hidden" name="isSearch" value="false" />');
document.write('<input type="hidden" name="WT_Ref" value="SrchMod_P" />');
document.write('<input type="hidden" name="numberOfNights" value="1" />');
document.write('<input type="hidden" name="groupCode" value="">');
document.write('<input type="hidden" name="marriottRewardsNumber" value="">');
document.write('<input type="hidden" name="corporateCode" value="">');
document.write('<table width="155" border="0" cellpadding="0" cellspacing="0"><tr><td colspan="3" align="left" style="padding:1px;">');
document.write('<span> Check-in date</span></td></tr><tr><td width="18" align="center" valign="middle"><a href="javascript:viewPopupCalendar(document.forms[&#39fullRatesCalloutForm&#39].elements[&#39checkInDate&#39], &#39checkOutDate&#39);"><input type="hidden" id="check_in_date" name="check_in_date"><img src="http://www.marriottvictoria.com/images/calendar.gif" alt="Calendar" name="check_in_trig" width="15"  hspace="0" vspace="0" border="0" id="check_in_trig" tabindex="1" /></a></td><td width="89" align="right" valign="middle">');
document.write('<select name="checkInDateMonth" id="restext" tabindex="2" onChange="SetFormDate(&#39checkInDate&#39)">');
<!--Check In Months: -->
document.write('<option value=""></option><option value="11/2010">Nov, 2010</option><option value="12/2010">Dec, 2010</option><option value="1/2011">Jan, 2011</option><option value="2/2011">Feb, 2011</option><option value="3/2011">Mar, 2011</option><option value="4/2011">Apr, 2011</option><option value="5/2011">May, 2011</option><option value="6/2011">Jun, 2011</option><option value="7/2011">Jul, 2011</option><option value="8/2011">Aug, 2011</option><option value="9/2011">Sep, 2010</option><option value="10/2011">Oct, 2011</option><option value="11/2011">Nov, 2011</option><option value="12/2011">Dec, 2011</option></select>');
document.write('<input type="hidden" name="checkInDate"/></td><td width="50" align="right" valign="middle">');
document.write('<select name="checkInDateDay" class="formContent" id="restext" tabindex="3" onChange="SetFormDate(&#39checkInDate&#39)">');
document.write('<option value=""></option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option></select></td></tr>');
document.write('<tr><td colspan="3" align="left" style="padding:1px;"><span>Check-out date</span>');
document.write('</td></tr><tr><td align="center" valign="middle"><a href="javascript:viewPopupCalendar(document.forms[&#39fullRatesCalloutForm&#39].elements[&#39checkOutDate&#39], &#39checkOutDate&#39);"><input type="hidden" id="check_out_date" name="check_out_date"><img src="http://www.marriottvictoria.com/images/calendar.gif" alt="Calendar" name="check_out_trig" width="15" hspace="0" vspace="0" border="0" id="check_out_trig" tabindex="4" /></a></td><td align="right" valign="middle">');
document.write('<select name="checkOutDateMonth2" id="checkOutDateMonth" tabindex="2" onchange="SetFormDate(&#39checkOutDate&#39)">');
<!--Check Out Months: -->
document.write('<option value=""></option><option value="11/2010">Nov, 2010</option><option value="12/2010">Dec, 2010</option><option value="1/2011">Jan, 2011</option><option value="2/2011">Feb, 2011</option><option value="3/2011">Mar, 2011</option><option value="4/2011">Apr, 2011</option><option value="5/2011">May, 2011</option><option value="6/2011">Jun, 2011</option><option value="7/2011">Jul, 2011</option><option value="8/2011">Aug, 2011</option><option value="9/2011">Sep, 2010</option><option value="10/2011">Oct, 2011</option><option value="11/2011">Nov, 2011</option><option value="12/2011">Dec, 2011</option></select>');
document.write('<input type="hidden" name="checkOutDate"/></td><td align="right" valign="middle">');
document.write('<select id="restext" name="checkOutDateDay" tabindex="3" onchange="SetFormDate(&#39checkOutDate&#39)" class="formContent">');
document.write('<option value=""></option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option></select></td></tr>');
<!--Rooms and Guests: -->
document.write('<tr><td colspan="3" class="reservation-box-text"><table width="155" border="0" cellpadding="0" cellspacing="0" style="margin-top:5px; margin-bottom:5px;">');
document.write('<tr><td width="36" class="textsmall">Rooms</td>');
document.write('<td width="40" align="right"><select name="numberOfRooms2" id="numberOfRooms2" tabindex="7"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select></td><td width="36"> Guests</td>');
document.write('<td width="43" align="right"><select name="numberOfGuests2" class="formContent" id="numberOfGuests2" tabindex="8"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option></select></td></tr></table></td></tr><tr><td colspan="3" align="center">');
document.write('<div align="center">');
<!--Button -->
document.write('<a href="javascript:document.fullRatesCalloutForm.submit();" onclick="DoAllThese()"><img src="http://www.marriottvictoria.com/images/checkrates2.gif" alt="Find" name="Find" width="146" height="18" hspace="0" vspace="5" border="0" tabindex="14" /></a>');
document.write('</div></td></tr></table></form>');
		
		Calendar.setup({
			inputField     :    "check_in_date",      // id of the input field
			ifFormat       :    "m/y-d",       // format of the input field
			button         :    "check_in_trig",   // trigger for the calendar (button ID)
			singleClick    :    true,            // double-click mode
			callback	   :	"set_date('check_in')",
			range		   :	[2010,2011]
		});
		Calendar.setup({
			inputField     :    "check_out_date",      // id of the input field
			ifFormat       :    "m/y-d",       // format of the input field
			button         :    "check_out_trig",   // trigger for the calendar (button ID)
			singleClick    :    true,            // double-click mode
			callback	   :	"set_date('check_out')",
			range		   :	[2010,2011]
		});

		var checkInDateValue = '';
		if(checkInDateValue == '')
		{
			initFormDates();
		}
		
		if(cookieValues == true)
		{
			readCookieJS();
		}
		
		loadFullRatesCalloutForm();
	}

	function set_date(type){
		form = document.fullRatesCalloutForm;
		if(type=='check_in'){
			temp = form.check_in_date.value.split("-");
			form.checkInDateMonth.value = temp[0];
			form.checkInDateDay.value = temp[1];
			temp1 = temp[0].split("/");
			checkoutday = new Date();
			checkoutday.setYear(temp1[1]);
			checkoutday.setMonth(temp1[0]-1);
			checkoutday.setDate(parseInt(temp[1])+1);
			form.checkOutDateMonth.value = (checkoutday.getMonth()+1)+'/'+checkoutday.getYear();
			form.checkOutDateDay.value = checkoutday.getDate();
		}else if(type=='check_out'){
			temp = form.check_out_date.value.split("-");
			form.checkOutDateMonth.value = temp[0];
			form.checkOutDateDay.value = temp[1];
		}
	}
	

