<!--//
var CheckInTime = '8:00 AM';
var CheckOutTime = '5:00 PM';

// Nascar dates
var arrSpecialDates = new Array();
arrSpecialDates[0] = new Date(2008,2,14); // Mar 13, 2008 - Nascar
arrSpecialDates[1] = new Date(2008,2,15); // Mar 14, 2008 - Nascar
arrSpecialDates[2] = new Date(2008,2,16); // Mar 15, 2008 - Nascar
arrSpecialDates[3] = new Date(2008,7,22); // Aug 21, 2008 - Nascar
arrSpecialDates[4] = new Date(2008,7,23); // Aug 22, 2008 - Nascar
arrSpecialDates[5] = new Date(2008,7,24); // Aug 23, 2008 - Nascar

var SpecialDateCount = 5; // set this equal to the last defined special date element


// holiday dates
var arrHolidayDates = new Array();
arrHolidayDates[0] = new Date(2008,7,29); // Aug 28, 2008 - Labor Day Weekend
arrHolidayDates[1] = new Date(2008,7,30); // Aug 29, 2008 - Labor Day Weekend
arrHolidayDates[2] = new Date(2008,7,31); // Aug 30, 2008 - Labor Day Weekend
arrHolidayDates[3] = new Date(2008,8,1); // Aug 31, 2008 - Labor Day Weekend
arrHolidayDates[4] = new Date(2008,8,2); // Sep 1, 2008 - Labor Day
arrHolidayDates[5] = new Date(2008,0,1); // Dec 31, 2008 - New Years Eve date
arrHolidayDates[6] = new Date(2009,0,2); // Jan 1, 2009 - New Years Day date

var HolidayDateCount = 6; // set this equal to the last defined holiday rate element

function LoadDays(mode)
  {
   /*
    Purpose: Load up the "Days" dropdowns based on Mo/Yr
  
   */
   var intLastDay;
   var Mo;
   var Yr;
   var intIdx = 1;
   var intWasDay = 0;
   
   if (mode=='F')
   {
                if (f.FromMo.selectedIndex<0)
                {
                        f.FromMo.selectedIndex = 0;
                }

                if (f.FromYr.selectedIndex<0)
                {
                        f.FromYr.selectedIndex = 0;
                }
   
                //get the Mo and Yr
                Mo = f.FromMo.options[f.FromMo.selectedIndex].value;
                Yr = f.FromYr.options[f.FromYr.selectedIndex].value;
                //clear out the old list boxes
                intWasDay = f.FromDa.value;
                while (f.FromDa.length > 0) 
                {
                 f.FromDa.options[f.FromDa.length-1]=null;
                }
                intLastDay = GetEndDay(Mo, Yr);
                //f.FromDa.options[f.FromDa.length] = new Option('', '');
                while (intIdx <= intLastDay) 
                {
                 f.FromDa.options[f.FromDa.length] = new Option(intIdx, intIdx);
                 intIdx++;
                } 
                if (intWasDay <= intLastDay)
                {
                 //restore value
                 f.FromDa.selectedIndex = intWasDay-1;
                } else
                {
                 f.FromDa.selectedIndex = 0;
                }
    
    } else { 
                // To
                   if (f.ToMo.selectedIndex<0)
                {
                        f.ToMo.selectedIndex = 0;
                }
                if (f.ToYr.selectedIndex<0)
                {
                        f.ToYr.selectedIndex = 0;
                }
   
                //get the Mo and Yr
                Mo = f.ToMo.options[f.ToMo.selectedIndex].value;
                Yr = f.ToYr.options[f.ToYr.selectedIndex].value;
                //clear out the old list boxes
                intWasDay = f.ToDa.value;
                while (f.ToDa.length > 0) 
                {
                 f.ToDa.options[f.ToDa.length-1]=null;
                }
                intLastDay = GetEndDay(Mo, Yr);
                //f.FromDa.options[f.FromDa.length] = new Option('', '');
                while (intIdx <= intLastDay) 
                {
                 f.ToDa.options[f.ToDa.length] = new Option(intIdx, intIdx);
                 intIdx++;
                } 
                if (intWasDay <= intLastDay)
                {
                 //restore value
                 f.ToDa.selectedIndex = intWasDay-1;
                }
                else
                {
                 f.ToDa.selectedIndex = 0;
                }
    }
  }
  
  function GetEndDay(pintMo, pintYr)
  {
   /*
    Purpose: Calculate the last day of the month for a given Mo/Yr
   */
   var arrEndDay  = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
   // leap year correction
   
   if (pintMo == 2)
   {
    if ((pintYr % 4) == 0 & pintYr !='')
    {
     return 29;
    }
    else
    {
     return 28;
    }
    
   }
   else if (pintMo == '')
   {
    //default value if no month selected
    return 31;
   }
   else
   {
    return arrEndDay[pintMo-1];
   }
  }
  
