// JavaScript Document

// function to get component cordinates
function getXCoord(el) {
	x = 0;
	while(el){
		x += el.offsetLeft;
		el = el.offsetParent;
	}
	return x;
}
function getYCoord(el) {
	y = 0;
	while(el){
		y += el.offsetTop;
		el = el.offsetParent;
	}
	return y;
}


// Get the HTTP Object

function getHTTPObject(){
if (window.ActiveXObject) 
return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) 
return new XMLHttpRequest();
else {
alert("Your browser does not support AJAX.");
return null;
}
}


// display calander in the left
function showCalendar(traverse,month,year,propid,onfunction){
httpObject = getHTTPObject();
//alert("showcalendar.php?traverse="+traverse+"&month="+month+"&year="+year+"&propid="+propid+"&divname="+divname+"&functionname=showCalendar");
if (httpObject != null) {
httpObject.open("GET", "showcalendar.php?traverse="+traverse+"&month="+month+"&year="+year+"&propid="+propid+"&onfunction="+onfunction+"&functionname=showCalendar", true);
httpObject.send(null);

httpObject.onreadystatechange = setCalendar;
}
}

function setCalendar(){
if(httpObject.readyState == 4){
document.getElementById('calshow').innerHTML = httpObject.responseText;
//alert(httpObject.responseText);
}
}


//display  calander to select from date

function showfromCalendar(traverse,month,year,propid,onfunction){
httpObject1 = getHTTPObject();
if (httpObject1 != null) {
httpObject1.open("GET", "showcalendar.php?traverse="+traverse+"&month="+month+"&year="+year+"&propid="+propid+"&onfunction="+onfunction+"&functionname=showfromCalendar", true);
//alert("showcalendar.php?traverse="+traverse+"&month="+month+"&year="+year+"&propid="+propid+"&divname="+divname);
httpObject1.send(null);
httpObject1.onreadystatechange = setfromCalendar;
}
}

function setfromCalendar(){
if(httpObject1.readyState == 4){
document.getElementById('bookfromdisplay').innerHTML = httpObject1.responseText;
//alert(httpObject.responseText);
}
}

function setfromDate(fromdate){
	document.getElementById('checkin').value=fromdate;
	divinfo=document.getElementById('bookfromdisplay');
	divinfo.style["display"]="none";
    divinfo.style["visibility"]="hidden";
	
}

//display calander for to date

function showtoCalendar(traverse,month,year,propid,onfunction){
httpObject2 = getHTTPObject();
if (httpObject2 != null) {
httpObject2.open("GET", "showcalendar.php?traverse="+traverse+"&month="+month+"&year="+year+"&propid="+propid+"&onfunction="+onfunction+"&functionname=showtoCalendar", true);
//alert("showcalendar.php?traverse="+traverse+"&month="+month+"&year="+year+"&propid="+propid+"&divname="+divname);
httpObject2.send(null);
httpObject2.onreadystatechange = settoCalendar;
}
}

function settoCalendar(){
if(httpObject2.readyState == 4){
document.getElementById('booktodisplay').innerHTML = httpObject2.responseText;
//alert(httpObject.responseText);
}
}

function settoDate(todate){
	document.getElementById('checkout').value=todate;
	divinfo=document.getElementById('booktodisplay');
	divinfo.style["display"]="none";
    divinfo.style["visibility"]="hidden";
	
}



// function to display div for selection

function showInputCal(inputid,displayid){
 poselement=document.getElementById(inputid);
 posleft=getXCoord(poselement);
// posleft+=parseInt(poselement.style.width)+10;
 postop=getYCoord(poselement);
 //alert('left: '+posleft+' top: '+postop);
 divinfo=document.getElementById(displayid);
 divinfo.style["display"]="block";
 divinfo.style["visibility"]="visible";
 divinfo.style["border"]="1px solid #000000";
 divinfo.style["left"]=posleft+"px";
 divinfo.style["top"]=postop+"px";
}

