function populateCitySelect( country ) {
  if ( country.length == 0 ) {
    document.theForm.Choice.length = 1;
    document.theForm.Choice.options[0] = new Option('Choose a country:');
    document.theForm.Choice.options[0].value = '';

    return;
  }

  newOptions = eval(country+'Array');

  document.theForm.Choice.length = 1;
  document.theForm.Choice.options[0] = new Option("OceanBeach Backpackers");
  document.theForm.Choice.options[0].value = 'H920';

  document.theForm.Choice.options[0].selected = true;

  for ( i=0; i<newOptions.length; i++ ) {
    document.theForm.Choice.length++;
    thisEntry = newOptions[i];
    newOption = new Option( thisEntry[1] );
    newOption.value = thisEntry[0];
    document.theForm.Choice.options[i+1] = newOption;
  }
}

var AustraliaArray = new Array (
  new Array( "H1926", "  Billabong Backpackers Resort" ),
new Array( "H920", "  Underground Backpackers" ),
new Array( "H1925", " Governor Robinsons" ),
  new Array( "H1720", "  Sundancer Resort - Fremantle" ),
  new Array( "CPerth;Australia", "<< or search all Perth hostels >>" )

);

function makeValidDate() {
  year = document.theForm.selYear.options[ document.theForm.selYear.selectedIndex ].value;
  month = document.theForm.selMonth.options[ document.theForm.selMonth.selectedIndex ].value;
  day = document.theForm.selDay.options[ document.theForm.selDay.selectedIndex ].value;
  maxDay = 31;
  if ( month == 4 || month == 6 || month == 9 || month == 11 ) {
    maxDay = 30;
  } else if ( month == 2 ) {
    if ( year%100 != 0 && year%4 == 0 ) {
      maxDay = 28;
    } else {
      maxDay = 29;
    }
  }
  document.theForm.selDay.selectedIndex = Math.min(day, maxDay)-1;
}


function isBrowserSupp() {
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description: Checks if browser is Netscape 2.0 since the options 
// *                            array properties don't work with Netscape 2.0x
// ****************************************************************

    // Get the version of the browser
    version =  parseFloat( navigator.appVersion );

    if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
        return false;
    }
    else {
        return true;
    }                  
}


function isLeapYear(yrStr)
{
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Checks if Year selected is a leap year
// ****************************************************************
var leapYear=false;
// every fourth year is a leap year
if ((parseInt(yrStr, 10)%4) == 0)
        {
        leapYear=true;
        }
return leapYear;
}

function getDaysInMonth(mthIdx, YrStr)
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Retrieves the number of days in a given month
// ****************************************************************
{
//Default number of days in a month is 31
var maxDays=31
// expect Feb. 
if (mthIdx==2) 
        {
        if (isLeapYear(YrStr))
                {
                maxDays=29;
                }
        else 
                {
                maxDays=28;
                }
        }
// All the rest of the months have 30 days
if (mthIdx==4 || mthIdx==6 || mthIdx==9 || mthIdx==11)
        {
        maxDays=30;
        }
return maxDays;
}


function adjustDate(mthIdx, Dt, Yr) 
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Adjusts the format of the Date
// ****************************************************************
{
var value=0;            
var numDays=getDaysInMonth(mthIdx, Yr.options[Yr.options.selectedIndex].value);

if (mthIdx==2) 
        {
        if (Dt.options.selectedIndex < numDays)
                {
                return 0;
                }
        else 
                {
                //check for leap year
                Dt.options.selectedIndex=numDays;
                if (numDays==29)
                        {
                        return 99;
                        }
                else 
                        {
                        return 1;
                        }
                }
        }
if (Dt.options.selectedIndex < numDays)
        {
        value=0;
        }
else 
        {
        if (Dt.options.selectedIndex > numDays)
                {
                Dt.options.selectedIndex;
                value=3;
                }
        else 
                {
                //index is 31 or 30
                value=2;
                }
        }
return value;
}


function parseMonth(mth, inM)
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Parses a string and returns a month value
// ****************************************************************
{
var i=1;
var retval =1;
for (i=1;i<=12;i++)
        {
        if (mth == inM.options[i].value)
                {
                retval=i;       
                break;
                }       
        }
        return retval;
}

function parseDay(day, inD)
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Parses a string and returns a day value
// ****************************************************************
{
var i=1;
var retval =1;
for (i=1;i<=31;i++)
        {
        if (day == inD.options[i].value)
                {
                retval=i;       
                break;
                }       
        }
return retval;
}

function parseYear(year, inY)
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Parses a string and returns a year value
// ****************************************************************
{
var retval=0;
var i=0;
     for (i=0; i<=5; i++)
     {
   
        if (year == inY.options[i].value)
                {
                retval=i;       
                break;
                }       
     }
return retval;
}

//Calendar Section

//calculation functions
function nextMonth(month)
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Retrieves the next Month's value
// **************************************************************** 
{
if (month==12)
        {
        return 1;
        }
else
        {
        return (month+1);
        }
}


function prevMonth(month) 
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Retrieves the previous Month's value
// ****************************************************************
{
var prevMonth = (month-1)
if (month==1)
        {
        prevMonth = 12;
        }
return prevMonth
}

function changeYear(direction,month,year)
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Increments or decrements month when it goes
// *                                    past Jan or Dec
// ****************************************************************
{
var theYear = year
if (direction=="next")
        {
        if (month == 12)
                {
                theYear = (year+1)
                }
        }
if (direction=="prev")
        {
        if (month == 1)
                {
                theYear = (year-1)
                }
        }
return theYear
}


