function showWaitPanel()
{				
	//document.getElementById('WaitPanel').style.visibility="visible";
	//document.getElementById('WaitPanel').style.display="inline";
	
	//if (document.getElementById('AvailabilityGrid')!=null)  { 
//		document.getElementById('AvailabilityGrid').innerHTML='<br/><p class="hometitle" align="Center">Please wait</p>' + '<p class="normal" align="center">We are searching our bed bank for available accommodation.<br>This may take in the region of 10-20 seconds.</p>';
//		toggleLayer('SearchForm');			

		document.getElementById('pleasewait').style.visibility="visible";
		document.getElementById('pleasewait').style.display="block";
//		document.getElementById('AvailabilityGrid').style.visibility="hidden";
		document.getElementById('SearchForm').style.display="inline";
		document.getElementById('SearchForm').style.visibility="hidden";
	//}
}

var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
//var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var mtend = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

var ingdays = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var aledays = new Array("Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag");
var espdays = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");

// display day of week
function getDayOfWeek(day, month, year) {
//	var lang=window.parent.frames['toptitle'].get_lang();
	var c = new Date(year,month-1,day);	
	switch (lang) {
		case 'ING': return ingdays[c.getDay()];break;
		case 'ALE': return aledays[c.getDay()];break;
		case 'ESP': return espdays[c.getDay()];break;
		break;
	}
}

// check date is valid
function checkDate(day, month, year) {
	// check for leaps
	if (month==1 && year % 4==0) 
		if (day > 29)
			return false
		else
			return true				
	else							
		if (day > mtend[month-1])
			return false
		else
			return true		
}

// get year 
function IBgetYear(month)  {
	var today = new Date();

	alert(today.getMonth());
	if (today.getMonth()+2 > month)
		return today.getFullYear()+1
	else
		return today.getFullYear()
}

function popupCalendar(field,daydropdown,monthdropdown)
{
	var year=IBgetYear(monthdropdown.selectedIndex+1);
	var month=monthdropdown.selectedIndex+1;
	var day=daydropdown.selectedIndex+1;

	window.open("calendar.aspx?field=" + field + "&year=" + year + "&month=" + month + "&day=" + day,"","toolbar=no,status=no,scrollbars=no,resizable=no,width=220,height=200,top=350,left=400")
}


function getDateInfo(daydropdown,monthdropdown,daylayer,yeardropdown) {


	if (checkDate(daydropdown.selectedIndex+1,monthdropdown.selectedIndex+1)==false)
	{
		switch (lang)
		{
			case "ALE": alert("Ungültiges Datum!");
						break;
			case "ING":	alert('Invalid Date');
						break;
			case "ESP": alert("Fecha inválida!");
						break;
		}
		return;
	}
		
	else
	{				
		if (document.getElementById(daylayer)!=null) {
			document.getElementById(daylayer).innerHTML= 
				getDayOfWeek(daydropdown.selectedIndex+1,monthdropdown.selectedIndex+1,yeardropdown.value);
			// Jahr ändern falls Monat kleiner als aktueller Monat ist
			var jetzt = new Date();
			search_month = document.IB.FromMonth.options[document.IB.FromMonth.selectedIndex].value;
			search_year = document.IB.FromYear2.options[document.IB.FromYear2.selectedIndex].value;
			act_month = jetzt.getMonth();
		  act_year = jetzt.getFullYear();
			act_month = act_month + 1;  // + 1 da Januar = 0
			if (search_month < act_month && search_year == act_year) {
				document.IB.FromYear2.selectedIndex = 1;
				recalculateAllDates();
			}
//			alert(act_month);
		}	

//		if (document.getElementById(yearlayer)!=null)
//		document.IB.FromYear2.value=IBgetYear(monthdropdown.selectedIndex+1);					
	}
}

function recalculateAllDates()
{
	getDateInfo(document.IB.FromDay,document.IB.FromMonth,'FromDayOfWeek',document.IB.FromYear2);
//	getDateInfo(document.Form1.ToDay,document.Form1.ToMonth,'ToDayOfWeek','ToYear');
}

// .NET client validator
function checkDatesSensible(source, arguments)
{

	var today = new Date();
	var fromDate = new Date(IBgetYear(document.Form1.FromMonth.selectedIndex+1),document.Form1.FromMonth.selectedIndex+1,document.Form1.FromDay.selectedIndex+1);
	var ToDate = new Date(IBgetYear(document.Form1.ToMonth.selectedIndex+1),document.Form1.ToMonth.selectedIndex+1,document.Form1.ToDay.selectedIndex+1);

	if (today >= fromDate)
	{
		alert ('Arrival Date must be later than today.');
		arguments.IsValid=false;
	}
	else if (ToDate <= fromDate)
	{
		alert ('Arrival Date must be earlier than departure date.');
		arguments.IsValid=false;
	}	
	else	
		arguments.IsValid=true;
}


function toggleLayer(id)  {
	if (document.getElementById(id)!=null)
		if (document.getElementById(id).style.visibility=='hidden')
			document.getElementById(id).style.visibility='visible'
		else
			document.getElementById(id).style.visibility='hidden'			
}


