﻿// globals #######################################
ie = document.all ? true : false;
dom = document.getElementById ? true : false;
ns = document.layers ? true : false;
// #########################################

// these could be overridden by an ouside js file containing language specific month names
var monthnames_display = new Array("Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık");
var daynames_display = new Array( "P", "Pt", "S", "Ç", "P", "C", "Ct" );

// these are the english monthnames which we need for comparation against <option value>
var monthnames = new Array("Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık");
var daynames = new Array( "P", "Pt", "S", "Ç", "P", "C", "Ct" );
var monthdays  = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

// alert messages. these may be overridden by an outside js file containing language
// specific alerts
var activityEndAfterActivityStart="The activity end date must be later than the activity start date.";
var activityStartCurrentDateOrLater="The activity start date must be current date or later.";
var onlySearch365DaysInAdvance="You can only search for activities up to 365 days in advance.";

var selectedMonthYr = new Date()
var firstClick = true
var onCheckIn = 1 // 1 = on check in, 2 = on check out, 3 = on nothing
var searchCal = false;
var inBrowserCal;
var calForm;
var checkInName = "Check-in"
var checkOutName = "Check-out"
var forceEnglish = false;

function setSearchCal( v ) {
  searchCal = v;
}

function setOnCheckIn( val ) {
  onCheckIn = val
}

function updateIECheckIn( checkIn ) {
  if ( checkIn == null ) {
    if ( searchCal )
      return;
    else
      checkIn = (getCheckInDate() == null ? new Date() : getCheckInDate())
  }
  resize( calForm.checkInDay, checkIn )
  //if ( checkIn.getMonth() != selectedMonthYr.getMonth() && checkIn.getMonth() != selectedMonthYr.getMonth() + 1 )
    selectedMonthYr = checkIn
  setCheckInDate( checkIn )
  if ( getCheckOutDate() <= checkIn ) {
    setCheckOutDate( new Date( checkIn.getTime() + 86400000 ) )
    if(getCheckOutDate().getDay() == getCheckInDate().getDay()){
	setCheckOutDate( new Date( checkIn.getTime() + 90000000 ))
    }
    resize( calForm.checkOutDay, getCheckOutDate() )
    if ( getCheckOutDate().getMonth() >= selectedMonthYr.getMonth() + 2 ||
	 ( getCheckOutDate().getMonth() == 0 && getCheckOutDate().getFullYear() >= selectedMonthYr.getFullYear() + 1 ) ){
      selectedMonthYr = checkIn;
}
  } else if ( searchCal && getCheckOutDate() == null  ) {
  }
  redrawCalendar()
}

function updateNSCheckIn( checkIn ) {
  if ( checkIn == null ) {
    if ( searchCal )
      return;
    else
      checkIn = (getCheckInDate() == null ? new Date() : getCheckInDate())
  }
  setCheckInDate( checkIn )
  if ( getCheckOutDate() <= checkIn ){
    setCheckOutDate( new Date( checkIn.getTime() + 86400000 ) )
    if(getCheckOutDate().getDay() == getCheckInDate().getDay()){
        setCheckOutDate( new Date( checkIn.getTime() + 90000000 ))
    }
  }
  else if ( searchCal )
    setCheckOutDate( getCheckOutDate() )
}
  

function updateIECheckOut( checkOut ) {
  if ( checkOut == null ) {
    if ( searchCal )
      return;
    else
      checkOut = (getCheckOutDate() == null ? new Date( new Date().getTime() + 86400000 ) : getCheckOutDate() )
  }
  resize( calForm.checkOutDay, checkOut )
  setCheckOutDate( checkOut )
  redrawCalendar();
}

function updateNSCheckOut( checkOut ) {
  if ( checkOut == null ) {
    if ( searchCal )
      return;
    else
      checkOut = (getCheckOutDate() == null ? new Date( new Date().getTime() + 86400000 ) : getCheckOutDate() )
  }
  setCheckOutDate( checkOut )
}

function resize( select, date ) {
  var dim = getDaysInMonth( date.getMonth(), date.getFullYear() )
  var size = select.length
  if ( searchCal ) size = size - 1
  while ( dim != size ) {
    if ( dim > size ) {
      var opt = document.createElement( "OPTION" )
      select.add( opt )
      opt.innerText = size + 1
      opt.value = size + 1
    } else if ( dim < size ) {
      if ( searchCal ) size = size + 1
      select.remove( size - 1 )
    }
    size = select.length
    if ( searchCal ) size = size - 1
  }
}

function handleIECalClick( day, month, year ) {
  if ( onCheckIn == 1 ) {
    setOnCheckIn( firstClick ? 2 : 3 )
    updateCheckIn( new Date( year, month, day ) )
	if (calForm.los) {
    	getLOS(calForm.los.options[calForm.los.options.selectedIndex].value)
	}
  } else if ( onCheckIn == 2 ) {
    setOnCheckIn( 3 )
    updateCheckOut( new Date( year, month, day ) )
  } else {
    alert( "Please select either " + checkInName + " or " + checkOutName + " above the calendar." )
  }
  firstClick = false;
  if(!inBrowserCal) {
  calendarWindow.close()
  }
}

function handleNSCalClick( day, month, year ) {
  if ( onCheckIn == 1 ) {
    updateNSCheckIn( new Date( year, month, day ) )
    if (calForm.los) {
    	getLOS(calForm.los.options[calForm.los.options.selectedIndex].value)
	}
  } else {
    updateNSCheckOut( new Date( year, month, day ) )
  }
  if(!inBrowserCal) {
  calendarWindow.close()
  }
}

function moveForward() {
  if ( selectedMonthYr.getMonth() == 11 )
    selectedMonthYr = new Date( selectedMonthYr.getFullYear() + 1, 0, 1 )
  else
    selectedMonthYr = new Date( selectedMonthYr.getFullYear(), selectedMonthYr.getMonth() + 1, 1 )
  redrawCalendar()
}

function moveBack() {
  if ( selectedMonthYr.getMonth() == 0 )
    selectedMonthYr = new Date( selectedMonthYr.getFullYear() - 1, 11, 1 )
  else
    selectedMonthYr = new Date( selectedMonthYr.getFullYear(), selectedMonthYr.getMonth() - 1, 1 )
  redrawCalendar()
}

function generateCal() {
  var out = ""
  out += "<CENTER>Choose: "
  if ( onCheckIn == 1 )
    out += "<INPUT onClick=\"javascript:setOnCheckIn(1)\" type=\"radio\" name=\"checkInOut\" checked>" + checkInName + "&nbsp;"
  else
    out += "<INPUT onClick=\"javascript:setOnCheckIn(1)\" type=\"radio\" name=\"checkInOut\">" + checkInName + "&nbsp;"
  out += " | "
  if ( onCheckIn == 2 )
    out += "<INPUT onClick=\"javascript:setOnCheckIn(2)\" type=\"radio\" name=\"checkInOut\" checked>" + checkOutName
  else
    out += "<INPUT onClick=\"javascript:setOnCheckIn(2)\" type=\"radio\" name=\"checkInOut\">" + checkOutName
  out += "<table class=\"pad2\" cellpadding=0 cellspacing=0 border=0>"
  out += "<tr valign=top><td class=\"pad6\">" + generateMonth( selectedMonthYr.getMonth(), selectedMonthYr.getFullYear(), 1 ) + "</td>"
  var nextMonth = selectedMonthYr.getMonth() == 11 ? 0 : selectedMonthYr.getMonth() + 1
  var nextYear  = selectedMonthYr.getMonth() == 11 ? selectedMonthYr.getFullYear() + 1 : selectedMonthYr.getFullYear()
  out += "<td class=\"pad6\">" + generateMonth( nextMonth, nextYear, 2 ) + "</td></tr>"
  out += "</table>"
  out += "</CENTER>"
  return out
}

function generateNSMonth( month, year, prev_next ) {
  var out = ""
  out += "<table width=100% border=0 cellpadding=1 cellspacing=0><tr bgcolor=#d0d0d0>"
  out += "<td align=left>" + ( prev_next != 2 && displayMoveBack( month, year ) ? "<a href=\"javascript:opener.moveBack()\"><img width=16 height=12 border=0 src=\"http://www1.hilton.com//common/media/images/misc/cal_previous.gif\"></a>" : "&nbsp&nbsp" )
  
  out += "<td align=center><b>"
  out += forceEnglish ? monthnames[month] : monthnames_display[month] + " " + year +"</b>"
  out += "</td>"
  
  out += "<td align=right>" + ( prev_next != 1 && displayMoveForward( month, year ) ? "<a href=\"javascript:opener.moveForward()\"><img width=16 height=12 border=0 src=\"http://www1.hilton.com/common/media/images/misc/cal_next.gif\"></a>" : "&nbsp&nbsp" )
  out += "</tr></table>"

  out += "<table width=100% border=0 cellpadding=1 cellspacing=0>"
  out += "<tr>"
  for ( var i = 0 ; i < daynames.length ; i++ ) {
    out += "<td align=center>";
    out += forceEnglish ? daynames[i] : daynames_display[i]; 
    out += "</td>";
  }
  
  out += "</tr>"

  var fdom = getFirstDayOfMonth( month, year ) - 1
  var nd   = getDaysInMonth( month, year )

  var days_out = 0
  for ( var i = -fdom ; i <= nd ; i++ ) {

    if ( days_out == 0 )
      out += "<tr>"

    var dayClass = getDayClass( i, month, year )
    var isClickable = dayClass != "noselect-day"
    out += "<td align=center><font size=-1>"
    if ( isClickable )
      out += "<a href='javascript:opener.handleCalClick( " + i + ", " + month + ", " + year + ")'>"
    if ( i > 0 )
      out += i
    if ( isClickable )
      out += "</a>"
    out += "</font></td>"

    if ( days_out == 6 )
      out += "</tr>"

    if ( days_out == 6 )
      days_out = 0
    else
      days_out++
  }
  out += "</table>"

  return out;
}

function generateMonth( month, year, prev_next ) {

  var out = ""
  out += "<table border=0 cellpadding=1 cellspacing=0>"
  out += "<tr><td class=break colspan=7></td></tr>"
  out += "<tr>"
  out += "<td align=center class=month_header colspan=7>"
  out += "<table width=100% border=0 cellpadding=1 cellspacing=0><tr>"
  out += "<td class=prev_month align=left>" + ( prev_next != 2 && displayMoveBack( month, year ) ? "<a class=\"static_a\" href=\"javascript:moveBack()\"><img width=16 height=12 border=0 src=\"http://www1.hilton.com/common/media/images/misc/cal_previous.gif\"></a>" : "&nbsp&nbsp" )
  
  if (forceEnglish) {
  	out += "<td class=cal align=center><font class=month_header>" + monthnames[ month ] + " " + year + "</font>"
  } else {
  	out += "<td class=cal align=center><font class=month_header>" + monthnames_display[ month ] + " " + year + "</font>"
  }
  
  out += "<td class=cal align=center><font class=month_header>"
  out += forceEnglish ? monthnames[month] : monthnames_display[month]+ " " + year +"</font>"
  out += "</td>"
  
  out += "<td class=next_month align=right>" + ( prev_next != 1 && displayMoveForward( month, year ) ? "<a class=\"static_a\" href=\"javascript:moveForward()\"><img width=16 height=12 border=0 src=\"http://www1.hilton.com/common/media/images/misc/cal_next.gif\"></a>" : "&nbsp&nbsp" )
  out += "</tr></table>"
  out += "</td>"
  out += "</tr>"

  out += "<tr><td class=break colspan=7></td></tr>"

  out += "<tr>"
  
  for ( var i = 0 ; i < daynames.length ; i++ ) {
    out += "<td class=day_header>";
    out += forceEnglish ? daynames[i] : daynames_display[i]; 
    out += "</td>";
  }
    
  out += "</tr>"

  out += "<tr><td class=break colspan=7></td></tr>"

  var fdom = getFirstDayOfMonth( month, year ) - 1
  var nd   = getDaysInMonth( month, year )

  var days_out = 0
  for ( var i = -fdom ; i <= nd ; i++ ) {

    if ( days_out == 0 )
      out += "<tr>"

    var dayClass = getDayClass( i, month, year )
    var isClickable = dayClass != "noselect-day"
    var mout = "onMouseOut=\"javascript:this.className='" + dayClass + "'\""
    var min  = "onMouseOver=\"javascript:this.className='" + dayClass + "-mover'\""
    var onc = "onClick=\"javascript:handleCalClick( " + i + ", " + month + ", " + year + " )\""
    var all = isClickable ? ( " " + mout + " " + min + " " + onc ) : ""
    out += "<td class=" + dayClass + all + ">"
    if ( isClickable )
      out += "<a>"
    if ( i > 0 )
      out += i
    if ( isClickable )
      out += "</a>"
    out += "</td>"
   
    if ( days_out == 6 )
      out += "</tr>"

    if ( days_out == 6 )
      days_out = 0
    else
      days_out++
  }
  out += "</table>"

  return out
}

// returns true if we should display a "next month" icon for the given month, year
function displayMoveForward( month, year ) {
  var today = new Date()
  var parm  = new Date( year, month, 1 )
  return ( parm.getFullYear() == today.getFullYear() ) || 
           ( parm.getFullYear() > today.getFullYear() && parm.getMonth() < today.getMonth() );
}

// returns true if we should display a "previous month" icon for the given month, year
function displayMoveBack( month, year ) {
  var today = new Date()
  var parm  = new Date( year, month, 1 )
  return ( parm.getFullYear() == today.getFullYear() && parm.getMonth() > today.getMonth() ) ||
           parm.getFullYear() > today.getFullYear();
}

function getFirstDayOfMonth( month, year ) {
  var day = new Date( year, month, 1 )
  return day.getDay()
}

function getDaysInMonth( month, year ) {
  if ( month == 1 )
    return isLeapYear( year ) ? 29 : 28
  else
    return monthdays[ month ]
}

function isLeapYear( year ) {
  return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0
}

function getIEDayClass( day, month, year ) {
  if ( day < 1 )
    return "noselect-day"
  var checkInDate = getCheckInDate()
  var checkOutDate = getCheckOutDate()

  var today = new Date()
  var nyr = new Date( today.getTime() + (86400000 * 365) )
  var selectedDay = new Date( year, month, day + 1 )
  var lastSelectedDay = new Date( year, month, day )

  if ( selectedDay < today )
    return "noselect-day"

  if ( selectedDay > nyr )
    return "noselect-day"

  if ( selectedDay > checkInDate && lastSelectedDay <= checkOutDate )
    return "selected-day"
  
  return "day"
}

function getNSDayClass( day, month, year ) {
  if ( day < 1 )
    return "noselect-day"

  var today = new Date()
  var nyr = new Date( today.getTime() + (86400000 * 365) )
  var selectedDay = new Date( year, month, day + 1 )
  var lastSelectedDay = new Date( year, month, day )

  if ( selectedDay < today )
    return "noselect-day"

  if ( selectedDay > nyr )
    return "noselect-day"

  return "day"
}

function setInBrowserCal( ibc ) {
  inBrowserCal = ibc
  if ( ibc ) {
    handleCalClick = handleIECalClick
    getDayClass = getIEDayClass
    updateCheckIn = updateIECheckIn
    updateCheckOut = updateIECheckOut
  } else {
    handleCalClick = handleNSCalClick
    getDayClass = getNSDayClass
    updateCheckIn = updateNSCheckIn
    updateCheckOut = updateNSCheckOut
  }
}

function redrawCalendar() {
  if ( inBrowserCal ) {
    var newCal = generateCal()
    calendar.innerHTML = newCal
  } else {
    generateCalendar( calendarWindow )
  }
}

var calendarWindow
function createCalendar( ci ) {
  onCheckIn = ci
  selectedMonthYr = ( onCheckIn == 1 ) ? getCheckInDate() : getCheckOutDate()

  if ( selectedMonthYr == null )
    selectedMonthYr = new Date()
  if ( ie ) {
    topABC = window.screenTop + 100
    leftABC = window.screenLeft + 250
  } else {
    topABC = window.screenY + 100
    leftABC = window.screenX + 250
  }
  calendarWindow = window.open("","Takvim","width=166,height=160,resizable=yes,scrollbars=no,status=no,top=" + topABC + ",left=" + leftABC )
  generateCalendar( calendarWindow )
  calendarWindow.focus()
}

function generateCalendar( target ) {
  target.document.open()
  var nextMonth = selectedMonthYr.getMonth() == 11 ? 0 : selectedMonthYr.getMonth() + 1
  var nextYear  = selectedMonthYr.getMonth() == 11 ? selectedMonthYr.getFullYear() + 1 : selectedMonthYr.getFullYear()
  var calStuff = "<html><head><title>Takvim</title></head>"
  calStuff += "<body bgcolor=#ffffff topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><center>"
  calStuff += generateNSMonth( selectedMonthYr.getMonth(), selectedMonthYr.getFullYear(), 3 )
  calStuff += "</center></body></html>"
  target.document.write( calStuff )
  target.document.close()
}

function getCheckInDate() {
  var day =  calForm.checkInDay.options[calForm.checkInDay.selectedIndex].value
  var month = calForm.checkInMonthYr.options[calForm.checkInMonthYr.selectedIndex].value
  if ( day == -1 || month == "" ) {
		return null;
	}
  else if (month == "-1") {
		return null;
	}
  month = month.substring( 0, month.indexOf( " " ) )
  var year = calForm.checkInMonthYr.options[calForm.checkInMonthYr.selectedIndex].value
  year = year.substring( year.indexOf( " " ) + 1, year.length )
  if ( !( month >= 0 && month <= 12 ) )
    for ( var j = 0 ; j < monthnames.length ; j++ )
      if ( monthnames[ j ] == month )
        month = j
  // if "31 Feb" is selected in the drop down, doing new Date( 31 feb ) will create a date on
  // march 1/2/3 or thereabouts.  this is a workaround:
  var date = new Date( year, month, day )
  if ( month != date.getMonth() )
    date = new Date( year, month, getDaysInMonth( month, year ) - 1 )
  return date
}

function setCheckInDate( checkIn ) {
  for ( var i = 0 ; i < calForm.checkInDay.options.length ; i++ )
    if ( calForm.checkInDay.options[ i ].value == checkIn.getDate() )
      calForm.checkInDay.options[ i ].selected = true;
  var moyear = monthnames[ checkIn.getMonth() ] + " " + checkIn.getFullYear()
  for ( var i = 0 ; i < calForm.checkInMonthYr.options.length ; i++ )
    if ( calForm.checkInMonthYr.options[ i ].value == moyear )
      calForm.checkInMonthYr.options[ i ].selected = true
      
  copyToFlex();
}

function getCheckOutDate() {
  var day = calForm.checkOutDay.options[calForm.checkOutDay.selectedIndex].value
  var month = calForm.checkOutMonthYr.options[calForm.checkOutMonthYr.selectedIndex].value

  if ( day == -1 || month == "" ) {
        return null;
	}
  else if (month == "-1") {
        return null;
	}
  month = month.substring( 0, month.indexOf( " " ) )
  var year = calForm.checkOutMonthYr.options[calForm.checkOutMonthYr.selectedIndex].value
  year = year.substring( year.indexOf( " " ) + 1, year.length )
  if ( !( month >= 0 && month <= 12 ) )
    for ( var j = 0 ; j < monthnames.length ; j++ )
      if ( monthnames[ j ] == month )
        month = j
  // if "31 Feb" is selected in the drop down, doing new Date( 31 feb ) will create a date on
  // march 1/2/3 or thereabouts.  this is a workaround:
  var date = new Date( year, month, day )
  if ( month != date.getMonth() )
    date = new Date( year, month, getDaysInMonth( month, year ) )
  return date
}

function setCheckOutDate( checkOut ) {
  for ( var i = 0 ; i < calForm.checkOutDay.options.length ; i++ )
    if ( calForm.checkOutDay.options[ i ].value == checkOut.getDate() )
      calForm.checkOutDay.options[ i ].selected = true;
  var moyear = monthnames[ checkOut.getMonth() ] + " " + checkOut.getFullYear()

  for ( var i = 0 ; i < calForm.checkOutMonthYr.options.length ; i++ )
    if ( calForm.checkOutMonthYr.options[ i ].value == moyear )
      calForm.checkOutMonthYr.options[ i ].selected = true
}

