$jq = jQuery.noConflict();
var rhcid = "264768";

$jq(document).ready(function(){	
	//$jq("#hotel_form_container").tabs();
	$jq("#op_hotel").attr("checked", "checked");
	//$jq("#hotel_search_form .hbamEntry, #hotel_search_form .hbaddEntry, #hotel_search_form .hbpriceEntry").hide();
	//$jq('#num_rooms').attr('value', '1');

	//$jq("#flightRoundRadio").attr("checked", "checked");
	
	//$jq(".datepicker").datepicker({dateFormat: 'd MM, yy', minDate: 0, maxDate: '+12M'});
	//$jq("button.fg-button").hover(
	//	function(){$jq(this).addClass("ui-state-hover");},
	//	function(){$jq(this).removeClass("ui-state-hover");}
	//);
	
	//IAN search form
	if($jq("#hot-search-params").length > 0)
		refresh();
});


function hotelFormHandler(element){
	var id = $jq(element).attr('id');
	
	if(id == 'hotelByCity'){
		$jq("#hotel_search_form .hbamEntry, #hotel_search_form .hbaddEntry, #hotel_search_form .hbpriceEntry").hide();
		$jq("#hotel_search_form .hbcEntry").show();
	}else if(id == 'hotelByAmenity'){
		$jq("#hotel_search_form .hbcEntry, #hotel_search_form .hbaddEntry, #hotel_search_form .hbpriceEntry").hide();
		$jq("#hotel_search_form .hbamEntry").show();
	}else if(id == 'hotelByAddress'){
		$jq("#hotel_search_form .hbcEntry, #hotel_search_form .hbamEntry, #hotel_search_form .hbpriceEntry").hide();
		$jq("#hotel_search_form .hbaddEntry").show();
	}else if(id == 'hotelByPrice'){
		$jq("#hotel_search_form .hbcEntry, #hotel_search_form .hbamEntry, #hotel_search_form .hbaddEntry").hide();
		$jq("#hotel_search_form .hbpriceEntry").show();
	}
	$jq('#cityRadioText').attr('checked', 'checked').triggerHandler('click');
}
function addRooms(){
	var rooms = $jq('#num_rooms option:selected').attr('value');
	var roomsExist = $jq("#room_count .roomEntry").length;
	
	if(rooms == "9+"){
		$jq("#room1Entry .roomSubEntry2, #room1Entry .roomSubEntry").hide();
		$jq("#room1Entry").siblings().remove();
		$jq("#room1Entry #grmsg").show();
		$jq("#hotel_search_form .buttonEntry .fg-button").addClass("ui-state-disabled").attr("disabled", "true");
		return 0;
	}
	
	$jq("#room1Entry #grmsg").hide();
	$jq("#room1Entry .roomSubEntry2, #room1Entry .roomSubEntry").show();
	$jq("#hotel_search_form .buttonEntry .fg-button").removeClass("ui-state-disabled").removeAttr("disabled");
	
	if(rooms < roomsExist){ 		//remove rooms
		$jq("#room1Entry").siblings().slice(rooms-1, roomsExist).remove();
	}else if(rooms > roomsExist){	//add rooms
		for(var currRoom = roomsExist+1; currRoom <= rooms; currRoom++){
			var roomEntry = 
				"<div class='roomEntry'>"+ 
					"<div class='roomSubEntry1'>&nbsp;</div>"+
					"<div class='roomSubEntry2'>Room "+currRoom+"</div>"+
					"<div class='roomSubEntry'>"+
						"<select  id='num_adult_room"+currRoom+"' name='num_adult_room"+currRoom+"' class='number'>"+
							"<option value='1'>1</option><option selected='selected' value='2'>2</option><option value='3'>3</option><option value='4'>4</option>"+
						"</select>"+
					"</div>"+
					"<div class='roomSubEntry'>"+
						"<select  id='num_child_room"+currRoom+"' name='num_child_room"+currRoom+"' class='number'>"+
							"<option value='0'>0</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>"+
						"</select>"+
					"</div>"+
				"</div>";
			$jq("#room_count").append(roomEntry);
		}
	}
}

