var datePickerDivID = "datepicker";
var iFrameDivID = "datepickeriframe";

var dayArrayShort = new Array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa');
var dayArrayMed = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
var dayArrayLong = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var monthArrayShort = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var monthArrayMed = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
var monthArrayLong = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
 
var defaultDateSeparator = "/";        // common values would be "/" or "."
var defaultDateFormat = "dmy"    // valid values are "mdy", "dmy", and "ymd"
var dateSeparator = defaultDateSeparator;
var dateFormat = defaultDateFormat;

function displayDatePicker(dateFieldName, displayBelowThisObject, dtFormat, dtSep)
{
  var targetDateField = document.getElementsByName (dateFieldName).item(0);
 
  // if we weren't told what node to display the datepicker beneath, just display it
  // beneath the date field we're updating
  if (!displayBelowThisObject)
    displayBelowThisObject = targetDateField;
 
  // if a date separator character was given, update the dateSeparator variable
  if (dtSep)
    dateSeparator = dtSep;
  else
    dateSeparator = defaultDateSeparator;
 
  // if a date format was given, update the dateFormat variable
  if (dtFormat)
    dateFormat = dtFormat;
  else
    dateFormat = defaultDateFormat;
 
  var x = displayBelowThisObject.offsetLeft;
  var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ;
 
  // deal with elements inside tables and such
  var parent = displayBelowThisObject;
  while (parent.offsetParent) {
    parent = parent.offsetParent;
    x += parent.offsetLeft;
    y += parent.offsetTop ;
  }
 
  drawDatePicker(targetDateField, x, y);
}


/**
Draw the datepicker object (which is just a table with calendar elements) at the
specified x and y coordinates, using the targetDateField object as the input tag
that will ultimately be populated with a date.

This function will normally be called by the displayDatePicker function.
*/
function drawDatePicker(targetDateField, x, y)
{
  var dt = getFieldDate(targetDateField.value );
 
  // the datepicker table will be drawn inside of a <div> with an ID defined by the
  // global datePickerDivID variable. If such a div doesn't yet exist on the HTML
  // document we're working with, add one.
  if (!document.getElementById(datePickerDivID)) {
    // don't use innerHTML to update the body, because it can cause global variables
    // that are currently pointing to objects on the page to have bad references
    //document.body.innerHTML += "<div id='" + datePickerDivID + "' class='dpDiv'></div>";
    var newNode = document.createElement("div");
    newNode.setAttribute("id", datePickerDivID);
    newNode.setAttribute("class", "dpDiv");
    newNode.setAttribute("style", "visibility: hidden;");
    document.body.appendChild(newNode);
  }
 
  // move the datepicker div to the proper x,y coordinate and toggle the visiblity
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.position = "absolute";
  pickerDiv.style.left = x + "px";
  pickerDiv.style.top = y + "px";
  pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible");
  pickerDiv.style.display = (pickerDiv.style.display == "block" ? "none" : "block");
  pickerDiv.style.zIndex = 10000;
 
  // draw the datepicker table
  refreshDatePicker(targetDateField.name, dt.getFullYear(), dt.getMonth(), dt.getDate());
}