function IsInteger(fld, e)
{
 var key = '';
 var i = 0;
 var strCheck = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-`=~!@#$%^&*()_+[]\{}|;:<>?,/';
 var whichCode = (window.Event) ? e.which : e.keyCode;
 if ((whichCode == 13) | (whichCode == 34) | (whichCode == 39) | (whichCode == 92)) {
  return false;  // Enter
 }
 key = String.fromCharCode(whichCode);  // Get key value from key code
 if (strCheck.indexOf(key) > -1) {
  return false;  // Not a valid key
 }
 for(i = 0; i < fld.value.length; i++) {
  if (strCheck.indexOf(fld.value.charAt(i))>=0) {
   return false;
  }
 }
}

function trim(strText) 
{ 
        // this will get rid of leading spaces 
        while (strText.substring(0,1) == ' ') 
                strText = strText.substring(1, strText.length);

        // this will get rid of trailing spaces 
        while (strText.substring(strText.length-1,strText.length) == ' ')
                strText = strText.substring(0, strText.length-1);

        return strText;
} 

function AddToCart()
{
  var s = '';
  var y = parseInt(f.FromYr.options[f.FromYr.selectedIndex].value,10);
  var m = parseInt(f.FromMo.options[f.FromMo.selectedIndex].value,10);
  var d = parseInt(f.FromDa.options[f.FromDa.selectedIndex].value,10);
        
  var y2 = parseInt(f.ToYr.options[f.ToYr.selectedIndex].value,10);
  var m2 = parseInt(f.ToMo.options[f.ToMo.selectedIndex].value,10);
  var d2 = parseInt(f.ToDa.options[f.ToDa.selectedIndex].value,10);
  
  // set the actual start and end dates
  var datStart = new Date(y,m-1,d); //note JavaScript months are 0 - 11...
  var datEnd = new Date(y2, m2-1, d2);

  // added 1-6-2008
  var trap = 0;
  if (datStart - datEnd == 0)
  {
    trap = 1;
  }


  //validate the dates  
  if (datStart > datEnd)
  {
        s = s + 'End date must be later than or equal to the start date.\n\n';
  }
  
  if (s != '')
  {
        alert(s);
  }
  else
  {
        
        // set the EventStart tag 
        f.EventStart.value = m + '-' + d + '-' + y + ' ' + CheckInTime;
        // determine the EventEnd tag
        f.EventEnd.value = m2 + '-' + d2 + '-' + y2  + ' ' + CheckOutTime;
        // determine the price
        var i = 1;
        var SpecialCharge = 0.0;
        var HolidayCharge = 0.0;
        var WeekendCharge = 0.0;
        var WeekDayCharge = 0.0;
                
        for (i = 1; i <= 365; i++)
                {
                var TestDate = new Date(y,m-1,d + i); //note JavaScript months are 0 - 11...
                // see if this is a special date
                var j = 0;
                var special = 0;
                for (j=0; j <= SpecialDateCount; j++)
                {
                        var sd = new Date(arrSpecialDates[j]);
                        if ((TestDate.getMonth() == sd.getMonth()) & (TestDate.getDate() == sd.getDate()) & (TestDate.getFullYear() == sd.getFullYear()))
                        {
                                SpecialCharge += parseFloat(f.SpecialRate.value);
                                special = 1;
                        }
                }
                
                if (special == 0) // not a special date, try the speciadate2 (holidays)
                {
                        j = 0;
                        for (j=0; j <= HolidayDateCount; j++)
                        {
                                var sd = new Date(arrHolidayDates[j]);
                                if ((TestDate.getMonth() == sd.getMonth()) & (TestDate.getDate() == sd.getDate()) & (TestDate.getFullYear() == sd.getFullYear()))
                                {
                                        HolidayCharge += parseFloat(f.HolidayRate.value);
                                        special = 1;
                                }
                        }
                }
                
                if (special == 0) // if not a special date or holiday, see if its weekend or weekday
                {
                        if ((TestDate.getDay() == 6) | (TestDate.getDay() == 0) | (TestDate.getDay() == 1)) 
                        {
                                // weekend
                                //0 = Sunday (Friday night)
                            //6 = Saturday (Saturday night)
                            //1 = Monday (Sunday night)
                                WeekendCharge += parseFloat(f.WeekendRate.value);
                        }
                        else
                        {
                                // weekday
                                WeekDayCharge += parseFloat(f.WeekDayRate.value);
                        }
                }
                // bail when we reach the last date
                if ((TestDate.getMonth() == datEnd.getMonth()) & (TestDate.getDate() == datEnd.getDate()) & (TestDate.getFullYear() == datEnd.getFullYear()))
                {
                        break;
                } 
                else if (trap == 1) 
                {
                        // added 1-6-2008 bail if Trap is set (i.e. - start and end date are the same)
                        break;
                }
        }
        //display the dates
        f.AddOn1.value = "Reserved from: " + f.EventStart.value + " thru " + f.EventEnd.value;
        // set the accumulated price and submit
        f.Price.value = (SpecialCharge + WeekendCharge + WeekDayCharge + HolidayCharge);
        f.method = 'post'; 
        f.action='http://www.asecurecart.net/server/cart.aspx/vazteck';
        f.submit();
  }
}

//-->