//============HOTEL VALIDATION=========================================================================
function validateHotelForm(ele){
	var validationStatus = validateHotelDestCity();
	
	if(validateHotelDates() == false)
		validationStatus = false;
	
	if(validationStatus){
		var searchPage = "http://travel.reservationhost.com/index.jsp?pageName=hotSearch&hotel=2&submitted=true&validateCity=true";
		var city   = $jq("#cityRadioText", "#hotel_search_form").is(":checked")? jQuery.trim($jq("#cityText", "#hotel_search_form").attr("value")): "dhaka";
		
		//window.location = 'http://travel.ian.com/hotel/searchresults?cid=264768&currencyCode=CAD&searchType=DESTINATION&userCity=New+York%2CNY%2CUS&searchParam=572B0850-4E3F-469B-87B2-C17ED3EA049B&travelDetail=[20090622-2]2';
		var query = searchPage + "&cid=" + rhcid + "&city=" + city + "&arrivalDay=14&arrivalMonth=11";
		
		if(ele == "hotelByCityBtn"){
			window.location = query;
		}else if(ele == "hotelByAmenityBtn"){
		}else if(ele == "hotelByAddressBtn"){
		}else if(ele == "hotelByPriceBtn"){
		}
		
		return false; //prevent form being submitted
	}
		
	$jq("input[name='cityRadio']", "#hotel_search_form").click(function(){
		validateHotelDestCity();
	});
	$jq("#cityText", "#hotel_search_form").bind("keyup focus", function(){
		validateHotelDestCity();
	});
	$jq("#checkin_date, #checkout_date", "#hotel_search_form").change(function(){
		validateHotelDates();
	});

	return false;
}
function validateHotelDestCity(){
	var destCityEle = $jq("#cityText", "#hotel_search_form");
	
	if($jq("#cityRadioText", "#hotel_search_form").is(":checked") && jQuery.trim(destCityEle.attr("value")) == ""){
		$jq("#hotelVDC").show();
		destCityEle.addClass("error");
		return false;
	}
	
	$jq("#hotelVDC").hide();
	destCityEle.removeClass("error");
	
	return true;
}
function validateHotelDates(){
	var validationStatus = true;
	var checkinDateEle   = $jq("#checkin_date", "#hotel_search_form");
	var checkoutDateEle  = $jq("#checkout_date", "#hotel_search_form");
	
	if(jQuery.trim(checkinDateEle.attr("value")) == ""){
		$jq("#hotelVCID").show();
		checkinDateEle.addClass("error");
		validationStatus = false;
	}else{
		$jq("#hotelVCID").hide();
		checkinDateEle.removeClass("error");
	}
		
	if(jQuery.trim(checkoutDateEle.attr("value")) == ""){
		$jq("#hotelVCOD").show();
		checkoutDateEle.addClass("error");
		validationStatus = false;
	}else{
		$jq("#hotelVCOD").hide();
		checkoutDateEle.removeClass("error");
	}
		
	if(validationStatus == false)
		return false;
		
	var checkinDateStamp  = Date.parse(jQuery.trim(checkinDateEle.attr("value")));
	var checkoutDateStamp = Date.parse(jQuery.trim(checkoutDateEle.attr("value")));
	
	if(checkoutDateStamp <= checkinDateStamp){
		$jq("#hotelVCICOC").show();
		checkoutDateEle.addClass("error");
		return false;
	}else
		$jq("#hotelVCICOC").hide();
		
	return true;
}
//============FLIGHT VALIDATION=========================================================================
function validateFlightForm(){
	var validationStatus = validateFlightLeavingCity();
	
	if(validateFlightGoingCity() == false)
		validationStatus = false;
	
	if(validateFlightDates() == false)
		validationStatus = false;
		
	if(validationStatus)
		return validationStatus && false; //should return true
	
	$jq("#airLeaveFromText", "#flight_search_form").bind("keyup", function(){
		validateFlightLeavingCity();
	});
	$jq("#airgoToText", "#flight_search_form").bind("keyup", function(){
		validateFlightGoingCity();
	});
	
	$jq("input[name='flightTypeRadio']", "#flight_search_form").click(function(){
		validateFlightDates();
	});

	$jq("#airDepartDateText, #airReturnDateText, #airDepartTimeSelect, #airReturnTimeSelect", "#flight_search_form").change(function(){
		validateFlightDates();
	});

	return false;
}
function validateFlightLeavingCity(){
	var leavingCityEle = $jq("#airLeaveFromText", "#flight_search_form");
	
	if(jQuery.trim(leavingCityEle.attr("value")) == ""){
		$jq("#flightVLC").show();
		leavingCityEle.addClass("error");
		return false;
	}
	
	$jq("#flightVLC").hide();
	leavingCityEle.removeClass("error");
	
	return true;
}
function validateFlightGoingCity(){
	var goingCityEle = $jq("#airgoToText", "#flight_search_form");
	
	if(jQuery.trim(goingCityEle.attr("value")) == ""){
		$jq("#flightVAC").show();
		goingCityEle.addClass("error");
		return false;
	}
	
	$jq("#flightVAC").hide();
	goingCityEle.removeClass("error");
	
	return true;
}
function validateFlightDates(){
	var validationStatus = true;
	var departingDateEle   = $jq("#airDepartDateText", "#flight_search_form");
	
	if(jQuery.trim(departingDateEle.attr("value")) == ""){
		$jq("#flightVDD").show();
		departingDateEle.addClass("error");
		validationStatus = false;
	}else{
		$jq("#flightVDD").hide();
		departingDateEle.removeClass("error");
	}
	
	if($jq("#flightOneWayRadio", "#flight_search_form").is(":checked")){
		$jq("#flightVRD").hide();
		$jq("#flightVDDRDC").hide();
		$jq("#flightVDTRTC").hide();
		
		return validationStatus;
	}
	
	var returningDateEle   = $jq("#airReturnDateText", "#flight_search_form");
	
	if(jQuery.trim(returningDateEle.attr("value")) == ""){
		$jq("#flightVRD").show();
		returningDateEle.addClass("error");
		validationStatus = false;
	}else{
		$jq("#flightVRD").hide();
		returningDateEle.removeClass("error");
	}
	
	if(validationStatus == false)
		return false;
		
	$jq("#flightVDTRTC").hide();
	$jq("#airReturnTimeSelect").removeClass("error");
		
	var departDateStamp = Date.parse(jQuery.trim(departingDateEle.attr("value")));
	var returnDateStamp = Date.parse(jQuery.trim(returningDateEle.attr("value")));
	
	if(returnDateStamp < departDateStamp){
		$jq("#flightVDDRDC").show();
		returningDateEle.addClass("error");
		return false;
	}else
		$jq("#flightVDDRDC").hide();
		
	if(returnDateStamp != departDateStamp){
		$jq("#flightVDTRTC").hide();
		return true;
	}
	
	var departTime = $jq('#airDepartTimeSelect option:selected').attr('value');
	var returnTime = $jq('#airReturnTimeSelect option:selected').attr('value');
	var isnum = departTime >=0 && departTime<=23 && returnTime >=0 && returnTime<=23;
	
	if(isnum && returnTime < (departTime*1+2)){
		$jq("#flightVDTRTC").show();
		$jq("#airReturnTimeSelect").addClass("error");
		return false;
	}else{
		$jq("#flightVDTRTC").hide();
		$jq("#airReturnTimeSelect").removeClass("error");
	}
		
	return true;
}
//================CAR VALIDATION========================================================================

