//Show Details in Light Box
var xLoading="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='/images/loading.gif' /><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Loading...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
var DIV_EDIT_AREA;
function closex(){
	document.getElementById("EditArea").removeChild(DIV_EDIT_AREA);
	document.getElementById("EditArea").style.display='none';
	document.getElementById("hoverbox").style.display='none';
	//document.body.className="enable-scroll-bars";
}
function getTop(){
	if(window.innerHeight)
	return window.pageYOffset;
	
	if(document.documentElement && document.documentElement.scrollTop)
	return document.documentElement.scrollTop;
	
	if(document.body)
	return document.body.scrollTop;
}	
function ShowEditArea(html,left,top){
	
	DIV_EDIT_AREA=document.createElement('DIV');
	DIV_EDIT_AREA.innerHTML=html;
	document.getElementById("EditArea").innerHTML="<div align='right'><strong onclick='closex()' style='cursor:pointer' title='Close'>X</strong>&nbsp;</div>";
	document.getElementById("EditArea").appendChild(DIV_EDIT_AREA);
	document.getElementById("EditArea").style.left = (window.screen.width/2 - left)+"px";
	document.getElementById("EditArea").style.top = (getTop()+top)+"px";
	document.getElementById("EditArea").style.display='block';
	//$("#EditArea:hidden:first").fadeIn("slow");

	//document.getElementById("EditArea").style.display='block';
	//document.body.className="disable-scroll-bars";
	//document.getElementById("hoverbox").style.display="block";
	//$("#hoverbox:hidden:first").fadeIn("slow");
	heightwidth=getPageSizeWithScroll();
	document.getElementById("hoverbox").style.display='block';
	document.getElementById("hoverbox").style.width=heightwidth[0]+20;
	document.getElementById("hoverbox").style.height=heightwidth[1]+40;
}
function getPageSizeWithScroll(){
	 if (window.innerHeight && window.scrollMaxY) {// Firefox
		 yWithScroll = window.innerHeight + window.scrollMaxY;
		 xWithScroll = window.innerWidth + window.scrollMaxX;
	 }
	 else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		 yWithScroll = document.body.scrollHeight;
		 xWithScroll = document.body.scrollWidth;
	 } 
	 else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		 yWithScroll = document.body.offsetHeight;
		 xWithScroll = document.body.offsetWidth;
	 }
	 arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	 //alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	 return arrayPageSizeWithScroll; 
}
//End

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

var map;
var myPano;   
var panoClient;
var nextPanoId;

function initialize(late,long) {
  var fenwayPark = new GLatLng(late,long);
  var fenwayPOV = {yaw:370.64659986187695,pitch:-20};
  
  panoClient = new GStreetviewClient();      
  
  map = new GMap2(document.getElementById("map_canvas"));
  map.setCenter(fenwayPark, 12);
  //var customUI = map.getDefaultUI();
        // Remove MapType.G_HYBRID_MAP
  //customUI.maptypes.hybrid = false;
  //map.setUI(customUI);
  map.setUIToDefault();
  //map.addControl(new GLargeMapControl());

  GEvent.addListener(map, "click", function(overlay,latlng) {
	panoClient.getNearestPanorama(latlng, showPanoData);
  });
  
  myPano = new GStreetviewPanorama(document.getElementById("pano"));
  myPano.setLocationAndPOV(fenwayPark, fenwayPOV);
  GEvent.addListener(myPano, "error", handleNoFlash);  
  panoClient.getNearestPanorama(fenwayPark, showPanoData);

window.onload=function(){window.onload;map.checkResize()} 
}


function handleNoFlash(errorCode) {
  if (errorCode == 603) {
	alert("Error: Flash doesn't appear to be supported by your browser");
	return;
  }
}  