function setCalForm( f ) {
	calForm = f;
}

function setup() {
  if ( calForm == null ) calForm = document.main;
  if ( inBrowserCal ) {
    updateCheckIn( getCheckInDate() )
    updateCheckOut( getCheckOutDate() )
    redrawCalendar()
  }
}

setInBrowserCal( (document.all && navigator.appVersion.toUpperCase().indexOf( "MSIE" ) != -1) ? 1 : 0 )


function validateDates() {
  var cid = getCheckInDate()
  var cod = getCheckOutDate()
  var tod = new Date()
  var yes = new Date( tod - 86400000 )
  var nyr = new Date( tod + (86400000 * 365) )

if ( cid == null || cod == null ) {
 return true;
}
else {
if ( cod <= cid )
    alert(activityEndAfterActivityStart)
  else if ( cid < yes )
    alert(activityStartCurrentDateOrLater)
  else if ( cod > nyr || cid > nyr )
    alert(activityStartCurrentDateOrLater)
  else
  return true
 return false
 }

}
function performAvailSearch()
{
    if (checkNoDate('availSearch','checkIn','checkOut') && checkDate('availSearch','checkIn','checkOut')){document.availSearch.submit()}
}

function performRewardSearch()
{
    if (checkNoDate('rewardSearch','checkIn','checkOut') && checkDate('rewardSearch','checkIn','checkOut')){document.rewardSearch.submit()}
}

function copyToFlex() {
	if (calForm.flexCheckInDay) {
		calForm.flexCheckInDay.value=calForm.checkInDay.value;
	}
	
	if (calForm.flexCheckInMonthYr) {
		calForm.flexCheckInMonthYr.value=calForm.checkInMonthYr.value;
	}
}

function copyToFixed() {
	if (calForm.flexCheckInDay) {
		calForm.checkInDay.value=calForm.flexCheckInDay.value;
	}
	
	if (calForm.flexCheckInMonthYr) {
		calForm.checkInMonthYr.value=calForm.flexCheckInMonthYr.value;
	}
}
/*to make sure use does not select dates in the past or that check-out date is not before check-in - jkenney*/

// alert messages. These could be overridden by an outside js file containing
// language specific messages
var startDateNotPastDateMessage="Please revise your dates. Start date cannot be a past date.";
var eventStartDateNotPastDateMessage="Event Start date cannot be a past date";
var checkInDateNotPastDateMessage="Please revise your dates. Check-in date cannot be a past date.";
var dateLimit12MonthsMessage="Please enter dates within the next 12 months.";
var dateLimit365DaysMessage="Your travel dates must not be greater than 365 days in advance. Please enter new dates and try again.";
var eventEndAfterEventStartMessage="Event End date must be after Event Start date.";
var checkOutAfterCheckInMessage="Check-out date must be later than Check-in date";
var pleaseEnterStartDateMessage="Please enter a Start date";
var pleaseEnterValidDatesMessage="Please enter valid dates";
var groups3DaysFromTodayMessage="Please choose an Event Start Date more than 3 days from today. If you need to book a Group Event that is less than 3 days from today, please contact the hotel directly.";
var groups14DayLimitMessage="Please enter a date range of 14 days or less if you would like to book online.  If you need to book a group for more than 14 days, please leave dates blank for hotel search. Then, submit a Request for Proposal.";

// if forceEnglish (stored in cal.js) is true, then we will use these messages, which should 
// not be overridden
var startDateNotPastDateMessage_en="Start date cannot be a past date";
var eventStartDateNotPastDateMessage_en="Event Start date cannot be a past date";
var checkInDateNotPastDateMessage_en="Check-in date cannot be a past date";
var dateLimit12MonthsMessage_en="Please enter dates within the next 12 months.";
var dateLimit365DaysMessage_en="Your travel dates must not be greater than 365 days in advance. Please enter new dates and try again.";
var eventEndAfterEventStartMessage_en="Event End date must be after Event Start date.";
var checkOutAfterCheckInMessage_en="Check-out date must be later than Check-in date";
var pleaseEnterStartDateMessage_en="Please enter a Start date";
var pleaseEnterValidDatesMessage_en="Please enter valid dates";
var groups3DaysFromTodayMessage_en="Please choose an Event Start Date more than 3 days from today. If you need to book a Group Event that is less than 3 days from today, please contact the hotel directly.";
var groups14DayLimitMessage_en="Please enter a date range of 14 days or less if you would like to book online.  If you need to book a group for more than 14 days, please leave dates blank for hotel search. Then, submit a Request for Proposal.";


function checkDate(formName,checkin,checkout,issmallgroups) {

	var x = eval("document."+formName);
	var checkinDay = parseInt(x[checkin+"Day"].options[x[checkin+"Day"].selectedIndex].value);
	var checkinMonthYr = x[checkin+"MonthYr"].options[x[checkin+"MonthYr"].selectedIndex].value;
	var checkinMonth = checkinMonthYr.substring(0,3);
	var checkinYear = checkinMonthYr.substring(checkinMonthYr.indexOf(" "),checkinMonthYr.length);
	var checkoutDay = parseInt(x[checkout+"Day"].options[x[checkout+"Day"].selectedIndex].value);
	var checkoutMonthYr = x[checkout+"MonthYr"].options[x[checkout+"MonthYr"].selectedIndex].value;
	var checkoutMonth = checkoutMonthYr.substring(0,3);
	var checkoutYear = checkoutMonthYr.substring(checkoutMonthYr.indexOf(" "),checkoutMonthYr.length);
	
	var checkinMonthNum = getMonthNum(checkinMonth);
	var checkoutMonthNum = getMonthNum(checkoutMonth);
		
	var now = new Date();
	var currentDay = now.getDate();
	var currentMonth = now.getMonth()+1;
	var currentYear = now.getFullYear();

	/*debug
	alert("checkinYear: "+checkinYear);
	alert("currentYear: "+currentYear);
	alert(currentYear+1);
	alert("checkinMonthNum: "+checkinMonthNum);
	alert("currentMonth: "+currentMonth);
	alert("checkinDay: "+checkinDay);
	alert("currentDay: "+currentDay);
	alert("checkoutMonthNum: "+checkinMonthNum);
	alert("checkoutDay: "+checkinDay);
	*/

	if( (checkinDay != "-1") || (checkinMonthYr != "") ) {
		if (checkinYear <= currentYear && checkoutYear <= currentYear) {
			if ( (checkinMonthNum < currentMonth) || (checkinMonthNum <= currentMonth && checkinDay < currentDay) ) {
				if(x.flexibleSearch && x.flexibleSearch.value=="true") {
					alert (forceEnglish ? startDateNotPastDateMessage_en  : startDateNotPastDateMessage); 
					return false;
				}
                else if ( issmallgroups ) {
					alert (forceEnglish ? eventStartDateNotPastDateMessage_en : eventStartDateNotPastDateMessage); 
					return false;
                } 
				else {
					alert (forceEnglish ? checkInDateNotPastDateMessage_en  : checkInDateNotPastDateMessage ); 
					return false;
				}
			}
		}
		// we now make sure the checkout date is also with 365 days - as of May 2006 
		if (checkinYear == currentYear+1 && ((checkinMonthNum >= currentMonth && checkinDay >= currentDay) ||
                                         (checkoutMonthNum >= currentMonth && checkoutDay > currentDay))) {
                if ( issmallgroups ) {
				    alert (forceEnglish ? dateLimit12MonthsMessage_en : dateLimit12MonthsMessage);
                } else {
				    alert (forceEnglish ? dateLimit365DaysMessage_en : dateLimit365DaysMessage);
                }
				return false;
			}
		if(checkoutDay != '-1') {
			if ( (checkoutMonthNum < checkinMonthNum && checkoutYear <= checkinYear) || (checkoutMonthNum == checkinMonthNum && checkoutDay <= checkinDay && checkoutYear <= checkinYear) ) {
				if ( issmallgroups ) {
					alert (forceEnglish ? eventEndAfterEventStartMessage_en : eventEndAfterEventStartMessage);
				} else {
					alert (forceEnglish ? checkOutAfterCheckInMessage_en : checkOutAfterCheckInMessage);
				}
				return false;
			}
		}
		if(!(x.flexibleSearch && x.flexibleSearch.value=="true")) {

			if (checkoutYear < checkinYear) {
				if ( issmallgroups ) {
					alert (forceEnglish ? eventEndAfterEventStartMessage_en : eventEndAfterEventStartMessage);
				} else {
					alert (forceEnglish ? pleaseEnterValidDatesMessage_en : pleaseEnterValidDatesMessage);
				}
				return false;
			}
			else {
				return true;
			}
		}
		else {
			/* for the flexible search, they must enter data before continuing */
       if (checkNoDate(formName,'checkIn','checkOut')) {
  		 		return true;
       } else {
	        return false;
       }
		}
	}
	else {
		return true;
	}
	
}

function getMonthNum(month) 
{
	var monthNames = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var pattern = month;
	
		for (i=0; i<monthNames.length; i++) {
			if (monthNames[i].match(pattern)) {
				var monthNum = i+1;
				break;
			}
		}
		
		return monthNum;
}

/* to make sure the user enters dates for availibility search - jkenney*/
function checkNoDate(formName,checkin,checkout) {

	var x = eval("document."+formName);
	var checkinDay = parseInt(x[checkin+"Day"].options[x[checkin+"Day"].selectedIndex].value);
	var checkinMonthYr = x[checkin+"MonthYr"].options[x[checkin+"MonthYr"].selectedIndex].value;
	var checkinMonth = checkinMonthYr.substring(0,3);
	var checkinYear = checkinMonthYr.substring(checkinMonthYr.indexOf(" "),checkinMonthYr.length);
	var checkoutDay = parseInt(x[checkout+"Day"].options[x[checkout+"Day"].selectedIndex].value);
	var checkoutMonthYr = x[checkout+"MonthYr"].options[x[checkout+"MonthYr"].selectedIndex].value;
	var checkoutMonth = checkoutMonthYr.substring(0,3);
	var checkoutYear = checkoutMonthYr.substring(checkoutMonthYr.indexOf(" "),checkoutMonthYr.length);
	
	if ((checkinDay == "-1" || checkinMonthYr == "-1") ||(checkoutDay == "-1" || checkoutMonthYr == "-1")) {
		if(x.flexibleSearch && x.flexibleSearch.value=="true") {
			//alert("entered flexiblesearch");
			alert (forceEnglish ? pleaseEnterValidDatesMessage_en : pleaseEnterValidDatesMessage); 
			return false;
		}
		else {
			//alert("entered fixedsearch");
			alert (forceEnglish ? pleaseEnterValidDatesMessage_en : pleaseEnterValidDatesMessage);
			return false;
		}
	}
	else{
		return true;
	}
}

function isWithinNumDays(date1, date2, numday) {
	/* 1 day = 86400000 msec */
	//alert(date1+" "+date2+" "+numday);
	return (date2.getTime() >= date1.getTime() && (date2.getTime()-date1.getTime()) < 86400000*numday+1);
}

/* check date for groups search */
function checkGroupsDate(formName,checkin,checkout) {
	var now = new Date();
	var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
	var x = eval("document."+formName);
	var checkinDay = parseInt(x[checkin+"Day"].options[x[checkin+"Day"].selectedIndex].value);
	var checkinMonthYr = x[checkin+"MonthYr"].options[x[checkin+"MonthYr"].selectedIndex].value;
	var checkinMonth = checkinMonthYr.substring(0,3);
	var checkinYear = checkinMonthYr.substring(checkinMonthYr.indexOf(" "),checkinMonthYr.length);
	var checkoutDay = parseInt(x[checkout+"Day"].options[x[checkout+"Day"].selectedIndex].value);
	var checkoutMonthYr = x[checkout+"MonthYr"].options[x[checkout+"MonthYr"].selectedIndex].value;
	var checkoutMonth = checkoutMonthYr.substring(0,3);
	var checkoutYear = checkoutMonthYr.substring(checkoutMonthYr.indexOf(" "),checkoutMonthYr.length);
	
	var checkinDateToCheck = new Date(checkinYear, getMonthNum(checkinMonth)-1, checkinDay);
	var checkoutDateToCheck = new Date(checkoutYear, getMonthNum(checkoutMonth)-1, checkoutDay);
	
	if (checkDate(formName,checkin,checkout,true)) {
		if (checkinDay == "-1" || checkinDay == "" || checkoutDay == "-1" || checkoutMonthYr == "") {
			return true;
		} else {
			if (isWithinNumDays(checkinDateToCheck, checkoutDateToCheck, 14)) {
				if (!isWithinNumDays(today, checkinDateToCheck, 3)) {
					return true;
				} else {
					alert (forceEnglish ? groups3DaysFromTodayMessage_en : groups3DaysFromTodayMessage);
					return false;
				}
			} else {
				alert (forceEnglish ? groups14DayLimitMessage_en : groups14DayLimitMessage);
				return false;
			}
		}
	} else {
		return false;
	}
}
var formName;
var monthVal = new Array();
	
	monthVal["Jan"] = "0"
	monthVal["Feb"] = "1";
	monthVal["Mar"] = "2";
	monthVal["Apr"] = "3";
	monthVal["May"] = "4";
	monthVal["Jun"] = "5";
	monthVal["Jul"] = "6";
	monthVal["Aug"] = "7";
	monthVal["Sep"] = "8";
	monthVal["Oct"] = "9";
	monthVal["Nov"] = "10";
	monthVal["Dec"] = "11";
    
    
// alert messages. These could be overridden by an outside js file containing
// language specific messages /{locale/common/js/flex_dates.js
var rewardRedemption9NightLimitMessage="There is a 9-night limit on reward redemption. Please change your selected dates.";
var missingAirportMessage = "Please enter the aiport code or city, state, and/or country.";
var addressStateCountryMessage="Please enter an address and city/state inside the U.S.A. or a country outside the U.S.A.";
var airportStateCountryMessage="Please enter an aiport code or city, state inside the U.S.A, and/or country.";
var attractionStateCountryMessage="Please enter an attraction name, state inside the U.S.A, and/or country.";
var cityStateCountryMessage="Please enter a city/state inside the U.S.A. or a country outside the U.S.A.";

// if forceEnglish (stored in cal.js) is true, we will use these error messages which should not be overriden
var rewardRedemption9NightLimitMessage_en="There is a 9-night limit on reward redemption. Please change your selected dates.";
var missingAirportMessage_en = "Please enter the aiport code or city, state, and/or country.";
var addressStateCountryMessage_en="Please enter an address and city/state inside the U.S.A. or a country outside the U.S.A.";
var airportStateCountryMessage_en="Please enter an aiport code or city, state inside the U.S.A, and/or country.";
var attractionStateCountryMessage_en="Please enter an attraction name, state inside the U.S.A, and/or country.";
var cityStateCountryMessage_en="Please enter a city/state inside the U.S.A. or a country outside the U.S.A.";

function getLOS(los) {

	//alert(formName) // defined in jhtml page;
	//alert(los);
	var dayIndex = document.forms[formName].checkInDay.selectedIndex;
	var monthIndex = document.forms[formName].checkInMonthYr.options.selectedIndex;
	var day = document.forms[formName].checkInDay.options[dayIndex].value;
	var month = document.forms[formName].checkInMonthYr.options[monthIndex].value.substring(0,3);
	var year = document.forms[formName].checkInMonthYr.options[monthIndex].value.substring(document.forms[formName].checkInMonthYr.options[monthIndex].value.indexOf(" "),document.forms[formName].checkInMonthYr.options[monthIndex].value.length);
	
	//alert (day);
	//alert (month);
	//alert (year);

	var inDate = new Date( year,monthVal[month],day );
	inDate.setHours(12);
	//alert(inDate.getTime());
	var outDate = new Date( inDate.getTime() + (86400000 * los) );
	outDate.setHours(12);
	//alert(outDate.getTime());
	//alert(los);
	if( day != '-1' && month !='-1' )  {
		document.forms[formName].checkOutDay.value = outDate.getDate();
		//alert(outDate.getDate());
		document.forms[formName].checkOutMonthYr.value = dateToMonthYr( outDate );
		//alert(los);
	}
	
}

function reflectLOS(los) {

	//alert(formName) // defined in jhtml page;
	
	//alert(los);
	var inDayIndex = document.forms[formName].checkInDay.selectedIndex;
	var inMonthIndex = document.forms[formName].checkInMonthYr.options.selectedIndex;
	var inDay = document.forms[formName].checkInDay.options[inDayIndex].value;
	var inMonth = document.forms[formName].checkInMonthYr.options[inMonthIndex].value.substring(0,3);
	var inYear = document.forms[formName].checkInMonthYr.options[inMonthIndex].value.substring(document.forms[formName].checkInMonthYr.options[inMonthIndex].value.indexOf(" "),document.forms[formName].checkInMonthYr.options[inMonthIndex].value.length);

	var outDayIndex = document.forms[formName].checkOutDay.selectedIndex;
	var outMonthIndex = document.forms[formName].checkOutMonthYr.options.selectedIndex;
	var outDay = document.forms[formName].checkOutDay.options[outDayIndex].value;
	var outMonth = document.forms[formName].checkOutMonthYr.options[outMonthIndex].value.substring(0,3);
	var outYear = document.forms[formName].checkOutMonthYr.options[outMonthIndex].value.substring(document.forms[formName].checkOutMonthYr.options[outMonthIndex].value.indexOf(" "),document.forms[formName].checkOutMonthYr.options[outMonthIndex].value.length);
	

	var inDate2 = new Date( inYear,monthVal[inMonth],inDay );
	inDate2.setHours(12);
	//alert(inDate.getTime());
	var outDate2 = new Date( outYear,monthVal[outMonth],outDay );
	outDate2.setHours(12);
	//alert(outDate.getTime());
	var diff = 0; 
    tmp_diff = (outDate2.getTime() - inDate2.getTime()) / 86400000;
    diff = parseInt(tmp_diff); 
	//alert(diff);

	var monthname=new Array("Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık");
            var next_date = new Date( inYear,monthVal[inMonth],Number(inDay) + 1 );  
                
    	diff = parseInt(tmp_diff); 
    
             if (inDay != '-1' && outDay != '-1') {            
                     if (diff <= 0) {          
    			 document.forms[formName].los.value = 1; 
                             document.forms[formName].checkOutMonthYr.value = monthname[next_date.getMonth()]+" "+next_date.getFullYear(); 
                             document.forms[formName].checkOutDay.value = next_date.getDate(); 
                       } 
                       else if (diff <= 14) { 
    
                            document.forms[formName].los.value = diff;
                    }
                    else {
                           document.forms[formName].los.value = "14";
                   }
           }
	
}

function checkLOSLimit() {


	var inDayIndex2 = document.forms[formName].checkInDay.selectedIndex;
	var inMonthIndex2 = document.forms[formName].checkInMonthYr.options.selectedIndex;
	var inDay2 = document.forms[formName].checkInDay.options[inDayIndex2].value;
	var inMonth2 = document.forms[formName].checkInMonthYr.options[inMonthIndex2].value.substring(0,3);
	var inYear2 = document.forms[formName].checkInMonthYr.options[inMonthIndex2].value.substring(document.forms[formName].checkInMonthYr.options[inMonthIndex2].value.indexOf(" "),document.forms[formName].checkInMonthYr.options[inMonthIndex2].value.length);
	
	var outDayIndex2 = document.forms[formName].checkOutDay.selectedIndex;
	var outMonthIndex2 = document.forms[formName].checkOutMonthYr.options.selectedIndex;
	var outDay2 = document.forms[formName].checkOutDay.options[outDayIndex2].value;
	var outMonth2 = document.forms[formName].checkOutMonthYr.options[outMonthIndex2].value.substring(0,3);
	var outYear2 = document.forms[formName].checkOutMonthYr.options[outMonthIndex2].value.substring(document.forms[formName].checkOutMonthYr.options[outMonthIndex2].value.indexOf(" "),document.forms[formName].checkOutMonthYr.options[outMonthIndex2].value.length);
	
	
	var inDate2 = new Date( inYear2,monthVal[inMonth2],inDay2 );
	inDate2.setHours(12);
	//alert(inDate.getTime());
	var outDate2 = new Date( outYear2,monthVal[outMonth2],outDay2 );
	outDate2.setHours(12);
	//alert(outDate.getTime());
	var tmp_diff2 = 0; 
	var diff2 = 0; 
	tmp_diff2 = (outDate2.getTime() - inDate2.getTime()) / 86400000;
	diff2 = parseInt(tmp_diff2); 

	if (outDay2 != '-1') {

		if (diff2 > 9) {
			alert(forceEnglish ? rewardRedemption9NightLimitMessage_en : rewardRedemption9NightLimitMessage);
			return false;
		}
		else {

			return true;
		}
	}
}