function validateCarForm(){
	var validationStatus = validateCarPickupCity();
	
	if(validateCarDropoffCity() == false)
		validationStatus = false;
	
	if(validateCarDates() == false)
		validationStatus = false;
		
	if(validationStatus)
		return validationStatus && false; //should return true
	
	$jq("#carPickupCity", "#car_search_form").bind("keyup", function(){
		validateCarPickupCity();
	});
	
	$jq("input[name='carDropoffRadio']", "#car_search_form").click(function(){
		validateCarDropoffCity();
	});
	$jq("#carDropoffCity", "#car_search_form").bind("keyup focus", function(){
		validateCarDropoffCity();
	});

	$jq("#pickup_date, #dropoff_date, #pickupTime, #dropoffTime", "#car_search_form").change(function(){
		validateCarDates();
	});

	return false;
}

function validateCarPickupCity(){
	var pickupCityEle = $jq("#carPickupCity", "#car_search_form");
	
	if(jQuery.trim(pickupCityEle.attr("value")) == ""){
		$jq("#carVPUC").show();
		pickupCityEle.addClass("error");
		return false;
	}
	
	$jq("#carVPUC").hide();
	pickupCityEle.removeClass("error");
	
	return true;
}
function validateCarDropoffCity(){
	var dropoffCityEle = $jq("#carDropoffCity", "#car_search_form");
	
	if($jq("#carDropoffRadioText", "#car_search_form").is(":checked") && jQuery.trim(dropoffCityEle.attr("value")) == ""){
		$jq("#carVDOC").show();
		dropoffCityEle.addClass("error");
		return false;
	}
	
	$jq("#carVDOC").hide();
	dropoffCityEle.removeClass("error");
	
	return true;
}
function validateCarDates(){
	var validationStatus = true;
	var pickupDateEle  = $jq("#pickup_date", "#car_search_form");
	var dropoffDateEle = $jq("#dropoff_date", "#car_search_form");
	
	if(jQuery.trim(pickupDateEle.attr("value")) == ""){
		$jq("#carVPUD").show();
		pickupDateEle.addClass("error");
		validationStatus = false;
	}else{
		$jq("#carVPUD").hide();
		pickupDateEle.removeClass("error");
	}
	
	if(jQuery.trim(dropoffDateEle.attr("value")) == ""){
		$jq("#carVDOD").show();
		dropoffDateEle.addClass("error");
		validationStatus = false;
	}else{
		$jq("#carVDOD").hide();
		dropoffDateEle.removeClass("error");
	}
	
	if(validationStatus == false)
		return false;
		
	$jq("#carVPTDTC").hide();
	$jq("#dropoffTime").removeClass("error");
		
	var pickupDateStamp  = Date.parse(jQuery.trim(pickupDateEle.attr("value")));
	var dropoffDateStamp = Date.parse(jQuery.trim(dropoffDateEle.attr("value")));
	
	if(dropoffDateStamp < pickupDateStamp){
		$jq("#carVPDDDC").show();
		dropoffDateEle.addClass("error");
		return false;
	}else
		$jq("#carVPDDDC").hide();
		
	if(dropoffDateStamp != pickupDateStamp){
		$jq("#carVPTDTC").hide();
		return true;
	}
	
	var departTime = $jq('#pickupTime option:selected').attr('value');
	var returnTime = $jq('#dropoffTime option:selected').attr('value');
	
	if(returnTime < (departTime*1+2)){
		$jq("#carVPTDTC").show();
		$jq("#dropoffTime").addClass("error");
		return false;
	}else{
		$jq("#carVPTDTC").hide();
		$jq("#dropoffTime").removeClass("error");
	}
		
	return true;
}

