/*********************************************
$Id: writeJSSearchModule.js,v 1.4 2004/11/12 11:16:53 nmargar Exp $
<Author>
L. Williams

<Description>
HTML document can call this file using meathod showSearch() to display the Search Module on a site. The Module can be confiured to unique specifications. Please reference the documentation provided by ICHotelsGroup.

<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 ICHotelsGroup main website, in addition to other JS code.
*********************************************/
var redirectVars=[["brandCode","6c"],["regionCode","1"],["localeCode","en"],["city",""],["state",""],["country",""],["hotelCode",""],["rateCode",""],["hide_rateCode",""],["IATAno",""],["hide_IATAno",""],["corpNum",""],["hide_corpNum",""],["GPC",""],["hide_GPC",""],["searchHI",""],["searchEX",""],["searchCP",""],["searchIC",""],["searchSB",""],["searchCW",""]]
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++)w.r("<option value="+x+">"+x+"</option>");
}

function monthName(month_value){
	switch (month_value){
		case 0: return "Jan"
		case 1: return "Feb"
		case 2: return "Mar"
		case 3: return "Apr"
		case 4: return "May"
		case 5: return "Jun"
		case 6: return "Jul"
		case 7: return "Aug"
		case 8: return "Sep"
		case 9: return "Oct"
		case 10: return "Nov"
		case 11: return "Dec"
	}
}

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
	w.r("<option value="+(i%12)+temp_year+">"+monthName(i%12)+" "+temp_year+"</option>");
	}
}

function writeStateId(stateName){
	for(var i=0;i<61;i++){
		if ((st[i]==stateName)&&(stateName!=""))
			w.r("<option selected value=\""+st[i]+"\">"+st[i]+"</option>");
		else
			w.r("<option value=\""+st[i]+"\">"+st[i]+"</option>");
	}
}

function writeCountryId(countryName){
	w.r("<select name=countryId class=f12quickres>");
	for(var i=0;i<102;i++){
		if ((b[i][0]==countryName)||(b[i][1]==countryName))
			w.r("<option selected value="+b[i][0]+">"+b[i][1]+"</option>");
		else
			w.r("<option value="+b[i][0]+">"+b[i][1]+"</option>");
	}
	w.r("</select>");
}


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;
                }
            }
    }
}


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]-1);// + "" + (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]-1);// + "" + (index +2002);
		}
  	}







function showSearch(cityPass, statePass, countryPass, IATAnoPass){
//alert(brandCode);
//backwards compatible support
if(cityPass!=null){city=cityPass;}
if(statePass!=null){state=statePass;}
if(countryPass!=null){country=countryPass;}
if(IATAnoPass!=null){IATAno=IATAnoPass;}
//end

document.write('<center>');

document.write('	<table width="100%"  border="0" cellpadding="0" cellspacing="0" bgcolor="#BBC9D9">');
document.write('		<tr>');
document.write('		</tr>');
document.write('	</table>');
document.write('	<table width="100%" border="0" cellpadding="4" cellspacing="0">');
document.write('		<tr>');
document.write('			<td>');
document.write('				<table width="100%"  border="0" cellpadding="0" cellspacing="0">');
document.write('					<tr valign="top">');
document.write('						<td colspan="4">');
document.write('							<table width="100%" border="0" cellpadding="0" cellspacing="0">');

//document.write('<script language="JavaScript" type="text/javascript" src="/globals/JSSearchCalendar.js"></script>');
//document.write('<link rel="stylesheet" type="text/css" href="http://images1.ichotelsgroup.com/css/6c_styles.css">');

document.write('<form action="counthits.php" name="searchForm" method="POST" target="_blank">');
//document.write('<form action="http://www.ichotelsgroup.com/redirect" name="searchForm" method="POST" target="_blank">');
document.write('<INPUT type=hidden name=firstinput>');

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+'">');

if ((searchHI!="")||(searchEX!="")||(searchCP!="")||(searchIC!="")||(searchSB!="")||(searchCW!=""))
{//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">');
}
else //user wants to search all brands
{
	document.write('<INPUT type="hidden" name="searchGroupCodes" value="all">');
}




//document.write('<table width="258" border="0" cellpadding="0" cellspacing="0">');
//document.write('	<tr>');
if(hotelCode=="")
	{
		document.write('		<td><a href="http://www.ichotelsgroup.com/h/d/6c/1/en/hotelsearch"><img  src="/images/qres.Par.0001.Image.gif" height="28" width="258" border="0"></a></td>');
	}
else
	{
//		document.write('		<td width="252" height="28" class="qresHeader" nowrap>&nbsp;&nbsp;&nbsp;RESERVE THIS HOTEL</td>');
	}