function dateToMonthYr( date )
{

	var string = monthnames[ date.getMonth() ] + " " + date.getFullYear();

	//alert(string);
	return string;
}

function setFlexSearch(value) {
	if (document.forms[formName].flexibleSearch) {
		document.forms[formName].flexibleSearch.value=value;
	}
}

function checkFlexSearch(formName) {

var flexSearch = document.forms[formName].flexibleSearch;
var losIndex = document.forms[formName].los.options.selectedIndex;
var losVal = document.forms[formName].los.options[losIndex].value;

	if (flexSearch.value == "true") {
		
		getLOS(losVal);
		
	}
}

function checkFlexSearchNoDates (formName) {

var flexSearch = document.forms[formName].flexibleSearch;

	if (flexSearch.value == "true") {
		
		if (checkNoDate(formName,'checkIn','checkOut')) {
			return true;
		}
		else {
			return false;
		}
	}
	else {
		return true;
	}
}

function checkBrandsToSearch(formName)
{
	var brandsIndex = document.forms[formName].brands.selectedIndex;
	var brandsVal = document.forms[formName].brands[brandsIndex].value;

	if (brandsVal == "true" || brandsVal == "")
	{
		document.forms[formName].searchAll.value = "true";
	}
}

function validateRewardSearch(formName) {

var countryIndex = document.forms[formName].country.selectedIndex
var countryVal = document.forms[formName].country[countryIndex].value
var stateIndex = document.forms[formName].state.selectedIndex
var stateVal = document.forms[formName].state[stateIndex].value

	//checkDate function in date_check.js

	if (checkDate(formName,'checkIn','checkOut')) {

		if (checkHRRStateCountry(formName, countryVal, stateVal)) {
		
			if (document.forms[formName].flexibleSearch.value=="true") {
				

				getLOS(document.forms[formName].los.options[document.forms[formName].los.options.selectedIndex].value);

				if (checkFlexSearchNoDates(formName)) {

					if (checkLOSLimit()) {
										
						document.forms[formName].submit();
					}				
				}
			}
			else {	

					document.forms[formName].submit();
			}
		}
	}
}


function validateHotelRewardSearch(formName) {

	//checkDate function in date_check.js
	if (checkDate(formName,'checkIn','checkOut')) {
		
		if (document.forms[formName].flexibleSearch.value=="true") {
				
				getLOS(document.forms[formName].los.options[document.forms[formName].los.options.selectedIndex].value);
									
			if (checkFlexSearchNoDates(formName)) {

				if (checkLOSLimit()) {
									
					document.forms[formName].submit();
				}
					
			}
		}
			
		else {
		
				document.forms[formName].submit();
		}
	}
}

function validateHomeSearch(formName) {

// this is pretty much the same as validateRewardSearch, but there is no LOS limit

var countryIndex = document.forms[formName].country.selectedIndex
var countryVal = document.forms[formName].country[countryIndex].value
var stateIndex = document.forms[formName].state.selectedIndex
var stateVal = document.forms[formName].state[stateIndex].value

var guestSuitesIndex
var guestSuitesValue
var tempCheck = document.forms[formName].guestSuitesFixed.selectedIndex
if(tempCheck != null && tempCheck != 'null' && tempCheck != 'undefined' )
{
	guestSuitesIndex = document.forms[formName].guestSuitesFixed.selectedIndex
	guestSuitesValue = document.forms[formName].guestSuitesFixed[guestSuitesIndex].value 
}
else
{
	guestSuitesIndex = 0
	guestSuitesValue = document.forms[formName].guestSuitesFlex[0].value 
}

var action;

	document.forms[formName].hdnGuestSuitsIndex.value = guestSuitesIndex;
		
	document.forms[formName].hdnGuestSuits.value = guestSuitesValue;
	
	if(guestSuitesValue > 1)
	{
		action = document.forms[formName].hdnMedAction.value
		document.forms[formName].action = action+'?it='+document.forms[formName].it.value;
	}
	else
	{
		action = document.forms[formName].hdnMainAction.value
		document.forms[formName].action = action+'?it='+document.forms[formName].it.value;
	}
	
	if (checkDate(formName,'checkIn','checkOut')) {
		
		if (checkStateCountry(formName, countryVal, stateVal)) {

			if (document.forms[formName].flexibleSearch.value=="true") {

				getLOS(document.forms[formName].los.options[document.forms[formName].los.options.selectedIndex].value);

				if (checkFlexSearchNoDates(formName)) {
					document.forms[formName].submit();
				}
			}
			else {	
					
					document.forms[formName].submit();
			}
		}
		
	}
}

function validateChangeSearch(formName) {

// this is pretty much the same as validateRewardSearch, but there is no LOS limit

var countryIndex = document.forms[formName].country.selectedIndex
var countryVal = document.forms[formName].country[countryIndex].value
var stateIndex = document.forms[formName].state.selectedIndex
var stateVal = document.forms[formName].state[stateIndex].value

//copySelectedCtyhocns(formName);

	var checkboxes = document.forms[formName].selectedHotels;
	var ctyhocns = "";

	if (checkboxes) {
		if (checkboxes.length) {
			// there are an array of checkboxes, loop through them
			for (var i = 0; i < checkboxes.length; i++) {
				if (checkboxes[i].checked) {
					ctyhocns = ctyhocns + checkboxes[i].value + ",";
				}
			}
		} else {
			// there is only one checkbox, get it's value
			if (checkboxes.checked) {
				ctyhocns = checkboxes.value + ",";
			}
		}
	}
	
	document.forms[formName].selectedHotels.value= ctyhocns.substring( 0, ctyhocns.length - 1 );


	if (checkDate(formName,'checkIn','checkOut')) {

		if (checkChangeStateCountry(formName, countryVal, stateVal)) {
		
			if (document.forms[formName].flexibleSearch.value=="true") {
				
				getLOS(document.forms[formName].los.options[document.forms[formName].los.options.selectedIndex].value);

				if (checkFlexSearchNoDates(formName)) {

						document.forms[formName].submit();
				}
			}
			else {	

					document.forms[formName].submit();
			}
		}
		else {
			return false;
		}
	}
}

function validateAdvancedSearch(formName) {

// used by the advanced hotel search page's city tab

var countryIndex = document.forms[formName].country.selectedIndex
var countryVal = document.forms[formName].country[countryIndex].value
var stateIndex = document.forms[formName].state.selectedIndex
var stateVal = document.forms[formName].state[stateIndex].value

	//checkDate function in date_check.js

	if (checkDate(formName,'checkIn','checkOut')) {

		if (checkStateCountry(formName, countryVal, stateVal)) {
		
			if (document.forms[formName].flexibleSearch.value=="true") {
				

				getLOS(document.forms[formName].los.options[document.forms[formName].los.options.selectedIndex].value);

				if (checkFlexSearchNoDates(formName)) {

					document.forms[formName].submit();

				}
			}
			else {	

					document.forms[formName].submit();
			}
		}
	}
}

function validateAdvancedAirportSearch(formName) {

// used by the advanced hotel search page's airport tab
// that form doesn't have 'city', but instead has an 'airport' field

var countryIndex = document.forms[formName].country.selectedIndex
var countryVal = document.forms[formName].country[countryIndex].value
var stateIndex = document.forms[formName].state.selectedIndex
var stateVal = document.forms[formName].state[stateIndex].value

var keepgoing = true;

	//checkDate function in date_check.js

	if (checkDate(formName,'checkIn','checkOut')) {

		if (document.forms[formName].airport.value == 'City or Airport Code') {
				alert(forceEnglish ? missingAirportMessage_en : missingAirportMessage);
        keepgoing = false;
        return;
		}
		else if (document.forms[formName].airport.value == '') {
			alert(forceEnglish ? missingAirportMessage_en : missingAirportMessage);
      keepgoing = false;
		}

    if (keepgoing) {		
			if (document.forms[formName].flexibleSearch.value=="true") {

				getLOS(document.forms[formName].los.options[document.forms[formName].los.options.selectedIndex].value);

				if (checkFlexSearchNoDates(formName)) {

					if (checkLOSLimit()) {
										
						document.forms[formName].submit();
					}
				}
			}
			else {	

					document.forms[formName].submit();
			}
		}
  }
}

function validateStaticSearch(formName) {

// this is pretty much the same as validateRewardSearch, but we arent
// checking for LOS, and aren't checking for flexible search = true

var countryIndex = document.forms[formName].country.selectedIndex
var countryVal = document.forms[formName].country[countryIndex].value
var stateIndex = document.forms[formName].state.selectedIndex
var stateVal = document.forms[formName].state[stateIndex].value

	//checkDate function in date_check.js

	if (checkDate(formName,'checkIn','checkOut')) {

		if (checkStateCountry(formName, countryVal, stateVal)) {

			document.forms[formName].submit();
		}
	}
}

function checkHRRStateCountry(formName, countryVal, stateVal) {

	var stateCountryMessage;
	var formType = document.forms[formName].searchType.value;
	
	// if the user has selected a top destination, we can skip all this
	if (document.forms[formName].topDestination) {
		if (document.forms[formName].topDestination.value != "") {
			return true;
		}
	}
	
	if (document.forms[formName].searchType.value=="address") {
		stateCountryMessage = forceEnglish ? addressStateCountryMessage_en : addressStateCountryMessage;
	}
	else if (document.forms[formName].searchType.value=="airport") {
		stateCountryMessage = forceEnglish ? airportStateCountryMessage_en : airportStateCountryMessage;
	}
	else if (document.forms[formName].searchType.value=="attraction") {
		stateCountryMessage = forceEnglish ? attractionStateCountryMessage_en : attractionStateCountryMessage;
	}
	else {
		stateCountryMessage = forceEnglish ? cityStateCountryMessage_en : cityStateCountryMessage;
	}

	if (countryVal == 'US' && stateVal == '') {
	//added for 17147
		 if(formType == "airport"){
			   if (document.forms[formName].airport.value == 'City or Airport Code') {
                                alert(stateCountryMessage);
                                return false;
                        }
                        else if (document.forms[formName].airport.value == '') {
                                alert(stateCountryMessage);
                                return false;
                        }
                        else {
                        
                                return true;
                        }
			
			}
			else{
                alert(stateCountryMessage);
                return false;
				}
		
	}
	else if (countryVal == 'US' && stateVal != '') {
		
		if (formType == "city") {
	
			if (document.forms[formName].city.value == 'City') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].city.value == 'City or Airport Code') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].city.value == 'Attraction name') {
				alert(stateCountryMessage);
				return false;
			} 
			else if (document.forms[formName].city.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		}
		else if (formType == "airport") {
		
			 if (document.forms[formName].city.value == 'City or Airport Code') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].city.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		}
		else if (formType == "attraction") {
		
			 if (document.forms[formName].city.value == 'Attraction name') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].city.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		}
		else {
			return true;
		}
	}
	else {

		return true;
	}
}

function checkChangeStateCountry(formName, countryVal, stateVal) {

	var stateCountryMessage;
	
	if (document.forms[formName].searchType.value=="address") {
		stateCountryMessage = forceEnglish ? addressStateCountryMessage_en : addressStateCountryMessage;
	}
	else if (document.forms[formName].searchType.value=="airport") {
		stateCountryMessage = forceEnglish ? airportStateCountryMessage_en : airportStateCountryMessage;
	}
	else if (document.forms[formName].searchType.value=="attraction") {
		stateCountryMessage = forceEnglish ? attractionStateCountryMessage_en : attractionStateCountryMessage;
	}
	else {
		stateCountryMessage = forceEnglish ? cityStateCountryMessage_en : cityStateCountryMessage;
	}

	if (countryVal == 'US' && stateVal == '') {
		//added for 17147
		 if(formType == "airport"){
			   if (document.forms[formName].airport.value == 'City or Airport Code') {
                                alert(stateCountryMessage);
                                return false;
                        }
                        else if (document.forms[formName].airport.value == '') {
                                alert(stateCountryMessage);
                                return false;
                        }
                        else {
                        
                                return true;
                        }
			
			}
			else{
                alert(stateCountryMessage);
                return false;
				}
	}
	else if (countryVal == 'US' && stateVal != '') {
		
		if (document.forms[formName].airport) {
		
			 if (document.forms[formName].airport.value == 'City or Airport Code') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].airport.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		}
		else if (document.forms[formName].attraction) {
		
			 if (document.forms[formName].attraction.value == 'Attraction name') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].attraction.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		}
		else {
			return true;
		}
	}
	else {

		return true;
	}
}

function checkStateCountry(formName, countryVal, stateVal) {

	var stateCountryMessage;
	var formType = document.forms[formName].searchType.value;
	
	if (document.forms[formName].searchType.value=="address") {
		stateCountryMessage = forceEnglish ? addressStateCountryMessage_en : addressStateCountryMessage;
	}
	else if (document.forms[formName].searchType.value=="airport") {
		stateCountryMessage = forceEnglish ? airportStateCountryMessage_en : airportStateCountryMessage;
	}
	else if (document.forms[formName].searchType.value=="attraction") {
		stateCountryMessage = forceEnglish ? attractionStateCountryMessage_en : attractionStateCountryMessage;
	}
	else {
		stateCountryMessage = forceEnglish ? cityStateCountryMessage_en : cityStateCountryMessage;
	}

	if (countryVal == 'US' && stateVal == '') {
		//added for 17147
		 if(formType == "airport"){
			   if (document.forms[formName].airport.value == 'City or Airport Code') {
                                alert(stateCountryMessage);
                                return false;
                        }
                        else if (document.forms[formName].airport.value == '') {
                                alert(stateCountryMessage);
                                return false;
                        }
                        else {
                        
                                return true;
                        }
			
			}
			else{
                alert(stateCountryMessage);
                return false;
				}
	}
	else if (countryVal == 'US' && stateVal != '') {
	
		if (formType == "city") {
			
			return true;
			
		}		
		else if (formType == "airport") {
		
			 if (document.forms[formName].airport.value == 'City or Airport Code') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].airport.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		}
		else if (formType == "attraction") {
		
			 if (document.forms[formName].attraction.value == 'Attraction name') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].attraction.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		} 
		else if (formType == "address") {
			if (document.forms[formName].address.value == 'Address') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].address.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
				return true;
			}
		}
		else {
			return true;
		}
	}
	else {

		return true;
	}
}

function swapElement(hideElement,showElement)
{
	document.getElementById(hideElement).style.display="none";
	document.getElementById(showElement).style.display="";
}

function swapText(element,newTxt)
{
	document.getElementById(element).innerHTML = newTxt;
}

// copy our standard date fields from one form to another
function copyDates(fromFormName, toFormName) {
	var fromForm = document.forms[fromFormName];
	var toForm = document.forms[toFormName];

	if (fromForm && toForm) {
		if (fromForm.checkInDay && toForm.checkInDay) {
			toForm.checkInDay.value = fromForm.checkInDay.value;
		}
		
		if (fromForm.checkInMonthYr && toForm.checkInMonthYr) {
			toForm.checkInMonthYr.value = fromForm.checkInMonthYr.value;
		}
		
		if (fromForm.checkOutDay && toForm.checkOutDay) {
			toForm.checkOutDay.value = fromForm.checkOutDay.value;
		}
		
		if (fromForm.checkOutMonthYr && toForm.checkOutMonthYr) {
			toForm.checkOutMonthYr.value = fromForm.checkOutMonthYr.value;
		}
		
		if (fromForm.flexCheckInDay && toForm.flexCheckInDay) {
			toForm.flexCheckInDay.value = fromForm.flexCheckInDay.value;
		}
		
		if (fromForm.flexCheckInMonthYr && toForm.flexCheckInMonthYr) {
			toForm.flexCheckInMonthYr.value = fromForm.flexCheckInMonthYr.value;
		}
		
		if (fromForm.los && toForm.los) {
			toForm.los.value = fromForm.los.value;
		}
	}
}
// this javascript is used to automagically set the state and country for 
// a search when a user enters one of the following top cities around the world
// NOTE: keys for the topCities associative array must be in all uppercase. The
// function that uses it upper cases the city passed in so that the search is
// case insensitive
var tC = new Array(); // short for "topCities"
// US Cities
tC["NEW YORK"] = gCO('New York', 'NY', 'US');
tC["LOS ANGELES"] = gCO('Los Angeles', 'CA', 'US');
tC["CHICAGO"] = gCO('Chicago', 'IL', 'US');
tC["HOUSTON"] = gCO('Houston', 'TX', 'US');
tC["PHILADELPHIA"] = gCO('Philadelphia', 'PA', 'US');
tC["PHOENIX"] = gCO('Phoenix', 'AZ', 'US');
tC["SAN DIEGO"] = gCO('San Diego', 'CA', 'US');
tC["DALLAS"] = gCO('Dallas', 'TX', 'US');
tC["SAN ANTONIO"] = gCO('San Antonio', 'TX', 'US');
tC["DETROIT"] = gCO('Detroit', 'MI', 'US');
tC["SAN JOSE"] = gCO('San Jose', 'CA', 'US');
tC["INDIANAPOLIS"] = gCO('Indianapolis', 'IN', 'US');
tC["SAN FRANCISCO"] = gCO('San Francisco', 'CA', 'US');
tC["COLUMBUS"] = gCO('Columbus', 'OH', 'US');
tC["AUSTIN"] = gCO('Austin', 'TX', 'US');
tC["BALTIMORE"] = gCO('Baltimore', 'MD', 'US');
tC["MILWAUKEE"] = gCO('Milwaukee', 'WI', 'US');
tC["BOSTON"] = gCO('Boston', 'MA', 'US');
tC["WASHINGTON"] = gCO('Washington', 'DC', 'US');
tC["EL PASO"] = gCO('El Paso', 'TX', 'US');
tC["SEATTLE"] = gCO('Seattle', 'WA', 'US');
tC["DENVER"] = gCO('Denver', 'CO', 'US');
tC["CHARLOTTE"] = gCO('Charlotte', 'NC', 'US');
tC["FORT WORTH"] = gCO('Fort Worth', 'TX', 'US');
tC["OKLAHOMA CITY"] = gCO('Oklahoma City', 'OK', 'US');
tC["TUCSON"] = gCO('Tucson', 'AZ', 'US');
tC["NEW ORLEANS"] = gCO('New Orleans', 'LA', 'US');
tC["LAS VEGAS"] = gCO('Las Vegas', 'NV', 'US');
tC["CLEVELAND"] = gCO('Cleveland', 'OH', 'US');
tC["LONG BEACH"] = gCO('Long Beach', 'CA', 'US');
tC["ALBUQUERQUE"] = gCO('Albuquerque', 'NM', 'US');
tC["FRESNO"] = gCO('Fresno', 'CA', 'US');
tC["VIRGINIA BEACH"] = gCO('Virginia Beach', 'VA', 'US');
tC["ATLANTA"] = gCO('Atlanta', 'GA', 'US');
tC["SACRAMENTO"] = gCO('Sacramento', 'CA', 'US');
tC["OAKLAND"] = gCO('Oakland', 'CA', 'US');
tC["MESA"] = gCO('Mesa', 'AZ', 'US');
tC["TULSA"] = gCO('Tulsa', 'OK', 'US');
tC["OMAHA"] = gCO('Omaha', 'NE', 'US');
tC["MINNEAPOLIS"] = gCO('Minneapolis', 'MN', 'US');
tC["HONOLULU"] = gCO('Honolulu', 'HI', 'US');
tC["COLORADO SPRINGS"] = gCO('Colorado Springs', 'CO', 'US');
tC["ST. LOUIS"] = gCO('St. Louis', 'MO', 'US');
tC["ST LOUIS"] = gCO('St. Louis', 'MO', 'US');
tC["SAINT LOUIS"] = gCO('St. Louis', 'MO', 'US');
tC["WICHITA"] = gCO('Wichita', 'KS', 'US');
tC["SANTA ANA"] = gCO('Santa Ana', 'CA', 'US');
tC["PITTSBURGH"] = gCO('Pittsburgh', 'PA', 'US');
tC["CINCINNATI"] = gCO('Cincinnati', 'OH', 'US');
tC["ANAHEIM"] = gCO('Anaheim', 'CA', 'US');
tC["BUFFALO"] = gCO('Buffalo', 'NY', 'US');
tC["ST. PAUL"] = gCO('St. Paul', 'MN', 'US');
tC["ST PAUL"] = gCO('St. Paul', 'MN', 'US');
tC["SAINT PAUL"] = gCO('St. Paul', 'MN', 'US');
tC["CORPUS CHRISTI"] = gCO('Corpus Christi', 'TX', 'US');
tC["AURORA"] = gCO('Aurora', 'CO', 'US');
tC["RALEIGH"] = gCO('Raleigh', 'NC', 'US');
tC["NEWARK"] = gCO('Newark', 'NJ', 'US');
tC["LEXINGTON-FAYETTE"] = gCO('Lexington-Fayette', 'KY', 'US');
tC["ANCHORAGE"] = gCO('Anchorage', 'AK', 'US');
tC["LOUISVILLE"] = gCO('Louisville', 'KY', 'US');
tC["RIVERSIDE"] = gCO('Riverside', 'CA', 'US');
tC["BAKERSFIELD"] = gCO('Bakersfield', 'CA', 'US');
tC["STOCKTON"] = gCO('Stockton', 'CA', 'US');
tC["BIRMINGHAM"] = gCO('Birmingham', 'AL', 'US');
tC["JERSEY CITY"] = gCO('Jersey City', 'NJ', 'US');
tC["NORFOLK"] = gCO('Norfolk', 'VA', 'US');
tC["BATON ROUGE"] = gCO('Baton Rouge', 'LA', 'US');
tC["HIALEAH"] = gCO('Hialeah', 'FL', 'US');
tC["LINCOLN"] = gCO('Lincoln', 'NE', 'US');
tC["GREENSBORO"] = gCO('Greensboro', 'NC', 'US');
tC["PLANO"] = gCO('Plano', 'TX', 'US');
tC["ROCHESTOR"] = gCO('Rochester', 'NY', 'US');
tC["GLENDALE"] = gCO('Glendale', 'AZ', 'US');
tC["AKRON"] = gCO('Akron', 'OH', 'US');
tC["GARLAND"] = gCO('Garland', 'TX', 'US');
tC["MADISON"] = gCO('Madison', 'WI', 'US');
tC["FORT WAYNE"] = gCO('Fort Wayne', 'IN', 'US');
tC["FREMONT"] = gCO('Fremont', 'CA', 'US');
tC["SCOTTSDALE"] = gCO('Scottsdale', 'AZ', 'US');
tC["MONTGOMERY"] = gCO('Montgomery', 'AL', 'US');
tC["SHREVEPORT"] = gCO('Shreveport', 'LA', 'US');
tC["LUBBOCK"] = gCO('Lubbock', 'TX', 'US');
tC["CHESAPEAKE"] = gCO('Chesapeake', 'VA', 'US');
tC["MOBILE"] = gCO('Mobile', 'AL', 'US');
tC["DES MOINES"] = gCO('Des Moines', 'IA', 'US');
tC["GRAND RAPIDS"] = gCO('Grand Rapids', 'MI', 'US');
tC["RICHMOND"] = gCO('Richmond', 'VA', 'US');
tC["YONKERS"] = gCO('Yonkers', 'NY', 'US');
tC["SPOKANE"] = gCO('Spokane', 'WA', 'US');
tC["AUGUSTA-RICHMOND COUNTY"] = gCO('Augusta-Richmond County', 'GA', 'US');
tC["GLENDALE"] = gCO('Glendale', 'CA', 'US');
tC["TACOMA"] = gCO('Tacoma', 'WA', 'US');
tC["IRVING"] = gCO('Irving', 'TX', 'US');
tC["HUNTINGTON BEACH"] = gCO('Huntington Beach', 'CA', 'US');
tC["MODESTO"] = gCO('Modesto', 'CA', 'US');
tC["DURHAM"] = gCO('Durham', 'NC', 'US');
tC["BOISE"] = gCO('Boise', 'ID', 'US');
tC["WINSTON-SALEM"] = gCO('Winston-Salem', 'NC', 'US');
tC["HONOLULU"] = gCO('Honolulu', 'HI', 'US');
tC["MAUI"] = gCO('Maui', 'HI', 'US');
tC["MEMPHIS"] = gCO('Memphis', 'TN', 'US');
tC["MIAMI"] = gCO('Miami', 'FL', 'US');
tC["ORLANDO"] = gCO('Orlando', 'FL', 'US');