//==========IAN Form Functions====================================================================================

//start new script code
// Checks if browser is Netscape 2.0x since the options array properties don't work with Netscape 2.0x
function isBrowserSupp() {
	// Get the version of the browser
    version =  parseFloat( navigator.appVersion );

    if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
        return false;
    } else {
        return true;
    }
    return true;
}

function isLeapYear( yrStr ) {
        var leapYear = false;
        var year = parseInt( yrStr, 10 );
        // every fourth year is a leap year
        if ( year % 4 == 0 ) {
            leapYear = true;
            // unless it's a multiple of 100
            if( year % 100 == 0 ) {
                leapYear = false;
                // unless it's a multiple of 400
                if( year % 400 == 0 ) {
                    leapYear=true;
                }
            }
        }
        return leapYear;
    }

    function getDaysInMonth( mthIdx, YrStr ) {
        // all the rest have 31
        var maxDays = 31
        // expect Feb. (of course)
        if( mthIdx == 1 ) {
            if( isLeapYear( YrStr ) ) {
                maxDays=29;
            } else {
                maxDays=28;
            }
        }

        // thirty days hath...
        if( mthIdx == 3 || mthIdx == 5 || mthIdx == 8 || mthIdx == 10 ) {
            maxDays=30;
        }
        return maxDays;
    }


    //the function which does some magic to the date fields
    // return non-zero if it is the last day of the month
    function adjustDate( mthIdx, Dt ) {
        var value = 0;

        var today = new Date()
        var theYear = parseInt( today.getYear(), 10 )

        if( mthIdx < today.getMonth() ) {
            theYear = ( parseInt( today.getYear(), 10 ) + 1 )
        }
        if( theYear < 100 ) {
            theYear = "19" + theYear
        } else {
            if( ( theYear - 100 ) < 10 ) {
                theYear = "0" + ( theYear - 100 )
            } else {
                theYear = ( theYear - 100 ) + ""
            }
            theYear = "20" + theYear
        }


        var numDays = getDaysInMonth( mthIdx, theYear );

        if( mthIdx == 1 ) {
            if( Dt.options.selectedIndex + 1 < numDays ) {
                return 0;
            } else {
                Dt.options.selectedIndex=numDays - 1;
                //check for leap year
                if( numDays == 29 ) {
                    return 99;
                } else {
                    return 1;
                }
            }
        }

        if( Dt.options.selectedIndex + 1 < numDays ) {
            value = 0;
        } else {
            if ( Dt.options.selectedIndex + 1 > numDays ) {
                Dt.options.selectedIndex--;
                value = 3;
            } else {
                //index is 31 or 30
                value = 2;
            }
        }
        return value;
    }

    //changes departure month when arrival month is changed
    function amadChange( inM, inD, outM, outD ) {
        if ( !isBrowserSupp() ) {
            return;
        }

        var res = adjustDate( inM.options.selectedIndex, inD );
        if( res != 0 ) {
               outD.options.selectedIndex = 0;
               if ( outM.options.selectedIndex == 11 ) {
                    outM.options.selectedIndex = 0
               } else {
                    outM.options.selectedIndex=inM.options.selectedIndex + 1;
                    outD.options.selectedIndex = 1;
               }
        } else {
            outM.options.selectedIndex = inM.options.selectedIndex;
            if (outD.options.selectedIndex <= inD.options.selectedIndex) {
                outD.options.selectedIndex = inD.options.selectedIndex + 2;
            }
        }
        return;
    }


    function dmddChange( outM, outD ) {
        if ( !isBrowserSupp() ) {
            return;
        }

        adjustDate( outM.options.selectedIndex, outD );
        return;
    }
	
	function loadDates(arrivalMonthSelect,  arrivalDaySelect, departureMonthSelect, departureDaySelect)
{
	var calendar = new Date();
	var calendar2 = new Date();
	var cal
	var cal2
	var date;
	var month;
	var year;
	var date2;
	var month2;
	var year2;

	//Here is the variable to change for to advance the arrival Date
	 var advanceArrival = 14;
	//Here is the variable to change for to advance the departure Date
	 var advanceDeparture = 16;


	//Set the arrival Days
	calendar.setDate(calendar.getDate()+ advanceArrival);
	date = calendar.getDate();
	month = calendar.getMonth();

	//Set the Departure Days
	calendar2.setDate(calendar2.getDate()+advanceDeparture);
	date2 = calendar2.getDate();
	month2 = calendar2.getMonth();

	arrivalMonthSelect.value=month;
	arrivalDaySelect.value=date;
	departureMonthSelect.value=month2;
	departureDaySelect.value=date2;
}

	//=================calender========================================================
