/*********************************************
<Author>
Landon Williams
2/16/04

<Description>
HTML document can call this file using meathod showResDesk() to display the Search Module on a site. The module will redirect the user with his information to the ICHotelsGroup main search site.
The showResDesk function recieves three variables, cityName, stateName, countryName.
		- cityName: The name of the city the user wan't to initaly be listen in the "City" form tag. Pass "" if no default is desired.
		- stateName: The two letter abbreviation of the State which the user would like the "State" drop down list to default to. Pass "" to default with no State listed.
		- countryName: The COUNTRY NAME -or- COUNTRY CODE which the user would like the "Country" drop down list to default to. Passing "" will default to the United States.
		- hotelCode: The 5 charater uniqute hotel idenfifier code.  (Leave null to display city/state/country search)
		- hotelName: The name of the hotel (Used to identify the Hotel Name used with hotelCode)  (Leave null to display city/state/country search)

<Dependenceies>
This file includes and requires for use two files.
  -- Main site Style Sheet: "http://images1.ichotelsgroup.com/css/6c_styles.css"
  -- Motified Static Site Calendar (Typically named cal2.js): "JSSearchCalendar.js"

<Other>
Much of this code is reproduced from either the existing static sites or ICHotelsGroup main website.
*********************************************/
var redirectVars=[["brandCode","6c"],["regionCode","1"],["localeCode","en"],["city",""],["state",""],["country",""],["searchGroupCodes","all"],["hotelCode",""],["hotelName",""],["rateCode",""],["IATAno",""],["corpNum",""],["GPC",""],["searchHI",""],["searchEX",""],["searchCP",""],["searchIC",""],["searchSB",""],["searchCW",""],["searchIN",""]]
for (var i=0; i<redirectVars.length ;i++ )
{
	var evalString='var '+redirectVars[i][0]+'="'+redirectVars[i][1]+'";';
	eval(evalString);
}

var st=["","AB","AK","AL","AR","AZ","BC","CA","CO","CT","DC","DE","FL","GA","HI","IA","ID","IL","IN","KS","KY","LA","MA","MB","MD","ME","MI","MN","MO","MS","MT","NB","NC","ND","NE","NF","NH","NJ","NM","NS","NV","NY","OH","OK","ON","OR","PA","PE","QC","RI","SC","SD","SK","TN","TX","UT","VA","VT","WA","WI","WV","WY"];

var b=[["0001","United States"],["0140","Andorra"],["0150","Argentina"],["0100","Aruba"],["0160","Australia"],["0165","Austria"],["0180","Bahamas"],["0181","Bahrain"],["0190","Belgium"],["0185","Bosnia & Herzegovina"],["0220","Brazil"],["0255","Cambodia"],["0260","Canada"],["0107","Caribbean"],["0268","Cayman Islands"],["0275","Chile"],["0280","China-Peoples Rep"],["0285","Colombia"],["0295","Costa Rica"],["0305","Cyprus"],["0311","Czech Republic"],["0320","Dominican Republic"],["0325","Ecuador"],["0922","Egypt"],["0330","El Salvador"],["0926","England"],["0327","Eritrea"],["0338","Fiji Islands"],["0340","Finland"],["0350","France"],["0367","French Polynesia"],["0388","Gabon"],["0394","Germany"],["0400","Greece"],["0066","Guam"],["0415","Guatemala"],["0430","Honduras"],["0435","Hong Kong"],["0445","Hungary"],["0455","India"],["0458","Indonesia"],["0470","Ireland"],["0475","Israel"],["0480","Italy"],["0487","Jamaica"],["0490","Japan"],["0500","Jordan"],["0525","Kazakhstan"],["0505","Kenya"],["0515","Korea-Republic Of"],["0520","Kuwait"],["0540","Lebanon"],["0532","Lithuania"],["0573","Macau"],["0574","Macedonia"],["0580","Malaysia"],["0590","Malta"],["0595","Mexico"],["0610","Morocco"],["0615","Mozambique"],["0625","Nepal"],["0630","Netherlands"],["0660","New Zealand"],["0665","Nicaragua"],["0616","Oman"],["0700","Pakistan"],["0710","Panama"],["0712","Papua New Guinea"],["0720","Peru"],["0725","Philippines"],["0730","Poland"],["0735","Portugal"],["0072","Puerto Rico"],["0747","Qatar"],["0755","Romania"],["0825","Russia"],["0785","Saudi Arabia"],["0760","Scotland"],["0795","Singapore"],["0796","Slovakia"],["0801","South Africa"],["0830","Spain"],["0272","Sri Lanka"],["0855","Switzerland"],["0281","Taiwan"],["0865","Tanzania"],["0875","Thailand"],["0887","Trinidad & Tobago"],["0890","Tunisia"],["0905","Turkey"],["0888","United Arab Emirates"],["0925","United Kingdom"],["0930","Uruguay"],["0001","United States"],["0078","US Virgin Islands"],["0931","Uzbekistan"],["0548","Vanuatu"],["0940","Venezuela"],["0950","Wales"],["0968","Yemen"],["0990","Zambia"],["0818","Zimbabwe"]];