// Canadian cities
tC["TORONTO"] = gCO('Toronto', 'ON', 'CA');
tC["MONTRÉAL"] = gCO('Montreal', 'QC', 'CA');
tC["MONTREAL"] = gCO('Montreal', 'QC', 'CA');
tC["OTTOWA"] = gCO('Ottawa', 'ON', 'CA');
tC["EDMONTON"] = gCO('Edmonton', 'AB', 'CA');
tC["CALGARY"] = gCO('Calgary', 'AB', 'CA');
tC["QUEBÉC"] = gCO('Quebec', 'QC', 'CA');
tC["QUEBEC"] = gCO('Quebec', 'QC', 'CA');
tC["WINNIPEG"] = gCO('Winnipeg', 'MB', 'CA');
tC["HAMILTON"] = gCO('Hamilton', 'ON', 'CA');
tC["LONDON"] = gCO('London', 'ON', 'CA');
tC["KITCHENER"] = gCO('Kitchener', 'ON', 'CA');
tC["ST CATHARINES-NIAGARA"] = gCO('St Catharines-Niagara', 'ON', 'CA');
tC["HALIFAX"] = gCO('Halifax', 'NS', 'CA');
tC["VICTORIA"] = gCO('Victoria', 'BC', 'CA');
tC["WINDSOR"] = gCO('Windsor', 'ON', 'CA');
tC["OSHAWA"] = gCO('Oshawa', 'ON', 'CA');
tC["SASKATOON"] = gCO('Saskatoon', 'SK', 'CA');
tC["REGINA"] = gCO('Regina', 'SK', 'CA');
tC["ST JOHN'S"] = gCO('St John\'s', 'NF', 'CA');
tC["ST JOHNS"] = gCO('St John\'s', 'NF', 'CA');
tC["SUDBURY"] = gCO('Sudbury', 'ON', 'CA');
tC["CHICOUTIMI"] = gCO('Chicoutimi', 'QC', 'CA');
tC["SHERBROOKE"] = gCO('Sherbrooke', 'QC', 'CA');
tC["KINGSTON"] = gCO('Kingston', 'ON', 'CA');
tC["TROIS-RIVIÈRES"] = gCO('Trois-Rivières', 'QC', 'CA');
tC["TROIS-RIVIERES"] = gCO('Trois-Rivières', 'QC', 'CA');
tC["KELOWNA"] = gCO('Kelowna', 'BC', 'CA');
tC["ABBOTSFORD"] = gCO('Abbotsford', 'BC', 'CA');
tC["SAINT JOHN"] = gCO('Saint John', 'NB', 'CA');
tC["THUNDER BAY"] = gCO('Thunder Bay', 'ON', 'CA');
tC["BARRIE"] = gCO('Barrie', 'ON', 'CA');
tC["SYDNEY"] = gCO('Sydney', 'NS', 'CA');

// United Kingdom
tC["LONDON"] = gCO('London', '', 'GB');
tC["BIRMINGHAM"] = gCO('Birmingham', '', 'GB');
tC["LEEDS"] = gCO('Leeds', '', 'GB');
tC["GLASGOW"] = gCO('Glasgow', '', 'GB');
tC["SHEFFIELD"] = gCO('Sheffield', '', 'GB');
tC["BRADFORD"] = gCO('Bradford', '', 'GB');
tC["LIVERPOOL"] = gCO('Liverpool', '', 'GB');
tC["EDINBURGH"] = gCO('Edinburgh', '', 'GB');
tC["MANCHESTER"] = gCO('Manchester', '', 'GB');
tC["BRISTOL"] = gCO('Bristol', '', 'GB');
tC["KIRKLEES"] = gCO('Kirklees', '', 'GB');
tC["FIFE"] = gCO('Fife', '', 'GB');
tC["WIRRAL"] = gCO('Wirral', '', 'GB');
tC["NORTH LANARKSHIRE"] = gCO('North Lanarkshire', '', 'GB');
tC["WAKEFIELD"] = gCO('Wakefield', '', 'GB');
tC["CARDIFF"] = gCO('Cardiff', '', 'GB');
tC["DUDLEY"] = gCO('Dudley', '', 'GB');
tC["WIGAN"] = gCO('Wigan', '', 'GB');
tC["EAST RIDING"] = gCO('East Riding', '', 'GB');
tC["SOUTH LANARKSHIRE"] = gCO('South Lanarkshire', '', 'GB');
tC["COVENTRY"] = gCO('Coventry', '', 'GB');
tC["HELFAST"] = gCO('Belfast', '', 'GB');
tC["LEICESTER"] = gCO('Leicester', '', 'GB');
tC["SUNDERLAND"] = gCO('Sunderland', '', 'GB');
tC["SANDWELL"] = gCO('Sandwell', '', 'GB');
tC["DONCASTER"] = gCO('Doncaster', '', 'GB');
tC["STOCKPORT"] = gCO('Stockport', '', 'GB');
tC["SEFTON"] = gCO('Sefton', '', 'GB');
tC["NOTTINGHAM"] = gCO('Nottingham', '', 'GB');
tC["NEWCASTLE-UPON-TYNE"] = gCO('Newcastle-upon-Tyne', '', 'GB');
tC["KINGSTON-UPON-HULL"] = gCO('Kingston-upon-Hull', '', 'GB');
tC["BOLTON"] = gCO('Bolton', '', 'GB');
tC["WALSALL"] = gCO('Walsall', '', 'GB');
tC["PLYMOUTH"] = gCO('Plymouth', '', 'GB');
tC["ROTHERHAM"] = gCO('Rotherham', '', 'GB');
tC["STOKE-ON-TRENT"] = gCO('Stoke-on-Trent', '', 'GB');
tC["WOLVERHAMPTON"] = gCO('Wolverhampton', '', 'GB');
tC["RHONDDA, CYNON, TAFF"] = gCO('Rhondda, Cynon, Taff', '', 'GB');
tC["SOUTH GLOUCESTERSHIRE"]= gCO('South Gloucestershire', '', 'GB');
tC["DERBY"] = gCO('Derby', '', 'GB');
tC["SWANSEA"] = gCO('Swansea', '', 'GB');
tC["SALFORD"] = gCO('Salford', '', 'GB');
tC["ABERDEENSHIRE"] = gCO('Aberdeenshire', '', 'GB');
tC["BARNSLEY"] = gCO('Barnsley', '', 'GB');
tC["TAMESIDE"] = gCO('Tameside', '', 'GB');
tC["OLDHAM"] = gCO('Oldham', '', 'GB');
tC["TRAFFORD"] = gCO('Trafford', '', 'GB');
tC["ABERDEEN"] = gCO('Aberdeen', '', 'GB');
tC["SOUTHAMPTON"] = gCO('Southampton', '', 'GB');
tC["HIGHLAND"] = gCO('Highland', '', 'GB');
tC["ROCHDALE"] = gCO('Rochdale', '', 'GB');
tC["SOLIHULL"] = gCO('Solihull', '', 'GB');
tC["GATESHEAD"] = gCO('Gateshead', '', 'GB');
tC["MILTON KEYNES"] = gCO('Milton Keynes', '', 'GB');
tC["NORTH TYNESIDE"] = gCO('North Tyneside', '', 'GB');
tC["CALDERDALE"] = gCO('Calderdale', '', 'GB');
tC["NORTHAMPTON"] = gCO('Northampton', '', 'GB');
tC["PORTSMOUTH"] = gCO('Portsmouth', '', 'GB');
tC["WARRINGTON"] = gCO('Warrington', '', 'GB');
tC["NORTH SOMERSET"] = gCO('North Somerset', '', 'GB');

// Europe
tC["BERLIN"] = gCO('Berlin', '', 'DE');
tC["MADRID"] = gCO('Madrid', '', 'ES');
tC["ROMA"] = gCO('Roma', '', 'IT');
tC["ROME"] = gCO('Roma', '', 'IT');
tC["PARIS"] = gCO('Paris', '', 'FR');
tC["HAMBURG"] = gCO('Hamburg', '', 'DE');
tC["BARCELONA"] = gCO('Barcelona', '', 'ES');
tC["NOVOSIBIRSK"] = gCO('Novosibirsk', '', 'RU');
tC["NIZHNY NOVGOROD"] = gCO('Nizhny Novgorod', '', 'RU');
tC["MILAN"] = gCO('Milan', '', 'IT');
tC["NAPLES"] = gCO('Naples', '', 'IT');
tC["KÖLN"] = gCO('Koln', '', 'DE');
tC["KOLN"] = gCO('Koln', '', 'DE');
tC["COLOGNE"] = gCO('Cologne', '', 'DE');
tC["TORINO"] = gCO('Torino', '', 'IT');
tC["TURIN"] = gCO('Turin', '', 'IT');
tC["MARSEILLE"] = gCO('Marseille', '', 'FR');
tC["LVOV"] = gCO('Lvov', '', 'UA');
tC["ATHINAI"] = gCO('Athinai', '', 'GR');
tC["ATHENS"] = gCO('Athens', '', 'GR');
tC["STOCKHOLM"] = gCO('Stockholm', '', 'SE');
tC["VALENCIA"] = gCO('Valencia', '', 'ES');
tC["AMSTERDAM"] = gCO('Amsterdam', '', 'NL');
tC["SEVILLA"] = gCO('Sevilla', '', 'ES');
tC["PALERMO"] = gCO('Palermo', '', 'IT');
tC["GENOVA"] = gCO('Genova', '', 'IT');
tC["FRANKFURT"] = gCO('Frankfurt', '', 'DE');
tC["ESSEN"] = gCO('Essen', '', 'DE');
tC["ROTTERDAM"] = gCO('Rotterdam', '', 'NL');
tC["IRKUTSK"] = gCO('Irkutsk', '', 'RU');
tC["DORTMUND"] = gCO('Dortmund', '', 'DE');
tC["STUTTGART"] = gCO('Stuttgart', '', 'DE');
tC["DÜSSELDORF"] = gCO('Düsseldorf', '', 'DE');
tC["DUSSELDORF"] = gCO('Düsseldorf', '', 'DE');
tC["HELSINKI"] = gCO('Helsinki', '', 'FI');
tC["MÁLAGA"] = gCO('Málaga', '', 'ES');
tC["MALAGA"] = gCO('Málaga', '', 'ES');
tC["BREMEN"] = gCO('Bremen', '', 'DE');
tC["HANNOVER"] = gCO('Hannover', '', 'DE');
tC["KOBENHAVN"] = gCO('Kobenhavn', '', 'DK');
tC["COPENHAGEN"] = gCO('Copenhagen', '', 'DK');
tC["KEMEROVO"] = gCO('Kemerovo', '', 'RU');

// rest o' the world
tC["SEOUL"] = gCO('Seoul', '', 'KR');
tC["SÃO PAULO"] = gCO('São Paulo', '', 'BR');
tC["SAO PAULO"] = gCO('Sao Paulo', '', 'BR');
tC["BOMBAY"] = gCO('Bombay', '', 'IN');
tC["ISTANBUL"] = gCO('Istanbul', '', 'TR');
tC["MEXICO"] = gCO('Mexico', '', 'MX');
tC["MEXICO CITY"] = gCO('Mexico City', '', 'MX');
tC["SHANGHAI"] = gCO('Shanghai', '', 'CN');
tC["TOKYO"] = gCO('Tokyo', '', 'JP');
tC["BANGKOK"] = gCO('Bangkok', '', 'TH');
tC["BEIJING"] = gCO('Beijing', '', 'CN');
tC["DELHI"] = gCO('Delhi', '', 'IN');
tC["HONGKONG"] = gCO('HongKong', '', 'CN');
tC["HONG KONG"] = gCO('HongKong', '', 'CN');
tC["CAIRO"] = gCO('Cairo', '', 'EG');
tC["BOGOTA"] = gCO('Bogota', '', 'CO');
tC["LIMA"] = gCO('Lima', '', 'PE');
tC["RIO DE JANEIRO"] = gCO('Rio de Janeiro', '', 'BR');
tC["SANTIAGO"] = gCO('Santiago', '', 'CL');
tC["SYDNEY"] = gCO('Sydney', '', 'AU');
tC["ALEXANDRIA"] = gCO('Alexandria', '', 'EG');
tC["ANKARA"] = gCO('Ankara', '', 'TR');
tC["BUENOS AIRES"] = gCO('Buenos Aires', '', 'AR');
tC["OSAKA"] = gCO('Osaka', '', 'JP');
tC["BUDAPEST"] = gCO('Budapest', '', 'HU');
tC["CARACAS"] = gCO('Caracas', '', 'VE');

// creates a city "object" containing city, state, 
// and country properties
function gCO(city, state, country) {
	var cityObj = new Object();
	cityObj.city = city;
	cityObj.state = state;
	cityObj.country = country;
	return cityObj;
}

// looks for an enter in the topCities array for the value
// of the textbox passed in. If an entry is found, the state
// and country dropdowns on the same form will be set
// to the proper state (if applicable) and country
function setStateAndCountry(cityTextBox) {
	var cityObj = tC[cityTextBox.value.toUpperCase()];
	if (cityObj) {
		if (cityTextBox.form.state) {
			cityTextBox.form.state.value = cityObj.state;
		}

		if (cityTextBox.form.country) {
			cityTextBox.form.country.value = cityObj.country;
		}
	}
}
/* js utility functions for search */

function setCountry(stateSelectBox) {
	var countrySelectBox = stateSelectBox.form.country;
	countrySelectBox.value = isCanadian(stateSelectBox.value) ? 'CA' : 'US';	
	
	if(stateSelectBox.value == 'DC' && stateSelectBox.form.city && stateSelectBox.form.city.value == '')
	{
		stateSelectBox.form.city.value='Washington';
	}
}

function isCanadian(state) {
	return (state == 'AB' || state == 'BC' || state == 'MB' || 
			state == 'NB' || state == 'NL' || state == 'NS'); 
}

function setTopDestination(dropdown) {
	// first turn the city tab on (in case we are on airport or address
	switchTab('findhotelcity');

	// will be in form "city:state:country"
	var ddValue = dropdown.value;
	var frm = dropdown.form;
	
	var tdArray = ddValue.split(":");
	
	if (tdArray.length == 3) {
		frm.city.value = tdArray[0];
		frm.state.value = tdArray[1];
		frm.country.value = tdArray[2];	
	}
}

function copyRadius(radiusElem) {
	frm = radiusElem.form;
	
	if (frm) {
		if (radiusElem.name == 'radius') {
			if (frm.radius1) {
				frm.radius1.value = radiusElem.value;
			}
		} else {
			if (frm.radius) {
				frm.radius.value = radiusElem.value;
			}
		}
	}
}

function copyRadiusUnits(radiusUnitsElem) {
	frm = radiusUnitsElem.form;

	if (frm) {
		if (radiusUnitsElem.name == 'units') {
			if (frm.units1) {
				selectRadio(frm, 'units1', radiusUnitsElem.value);
				//frm.units1.value = radiusUnitsElem.value;
			}
		} else {
			if (frm.units) {
				selectRadio(frm, 'units', radiusUnitsElem.value);
				//frm.units.value = radiusUnitsElem.value;
			}
		}
	}
}

function selectRadio(frm, name, newValue) {
	if (frm && frm[name]) {
		if (frm[name].length) {
			for (var i = 0; i < frm[name].length; i++) {
				//alert(i + " - value: " + frm[name][i].value + " - new value: " + newValue);
				frm[name][i].checked = frm[name][i].value == newValue;
			}
		} else {
			frm[name].checked = frm[name].value == newValue;
		}
	}
}

function resetTopDestinationDD(form) {
	form.topDestination.value="";
}