/**
This is the function that actually draws the datepicker calendar.
*/
function refreshDatePicker(dateFieldName, year, month, day)
{
  // if no arguments are passed, use today's date; otherwise, month and year
  // are required (if a day is passed, it will be highlighted later)
  var thisDay = new Date();
 
  if ((month >= 0) && (year > 0)) {
    thisDay = new Date(year, month, 1);
  } else {
    day = thisDay.getDate();
    thisDay.setDate(1);
  }
 
  // the calendar will be drawn as a table
  // you can customize the table elements with a global CSS style sheet,
  // or by hardcoding style and formatting elements below
  var crlf = "\r\n";
  var TABLE = "<table cols=7 class='dpTable'>" + crlf;
  var xTABLE = "</table>" + crlf;
  var TR = "<tr class='dpTR'>";
  var TR_title = "<tr class='dpTitleTR'>";
  var TR_days = "<tr class='dpDayTR'>";
  var TR_todaybutton = "<tr class='dpTodayButtonTR'>";
  var xTR = "</tr>" + crlf;
  var TD = "<td class='dpTD' onMouseOut='this.className=\"dpTD\";' onMouseOver=' this.className=\"dpTDHover\";' ";    // leave this tag open, because we'll be adding an onClick event
  var TD_title = "<td colspan=5 class='dpTitleTD'>";
  var TD_buttons = "<td class='dpButtonTD'>";
  var TD_todaybutton = "<td colspan=7 class='dpTodayButtonTD'>";
  var TD_days = "<td class='dpDayTD'>";
  var TD_selected = "<td class='dpDayHighlightTD' onMouseOut='this.className=\"dpDayHighlightTD\";' onMouseOver='this.className=\"dpTDHover\";' ";    // leave this tag open, because we'll be adding an onClick event
  var xTD = "</td>" + crlf;
  var DIV_title = "<div class='dpTitleText'>";
  var DIV_selected = "<div class='dpDayHighlight'>";
  var xDIV = "</div>";
 
  // start generating the code for the calendar table
  var html = TABLE;
 
  // this is the title bar, which displays the month and the buttons to
  // go back to a previous month or forward to the next month
  html += TR_title;
  html += TD_buttons + getButtonCode(dateFieldName, thisDay, -1, "&lt;") + xTD;
  html += TD_title + DIV_title + monthArrayLong[ thisDay.getMonth()] + " " + thisDay.getFullYear() + xDIV + xTD;
  html += TD_buttons + getButtonCode(dateFieldName, thisDay, 1, "&gt;") + xTD;
  html += xTR;
 
  // this is the row that indicates which day of the week we're on
  html += TR_days;
  for(i = 0; i < dayArrayShort.length; i++)
    html += TD_days + dayArrayShort[i] + xTD;
  html += xTR;
 
  // now we'll start populating the table with days of the month
  html += TR;
 
  // first, the leading blanks
  for (i = 0; i < thisDay.getDay(); i++)
    html += TD + "&nbsp;" + xTD;
 
  // now, the days of the month
  do {
    dayNum = thisDay.getDate();
    TD_onclick = " onclick=\"updateDateField('" + dateFieldName + "', '" + getDateString(thisDay) + "');\">";
    
    if (dayNum == day)
      html += TD_selected + TD_onclick + DIV_selected + dayNum + xDIV + xTD;
    else
      html += TD + TD_onclick + dayNum + xTD;
    
    // if this is a Saturday, start a new row
    if (thisDay.getDay() == 6)
      html += xTR + TR;
    
    // increment the day
    thisDay.setDate(thisDay.getDate() + 1);
  } while (thisDay.getDate() > 1)
 
  // fill in any trailing blanks
  if (thisDay.getDay() > 0) {
    for (i = 6; i > thisDay.getDay(); i--)
      html += TD + "&nbsp;" + xTD;
  }
  html += xTR;
 
  // add a button to allow the user to easily return to today, or close the calendar
  var today = new Date();
  var todayString = "Today is " + dayArrayMed[today.getDay()] + ", " + monthArrayMed[ today.getMonth()] + " " + today.getDate();
  html += TR_todaybutton + TD_todaybutton;
  html += "<button class='dpTodayButton' onClick='refreshDatePicker(\"" + dateFieldName + "\");'>this month</button> ";
  html += "<button class='dpTodayButton' onClick='updateDateField(\"" + dateFieldName + "\");'>close</button>";
  html += xTD + xTR;
 
  // and finally, close the table
  html += xTABLE;
 
  document.getElementById(datePickerDivID).innerHTML = html;
  // add an "iFrame shim" to allow the datepicker to display above selection lists
  adjustiFrame();
}


/**
Convenience function for writing the code for the buttons that bring us back or forward
a month.
*/
function getButtonCode(dateFieldName, dateVal, adjust, label)
{
  var newMonth = (dateVal.getMonth () + adjust) % 12;
  var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);
  if (newMonth < 0) {
    newMonth += 12;
    newYear += -1;
  }
 
  return "<button class='dpButton' onClick='refreshDatePicker(\"" + dateFieldName + "\", " + newYear + ", " + newMonth + ");'>" + label + "</button>";
}


/**
Convert a JavaScript Date object to a string, based on the dateFormat and dateSeparator
variables at the beginning of this script library.
*/
function getDateString(dateVal)
{
  var dayString = "00" + dateVal.getDate();
  var monthString = "00" + (dateVal.getMonth()+1);
  dayString = dayString.substring(dayString.length - 2);
  monthString = monthString.substring(monthString.length - 2);
 
  switch (dateFormat) {
    case "dmy" :
      return dayString + dateSeparator + monthString + dateSeparator + dateVal.getFullYear();
    case "ymd" :
      return dateVal.getFullYear() + dateSeparator + monthString + dateSeparator + dayString;
    case "mdy" :
    default :
      return monthString + dateSeparator + dayString + dateSeparator + dateVal.getFullYear();
  }
}


