// JavaScript Document : global.js
var months = new Array( "January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");

var _POPUP_FEATURES = 'location=0, statusbar=0, menubar=0, toolbar=0, resizable=1, scrollbars=1, width=580, height=480';
var _LINK_FEATURES = 'location=1, statusbar=1, menubar=1, toolbar=1, resizable=1, width=800, height=600';

function raw_popup(url, target, features)
{
   if (isUndefined(features)) features = _LINK_FEATURES;
   if (isUndefined(target  )) target   = '_blank';
   var theWindow = window.open(url, target, features);
   theWindow.focus();
   return theWindow;
}

function link_popup(src, features)
{
   return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}

function isUndefined(v)
{
   var undef;
   return v === undef;
}

function doSubmit(frm)
{
   if (tmt_validateForm(frm))
   {
      frm.submit();
      return true;
   }
   return false;
}

function LZ(x)
{
   return (x >= 10 || x < 0 ? "" : "0") + x;
}

function getDepartureDate(qs, thisid)
{

   var thisDate = new Date;
   thisDate.setDate(parseInt(qs.day.value));
   thisDate.setMonth(qs.month.selectedIndex);
   thisDate.setYear(parseInt(qs.year.value))

   thisDate.setDate(thisDate.getDate() + parseInt(qs.nights.value));

   var curr_date = thisDate.getDate();
   var sup = "";
   if (curr_date == 1 || curr_date == 21 || curr_date == 31)
   {
      sup = "st";
   }
   else if (curr_date == 2 || curr_date == 22)
   {
      sup = "nd";
   }
   else if (curr_date == 3 || curr_date == 23)
   {
      sup = "rd";
   }
   else
   {
      sup = "th";
   }

   var curr_month = thisDate.getMonth();
   var curr_year = thisDate.getFullYear();

   qs.departure.value = curr_year + LZ(curr_month + 1) + LZ(curr_date);

   document.getElementById(thisid).innerHTML = curr_date + "<SUP>" + sup + "</SUP> "
   + months[curr_month] + " " + curr_year;
}

function setPopulation(d)
{
   for (i = 0; i < d.area.length; i ++ )
   {
      if (d.area[i].checked)
      {
         populate(d.area[i]);
      }
   }
}

function populate(o)
{
   d = document.getElementById('region');
   d.options.length = items[o.value].length;
   for (var i = 0; i < items[o.value].length;
   i ++ )
   {
      d.options[i].text = items[o.value][i][0].substring(14);
      d.options[i].value = items[o.value][i][0].substring(1, 13);
   }
   document.getElementById("selectedArea").value = o.value;
   d.selectedIndex = 0;
   populateLocations(d);
}

function populateLocations(p)
{
   o = document.quicks.selectedArea.value;
   d = document.getElementById('location');
   d.options.length = items[o][p.selectedIndex].length - 1;
   for (var i = 1; i < items[o][p.selectedIndex].length;
   i ++ )
   {
      d.options[i - 1].text = items[o][p.selectedIndex][i].substring(14);
      d.options[i - 1].value = items[o][p.selectedIndex][i].substring(1, 13);
   }
   d.selectedIndex = 0;
}



function setCurrentDate(d)
{

   var currentDate = new Date();

   var currentYear = currentDate.getYear();

   if ( currentYear < 2000 )
   {
      currentYear += 1900;
   }

   d.year.options.length = 5;
   for (var i = 0; i < 5; i ++ )
   {
      d.year.options[i].text = currentYear;
      d.year.options[i].value = currentYear;
      currentYear ++ ;
   }

   d.year.selectedIndex = 0;
   d.month.selectedIndex = currentDate.getMonth();
   setDays(d);
   d.day.selectedIndex = currentDate.getDate() - 1;
}


function setDays(d)
{
   var y = d.year.options[d.year.selectedIndex].value;
   var m = d.month.selectedIndex;
   var d;
   // find number of days in current month
   if ( (m == 3) || (m == 5) || (m == 8) || (m == 10) )
   {
      days = 30;
   }
   else if (m == 1)
   {
      // check for leapyear - Any year divisible by 4, except those divisible by 100 (but NOT 400)
      if ( (Math.floor(y / 4) == (y / 4)) && ((Math.floor(y / 100) != (y / 100)) || (Math.floor(y / 400) == (y / 400))) )
      days = 29
      else
      days = 28
   }
   else
   {
      days = 31;
   }
   // if (days in new month > current days) then we must add the extra days
   if (days > d.day.length)
   {
      for (i = d.day.length; i < days; i ++ )
      {
         d.day.length = days;
         d.day.options[i].text = i + 1;
         d.day.options[i].value = LZ(i + 1);
      }
   }
   // if (days in new month < current days) then we must delete the extra days
   if (days < d.day.length)
   {
      d.day.length = days;
      if (d.day.selectedIndex == - 1)
      d.day.selectedIndex = days - 1;
   }
}