function update(themonth,theday){
    document.forms[fName].elements[formType+'Day'].options[theday - 1].selected = true;
    document.forms[fName].elements[formType+'Month'].options[themonth].selected = true;

    testWindow.close();
}

function loadCalendar(viewMonth) {


	testWindow.document.close();
	testWindow.document.open();


    var day_of_week = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	var month_of_year = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

	var dateObj = new Date();
	var year = dateObj.getYear();	 // Returns year
	var month = dateObj.getMonth();  // Returns month (0-11)
	var today = dateObj.getDate();   // Returns day (1-31)
	var weekday = dateObj.getDay();  // Returns day (1-31)

	var DAYS_OF_WEEK = 7;   // "constant" for number of days in a week
	var DAYS_OF_MONTH = 31; // "constant" for number of days in a month
	var cal;                // Used for printing

	if (viewMonth < month) {
		year = year + 1;
	}

	if(year < 1900){
		year += 1900; //done to solve the problem of netscape and mozilla returning year in form 10X for years > 2000
	}

	month = viewMonth;
	dateObj.setDate(1);      // Start the calendar day at '1'
	dateObj.setMonth(month); // Start the calendar month at now
	dateObj.setYear((year));

	// VARIABLES FOR FORMATTING
	var TR_start = '<TR>';
	var TR_end = '</TR>';
	var highlight_start = '<TD WIDTH="30"><TABLE CELLSPACING=0 BORDER=1 BGCOLOR=DEDEFF BORDERCOLOR=CCCCCC><TR><TD WIDTH=20><B><CENTER>';
	var highlight_end   = '</CENTER></TD></TR></TABLE></B>';
	var TD_start = '<TD WIDTH="30"><CENTER>';
	var TD_end = '</CENTER></TD>';
	var prevM = month - 1;
	var nextM = month + 1;

	if (nextM == 12) {
		nextM = 0;
	}

	if (prevM == -1) {
		prevM = 11;
	}

	// BEGIN CODE FOR CALENDAR
	cal =  '<html><head><title>Calendar</title></head><body>';
	cal += "<style>body,td{font-family: sans-serif; font-size: 11px; color: #000000;cursor: default}a:link{cursor: hand}a:active{cursor: hand}a:hover{cursor: hand}a:visited{cursor: hand} .tableborder {border: #91b1fa 1px solid; background: #d9e5fd} .month {background: #2e57a7; color: #C4DFFF; text-align: center;}</style>";

    // NOTE:
    // Update the calendar.js reference below to reference where you
    // put the calendar.js file.

    cal += '<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="0" BORDERCOLOR="BBBBBB" width="100%" height="200"><TR><TD>';
	cal += '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="2" width="100%">' + TR_start;
	cal += '<TD COLSPAN="' + DAYS_OF_WEEK + '" BGCOLOR="#EFEFEF"><CENTER><B>';
	cal += month_of_year[month]  + '   ' + year + '</B>' + TD_end + TR_end;
	cal += TR_start;

    ///////////////////////////////////
    // DO NOT EDIT BELOW THIS POINT  //
    ///////////////////////////////////

	// LOOPS FOR EACH DAY OF WEEK
	for(index=0; index < DAYS_OF_WEEK; index++) {
        // PRINTS DAY
        cal += TD_start + day_of_week[index] + TD_end;
	}

	cal += TD_end + TR_end;
	cal += TR_start;

	// FILL IN BLANK GAPS UNTIL TODAY'S DAY
	for(index=0; index < dateObj.getDay(); index++) {
	    cal += TD_start + '  ' + TD_end;
    }

	// LOOPS FOR EACH DAY IN CALENDAR
    for(index=0; index < DAYS_OF_MONTH; index++) {
        if( dateObj.getDate() > index ) {
            // RETURNS THE NEXT DAY TO PRINT
            week_day =dateObj.getDay();

            // START NEW ROW FOR FIRST DAY OF WEEK
            if(week_day == 0) {
                cal += TR_start;
            }

            if(week_day != DAYS_OF_WEEK) {
                // SET VARIABLE INSIDE LOOP FOR INCREMENTING PURPOSES
                var day  = dateObj.getDate();

                // PRINTS DAY
                cal += TD_start + "<span onclick='window.opener.update(" + month + "," + day + ")' style='cursor:hand;font-weight:bold;background:#EFEFEF;width:22px;'>" + day + "</span>" + TD_end;
            }

            // END ROW FOR LAST DAY OF WEEK
            if(week_day == DAYS_OF_WEEK) {
                cal += TR_end;
            }
        }

        // INCREMENTS UNTIL END OF THE MONTH
        dateObj.setDate(dateObj.getDate()+1);

    }// end for loop

	cal += '</td></TR></TABLE></TABLE><br>';
    cal += '<div align="center"><a href="javascript:" onClick="window.opener.loadCalendar(' + prevM + ');">&lt;&lt;</a>&nbsp;&nbsp;&nbsp;&nbsp;';
	cal += '<a href="javascript:" onClick="window.opener.loadCalendar(' + nextM + ');">&gt;&gt;</a><br><br></div>';
	cal += '<div align="right"><a href="javascript:window.close();">close</a></div>';
	cal += '</body></html>';

	//  PRINT CALENDAR
	testWindow.document.write(cal);
}