/**
Convert a string to a JavaScript Date object.
*/
function getFieldDate(dateString)
{
  var dateVal;
  var dArray;
  var d, m, y;
 
  try {
    dArray = splitDateString(dateString);
    if (dArray) {
      switch (dateFormat) {
        case "dmy" :
          d = parseInt(dArray[0], 10);
          m = parseInt(dArray[1], 10) - 1;
          y = parseInt(dArray[2], 10);
          break;
        case "ymd" :
          d = parseInt(dArray[2], 10);
          m = parseInt(dArray[1], 10) - 1;
          y = parseInt(dArray[0], 10);
          break;
        case "mdy" :
        default :
          d = parseInt(dArray[1], 10);
          m = parseInt(dArray[0], 10) - 1;
          y = parseInt(dArray[2], 10);
          break;
      }
      dateVal = new Date(y, m, d);
    } else if (dateString) {
      dateVal = new Date(dateString);
    } else {
      dateVal = new Date();
    }
  } catch(e) {
    dateVal = new Date();
  }
 
  return dateVal;
}


/**
Try to split a date string into an array of elements, using common date separators.
If the date is split, an array is returned; otherwise, we just return false.
*/
function splitDateString(dateString)
{
  var dArray;
  if (dateString.indexOf("/") >= 0)
    dArray = dateString.split("/");
  else if (dateString.indexOf(".") >= 0)
    dArray = dateString.split(".");
  else if (dateString.indexOf("-") >= 0)
    dArray = dateString.split("-");
  else if (dateString.indexOf("\\") >= 0)
    dArray = dateString.split("\\");
  else
    dArray = false;
 
  return dArray;
}


function updateDateField(dateFieldName, dateString)
{
  var targetDateField = document.getElementsByName (dateFieldName).item(0);
  if (dateString)
    targetDateField.value = dateString;
 
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.visibility = "hidden";
  pickerDiv.style.display = "none";
 
  adjustiFrame();
  targetDateField.focus();
 
  // after the datepicker has closed, optionally run a user-defined function called
  // datePickerClosed, passing the field that was just updated as a parameter
  // (note that this will only run if the user actually selected a date from the datepicker)
  if ((dateString) && (typeof(datePickerClosed) == "function"))
    datePickerClosed(targetDateField);
}

function datePickerClosed(x) {
var f = document.forms[0];
var y = f.datereturn.value;
var z = f.type.options[f.type.selectedIndex].text ;
if ( y =='Select date' && (z == 'Single Trip' || z == 'Family Single Trip' )) {
f.datereturn.value = x.value }

}

function adjustiFrame(pickerDiv, iFrameDiv)
{
  // we know that Opera doesn't like something about this, so if we
  // think we're using Opera, don't even try
  var is_opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
  if (is_opera)
    return;
  
  // put a try/catch block around the whole thing, just in case
  try {
    if (!document.getElementById(iFrameDivID)) {
      // don't use innerHTML to update the body, because it can cause global variables
      // that are currently pointing to objects on the page to have bad references
      //document.body.innerHTML += "<iframe id='" + iFrameDivID + "' src='javascript:false;' scrolling='no' frameborder='0'>";
      var newNode = document.createElement("iFrame");
      newNode.setAttribute("id", iFrameDivID);
      newNode.setAttribute("src", "javascript:false;");
      newNode.setAttribute("scrolling", "no");
      newNode.setAttribute ("frameborder", "0");
      document.body.appendChild(newNode);
    }
    
    if (!pickerDiv)
      pickerDiv = document.getElementById(datePickerDivID);
    if (!iFrameDiv)
      iFrameDiv = document.getElementById(iFrameDivID);
    
    try {
      iFrameDiv.style.position = "absolute";
      iFrameDiv.style.width = pickerDiv.offsetWidth;
      iFrameDiv.style.height = pickerDiv.offsetHeight ;
      iFrameDiv.style.top = pickerDiv.style.top;
      iFrameDiv.style.left = pickerDiv.style.left;
      iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1;
      iFrameDiv.style.visibility = pickerDiv.style.visibility ;
      iFrameDiv.style.display = pickerDiv.style.display;
    } catch(e) {
    }
 
  } catch (ee) {
  }
 
}