// GS
function mySubmit(formname)
{
   eval('document.' + formname + '.submit()');
}

// Add days to starting date
// Ensure there a two digit day and month
function LZ(x)
{
   return (x >= 10 || x < 0 ? "" : "0") + x;
}

function addDays()
{
   if (document.QSSearch.arrDate.value != '')
   {
      // get source date
      var StartingDate = document.QSSearch.arrDate.value;
      // source date is dd / mm / yyyy format, convert to mm / dd / yyyy
      var strSeperator = "/";
      // manipulate
      var mDay = StartingDate.substr(0, 2);
      var mMonth = StartingDate.substr(3, 2);
      var mYear = StartingDate.substr(6, 4)
      // represent as mm / dd / yyy
      StartingDate2 = mMonth + strSeperator + mDay + strSeperator + mYear;
      // no of days to add from dd menu
      DaysToAdd = document.QSSearch.nights.value;

		var newdate = new Date(StartingDate2);
		var newtimems = newdate.setDate(newdate.getDate()+Number(DaysToAdd));
//		Old vars - rounding issues for Oct?
//		var newtimems = newdate.getTime() + (DaysToAdd * 24 * 60 * 60 * 1000);
//      newdate.setTime(newtimems);

		var month = newdate.getMonth() + 1;
		var day = newdate.getDate();
		var year = newdate.getFullYear();
		document.QSSearch.depDate.value = LZ(day) + "/" + LZ(month) + "/" + year;
   }
}

function compareDates(date1, dateformat1, date2, dateformat2)
{
   var d1 = getDateFromFormat(date1, dateformat1);
   var d2 = getDateFromFormat(date2, dateformat2);
   if(d1 == 0 || d2 == 0)
   {
      return - 1;
   }
   else if(d1 > d2)
   {
      return 1;
   }
   return 0;
}

// Check for earlier date
// 1 = Date is greater
// 0 = Date is not greater
// - 1 = Date format error

function checkEarlierDate()
{
   if (document.QSSearch.arrDate2.value != '')
   {
      var da = compareDates(document.QSSearch.todaysdate.value, document.QSSearch.dateformat1.value, document.QSSearch.arrDate2.value, document.QSSearch.dateformat1.value);
      if((da == 0) || (da == - 1))
      {
         // 			document.QSSearch.depDate.value = '';
         // 			document.QSSearch.nights.disabled = true;
         // 			document.QSSearch.arrDate.value = '';
         // 			document.QSSearch.arrDate2.value = '';
         alert('Please select a future date.');
         return false;
      }
      else
      {
         document.QSSearch.nights.disabled = false;
         return true;
      }

   }
   else
   {
      document.QSSearch.depDate.value = '';
      document.QSSearch.nights.disabled = true;
   }
}
function checkEarlierDate2()
{
   if (document.QSSearch.arrDate.value != '')
   {
      var da = compareDates(document.QSSearch.arrDate.value, document.QSSearch.dateformat1.value, document.QSSearch.todaysdate.value, document.QSSearch.dateformat1.value);
      if((da == 0) || (da == - 1))
      {
         // 			document.QSSearch.depDate.value = '';
         // 			document.QSSearch.nights.disabled = true;
         // 			document.QSSearch.arrDate.value = '';
         // 			document.QSSearch.arrDate2.value = '';
         alert('Please select a future date.');
         return false;
      }
      else
      {
         // 			document.QSSearch.nights.disabled = false;
         return true;
      }

   }
}


function checkDateFields()
{
   if (document.QSSearch.arrDate.value = "")
   {
      document.QSSearch.nights.disabled = true;
      document.QSSearch.depDate.value = "";
   }
}
function reinit2()
{
   document.QSSearch.depDate.value = "";
   document.QSSearch.displayDate.value = "";
   document.QSSearch.arrDateT.value = "";
}
function checkDateFields2()
{
   if (document.QSSearch.arrDate.value = "")
   {
      alert('Please select an arrival date.');
      return false;
   }
}

