var xmlHttp

var time = null;


function submitenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	   {
	   return loginform();
	   }
	else
	   return true;
}


function changeProperty() {
	time = null;
	getCalendar(true);
	updatePropertyName();
	return true;
}

function updatePropertyName() {
	xmlHttp3=GetXmlHttpObject();
	if (xmlHttp3==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var property = document.getElementById("selectproperties").value;	
	var url="propertyname.php";
	url=url+"?id="+property;
	xmlHttp3.onreadystatechange=stateChangedProperty;
	xmlHttp3.open("GET",url,true);
	xmlHttp3.send(null);
}

function getCalendar(next)
{ 		
	if (time == null) {
		time = new Date();
	} else {
		if (next  == true) {
			time.setMonth(time.getMonth()+1);
		} else {
			time.setMonth(time.getMonth()-1);
		}
	}
	
	var newbuttons = "<div id='calendar_previous' onClick='getCalendar(false);'>Prev Month</div><div id='calendar_next' onClick='getCalendar(true);'>Next Month</div>";

	document.getElementById("calendar_buttons").innerHTML = newbuttons;
	var property = 0;
	
	if (document.getElementById("selectproperties")) {
		property = document.getElementById("selectproperties").value;
	}
	
	
	xmlHttp2=GetXmlHttpObject();
	if (xmlHttp2==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	
	var thismonth = Math.round(time.getTime()/1000.0);
	
	var url="calendar.php";
	url=url+"?time="+thismonth;
	url=url+"&property="+property;
	xmlHttp2.onreadystatechange=stateChanged;
	xmlHttp2.open("GET",url,true);
	xmlHttp2.send(null);
}

function getBookingInfo(bookingid)
{ 		
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
		
	var url="bookinginfo.php";
	url=url+"?id="+bookingid;
	xmlHttp.onreadystatechange=stateChangedTwo;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChangedTwo() { 
	if (xmlHttp.readyState==4) { 
		document.getElementById("popover").innerHTML=xmlHttp.responseText;
		document.getElementById('popover').style.display='block';
	}
}

function stateChanged() { 
	if (xmlHttp2.readyState==4) { 
		document.getElementById("calendar").innerHTML=xmlHttp2.responseText;
	}
}

function stateChangedProperty() { 
	if (xmlHttp3.readyState==4) { 
		document.getElementById("propertyname").innerHTML=xmlHttp3.responseText;
	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
	  xmlHttp=new XMLHttpRequest();
	} catch (e){
	  try {
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }catch (e){
		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	}
	return xmlHttp;
}