function buttonclick(x) {
f = document.forms[0];
f.type.options.selectedIndex  = x  ;
typechange();
}

function changemultitype(){
f = document.forms[0];
var x = getFieldValue(f.covertype , 'radio') ;

if (x == 'B' ) {
document.getElementById("multiagerow2").style.display  = "" 	;
//hide
document.getElementById("multiagerow").style.display  = "none" 	;
} else
{
document.getElementById("multiagerow").style.display  = "" 	;
//hide
document.getElementById("multiagerow2").style.display  = "none" 	;
}
}

function validate1b(){
var f = document.forms[0];
x = f.type.options[f.type.selectedIndex].text ;
age2 = f.agebracket2.options[f.agebracket2.selectedIndex].text ;
a70 = f.adults70.options[f.adults70.selectedIndex].text ;
y = f.destination.options[f.destination.selectedIndex].text ;
yst = f.destination_st.options[f.destination_st.selectedIndex].text ;
ybp = f.destination_bp.options[f.destination_bp.selectedIndex].text ;
var msg = '';
var lf = String.fromCharCode(10);

if (x == 'Backpacker'  && ybp  == '- Select One -'  ) {msg = lf + "Please select a destination." + msg;} ;
if (x == 'Single Trip'  && yst  == '- Select One -'  ) {msg = lf + "Please select a destination." + msg;} ;
if (x == 'Family Single Trip'  && yst  == '- Select One -'  ) {msg = lf + "Please select a destination." + msg;} ;
if (x == 'Annual Multi Trip'  && y  == '- Select One -'  ) {msg = lf + "Please select a destination." + msg;} ;
if (x == 'Annual Multi Trip'  && age2  == '-' && getFieldValue ( f.covertype , "radio" )  == 'B' ) {msg = lf + "Please select the adult ages." + msg;} ;
if (x == 'Annual Multi Trip'  && getFieldValue ( f.agebracket , "radio" )  == ''  ) {msg = lf + "Please select an age bracket." + msg;} ;
if (x == 'Single Trip'  && f.datereturn.value  == 'Select date'  ) {msg = lf + "Please select a return date" + msg;} ;
if (x == 'Family Single Trip'  && f.datereturn.value  == 'Select date'  ) {msg = lf + "Please select a return date" + msg;} ;
//if (x == 'Annual Multi Trip'  && ageb  == 'C' && y != 'Europe'  ) {msg =  "Unfortunately we can only offer Multi-trip Policies to Europe for persons aged 70 - 75 years." + lf + "We can however offer Single Trip Policies World Wide  for persons aged 70 - 75 years. " ;} ;

if (msg == '') { 
f.step.value = 1.5 ;
f.submit() }
else { 
alert(msg )
return false}
}

function validate1(){
var f = document.forms[0];
x = f.type.options[f.type.selectedIndex].text ;
a70 = f.adults70.options[f.adults70.selectedIndex].text ;
y = f.destination.options[f.destination.selectedIndex].text ;
yst = f.destination_st.options[f.destination_st.selectedIndex].text ;
ybp = f.destination_bp.options[f.destination_bp.selectedIndex].text ;
var msg = '';
var lf = String.fromCharCode(10);

if (x == 'Backpacker'  && ybp  == '- Select One -'  ) {msg = lf + "Please select a destination." + msg;} ;
if (x == 'Single Trip'  && yst  == '- Select One -'  ) {msg = lf + "Please select a destination." + msg;} ;
if (x == 'Family Single Trip'  && yst  == '- Select One -'  ) {msg = lf + "Please select a destination." + msg;} ;
if (x == 'Annual Multi Trip'  && y  == '- Select One -'  ) {msg = lf + "Please select a destination." + msg;} ;
if (x == 'Annual Multi Trip'  && getFieldValue ( f.agebracket , "radio" )  == ''  ) {msg = lf + "Please select an age bracket." + msg;} ;
if (x == 'Single Trip'  && f.datereturn.value  == 'Select date'  ) {msg = lf + "Please select a return date" + msg;} ;
if (x == 'Family Single Trip'  && f.datereturn.value  == 'Select date'  ) {msg = lf + "Please select a return date" + msg;} ;
//if (x == 'Annual Multi Trip'  && ageb  == 'C' && y != 'Europe'  ) {msg =  "Unfortunately we can only offer Multi-trip Policies to Europe for persons aged 70 - 75 years." + lf + "We can however offer Single Trip Policies World Wide  for persons aged 70 - 75 years. " ;} ;

if (msg == '') { 
f.step.value = 2 ;
f.submit() }
else { 
alert(msg )
return false}

}


