/*******************************************************************************************************
 WebPLS JavaScript, Copyright (c) 2004-2008 WebPLS Inc.
 Author: Derek M Wickersham [derek@webpls.com]
 Last Modified: 15-Mar-2009
 *******************************************************************************************************/

// function called when home page loads
function init(){
  document.quickselect.nav[0].checked=1;
  toggleForm(document.getElementById('crusearch'));
}

// function pops open a child window
function openWin(url,width,height){
  var t = url;
  var w = width;
  var h = height;
  var s = "width=" + w + ",height=" + h + ",scrollbars=yes,location=yes,menubar=yes,resizable=yes,toolbar=yes,status=yes";
  top.window.open(t,"popup",s);
}

// function submits default form on page
function submit(){
   document.forms[1].submit();
}

// function pops open a child window -- no toolbar
function openWin2(url,width,height){
  var t = url;
  var w = width;
  var h = height;
  var s = "width=" + w + ",height=" + h + ",scrollbars=yes,location=no,menubar=yes,resizable=yes,toolbar=no,status=no";
  top.window.open(t,"popup2",s);
}

// function checks for form value
function loadSubmitter() {
  addr = document.theform.email1.value;
  if ( (addr == '') || (!isEmail(addr)) ){
    alert('Please enter a valid e-mail address.');
    return false;
  } else {
    return true;
  }
}

// function checks for validity of e-mail address
function isEmail(string) {
  if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    return true;
  else
    return false;
}

// prints a div element for tripInfoRequest page
function printBookBoxDiv() {
  if (document.layers) {
    document.writeln("<div class=\"bookboxns\">");
  } else {
    document.writeln("<div class=\"bookboxw3\">");
  }
}

// function called on calendar load
function initCal () {
        theDate         = new Date();
        today           = new Date();
        currMonth       = today.getMonth();
        msPerDay        = 24*60*60*1000;
        cookieString    = "dispMonth="+currMonth+";";
        document.cookie = cookieString;
        startOfString   = document.cookie.indexOf("dispMonth");
        countbegin      = document.cookie.indexOf("=",startOfString) + 1;
        countend        = document.cookie.indexOf(";",countbegin);
        if (countend == -1) countend = document.cookie.length;
        dispMonth     = eval ("document.cookie.substring(countbegin,countend)");
        firstOfMonth  = new Date(today.getYear(),dispMonth,1);
        monthName = new Array("","January","February","March","April","May","June","July","August","September","October","November","December");
}

// function opens calendar window pop-up
function openCalendar (monthFldName, dateFldname, monthFldName1, dateFldname1,formNumber) {
        initCal();
        formNum  = formNumber;
        for (var j=0; j< document.forms[formNum].length; j++) {
                if ( document.forms[formNum].elements[j].name.toLowerCase() == monthFldName.toLowerCase()) {
                        monthFld = "elements["+j+"]";
                        dispMonth=document.forms[formNum].elements[j].selectedIndex;
                } 
                if ( document.forms[formNum].elements[j].name.toLowerCase() == dateFldname.toLowerCase() ) {
                        dateFld = "elements["+j+"]";
                }
                if(monthFldName1!=''){
                        if ( document.forms[formNum].elements[j].name.toLowerCase() == monthFldName1.toLowerCase()) {
                                monthFld1 = "elements["+j+"]";
                        } 
                } else {
                        monthFld1 = '';
                }
                if(dateFldname1!=''){
                        if ( document.forms[formNum].elements[j].name.toLowerCase() == dateFldname1.toLowerCase() ) {
                                dateFld1 ="elements["+j+"]";
                        } 
                } else {
                        dateFld1 ='';
                }
        }
        windowOptions  = "toolbar=no,location=no,statusbar=no,status=no,menubar=no,resizable=yes,width=260,height=260";
        calendarWindow = this.open("","calendarWindow",windowOptions);
        calendarWindow.callingForm = this;
        redraw(-1);
}

