// JavaScript Document
function Onenews($this){
	// For Firefox and Internet Explorer
	if((navigator.appName == "Microsoft Internet Explorer" || navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4)){
		var curleft = curtop = 0;
		if($this.offsetParent){
			curleft = $this.offsetLeft;
			curtop = $this.offsetTop;
			
			while($this = $this.offsetParent){
				curleft += $this.offsetLeft;
				curtop += $this.offsetTop;
			}
		}
		document.getElementById("availability").style.visibility = "visible";
		document.getElementById("availability").style.left = (curleft - (250 - document.getElementById("availability_button").width)) + 'px';
		document.getElementById("availability").style.top = (curtop - 200) + 'px';
		
		document.getElementById("availability_button").onclick = function(){
			Offenews(this);
		}
	}else{
		alert("Not support Internet Explorer version");
	}
}
function Offenews($this){
	document.getElementById("availability").style.visibility = "hidden";
	document.getElementById("availability").style.left = -500 + 'px';
	document.getElementById("availability").style.top = 0 + 'px';
	
	document.getElementById("availability_button").onclick = function(){
		Onenews(this);
	}
}

function createXMLHttpRequest(){
	try{ return new ActiveXObject("Msxml2.XMLHTTP");	} catch(e){}
	try{ return new ActiveXObject("Microsoft.XMLHTTP");	} catch(e){}
	try{ return new XMLHttpRequest();								} catch(e){}
	alert("XMLHttpRequest not supported");
	return null;
}

function availability($this){ // Click Date
	$a = document.getElementById("Bdate").value;
	$b = document.getElementById("Bnight").value;
	var xhr = createXMLHttpRequest();
	xhr.open("GET", "./availability.inc.php?action=Checkdate&a=" + $a + "&b=" + $b, true);
	xhr.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4){
			if(xhr.status == 200){
				//alert(xhr.responseText);
				$text = xhr.responseText;
				if($text == "complete"){
					location = "page_booking.php";
				}else if($text == "error"){
					alert("The selected date can not be booked.");
				}
			}
		}
	};
	xhr.send(null);
}
