Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape

//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear)
{
  var DaysInMonth = 31;
  if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
  if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
  if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
  return DaysInMonth;
}

function DaysInMonthNum(WhichMonth, WhichYear)
{
  var DaysInMonth = 31;
  if (WhichMonth == 4 || WhichMonth == 1 || WhichMonth == 9 || WhichMonth == 11) DaysInMonth = 30;
  if (WhichMonth == 2 && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
  if (WhichMonth == 2 && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
  return DaysInMonth;
}

// Reservation form
function FormsOnLoad()
{
	// CLIENT CACHE
	/*
	if(Client && document.weform)
	{		
		for (fi=0; fi<=document.weform.elements.length; fi++)
		{			
			document.weform.elements[fi].onchange = onWeFormElementChange;
			//WebKit.addEvent(document.weform.elements[fi], "change", );
		}
	}
	*/
	
	if (!document.weform || !document.weform.starteq)return;
	
	// DEFAULT VALUES	
	inpTime = document.weform.inp6;
	inpPeople = document.weform.inp7;
	inpTime[7].selected = true;
	inpPeople[1].selected = true;
  
	DaysObject = document.weform.inp4;
	MonthObject = document.weform.starteq;
	YearObject = document.weform.card;
	
	//YearObject[NowYear].selected = true;
	YearObject.value = NowYear;
	MonthObject[NowMonth].selected = true;
	
	chinp();
	
	DaysObject[NowDay-1].selected = true;  
	
	
	// CACHE VALUES	
	/*
	for (fi=0; fi<=document.weform.elements.length; fi++)
	{
		if(document.weform.elements[fi] != undefined)
		{
			document.weform.elements[fi].onchange = onWeFormElementChange;
	
			inp = Client.getVar("WeForm_"+document.weform.elements[fi].id);
			if(inp)
			{			
				switch(inp.type)
				{
					case "text":
					case "textarea":
						document.weform.elements[fi].value = inp.value;
						break;
												
					case "select-one":
						document.weform.elements[fi][inp.value].selected = true;
						break;				
				}
			}
		}
	}	
	*/	
}

WebKit.addEvent(window, "DOMContentLoaded", FormsOnLoad);

function onWeFormElementChange()
{	
	switch(this.type)
	{
		case "text":
		case "textarea":
			eval("Client.Update({WeForm_"+this.id+": {type: this.type, value: this.value}});");
			break;
			
		case "select-one":
			break;
		
	}
}


//function to change the available days in a months
function chinp()
{
	Which = 'FirstSelect';
	DaysObject = eval("document.weform.inp4");
	MonthObject = eval("document.weform.starteq");
	YearObject = eval("document.weform.card");
	
	Month = MonthObject[MonthObject.selectedIndex].value;
	Year = YearObject[YearObject.selectedIndex].value;

	DaysForThisSelection = DaysInMonthNum(Month, Year);
	
	//alert(DaysForThisSelection);
	CurrentDaysInSelection = DaysObject.length;
	if (CurrentDaysInSelection > DaysForThisSelection)
	{
		for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
		{
			DaysObject.options[DaysObject.options.length - 1] = null
		}
	}
	if (DaysForThisSelection > CurrentDaysInSelection)
	{
		for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
		{
			//NewOption = new Option(DaysObject.options.length + 1);
			//alert(NewOption);
			//DaysObject.add(NewOption);
		    NewOption = new Option(DaysObject.options.length + 1, DaysObject.options.length + 1);
			DaysObject.options[DaysObject.options.length] = NewOption;
		}
	}
	if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}