if(hotelCode=="")
	{
		document.write('	<tr> ');
		document.write('     <td> ');
		document.write('        <table width="100%" border="0" cellspacing="0" cellpadding="0" class=qresHome>');
		document.write('          <tr class=qresHome> ');
		document.write('            <td colspan="2" >');
		document.write('              <table width="100%" border="0" cellspacing="0" cellpadding="0" class=qresHome>');
		document.write('                 <tr class=qresHome> ');
		document.write('                  <td align="left">City:</td>');
		document.write('                  <td align="right">State/Prov. (US/Canada)</td>');
		document.write('                 </tr>');
		document.write('              </table>');
		document.write('            </td>');
		document.write('          </tr>');
		document.write('          <tr> ');
		document.write('           <td width="50%">');
		document.write('              <input type="text" name="city" width="115" size="18" maxlength="35" class="f12quickres" value="'+city+'">');
		document.write('            </td>');
		document.write('            <td width="50%" align="left">&nbsp;&nbsp;');
		document.write('              <select name=stateId class="f12quickres">');
		writeStateId(state);
		document.write('        </select>');
		document.write('            </td>');
		document.write('          </tr>');
		document.write('          <tr>');
		document.write('            <td width="50%">Country:</td>');
		document.write('            <td width="50%"></td>');
		document.write('          </tr>');
		document.write('          <tr>');
		document.write('            <td width="50%">');
		writeCountryId(country);
		document.write('            </td>');
		document.write('            <td width="50%"></td>');
		document.write('          </tr>');

		document.write('        </table>');
		document.write('      </td>');
		document.write('    </tr>');

		document.write('    <tr> ');
		document.write('      <td>&nbsp;</td>');
		document.write('    </tr>');
	}//end hotelCode if statement
else //hotelCode!=null
	{
		city=null;state=null;country=null;
		document.write('<INPUT type="hidden" name="hotelCode" value="'+hotelCode+'">');
	}



document.write('								<tr>');
document.write('									<td><div align="left">');

document.write('	Date d&acute;arrivee:<img src="images/trans.gif" width="5" height="1" /><select name="checkInDate"  onchange=\'javascript:populateCheckOut()\'>');
document.write('										<option value="-1" ></option>');
writeSelectNumbers(32);
document.write('										</select>');

document.write('										 <select name="checkInMonthYear"  onchange=\'javascript:populateCheckOut()\'>');
document.write('											<option value="-1" ></option>');
writeMonthYear();
document.write('											</select></div>');
document.write('										</td>');

document.write('									</tr>');

document.write('									<tr valign="bottom">');
document.write('										<td colspan="3"><div align="left">');

document.write('										</td>');
document.write('									</tr>');
document.write('									<tr>');
document.write('										<td  class="pad5"><div align="left">');

document.write('											Date de depart:&nbsp;<select name="checkOutDate"  onchange=\'javascript:populateCheckOut()\'>');
document.write('											<option value="-1" ></option>');
writeSelectNumbers(32);
document.write('											</select>');
document.write('										<select name="checkOutMonthYear"  onchange=\'javascript:populateCheckOut()\'>');
document.write('										<option value="-1" ></option>');
writeMonthYear();
document.write('										</select></div>');
document.write('									</td>');

document.write('								</tr>');

document.write('								<tr valign="bottom">');
document.write('			<td align="bottom" class="pad10"><table width="100%"  border="0" cellspacing="0" cellpadding="0">      <tr>        <td><div align="left">Adultes:</td>');
document.write('									<td><div align="left">Enfants:</td>');
document.write('									<td><div align="left">Chambres:</td>');
document.write('								 <td rowspan="2" valign="bottom"><input type="image" name="hotelDetailAvailabilitySearch"src="images/blank.gif"" value="Check" class="check"/></td></tr>');
document.write('								<tr> ');
document.write('									<td><div align="left">');
document.write('										<select name="numberOfAdults" >');
writeSelectNumbers(21);
document.write('										</select>');
document.write('									</td>');
document.write('									<td><div align="left">');
document.write('										<select name= "numberOfChildren">');
document.write('										<option value=0>0</option>');
writeSelectNumbers(21);
document.write('										</select>');
document.write('									</td>');
document.write('									<td><div align="left">');
document.write('										<select name="numberOfRooms" >');
writeSelectNumbers(10);
document.write('										</select>');
document.write('									</td>  </tr></table>');
if(hotelCode=="")
	{
		document.write('<input type="image" src="/images/qres.Par.0002.Image.gif" name="smartQuickSearch">');
	}
else
	{
document.write('<tr><td valign="bottom"></td></tr>');
	}
document.write('								</tr>');
document.write('							</table>');

