	var xmlHttp;
	var endpreviousgetrate = 1;
	var editingid = 0;
	var nexteditingid = 0;
	var allrates = 0;
	var totalamount = 0;
	var rates = new Array;
	rates[0] = 0;
	rates[1] = 0;
	rates[2] = 0;
	rates[3] = 0;
	rates[4] = 0;
	function zeroamount() {
		if (totalamount == 0) {
			alert ("Please be sure that you selected Available Check in and Check out Dates.");
			return false;
		}
		else {
			return true;
		}
	}
	function challrates() {		
		if (document.getElementById("check_in").value == "" && document.getElementById("check_out").value == "") {
			alert("Select Travel Dates first please.");
			exit_comment();
		}
		else {
			allrates = 1;
			if (document.getElementById("rate0")) {
				document.getElementById("rate0").innerHTML = "wait";
				rateid = document.getElementById("room0").options[document.getElementById("room0").selectedIndex].value;
				getrate(0, rateid);
			}
		}
	}
	function getrate(formid, rateid) {
		if (document.getElementById("check_in").value == "" && document.getElementById("check_out").value == "") {
			alert("Select Travel Dates first please.");
			exit_comment();
		}
		else {
			if (endpreviousgetrate == 1) {
				endpreviousgetrate = 0;
				editingid = formid;
				document.getElementById("rate"+formid).innerHTML = "wait";
				var url="getrate.php";
				url=url+"?rateid="+rateid;
				url=url+"&checkin="+document.getElementById("check_in").value;
				url=url+"&checkout="+document.getElementById("check_out").value;
				url=url+"&sid="+Math.random();
				xmlHttp=GetXmlHttpObject(stateChanged);
				xmlHttp.open("GET", url , true);
				xmlHttp.send(null);
			}
		}
	}
	function stateChanged() {
		var rate;
		var rateid = 0;
		endpreviousgetrate = 1;
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
			if (xmlHttp.responseText != "nodates") {
				rate = xmlHttp.responseText * document.getElementById("quantity"+editingid).options[document.getElementById("quantity"+editingid).selectedIndex].value;
				rates[editingid] = rate;
				totalamount = rates[0] + rates[1] + rates[2] + rates[3] + rates[4];
				document.getElementById("rate"+editingid).innerHTML = "&euro; " + rate;
				document.getElementById("totalamount").innerHTML = "<strong>Total Amount:</strong> &euro; " + totalamount;
				if (allrates == 1) {
					nexteditingid = editingid + 1;
					if (nexteditingid <= 4) {
						if (document.getElementById("rate"+nexteditingid)) {
							document.getElementById("rate"+nexteditingid).innerHTML = "wait";
							rateid = document.getElementById("room"+nexteditingid).options[document.getElementById("room"+nexteditingid).selectedIndex].value;
							getrate(nexteditingid, rateid);
						}
						else {
							allrates = 0;
						}
					}
					else {
						allrates = 0;
					}
				}
			}
			else {
				document.getElementById("rate"+editingid).innerHTML = "&euro; 0";
			}
		}
	}
	function GetXmlHttpObject(handler) { 
		var objXmlHttp=null
		if (navigator.userAgent.indexOf("Opera")>=0) {
			alert("Error. Rate system doesn't work in Opera") 
			return  
		}
		if (navigator.userAgent.indexOf("MSIE")>=0) { 
		   var strName="Msxml2.XMLHTTP"
		   if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
			  strName="Microsoft.XMLHTTP"
		   } 
		   try { 
			  objXmlHttp=new ActiveXObject(strName)
			  objXmlHttp.onreadystatechange=handler 
			  return objXmlHttp
		   } 
		   catch(e) { 
			  alert("Error. Scripting for ActiveX might be disabled") 
			  return 
		   } 
		} 
		if (navigator.userAgent.indexOf("Mozilla")>=0) {
		   objXmlHttp=new XMLHttpRequest()
		   objXmlHttp.onload=handler
		   objXmlHttp.onerror=handler 
		   return objXmlHttp
		}
	} 
	function addroomgroup(id) {
		var oid = id-1;
		var nid = id+1;
		if (document.getElementById("roomgroup"+id) && document.getElementById("roomgroup"+id).innerHTML == "" && document.getElementById("room"+oid).options[document.getElementById("room"+oid).selectedIndex].value != 0) {
			var group = "<select id='room"+id+"' name='rooms["+id+"]' style='width:85px; font-size:10px;' onchange='addroomgroup("+nid+");' onclick=\"show_comment('{rooms}', 'room0', 'room0');\">"+window.hotel_rooms_from_php+"</select> <select id='quantity"+id+"' name='quantity["+id+"]' style='width:40px; font-size:10px;' onchange='addroomgroup("+nid+");' onclick=\"show_comment('{rooms}', 'room0', 'room0');\"><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option></select> <div id='rate"+id+"' style='display:inline; font-weight:bold; font-size:10px;'>&euro; 0<br /></div>";
			document.getElementById("roomgroup"+id).innerHTML = group;
		}
		var rateid = document.getElementById("room"+oid).options[document.getElementById("room"+oid).selectedIndex].value;
		getrate(oid, rateid);
	}
	function ifchildren() {
		if (document.getElementById("children").options[document.getElementById("children").selectedIndex].value != 0) {
			document.getElementById("childrennotice").innerHTML = "<strong>Notice: </strong>Rates may be lower that they seem, please book and we will contact to inform you if there is an offer for your children.";
		}
		else {
			document.getElementById("childrennotice").innerHTML = "";
		}
	}
	function galerie(url) {
		window.open(url, null, 'height=670,width=500,status=yes,toolbar=no,menubar=no,location=no,scrollbars=no');
		return false;
	}
	function show_comment(txt, x, y) {
		var posX = x;
		var posY = y;
		
		if (document.getElementById(x)) {
			var obj = document.getElementById(x);
			var posX = posY = 0;
			if (obj.offsetParent) {
				posX = obj.offsetLeft
				posY = obj.offsetTop
				while (obj = obj.offsetParent) {
					posX += obj.offsetLeft
					posY += obj.offsetTop
				}
			}
		}
		posX = posX - 240;
		posY = posY - 220;
		document.getElementById("comment").style.left = posX + "px";
		document.getElementById("comment").style.top = posY + "px";
		var html = "";
		if (txt == "{rooms}") {
			if (document.getElementById("check_in").value != "" && document.getElementById("check_out").value != "") {
				document.getElementById("comment").style.visibility = "visible";
				html += "<strong>Selected rooms:</strong><br />";
				if (document.getElementById("room0") && document.getElementById("room0").options[document.getElementById("room0").selectedIndex].text != "Select here") {
					html += document.getElementById("quantity0").value;
					html += " x ";
					html += document.getElementById("room0").options[document.getElementById("room0").selectedIndex].text;
					html += "<br />";
				}
				if (document.getElementById("room1") && document.getElementById("room1").options[document.getElementById("room1").selectedIndex].text != "Select here") {
					html += document.getElementById("quantity1").value;
					html += " x ";
					html += document.getElementById("room1").options[document.getElementById("room1").selectedIndex].text;
					html += "<br />";
				}
				if (document.getElementById("room2") && document.getElementById("room2").options[document.getElementById("room2").selectedIndex].text != "Select here") {
					html += document.getElementById("quantity2").value;
					html += " x ";
					html += document.getElementById("room2").options[document.getElementById("room2").selectedIndex].text;
					html += "<br />";
				}
				if (document.getElementById("room3") && document.getElementById("room3").options[document.getElementById("room3").selectedIndex].text != "Select here") {
					html += document.getElementById("quantity3").value;
					html += " x ";
					html += document.getElementById("room3").options[document.getElementById("room3").selectedIndex].text;
					html += "<br />";
				}
				if (document.getElementById("room4") && document.getElementById("room4").options[document.getElementById("room4").selectedIndex].text != "Select here") {
					html += document.getElementById("quantity4").value;
					html += " x ";
					html += document.getElementById("room4").options[document.getElementById("room4").selectedIndex].text;
					html += "<br />";
				}
				document.getElementById("comment_text").innerHTML = html;
			}
		}
		else {
			document.getElementById("comment").style.visibility = "visible";
			html += txt;
			document.getElementById("comment_text").innerHTML = html;
		}
	}
