document.onclick=check;

function check(e) {
	//alert('checking');
	var target = (e && e.target) || (event && event.srcElement);
	//checkParent(target,'windowcontent_apartment1')?alert('do it'):null;
	checkParent(target,'windowcontent_apartment1')?hideWindow('thewindow_apartment1'):null; 
	checkParent(target,'windowcontent_contact')?hideWindow('thewindow_contact'):null;
	checkParent(target,'windowcontent_directions')?hideWindow('thewindow_directions'):null;
	checkParent(target,'windowcontent_bookingform')?hideWindow('thewindow_bookingform'):null;
	checkParent(target,'windowcontent_exclusive')?hideWindow('thewindow_exclusive'):null;
}

function checkParent(t,w){ 
	while(t.parentNode){ 
		if(t==document.getElementById(w)){
			//alert('here');
			return false;
		}
		t=t.parentNode;
	}
	//alert('there');
	var temp = document.getElementById(w);
	var winbackground = document.getElementById('thewindowbackground');
	if (temp.style.display == 'block' && winbackground.style.display == 'block') {
		return true;
	}
} 

function submitBookingForm(offset) {
	var selRoomType = document.getElementById("cbApartment");
	if(selRoomType.selectedIndex==0) {
		alert("Please select an apartment from the available options");
		return false;
	}
	var fldname = document.getElementById("cbName");
	if ((fldname.value.length==0) || (fldname.value==null)) {
      alert("Please enter a contact name");
	  return false;
	}
	var fldemail = document.getElementById("cbEmail");
	if ((fldemail.value.length==0) || (fldemail.value==null)) {
      alert("Please enter an email address for us to contact you");
	  return false;
	}
	showWindow('thewindow_bookingform','windowcontent_bookingform',offset-100);
	document.BookingForm.submit();
}
	
function obSetDates() {
	var now = new Date();

	var nowYear = now.getFullYear()*1;

	var selYear  = document.getElementById("cbArrivalYear");
	var selMonth = document.getElementById("cbArrivalMonth");
	var selDay   = document.getElementById("cbArrivalDay");

	for(var i=0; i<=1; i++) {
		var optYear = new Option();
		optYear.value=nowYear+i;
		optYear.text=nowYear+i;
		if(i==0) optYear.selected = true;
		selYear.options[i]=optYear;
	}

	selMonth.selectedIndex = now.getMonth();
	selDay.selectedIndex   = now.getDate()-1;
}