function createCalendar(month,year,io) 
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    //opens a new window for the calendar
// ****************************************************************
{
if (!isBrowserSupp())
        {
        alert("Your browser is outdated and does not support this feature")
        return;
        }
if (navigator.appVersion.indexOf("Mac",0) != -1) 
        {
        calendarWindow = window.open("","Calendar","width=230,height=365,resizable=yes,scrollbars=no");
        } 
else 
        {
        calendarWindow = window.open("","Calendar","width=230,height=300,resizable=yes,scrollbars=no");
        }
        var mthIdx = month.options.selectedIndex
        var mthVal = month.options[mthIdx].value
        var yearVal = year.options[year.options.selectedIndex].value
        //call the function to populate the window
        generateCalendar(calendarWindow,mthVal,yearVal,io)
}


//generates the meat of the calendar
function generateCalendar(target,month,year,io)
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    generates the contents of the calender window
// **************************************************************** 
{
if (!isBrowserSupp())
        {
        return;
        }       
var monthName = new Array ("January","February","March","April","May","June","July","August","September","October","November","December")

//begin table for calendar
target.document.open()
calendar = "<html><head><title>calendar</title></head><body bgcolor=ffffff link='#000080'><center></center>"
calendar +="<table border=0 cellspacing=0 cellpadding=4 width=200>"
calendar +="<tr valign=top>"

//The parseInt function parses the string argument as a signed decimal integer. 
var mthIdx = parseInt(month);
var endday = getDaysInMonth(mthIdx, year)

//month header
calendar +="<td colspan=7 align=center bgcolor=#FF9933>"
var index = (mthIdx-1)
calendar +="<b><font face='Helvetica,Arial,Futura' color=white>" + monthName[index] + " " + year + "</font></b></td></tr>"

//writes in the day of the week labels
calendar +="</tr><tr align=center>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura' color='#00C000'>&nbsp;<b>S</b></font></td>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura' color='#000080'>&nbsp;<b>M</b></font></td>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura' color='#000080'>&nbsp;<b>T</b></font></td>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura' color='#000080'>&nbsp;<b>W</b></font></td>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura' color='#000080'>&nbsp;<b>T</b></font></td>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura' color='#000080'>&nbsp;<b>F</b></font></td>"
calendar +="<td width=10><font face='Helvetica,Arial,Futura' color='#00C000'>&nbsp;<b>S</b></font></td>"
calendar +="</tr>"

wholeDate = month + "/01/" + year
thedate = new Date(wholeDate)
firstDay = thedate.getDay()

selectedmonth = mthIdx;
var today = new Date();
var thisyear = today.getYear() + 1900;
selectedyear = year

var lastDay = (endday + firstDay+1)
calendar +="<tr>"
for (var i = 1; i < lastDay; i++)
        {
        if (i <= firstDay)
                {
                // 'empty' boxes prior to first day
                calendar +="<td>&nbsp;</td>"
                }
        else 
                {
                // enter date number
                calendar +="<td align=center><a href='JavaScript:self.close();opener.closeCalendar"+io+"("+(i-firstDay) + ")'> "+(i-firstDay)+"</a></td>"
                }
        //must start new row after each week
        if (i % 7 == 0 &&  i != lastDay)
                {
                calendar +="</tr><tr>"
                }
        }
calendar +="</tr>"

//separator line
calendar +="<tr><td colspan=7 align=center width=200><hr noshade></td></tr>"


//next month and previous month buttons
var goPrevMonth = prevMonth(mthIdx)
var goNextMonth = nextMonth(mthIdx)
var nextYear = changeYear("next",parseInt(month),parseInt(year))
var prevYear = changeYear("prev",parseInt(month),parseInt(year))

if(navigator.userAgent.indexOf('MSIE',0) != -1)
        {
        calendar +="<tr><td align=left colspan=3 bgcolor=#FF9933><a href='javascript:opener.generateCalendar(self,"+goPrevMonth+","+prevYear+",\""+io+"\")'>Prev</a></td>"
        calendar +="<td align=center colspan=1 bgcolor=#FF9933>&nbsp;</td>"
        calendar +="<td align=right colspan=3 bgcolor=#FF9933><a href='javascript:opener.generateCalendar(self,"+goNextMonth+","+nextYear+",\""+io+"\")'>Next</a></td></tr>"
        calendar +="</table></body></html>"
        target.document.close()
        }
else
        {
        calendar +="<form><tr><td align=left colspan=3 bgcolor=#62C400><input type=button value=' < '"+"onClick='document.clear();opener.generateCalendar(opener.calendarWindow,"+goPrevMonth+","+prevYear+",\""+io+"\")'></td>"
        calendar +="<td align=center colspan=1 bgcolor=#62C400>&nbsp;</td>"
        calendar +="<td align=right colspan=3 bgcolor=#62C400><input type=button value=' > '"+"onClick='document.clear();opener.generateCalendar(opener.calendarWindow,"+goNextMonth+","+nextYear+",\""+io+"\")'></td></tr></form>"
        calendar +="</table></body></html>"
        }
target.document.write(calendar);
target.document.close() 
}

function closeCalendar(day) {
        var yrIdx = parseYear(selectedyear,document.theForm.selYear );

        // Decrement index for day and month, because code assumes 
        // that we have an extra defaultvalue at the start.
        document.theForm.selMonth.options.selectedIndex=selectedmonth-1;
        document.theForm.selYear.options.selectedIndex= yrIdx;
        document.theForm.selDay.options.selectedIndex=parseInt(day)-1;
}