var testWindow;
var formType;
var fName;

function openCalendar(formName,type, event) {
	formType=type;
	fName=formName;
	xcord = event.screenX;
	ycord = event.screenY-125;
	testWindow = window.open('','dates','left='+xcord+',top='+ycord+',width=300,height=250,resizable=1,status=1,menubar=0,location=0');
	loadCalendar(document.forms[fName].elements[formType+'Month'].selectedIndex);
}
	//===========Java script to handle city radio buttons and form submission
function setCSC(city,state,country) {
    if (city != "") {
        document.hotSearch.cityRadio2.checked=false;
        document.hotSearch.cityText.value='';
        document.hotSearch.city.value=city;
        document.hotSearch.stateProvince.value=state;
        document.hotSearch.country.value=country;
    }
}

function submitForm(form) {
    if (form.numberOfRooms.selectedIndex == 8) {
        window.location="http://www.travelnow.com/index.jsp?pageName=groups&cid=264768";
        return false;
    }
    if (document.hotSearch.cityText.value == "" && document.hotSearch.city.value == "") {
        alert('must enter city');
        return false;
    }
    if (document.hotSearch.cityText.value != "") {
        document.hotSearch.city.value=document.hotSearch.cityText.value;
        document.hotSearch.stateProvince.value='';
        document.hotSearch.country.value='';
    }
        return submitGuestInfoForm(form);
}

    var defaultAdults="2";
    var cellStyle=" class='index-11bold-text'";
    var childHelp="Please provide the ages of children in each room. Children's ages should be their age at the time of travel.";
    var adultHelp="";
    var textRooms="Rooms:";
    var textAdults="Adults: (age 19+)";
    var textChildren="Children: (0-17)";
    var textChildError="Please specify the ages of all children.";
    var pad='<img src="http://travel.ian.com/images/p.gif" width="5" height="1">';
    // NOTE: Question marks ("?") get replaced with a numeric value
    var textRoomX="Room ?:";
    var textChildX="Child ?:";
	
	//=========NOTE: DO NOT MODIFY THIS JAVASCRIPT BLOCK=============
	var adultsPerRoom=new Array(defaultAdults);
    var childrenPerRoom=new Array();
    var childAgesPerRoom=new Array();
    var numRooms=1;
    var maxChildren=0;

    function setChildAge(room, child, age) {
        if (childAgesPerRoom[room] == null) {
            childAgesPerRoom[room] = new Array();
        }
        childAgesPerRoom[room][child] = age;
    }

    function setNumAdults(room, numAdults) {
        adultsPerRoom[room] = numAdults;
    }

    function setNumChildren(room, numChildren) {
        childrenPerRoom[room] = numChildren;
        refresh();
    }

    function setNumRooms(x) {
        numRooms = x;
        for (i = 0; i < x; i++) {
            if (adultsPerRoom[i] == null) {
                adultsPerRoom[i] = 2;
            }
            if (childrenPerRoom[i] == null) {
                childrenPerRoom[i] = 0;
            }
        }
        refresh();
    }

    function renderRoomSelect() {
        var x = '';
        x += '<select name="numberOfRooms" onchange="setNumRooms(this.options[this.selectedIndex].value);">';
        for (var i = 1; i < 9; i++) {
            x += '<option value="'+i+'"'+(numRooms == i ? ' selected' : '')+'>' + i;
        }
        x += '<option value="9"'+(numRooms == 9 ? ' selected' : '')+'>9+';
        x += '</select>';
        return x;
    }

    function refresh() {
        maxChildren = 0;
        for (var i = 0; i < numRooms; i++) {
            if (childrenPerRoom[i] > maxChildren) {
                maxChildren = childrenPerRoom[i];
            }
        }

        var x = '';
        if (adultHelp.length > 0) {
            x = adultHelp + "<p>\n";
        }

        if (numRooms > 8) {
            x += textRooms;
            x += renderRoomSelect();

        } else {
            x += '<table border="0" cellspacing="2" cellpadding="0">\n';
            x += '<tr><td'+cellStyle+'>'+textRooms+pad+'</td>';
            if (numRooms > 1) {
                x += '<td'+cellStyle+'>&nbsp;</td>';
            }
            x += '<td'+cellStyle+'><nobr>'+textAdults+pad+'</nobr></td><td'+cellStyle+'><nobr>'+textChildren+pad+'</nobr></td></tr>\n';
            for (var i = 0; i < numRooms; i++) {
                x += '<tr><td'+cellStyle+'>';
                if (i == 0) {
                    x += renderRoomSelect();
                } else {
                    x += '&nbsp;';
                }
                x += '</td>';
                if (numRooms > 1) {
                    x += '<td'+cellStyle+'><nobr>'+getValue(textRoomX, i+1)+pad + '</nobr></td>';
                }
                x += '<td'+cellStyle+'>';
                x += buildSelect('room-' + i + '-adult-total', 'setNumAdults(' + i + ', this.options[this.selectedIndex].value)', 1, 4, adultsPerRoom[i]);
                x += '</td><td'+cellStyle+'>';
                x += buildSelect('room-' + i + '-child-total', 'setNumChildren(' + i + ', this.options[this.selectedIndex].value)', 0, 6, childrenPerRoom[i]);
                x += '</td></tr>\n';
            }
            x += '</table>\n';

            var didHeader = false;
            for (var i = 0; i < numRooms; i++) {
                if (childrenPerRoom[i] > 0) {
                    if (!didHeader) {
                        x += '<table border="0" cellpadding="0" cellspacing="2">\n';
                        x += '<tr><td'+cellStyle+' colspan="'+(maxChildren+1)+'">';
                        x += '<img src="/images/p.gif" width="1" height="5"><br>';
                        x += childHelp;
                        x += '<img src="/images/p.gif" width="1" height="5"><br>';
                        x += '</td></tr>\n<tr><td'+cellStyle+'>&nbsp;</td>';
                        for (var j = 0; j < maxChildren; j++) {
                            x += '<td'+cellStyle+'><nobr>'+getValue(textChildX, j+1)+pad+'</nobr></td>\n';
                        }
                        didHeader = true;
                    }
                    x += '</tr>\n<tr><td'+cellStyle+'><nobr>'+getValue(textRoomX, i+1)+pad+'</nobr></td>';
                    for (var j = 0; j < childrenPerRoom[i]; j++) {
                        x += '<td'+cellStyle+'>';
                        var def = -1;
                        if (childAgesPerRoom[i] != null) {
                            if (childAgesPerRoom[i][j] != null) {
                                def = childAgesPerRoom[i][j];
                            }
                        }
                        x += '<select name="room-'+i+'-child-'+j+'-age" onchange="setChildAge('+i+', '+j+', this.options[this.selectedIndex].value);">';
                        x += '<option value="-1"'+(def == -1 ? ' selected' : '')+'>-?-';
                        x += '<option value="0"'+(def == 0 ? ' selected' : '')+'>&lt;1';
                        for (var k = 1; k <= 18; k++) {
                            x += '<option value="'+k+'"'+(def == k ? ' selected' : '')+'>'+k;
                        }
                        x += '</td>';
                    }
                    if (childrenPerRoom[i] < maxChildren) {
                        for (var j = childrenPerRoom[i]; j < maxChildren; j++) {
                            x += '<td'+cellStyle+'>&nbsp;</td>';
                        }
                    }
                    x += '</tr>\n';
                }
            }
            if (didHeader) {
                x += '</table>\n';
            }
        }

        document.getElementById("hot-search-params").innerHTML = x;
    }

    function buildSelect(name, onchange, min, max, selected) {
        var x = '<select name="' + name + '"';
        if (onchange != null) {
            x += ' onchange="' + onchange + '"';
        }
        x +='>\n';
        for (var i = min; i <= max; i++) {
            x += '<option value="' + i + '"';
            if (i == selected) {
                x += ' selected';
            }

            x += '>' + i + '\n';
        }
        x += '</select>';
        return x;
    }

    function validateGuests(form) {
        if (numRooms < 9) {
            var missingAge = false;
            for (var i = 0; i < numRooms; i++) {
                var numChildren = childrenPerRoom[i];
                if (numChildren != null && numChildren > 0) {
                    for (var j = 0; j < numChildren; j++) {
                        if (childAgesPerRoom[i] == null || childAgesPerRoom[i][j] == null || childAgesPerRoom[i][j] == -1) {
                            missingAge = true;
                        }
                    }
                }
            }

            if (missingAge) {
                alert(textChildError);
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
    }

    function submitGuestInfoForm(form) {
        if (!validateGuests(form)) {
            return false;
        }
        return true;
    }

    function getValue(str, val) {
        return str.replace(/\?/g, val);
    }





