//javascript for initializing dates - see bottom for other scripts besides dates

//Used in Body onload for drop down search box style
function initDate()
{
	var today = new Date();
	var currMth = today.getMonth();
	var currDate = today.getDate();
	var curr_yearn = today.getFullYear();
        var curr_year = curr_yearn+'';
	if (document.resrvForm.doa_dd.options)
		{
		var mth = document.resrvForm.doa_dd.options.selectedIndex = currMth;
		var Dt = document.resrvForm.doa_dd.options.selectedIndex = currDate;
		adjustDate(mth, Dt, 1);
		}
	else
		{
		document.resrvForm.doa_mm.value = currMth+1;
		document.resrvForm.doa_dd.value = currDate;
		document.resrvForm.doa_yy.value = curr_year;
		chgdate();
		}
}


//Used for Check-in date verification on non-drop down search
function chgdate()
{
var today = new Date();
var mth = today.getMonth()+1;
var numDaysIN = getDaysInMonth2(document.resrvForm.doa_mm.value, document.resrvForm.doa_yy.value);

if (document.resrvForm.doa_mm.value < 1)
	{
	alert('month must be between greater than 0');
	document.resrvForm.doa_mm.value=1;
	document.resrvForm.doa_mm.focus();
	}
else
	{
	if (document.resrvForm.doa_mm.value > 12)
		{
		alert('month must be 12 or less');
 		document.resrvForm.doa_mm.value=12;
		document.resrvForm.doa_mm.focus();
		}
	else
	{
	document.resrvForm.dod_mm.value = document.resrvForm.doa_mm.value;
	}
}
if (document.resrvForm.doa_dd.value < 1)
	{
	alert('day must be greater than 0');
	document.resrvForm.doa_dd.value=1;
	document.resrvForm.doa_dd.focus();
	}
else
	{
	if (document.resrvForm.doa_dd.value > numDaysIN)
		{
		alert('days must be less than or equal '+numDaysIN);
		document.resrvForm.doa_dd.value=numDaysIN;
		document.resrvForm.doa_mm.focus();
		}
	else
		{
		document.resrvForm.dod_dd.value = (document.resrvForm.doa_dd.value -0) + 1;
		if (document.resrvForm.dod_dd.value > numDaysIN)
			{
			document.resrvForm.dod_dd.value = 1;
			document.resrvForm.dod_mm.value = (document.resrvForm.doa_mm.value -0) + 1;
			if (document.resrvForm.dod_mm.value>12)
				{
				document.resrvForm.dod_mm.value = 1;
				document.resrvForm.dod_yy.value = (document.resrvForm.dod_yy.value - 0) + 1;
				}
			}
		}
	}
if (document.resrvForm.dod_yy.value < document.resrvForm.doa_yy.value)
	{
	document.resrvForm.dod_yy.value = document.resrvForm.doa_yy.value;
	}
}
//Used for Check-out date verification on non-drop down search
function chgoutdate()
{
var today = new Date();
var mth = today.getMonth()+1;
var numDaysOUT = getDaysInMonth2(document.resrvForm.dod_mm.value, document.resrvForm.dod_yy.value);
if (document.resrvForm.dod_mm.value < 1)
	{
	alert('month must be between greater than 0');
	document.resrvForm.dod_mm.value=1;
	document.resrvForm.dod_mm.focus();
	}
else
	{
	if (document.resrvForm.dod_mm.value > 12)
		{
		alert('month must be 12 or less');
 		document.resrvForm.dod_mm.value=12;
		document.resrvForm.dod_mm.focus();
		}
	
}

if (document.resrvForm.dod_dd.value < 1)
	{
	alert('day must be greater than 0');
	document.resrvForm.dod_dd.value=1;
	document.resrvForm.dod_dd.focus();
	}
else
	{
	if (document.resrvForm.dod_dd.value > numDaysOUT)
		{
		alert('days must be less than or equal '+numDaysOUT);
		document.resrvForm.dod_dd.value=numDaysOUT;
		document.resrvForm.dod_mm.focus();
		}
	}

if (document.resrvForm.dod_yy.value < document.resrvForm.doa_yy.value)
	{
	alert('Check-out Year must be greater than or equal to check-in year');
	document.resrvForm.dod_yy.value = document.resrvForm.doa_yy.value;
	document.resrvForm.dod_yy.focus();
	}
}


function IsLeapYear(yrStr)
{
 var leapYear = false;
 var year = parseInt(yrStr, 10);
 if (year%4 == 0) 
  { 
	leapYear = true;
	if (year%100 == 0)
	 {
	  leapYear = false;
	  if (year%400 == 0)
	   {
	    leapYear = true;
		}
	  }
   }
  return leapYear;
 }


function getDaysInMonth(mthIdx, yrStr) 
{
 var maxDays = 31;
 if (mthIdx == 1)
	{
	 if (IsLeapYear(yrStr))
	   { 
	    maxDays = 29;
	   }
	 else
		{
		  maxDays = 28;
		}
     }
 if (mthIdx == 3 || mthIdx == 5 || mthIdx == 8 || mthIdx == 10)
	{
	 maxDays = 30;
	 }
 return maxDays;
}