//var w = document;
//w.r = w.write; 

function writeSelectNumbers(i){
	for(var x=1;x<i;x++)document.write("<option value="+x+">"+x+"</option>");
	document.close();
}

function writeStateId(stateName){
	for(var i=0;i<61;i++){
		if (st[i]==stateName)
			document.write("<option selected value="+st[i]+">"+st[i]+"</option>");
		else 
			document.write("<option value="+st[i]+">"+st[i]+"</option>");
	}
	document.close();
}

function writeCountryId(countryName){
	document.write("<select name=countryId class=f11>");
	for(var i=0;i<102;i++){
		if ((b[i][0]==countryName)||(b[i][1]==countryName))
			document.write("<option selected value="+b[i][0]+">"+b[i][1]+"</option>");
		else
			document.write("<option value="+b[i][0]+">"+b[i][1]+"</option>");
	}
	document.write("</select>");
	document.close();
}
function monthName(month_value){
	switch (month_value){
		case 0: return "January"
		case 1: return "Feburary"
		case 2: return "March"
		case 3: return "April"
		case 4: return "May"
		case 5: return "June"
		case 6: return "July"
		case 7: return "August"
		case 8: return "September"
		case 9: return "October"
		case 10: return "November"
		case 11: return "December"
	}
	document.close();
}

function writeMonthYear(){
var date_now = new Date()
var month_now = date_now.getMonth()
var year_now = date_now.getFullYear()
var temp_year
for(var i=month_now;i<month_now+12;i++){
	temp_year = year_now
	if(i>11)
	  temp_year = temp_year + 1
//	if (first_loop = 0) {
//		document.write("<option value="+(i%11)+temp_year+">"+monthName(i%11)+" "+temp_year+"</option>");
//		
//	}
//	else{
		document.write("<option value="+(i%12)+temp_year+">"+monthName(i%12)+" "+temp_year+"</option>");
//		}
	}
	document.close();
}

function populateCheckOut()
{
    var theForm = document.searchForm;
    if ((theForm.checkOutMonthYear.selectedIndex == 0)    ||
        (theForm.checkOutMonthYear.selectedIndex < theForm.checkInMonthYear.selectedIndex) ||
        ((theForm.checkOutMonthYear.selectedIndex == theForm.checkInMonthYear.selectedIndex) &&
         (theForm.checkOutDate.selectedIndex <= theForm.checkInDate.selectedIndex))) {
           if(theForm.checkInMonthYear.selectedIndex != 0) {
               if (theForm.checkInDate.selectedIndex > 29 ) {
                    theForm.checkOutDate.selectedIndex = 1;
                    theForm.checkOutMonthYear.selectedIndex = theForm.checkInMonthYear.selectedIndex + 1;
                }
                else if ((theForm.checkInDate.selectedIndex == 29 ) &&
                     ((theForm.checkInMonthYear.selectedIndex == 4) ||
                      (theForm.checkInMonthYear.selectedIndex == 6)  ||
                      (theForm.checkInMonthYear.selectedIndex == 9) ||
                      (theForm.checkInMonthYear.selectedIndex == 11))) {
                          theForm.checkOutDate.selectedIndex = 1;
                          theForm.checkOutMonthYear.selectedIndex = theForm.checkInMonthYear.selectedIndex + 1;
                }
                else {
                      theForm.checkOutDate.selectedIndex = theForm.checkInDate.selectedIndex + 1;
                      theForm.checkOutMonthYear.selectedIndex = theForm.checkInMonthYear.selectedIndex;
                }
            }
    }
}
//document.write('</script>');