if (hide_rateCode=="")  //use the rate code
{
	if(rateCode=="")
		{
		document.write('                <tr> ');
		document.write('                  <td>');
		document.write('                    <table width="100%" border="0" cellspacing="0" cellpadding="0">');
		document.write('                      <tr>');
		document.write('                        <td class="f11">Rate Preference:</td>');
		document.write('                        <td>&nbsp;</td>');
		document.write('                      </tr>');
		document.write('                      <tr>');
		document.write('                        <td>');
		document.write('                         <select name="rateTypeCodes" class="f11">');
		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('                        <td>&nbsp;</td>');
		document.write('                      </tr>');
		document.write('                    </table>');
		document.write('                  </td>');
		document.write('                </tr>');
	}
	else
	{
		document.write('<INPUT type="hidden" name="rateTypeCodes" value="'+rateCode+'">');
	}
}
else
{
	if(rateCode=="") //default rate code to best available.
		rateCode="6CBARC";
	document.write('<INPUT type="hidden" name="rateTypeCodes" value="'+rateCode+'">');
}
if(hotelCode!="")
{
/*
	document.write('                <tr> ');
	document.write('                  <td height="9"></td>');
	document.write('                </tr>');
	document.write('                <tr> ');
	document.write('                  <td>');
	document.write('                    <table width="100%" border="0" cellspacing="0" cellpadding="0">');
	document.write('                      <tr>');
*/
	if (hide_corpNum=="")  //show corpNum field, either programmed or entry field
	{
		document.write('                        <td class="f11">Corporate ID:</td>');
	}
	if (hide_IATAno=="")  //show corpNum field, either programmed or entry field
	{
		document.write('                        <td class="f11">IATA #:</td>');
	}
//	document.write('                      </tr>');
//	document.write('                      <tr>');
	if (hide_corpNum=="")  //show corpNum field, either programmed or entry field
	{
		document.write('                        <td class="f12quickres">');
		if (corpNum!="")
		{
			document.write('							'+corpNum);
			document.write('<INPUT type="hidden" name="corpNum" value="'+corpNum+'">');
		}
		else
		{
			document.write('							<input type="text" name="corpNum" width="115" size="16" maxlength="35" class="f12quickres" value="'+corpNum+'">');
		}
		document.write('                        </td>');
	}
	else  //hide corpNum field.
	{
		document.write('<INPUT type="hidden" name="corpNum" value="'+corpNum+'">');
	}
	if (hide_IATAno=="")  //show IATAno field, either programmed or entry field
	{
		document.write('                        <td class="f12quickres">');
		if (IATAno!="")
		{
			document.write('							'+IATAno);
			document.write('<INPUT type="hidden" name="IATAno" value="'+IATAno+'">');
		}
		else
		{
			document.write('							 <input type="text" name="IATAno" width="115" size="16" maxlength="35" class="f12quickres" value="'+IATAno+'">');
		}
		document.write('                        </td>');
	}
	else  //hide IATAno field.
	{
		document.write('<INPUT type="hidden" name="IATAno" value="'+IATAno+'">');
	}
/*
	document.write('                      </tr>');
	document.write('                    </table>');
	document.write('                  </td>');
	document.write('                </tr>');

	document.write('                <tr> ');
	document.write('                  <td height="9"></td>');
	document.write('                </tr>');
*/
	if (hide_GPC=="")  //show GPC field, either programmed or entry field (we can removed the entire row since this is the only object present on that row)
	{
		document.write('                <tr> ');
		document.write('                  <td>');
		document.write('                    <table width="100%" border="0" cellspacing="0" cellpadding="0">');
		document.write('                      <tr>');
		document.write('                        <td class="f11">Group Booking Code:</td>');
		document.write('                        <td class="f11">&nbsp;</td>');
		document.write('                      </tr>');
		document.write('                      <tr>');
		document.write('                        <td class="f12quickres">');
		if (GPC!="")
		{
			document.write('							'+GPC);
			document.write('<INPUT type="hidden" name="GPC" value="'+GPC+'">');
		}
		else
		{
			document.write('							 <input type="text" name="GPC" width="115" size="16" maxlength="35" class="f12quickres" value="'+GPC+'">');
		}
		document.write('                        </td>');
		document.write('                        <td>&nbsp;</td>');
		document.write('                      </tr>');
		document.write('                    </table>');
		document.write('                  </td>');
		document.write('                </tr>');
	}
	else  //hide GPC field.
	{
		document.write('<INPUT type="hidden" name="GPC" value="'+GPC+'">');
	}

}
/*
document.write('              </table>');
document.write('            </td>');
document.write('          </tr>');
document.write('        </table>');
document.write('      </td>');
document.write('    </tr>');
document.write('	</table>');
document.write('	</td></tr></table></td></tr></table></td></tr>');
document.write('    <tr> ');
document.write('      <td>');
document.write('        <table width="100%" border="0" cellspacing="0" cellpadding="0" class=qresHome>');
document.write('          <tr>');
document.write('            <td>&nbsp;</td>');
document.write('            <td align=center><font size="2" face="Arial, Helvetica, sans-serif">');
*/

/*
placed above
if(hotelCode=="")
	{
		document.write('        <input type="image" src="http://images1.ichotelsgroup.com/cq/etc/media_library/cn/0/en/reservation/qres.Par.0002.Image.gif" name="smartQuickSearch">');
	}
else
	{
		document.write('        <input type="image" src="images/online-reservations-go.gif" name="hotelDetailAvailabilitySearch">');
	}
*/

/*
document.write('        </font></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('  </td>');
document.write('  </tr>');
document.write('  </table>');
*/
document.write('  </form>');


document.write('						</td>');
document.write('					</tr>');
document.write('				</table>');
document.write('			</td>');
document.write('		</tr>');
document.write('	</table>');
document.write('</center>');


}