// redraws the calendar window
function redraw(increment) {
        calendarWindow.callingForm = this;
        if (navigator.appName =='Netscape' ) {
                newYear = today.getYear();
                newYear = 1900 + newYear;
        } else {  
                newYear = today.getYear();
        }
        var tmpDate = new Date();
        tmpDate.setMonth(dispMonth);
        if ( tmpDate.getTime() < today.getTime() )
        newYear++;
        firstOfMonth = new Date(newYear,dispMonth,1);
        calendarWindow.document.open();
        drawCalendar(firstOfMonth);
        calendarWindow.document.write(htmlBuffer);
        calendarWindow.document.close();
        calendarWindow.callingForm = this;
}

// calendar function
function fillDate(filler) {
        var m = monthNum-1;
        var d = filler-1;
        eval("document.forms[" + formNum + "]." + monthFld + ".selectedIndex=" + m);
        eval("document.forms[" + formNum + "]." + dateFld  + ".selectedIndex=" + d);
        if(monthFld1!='') eval("document.forms[" + formNum + "]." + monthFld1 + ".selectedIndex=" + m);
        if(dateFld1!='') eval("document.forms[" + formNum + "]." + dateFld1  + ".selectedIndex=" + d);
        calendarWindow.close();
}

// calendar month function
function changeMonth (increment) {
        nextMonth = dispMonth;
        if (increment == 1) {
                nextMonth++;
        } else {
                nextMonth--;
        }
        if (nextMonth == 12) nextMonth = 0;
        if (nextMonth == -1) nextMonth = 11;
        dispMonth = nextMonth;
        document.cookie="dispMonth="+nextMonth;
        redraw(increment);
}

// draws html for calendar window
function drawCalendar (theDate) {
        tempYear = theDate.getYear();
        monthNum = theDate.getMonth() + 1;
        if ( tempYear <= 1900 ) tempYear += 1900;
        htmlBuffer = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html401/loose.dtd\">";
        htmlBuffer += "<html><head><title>Calendar</title><link type='text/css' rel='stylesheet' href='css/tncss.cfm'></head><body class='grey01bg'>";
        htmlBuffer += "<table cellspacing='0' cellpadding='0' border='0' width='100%'>";
        htmlBuffer += "<tr><td><img src='img/spacer.gif' width='1' height='260'></td><td align='center' valign='middle' width='100%'>";
        htmlBuffer += "<form name='cal'><table border='0' cellpadding='2' cellspacing='0' class='ltyellowbg' bgcolor='#FFFFCC'><tr>";
        htmlBuffer += "<td colspan='2' align='left'><input type='button' name='monthDn' value='<<' onClick='callingForm.changeMonth(-1);' class='sm-blk nopad'></td>";
        htmlBuffer += "<td colspan='3' align='center' class='b-sm-blk'>" + monthName[monthNum] + "&#160;" + tempYear + "</td>";
        htmlBuffer += "<td colspan='2' align='right'><input type='button' name='monthUp' value='>>' onClick='callingForm.changeMonth(1);' class='sm-blk nopad'></td></tr>";
        htmlBuffer += "<tr class='sm-blk centerit'><td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td></tr>";
        drawBody(theDate);
        htmlBuffer += "</table></form></td><td><img src='spacer.gif' width='1' height='260'></td></tr></table></body></html>";
}

// draws html for calendar window
function drawBody (theDate) {
        theDate.setHours(11);
        theDate.setMinutes(30);
        thisMonth = theDate.getMonth();
        thisDate  = theDate.getDate();
        firstSunday(theDate);
        for (w=0; w<6; w++) {
                htmlBuffer += "<tr>";
                for (d=0; d<7; d++) {
                        printdate = theDate.getDate();
                        htmlBuffer += "<td>";
                        if (theDate.getMonth() != thisMonth) {
                                htmlBuffer += "&#160;";
                        } else {
                                htmlBuffer += "<input type='button' class='sm-blk nopad' name='printdate' value='";
                                if ( printdate < 10 ) htmlBuffer += "0";
                                htmlBuffer += printdate + "' onClick='callingForm.fillDate(" + printdate + ");'>";
                        }
                        newTime = theDate.getTime() + msPerDay;
                        theDate.setTime(newTime);
                        htmlBuffer += "</td>";
                }
                htmlBuffer += "</tr>";
        }
}