function CountConversion()
{
    var optimizerTracker=_gat._getTracker("UA-8731664-1");
    optimizerTracker._trackPageview("/0071292122/goal");
}

function typechange(){
f = document.forms[0];
x = f.type.options[f.type.selectedIndex].text ;
if (x == 'Family Single Trip' ) {
document.getElementById("fsta18row").style.display  = "" 	; document.getElementById("fsta22row").style.display  = "" 	;document.getElementById("a2row").style.display  = "" 	;
document.getElementById("couplerow").style.display  = "" 	;
document.getElementById("returnrow").style.display  = "" 	;
document.getElementById("deststrow").style.display  = "" 	;
//hide
document.getElementById("a18row").style.display  = "none" 	; document.getElementById("a22row").style.display  = "none" ;document.getElementById("a66row").style.display  = "none" 	;document.getElementById("a70row").style.display  = "none" 	;
document.getElementById("destbprow").style.display  = "none" 	;
document.getElementById("destrow").style.display  = "none" 	;
document.getElementById("bpstayrow").style.display  = "none" 	;
document.getElementById("bpa18row").style.display  = "none" 	;
document.getElementById("couplerow").style.display  = "none" 	;
document.getElementById("multityperow").style.display  = "none" 	;
document.getElementById("multiagerow").style.display  = "none" 	;
document.getElementById("multiagerow2").style.display  = "none" 	;
}
if (x == 'Backpacker' ) {
//show
document.getElementById("bpa18row").style.display  = "" 	;
document.getElementById("bpstayrow").style.display  = "" 	;
document.getElementById("destbprow").style.display  = "" 	;
//hide
document.getElementById("destrow").style.display  = "none" 	;
document.getElementById("deststrow").style.display  = "none" 	;
document.getElementById("a18row").style.display  = "none" 	;document.getElementById("a66row").style.display  = "none" 	;document.getElementById("a70row").style.display  = "none" 	;document.getElementById("a22row").style.display  = "none" 	;document.getElementById("a2row").style.display  = "none" 	;
document.getElementById("fsta18row").style.display  = "none" 	; document.getElementById("fsta22row").style.display  = "none" 	;
document.getElementById("couplerow").style.display  = "none" 	;
document.getElementById("returnrow").style.display  = "none" 	;
document.getElementById("multityperow").style.display  = "none" 	;
document.getElementById("multiagerow").style.display  = "none" 	;
document.getElementById("multiagerow2").style.display  = "none" 	;
}
if (x == 'Single Trip' ) {
document.getElementById("a18row").style.display  = "" 	;document.getElementById("a66row").style.display  = "" 	;document.getElementById("a70row").style.display  = "" 	;document.getElementById("a22row").style.display  = "" 	;document.getElementById("a2row").style.display  = "" 	;
document.getElementById("couplerow").style.display  = "" 	;
document.getElementById("returnrow").style.display  = "" 	;
document.getElementById("deststrow").style.display  = "" 	;
//hide
document.getElementById("fsta18row").style.display  = "none" 	; document.getElementById("fsta22row").style.display  = "none" 	;
document.getElementById("destbprow").style.display  = "none" 	;
document.getElementById("destrow").style.display  = "none" 	;
document.getElementById("bpstayrow").style.display  = "none" 	;
document.getElementById("bpa18row").style.display  = "none" 	;
document.getElementById("multityperow").style.display  = "none" 	;
document.getElementById("multiagerow").style.display  = "none" 	;
document.getElementById("multiagerow2").style.display  = "none" 	;
}
if (x == 'Annual Multi Trip' ) {
//show
document.getElementById("multityperow").style.display  = "" 	;
document.getElementById("multiagerow").style.display  = "" 	;
document.getElementById("destrow").style.display  = "" 	;
//hide
document.getElementById("deststrow").style.display  = "none" 	;
document.getElementById("destbprow").style.display  = "none" 	;
document.getElementById("bpstayrow").style.display  = "none" 	;
document.getElementById("bpa18row").style.display  = "none" 	;
document.getElementById("a18row").style.display  = "none" 	;document.getElementById("a66row").style.display  = "none" 	;document.getElementById("a70row").style.display  = "none" 	;document.getElementById("a22row").style.display  = "none" 	;document.getElementById("a2row").style.display  = "none" 	;
document.getElementById("fsta18row").style.display  = "none" 	; document.getElementById("fsta22row").style.display  = "none" 	;
document.getElementById("returnrow").style.display  = "none" 	;
document.getElementById("couplerow").style.display  = "none" 	;

changemultitype();
//reset
//f.adults18.value = "0";
}
}