//<script language="JavaScript">');                                                                             
var calendarSwap = 0; //set to 0 for checkIn, 1 for checkOut;');                                              
                                                                                                           
//This function will be called from cal2.js to set the defualt fields on this page.');                        
function setDateFields(){ 
	    var today = new Date();
        if (calendarSwap == 0){  //Check IN Date                                                                          
			var date = document.searchForm.firstinput.value ;                                              
			dateArray = date.split("/");                                                                 
			document.searchForm.checkInDate.selectedIndex = dateArray[1];                                 
                                                                                                           
   			index = 0;                                                                                     
   			for (i=2003;i<=dateArray[2];i++){ index = index + 1;}                                         
			if((dateArray[0]-1)<today.getMonth())
				document.searchForm.checkInMonthYear.selectedIndex = (12-today.getMonth()+1)+(dateArray[0]-1);
			else	 
				document.searchForm.checkInMonthYear.selectedIndex = (dateArray[0])-(today.getMonth());// + "" + (index +2002);
			if (document.searchForm.checkOutMonthYear.selectedIndex == 0)  {
				populateCheckOut();
			}
		}                                                                                                  
		else {        //Check OUT Date                                                                           
			var date = document.searchForm.firstinput.value ;                                       
			dateArray = date.split("/");                                                               
			document.searchForm.checkOutDate.selectedIndex = dateArray[1];                                 
                                                                                                        
   			index = 0;                                                                                 
   			for (i=2003;i<=dateArray[2];i++){ index = index + 1;}                                          
			if((dateArray[0]-1)<today.getMonth())
				document.searchForm.checkOutMonthYear.selectedIndex = (12-today.getMonth()+1)+(dateArray[0]-1);
			else
				document.searchForm.checkOutMonthYear.selectedIndex = (dateArray[0])-(today.getMonth());// + "" + (index +2002);
		}                                                                                                  
  	}    