function selectDDAreaSubmit()
{
   if (document.QSarea.DDareas.selectedIndex == 0)
   {
      return false;
   }
   mySubmit('QSarea');
   return true;
}
function selectDDLocationSubmit()
{
   if (document.QSarea.DDareas.selectedIndex == 0)
   {
      return false;
   }
   mySubmit('QSarea');
   return true;
}

// Cookie functions

function MM_findObj(n, d)
{
   // v4.01
   var p, i, x;
   if( ! d) d = document;
   if((p = n.indexOf("?")) > 0 && parent.frames.length)
   {
      d = parent.frames[n.substring(p + 1)].document;
      n = n.substring(0, p);
   }
   if( ! (x = d[n]) && d.all) x = d.all[n];
   for (i = 0; ! x && i < d.forms.length; i ++ ) x = d.forms[i][n];
   for(i = 0; ! x && d.layers && i < d.layers.length; i ++ ) x = MM_findObj(n, d.layers[i].document);
   if( ! x && d.getElementById) x = d.getElementById(n);
   return x;
}

function XMwriteCookie(n, i, t)
{
   var ep = "";
   if (t)
   {
      d = new Date();
      d.setTime(d.getTime() + (t * 86400000));
      ep = "; expires=" + d.toGMTString();
   }
   document.cookie = n + "=" + i + ep + "; path=/";
}

function XMreadCookie(n)
{
   eq = n + "=";
   ca = document.cookie.split(';');
   for(var i = 0; i < ca.length; i ++ )
   {
      c = ca[i];
      while (c.charAt(0) == ' ') c = c.substring(1, c.length);
      if (c.indexOf(eq) == 0) return c.substring(eq.length, c.length);
   }
   return '';
}


function validateQS()
{
   if (document.QSSearch.areaID.value != '')
   {
      return true;
   }
   else
   {
      alert('Please choose a Florida Area');
      return false;
   }
}


var QSdate = "";
function InitSaveVariables(form)
{
   QSdate = document.QSSearch.arrDate2.value;
}

function copyValue(form)
{
   if (document.QSSearch.arrDate.value != '')
   {
      InitSaveVariables(form);
      document.QSSearch.arrDate2.value = document.QSSearch.arrDate.value;
   }
   else
   {
      document.QSSearch.arrDate2.value = QSdate;
   }
}



/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Bookmark site script - © Dynamic Drive DHTML code library (www.dynamicdrive.com)
 * This notice MUST stay intact for legal use
 * Visit Dynamic Drive at http : // www.dynamicdrive.com / for full source code
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* Modified to support Opera */
function bookmarksite(title, url)
{
   if (window.sidebar) // firefox
   window.sidebar.addPanel(title, url, "");
   else if(window.opera && window.print)
   {
      // opera
      var elem = document.createElement('a');
      elem.setAttribute('href', url);
      elem.setAttribute('title', title);
      elem.setAttribute('rel', 'sidebar');
      elem.click();
   }
   else if(document.all)// ie
   window.external.AddFavorite(url, title);
}


/*
This script is written by Eric (Webcrawl@usa.net)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
 */

function printit()
{
   if (window.print)
   {
      window.print() ;
   }
   else
   {
      var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
      document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
      WebBrowser1.ExecWB(6, 2);
      // Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";
   }
}


function convertdate1()
{
   if (document.QSSearch)
   {
      document.QSSearch.displayDate.value = formatDate(new Date(getDateFromFormat(document.QSSearch.depDate.value, document.QSSearch.inputFormat.value)), document.QSSearch.newFormat.value);
   }
   else
   {
      return false;
   }
}