function coupleonoff(){
f = document.forms[0];
x = f.adults18.options.selectedIndex;
a = f.adults18.options[x].text;
y = f.adults65.options.selectedIndex;
b = f.adults65.options[y].text;
z = f.adults70.options.selectedIndex;
c = f.adults70.options[z].text;

if (a == "2"  && b =="0" && c =="0" || a == "0"  && b =="2"  && c =="0" || a == "1"  && b =="1" && c =="0" || a == "0"  && b =="0" && c =="2" || a == "1"  && b =="0"  && c =="1" || a == "0"  && b =="1" && c =="1") {
f.couple.disabled = false
} 
else { 
f.couple.disabled = true
f.couple.options.selectedIndex = 0
}
}

function getFieldValue ( theField, vType ) { 
   //this function will return the field value (or value list)    based on the element type 
   theValue = ""; 
   sep = ""; 
   hits = 0; 
   //text is the user-entered value as a string
   if ( vType == "text" ) return ( theField.value ); 
   //textarea is the user-entered value as a string array of one element
   if ( vType == "textarea" ) return ( theField[0].value ); 
   //checkboxes & radio buttons are not so simple
   if ( vType == "checkbox" || vType == "radio" ) { 
      if ( theField.value == null ) { 
        //if we're here, we are validating a radio button or a nn         multi-element checkbox 
       for ( i = 0; i < theField.length; i++ ) { 
          if ( theField[i].checked ) { 
          hits++; 
            if ( hits > 1 ) {
               sep = "; ";
            } 
            theValue += sep + theField[i].value; 
          } 
      }
   } 
   return ( theValue );

} else { 

   //if we are here, must be an ie checkbox, or nn with a    one-element checkbox") 

   if ( navigator.appName == "Microsoft Internet Explorer" ) { 

      //ie. return some data so we can validate on the server; 
      return ("can't validate on client")
   } 

   //nn one-element checkbox, see if its checked ...
   if (theField.checked ) { 
      return ( theField.value ); 

   } else {
      return ( "" ); 
   } 
} 

   //select is an array of selection pointers to an array of strings    representing the choices
   if ( vType == "select" ) { 

      for ( i = 0; i < theField.options.length; i++ ) {
        if ( theField.options[i].selected ) theValue = theField.options[i].text 
      } 
      return ( theValue );
    }
}

function HIonoff(){
f = document.forms[0];
x = f.stay.options.selectedIndex;
a = f.stay.options[x].text;
y = f.hi.options.selectedIndex;
b = f.hi.options[y].text;
if (x==0  || x==1 || x==2     ) {
f.hi.disabled = false
} 
else { 
f.hi.disabled = true
f.hi.options.selectedIndex = 0
}
}



var month; var day; var year; 
var delim = new Array(":","/","\\","-"," ",".");
var monthArray = new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);


function getMonth_and_Date(form,fieldName){
dtString = eval("form." + fieldName + ".value");
// trim date string
while ((dtString.charAt(0) == " ") && (dtString.length != 0))
dtString = dtString.substring(1,dtString.length - 1)
while ((dtString.charAt(dtString.length - 1) == " ") && (dtString.length != 0))
dtString = dtString.substring(0,dtString.length - 1)
//get date components
i = 0; startPos = 0; pos = 0;
//get day
do {
pos = dtString.indexOf(delim[i], startPos);
i++
}
while ((pos == -1) && (i < delim.length));
if (pos == -1){//there's no day
getToday(); 
return;
}
day = parseInt(dtString.substring(startPos,pos),10) - 1;
startPos = pos + 1;
if ((day < 0) || (day > 31)){ //no valid day
getToday();
return;
}
else
day++; 
//get month
i = 0;
do {
pos = dtString.indexOf(delim[i], startPos);
i++
}
while ((pos == -1) && (i < delim.length));
if (pos == -1){
getToday();
return;
}
month = parseInt(dtString.substring(startPos,pos),10);
startPos = pos + 1;
if ((month < 1) || (month > 12)){
getToday();
return;
}
//get year
year = parseInt(dtString.substring(startPos,dtString.length),10)
year = (year < 100) ? 1900 + year : year;
}//getMonth_and_Date