function setItTrackingParam(form, value) {
	form.it.value = value;
}

function submitHotelSearch() {
	validateHomeSearch('frmfindHotel');
}

function submitRewardSearch() {
	validateRewardSearch('frmrewardstays');
}// globals #######################################
ie = document.all ? true : false;
dom = document.getElementById ? true : false;
ns = document.layers ? true : false;

// #########################################

// these could be overridden by an ouside js file containing language specific month names
var monthnames_display = new Array("Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık");
var daynames_display = new Array( "P", "Pt", "S", "Ç", "P", "C", "Ct" );

// these are the english monthnames which we need for comparation against <option value>
var monthnames = new Array("Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık");
var daynames = new Array( "P", "Pt", "S", "Ç", "P", "C", "Ct" );
var monthdays  = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

// alert messages. these may be overridden by an outside js file containing language
// specific alerts
var activityEndAfterActivityStart="The activity end date must be later than the activity start date.";
var activityStartCurrentDateOrLater="The activity start date must be current date or later.";
var onlySearch365DaysInAdvance="You can only search for activities up to 365 days in advance.";

var selectedMonthYr = new Date()
var firstClick = true
var onCheckIn = 1 // 1 = on check in, 2 = on check out, 3 = on nothing
var searchCal = false;
var inBrowserCal;
var calForm;
var checkInName = "Check-in"
var checkOutName = "Check-out"
var forceEnglish = false;

function setSearchCal( v ) {
  searchCal = v;
}

function setOnCheckIn( val ) {
  onCheckIn = val
}

function updateIECheckIn( checkIn ) {
  if ( checkIn == null ) {
    if ( searchCal )
      return;
    else
      checkIn = (getCheckInDate() == null ? new Date() : getCheckInDate())
  }
  resize( calForm.checkInDay, checkIn )
  //if ( checkIn.getMonth() != selectedMonthYr.getMonth() && checkIn.getMonth() != selectedMonthYr.getMonth() + 1 )
    selectedMonthYr = checkIn
  setCheckInDate( checkIn )
  if ( getCheckOutDate() <= checkIn ) {
    setCheckOutDate( new Date( checkIn.getTime() + 86400000 ) )
    if(getCheckOutDate().getDay() == getCheckInDate().getDay()){
	setCheckOutDate( new Date( checkIn.getTime() + 90000000 ))
    }
    resize( calForm.checkOutDay, getCheckOutDate() )
    if ( getCheckOutDate().getMonth() >= selectedMonthYr.getMonth() + 2 ||
	 ( getCheckOutDate().getMonth() == 0 && getCheckOutDate().getFullYear() >= selectedMonthYr.getFullYear() + 1 ) ){
      selectedMonthYr = checkIn;
}
  } else if ( searchCal && getCheckOutDate() == null  ) {
  }
  inBrowserCal = false;
  redrawCalendar()
}

function updateNSCheckIn( checkIn ) {
  if ( checkIn == null ) {
    if ( searchCal )
      return;
    else
      checkIn = (getCheckInDate() == null ? new Date() : getCheckInDate())
  }
  setCheckInDate( checkIn )
  if ( getCheckOutDate() <= checkIn ){
    setCheckOutDate( new Date( checkIn.getTime() + 86400000 ) )
    if(getCheckOutDate().getDay() == getCheckInDate().getDay()){
        setCheckOutDate( new Date( checkIn.getTime() + 90000000 ))
    }
  }
  else if ( searchCal )
    setCheckOutDate( getCheckOutDate() )
}
  

function updateIECheckOut( checkOut ) {
  if ( checkOut == null ) {
    if ( searchCal )
      return;
    else
      checkOut = (getCheckOutDate() == null ? new Date( new Date().getTime() + 86400000 ) : getCheckOutDate() )
  }
  resize( calForm.checkOutDay, checkOut )
  setCheckOutDate( checkOut )
  redrawCalendar();
}

function updateNSCheckOut( checkOut ) {
  if ( checkOut == null ) {
    if ( searchCal )
      return;
    else
      checkOut = (getCheckOutDate() == null ? new Date( new Date().getTime() + 86400000 ) : getCheckOutDate() )
  }
  setCheckOutDate( checkOut )
}

function resize( select, date ) {
  var dim = getDaysInMonth( date.getMonth(), date.getFullYear() )
  var size = select.length
  if ( searchCal ) size = size - 1
  while ( dim != size ) {
    if ( dim > size ) {
      var opt = document.createElement( "OPTION" )
      select.add( opt )
      opt.innerText = size + 1
      opt.value = size + 1
    } else if ( dim < size ) {
      if ( searchCal ) size = size + 1
      select.remove( size - 1 )
    }
    size = select.length
    if ( searchCal ) size = size - 1
  }
}

function handleIECalClick( day, month, year ) {
  if ( onCheckIn == 1 ) {
    setOnCheckIn( firstClick ? 2 : 3 )
    updateCheckIn( new Date( year, month, day ) )
	if (calForm.los) {
    	getLOS(calForm.los.options[calForm.los.options.selectedIndex].value)
	}
  } else if ( onCheckIn == 2 ) {
    setOnCheckIn( 3 )
    updateCheckOut( new Date( year, month, day ) )
  } else {
    alert( "Please select either " + checkInName + " or " + checkOutName + " above the calendar." )
  }
  firstClick = false;
  if(!inBrowserCal) {
  calendarWindow.close()
  }
}

function handleNSCalClick( day, month, year ) {
  if ( onCheckIn == 1 ) {
    updateNSCheckIn( new Date( year, month, day ) )
    if (calForm.los) {
    	getLOS(calForm.los.options[calForm.los.options.selectedIndex].value)
	}
  } else {
    updateNSCheckOut( new Date( year, month, day ) )
  }
  if(!inBrowserCal) {
  calendarWindow.close()
  }
}

function moveForward() {
  if ( selectedMonthYr.getMonth() == 11 )
    selectedMonthYr = new Date( selectedMonthYr.getFullYear() + 1, 0, 1 )
  else
    selectedMonthYr = new Date( selectedMonthYr.getFullYear(), selectedMonthYr.getMonth() + 1, 1 )
  redrawCalendar()
}

function moveBack() {
  if ( selectedMonthYr.getMonth() == 0 )
    selectedMonthYr = new Date( selectedMonthYr.getFullYear() - 1, 11, 1 )
  else
    selectedMonthYr = new Date( selectedMonthYr.getFullYear(), selectedMonthYr.getMonth() - 1, 1 )
  redrawCalendar()
}

function generateCal() {
  var out = ""
  out += "<CENTER>Choose: "
  if ( onCheckIn == 1 )
    out += "<INPUT onClick=\"javascript:setOnCheckIn(1)\" type=\"radio\" name=\"checkInOut\" checked>" + checkInName + "&nbsp;"
  else
    out += "<INPUT onClick=\"javascript:setOnCheckIn(1)\" type=\"radio\" name=\"checkInOut\">" + checkInName + "&nbsp;"
  out += " | "
  if ( onCheckIn == 2 )
    out += "<INPUT onClick=\"javascript:setOnCheckIn(2)\" type=\"radio\" name=\"checkInOut\" checked>" + checkOutName
  else
    out += "<INPUT onClick=\"javascript:setOnCheckIn(2)\" type=\"radio\" name=\"checkInOut\">" + checkOutName
  out += "<table class=\"pad2\" cellpadding=0 cellspacing=0 border=0>"
  out += "<tr valign=top><td class=\"pad6\">" + generateMonth( selectedMonthYr.getMonth(), selectedMonthYr.getFullYear(), 1 ) + "</td>"
  var nextMonth = selectedMonthYr.getMonth() == 11 ? 0 : selectedMonthYr.getMonth() + 1
  var nextYear  = selectedMonthYr.getMonth() == 11 ? selectedMonthYr.getFullYear() + 1 : selectedMonthYr.getFullYear()
  out += "<td class=\"pad6\">" + generateMonth( nextMonth, nextYear, 2 ) + "</td></tr>"
  out += "</table>"
  out += "</CENTER>"
  return out
}

function generateNSMonth( month, year, prev_next ) {
  var out = ""
  out += "<table width=100% border=0 cellpadding=1 cellspacing=0><tr bgcolor=#d0d0d0>"
  out += "<td align=left>" + ( prev_next != 2 && displayMoveBack( month, year ) ? "<a href=\"javascript:opener.moveBack()\"><img width=16 height=12 border=0 src=\"http://www1.hilton.com/common/media/images/misc/cal_previous.gif\"></a>" : "&nbsp&nbsp" )
  
  out += "<td align=center><b>"
  out += forceEnglish ? monthnames[month] : monthnames_display[month] + " " + year +"</b>"
  out += "</td>"
  
  out += "<td align=right>" + ( prev_next != 1 && displayMoveForward( month, year ) ? "<a href=\"javascript:opener.moveForward()\"><img width=16 height=12 border=0 src=\"http://www1.hilton.com/common/media/images/misc/cal_next.gif\"></a>" : "&nbsp&nbsp" )
  out += "</tr></table>"

  out += "<table width=100% border=0 cellpadding=1 cellspacing=0>"
  out += "<tr>"
  for ( var i = 0 ; i < daynames.length ; i++ ) {
    out += "<td align=center>";
    out += forceEnglish ? daynames[i] : daynames_display[i]; 
    out += "</td>";
  }
  
  out += "</tr>"

  var fdom = getFirstDayOfMonth( month, year ) - 1
  var nd   = getDaysInMonth( month, year )

  var days_out = 0
  for ( var i = -fdom ; i <= nd ; i++ ) {

    if ( days_out == 0 )
      out += "<tr>"

    var dayClass = getDayClass( i, month, year )
    var isClickable = dayClass != "noselect-day"
    out += "<td align=center><font size=-1>"
    if ( isClickable )
      out += "<a href='javascript:opener.handleCalClick( " + i + ", " + month + ", " + year + ")'>"
    if ( i > 0 )
      out += i
    if ( isClickable )
      out += "</a>"
    out += "</font></td>"

    if ( days_out == 6 )
      out += "</tr>"

    if ( days_out == 6 )
      days_out = 0
    else
      days_out++
  }
  out += "</table>"

  return out;
}

function generateMonth( month, year, prev_next ) {

  var out = ""
  out += "<table border=0 cellpadding=1 cellspacing=0>"
  out += "<tr><td class=break colspan=7></td></tr>"
  out += "<tr>"
  out += "<td align=center class=month_header colspan=7>"
  out += "<table width=100% border=0 cellpadding=1 cellspacing=0><tr>"
  out += "<td class=prev_month align=left>" + ( prev_next != 2 && displayMoveBack( month, year ) ? "<a class=\"static_a\" href=\"javascript:moveBack()\"><img width=16 height=12 border=0 src=\"/common/media/images/misc/cal_previous.gif\"></a>" : "&nbsp&nbsp" )
  
  if (forceEnglish) {
  	out += "<td class=cal align=center><font class=month_header>" + monthnames[ month ] + " " + year + "</font>"
  } else {
  	out += "<td class=cal align=center><font class=month_header>" + monthnames_display[ month ] + " " + year + "</font>"
  }
  
  out += "<td class=cal align=center><font class=month_header>"
  out += forceEnglish ? monthnames[month] : monthnames_display[month]+ " " + year +"</font>"
  out += "</td>"
  
  out += "<td class=next_month align=right>" + ( prev_next != 1 && displayMoveForward( month, year ) ? "<a class=\"static_a\" href=\"javascript:moveForward()\"><img width=16 height=12 border=0 src=\"http://www1.hilton.com/common/media/images/misc/cal_next.gif\"></a>" : "&nbsp&nbsp" )
  out += "</tr></table>"
  out += "</td>"
  out += "</tr>"

  out += "<tr><td class=break colspan=7></td></tr>"

  out += "<tr>"
  
  for ( var i = 0 ; i < daynames.length ; i++ ) {
    out += "<td class=day_header>";
    out += forceEnglish ? daynames[i] : daynames_display[i]; 
    out += "</td>";
  }
    
  out += "</tr>"

  out += "<tr><td class=break colspan=7></td></tr>"

  var fdom = getFirstDayOfMonth( month, year ) - 1
  var nd   = getDaysInMonth( month, year )

  var days_out = 0
  for ( var i = -fdom ; i <= nd ; i++ ) {

    if ( days_out == 0 )
      out += "<tr>"

    var dayClass = getDayClass( i, month, year )
    var isClickable = dayClass != "noselect-day"
    var mout = "onMouseOut=\"javascript:this.className='" + dayClass + "'\""
    var min  = "onMouseOver=\"javascript:this.className='" + dayClass + "-mover'\""
    var onc = "onClick=\"javascript:handleCalClick( " + i + ", " + month + ", " + year + " )\""
    var all = isClickable ? ( " " + mout + " " + min + " " + onc ) : ""
    out += "<td class=" + dayClass + all + ">"
    if ( isClickable )
      out += "<a>"
    if ( i > 0 )
      out += i
    if ( isClickable )
      out += "</a>"
    out += "</td>"
   
    if ( days_out == 6 )
      out += "</tr>"

    if ( days_out == 6 )
      days_out = 0
    else
      days_out++
  }
  out += "</table>"

  return out
}

// returns true if we should display a "next month" icon for the given month, year
function displayMoveForward( month, year ) {
  var today = new Date()
  var parm  = new Date( year, month, 1 )
  return ( parm.getFullYear() == today.getFullYear() ) || 
           ( parm.getFullYear() > today.getFullYear() && parm.getMonth() < today.getMonth() );
}

// returns true if we should display a "previous month" icon for the given month, year
function displayMoveBack( month, year ) {
  var today = new Date()
  var parm  = new Date( year, month, 1 )
  return ( parm.getFullYear() == today.getFullYear() && parm.getMonth() > today.getMonth() ) ||
           parm.getFullYear() > today.getFullYear();
}

function getFirstDayOfMonth( month, year ) {
  var day = new Date( year, month, 1 )
  return day.getDay()
}

function getDaysInMonth( month, year ) {
  if ( month == 1 )
    return isLeapYear( year ) ? 29 : 28
  else
    return monthdays[ month ]
}

function isLeapYear( year ) {
  return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0
}

function getIEDayClass( day, month, year ) {
  if ( day < 1 )
    return "noselect-day"
  var checkInDate = getCheckInDate()
  var checkOutDate = getCheckOutDate()

  var today = new Date()
  var nyr = new Date( today.getTime() + (86400000 * 365) )
  var selectedDay = new Date( year, month, day + 1 )
  var lastSelectedDay = new Date( year, month, day )

  if ( selectedDay < today )
    return "noselect-day"

  if ( selectedDay > nyr )
    return "noselect-day"

  if ( selectedDay > checkInDate && lastSelectedDay <= checkOutDate )
    return "selected-day"
  
  return "day"
}

function getNSDayClass( day, month, year ) {
  if ( day < 1 )
    return "noselect-day"

  var today = new Date()
  var nyr = new Date( today.getTime() + (86400000 * 365) )
  var selectedDay = new Date( year, month, day + 1 )
  var lastSelectedDay = new Date( year, month, day )

  if ( selectedDay < today )
    return "noselect-day"

  if ( selectedDay > nyr )
    return "noselect-day"

  return "day"
}

function redrawCalendar() {
  if ( inBrowserCal ) {
    var newCal = generateCal()
    calendar.innerHTML = newCal
  } else {
    generateCalendar( calendarWindow )
  }
}

var calendarWindow
function createCalendar( ci ) {
  onCheckIn = ci
  selectedMonthYr = ( onCheckIn == 1 ) ? getCheckInDate() : getCheckOutDate()

  if ( selectedMonthYr == null )
    selectedMonthYr = new Date()
  if ( ie ) {
    topABC = window.screenTop + 100
    leftABC = window.screenLeft + 250
  } else {
    topABC = window.screenY + 100
    leftABC = window.screenX + 250
  }
  calendarWindow = window.open("","Takvim","width=166,height=160,resizable=yes,scrollbars=no,status=no,top=" + topABC + ",left=" + leftABC )
  generateCalendar( calendarWindow )
  calendarWindow.focus()
}

function generateCalendar( target ) {
  target.document.open()
  var nextMonth = selectedMonthYr.getMonth() == 11 ? 0 : selectedMonthYr.getMonth() + 1
  var nextYear  = selectedMonthYr.getMonth() == 11 ? selectedMonthYr.getFullYear() + 1 : selectedMonthYr.getFullYear()
  var calStuff = "<html><head><title>Takvim</title></head>"
  calStuff += "<body bgcolor=#ffffff topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><center>"
  calStuff += generateNSMonth( selectedMonthYr.getMonth(), selectedMonthYr.getFullYear(), 3 )
  calStuff += "</center></body></html>"
  target.document.write( calStuff )
  target.document.close()
}

function getCheckInDate() {
  var day =  calForm.checkInDay.options[calForm.checkInDay.selectedIndex].value
  var month = calForm.checkInMonthYr.options[calForm.checkInMonthYr.selectedIndex].value
  if ( day == -1 || month == "" ) {
		return null;
	}
  else if (month == "-1") {
		return null;
	}
  month = month.substring( 0, month.indexOf( " " ) )
  var year = calForm.checkInMonthYr.options[calForm.checkInMonthYr.selectedIndex].value
  year = year.substring( year.indexOf( " " ) + 1, year.length )
  if ( !( month >= 0 && month <= 12 ) )
    for ( var j = 0 ; j < monthnames.length ; j++ )
      if ( monthnames[ j ] == month )
        month = j
  // if "31 Feb" is selected in the drop down, doing new Date( 31 feb ) will create a date on
  // march 1/2/3 or thereabouts.  this is a workaround:
  var date = new Date( year, month, day )
  if ( month != date.getMonth() )
    date = new Date( year, month, getDaysInMonth( month, year ) - 1 )
  return date
}

function setCheckInDate( checkIn ) {
  for ( var i = 0 ; i < calForm.checkInDay.options.length ; i++ )
    if ( calForm.checkInDay.options[ i ].value == checkIn.getDate() )
      calForm.checkInDay.options[ i ].selected = true;
  var moyear = monthnames[ checkIn.getMonth() ] + " " + checkIn.getFullYear()
  for ( var i = 0 ; i < calForm.checkInMonthYr.options.length ; i++ )
    if ( calForm.checkInMonthYr.options[ i ].value == moyear )
      calForm.checkInMonthYr.options[ i ].selected = true
      
  copyToFlex();
}

function getCheckOutDate() {
  var day = calForm.checkOutDay.options[calForm.checkOutDay.selectedIndex].value
  var month = calForm.checkOutMonthYr.options[calForm.checkOutMonthYr.selectedIndex].value

  if ( day == -1 || month == "" ) {
        return null;
	}
  else if (month == "-1") {
        return null;
	}
  month = month.substring( 0, month.indexOf( " " ) )
  var year = calForm.checkOutMonthYr.options[calForm.checkOutMonthYr.selectedIndex].value
  year = year.substring( year.indexOf( " " ) + 1, year.length )
  if ( !( month >= 0 && month <= 12 ) )
    for ( var j = 0 ; j < monthnames.length ; j++ )
      if ( monthnames[ j ] == month )
        month = j
  // if "31 Feb" is selected in the drop down, doing new Date( 31 feb ) will create a date on
  // march 1/2/3 or thereabouts.  this is a workaround:
  var date = new Date( year, month, day )
  if ( month != date.getMonth() )
    date = new Date( year, month, getDaysInMonth( month, year ) )
  return date
}

function setCheckOutDate( checkOut ) {
  for ( var i = 0 ; i < calForm.checkOutDay.options.length ; i++ )
    if ( calForm.checkOutDay.options[ i ].value == checkOut.getDate() )
      calForm.checkOutDay.options[ i ].selected = true;
  var moyear = monthnames[ checkOut.getMonth() ] + " " + checkOut.getFullYear()

  for ( var i = 0 ; i < calForm.checkOutMonthYr.options.length ; i++ )
    if ( calForm.checkOutMonthYr.options[ i ].value == moyear )
      calForm.checkOutMonthYr.options[ i ].selected = true
}

function setCalForm( f ) {
	calForm = f;
}

function setup() {
  if ( calForm == null ) calForm = document.main;
  if ( inBrowserCal ) {
    updateCheckIn( getCheckInDate() )
    updateCheckOut( getCheckOutDate() )
    redrawCalendar()
  }
}

