<!--//
var CheckInTime = '4:00 PM';
var CheckOutTime = '11:00 AM';

// Nascar dates
var arrSpecialDates = new Array();
arrSpecialDates[0] = new Date(2007,2,23); // Mar 22, 2007 - Nascar NEXTEL Cup Series Food City 500 date
arrSpecialDates[1] = new Date(2007,2,24); // Mar 23, 2007 - Nascar NEXTEL Cup Series Food City 500 date
arrSpecialDates[2] = new Date(2007,2,25); // Mar 24, 2007 - Nascar Busch Series Sharpie Mini 300 date
arrSpecialDates[3] = new Date(2007,2,26); // Mar 25, 2007 - Nascar NEXTEL Cup Series Food City 500 date
arrSpecialDates[4] = new Date(2007,7,23); // Aug 22, 2007 - Nascar Sharpie 500 Weekday Wednesday date
arrSpecialDates[5] = new Date(2007,7,24); // Aug 23, 2007 - Nascar Sharpie 500 Weekday Thursday date
arrSpecialDates[6] = new Date(2007,7,25); // Aug 24, 2007 - Nascar Busch Series Food City 250 date
arrSpecialDates[7] = new Date(2007,7,26); // Aug 25, 2007 - Nascar NEXTEL Cup Series Sharpie date
arrSpecialDates[8] = new Date(2007,7,27); // Aug 26, 2007 - Nascar Sunday date
arrSpecialDates[9] = new Date(2007,7,28); // Aug 27, 2007 - Nascar Monday date

var SpecialDateCount = 9; // set this equal to the last defined special date element


// holiday dates
var arrHolidayDates = new Array();
arrHolidayDates[0] = new Date(2006,10,24); // Nov 23, 2006 - Thanksgiving Day date
arrHolidayDates[1] = new Date(2006,11,25); // Dec 24, 2006 - Christmas Eve date
arrHolidayDates[2] = new Date(2006,11,26); // Dec 25, 2006 - Christmas Day date
arrHolidayDates[3] = new Date(2007,0,1); // Dec 31, 2006 - New Years Eve date
arrHolidayDates[4] = new Date(2007,0,2); // Jan 1, 2007 - New Years Day date
arrHolidayDates[5] = new Date(2007,0,12); // Jan 11, 2007 - My Birthday date
arrHolidayDates[6] = new Date(2007,0,16); // Jan 15, 2007 - Martin Luther King date
arrHolidayDates[7] = new Date(2007,1,20); // Feb 19, 2007 - Presidents Day date
arrHolidayDates[8] = new Date(2007,4,29); // May 28, 2007 - Memmorial Day date
arrHolidayDates[9] = new Date(2007,6,5); // Jul 4, 2007 - Independence Day date
arrHolidayDates[10] = new Date(2007,8,4); // Sep 3, 2007 - Labor Day date
arrHolidayDates[11] = new Date(2007,9,9); // Oct 8, 2007 - Columbus Day date
arrHolidayDates[12] = new Date(2007,10,13); // Nov 12, 2007 - Veterans Day date
arrHolidayDates[13] = new Date(2007,10,23); // Nov 22, 2007 - Thanksgiving Day date
arrHolidayDates[14] = new Date(2007,11,25); // Dec 24, 2007 - Christmas Eve date
arrHolidayDates[15] = new Date(2007,11,26); // Dec 25, 2007 - Christmas Day date
arrHolidayDates[16] = new Date(2007,0,1); // Dec 31, 2007 - New Years Eve date
arrHolidayDates[17] = new Date(2008,0,2); // Jan 1, 2008 - New Years Day date

var HolidayDateCount = 17; // 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);

  //validate the dates  
  if (datStart >= datEnd)
  {
	s = s + 'End date must be later than 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;
		}
	}
	//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();
  }
}

//-->