function addDays2()
{
   if (document.QSSearch.arrDate.value != '')
   {
      // get source date
      var StartingDate = document.QSSearch.arrDate.value;
      // source date is dd / mm / yyyy format, convert to mm / dd / yyyy
      var strSeperator = "/";
      // manipulate
      var mDay = StartingDate.substr(0, 2);
      var mMonth = StartingDate.substr(3, 2);
      var mYear = StartingDate.substr(6, 4)
      // represent as mm / dd / yyy
      StartingDate2 = mMonth + strSeperator + mDay + strSeperator + mYear;
      // no of days to add from dd menu
      DaysToAdd = document.QSSearch.nights.value;
      var now = new Date();

		var newdate = new Date(StartingDate2);
		var newtimems = newdate.setDate(newdate.getDate()+Number(DaysToAdd));
//		Old vars - rounding issues for Oct?
//		var newtimems = newdate.getTime() + (DaysToAdd * 24 * 60 * 60 * 1000);
//      newdate.setTime(newtimems);

      var month = newdate.getMonth() + 1
      var day = newdate.getDate()
      var year = newdate.getFullYear()
      document.QSSearch.depDate.value = LZ(day) + "/" + LZ(month) + "/" + year;
      document.QSSearch.arrDateT.value = StartingDate;
      convertdate1()
   }
}

function YY_checkform()
{
   // v4.71
   // copyright (c)1998, 2002 Yaromat.com
   var a = YY_checkform.arguments, oo = true, v = '', s = '', err = false, r, o, at, o1, t, i, j, ma, rx, cd, cm, cy, dte, at;
   for (i = 1; i < a.length; i = i + 4)
   {
      if (a[i + 1].charAt(0) == '#')
      {
         r = true;
         a[i + 1] = a[i + 1].substring(1);
      }
      else
      {
         r = false
      }
      o = MM_findObj(a[i].replace(/\[\d+\]/ig, ""));
      o1 = MM_findObj(a[i + 1].replace(/\[\d+\]/ig, ""));
      v = o.value;
      t = a[i + 2];
      if (o.type == 'text' || o.type == 'password' || o.type == 'hidden')
      {
         if (r && v.length == 0)
         {
            err = true
         }
         if (v.length > 0)
         if (t == 1)
         {
            // fromto
            ma = a[i + 1].split('_');
            if(isNaN(v) || v < ma[0] / 1 || v > ma[1] / 1)
            {
               err = true
            }
         }
         else if (t == 2)
         {
            rx = new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");
            if( ! rx.test(v))err = true;
         }
         else if (t == 3)
         {
            // date
            ma = a[i + 1].split("#");
            at = v.match(ma[0]);
            if(at)
            {
               cd = (at[ma[1]]) ? at[ma[1]] : 1;
               cm = at[ma[2]] - 1;
               cy = at[ma[3]];
               dte = new Date(cy, cm, cd);
               if(dte.getFullYear() != cy || dte.getDate() != cd || dte.getMonth() != cm)
               {
                  err = true
               }
               ;
            }
            else
            {
               err = true
            }
         }
         else if (t == 4)
         {
            // time
            ma = a[i + 1].split("#");
            at = v.match(ma[0]);
            if( ! at)
            {
               err = true
            }
         }
         else if (t == 5)
         {
            // check this 2
            if(o1.length)o1 = o1[a[i + 1].replace(/(.*\[)|(\].*)/ig, "")];
            if( ! o1.checked)
            {
               err = true
            }
         }
         else if (t == 6)
         {
            // the same
            if(v != MM_findObj(a[i + 1]).value)
            {
               err = true
            }
         }
      }
      else
      if ( ! o.type && o.length > 0 && o[0].type == 'radio')
      {
         at = a[i].match(/(.*)\[(\d+)\].*/i);
         o2 = (o.length > 1) ? o[at[2]] : o;
         if (t == 1 && o2 && o2.checked && o1 && o1.value.length / 1 == 0)
         {
            err = true
         }
         if (t == 2)
         {
            oo = false;
            for(j = 0; j < o.length; j ++ )
            {
               oo = oo || o[j].checked
            }
            if( ! oo)
            {
               s += ' ' + a[i + 3] + '\n'
            }
         }
      }
      else if (o.type == 'checkbox')
      {
         if((t == 1 && o.checked == false) || (t == 2 && o.checked && o1 && o1.value.length / 1 == 0))
         {
            err = true
         }
      }
      else if (o.type == 'select-one' || o.type == 'select-multiple')
      {
         if(t == 1 && o.selectedIndex / 1 == 0)
         {
            err = true
         }
      }
      else if (o.type == 'textarea')
      {
         if(v.length < a[i + 1])
         {
            err = true
         }
      }
      if (err)
      {
         s += ' ' + a[i + 3] + '\n';
         err = false
      }
   }
   if (s != '')
   {
      alert('' + s)
   }
   document.MM_returnValue = (s == '');
}
// -->