function validateDates() {
  var cid = getCheckInDate()
  var cod = getCheckOutDate()
  var tod = new Date()
  var yes = new Date( tod - 86400000 )
  var nyr = new Date( tod + (86400000 * 365) )

if ( cid == null || cod == null ) {
 return true;
}
else {
if ( cod <= cid )
    alert(activityEndAfterActivityStart)
  else if ( cid < yes )
    alert(activityStartCurrentDateOrLater)
  else if ( cod > nyr || cid > nyr )
    alert(activityStartCurrentDateOrLater)
  else
  return true
 return false
 }

}
function performAvailSearch()
{
    if (checkNoDate('availSearch','checkIn','checkOut') && checkDate('availSearch','checkIn','checkOut')){document.availSearch.submit()}
}

function performRewardSearch()
{
    if (checkNoDate('rewardSearch','checkIn','checkOut') && checkDate('rewardSearch','checkIn','checkOut')){document.rewardSearch.submit()}
}

function copyToFlex() {
	if (calForm.flexCheckInDay) {
		calForm.flexCheckInDay.value=calForm.checkInDay.value;
	}
	
	if (calForm.flexCheckInMonthYr) {
		calForm.flexCheckInMonthYr.value=calForm.checkInMonthYr.value;
	}
}

function copyToFixed() {
	if (calForm.flexCheckInDay) {
		calForm.checkInDay.value=calForm.flexCheckInDay.value;
	}
	
	if (calForm.flexCheckInMonthYr) {
		calForm.checkInMonthYr.value=calForm.flexCheckInMonthYr.value;
	}
}
/*to make sure use does not select dates in the past or that check-out date is not before check-in - jkenney*/

// alert messages. These could be overridden by an outside js file containing
// language specific messages
var startDateNotPastDateMessage="Please revise your dates. Start date cannot be a past date.";
var eventStartDateNotPastDateMessage="Event Start date cannot be a past date";
var checkInDateNotPastDateMessage="Please revise your dates. Check-in date cannot be a past date.";
var dateLimit12MonthsMessage="Please enter dates within the next 12 months.";
var dateLimit365DaysMessage="Your travel dates must not be greater than 365 days in advance. Please enter new dates and try again.";
var eventEndAfterEventStartMessage="Event End date must be after Event Start date.";
var checkOutAfterCheckInMessage="Check-out date must be later than Check-in date";
var pleaseEnterStartDateMessage="Please enter a Start date";
var pleaseEnterValidDatesMessage="Please enter valid dates";
var groups3DaysFromTodayMessage="Please choose an Event Start Date more than 3 days from today. If you need to book a Group Event that is less than 3 days from today, please contact the hotel directly.";
var groups14DayLimitMessage="Please enter a date range of 14 days or less if you would like to book online.  If you need to book a group for more than 14 days, please leave dates blank for hotel search. Then, submit a Request for Proposal.";

// if forceEnglish (stored in cal.js) is true, then we will use these messages, which should 
// not be overridden
var startDateNotPastDateMessage_en="Start date cannot be a past date";
var eventStartDateNotPastDateMessage_en="Event Start date cannot be a past date";
var checkInDateNotPastDateMessage_en="Check-in date cannot be a past date";
var dateLimit12MonthsMessage_en="Please enter dates within the next 12 months.";
var dateLimit365DaysMessage_en="Your travel dates must not be greater than 365 days in advance. Please enter new dates and try again.";
var eventEndAfterEventStartMessage_en="Event End date must be after Event Start date.";
var checkOutAfterCheckInMessage_en="Check-out date must be later than Check-in date";
var pleaseEnterStartDateMessage_en="Please enter a Start date";
var pleaseEnterValidDatesMessage_en="Please enter valid dates";
var groups3DaysFromTodayMessage_en="Please choose an Event Start Date more than 3 days from today. If you need to book a Group Event that is less than 3 days from today, please contact the hotel directly.";
var groups14DayLimitMessage_en="Please enter a date range of 14 days or less if you would like to book online.  If you need to book a group for more than 14 days, please leave dates blank for hotel search. Then, submit a Request for Proposal.";


function checkDate(formName,checkin,checkout,issmallgroups) {

	var x = eval("document."+formName);
	var checkinDay = parseInt(x[checkin+"Day"].options[x[checkin+"Day"].selectedIndex].value);
	var checkinMonthYr = x[checkin+"MonthYr"].options[x[checkin+"MonthYr"].selectedIndex].value;
	var checkinMonth = checkinMonthYr.substring(0,3);
	var checkinYear = checkinMonthYr.substring(checkinMonthYr.indexOf(" "),checkinMonthYr.length);
	var checkoutDay = parseInt(x[checkout+"Day"].options[x[checkout+"Day"].selectedIndex].value);
	var checkoutMonthYr = x[checkout+"MonthYr"].options[x[checkout+"MonthYr"].selectedIndex].value;
	var checkoutMonth = checkoutMonthYr.substring(0,3);
	var checkoutYear = checkoutMonthYr.substring(checkoutMonthYr.indexOf(" "),checkoutMonthYr.length);
	
	var checkinMonthNum = getMonthNum(checkinMonth);
	var checkoutMonthNum = getMonthNum(checkoutMonth);
		
	var now = new Date();
	var currentDay = now.getDate();
	var currentMonth = now.getMonth()+1;
	var currentYear = now.getFullYear();

	/*debug
	alert("checkinYear: "+checkinYear);
	alert("currentYear: "+currentYear);
	alert(currentYear+1);
	alert("checkinMonthNum: "+checkinMonthNum);
	alert("currentMonth: "+currentMonth);
	alert("checkinDay: "+checkinDay);
	alert("currentDay: "+currentDay);
	alert("checkoutMonthNum: "+checkinMonthNum);
	alert("checkoutDay: "+checkinDay);
	*/

	if( (checkinDay != "-1") || (checkinMonthYr != "") ) {
		if (checkinYear <= currentYear && checkoutYear <= currentYear) {
			if ( (checkinMonthNum < currentMonth) || (checkinMonthNum <= currentMonth && checkinDay < currentDay) ) {
				if(x.flexibleSearch && x.flexibleSearch.value=="true") {
					alert (forceEnglish ? startDateNotPastDateMessage_en  : startDateNotPastDateMessage); 
					return false;
				}
                else if ( issmallgroups ) {
					alert (forceEnglish ? eventStartDateNotPastDateMessage_en : eventStartDateNotPastDateMessage); 
					return false;
                } 
				else {
					alert (forceEnglish ? checkInDateNotPastDateMessage_en  : checkInDateNotPastDateMessage ); 
					return false;
				}
			}
		}
		// we now make sure the checkout date is also with 365 days - as of May 2006 
		if (checkinYear == currentYear+1 && ((checkinMonthNum >= currentMonth && checkinDay >= currentDay) ||
                                         (checkoutMonthNum >= currentMonth && checkoutDay > currentDay))) {
                if ( issmallgroups ) {
				    alert (forceEnglish ? dateLimit12MonthsMessage_en : dateLimit12MonthsMessage);
                } else {
				    alert (forceEnglish ? dateLimit365DaysMessage_en : dateLimit365DaysMessage);
                }
				return false;
			}
		if(checkoutDay != '-1') {
			if ( (checkoutMonthNum < checkinMonthNum && checkoutYear <= checkinYear) || (checkoutMonthNum == checkinMonthNum && checkoutDay <= checkinDay && checkoutYear <= checkinYear) ) {
				if ( issmallgroups ) {
					alert (forceEnglish ? eventEndAfterEventStartMessage_en : eventEndAfterEventStartMessage);
				} else {
					alert (forceEnglish ? checkOutAfterCheckInMessage_en : checkOutAfterCheckInMessage);
				}
				return false;
			}
		}
		if(!(x.flexibleSearch && x.flexibleSearch.value=="true")) {

			if (checkoutYear < checkinYear) {
				if ( issmallgroups ) {
					alert (forceEnglish ? eventEndAfterEventStartMessage_en : eventEndAfterEventStartMessage);
				} else {
					alert (forceEnglish ? pleaseEnterValidDatesMessage_en : pleaseEnterValidDatesMessage);
				}
				return false;
			}
			else {
				return true;
			}
		}
		else {
			/* for the flexible search, they must enter data before continuing */
       if (checkNoDate(formName,'checkIn','checkOut')) {
  		 		return true;
       } else {
	        return false;
       }
		}
	}
	else {
		return true;
	}
	
}

function getMonthNum(month) 
{
	var monthNames = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var pattern = month;
	
		for (i=0; i<monthNames.length; i++) {
			if (monthNames[i].match(pattern)) {
				var monthNum = i+1;
				break;
			}
		}
		
		return monthNum;
}

/* to make sure the user enters dates for availibility search - jkenney*/
function checkNoDate(formName,checkin,checkout) {

	var x = eval("document."+formName);
	var checkinDay = parseInt(x[checkin+"Day"].options[x[checkin+"Day"].selectedIndex].value);
	var checkinMonthYr = x[checkin+"MonthYr"].options[x[checkin+"MonthYr"].selectedIndex].value;
	var checkinMonth = checkinMonthYr.substring(0,3);
	var checkinYear = checkinMonthYr.substring(checkinMonthYr.indexOf(" "),checkinMonthYr.length);
	var checkoutDay = parseInt(x[checkout+"Day"].options[x[checkout+"Day"].selectedIndex].value);
	var checkoutMonthYr = x[checkout+"MonthYr"].options[x[checkout+"MonthYr"].selectedIndex].value;
	var checkoutMonth = checkoutMonthYr.substring(0,3);
	var checkoutYear = checkoutMonthYr.substring(checkoutMonthYr.indexOf(" "),checkoutMonthYr.length);
	
	if ((checkinDay == "-1" || checkinMonthYr == "-1") ||(checkoutDay == "-1" || checkoutMonthYr == "-1")) {
		if(x.flexibleSearch && x.flexibleSearch.value=="true") {
			//alert("entered flexiblesearch");
			alert (forceEnglish ? pleaseEnterValidDatesMessage_en : pleaseEnterValidDatesMessage); 
			return false;
		}
		else {
			//alert("entered fixedsearch");
			alert (forceEnglish ? pleaseEnterValidDatesMessage_en : pleaseEnterValidDatesMessage);
			return false;
		}
	}
	else{
		return true;
	}
}

function isWithinNumDays(date1, date2, numday) {
	/* 1 day = 86400000 msec */
	//alert(date1+" "+date2+" "+numday);
	return (date2.getTime() >= date1.getTime() && (date2.getTime()-date1.getTime()) < 86400000*numday+1);
}

/* check date for groups search */
function checkGroupsDate(formName,checkin,checkout) {
	var now = new Date();
	var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
	var x = eval("document."+formName);
	var checkinDay = parseInt(x[checkin+"Day"].options[x[checkin+"Day"].selectedIndex].value);
	var checkinMonthYr = x[checkin+"MonthYr"].options[x[checkin+"MonthYr"].selectedIndex].value;
	var checkinMonth = checkinMonthYr.substring(0,3);
	var checkinYear = checkinMonthYr.substring(checkinMonthYr.indexOf(" "),checkinMonthYr.length);
	var checkoutDay = parseInt(x[checkout+"Day"].options[x[checkout+"Day"].selectedIndex].value);
	var checkoutMonthYr = x[checkout+"MonthYr"].options[x[checkout+"MonthYr"].selectedIndex].value;
	var checkoutMonth = checkoutMonthYr.substring(0,3);
	var checkoutYear = checkoutMonthYr.substring(checkoutMonthYr.indexOf(" "),checkoutMonthYr.length);
	
	var checkinDateToCheck = new Date(checkinYear, getMonthNum(checkinMonth)-1, checkinDay);
	var checkoutDateToCheck = new Date(checkoutYear, getMonthNum(checkoutMonth)-1, checkoutDay);
	
	if (checkDate(formName,checkin,checkout,true)) {
		if (checkinDay == "-1" || checkinDay == "" || checkoutDay == "-1" || checkoutMonthYr == "") {
			return true;
		} else {
			if (isWithinNumDays(checkinDateToCheck, checkoutDateToCheck, 14)) {
				if (!isWithinNumDays(today, checkinDateToCheck, 3)) {
					return true;
				} else {
					alert (forceEnglish ? groups3DaysFromTodayMessage_en : groups3DaysFromTodayMessage);
					return false;
				}
			} else {
				alert (forceEnglish ? groups14DayLimitMessage_en : groups14DayLimitMessage);
				return false;
			}
		}
	} else {
		return false;
	}
}
var formName;
var monthVal = new Array();
	
	monthVal["Jan"] = "0"
	monthVal["Feb"] = "1";
	monthVal["Mar"] = "2";
	monthVal["Apr"] = "3";
	monthVal["May"] = "4";
	monthVal["Jun"] = "5";
	monthVal["Jul"] = "6";
	monthVal["Aug"] = "7";
	monthVal["Sep"] = "8";
	monthVal["Oct"] = "9";
	monthVal["Nov"] = "10";
	monthVal["Dec"] = "11";
    
    
// alert messages. These could be overridden by an outside js file containing
// language specific messages /{locale/common/js/flex_dates.js
var rewardRedemption9NightLimitMessage="There is a 9-night limit on reward redemption. Please change your selected dates.";
var missingAirportMessage = "Please enter the aiport code or city, state, and/or country.";
var addressStateCountryMessage="Please enter an address and city/state inside the U.S.A. or a country outside the U.S.A.";
var airportStateCountryMessage="Please enter an aiport code or city, state inside the U.S.A, and/or country.";
var attractionStateCountryMessage="Please enter an attraction name, state inside the U.S.A, and/or country.";
var cityStateCountryMessage="Please enter a city/state inside the U.S.A. or a country outside the U.S.A.";

// if forceEnglish (stored in cal.js) is true, we will use these error messages which should not be overriden
var rewardRedemption9NightLimitMessage_en="There is a 9-night limit on reward redemption. Please change your selected dates.";
var missingAirportMessage_en = "Please enter the aiport code or city, state, and/or country.";
var addressStateCountryMessage_en="Please enter an address and city/state inside the U.S.A. or a country outside the U.S.A.";
var airportStateCountryMessage_en="Please enter an aiport code or city, state inside the U.S.A, and/or country.";
var attractionStateCountryMessage_en="Please enter an attraction name, state inside the U.S.A, and/or country.";
var cityStateCountryMessage_en="Please enter a city/state inside the U.S.A. or a country outside the U.S.A.";

function getLOS(los) {

	//alert(formName) // defined in jhtml page;
	//alert(los);
	var dayIndex = document.forms[formName].checkInDay.selectedIndex;
	var monthIndex = document.forms[formName].checkInMonthYr.options.selectedIndex;
	var day = document.forms[formName].checkInDay.options[dayIndex].value;
	var month = document.forms[formName].checkInMonthYr.options[monthIndex].value.substring(0,3);
	var year = document.forms[formName].checkInMonthYr.options[monthIndex].value.substring(document.forms[formName].checkInMonthYr.options[monthIndex].value.indexOf(" "),document.forms[formName].checkInMonthYr.options[monthIndex].value.length);
	
	//alert (day);
	//alert (month);
	//alert (year);

	var inDate = new Date( year,monthVal[month],day );
	inDate.setHours(12);
	//alert(inDate.getTime());
	var outDate = new Date( inDate.getTime() + (86400000 * los) );
	outDate.setHours(12);
	//alert(outDate.getTime());
	//alert(los);
	if( day != '-1' && month !='-1' )  {
		document.forms[formName].checkOutDay.value = outDate.getDate();
		//alert(outDate.getDate());
		document.forms[formName].checkOutMonthYr.value = dateToMonthYr( outDate );
		//alert(los);
	}
	
}

function reflectLOS(los) {

	//alert(formName) // defined in jhtml page;
	
	//alert(los);
	var inDayIndex = document.forms[formName].checkInDay.selectedIndex;
	var inMonthIndex = document.forms[formName].checkInMonthYr.options.selectedIndex;
	var inDay = document.forms[formName].checkInDay.options[inDayIndex].value;
	var inMonth = document.forms[formName].checkInMonthYr.options[inMonthIndex].value.substring(0,3);
	var inYear = document.forms[formName].checkInMonthYr.options[inMonthIndex].value.substring(document.forms[formName].checkInMonthYr.options[inMonthIndex].value.indexOf(" "),document.forms[formName].checkInMonthYr.options[inMonthIndex].value.length);

	var outDayIndex = document.forms[formName].checkOutDay.selectedIndex;
	var outMonthIndex = document.forms[formName].checkOutMonthYr.options.selectedIndex;
	var outDay = document.forms[formName].checkOutDay.options[outDayIndex].value;
	var outMonth = document.forms[formName].checkOutMonthYr.options[outMonthIndex].value.substring(0,3);
	var outYear = document.forms[formName].checkOutMonthYr.options[outMonthIndex].value.substring(document.forms[formName].checkOutMonthYr.options[outMonthIndex].value.indexOf(" "),document.forms[formName].checkOutMonthYr.options[outMonthIndex].value.length);
	

	var inDate2 = new Date( inYear,monthVal[inMonth],inDay );
	inDate2.setHours(12);
	//alert(inDate.getTime());
	var outDate2 = new Date( outYear,monthVal[outMonth],outDay );
	outDate2.setHours(12);
	//alert(outDate.getTime());
	var diff = 0; 
    tmp_diff = (outDate2.getTime() - inDate2.getTime()) / 86400000;
    diff = parseInt(tmp_diff); 
	//alert(diff);

	var monthname=new Array("Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık");
            var next_date = new Date( inYear,monthVal[inMonth],Number(inDay) + 1 );  
                
    	diff = parseInt(tmp_diff); 
    
             if (inDay != '-1' && outDay != '-1') {            
                     if (diff <= 0) {          
    			 document.forms[formName].los.value = 1; 
                             document.forms[formName].checkOutMonthYr.value = monthname[next_date.getMonth()]+" "+next_date.getFullYear(); 
                             document.forms[formName].checkOutDay.value = next_date.getDate(); 
                       } 
                       else if (diff <= 14) { 
    
                            document.forms[formName].los.value = diff;
                    }
                    else {
                           document.forms[formName].los.value = "14";
                   }
           }
	
}

function checkLOSLimit() {


	var inDayIndex2 = document.forms[formName].checkInDay.selectedIndex;
	var inMonthIndex2 = document.forms[formName].checkInMonthYr.options.selectedIndex;
	var inDay2 = document.forms[formName].checkInDay.options[inDayIndex2].value;
	var inMonth2 = document.forms[formName].checkInMonthYr.options[inMonthIndex2].value.substring(0,3);
	var inYear2 = document.forms[formName].checkInMonthYr.options[inMonthIndex2].value.substring(document.forms[formName].checkInMonthYr.options[inMonthIndex2].value.indexOf(" "),document.forms[formName].checkInMonthYr.options[inMonthIndex2].value.length);
	
	var outDayIndex2 = document.forms[formName].checkOutDay.selectedIndex;
	var outMonthIndex2 = document.forms[formName].checkOutMonthYr.options.selectedIndex;
	var outDay2 = document.forms[formName].checkOutDay.options[outDayIndex2].value;
	var outMonth2 = document.forms[formName].checkOutMonthYr.options[outMonthIndex2].value.substring(0,3);
	var outYear2 = document.forms[formName].checkOutMonthYr.options[outMonthIndex2].value.substring(document.forms[formName].checkOutMonthYr.options[outMonthIndex2].value.indexOf(" "),document.forms[formName].checkOutMonthYr.options[outMonthIndex2].value.length);
	
	
	var inDate2 = new Date( inYear2,monthVal[inMonth2],inDay2 );
	inDate2.setHours(12);
	//alert(inDate.getTime());
	var outDate2 = new Date( outYear2,monthVal[outMonth2],outDay2 );
	outDate2.setHours(12);
	//alert(outDate.getTime());
	var tmp_diff2 = 0; 
	var diff2 = 0; 
	tmp_diff2 = (outDate2.getTime() - inDate2.getTime()) / 86400000;
	diff2 = parseInt(tmp_diff2); 

	if (outDay2 != '-1') {

		if (diff2 > 9) {
			alert(forceEnglish ? rewardRedemption9NightLimitMessage_en : rewardRedemption9NightLimitMessage);
			return false;
		}
		else {

			return true;
		}
	}
}