// calendar utility
function firstSunday (fromDate) {
        while (fromDate.getDay() != 0) {
                newTime = fromDate.getTime() - msPerDay;
                fromDate.setTime(newTime);
        }
}

function toggleForm(me) {
  document.getElementById("crusearch").style.display="none";
  document.getElementById("crusearch").style.visibility="hidden";  
  document.getElementById("airsearch").style.display="none";
  document.getElementById("airsearch").style.visibility="hidden";
  document.getElementById("carsearch").style.display="none";
  document.getElementById("carsearch").style.visibility="hidden";
  document.getElementById("hotsearch").style.display="none";
  document.getElementById("hotsearch").style.visibility="hidden";
  me.style.display="block";
  me.style.visibility="visible";
}

function disableCarForm() {
  document.RequestCarForm.FRnumber1.disabled=true;
  document.RequestCarForm.auto1Value.disabled=true;
  document.RequestCarForm.Dnumber1.disabled=true;
  document.RequestCarForm.FRFirstName1.disabled=true;
  document.RequestCarForm.FRLastName1.disabled=true;
}

function enableCarForm() {
  document.RequestCarForm.FRnumber1.disabled=false;
  document.RequestCarForm.auto1Value.disabled=false;
  document.RequestCarForm.Dnumber1.disabled=false;
  document.RequestCarForm.FRFirstName1.disabled=false;
  document.RequestCarForm.FRLastName1.disabled=false;
}

function disableHotelForm() {
  document.RequestHotelForm.hotel1Value.disabled=true;
  document.RequestHotelForm.FGnumber1.disabled=true;
  document.RequestHotelForm.Dnumber1.disabled=true;
}

function enableHotelForm() {
  document.RequestHotelForm.hotel1Value.disabled=false;
  document.RequestHotelForm.FGnumber1.disabled=false;
  document.RequestHotelForm.Dnumber1.disabled=false;
}

function disableCruiseForm() {
  document.RequestCruiseForm.BrowseDestinationID.disabled=true;
  document.RequestCruiseForm.BrowseVendorID.disabled=true;
}

function enableCruiseForm() {
  document.RequestCruiseForm.BrowseDestinationID.disabled=false;
  document.RequestCruiseForm.BrowseVendorID.disabled=false;
}

function removeAllOptionsFromSelect(selectObj)
{
  for (index = 0; index < selectObj.options.length; index++) {
    selectObj.options[index] = null;
    index--;
  }
  return true;
}

function addOptionToSelect(selectObj, text, value, selected)
{
  var new_Option = new Option(text, value, selected, selected);
  selectObj.options[selectObj.options.length] = new_Option;
}

function frm_onload() 
{
  var frmname=top.frames['ifm'];
  if(frmname!=null) {
    var str=frmname.document.location.href;
    var aPosition = str.search("Search.aspx");
    var _browser=navigator.appName;
    var _version=navigator.appVersion;
    if (_browser=='Netscape' && _version.indexOf('5.0 (Macintosh')>=0) {
      var h = 0; 
      if (!document.all) { 
        h = document.getElementById('ifm').contentDocument.height; 
        document.getElementById('ifm').height=0;
        if(aPosition>0) {
          document.getElementById('ifm').contentDocument.height=0;
          document.getElementById('ifm').height = h + 750;
        } else {
          h = frmname.document.body.scrollHeight;
          frmname.document.body.scrollHeight=0;
          document.getElementById('ifm').height  = h +70;
        }
      }
    } else {
      if(aPosition>0)
        frmname.frameElement.height = frmname.document.body.scrollHeight+250;
      else
        frmname.frameElement.height = frmname.document.body.scrollHeight+20;
    }
  }
}

function setDimensions(h,w,u) {
  h= parseInt(h)+15;
  w= parseInt(w);
  var iframe= document.getElementById('ifm');
  //iframe.style.width = w + "px";
  iframe.style.height= h + "px";
}

// End WebPLS
 