/* 
 * HOTEL BOOKING PLUGIN - the easy way to integrate hotel booking into your website -
 * Copyright (c) 2010 travelseller GmbH
 * 
*/

var tshotel_hotelid = "60249";
var tshotel_hotelname = "Batschari Suite Hotel";
var tshotel_url = "https://hotel.travelseller.net/booking/booking_room_singlestep.x4";
var tb_pathToImage = "/style/loadingAnimation.gif";

$(document).ready(function(){   
	tshotel_init('a.tshotel, area.tshotel, input.tshotel'); //pass where to apply tshotel
}); 

function tshotel_init(fields) {
	$(fields).click(function(){
		// determine startdate field
		var outDate="";
		var outNights="";
		var outLang="";
		var url=tshotel_url + "?hotelid=" + tshotel_hotelid;
		if (this.getAttribute("datefield")!=undefined) {
			try // eval date
			{
				var givenDate=document.getElementById(this.getAttribute("datefield")).value;
				var re = /\b(\d{1,2})[\.](\d{1,2})[\.](\d{4})\b/;
				if (re.test(givenDate)) 
				{ 
					var match=re.exec(givenDate);
					outDate=match[3] + match[2] + match[1];
				}
			} catch(e) {}
		}
		if (this.getAttribute("numnightsfield")!=undefined) {
			try // eval numnights
			{
				numNightsObj=document.getElementById(this.getAttribute("numnightsfield"));
				outNights=numNightsObj.options[numNightsObj.selectedIndex].value;
			}
			catch(e)  {}
		}
		if (this.getAttribute("lang")!=undefined) {
			try // eval numnights
			{
				outLang=document.getElementById(this.getAttribute("lang")).value.toLowerCase();
			}
			catch(e)  {}
		}
		if (outDate!="") url+="&fromdate=" + outDate;
		if (outNights!="") url+="&numnights=" +outNights;
		if (outLang!="") url+="&lang=" +outLang;

		// für die thickbox notwendig
		url+="&hidetitle=1&TB_iframe=true&height=500&width=600";
		
		tb_show("Zimmerbuchung im " + tshotel_hotelname,url,false);
		this.blur();
	return false;
	}); 
}