function putDate(form,fieldName,value){
eval("form." + fieldName + ".value=" + value)
}

function gm(num) {
var mydate = new Date();
mydate.setDate(1);
mydate.setMonth(num-1);
var datestr = "" + mydate;
return datestr.substring(4,7);
}

function gy(num) {
var mydate = new Date();
return (1900 + eval(mydate.getYear()) - 4 + num);
}

function ud(mon) {
var i = mon.selectedIndex;

if(mon.options[i].value == "2") {
document.myform.day.options[30] = null;
document.myform.day.options[29] = null;
var j = document.myform.year.selectedIndex;
var year = eval(document.myform.year.options[j].value);
if ( ((year%400)==0) || (((year%100)!=0) && ((year%4)==0)) ) {
if (document.myform.day.options[28] == null) {
document.myform.day.options[28] = new Option("29");
document.myform.day.options[28].value = "29";
}
} else {
document.myform.day.options[28] = null;
}
}

if(mon.options[i].value == "1" ||
mon.options[i].value == "3" ||
mon.options[i].value == "5" ||
mon.options[i].value == "7" ||
mon.options[i].value == "8" ||
mon.options[i].value == "10" ||
mon.options[i].value == "12")
{
if (document.myform.day.options[28] == null) {
document.myform.day.options[28] = new Option("29");
document.myform.day.options[28].value = "29";
}
if (document.myform.day.options[29] == null) {
document.myform.day.options[29] = new Option("30");
document.myform.day.options[29].value = "30";
}
if (document.myform.day.options[30] == null) {
document.myform.day.options[30] = new Option("31");
document.myform.day.options[30].value = "31";
}
}

if(mon.options[i].value == "4" ||
mon.options[i].value == "6" ||
mon.options[i].value == "9" ||
mon.options[i].value == "11")
{
if (document.myform.day.options[28] == null) {
document.myform.day.options[28] = new Option("29");
document.myform.day.options[28].value = "29";
}
if (document.myform.day.options[29] == null) {
document.myform.day.options[29] = new Option("30");
document.myform.day.options[29].value = "30";
}
document.myform.day.options[30] = null;
}

if (document.myform.day.selectedIndex == -1)
document.myform.day.selectedIndex = 0;
}


function showdate() {
var i = document.myform.month.selectedIndex;
var j = document.myform.day.selectedIndex;
var k = document.myform.year.selectedIndex;
alert(document.myform.month.options[i].value + "/" +
document.myform.day.options[j].value + "/" +
document.myform.year.options[k].value)
}


function putcal(form, dateFieldName) {
var version = navigator.appVersion;
if (navigator.appVersion.indexOf("Mac") != -1) {
calwin = open("","calwin","width=300,height=300,resizable=yes");
} else {
calwin = open("","calwin","width=230,height=280,resizable=yes");
}

calccal(calwin,form,dateFieldName);
}

