// JavaScript Document

var request = false;
try {
  request = new XMLHttpRequest();
} catch (trymicrosoft) {
  try {
    request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
    try {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed) {
      request = false;
    }
  }
}

if (!request)
  alert("Error initializing XMLHttpRequest!");
 
 function renewRequest()
{
	var request = false;
	try {
	  request = new XMLHttpRequest();
	} catch (trymicrosoft) {
	  try {
		request = new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (othermicrosoft) {
		try {
		  request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (failed) {
		  request = false;
		}
	  }
	}
	return request;
}
//window.onerror = hotelSearch(1);

var newValue;
newValue = '';

function setLocationSearch() {
	document.getElementById("txtHotelName").value = "[Enter Location Name]"
	document.getElementById("searchinfoHelp").innerHTML = "<strong>Find your location.</strong><br/>Type the name, select from the list and click go.";
	document.getElementById("rsHotelName").checked = false;
	closeSearch();
	newValue = '';

}

function setHotelNameSearch() {
	document.getElementById("txtHotelName").value = "[Enter Hotel Name]";
	document.getElementById("searchinfoHelp").innerHTML = "<strong>Find your hotel.</strong><br/>Type the name, select from the list and click go.";
	document.getElementById("rsLocation").checked = false;
	closeSearch();
	newValue = '';

}

function setLocationSearchGR() {
	document.getElementById("txtHotelName").value = "[Όνομα Περιοχής]"
	document.getElementById("searchinfoHelp").innerHTML = "<b>Γρήγορη Αναζήτηση</b><br />Γράψτε και επιλέξτε το όνομα Περιοχής και πιέστε GO.";
	document.getElementById("rsHotelName").checked = false;
	closeSearch();
	newValue = '';

}

function setHotelNameSearchGR() {
	document.getElementById("txtHotelName").value = "[Όνομα Ξενοδοχείου]";
	document.getElementById("searchinfoHelp").innerHTML = "<b>Γρήγορη Αναζήτηση</b><br />Γράψτε και επιλέξτε το όνομα του Ξενοδοχείου και πιέστε GO.";
	document.getElementById("rsLocation").checked = false;
	closeSearch();
	newValue = '';

}

function setValue(srchbox) {
	if (newValue!=undefined){
		srchbox.value = newValue;}
	else{
		srchbox.value = "";}
	document.frmNameSearch.txtLocationid.value="0";
}

function hotelSearch(obj) {
	//if (request.readyState == 4|| request.readyState==0){
		document.getElementById("dropbox").style.visibility = "hidden";
		document.body.style.cursor = "wait";
		request.abort();
		request = renewRequest();
		newValue = obj.value;
		if (newValue == "")
			document.body.style.cursor = "default";
		queryStr = escape(obj.value);
		if (document.getElementById("rsLocation").checked) {
			url = "/cgi-bin/locationSrch.asp?locname=" + queryStr;						
		} else {
			url = "/cgi-bin/hotelSrch.asp?hotelname=" + queryStr;
		}
		request.open("GET", url, true);
		request.onreadystatechange = updatePage;
		request.send(null);
	//}
}
function hotelSearchGR(obj) {
		document.getElementById("dropbox").style.visibility = "hidden";
		document.body.style.cursor = "wait";
		request.abort();
		request = renewRequest();
		newValue = obj.value;
		if (newValue == "")
			document.body.style.cursor = "default";
		queryStr = escape(obj.value);
		if (document.getElementById("rsLocation").checked) {
			url = "/cgi-bin/gr/locationSrch.asp?locname=" + queryStr;						
		} else {
			url = "/cgi-bin/gr/hotelSrch.asp?hotelname=" + queryStr;
		}
		request.open("GET", url, true);
		request.onreadystatechange = updatePage;
		request.send(null);
}

function updatePage() {	
	if (request.readyState == 4)
    	{
		if (request.status == 200)
			{
			var response = request.responseText;
			if (response!="")
				{
				document.getElementById("dropbox").innerHTML = response;
				document.getElementById("dropbox").style.visibility = "visible";
				document.body.style.cursor = "default";
				}
			else{document.getElementById("dropbox").style.visibility = "hidden";}
			}
    	else if (request.status == 404)
			{
				alert("Page Does Not Exist!");
			}
		else
			{/*alert("Error: status code is " + request.status);*/
			document.getElementById("dropbox").style.visibility = "hidden";}
		}
}

function fillSearch(str,lvl4id){
	document.frmNameSearch.txtHotelName.value=str;
	document.frmNameSearch.txtLocationid.value=lvl4id;
	newValue=str;
	//hotelSearch(document.frmNameSearch.txtHotelName);
	closeSearch();
}

function nullCheck(objValue){
	if (objValue==""||objValue.indexOf("[")!=-1){
		var response;
		response = "<div style=\"float:right;padding-top:3px;cursor:pointer;\"><img src=\"/images/close_box.gif\" alt=\"close\" onclick=\"closeSearch()\" /></div>";
		if (document.getElementById("rsHotelName").checked) {
			response = response + "<br /><p><strong>Please enter a hotel name in the search box</strong></p><br />&nbsp;";
		} else {
			response = response + "<br /><p><strong>Please enter a location name in the search box</strong></p><br />&nbsp;";
		}
		document.getElementById("dropbox").innerHTML = response;
		document.getElementById("dropbox").style.visibility = "visible";
		return false;
	} else {
		return true;
	}
}

function submitSearchForm() {
	var objValue = document.frmNameSearch.txtHotelName.value;
	if (document.getElementById("rsHotelName").checked) {
		if (objValue==""||objValue.indexOf("[")!=-1){
			var response;
			response = "<div style=\"float:right;padding-top:3px;cursor:pointer;\"><img src=\"/images/close_box.gif\" alt=\"close\" onclick=\"closeSearch()\" /></div>";
			response = response + "<br /><p><strong>Please enter a hotel name in the search box</strong></p><br />&nbsp;";
			document.getElementById("dropbox").innerHTML = response;
			document.getElementById("dropbox").style.visibility = "visible";
			return false;
		}
   		document.frmNameSearch.submit();
	} else {
		if (objValue==""||objValue.indexOf("[")!=-1){
			var response;
			response = "<div style=\"float:right;padding-top:3px;cursor:pointer;\"><img src=\"/images/close_box.gif\" alt=\"close\" onclick=\"closeSearch()\" /></div>";
			response = response + "<br /><p><strong>Please enter a location name in the search box</strong></p><br />&nbsp;";
			document.getElementById("dropbox").innerHTML = response;
			document.getElementById("dropbox").style.visibility = "visible";
			return false;
		}
		window.location.href = document.frmNameSearch.txtLocationid.value;
	}
}

function closeSearch(){
	document.getElementById("dropbox").style.visibility = "hidden";
}

function submitSearch(){
	window.location="/cgi-bin/search.asp?lvl4id=" + document.frmNameSearch.txtLocationid.value + "&hotelname=" + document.frmNameSearch.txtHotelName.value;
}