var endDate = new Date(2010,12,31);
var isPr = false;

function CurrentDate()
{
	//********** Inserts the current date onLoad
	//Update only if first time in page

	Current = new Date();
	CurYear = Current.getFullYear();
	CurDay = Current.getDate();
	CurMonth = Current.getMonth();

	Current2 = new Date(CurYear,CurMonth,CurDay+1);

	document.form.inDay.selectedIndex = CurDay-1;
	document.form.inMonth.selectedIndex = CurMonth;
	document.form.inYear.selectedIndex = 0;

	document.form.outDay.selectedIndex = Current2.getDate()-1;
	document.form.outMonth.selectedIndex = Current2.getMonth();
	document.form.outYear.selectedIndex = Current2.getFullYear()-Current.getFullYear();

}

function UpdateCheckOut()
{
	
	//**** Updates the Check Out Date (all fields) to be equal to the Check In Date
	var now = new Date();
	var currTemp = new Date(document.form.inYear.selectedIndex+now.getYear(),document.form.inMonth.selectedIndex,document.form.inDay.selectedIndex+2);
	if(now>currTemp)
	{
		var Current = new Date(document.form.inYear.selectedIndex+now.getYear()+1,document.form.inMonth.selectedIndex,document.form.inDay.selectedIndex+2);
		document.form.inYear.selectedIndex =Current.getYear()-now.getYear();
	}
	else
		var Current = new Date(document.form.inYear.selectedIndex+now.getYear(),document.form.inMonth.selectedIndex,document.form.inDay.selectedIndex+2);

	document.form.outYear.selectedIndex = Current.getYear()-now.getYear();
	document.form.outMonth.selectedIndex = Current.getMonth();
	document.form.outDay.selectedIndex = Current.getDate()-1;
			
}


function CheckDates()
{
//***** The Function alerts if the user entered a day that does not exist
//***** in a certain month (Example: 31 of February)

//********* Get Date variables **************
tmpCurrDate = new Date();
currentDate = new Date(tmpCurrDate.getFullYear(), tmpCurrDate.getMonth(), tmpCurrDate.getDate());
InMonth = document.form.inMonth.selectedIndex+1;
InDay = document.form.inDay.selectedIndex+1;
InYear = document.form.inYear.selectedIndex+currentDate.getFullYear();
OutMonth = document.form.outMonth.selectedIndex+1;
OutDay = document.form.outDay.selectedIndex+1;
OutYear = document.form.outYear.selectedIndex+currentDate.getFullYear();

//***** Transform to valid date objects *********
var InDate = new Date(InYear,InMonth-1,InDay);
var OutDate = new Date(OutYear,OutMonth-1,OutDay);

var Num = Date.UTC(OutYear,OutMonth-1,OutDay) - Date.UTC(InYear,InMonth-1,InDay);
var NumDays = Num/1000/60/60/24;

var Send = 1; //**** Submit Form if Send = 1

//********* Check if valid day for month ***********
if (InDate.getDate()!= InDay)
	{
	alert("This month Does not contain "+ InDay + " days !\n Please Select the Check In Date Again.");
	Send = 0;
	}
else if (OutDate.getDate()!= OutDay)
	{
	alert("This month Does not contain "+ OutDay +" days !\n Please Select the Check Out Date Again.");
	Send = 0;
	}
else if (OutYear < InYear)
	{
	alert("Your Check-Out date precedes your Check-In date \nPlease check your dates !")
	Send = 0;
	}
else if (OutYear == InYear)
	{
	if (OutMonth < InMonth)
		{
		alert("Your Check-Out date precedes your Check-In date \nPlease check your dates !")
		Send = 0;
		}
	else if (OutMonth == InMonth)
		{
		if (OutDay <= InDay)
			{
			alert("Your Check-Out date precedes your Check-In date \nPlease check your dates !")
			Send = 0;
			}
		 //**** CHECK IF RESERVATION PAST THE END DATE ****
        else if(OutYear == (endDate.getYear()))
			{
			if ((OutMonth > endDate.getMonth()) || (OutMonth == endDate.getMonth() && OutDay > endDate.getDate()))
				{
				if(confirm("Sorry, our search engine can only search up to " + endDate.getMonth() + "/" + endDate.getDate() + "/" + endDate.getYear() + "\nYou will need to fill out a special form.\nPress CANCEL to try again or Press O.K."))
					{
					Send = 0;
					}
				else
					Send = 0;
				}
			}
		 }
	//**** CHECK IF RESERVATION OVER 30 DAYS ****
	else if (NumDays > 30)
		{
		if(confirm("Your reservation is for over 30 days !\nYou will need to fill out a special form.\nPress CANCEL to try again or Press O.K."))
			{
			Send = 0;
			}
		else
			Send = 0;
		}
	//**** CHECK IF RESERVATION END AFTER ENDDATE ****
	else if(OutYear == endDate.getYear())
		{
		if ((OutMonth > endDate.getMonth()) || (OutMonth == endDate.getMonth() && OutDay > endDate.getDate()))
			{
			if(confirm("Sorry, our search engine can only search up to " + endDate.getMonth() + "/" + endDate.getDate() + "/" + endDate.getYear() + "\nYou will need to fill out a special form.\nPress CANCEL to try again or Press O.K."))
				{
				Send = 0;
				}
			else
				Send = 0;
			}
		}
	}
//***** END OF REGULAR DATE VALIDATION *****

//***** CHECK IF RESERVATION NOT MORE THAN 30 DAYS
else if (NumDays > 30)
	{
	if(confirm("Your reservation is for over 30 days !\nYou will need to fill out a special form.\nPress CANCEL to try again or Press O.K."))
		{
		Send = 0;
		}
	else
		Send = 0;
	}
  //**** CHECK IF RESERVATION DATE ENDS AFTER ENDDATE ****
  else if(OutYear == (endDate.getYear()))
		{
		if ((OutMonth > endDate.getMonth()) || (OutMonth == endDate.getMonth() && OutDay > endDate.getDate()))
			{
			if(confirm("Sorry, our search engine can only search up to " + endDate.getMonth() + "/" + endDate.getDate() + "/" + endDate.getYear() + "\nYou will need to fill out a special form.\nPress CANCEL to try again or Press O.K."))
				{
				Send = 0;
				}
			else
				Send = 0;
			}
		}
		
  if(InDate < currentDate)
  {
    alert("Sorry, you can't order before today's date");
    Send = 0;
  }


  //***** Submit Form if valid dates ********
  if (Send == 1)
    document.form.submit();
}