function showResDesk(hotelCodePass,hotelNamePass,brandCodePass,IATAnoPass){

if(hotelCodePass!=null){hotelCode=hotelCodePass;}
if(hotelNamePass!=null){hotelName=hotelNamePass;}
if(brandCodePass!=null){brandCode=brandCodePass;}
if(IATAnoPass!=null){IATAno=IATAnoPass;}


document.write('<script language="JavaScript" type="text/javascript" src="http://images.ichotelsgroup.com/jsquickres/JSSearchCalendar.js"></script>');
document.write('<link rel="stylesheet" type="text/css" href="http://images1.ichotelsgroup.com/css/6c_styles.css">');


//document.write('<form action="http://www.ichotelsgroup.com/h/d/6c/1/en/asearch" name="searchForm" method="POST">');
document.write('<form action="http://www.ichotelsgroup.com/redirect" name="searchForm" method="POST">');
if (hotelCode!="")
{
	document.write('<INPUT type="hidden" name="path" value="asearch">');
}else
{
	document.write('<INPUT type="hidden" name="path" value="asearch">');
}
document.write('<INPUT type="hidden" name="regionCode" value="'+regionCode+'">');
document.write('<INPUT type="hidden" name="localeCode" value="'+localeCode+'">');
document.write('<INPUT type="hidden" name="brandCode" value="'+brandCode+'">');
document.write('<INPUT type=hidden name=firstinput>'); 


if ((searchHI!="")||(searchEX!="")||(searchCP!="")||(searchIC!="")||(searchSB!="")||(searchCW!="")||(searchIN!=""))
{   //User has set at least one individual brand to search..
	if (searchHI!="")document.write('<INPUT type="hidden" name="searchGroupCodes" value="HI">');
	if (searchEX!="")document.write('<INPUT type="hidden" name="searchGroupCodes" value="EX">');
	if (searchCP!="")document.write('<INPUT type="hidden" name="searchGroupCodes" value="CP">');
	if (searchIC!="")document.write('<INPUT type="hidden" name="searchGroupCodes" value="IC">');
	if (searchSB!="")document.write('<INPUT type="hidden" name="searchGroupCodes" value="SB">');
	if (searchCW!="")document.write('<INPUT type="hidden" name="searchGroupCodes" value="CW">');
	if (searchCW!="")document.write('<INPUT type="hidden" name="searchGroupCodes" value="IN">');
}
else //user wants to search all brands
{
	document.write('<INPUT type="hidden" name="searchGroupCodes" value="all">');
}


document.write('<table  width="540"  border="0" cellpadding="5" cellspacing="0" class="resBorder" bgcolor="#FFFFFF">');
document.write('	<tr>');
document.write('		<td class="cf14" colspan="3">Required Information</td>');
document.write('	</tr>');

if (hotelCode!="")
{
	city=null;state=null;country=null;
	document.write('    <input type="hidden" name="hotelCode" value="'+hotelCode+'">');
	document.write('	<tr align="left" class="f11" valign="bottom"> ');
	document.write('        <td class="f11" height="23"><b>Selected Hotel:</b></td>');
	document.write('        <td  class="f11"></td>');
	document.write('        <td  class="f11"></td>');
	document.write('    </tr>');
	document.write('	<tr align="left" class="f11" valign="top"> ');
	document.write('        <td class="f11" height="23">'+hotelName+'</td>');
	document.write('        <td  class="f11"></td>');
	document.write('        <td  class="f11"></td>');
	document.write('    </tr>');
}
else
{
	document.write('	<tr> ');
	document.write('		<td colspan="3" class="f12"><b>Destination:</b></td>');
	document.write('	</tr>');
	document.write('	<tr align="left" class="f11" valign="bottom"> ');
	document.write('        <td class="f11" height="23">City:</td>');
	document.write('        <td  class="f11">State/Province (US/Canada):</td>');
	document.write('        <td  class="f11">Country:</td>');
	document.write('    </tr>');
	document.write('	<tr>');
	document.write('		<td class="f11"><input type="text" name="city" value="'+city+'" maxlength="20" class="f11"></td>');
	document.write('		<td class="f11">');
	document.write('			<select name="stateId" class="f11">');
									writeStateId(state);
	document.write('			</select>');
	document.write('		</td>');
	document.write('		<td class="f11">');
									writeCountryId(country);
	document.write('		</td>');
	document.write('	</tr>');

}
document.write('    <tr>');
document.write('	</tr>');
document.write('	<tr> ');
document.write('		<td colspan="3" class="f12"><b>Travel Dates:</b></td>');
document.write('	</tr>	');
document.write('	<tr>');
document.write('		<td colspan="3">');
document.write('			<table  border="0" cellpadding="0" cellspacing="0">');
document.write('				<tr>');
document.write('					<td valign="top">');
document.write('						<table  border="0" cellpadding="0" cellspacing="0" >');
document.write('							<tr valign="bottom"> ');
document.write('								<td class="f11" align="left">Check-In Date:</td>');
document.write('							</tr>');
document.write('							<tr valign="top"> ');
document.write('								<td class="f11" align="left" nowrap>');
document.write('                         <select name="checkInDate" class="f11" onchange=\'javascript:populateCheckOut()\'>');
document.write('							<option value="-1" ></option>');
												writeSelectNumbers(32);
document.write('						  </select>');
document.write('');
document.write('                          <select name="checkInMonthYear" class="f11" onchange=\'javascript:populateCheckOut()\'>');
document.write('							<option value="-1" ></option>');
												writeMonthYear();
document.write('						  </select>');
document.write('								</td>');
document.write('								<td align=\'left\' valign=\'top\'>');
document.write('									<a href="javascript:calendarSwap=0; javascript:showCal(\'Calendar1\')"><img  src="http://images1.ichotelsgroup.com/cq/etc/media_library/common/1/en/calendar.Par.0001.Image.gif" alt="Calendar" name="Calendar" align="top" border="0"></a>');
document.write('								</td>');
document.write('								</td>');
document.write('							</tr>');
document.write('							<tr valign="bottom">');
document.write('				  			    <td class="f11" align="left">Check-Out Date:</td>');
document.write('							</tr>');
document.write('							<tr>');
document.write('								 <!-- The check out fields  -->');
document.write('								<td class="f11" valign=\'top\' align="left" nowrap>');
document.write('                          <select name="checkOutDate" class="f11" onchange=\'javascript:populateCheckOut()\'>');
document.write('							 <option value="-1" ></option>');
												writeSelectNumbers(32);
document.write('						  </select>');
document.write('                          <select name="checkOutMonthYear" class="f11" onchange=\'javascript:populateCheckOut()\'>');
document.write('                          	<option value="-1" ></option>');
												writeMonthYear();
document.write('						  </select>');
document.write('								</td>');
document.write('								<td align=\'left\' valign=\'top\'> ');                                     
document.write('									<a href="javascript:calendarSwap=1; javascript:showCal(\'Calendar1\')"><img  src="http://images1.ichotelsgroup.com/cq/etc/media_library/common/1/en/calendar.Par.0001.Image.gif" alt="Calendar" name="Calendar" align="top" border="0"></a>');
document.write('								</td>');
document.write('							</tr>');
document.write('						</table>');
document.write('					</td>');
document.write('					<td width="50">&nbsp;</td>');
document.write('					<td valign="top">');
document.write('						<table  border="0" cellpadding="0" cellspacing="0" >');
document.write('							<tr>');
document.write('							    <td class="f11" style="padding-left: 15px;">Adult(s)</td>');
document.write('							    <td class="f11" style="padding-left: 15px;">Child(ren)</td>');
document.write('								<td class="f11" style="padding-left: 15px;">Room(s)</td>');
document.write('							</tr>');
document.write('							<tr>');
document.write('								<td class="f11" style="padding-left: 15px;">');
document.write('								  <select name="numberOfAdults" class="f11">');
														writeSelectNumbers(21);
document.write('								  </select>	');
document.write('								</td>');
document.write('								<td class="f11" style="padding-left: 15px;">');
document.write('                                        <select name="numberOfChildren" class="f11">');
document.write('											<option value=0>0</option>');
															writeSelectNumbers(21);
document.write('                                        </select>');
document.write('								</td>');
document.write('								<td style="padding-left: 15px;">');
document.write('                                    <select name="numberOfRooms" class="f11">');
														writeSelectNumbers(10);
document.write('                                    </select>');
document.write('								</td>');
document.write('							</tr>');
document.write('						</table>');
document.write('					</td>');
document.write('				</tr>');
document.write('			</table>');
document.write('		</td>');
document.write('	</tr>');
document.write('</table>');
document.write('');
document.write('<br>');
document.write('');
document.write('<table cellpadding="0" cellspacing="0" border="0" width="540">');
document.write('	<tr>');
document.write('		<td align="center" width="540">');
document.write('			<table cellpadding="5" cellspacing="0" border="0" width="540" class="resBorder" bgcolor="#FFFFFF">');
document.write('				<tr>');
document.write('					<td class="cf14" colspan="2">Optional Information</td>');
document.write('				</tr>');
document.write('				<tr>');
document.write('					<td class="f12">');
document.write('                            <b>Room Preference:</b>');
document.write('                    </td>');
document.write('					<td class="f12">');
document.write('                            <b>Smoking Preference:</b>');
document.write('                    </td>');
document.write('				</tr>');
document.write('				<tr>');
document.write('					<td class="f11" valign="top">');
document.write('						<table cellpadding="0" cellspacing="0" border="0">');
document.write('							<tr>');
document.write('								<td valign="top">');
document.write('									<select name="roomTypePreference" class="f11">');
document.write('										<option value="3" selected>No Preference');
document.write('										<option value="1BD">One Bed</option>');
document.write('										<option value="2BD">Two Beds</option>');
document.write('										<option value="SUI">Suite</option>');
document.write('									</select>');
document.write('								</td>');
document.write('								<td valign="top>');
document.write('									<a href="#" onclick="window.open(\'http://www.ichotelsgroup.com/h/d/6c/1/en/c/3/dec/6c/1/en/rd/wa.html\',\'wa\',\'width=500,height=400,scrollbars=yes\'); return false;"><img  src="http://images1.ichotelsgroup.com/cq/etc/media_library/common/icons.Par.0003.Image.gif " alt="Wheelchair Accessible" height="25" width="24" border="0"></a><br>');
document.write('								</td>');
document.write('								<td valign="top">');
document.write('									<input name="wheelchairAccessible" value="true" type="checkbox">');
document.write('								</td>');
document.write('							</tr>');
document.write('						</table>');
document.write('					</td>');
document.write('					<td valign="top" >');
document.write('						<select name="smokingPreference" class="f11">');
document.write('							<option selected value="3">No Preference</option>');
document.write('							<option value="1">Non-Smoking</option>');
document.write('							<option value="2">Smoking</option>');
document.write('						</select>');
document.write('					</td>');
document.write('				</tr>');
if(rateCode=="")
	{
		document.write('		 		<tr> ');
		document.write('					<td class="f12" colspan="2"> ');
		document.write('						<b>Room Rate Selection      ');      
		document.write('						 <span style="font-size:11px;">');
		document.write('						 - AAA, AARP, Government and other available rate plans:   ');         
		document.write('						</span></b>');
		document.write('					</td>');
		document.write('				</tr>');
		document.write('				<tr>');
		document.write('					<td class="f11" colspan="2">');
		document.write('						<select class="f11" name="rateTypeCodes" >');
		document.write('							<option value="6CBARC">&#34;Best Available&#34;');
		document.write('							<OPTION VALUE="IDAAA" >AAA-CAA*</OPTION><BR><OPTION VALUE="IDARP" >AARP*</OPTION><BR><OPTION VALUE="IMCGV" >Canadian Govt*</OPTION><BR><OPTION VALUE="IDADC" >German Automobile Club*</OPTION><BR><OPTION VALUE="IMGOV" >Gov\'t-Military*</OPTION><BR><OPTION VALUE="IVANI" >Reward Nights*</OPTION><BR><OPTION VALUE="IMSTI" >State-Gov\'t Rate*</OPTION><BR>');
		document.write('						</select>');
		document.write('					</td>');
		document.write('				</tr>');
	}
else
	{
		document.write('<INPUT type="hidden" name="rateTypeCodes" value="'+rateCode+'">');
	}
document.write('				<tr>');
document.write('					<td class="f12" colspan="2"><b>Additional Information:</b></td>');
document.write('				</tr>');
document.write('				<tr>');
document.write('					<td nowrap class="f11">');
document.write('						Corporate ID:&nbsp;&nbsp;&nbsp;');
if (corpNum!="")
	{
		document.write('							'+corpNum);
	}
else
	{
		document.write('						<input type="text" name="corpNum" size="10" maxlength="9" class="f11">');
	}
document.write('					</td>');
document.write('					<td class="f11">');
if(IATAno!="")
	{
	document.write('						IATA#:'+IATAno+'');
	}
else
	{
	document.write('						IATA#:');
	}	
document.write('						&nbsp;&nbsp;&nbsp;');
if(IATAno!="")
	{
	document.write('						<input name="_IATAno" type="hidden" value="'+IATAno+'">');
	}
else{
	document.write('						<input type="text" name="_IATAno" size="10" maxlength="8" class="f11">');
}
document.write('					</td>');
document.write('				</tr>');
document.write('				<tr>	');
document.write('				</tr>');
document.write('			</table>');
document.write('		</td>');
document.write('	</tr>');
document.write('</table>');
document.write('<table cellpadding="5" cellspacing="0" border="0" width="540">');
document.write('	<tr>');
document.write('		<td align="right">');
document.write('			<br>');
if(hotelCode=="")
	{
		document.write('        <input type="image" src="http://images1.ichotelsgroup.com/cq/etc/media_library/common/1/en/reservation/buttons.Par.0025.Image.gif" name="smartQuickSearch">');
	}
else
	{
		document.write('        <input type="image" src="http://images1.ichotelsgroup.com/cq/etc/media_library/common/1/en/reservation/buttons.Par.0025.Image.gif" name="hotelDetailAvailabilitySearch">');
	}
//document.write('				<input type="image" src="http://images1.ichotelsgroup.com/cq/etc/media_library/common/1/en/reservation/buttons.Par.0025.Image.gif" alt="Check Availability" border="0">');
document.write('		</td>');
document.write('	</tr>');
document.write('</table>');
document.write('</form>');
document.write('<script language="javascript">');
document.write(' var theForm = document.searchForm; ');
document.write(' theForm.smokingPreference.selectedIndex = 0; ');
document.write(' theForm.roomTypePreference.selectedIndex = 0; ');
document.write('</script>');
document.close();

						
}