function addToFavorite(favTitle){
  if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
    window.external.AddFavorite(location.href, unescape(favTitle));
  }
}
function endOfMonth(month, year)
{
    if (month < 8) {
        if (month == 2) {
            if (((year % 4) == 0) && (((year % 100) != 0) || ((year % 400) == 0)))
                nDay = 29;
            else
                nDay = 28;
        } else {
            if ((month % 2) == 0) nDay = 30;
            else nDay = 31;
        }
    } else {
        if ((month % 2) == 0) nDay = 31;
        else nDay = 30;
    }
    return nDay;
}
function setDefaultDate()
{
    listStartYear=2005;
    offset = 9;
    date = new Date();
    dToCheck = date.getDate()+offset;
    mToCheck = date.getMonth()+1;
    yToCheck = date.getFullYear();
    if (dToCheck > endOfMonth(mToCheck,yToCheck)) {
        dToCheck -= endOfMonth(mToCheck,yToCheck);
        ++mToCheck;
        if (mToCheck > 11) {
            mToCheck = 0;
            ++yToCheck;
        }
    }
    yToCheck -= listStartYear;
    aform = document.frmSearch;
    aform.InDay.selectedIndex = dToCheck;
    aform.InMonth.selectedIndex = mToCheck;
    aform.InYear.selectedIndex = yToCheck;
    setOutDate();
}
function setOutDate()
{
    listStartYear=2005;
    offsetCheckout = 1;
    aform = document.frmSearch;
    dToCheck = parseInt(aform.InDay.options[aform.InDay.selectedIndex].value);
    mToCheck = parseInt(aform.InMonth.options[aform.InMonth.selectedIndex].value);
    yToCheck = parseInt(aform.InYear.options[aform.InYear.selectedIndex].value);
    dToCheck += offsetCheckout;
    if (dToCheck > endOfMonth(mToCheck,yToCheck)) {
        dToCheck -= endOfMonth(mToCheck,yToCheck);
        ++mToCheck;
        if (mToCheck > 12) {
            mToCheck = 1;
            ++yToCheck;
        }
    }
    yToCheck -= listStartYear;
    aform.OutDay.selectedIndex = dToCheck;
    aform.OutMonth.selectedIndex = mToCheck;
    aform.OutYear.selectedIndex = yToCheck;
}
function isDateOver(d, m, y, d2, m2, y2)
{
    if ((y > y2) || ((y == y2) && (m > m2)) ||
        ((y == y2) && (m == m2) && (d > d2))) {
        return true;
    }
    return false;
}
function checkCode(frm) {
  for (i=0;i<20;i++ ) {
    if(frm.CCode[i].checked) return true;
  }
  if (frm.CCode[20].checked) {
    if (frm.city.selectedIndex != 0 ) {
      frm.CCode[20].value=frm.city.options[frm.city.selectedIndex].value;
	}
	else {
	  alert("Please select a city name");
	  frm.city.focus();
	  return false;
	}
  } else {
	alert("Please select a city");
	frm.CCode[0].focus();
    return false;
  }
  return true;
}
function validateDate(aform)
{
	sd = parseInt(aform.InDay.options[aform.InDay.selectedIndex].value);
    sm = parseInt(aform.InMonth.options[aform.InMonth.selectedIndex].value);
    sy = parseInt(aform.InYear.options[aform.InYear.selectedIndex].value);
    if ((sd > endOfMonth(sm,sy)) || (sd == 0) || (sm == 0) || (sy == 0)){
        alert("Invalid Check-in date.");
        return false;
    }
    ed = parseInt(aform.OutDay.options[aform.OutDay.selectedIndex].value);
    em = parseInt(aform.OutMonth.options[aform.OutMonth.selectedIndex].value);
    ey = parseInt(aform.OutYear.options[aform.OutYear.selectedIndex].value);
    if ((ed > endOfMonth(em,ey)) || (ed == 0) || (em == 0) || (ey == 0)) {
        alert("Invalid Check-out date.");
        return false;
    }
    if (!isDateOver(ed, em, ey, sd, sm, sy)) {
        alert("Check-out date is before Check-in date.");
        return false;
    }
    cdate = new Date();
    bdate = new Date(sy,sm-1,sd);
    if ( bdate < cdate ) {
        alert("Invalid check-in date.");
        return false;
    }
    if ( (bdate - cdate) <= (86400000 * 4) ){
        alert("Reservation requested less than 4 days prior to check-in date is not acceptable.");
        return false;
    }
    return true;
}

function openRate() {
rateWindow = window.open('rate.htm','rate','width=520,height=200,resizable=no,toolbar=no,location=no,scrollbars=no')
}

function showHotelPage(url)
{	var win  = window.open(url,"HotelInfoWindow");  
	win.focus();
}

function jumpTo(url)
{	if( url != "" ) {
		var win = window.open(url,"_blank");
		win.focus();
	}
}

function updateRoom()
{
	obj = document.frmSearch;
	obj.Single.value = 0
	obj.Twin.value = 0;
	obj.Double.value = 0;
	obj.Triple.value = 0;
	obj.Triple.value = 0;
	obj[obj.roomtype.value].value = obj.count.value;
}