function dateToMonthYr( date )
{

	var string = monthnames[ date.getMonth() ] + " " + date.getFullYear();

	//alert(string);
	return string;
}

function setFlexSearch(value) {
	if (document.forms[formName].flexibleSearch) {
		document.forms[formName].flexibleSearch.value=value;
	}
}

function checkFlexSearch(formName) {

var flexSearch = document.forms[formName].flexibleSearch;
var losIndex = document.forms[formName].los.options.selectedIndex;
var losVal = document.forms[formName].los.options[losIndex].value;

	if (flexSearch.value == "true") {
		
		getLOS(losVal);
		
	}
}

function checkFlexSearchNoDates (formName) {

var flexSearch = document.forms[formName].flexibleSearch;

	if (flexSearch.value == "true") {
		
		if (checkNoDate(formName,'checkIn','checkOut')) {
			return true;
		}
		else {
			return false;
		}
	}
	else {
		return true;
	}
}

function checkBrandsToSearch(formName)
{
	var brandsIndex = document.forms[formName].brands.selectedIndex;
	var brandsVal = document.forms[formName].brands[brandsIndex].value;

	if (brandsVal == "true" || brandsVal == "")
	{
		document.forms[formName].searchAll.value = "true";
	}
}

function validateRewardSearch(formName) {

var countryIndex = document.forms[formName].country.selectedIndex
var countryVal = document.forms[formName].country[countryIndex].value
var stateIndex = document.forms[formName].state.selectedIndex
var stateVal = document.forms[formName].state[stateIndex].value

	//checkDate function in date_check.js

	if (checkDate(formName,'checkIn','checkOut')) {

		if (checkHRRStateCountry(formName, countryVal, stateVal)) {
		
			if (document.forms[formName].flexibleSearch.value=="true") {
				

				getLOS(document.forms[formName].los.options[document.forms[formName].los.options.selectedIndex].value);

				if (checkFlexSearchNoDates(formName)) {

					if (checkLOSLimit()) {
										
						document.forms[formName].submit();
					}				
				}
			}
			else {	

					document.forms[formName].submit();
			}
		}
	}
}


function validateHotelRewardSearch(formName) {

	//checkDate function in date_check.js
	if (checkDate(formName,'checkIn','checkOut')) {
		
		if (document.forms[formName].flexibleSearch.value=="true") {
				
				getLOS(document.forms[formName].los.options[document.forms[formName].los.options.selectedIndex].value);
									
			if (checkFlexSearchNoDates(formName)) {

				if (checkLOSLimit()) {
									
					document.forms[formName].submit();
				}
					
			}
		}
			
		else {
		
				document.forms[formName].submit();
		}
	}
}

function validateHomeSearch(formName) {

// this is pretty much the same as validateRewardSearch, but there is no LOS limit

var countryIndex = document.forms[formName].country.selectedIndex
var countryVal = document.forms[formName].country[countryIndex].value
var stateIndex = document.forms[formName].state.selectedIndex
var stateVal = document.forms[formName].state[stateIndex].value

var guestSuitesIndex
var guestSuitesValue
var tempCheck = document.forms[formName].guestSuitesFixed.selectedIndex
if(tempCheck != null && tempCheck != 'null' && tempCheck != 'undefined' )
{
	guestSuitesIndex = document.forms[formName].guestSuitesFixed.selectedIndex
	guestSuitesValue = document.forms[formName].guestSuitesFixed[guestSuitesIndex].value 
}
else
{
	guestSuitesIndex = 0
	guestSuitesValue = document.forms[formName].guestSuitesFlex[0].value 
}

var action;

	document.forms[formName].hdnGuestSuitsIndex.value = guestSuitesIndex;
		
	document.forms[formName].hdnGuestSuits.value = guestSuitesValue;
	
	if(guestSuitesValue > 1)
	{
		action = document.forms[formName].hdnMedAction.value
		document.forms[formName].action = action+'?it='+document.forms[formName].it.value;
	}
	else
	{
		action = document.forms[formName].hdnMainAction.value
		document.forms[formName].action = action+'?it='+document.forms[formName].it.value;
	}
	
	if (checkDate(formName,'checkIn','checkOut')) {
		
		if (checkStateCountry(formName, countryVal, stateVal)) {

			if (document.forms[formName].flexibleSearch.value=="true") {

				getLOS(document.forms[formName].los.options[document.forms[formName].los.options.selectedIndex].value);

				if (checkFlexSearchNoDates(formName)) {
					document.forms[formName].submit();
				}
			}
			else {	
					
					document.forms[formName].submit();
			}
		}
		
	}
}

function validateChangeSearch(formName) {

// this is pretty much the same as validateRewardSearch, but there is no LOS limit

var countryIndex = document.forms[formName].country.selectedIndex
var countryVal = document.forms[formName].country[countryIndex].value
var stateIndex = document.forms[formName].state.selectedIndex
var stateVal = document.forms[formName].state[stateIndex].value

//copySelectedCtyhocns(formName);

	var checkboxes = document.forms[formName].selectedHotels;
	var ctyhocns = "";

	if (checkboxes) {
		if (checkboxes.length) {
			// there are an array of checkboxes, loop through them
			for (var i = 0; i < checkboxes.length; i++) {
				if (checkboxes[i].checked) {
					ctyhocns = ctyhocns + checkboxes[i].value + ",";
				}
			}
		} else {
			// there is only one checkbox, get it's value
			if (checkboxes.checked) {
				ctyhocns = checkboxes.value + ",";
			}
		}
	}
	
	document.forms[formName].selectedHotels.value= ctyhocns.substring( 0, ctyhocns.length - 1 );


	if (checkDate(formName,'checkIn','checkOut')) {

		if (checkChangeStateCountry(formName, countryVal, stateVal)) {
		
			if (document.forms[formName].flexibleSearch.value=="true") {
				
				getLOS(document.forms[formName].los.options[document.forms[formName].los.options.selectedIndex].value);

				if (checkFlexSearchNoDates(formName)) {

						document.forms[formName].submit();
				}
			}
			else {	

					document.forms[formName].submit();
			}
		}
		else {
			return false;
		}
	}
}

function validateAdvancedSearch(formName) {

// used by the advanced hotel search page's city tab

var countryIndex = document.forms[formName].country.selectedIndex
var countryVal = document.forms[formName].country[countryIndex].value
var stateIndex = document.forms[formName].state.selectedIndex
var stateVal = document.forms[formName].state[stateIndex].value

	//checkDate function in date_check.js

	if (checkDate(formName,'checkIn','checkOut')) {

		if (checkStateCountry(formName, countryVal, stateVal)) {
		
			if (document.forms[formName].flexibleSearch.value=="true") {
				

				getLOS(document.forms[formName].los.options[document.forms[formName].los.options.selectedIndex].value);

				if (checkFlexSearchNoDates(formName)) {

					document.forms[formName].submit();

				}
			}
			else {	

					document.forms[formName].submit();
			}
		}
	}
}

function validateAdvancedAirportSearch(formName) {

// used by the advanced hotel search page's airport tab
// that form doesn't have 'city', but instead has an 'airport' field

var countryIndex = document.forms[formName].country.selectedIndex
var countryVal = document.forms[formName].country[countryIndex].value
var stateIndex = document.forms[formName].state.selectedIndex
var stateVal = document.forms[formName].state[stateIndex].value

var keepgoing = true;

	//checkDate function in date_check.js

	if (checkDate(formName,'checkIn','checkOut')) {

		if (document.forms[formName].airport.value == 'City or Airport Code') {
				alert(forceEnglish ? missingAirportMessage_en : missingAirportMessage);
        keepgoing = false;
        return;
		}
		else if (document.forms[formName].airport.value == '') {
			alert(forceEnglish ? missingAirportMessage_en : missingAirportMessage);
      keepgoing = false;
		}

    if (keepgoing) {		
			if (document.forms[formName].flexibleSearch.value=="true") {

				getLOS(document.forms[formName].los.options[document.forms[formName].los.options.selectedIndex].value);

				if (checkFlexSearchNoDates(formName)) {

					if (checkLOSLimit()) {
										
						document.forms[formName].submit();
					}
				}
			}
			else {	

					document.forms[formName].submit();
			}
		}
  }
}

function validateStaticSearch(formName) {

// this is pretty much the same as validateRewardSearch, but we arent
// checking for LOS, and aren't checking for flexible search = true

var countryIndex = document.forms[formName].country.selectedIndex
var countryVal = document.forms[formName].country[countryIndex].value
var stateIndex = document.forms[formName].state.selectedIndex
var stateVal = document.forms[formName].state[stateIndex].value

	//checkDate function in date_check.js

	if (checkDate(formName,'checkIn','checkOut')) {

		if (checkStateCountry(formName, countryVal, stateVal)) {

			document.forms[formName].submit();
		}
	}
}

function checkHRRStateCountry(formName, countryVal, stateVal) {

	var stateCountryMessage;
	var formType = document.forms[formName].searchType.value;
	
	// if the user has selected a top destination, we can skip all this
	if (document.forms[formName].topDestination) {
		if (document.forms[formName].topDestination.value != "") {
			return true;
		}
	}
	
	if (document.forms[formName].searchType.value=="address") {
		stateCountryMessage = forceEnglish ? addressStateCountryMessage_en : addressStateCountryMessage;
	}
	else if (document.forms[formName].searchType.value=="airport") {
		stateCountryMessage = forceEnglish ? airportStateCountryMessage_en : airportStateCountryMessage;
	}
	else if (document.forms[formName].searchType.value=="attraction") {
		stateCountryMessage = forceEnglish ? attractionStateCountryMessage_en : attractionStateCountryMessage;
	}
	else {
		stateCountryMessage = forceEnglish ? cityStateCountryMessage_en : cityStateCountryMessage;
	}

	if (countryVal == 'US' && stateVal == '') {
	//added for 17147
		 if(formType == "airport"){
			   if (document.forms[formName].airport.value == 'City or Airport Code') {
                                alert(stateCountryMessage);
                                return false;
                        }
                        else if (document.forms[formName].airport.value == '') {
                                alert(stateCountryMessage);
                                return false;
                        }
                        else {
                        
                                return true;
                        }
			
			}
			else{
                alert(stateCountryMessage);
                return false;
				}
		
	}
	else if (countryVal == 'US' && stateVal != '') {
		
		if (formType == "city") {
	
			if (document.forms[formName].city.value == 'City') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].city.value == 'City or Airport Code') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].city.value == 'Attraction name') {
				alert(stateCountryMessage);
				return false;
			} 
			else if (document.forms[formName].city.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		}
		else if (formType == "airport") {
		
			 if (document.forms[formName].city.value == 'City or Airport Code') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].city.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		}
		else if (formType == "attraction") {
		
			 if (document.forms[formName].city.value == 'Attraction name') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].city.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		}
		else {
			return true;
		}
	}
	else {

		return true;
	}
}

function checkChangeStateCountry(formName, countryVal, stateVal) {

	var stateCountryMessage;
	
	if (document.forms[formName].searchType.value=="address") {
		stateCountryMessage = forceEnglish ? addressStateCountryMessage_en : addressStateCountryMessage;
	}
	else if (document.forms[formName].searchType.value=="airport") {
		stateCountryMessage = forceEnglish ? airportStateCountryMessage_en : airportStateCountryMessage;
	}
	else if (document.forms[formName].searchType.value=="attraction") {
		stateCountryMessage = forceEnglish ? attractionStateCountryMessage_en : attractionStateCountryMessage;
	}
	else {
		stateCountryMessage = forceEnglish ? cityStateCountryMessage_en : cityStateCountryMessage;
	}

	if (countryVal == 'US' && stateVal == '') {
		//added for 17147
		 if(formType == "airport"){
			   if (document.forms[formName].airport.value == 'City or Airport Code') {
                                alert(stateCountryMessage);
                                return false;
                        }
                        else if (document.forms[formName].airport.value == '') {
                                alert(stateCountryMessage);
                                return false;
                        }
                        else {
                        
                                return true;
                        }
			
			}
			else{
                alert(stateCountryMessage);
                return false;
				}
	}
	else if (countryVal == 'US' && stateVal != '') {
		
		if (document.forms[formName].airport) {
		
			 if (document.forms[formName].airport.value == 'City or Airport Code') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].airport.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		}
		else if (document.forms[formName].attraction) {
		
			 if (document.forms[formName].attraction.value == 'Attraction name') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].attraction.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		}
		else {
			return true;
		}
	}
	else {

		return true;
	}
}

function checkStateCountry(formName, countryVal, stateVal) {

	var stateCountryMessage;
	var formType = document.forms[formName].searchType.value;
	
	if (document.forms[formName].searchType.value=="address") {
		stateCountryMessage = forceEnglish ? addressStateCountryMessage_en : addressStateCountryMessage;
	}
	else if (document.forms[formName].searchType.value=="airport") {
		stateCountryMessage = forceEnglish ? airportStateCountryMessage_en : airportStateCountryMessage;
	}
	else if (document.forms[formName].searchType.value=="attraction") {
		stateCountryMessage = forceEnglish ? attractionStateCountryMessage_en : attractionStateCountryMessage;
	}
	else {
		stateCountryMessage = forceEnglish ? cityStateCountryMessage_en : cityStateCountryMessage;
	}

	if (countryVal == 'US' && stateVal == '') {
		//added for 17147
		 if(formType == "airport"){
			   if (document.forms[formName].airport.value == 'City or Airport Code') {
                                alert(stateCountryMessage);
                                return false;
                        }
                        else if (document.forms[formName].airport.value == '') {
                                alert(stateCountryMessage);
                                return false;
                        }
                        else {
                        
                                return true;
                        }
			
			}
			else{
                alert(stateCountryMessage);
                return false;
				}
	}
	else if (countryVal == 'US' && stateVal != '') {
	
		if (formType == "city") {
			
			return true;
			
		}		
		else if (formType == "airport") {
		
			 if (document.forms[formName].airport.value == 'City or Airport Code') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].airport.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		}
		else if (formType == "attraction") {
		
			 if (document.forms[formName].attraction.value == 'Attraction name') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].attraction.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
			
				return true;
			}
		} 
		else if (formType == "address") {
			if (document.forms[formName].address.value == 'Address') {
				alert(stateCountryMessage);
				return false;
			}
			else if (document.forms[formName].address.value == '') {
				alert(stateCountryMessage);
				return false;
			}
			else {
				return true;
			}
		}
		else {
			return true;
		}
	}
	else {

		return true;
	}
}

function swapElement(hideElement,showElement)
{
	document.getElementById(hideElement).style.display="none";
	document.getElementById(showElement).style.display="";
}

function swapText(element,newTxt)
{
	document.getElementById(element).innerHTML = newTxt;
}

// copy our standard date fields from one form to another
function copyDates(fromFormName, toFormName) {
	var fromForm = document.forms[fromFormName];
	var toForm = document.forms[toFormName];

	if (fromForm && toForm) {
		if (fromForm.checkInDay && toForm.checkInDay) {
			toForm.checkInDay.value = fromForm.checkInDay.value;
		}
		
		if (fromForm.checkInMonthYr && toForm.checkInMonthYr) {
			toForm.checkInMonthYr.value = fromForm.checkInMonthYr.value;
		}
		
		if (fromForm.checkOutDay && toForm.checkOutDay) {
			toForm.checkOutDay.value = fromForm.checkOutDay.value;
		}
		
		if (fromForm.checkOutMonthYr && toForm.checkOutMonthYr) {
			toForm.checkOutMonthYr.value = fromForm.checkOutMonthYr.value;
		}
		
		if (fromForm.flexCheckInDay && toForm.flexCheckInDay) {
			toForm.flexCheckInDay.value = fromForm.flexCheckInDay.value;
		}
		
		if (fromForm.flexCheckInMonthYr && toForm.flexCheckInMonthYr) {
			toForm.flexCheckInMonthYr.value = fromForm.flexCheckInMonthYr.value;
		}
		
		if (fromForm.los && toForm.los) {
			toForm.los.value = fromForm.los.value;
		}
	}
}
// this javascript is used to automagically set the state and country for 
// a search when a user enters one of the following top cities around the world
// NOTE: keys for the topCities associative array must be in all uppercase. The
// function that uses it upper cases the city passed in so that the search is
// case insensitive
var tC = new Array(); // short for "topCities"
// US Cities
tC["NEW YORK"] = gCO('New York', 'NY', 'US');
tC["LOS ANGELES"] = gCO('Los Angeles', 'CA', 'US');
tC["CHICAGO"] = gCO('Chicago', 'IL', 'US');
tC["HOUSTON"] = gCO('Houston', 'TX', 'US');
tC["PHILADELPHIA"] = gCO('Philadelphia', 'PA', 'US');
tC["PHOENIX"] = gCO('Phoenix', 'AZ', 'US');
tC["SAN DIEGO"] = gCO('San Diego', 'CA', 'US');
tC["DALLAS"] = gCO('Dallas', 'TX', 'US');
tC["SAN ANTONIO"] = gCO('San Antonio', 'TX', 'US');
tC["DETROIT"] = gCO('Detroit', 'MI', 'US');
tC["SAN JOSE"] = gCO('San Jose', 'CA', 'US');
tC["INDIANAPOLIS"] = gCO('Indianapolis', 'IN', 'US');
tC["SAN FRANCISCO"] = gCO('San Francisco', 'CA', 'US');
tC["COLUMBUS"] = gCO('Columbus', 'OH', 'US');
tC["AUSTIN"] = gCO('Austin', 'TX', 'US');
tC["BALTIMORE"] = gCO('Baltimore', 'MD', 'US');
tC["MILWAUKEE"] = gCO('Milwaukee', 'WI', 'US');
tC["BOSTON"] = gCO('Boston', 'MA', 'US');
tC["WASHINGTON"] = gCO('Washington', 'DC', 'US');
tC["EL PASO"] = gCO('El Paso', 'TX', 'US');
tC["SEATTLE"] = gCO('Seattle', 'WA', 'US');
tC["DENVER"] = gCO('Denver', 'CO', 'US');
tC["CHARLOTTE"] = gCO('Charlotte', 'NC', 'US');
tC["FORT WORTH"] = gCO('Fort Worth', 'TX', 'US');
tC["OKLAHOMA CITY"] = gCO('Oklahoma City', 'OK', 'US');
tC["TUCSON"] = gCO('Tucson', 'AZ', 'US');
tC["NEW ORLEANS"] = gCO('New Orleans', 'LA', 'US');
tC["LAS VEGAS"] = gCO('Las Vegas', 'NV', 'US');
tC["CLEVELAND"] = gCO('Cleveland', 'OH', 'US');
tC["LONG BEACH"] = gCO('Long Beach', 'CA', 'US');
tC["ALBUQUERQUE"] = gCO('Albuquerque', 'NM', 'US');
tC["FRESNO"] = gCO('Fresno', 'CA', 'US');
tC["VIRGINIA BEACH"] = gCO('Virginia Beach', 'VA', 'US');
tC["ATLANTA"] = gCO('Atlanta', 'GA', 'US');
tC["SACRAMENTO"] = gCO('Sacramento', 'CA', 'US');
tC["OAKLAND"] = gCO('Oakland', 'CA', 'US');
tC["MESA"] = gCO('Mesa', 'AZ', 'US');
tC["TULSA"] = gCO('Tulsa', 'OK', 'US');
tC["OMAHA"] = gCO('Omaha', 'NE', 'US');
tC["MINNEAPOLIS"] = gCO('Minneapolis', 'MN', 'US');
tC["HONOLULU"] = gCO('Honolulu', 'HI', 'US');
tC["COLORADO SPRINGS"] = gCO('Colorado Springs', 'CO', 'US');
tC["ST. LOUIS"] = gCO('St. Louis', 'MO', 'US');
tC["ST LOUIS"] = gCO('St. Louis', 'MO', 'US');
tC["SAINT LOUIS"] = gCO('St. Louis', 'MO', 'US');
tC["WICHITA"] = gCO('Wichita', 'KS', 'US');
tC["SANTA ANA"] = gCO('Santa Ana', 'CA', 'US');
tC["PITTSBURGH"] = gCO('Pittsburgh', 'PA', 'US');
tC["CINCINNATI"] = gCO('Cincinnati', 'OH', 'US');
tC["ANAHEIM"] = gCO('Anaheim', 'CA', 'US');
tC["BUFFALO"] = gCO('Buffalo', 'NY', 'US');
tC["ST. PAUL"] = gCO('St. Paul', 'MN', 'US');
tC["ST PAUL"] = gCO('St. Paul', 'MN', 'US');
tC["SAINT PAUL"] = gCO('St. Paul', 'MN', 'US');
tC["CORPUS CHRISTI"] = gCO('Corpus Christi', 'TX', 'US');
tC["AURORA"] = gCO('Aurora', 'CO', 'US');
tC["RALEIGH"] = gCO('Raleigh', 'NC', 'US');
tC["NEWARK"] = gCO('Newark', 'NJ', 'US');
tC["LEXINGTON-FAYETTE"] = gCO('Lexington-Fayette', 'KY', 'US');
tC["ANCHORAGE"] = gCO('Anchorage', 'AK', 'US');
tC["LOUISVILLE"] = gCO('Louisville', 'KY', 'US');
tC["RIVERSIDE"] = gCO('Riverside', 'CA', 'US');
tC["BAKERSFIELD"] = gCO('Bakersfield', 'CA', 'US');
tC["STOCKTON"] = gCO('Stockton', 'CA', 'US');
tC["BIRMINGHAM"] = gCO('Birmingham', 'AL', 'US');
tC["JERSEY CITY"] = gCO('Jersey City', 'NJ', 'US');
tC["NORFOLK"] = gCO('Norfolk', 'VA', 'US');
tC["BATON ROUGE"] = gCO('Baton Rouge', 'LA', 'US');
tC["HIALEAH"] = gCO('Hialeah', 'FL', 'US');
tC["LINCOLN"] = gCO('Lincoln', 'NE', 'US');
tC["GREENSBORO"] = gCO('Greensboro', 'NC', 'US');
tC["PLANO"] = gCO('Plano', 'TX', 'US');
tC["ROCHESTOR"] = gCO('Rochester', 'NY', 'US');
tC["GLENDALE"] = gCO('Glendale', 'AZ', 'US');
tC["AKRON"] = gCO('Akron', 'OH', 'US');
tC["GARLAND"] = gCO('Garland', 'TX', 'US');
tC["MADISON"] = gCO('Madison', 'WI', 'US');
tC["FORT WAYNE"] = gCO('Fort Wayne', 'IN', 'US');
tC["FREMONT"] = gCO('Fremont', 'CA', 'US');
tC["SCOTTSDALE"] = gCO('Scottsdale', 'AZ', 'US');
tC["MONTGOMERY"] = gCO('Montgomery', 'AL', 'US');
tC["SHREVEPORT"] = gCO('Shreveport', 'LA', 'US');
tC["LUBBOCK"] = gCO('Lubbock', 'TX', 'US');
tC["CHESAPEAKE"] = gCO('Chesapeake', 'VA', 'US');
tC["MOBILE"] = gCO('Mobile', 'AL', 'US');
tC["DES MOINES"] = gCO('Des Moines', 'IA', 'US');
tC["GRAND RAPIDS"] = gCO('Grand Rapids', 'MI', 'US');
tC["RICHMOND"] = gCO('Richmond', 'VA', 'US');
tC["YONKERS"] = gCO('Yonkers', 'NY', 'US');
tC["SPOKANE"] = gCO('Spokane', 'WA', 'US');
tC["AUGUSTA-RICHMOND COUNTY"] = gCO('Augusta-Richmond County', 'GA', 'US');
tC["GLENDALE"] = gCO('Glendale', 'CA', 'US');
tC["TACOMA"] = gCO('Tacoma', 'WA', 'US');
tC["IRVING"] = gCO('Irving', 'TX', 'US');
tC["HUNTINGTON BEACH"] = gCO('Huntington Beach', 'CA', 'US');
tC["MODESTO"] = gCO('Modesto', 'CA', 'US');
tC["DURHAM"] = gCO('Durham', 'NC', 'US');
tC["BOISE"] = gCO('Boise', 'ID', 'US');
tC["WINSTON-SALEM"] = gCO('Winston-Salem', 'NC', 'US');
tC["HONOLULU"] = gCO('Honolulu', 'HI', 'US');
tC["MAUI"] = gCO('Maui', 'HI', 'US');
tC["MEMPHIS"] = gCO('Memphis', 'TN', 'US');
tC["MIAMI"] = gCO('Miami', 'FL', 'US');
tC["ORLANDO"] = gCO('Orlando', 'FL', 'US');