// for non drop down calendar
function getDaysInMonth2(mthIdx, yrStr) 
{
 var maxDays = 31;
 if (mthIdx == 2)
	{
	 if (IsLeapYear(yrStr))
	   { 
	    maxDays = 29;
	   }
	 else
		{
		  maxDays = 28;
		}
     }
 if (mthIdx == 4 || mthIdx == 6 || mthIdx == 9 || mthIdx == 11)
	{
	 maxDays = 30;
	 }
 return maxDays;
}

function adjustDate(mthIdx, Dt, initDate)
{
var value = 0;

var today = new Date();
var theYear = parseInt(today.getYear(),10);

if (mthIdx < today.getMonth()) {
	theYear = (parseInt(today.getYear(),10) + 1);
}

if (theYear < 100) {
	theYear = "19" + theYear;
	}
else {
	if ((theYear - 100) < 10) {
		theYear = "0" + (theYear - 100);
		}
	else 
		{
		theYear = (theYear - 100) + "";
		}
	theYear = "20" + theYear
}

var numDays = getDaysInMonth(mthIdx, theYear);

 
// checks whether to initialize date or not.
if (initDate == 1) 
	{
	  if (numDays - Dt == 7)
		{
		document.resrvForm.doa_mm.options.selectedIndex = mthIdx;
	    document.resrvForm.doa_dd.options.selectedIndex = numDays - 1;
		document.resrvForm.dod_mm.options.selectedIndex = document.resrvForm.doa_mm.options.selectedIndex + 1;
	    document.resrvForm.dod_dd.options.selectedIndex =  7 - (numDays - Dt);
		}
		else if (numDays - Dt  < 7)
				{
				document.resrvForm.doa_mm.options.selectedIndex = mthIdx + 1;
				document.resrvForm.doa_dd.options.selectedIndex = 6 - (numDays - Dt);
				document.resrvForm.dod_mm.options.selectedIndex = document.resrvForm.doa_mm.options.selectedIndex;
				document.resrvForm.dod_dd.options.selectedIndex = 7 - (numDays - Dt);	
				}
		else
			{ 
			document.resrvForm.doa_mm.options.selectedIndex = mthIdx;
			document.resrvForm.doa_dd.options.selectedIndex = (Dt - 1) + 7
			document.resrvForm.dod_mm.options.selectedIndex = document.resrvForm.doa_mm.options.selectedIndex;
			document.resrvForm.dod_dd.options.selectedIndex = (Dt - 1) + 8;
			}
		}
else
	{		
	if (mthIdx == 1)
		{
		if (Dt.options.selectedIndex + 1 < numDays) 
			{
			return 0;
			}
		else
			{
			Dt.options.selectedIndex=numDays - 1;
			if (numDays == 29)
				{
				return 99;
				}
			else
				{
				return 1;
				}
			}
		}
	 if (Dt.options.selectedIndex + 1 < numDays)
		{
		value = 0;
		}
	 else
		{
		if (Dt.options.selectedIndex + 1 > numDays)
			{
			Dt.options.selectedIndex--;
			value = 3;
			}
		else
			{
			value = 2;
			}
		}
	 return value;
	}
}


function amadChange(inM, inD, outM, outD)
{
 var res = adjustDate(inM.options.selectedIndex, inD, 0);
 if (res != 0 )
	{
		outD.options.selectedIndex = 0;
		if (outM.options.selectedIndex == 11) {
			outM.options.selectedIndex = 0;
			}
		else {
			outM.options.selectedIndex = inM.options.selectedIndex + 1;
			}
		}
 else
	{
	outM.options.selectedIndex = inM.options.selectedIndex;
	outD.options.selectedIndex = inD.options.selectedIndex + 1;
	}
return;
}



// New for football scripts
var Alabama = new Array("Tuscaloosa", "AL");
var Arkansas = new Array("Fayetteville", "AR");
var Auburn = new Array("Auburn", "AL");
var Duke = new Array("Raleigh", "NC");
var Florida = new Array("Gainesville","FL");
var Geogia = new Array("Athens", "GA");
var Kentucky = new Array("Lexington", "KY");
var LSU = new Array("Baton Rouge", "LA");
var Miami = new Array("Miami", "FL");
var Miss_St = new Array("Starkville", "MS");
var Ole_Miss = new Array("Oxford", "MS");
var Tennessee = new Array("Knoxville", "TN");
var S_Carolina = new Array("Columbia", "SC");
var Vanderbilt = new Array("Nashville", "TN");

function chgschool(the_array_name)
{
	var the_array = eval(the_array_name);
	document.resrvForm.city.value = the_array[0];
	document.resrvForm.state.value = the_array[1];
}
// create drop down year

function buildyear()
{
  for (yearCounter = 0; yearCounter < 4; yearCounter++)
  {
   ocurr_year=curr_yearn+yearCounter;
   curr_year = ocurr_year+'';
   var ocurr_year2 = curr_year.substring(2,4)
   document.write('<OPTION value=' + ocurr_year + '>' + ocurr_year2);
  }
}
// Original:  Ronnie T. Moore 
// Web Site:  The JavaScript Source 
// Dynamic 'fix' by: Nannette Thacker 
// Web Site: http://www.shiningstar.net 
// This script and many more are available free online at 
// The JavaScript Source!! http://javascript.internet.com 

function textCounter(field, countfield, maxlimit) {
  if (field.value.length > maxlimit) // if too long...trim it!
    field.value = field.value.substring(0, maxlimit); 
    // otherwise, update 'characters left' counter
  else 
    countfield.value = maxlimit - field.value.length;
}