function calccal(targetwin,form,dateFieldName) { 
var monthname = new Array(12);
monthname[0] = "January";
monthname[1] = "February";
monthname[2] = "March";
monthname[3] = "April";
monthname[4] = "May";
monthname[5] = "June";
monthname[6] = "July";
monthname[7] = "August";
monthname[8] = "September";
monthname[9] = "October";
monthname[10] = "November";
monthname[11] = "December";

var endday = calclastday(eval(month),eval(year));

mystr = month + "/01/" + year;
mydate = new Date(mystr);
firstday = mydate.getDay();

var cnt = 0;

var day = new Array(6);
for (var i=0; i<6; i++)
day[i] = new Array(7);

for (var r=0; r<6; r++)
{
for (var c=0; c<7; c++)
{
if ((cnt==0) && (c!=firstday))
continue;
cnt++;
day[r][c] = cnt;
if (cnt==endday)
break;
}
if (cnt==endday)
break;
}
targetwin.document.open()
targetwin.document.writeln("<FORM><TABLE><TR VALIGN=TOP>");

var prevyear = eval(year) - 1;
targetwin.document.writeln("<TD><INPUT TYPE=BUTTON NAME=prevyearbutton VALUE='<<'"+
" onclick='opener.month = " + month + "; opener.year = " + prevyear + ";document.clear();opener.calccal(opener.calwin,opener.document." + form.name + ",\"" + dateFieldName + "\")'></TD>");

var prevmonth = (month == 1) ? 12 : month - 1;
var prevmonthyear = (month == 1) ? year - 1 : year;
targetwin.document.writeln("<TD><INPUT TYPE=BUTTON NAME=prevmonthbutton VALUE='&nbsp;<&nbsp;'"+
" onclick='opener.month = " + prevmonth + "; opener.year = " + prevmonthyear + ";document.clear();opener.calccal(opener.calwin,opener.document." + form.name + ",\"" + dateFieldName + "\")'></TD>");

targetwin.document.writeln("<TD COLSPAN=3 ALIGN=CENTER>");
var index = eval(month) - 1;
targetwin.document.writeln("<B>" + monthname[index] + " " + year + "</B></TD>");

var nextyear = eval(year) + 1; 
var nextmonth = (month == 12) ? 1 : month + 1;
var nextmonthyear = (month == 12) ? year + 1 : year;
targetwin.document.writeln("<TD><INPUT TYPE=BUTTON NAME=nextmonthbutton VALUE='&nbsp;>&nbsp;'"+
" onclick='opener.month = " + nextmonth + "; opener.year = " + nextmonthyear + ";document.clear();opener.calccal(opener.calwin,opener.document." + form.name + ",\"" + dateFieldName + "\")'></TD>");

targetwin.document.writeln("<TD><INPUT TYPE=BUTTON NAME=nextyearbutton VALUE='>>'"+
" onclick='opener.month = " + month + "; opener.year = " + nextyear + ";document.clear();opener.calccal(opener.calwin,opener.document." + form.name + ",\"" + dateFieldName + "\")'></TD>");

targetwin.document.writeln("</TR><TR>");
targetwin.document.writeln("<TD>Su</TD>");
targetwin.document.writeln("<TD>Mo</TD>");
targetwin.document.writeln("<TD>Tu</TD>");
targetwin.document.writeln("<TD>We</TD>");
targetwin.document.writeln("<TD>Th</TD>");
targetwin.document.writeln("<TD>Fr</TD>");
targetwin.document.writeln("<TD>Sa</TD>");
targetwin.document.writeln("</TR>");

targetwin.document.writeln("<TR><TD COLSPAN=7><HR NOSHADE></TD></TR>");
targetwin.document.writeln("<TR><TD COLSPAN=7><TABLE WIDTH=\"100%\" BORDER=\"1\">");

var selectedmonth = eval(month) - 1;
var today = new Date();
var thisyear = today.getYear() + 1900;
var selectedyear = eval(year) - thisyear + 4;

var conditionalpadder = "";

for(r=0; r<6; r++)
{
targetwin.document.writeln("<TR>");
for(c=0; c<7; c++)
{
targetwin.document.writeln("<TD>");
if(day[r][c] != null) {
if (day[r][c] < 10)
conditionalpadder = "&nbsp;"
else
conditionalpadder = "";
targetwin.document.writeln("<a href=\"javascript:window.close();" + 
"opener.document." + form.name + "." + dateFieldName + ".value = '" + day[r][c] + "/" + month + "/" + year + "'" + 
"\">" + conditionalpadder + day[r][c] + conditionalpadder + "</a>")
}
targetwin.document.writeln("</TD>");
}
targetwin.document.writeln("</TR>");
}
targetwin.document.writeln("</TABLE></TABLE></FORM>");
targetwin.document.close()
}

function calclastday(month,year) {
if ((month==2) && ((year%4)==0))
return 29;

if ((month==2) && ((year%4)!=0))
return 28;

if ((month==1) || (month == 3) || (month == 5) || (month == 7) ||
(month==8) || (month == 10) || (month ==12))
return 31;

return 30;
}

function calcnextmonth(month) {
if (month=="12")
return "1";
else
return (eval(month)+1);
}

function calcnextyear(month,year) {
if (month=="12")
return (eval(year)+1);
else
return (year);
}

function calcprevmonth(month) {
if (month=="1")
return "12";
else
return (eval(month)-1);
}

function calcprevyear(month,year) {
if (month=="1")
return (eval(year)-1);
else
return (year);
}