// Canadian cities
tC["TORONTO"] = gCO('Toronto', 'ON', 'CA');
tC["MONTRÉAL"] = gCO('Montreal', 'QC', 'CA');
tC["MONTREAL"] = gCO('Montreal', 'QC', 'CA');
tC["OTTOWA"] = gCO('Ottawa', 'ON', 'CA');
tC["EDMONTON"] = gCO('Edmonton', 'AB', 'CA');
tC["CALGARY"] = gCO('Calgary', 'AB', 'CA');
tC["QUEBÉC"] = gCO('Quebec', 'QC', 'CA');
tC["QUEBEC"] = gCO('Quebec', 'QC', 'CA');
tC["WINNIPEG"] = gCO('Winnipeg', 'MB', 'CA');
tC["HAMILTON"] = gCO('Hamilton', 'ON', 'CA');
tC["LONDON"] = gCO('London', 'ON', 'CA');
tC["KITCHENER"] = gCO('Kitchener', 'ON', 'CA');
tC["ST CATHARINES-NIAGARA"] = gCO('St Catharines-Niagara', 'ON', 'CA');
tC["HALIFAX"] = gCO('Halifax', 'NS', 'CA');
tC["VICTORIA"] = gCO('Victoria', 'BC', 'CA');
tC["WINDSOR"] = gCO('Windsor', 'ON', 'CA');
tC["OSHAWA"] = gCO('Oshawa', 'ON', 'CA');
tC["SASKATOON"] = gCO('Saskatoon', 'SK', 'CA');
tC["REGINA"] = gCO('Regina', 'SK', 'CA');
tC["ST JOHN'S"] = gCO('St John\'s', 'NF', 'CA');
tC["ST JOHNS"] = gCO('St John\'s', 'NF', 'CA');
tC["SUDBURY"] = gCO('Sudbury', 'ON', 'CA');
tC["CHICOUTIMI"] = gCO('Chicoutimi', 'QC', 'CA');
tC["SHERBROOKE"] = gCO('Sherbrooke', 'QC', 'CA');
tC["KINGSTON"] = gCO('Kingston', 'ON', 'CA');
tC["TROIS-RIVIÈRES"] = gCO('Trois-Rivières', 'QC', 'CA');
tC["TROIS-RIVIERES"] = gCO('Trois-Rivières', 'QC', 'CA');
tC["KELOWNA"] = gCO('Kelowna', 'BC', 'CA');
tC["ABBOTSFORD"] = gCO('Abbotsford', 'BC', 'CA');
tC["SAINT JOHN"] = gCO('Saint John', 'NB', 'CA');
tC["THUNDER BAY"] = gCO('Thunder Bay', 'ON', 'CA');
tC["BARRIE"] = gCO('Barrie', 'ON', 'CA');
tC["SYDNEY"] = gCO('Sydney', 'NS', 'CA');

// United Kingdom
tC["LONDON"] = gCO('London', '', 'GB');
tC["BIRMINGHAM"] = gCO('Birmingham', '', 'GB');
tC["LEEDS"] = gCO('Leeds', '', 'GB');
tC["GLASGOW"] = gCO('Glasgow', '', 'GB');
tC["SHEFFIELD"] = gCO('Sheffield', '', 'GB');
tC["BRADFORD"] = gCO('Bradford', '', 'GB');
tC["LIVERPOOL"] = gCO('Liverpool', '', 'GB');
tC["EDINBURGH"] = gCO('Edinburgh', '', 'GB');
tC["MANCHESTER"] = gCO('Manchester', '', 'GB');
tC["BRISTOL"] = gCO('Bristol', '', 'GB');
tC["KIRKLEES"] = gCO('Kirklees', '', 'GB');
tC["FIFE"] = gCO('Fife', '', 'GB');
tC["WIRRAL"] = gCO('Wirral', '', 'GB');
tC["NORTH LANARKSHIRE"] = gCO('North Lanarkshire', '', 'GB');
tC["WAKEFIELD"] = gCO('Wakefield', '', 'GB');
tC["CARDIFF"] = gCO('Cardiff', '', 'GB');
tC["DUDLEY"] = gCO('Dudley', '', 'GB');
tC["WIGAN"] = gCO('Wigan', '', 'GB');
tC["EAST RIDING"] = gCO('East Riding', '', 'GB');
tC["SOUTH LANARKSHIRE"] = gCO('South Lanarkshire', '', 'GB');
tC["COVENTRY"] = gCO('Coventry', '', 'GB');
tC["HELFAST"] = gCO('Belfast', '', 'GB');
tC["LEICESTER"] = gCO('Leicester', '', 'GB');
tC["SUNDERLAND"] = gCO('Sunderland', '', 'GB');
tC["SANDWELL"] = gCO('Sandwell', '', 'GB');
tC["DONCASTER"] = gCO('Doncaster', '', 'GB');
tC["STOCKPORT"] = gCO('Stockport', '', 'GB');
tC["SEFTON"] = gCO('Sefton', '', 'GB');
tC["NOTTINGHAM"] = gCO('Nottingham', '', 'GB');
tC["NEWCASTLE-UPON-TYNE"] = gCO('Newcastle-upon-Tyne', '', 'GB');
tC["KINGSTON-UPON-HULL"] = gCO('Kingston-upon-Hull', '', 'GB');
tC["BOLTON"] = gCO('Bolton', '', 'GB');
tC["WALSALL"] = gCO('Walsall', '', 'GB');
tC["PLYMOUTH"] = gCO('Plymouth', '', 'GB');
tC["ROTHERHAM"] = gCO('Rotherham', '', 'GB');
tC["STOKE-ON-TRENT"] = gCO('Stoke-on-Trent', '', 'GB');
tC["WOLVERHAMPTON"] = gCO('Wolverhampton', '', 'GB');
tC["RHONDDA, CYNON, TAFF"] = gCO('Rhondda, Cynon, Taff', '', 'GB');
tC["SOUTH GLOUCESTERSHIRE"]= gCO('South Gloucestershire', '', 'GB');
tC["DERBY"] = gCO('Derby', '', 'GB');
tC["SWANSEA"] = gCO('Swansea', '', 'GB');
tC["SALFORD"] = gCO('Salford', '', 'GB');
tC["ABERDEENSHIRE"] = gCO('Aberdeenshire', '', 'GB');
tC["BARNSLEY"] = gCO('Barnsley', '', 'GB');
tC["TAMESIDE"] = gCO('Tameside', '', 'GB');
tC["OLDHAM"] = gCO('Oldham', '', 'GB');
tC["TRAFFORD"] = gCO('Trafford', '', 'GB');
tC["ABERDEEN"] = gCO('Aberdeen', '', 'GB');
tC["SOUTHAMPTON"] = gCO('Southampton', '', 'GB');
tC["HIGHLAND"] = gCO('Highland', '', 'GB');
tC["ROCHDALE"] = gCO('Rochdale', '', 'GB');
tC["SOLIHULL"] = gCO('Solihull', '', 'GB');
tC["GATESHEAD"] = gCO('Gateshead', '', 'GB');
tC["MILTON KEYNES"] = gCO('Milton Keynes', '', 'GB');
tC["NORTH TYNESIDE"] = gCO('North Tyneside', '', 'GB');
tC["CALDERDALE"] = gCO('Calderdale', '', 'GB');
tC["NORTHAMPTON"] = gCO('Northampton', '', 'GB');
tC["PORTSMOUTH"] = gCO('Portsmouth', '', 'GB');
tC["WARRINGTON"] = gCO('Warrington', '', 'GB');
tC["NORTH SOMERSET"] = gCO('North Somerset', '', 'GB');

// Europe
tC["BERLIN"] = gCO('Berlin', '', 'DE');
tC["MADRID"] = gCO('Madrid', '', 'ES');
tC["ROMA"] = gCO('Roma', '', 'IT');
tC["ROME"] = gCO('Roma', '', 'IT');
tC["PARIS"] = gCO('Paris', '', 'FR');
tC["HAMBURG"] = gCO('Hamburg', '', 'DE');
tC["BARCELONA"] = gCO('Barcelona', '', 'ES');
tC["NOVOSIBIRSK"] = gCO('Novosibirsk', '', 'RU');
tC["NIZHNY NOVGOROD"] = gCO('Nizhny Novgorod', '', 'RU');
tC["MILAN"] = gCO('Milan', '', 'IT');
tC["NAPLES"] = gCO('Naples', '', 'IT');
tC["KÖLN"] = gCO('Koln', '', 'DE');
tC["KOLN"] = gCO('Koln', '', 'DE');
tC["COLOGNE"] = gCO('Cologne', '', 'DE');
tC["TORINO"] = gCO('Torino', '', 'IT');
tC["TURIN"] = gCO('Turin', '', 'IT');
tC["MARSEILLE"] = gCO('Marseille', '', 'FR');
tC["LVOV"] = gCO('Lvov', '', 'UA');
tC["ATHINAI"] = gCO('Athinai', '', 'GR');
tC["ATHENS"] = gCO('Athens', '', 'GR');
tC["STOCKHOLM"] = gCO('Stockholm', '', 'SE');
tC["VALENCIA"] = gCO('Valencia', '', 'ES');
tC["AMSTERDAM"] = gCO('Amsterdam', '', 'NL');
tC["SEVILLA"] = gCO('Sevilla', '', 'ES');
tC["PALERMO"] = gCO('Palermo', '', 'IT');
tC["GENOVA"] = gCO('Genova', '', 'IT');
tC["FRANKFURT"] = gCO('Frankfurt', '', 'DE');
tC["ESSEN"] = gCO('Essen', '', 'DE');
tC["ROTTERDAM"] = gCO('Rotterdam', '', 'NL');
tC["IRKUTSK"] = gCO('Irkutsk', '', 'RU');
tC["DORTMUND"] = gCO('Dortmund', '', 'DE');
tC["STUTTGART"] = gCO('Stuttgart', '', 'DE');
tC["DÜSSELDORF"] = gCO('Düsseldorf', '', 'DE');
tC["DUSSELDORF"] = gCO('Düsseldorf', '', 'DE');
tC["HELSINKI"] = gCO('Helsinki', '', 'FI');
tC["MÁLAGA"] = gCO('Málaga', '', 'ES');
tC["MALAGA"] = gCO('Málaga', '', 'ES');
tC["BREMEN"] = gCO('Bremen', '', 'DE');
tC["HANNOVER"] = gCO('Hannover', '', 'DE');
tC["KOBENHAVN"] = gCO('Kobenhavn', '', 'DK');
tC["COPENHAGEN"] = gCO('Copenhagen', '', 'DK');
tC["KEMEROVO"] = gCO('Kemerovo', '', 'RU');

// rest o' the world
tC["SEOUL"] = gCO('Seoul', '', 'KR');
tC["SÃO PAULO"] = gCO('São Paulo', '', 'BR');
tC["SAO PAULO"] = gCO('Sao Paulo', '', 'BR');
tC["BOMBAY"] = gCO('Bombay', '', 'IN');
tC["ISTANBUL"] = gCO('Istanbul', '', 'TR');
tC["MEXICO"] = gCO('Mexico', '', 'MX');
tC["MEXICO CITY"] = gCO('Mexico City', '', 'MX');
tC["SHANGHAI"] = gCO('Shanghai', '', 'CN');
tC["TOKYO"] = gCO('Tokyo', '', 'JP');
tC["BANGKOK"] = gCO('Bangkok', '', 'TH');
tC["BEIJING"] = gCO('Beijing', '', 'CN');
tC["DELHI"] = gCO('Delhi', '', 'IN');
tC["HONGKONG"] = gCO('HongKong', '', 'CN');
tC["HONG KONG"] = gCO('HongKong', '', 'CN');
tC["CAIRO"] = gCO('Cairo', '', 'EG');
tC["BOGOTA"] = gCO('Bogota', '', 'CO');
tC["LIMA"] = gCO('Lima', '', 'PE');
tC["RIO DE JANEIRO"] = gCO('Rio de Janeiro', '', 'BR');
tC["SANTIAGO"] = gCO('Santiago', '', 'CL');
tC["SYDNEY"] = gCO('Sydney', '', 'AU');
tC["ALEXANDRIA"] = gCO('Alexandria', '', 'EG');
tC["ANKARA"] = gCO('Ankara', '', 'TR');
tC["BUENOS AIRES"] = gCO('Buenos Aires', '', 'AR');
tC["OSAKA"] = gCO('Osaka', '', 'JP');
tC["BUDAPEST"] = gCO('Budapest', '', 'HU');
tC["CARACAS"] = gCO('Caracas', '', 'VE');

// creates a city "object" containing city, state, 
// and country properties
function gCO(city, state, country) {
	var cityObj = new Object();
	cityObj.city = city;
	cityObj.state = state;
	cityObj.country = country;
	return cityObj;
}

// looks for an enter in the topCities array for the value
// of the textbox passed in. If an entry is found, the state
// and country dropdowns on the same form will be set
// to the proper state (if applicable) and country
function setStateAndCountry(cityTextBox) {
	var cityObj = tC[cityTextBox.value.toUpperCase()];
	if (cityObj) {
		if (cityTextBox.form.state) {
			cityTextBox.form.state.value = cityObj.state;
		}

		if (cityTextBox.form.country) {
			cityTextBox.form.country.value = cityObj.country;
		}
	}
}
/* js utility functions for search */

function setCountry(stateSelectBox) {
	var countrySelectBox = stateSelectBox.form.country;
	countrySelectBox.value = isCanadian(stateSelectBox.value) ? 'CA' : 'US';	
	
	if(stateSelectBox.value == 'DC' && stateSelectBox.form.city && stateSelectBox.form.city.value == '')
	{
		stateSelectBox.form.city.value='Washington';
	}
}

function isCanadian(state) {
	return (state == 'AB' || state == 'BC' || state == 'MB' || 
			state == 'NB' || state == 'NL' || state == 'NS'); 
}

function setTopDestination(dropdown) {
	// first turn the city tab on (in case we are on airport or address
	switchTab('findhotelcity');

	// will be in form "city:state:country"
	var ddValue = dropdown.value;
	var frm = dropdown.form;
	
	var tdArray = ddValue.split(":");
	
	if (tdArray.length == 3) {
		frm.city.value = tdArray[0];
		frm.state.value = tdArray[1];
		frm.country.value = tdArray[2];	
	}
}

function copyRadius(radiusElem) {
	frm = radiusElem.form;
	
	if (frm) {
		if (radiusElem.name == 'radius') {
			if (frm.radius1) {
				frm.radius1.value = radiusElem.value;
			}
		} else {
			if (frm.radius) {
				frm.radius.value = radiusElem.value;
			}
		}
	}
}

function copyRadiusUnits(radiusUnitsElem) {
	frm = radiusUnitsElem.form;

	if (frm) {
		if (radiusUnitsElem.name == 'units') {
			if (frm.units1) {
				selectRadio(frm, 'units1', radiusUnitsElem.value);
				//frm.units1.value = radiusUnitsElem.value;
			}
		} else {
			if (frm.units) {
				selectRadio(frm, 'units', radiusUnitsElem.value);
				//frm.units.value = radiusUnitsElem.value;
			}
		}
	}
}

function selectRadio(frm, name, newValue) {
	if (frm && frm[name]) {
		if (frm[name].length) {
			for (var i = 0; i < frm[name].length; i++) {
				//alert(i + " - value: " + frm[name][i].value + " - new value: " + newValue);
				frm[name][i].checked = frm[name][i].value == newValue;
			}
		} else {
			frm[name].checked = frm[name].value == newValue;
		}
	}
}

function resetTopDestinationDD(form) {
	form.topDestination.value="";
}

function setItTrackingParam(form, value) {
	form.it.value = value;
}

function submitHotelSearch() {
	validateHomeSearch('frmfindHotel');
}

function submitRewardSearch() {
	validateRewardSearch('frmrewardstays');
}