function tabview(e) // components/zoo/templates/hotel/item.php
{
	document.getElementById('tab1').style.borderBottom="1px solid #000";
	document.getElementById('tab2').style.borderBottom="1px solid #000";
	document.getElementById('tab3').style.borderBottom="1px solid #000";
	document.getElementById('tab4').style.borderBottom="1px solid #000";
	document.getElementById('tab5').style.borderBottom="1px solid #000";
	
	document.getElementById('tab1').style.backgroundColor="#0C85FF";
	document.getElementById('tab2').style.backgroundColor="#0C85FF";
	document.getElementById('tab3').style.backgroundColor="#0C85FF";
	document.getElementById('tab4').style.backgroundColor="#0C85FF";
	document.getElementById('tab5').style.backgroundColor="#0C85FF";
	
	document.getElementById('tab1').style.color="#FFF";
	document.getElementById('tab2').style.color="#FFF";
	document.getElementById('tab3').style.color="#FFF";
	document.getElementById('tab4').style.color="#FFF";
	document.getElementById('tab5').style.color="#FFF";
	
	document.getElementById('tab1_detail').style.display="none";
	document.getElementById('tab2_detail').style.display="none";
	document.getElementById('tab3_detail').style.display="none";
	document.getElementById('tab4_detail').style.display="none";
	document.getElementById('tab5_detail').style.display="none";
	
	e.style.borderBottom="0px";	
	
	e.style.backgroundColor="#FFF";
	
	e.style.color="#000";
	
	document.getElementById(e.id+'_detail').style.display="block";
}

var req = createXMLHttpRequest();  
var req_captcha = createXMLHttpRequest();  
   
function createXMLHttpRequest() {  
	var ua;  
	if(window.XMLHttpRequest) {  
		try {  
			ua = new XMLHttpRequest();  
		} catch(e) {  
			ua = false;  
		}  
	} else if(window.ActiveXObject) {  
		try {  
			ua = new ActiveXObject("Microsoft.XMLHTTP");  
		} catch(e) {  
			ua = false;  
		}  
	}  
	return ua;  
}  
   
function showAvailability(sdate,nights,hotelid) {  
	ShowEditArea(xLoading,50,230);
	
	req.open('GET','/availability.php?sdate='+sdate+'&nights='+nights+'&hotelid='+hotelid);  
	req.onreadystatechange = handleResponse;  
	req.send(null);  	
	return false;  
}  
function handleResponse() {  
	if(req.readyState == 4){  
		var response = req.responseText;  
		closex();
		document.getElementById('ServiceData').innerHTML = response;  
	}  
}

function getHotels(city_id) {
	req.open('GET','/get_hotels.php?city_id='+city_id);  
	req.onreadystatechange = handleResponse_getHotels;  
	req.send(null);  
	
	return false;  
}
function handleResponse_getHotels() {  
	if(req.readyState == 4){  
		var response = req.responseText;  
		document.getElementById('cmbHotel').innerHTML = response;  
	}  
}

function checkVerification(val)
{
	req.open('GET','/captchacheck.php?captcha='+val);
	req.onreadystatechange = handleResponse_captcha;
	req.send(null);	
	return false;
}
function handleResponse_captcha() {  
	if(req.readyState == 4){  
		var response = req.responseText;  
		if(response=="Correct")
		{	
			document.getElementById('enquiry_item').submit();
		}
		else
		{
			alert("Verification Code Incorrect...");
		}
	}  
}

function getAvailability()
{
	var one_day=1000*60*60*24;
	fromDate=document.getElementById('checkinValue');
	toDate=document.getElementById('checkoutValue');
	var firstDate = new Date(fromDate.value.substr(0,4), fromDate.value.substr(5,2)-1, fromDate.value.substr(8,2))
	var secondDate = new Date(toDate.value.substr(0,4), toDate.value.substr(5,2)-1, toDate.value.substr(8,2))
	//Calculate difference btw the two dates, and convert to days
	var nights=(Math.ceil((secondDate.getTime()-firstDate.getTime())/(one_day))+1);

	showAvailability(document.getElementById('checkinValue').value,nights,document.getElementById('hotelid').value);
	return false;
}
