// JavaScript Document
var chkHotelId = 0

function lCount(type,id) {
	switch (type)
	{
	case 'area':
		url = "/cgi-bin/hitCount.asp?id=" + id;
		request.open("GET", url, true);
		request.send(null);
	  break
	case 'hotel':
		if (chkHotelId!=id){
			chkHotelId=id;
			url = "/cgi-bin/hitCount2.asp?id=" + id;
			request.open("GET", url, true);
			request.send(null);
		}
	  break
	case 'banner':
		url = "/cgi-bin/hitCount3.asp?id=" + id;
		request.open("GET", url, true);
		request.send(null);
	  break
	}
	CloseMail();
}

/*function hcBookingCount(id) {
	url = "/cgi-bin/hcBookingCount.asp?id=" + id;
	request.open("GET", url, true);
	request.send(null);
}*/

function hcBookingCount(hf, id, item, n, lng, cookieEnabled, hcCheckIn, hcCheckOut, hcGuests, hcRooms) {
	document.getElementById("hcAccommodationID").value = id;
	document.getElementById("hcHF").value = hf;
	if (cookieEnabled == "True") {
		hcSearch(lng, hcCheckIn, hcCheckOut, hcGuests, hcRooms, cookieEnabled);
	} else {
		var winScroll = window.pageYOffset;
		if (isNaN(winScroll)) {
			winScroll = document.documentElement.scrollTop;
		}
		var winHeight = window.innerHeight ;
		if (isNaN(winHeight)) {
			winHeight = document.documentElement.clientHeight;
		}
		document.getElementById("divDarkBody").style.height = document.body.clientHeight + "px";
		document.getElementById("divDarkBody").style.visibility = "visible";
		document.getElementById("divDarkBody").style.display = "block";
		document.getElementById("divGetHC").style.visibility = "visible";
		document.getElementById("divGetHC").style.display = "block";
		document.getElementById("divGetHC").style.marginTop = winScroll + ((winHeight - 200)/2) + "px";
	}
}

function closeHCSearch() {
	document.getElementById("divDarkBody").style.visibility = "hidden";
	document.getElementById("divDarkBody").style.display = "none";
	document.getElementById("divGetHC").style.visibility = "hidden";
	document.getElementById("divGetHC").style.display = "none";
}

function hcSearch(lng, hcCheckIn, hcCheckOut, hcGuests, hcRooms, cookieEnabled) {
	var id = document.getElementById("hcAccommodationID").value;
	if (cookieEnabled == "False") {
		hcCheckIn = dateToYYYYMMDD(document.getElementById("hcCheckInDate").value);
		hcCheckOut = dateToYYYYMMDD(document.getElementById("hcCheckOutDate").value);
		hcGuests = document.getElementById("hcGuests").value;
		hcRooms = document.getElementById("hcRooms").value
	}
	
	var hcURL = "http://www.booking.greekhotels.gr/SearchedHotel.aspx?fileName=" + document.getElementById("hcHF").value
		+ "&checkin=" + hcCheckIn + "&checkout=" + hcCheckOut 
		+ "&Adults=" + hcGuests + "&Rooms=" + hcRooms + "&tabId=Overview&languageCode=" + lng + "&currencyCode=EUR&returnPath=";
	//alert(hcURL);	
	url = "/cgi-bin/hcBookingCount.asp?id=" + id + "&cookieEnabled=" + cookieEnabled + "&checkin=" + hcCheckIn + "&checkout=" + hcCheckOut 
		+ "&adults=" + hcGuests + "&rooms=" + hcRooms;
	request.open("GET", url, true);
	request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
	request.onreadystatechange = function(){updateHCCount()};
	request.send(null);
	closeHCSearch();
	window.open(hcURL, "_blank");
	/*url = "/cgi-bin/hcBookingCount.asp?id=" + id;
	request.open("GET", url, true);
	request.send(null);*/
}

function updateHCCount() {
	if (request.readyState == 4) {
	 	if (request.status == 200) {
	   		var response = request.responseText;
			if (response == "") {
				alert("Resort with this code not found!");
			} else if (response == "False") {
				window.location.reload();
			}
			document.body.style.cursor = "default";
	 	} else if (request.status == 404) {
			document.body.style.cursor = "default";
			alert("Unexpected error occured!");
		} else if (request.status == 500) {
			document.body.style.cursor = "default";
			alert("A connection with the server could not be established! Try again later.");
		} else {
			document.body.style.cursor = "default";
			alert("Error occured. Login failed."); 
		} 
    }
}

function dateToYYYYMMDD(date) {
	if (date.length == 10) {
		//alert(date.substring(6, 10) + "-" + date.substring(0, 2) + "-" + date.substring(3, 5));
		return date.substring(6, 10) + "-" + date.substring(0, 2) + "-" + date.substring(3, 5);
	} else {
		return "";
	}
}

//http://www.booking.greekhotels.gr/SearchProgress.aspx?fileName=Gazi&languageCode=EN&currencyCode=EUR&checkin=2010-12-22&checkout=2010-12-30&Adults=1&Rooms=1&HotelID=1392473&redirect=1

function cursorToPointer()
{
	document.body.style.cursor = "pointer";
}

function cursorToDefault()
{
	document.body.style.cursor = "default";
}
