<!--//
var CheckInTime = '4:00 PM';
var CheckOutTime = '11:00 AM';

// Nascar dates
var arrSpecialDates = new Array();
arrSpecialDates[0] = new Date(2010,2,19); // Mar 18, 2010 - Nascar
arrSpecialDates[1] = new Date(2010,2,20); // Mar 19, 2010 - Nascar
arrSpecialDates[2] = new Date(2010,2,21); // Mar 20, 2010 - Nascar
arrSpecialDates[3] = new Date(2010,2,22); // Mar 21, 2010 - Nascar

arrSpecialDates[4] = new Date(2010,7,19); // Aug 18, 2010 - Nascar
arrSpecialDates[5] = new Date(2010,7,20); // Aug 19, 2010 - Nascar
arrSpecialDates[6] = new Date(2010,7,21); // Aug 20, 2010 - Nascar
arrSpecialDates[7] = new Date(2010,7,22); // Aug 21, 2010 - Nascar

var SpecialDateCount = 7; // set this equal to the last defined special date element


// holiday dates
var arrHolidayDates = new Array();
arrHolidayDates[0] = new Date(2010,8,3); // Sep 2, 2010 - Labor Day Weekend
arrHolidayDates[1] = new Date(2010,8,4); // Sep 3, 2010 - Labor Day Weekend
arrHolidayDates[2] = new Date(2010,8,5); // Sep 4, 2010 - Labor Day Weekend
arrHolidayDates[3] = new Date(2010,8,6); // Sep 5, 2010 - Labor Day Weekend
arrHolidayDates[4] = new Date(2010,8,7); // Sep 6, 2010 - Labor Day

arrHolidayDates[5] = new Date(2010,11,26); // Dec 25, 2010 - Christmas
arrHolidayDates[6] = new Date(2010,11,27); // Dec 26, 2010 - Christmas Weekend
arrHolidayDates[7] = new Date(2010,11,28); // Dec 27, 2010 - Christmas Weekend

arrHolidayDates[8] = new Date(2011,0,1); // Dec 31, 2010 - New Years Eve date
arrHolidayDates[9] = new Date(2011,0,2); // Jan 1, 2011 - New Years Day date
arrHolidayDates[10] = new Date(2011,0,3); // Jan 2, 2011 - New Years Day date

var HolidayDateCount = 10; // 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();
  }
}

//-->

