/** ajax functions **/

function wheelAnimate()
{
	return "<center><div><img src='"+_sys_url_static2+"images/loading1.gif'/></div></center>";
}

 
function createXMLHttpRequest() {  
 var ua; 
try {  
		ua = new ActiveXObject("Microsoft.XMLHTTP"); 
	}
catch (e) 
    {  
		try 
		{  
			ua = new ActiveXObject('Msxml2.XMLHTTP');   
		} 
		catch(e) 
		{  
			try
			{
				ua = new XMLHttpRequest();  
			}
			catch(e)
			{
				ua = null;
			}
		}  
	}  
return ua;  
}  
var ajaxTimeout = null;
function sendRequest(req,type,file , data , func ,timeoutfunc) {  
	var rnd982g = Math.random();  
	var str = "";  
	if(typeof(timeoutfunc) != "undefined")
	{
		ajaxTimeout = setTimeout(timeoutfunc , 10000);
	}
	req.open(type, file+'?'+data+'&rnd982g='+rnd982g,true);  
	if(type == "POST")
	{
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
		req.onreadystatechange = func;  
		req.send(data);  	
	}
	else
	{
		req.onreadystatechange = func; 
		req.send(null);  
	}
	return false;  
}  
  
/** handles all search operations on the server of the top search form **/

var url_redir = "";
function st_search() {
    this.citiesList = []; /** select the city country in the top form **/
    this.selectCountryCity = function (city_id, country_id) {
        var country_found = false;
        $("#dCountry option").each(function () {
            if ($(this).val() == country_id) {
                $(this).attr("selected", "selected");
                country_found = true;
            }
        });
        if (country_found == true) {
            this.countryChange(country_id, city_id);
        }
        var browserName = navigator.appName;
        if (browserName == "Microsoft Internet Explorer") {
            if (parseFloat(navigator.appVersion.split("MSIE")[1]) <= 7) {
                $("#dCountry").css("display", "");
                $("#dCity").css("display", "");
                $("#dDateD").css("display", "");
                $("#dDateM").css("display", "");
                $("#dDateY").css("display", "");
                $("#dNights").css("display", "");
                $("#box").hide("fast");
            }
        }
    } /** search for the city , country (property to be implemented) **/
    this.search = function () {
        var content = $("#text_content").val();
        var s = this;
        if (content.replace(/^\s+|\s+$/g, '') != "") {
            var browserName = navigator.appName;
            if (browserName == "Microsoft Internet Explorer") {
                if (parseFloat(navigator.appVersion.split("MSIE")[1]) <= 7) {
                    $("#dCountry").css("display", "none");
                    $("#dCity").css("display", "none");
                    $("#dDay").css("display", "none");
                    $("#dMonth").css("display", "none");
                    $("#dYear").css("display", "none");
                    $("#dNights").css("display", "none");
                }
            }
			var req = createXMLHttpRequest(); 
			if(req != null)
			{
			sendRequest(req,"GET","script/script_page.php","lang=" + _sys_lang + "&content=" + escape(content),function () {
			 if(req.readyState == 4){  
				clearTimeout(ajaxTimeout);
				var data = req.responseText;  
				var list = eval('([' + data + '])');
                var x = $("#box");
                $("#box").html("");
                if (list.length > 0) {
                    for (var m in list) {
                        var first_str = list[m].t.substring(0, list[m].t.indexOf(content) + content.length + 1);
                        var second_str = list[m].t.substring(list[m].t.indexOf(content) + content.length + 1, list[m].t.length);
                        $("#box").append('<a href=\'javascript:selectCityCountry("' + list[m].id + '","' + list[m].cid + '")\'><span class="sel">' + first_str + '</span>' + second_str + ' , ' + list[m].c + '</a>');
                    }
                    $("#box").show("fast");
                }
				}},function(){req.abort();});
			}
			else
			{
				showMsg(search_trans["ajax_error_text"]);
			}
        } else {
            $("#box").hide("fast");
        }
    } /** change the country in the top form **/
    this.countryChange = function (id, sel) {
	
        this.getCityObject(_sys_url + "script/cities.php","lang=" + _sys_lang + "&country_id=" + id +"&rand=" + Math.random(), sel);
    } /** get the cities by ajax **/
    this.getCityObject = function (url,param, sel) {
        var s = this;
        $('#dCity').html("<option value='-1'>"+search_trans["loading_cities_msg"]+"</option>");
        $("#dCity").attr('disabled', 'disabled');
		var req = createXMLHttpRequest(); 
		if(req != null)
		{
			sendRequest(req,"GET",url,param,function () {
			 if(req.readyState == 4){  
				var data = req.responseText; 				
				eval(data);
				s.generateCity(city_obj, top_city_obj, sel);
				}},function(){
					req.abort();
					//alert("retrying");
					this.getCityObject(url,param, sel);
				});
		}
		else
		{
			showMsg(search_trans["ajax_error_text"]);
		}
    } 
	/** generate the city select element **/
    this.generateCity = function (json, json2, sel) {
		clearTimeout(ajaxTimeout);
        var obj = $("#dCity");
        obj.find('option').remove();
		var browserName = navigator.appName;
		var x = "";
        if (json2) {
            x = "<optgroup label=\""+search_trans["title_o_top"] +"\">"; /*obj.options[obj.options.length] = new Option( '-- TOP DESTINATIONS', 0 ); */
            for (i = 0; i < json2.length; i++) {
                x +="<option value='" + json2[i].u + "'>" + json2[i].t + "</option>";
            }
            x += "</optgroup>"; /*$('#dCity').append("<optgroup>");*/
            /*obj.options[obj.options.length] = new Option( '-- ALPHABETICAL LIST', 0 );*/
        }
		var y = x + "<optgroup label=\""+search_trans["title_o_alpha"]+"\">";
        for (i = 0; i < json.length; i++) {
            if (sel != '' && sel == json[i].u) {
                y += "<option value='" + json[i].u + "' selected='selected'>" + json[i].t + "</option>";
            } else {
                y += "<option value='" + json[i].u + "'>" + json[i].t + "</option>";
            }
        }
        y += "</optgroup>";
		if(browserName == "Microsoft Internet Explorer")
		{
			document.getElementById("dCity").outerHTML = "<select id='dCity'>"+y+"</select>";
		}
		else
		{
			document.getElementById("dCity").innerHTML = y;
		}
        $("#dCity").attr('disabled', '');
    }
    this.checkFormValues = function () {
        if ($("#dCountry option:selected").val() == 0 || $("#dCountry option:selected").val() == -1) {
            return -1;
        }
        if ($("#dCity option:selected").val() == 0 || $("#dCity option:selected").val() == -1) {
            return -2;
        }
        var year = parseInt($("#dDateY option:selected").val(),10);
        var month = parseInt($("#dDateM option:selected").val(),10);
        var day = parseInt($("#dDateD option:selected").val(),10);
        var d = new Date(year, month - 1, day + 1);
        var today = new Date();
        if (today <= d) {
            return true;
        } else {
            return -3;
        }
    }
    this.startSearching = function () {
        var city = $('#dCity option:selected').val();
        var country = $('#dCountry option:selected').val();
        var year = parseInt($("#dDateY option:selected").val(),10);
        var month = parseInt($("#dDateM option:selected").val(),10);
        var day = parseInt($("#dDateD option:selected").val(),10);
        var nights = parseInt($("#dNights option:selected").val(),10);
        if (this.checkFormValues() == true) {
            url_redir = _sys_url + _sys_lang + "/" + country + "/" + city + "/search-index.html?d=" + year + "-" + month + "-" + day + "-" + nights;
            //window.location = url;
			trackit('left search form action', '16 - click on search button', city + ", " + country + ", for " + nights + " night/s");
			redirect();
            return url;
        } else if (this.checkFormValues() < 0) {
            if (this.checkFormValues() == -1)
			{ alert("no country selected");} 
			else if (this.checkFormValues() == -2) 
			{ alert("no city selected");} 
			else if (this.checkFormValues() == -3) 
			{ alert("Invalid date selected");}
        }
    }

}

window.st_search = new st_search(); /** all the property values and functions are executed here **/
function redirect()
{
	try
	{
		setTimeout( "window.location.href = url_redir", 0 );
		
	}
	catch(e)
	{
	}	
}

function st_property(JSON, isMap) { /*property basic info*/
    this.id = -1;
    this.title = "";
    this.address = "";
    this.language = "en";
    this.thumbnail = "";
    this.city = "";
    this.country = "";
    this.url = "";
	this.category = "";
	this.category_url = "";
    this.json_info = JSON;
    this.rating = -1;
    this.price_private = 0;
    this.price_shared = 0;
    this.available = false; /*map parameters*/
    this.map_latitude = 0;
    this.map_longitude = 0;
    this.map_title = "";
    this.description = "";
    this.reviews = "";
    this.ismap = false;
    this.track = true; /** check if this property is valid or just for map **/
	this.rate_min = "";
	this.rate_max = "";
	this.rate_people = 1;
	this.rooms_json = false;
	this.is_available = false;
    if (typeof(isMap) == "undefined") {
        this.ismap = false;
    } else {
        this.ismap = isMap;
    } /** show the map of this property **/
    this.showMap = function () {
        var obj = document.getElementById('gMap');
        var browserName = navigator.appName;
        if (browserName == "Microsoft Internet Explorer") {
            obj.style.position = "absolute";
            obj.style.top = ($(window).scrollTop() + 100) + "px";
            obj.style.left = "110px";
        } else {
            obj.style.position = "fixed";
            obj.style.top = '130px';
            z = ((screen.width / 2) - 400);
            obj.style.left = z + "px";
        }
        obj.style.display = 'block';
        if (GBrowserIsCompatible()) {
            var zoom = 16;
            var map = new GMap2(document.getElementById("map"));
            map.setMapType(G_NORMAL_MAP);
            var point = new GLatLng(this.map_latitude, this.map_longitude);
            map.setCenter(point, zoom);
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            var mainIcon = new GIcon();
            mainIcon.image = "images/map_mainIcon_big.png";
            mainIcon.shadow = "images/map_mainIconShadow.png";
            mainIcon.iconSize = new GSize(22, 26);
            mainIcon.shadowSize = new GSize(0, 0);
            mainIcon.iconAnchor = new GPoint(20, 20);
            mainIcon.infoWindowAnchor = new GPoint(20, 20);
            markerOptions1 = {
                icon: mainIcon
            };
            var tinyIcon = new GIcon();
            tinyIcon.image = "images/map_tinyIcon.png";
            tinyIcon.shadow = "images/map_tinyIconShadow.png";
            tinyIcon.iconSize = new GSize(17, 20);
            tinyIcon.shadowSize = new GSize(0, 0);
            tinyIcon.iconAnchor = new GPoint(15, 15);
            tinyIcon.infoWindowAnchor = new GPoint(15, 15);
            markerOptions2 = {
                icon: tinyIcon
            };
            if (this.url != "") { /*var point = new GLatLng(this.map_latitude, this.map_longitude);*/
                map.addOverlay(createMarker(map, point, this, markerOptions1));
            }
        }
    } /** get the property description **/
    this.getDescription = function () { /** to be implemented if needed (get the property description) **/
    } /** get the property reviews **/
    this.getReviews = function () { /** to be implemented if needed (get the property reviews) **/
    } 

	/** load the property from json **/
    this.load = function () {
        var info = eval(this.json_info);
        if (info != null) {
            if (this.ismap == false) {
                this.id = info.id;
                this.address = info.address;
                this.title = info.title;
                this.city = info.city;
                this.country = info.country;
                this.thumbnail = info.thumbnail;
				this.description = info.description;
                this.map_latitude = info.latitude;
                this.map_longitude = info.longitude;
                this.url = info.url;
                this.map_title = info.map_title;
                this.rating = info.rating;
                this.price_private = info.price_private;
                this.price_shared = info.price_shared;
				this.category = info.category;
				this.category_url = info.category_url;
				this.rate_min = info.rate_min;
				this.rate_max = info.rate_max;
				this.rate_people = info.rate_people;
                if (this.map_latitude.trim() == "") {
                    var sm = this;
                    var geocoder = new GClientGeocoder();
                    geocoder.getLatLng(this.address+ " , " +this.city +" , "+ this.country, function (pt) {
						if(pt != null && typeof(pt) != 'undefined')
						{
							sm.map_latitude = pt.lat();
							sm.map_longitude = pt.lng();
						}
                    });
                }
            } else if (this.ismap == true) {
                var did = new Date();
                this.id = did.getTime();
                this.address = info.a;
                this.title = info.t;
                this.city = "";
                this.country = "";
                this.thumbnail = info.p;
                this.map_latitude = info.la;
                this.map_longitude = info.lo;
                this.url = info.u;
                this.map_title = info.t;
                this.rating = 0;
                this.price_private = -1;
                this.price_shared = -1;
				if (this.map_latitude.trim() == "") {
                    var sm = this;
                    var geocoder = new GClientGeocoder();
                    geocoder.getLatLng(this.address+ " , " +this.city +" , "+ this.country, function (pt) {
						if(pt != null && typeof(pt) != 'undefined')
						{
							sm.map_latitude = pt.lat();
							sm.map_longitude = pt.lng();
						}
                    });
                }
            }
        }
    }
    this.load();
} /** controlls all general operations for each property or all properties **/


function st_controller() { /** search dates and nights , curreny is set to euro **/
    this.date = new Date();
    this.date.setDate(this.date.getDate() + 1);
    this.nights = 3;
    this.currency = "EUR";
    this.language = _sys_lang;
    this.country_id = -1;
    this.city_id = -1; 
	/** alerts , can be changed for translation issues **/
    this.alert_dates = search_trans["alert_dates"];
    this.alert_rooms = search_trans["alert_rooms"]; /** remeber the avaiulability dates **/
    this.remember = false; 
	/** page we are working at , url, language , country and city if exists **/
    this.page = "listing";
    this.page_url = "";
    this.page_lang = "en";
    this.country = _sys_country;
	this.dateUpdated = false;
    this.city = _sys_city;
	/** all the loaded properties , and their length **/
    this.properties = new Array();
	this.categories = new Array();
    this.totalProperties = 0;
    this.working_property = null; 
	/** the cached properties so that we don't have to load all the properties again **/
    this.cachedProperties = null; 
	/** enable or disable animation (not yet implemented ,used for browser compatibility)**/
    this.animation_enabled = false;
	/** set the default rating range **/
    this.ratingRangeMin = 0;
    this.ratingRangeMax = 100; 
	/** set the default price private range **/
    this.pricepRangeMin = 0;
    this.pricepRangeMax = 100; 
	/** set the default price shared range **/
    this.pricesRangeMin = 0;
    this.pricesRangeMax = 100; 
	/** Search translations load **/
    this.nights_lbl = "Number Of Nights";
    this.city_lbl = "City";
    this.country_lbl = "Country";
    this.arrival_date_lbl = "Arrival Date";
	
	this.htmlProperties = [];
	this.hotelRooms =[];
	this.propertiesArray = new Array();
	this.availabilityCounter = 0;
	
	this.limitFrom = 0;
	this.limitTo = 15;
	this.shown = 0;
	this.tracked = false;
	this.availableProperties = [];
	
	this.help_book = "<div class='bill_panel'>"+search_trans["rooms_help_book"]+"</div>";
	
    this.load_translations = function () {
        if (typeof(search_trans) != "undefined") {
            if (typeof(search_trans["title_country"]) != "undefined") {
                this.country_lbl = search_trans["title_country"];
            }
            if (typeof(search_trans["title_city"]) != "undefined") {
                this.city_lbl = search_trans["title_city"];
            }
            if (typeof(search_trans["title_date_arrival"]) != "undefined") {
                this.arrival_date_lbl = search_trans["title_date_arrival"];
            }
            if (typeof(search_trans["title_nights_number"]) != "undefined") {
                this.nights_lbl = search_trans["title_nights_number"];
            }
        }
    }
    this.load_translations(); 
	/** load all the properties in to the window **/
    this.load = function () {
        var con = this;
        var count = 0;
		var hostels = 0;
		var hotels = 0;
		var babs = 0;
		var guesthouses = 0;
		var apartments = 0;
		var campings = 0;
        if (typeof(_json_properties) != "undefined") {
            for (var json_id in _json_properties) {
                var json = _json_properties[json_id];
                try {
                    var property = eval(json);
                    if (typeof(property) != 'undefined') {
						con.propertiesArray[count] = new st_property(json);
                        count++;
                        con.properties[property.id] = new st_property(json);
						if(typeof(con.properties[property.id])!="undefined")
						{
							var category = con.properties[property.id].category_url;
							if(con.properties[property.id].category_url != "")
							{
								if(category == "hostel")
								{
									hostels ++;
								}
								else if(category == "hotel")
								{
									hotels ++;
								}
								else if(category == "bed_and_breakfast")
								{
									babs ++;
								}
								else if(category == "guest_house_limited_service")
								{
									guesthouses ++;
								}
								else if(category == "apartment")
								{
									apartments ++;
								}
								else if(category == "camping")
								{
									campings ++;
								}
							}
						}
                    }
                } catch (err) {}
            }
            this.totalProperties = count;
            if (count > 1) {
				try
				{
					if(page_at == "listing" )
					{
						document.getElementById("stsearchfilter").style.display="block";
						document.getElementById("search_col_sep").style.display="block";
						var a = 0;
						if(hostels > 0)
						{
							document.getElementById("chk_hostels_lbl").style.display = "block";
							document.getElementById("chk_hostels_span").innerHTML =  hostels ;
							a++;
						}
						if(hotels > 0)
						{
							document.getElementById("chk_hotel_lbl").style.display = "block";
							document.getElementById("chk_hotel_span").innerHTML = hotels ;
							a++;
						}
						if(babs > 0)
						{
							document.getElementById("chk_babs_lbl").style.display = "block";
							document.getElementById("chk_babs_span").innerHTML = babs ;
							a++;
						}
						if(guesthouses > 0)
						{
							document.getElementById("chk_guesthouse_lbl").style.display = "block";
							document.getElementById("chk_guesthouse_span").innerHTML =  guesthouses ;
							a++;
						}
						if(apartments > 0)
						{
							document.getElementById("chk_apartment_lbl").style.display = "block";
							document.getElementById("chk_apartment_span").innerHTML =  apartments ;
							a++;
						}
						if(campings > 0)
						{
							document.getElementById("chk_camping_lbl").style.display = "block";
							document.getElementById("chk_camping_span").innerHTML = campings ;
							a++;
						}
						if(a > 1)
						{
							document.getElementById("properties_shown").style.display = "block";
						}
					}
					else if(page_at == "search")
					{
						document.getElementById("stsearchfilter").style.display="block";
						document.getElementById("search_col_sep").style.display="block";
					}
				}
				catch(e){}
            }
        }
        if ((typeof(place) != "undefined" && this.totalProperties == 0) || (typeof(_json_properties) == "undefined" && typeof(place) != "undefined")) {
            for (var json_id in place) {
                var json = place[json_id];
                try {
                    var property = eval(json);
                    if (typeof(property) != 'undefined') {
						con.propertiesArray[count] = new st_property(json, true);
                        count++;
                        con.properties[json_id] = new st_property(json, true);
                    }
                } catch (e) {}
            }
            this.totalProperties = count;
        }
    } 
	/** show the change dates form **/
    this.changeDate = function (property_id) {
        this.remember = false;
        this.showAvailabilityForm(property_id);
    } 
	/** set the date to check availability **/
    this.setDate = function (day, month, year) {
        this.date = new Date(year, month - 1, day);
        this.remember = true;
		this.updateSearchForm();
    } 
	/** set the number of nights **/
    this.setNumberOfNights = function (nights) {
        this.nights = nights;
    } 
	this.getHotelRooms = function(id , onlyrooms , hide_unavailable)
	{
		var me = this;
		me.limitFrom ++;
		var req = createXMLHttpRequest(); 
		if(req != null)
		{
			var values = "giorno=" + this.date.getDate() + "&mese=" + (this.date.getMonth() + 1) + "&anno=" + this.date.getFullYear() + "&notti=" + this.nights + "&ajax_command=ajax_hotel_avail&currency=" + this.currency + "&lang=" + this.language + "&str=" + id;
			sendRequest(req,"POST","js/ajax_avail.php",values, function () {
				if(req.readyState == 4){ 
					if(req.status == 200){
						var msg = req.responseText; 
						var hotel_json = eval('('+msg+')');
						if(typeof(hotel_json) != 'undefined')
						{
							if(typeof(hotel_json.hotel) != 'undefined')
							{
								var dmn = document.getElementById("hotel_menu_"+id);
								if(dmn != null)
								{
									dmn.style.display = "none"; 
								}
								if(parseInt(hotel_json.hotel.available,10) == 1)
								{
									me.hotelRooms[id] = hotel_json;
									
									me.showHostel(id,onlyrooms);
									me.availabilityCounter++;
									if(dmn != null)
									{
										dmn.style.display = "block"; 
									}
									if(onlyrooms ==  false)
									{
										me.updateSearchFilter(id);
										me.checkRangeAvailability();
									}
									return;
								}
								else if(parseInt(hotel_json.hotel.available,10) == 0 && hide_unavailable == false)
								{
									me.hotelRooms[id] = hotel_json;
									me.showHostel(id,onlyrooms);
									if(dmn != null)
									{
										dmn.style.display = "block";  
									}
								}
								
							}
						}
						if(onlyrooms ==  false)
						{
							me.checkRangeAvailability();
						}
						if(ajaxTimeout != null)
						{
							clearTimeout(ajaxTimeout);
							ajaxTimeout = null;
						}
					}
					else if(req.status == 404)
					{
						if(onlyrooms ==  false)
						{
							me.checkRangeAvailability();
						}
						if(ajaxTimeout != null)
						{
							clearTimeout(ajaxTimeout);
							ajaxTimeout = null;
						}
					}

				}
				
			},function(){
						req.abort();
						if(onlyrooms ==  false)
						{
							me.checkRangeAvailability();
						}
			});
		}
		else
		{
			return -1;
		}
	}
	this.getPropertyDescription = function(id)
	{
		var me = this;
		me.limitFrom ++;
		document.getElementById("desc_content_"+id).innerHTML = wheelAnimate();
		document.getElementById("desc_"+id).style.display = "block"; 
		document.getElementById("reviews_"+id).style.display = "none";
		document.getElementById("ajaxrooms_"+id).style.display = "none";
		//document.getElementById("but_ajaxrooms_"+id).style.display = "block";
		var req = createXMLHttpRequest(); 
		if(req != null)
		{
			var values = "hotel_id=" + id + "&lang=" + _sys_lang + "&type=descr";
			sendRequest(req,"GET","script/structure.php",values, function () {
				if(req.readyState == 4){ 
					if(req.status == 200){
						var msg = req.responseText; 
						var hotel_json = eval('('+msg+')');
						var pics = "";
						var desc = "";
						if(typeof(hotel_json.d) != 'undefined')
						{
							try
							{
								desc = hotel_json.d;
							}
							catch(e){}
						}
						if(typeof(hotel_json.p) != 'undefined')
						{
							if(hotel_json.p.length > 0)
							{
								for(var l=0;l<hotel_json.p.length;l++)
								{
									 pics += "<a rel=\"prettyPhoto"+id+"[gallery]\" href=\""+_sys_url_static + hotel_json.p[l].b + "\"><img width=\"80\" height=\"80\" class=\"property_img\" src=\""+_sys_url_static+ hotel_json.p[l].s + "\"></a>";
								}
							} 
						}
						var tdn = document.getElementById("hotel_menu_"+id);
						if(tdn != null)
						{
							tdn.style.display = "none"; 
						}
						//document.getElementById("desc_content_"+id).style.display = "none"; 
						//document.getElementById("desc_content_"+id).innerHTML = "<div class='prop_desc'>"  + pics + desc + "</div>";
						document.getElementById("desc_content_"+id).innerHTML =  "<div class='prop_desc'>"  + pics + desc + "<center><a href=\"javascript:availability("+id+")\" class=\"but_book\"><div class=\"but-left\"><div class=\"but-right\"><div class=\"but-middle\">"+search_trans["check_avail_label"]+"</div></div></div></a></center></div></div>";
						try
						{
							startprettyphoto(id);
						}
						catch(e)
						{
						}
						if(tdn != null)
						{
							tdn.style.display = "block"; 
						}
						//alert(newdiv.style.height);      
						  
					}
					}
				
			},function(){
						req.abort();
			});
		}
		else
		{
			return -1;
		}
	}
	this.getPropertyReviews = function(id)
	{
		var me = this;
		me.limitFrom ++;
		document.getElementById("rev_content_"+id).innerHTML = wheelAnimate();
		document.getElementById("reviews_"+id).style.display = "block";
		document.getElementById("ajaxrooms_"+id).style.display = "none";
		document.getElementById("desc_"+id).style.display = "none";
		//document.getElementById("but_ajaxrooms_"+id).style.display = "block";
		var req = createXMLHttpRequest(); 
		if(req != null)
		{
			var values = "hotel_id=" + id + "&lang=" + _sys_lang + "&type=reviews";
			sendRequest(req,"GET","script/structure.php",values, function () {
				if(req.readyState == 4){ 
					if(req.status == 200){
						var msg = req.responseText; 
						var hotel_json = eval('('+msg+')');
						if(typeof(hotel_json) != 'undefined')
						{
							document.getElementById("hotel_menu_"+id).style.display = "none"; 
							document.getElementById("rev_content_"+id).innerHTML = "";
							if(hotel_json.length > 0)
							{
								for(var i =0;i<hotel_json.length;i++)
								{
								try
								{
								document.getElementById("rev_content_"+id).innerHTML  += "<div class='rvw_box2'><h3>" +hotel_json[i].person+"</h3>";
								document.getElementById("rev_content_"+id).innerHTML  += "<p align='justify'>"+ hotel_json[i].body+"</p></div>";
								
								}
								catch(e){}
								}
								var rvurl = document.getElementById("reviews_lnk_"+id).innerHTML;
								document.getElementById("rev_content_"+id).innerHTML += "<div style='text-align:center'><br/>"+
								"<a href=\""+rvurl+"\" class=\"but_book\"><div class=\"but-left\"><div class=\"but-right\"><div class=\"but-middle\">Show more reviews for this property</div></div></div></a><center><a href=\"javascript:availability("+id+")\" class=\"but_book\"><div class=\"but-left\"><div class=\"but-right\"><div class=\"but-middle\">"+search_trans["check_avail_label"]+"</div></div></div></a></center></div>";
							}
							else
							{
								var rvurl = document.getElementById("reviews_lnk_"+id).innerHTML;
								document.getElementById("rev_content_"+id).innerHTML = "<div style='text-align:center'>There are no current reviews for this property<br/>"+
								"<a href=\""+rvurl+"\" class=\"but_book\"><div class=\"but-left\"><div class=\"but-right\"><div class=\"but-middle\">Add a review for this property</div></div></div></a><center><a href=\"javascript:availability("+id+")\" class=\"but_book\"><div class=\"but-left\"><div class=\"but-right\"><div class=\"but-middle\">"+search_trans["check_avail_label"]+"</div></div></div></a></center></div>";
							}
							document.getElementById("rev_content_"+id).style.display = "block";
							document.getElementById("hotel_menu_"+id).style.display = "block"; 
						}
					}
					}
				
			},function(){
						req.abort();
			});
		}
		else
		{
			return -1;
		}
	}
	this.updateSearchFilter = function(id)
	{
		if(page_at == "search")
		{
			try 
			{
				if(typeof(this.properties[id])!="undefined")
				{
					var category = this.properties[id].category_url;
					if(category != "")
					{
						var id = "";
						if(category == "hostel")
						{
							id = "chk_hostels";
						}
						else if(category == "hotel")
						{
							id = "chk_hotel";
						}
						else if(category == "bed_and_breakfast")
						{
							id = "chk_babs";
						}
						else if(category == "apartment")
						{
							id = "chk_apartment";
						}
						else if(category == "guest_house_limited_service")
						{
							id = "chk_guesthouse";
						}
						else if(category == "camping")
						{
							id = "chk_camping";
						}
						if(id != "")
						{
							try
							{
								document.getElementById(id + "_lbl").style.display = "block";
								var h = 0;
								try
								{
									h = parseInt(document.getElementById(id + "_span").innerHTML,10);
									h ++;
								}
								catch(e)
								{
									h = 1;
								}
								document.getElementById(id + "_span").innerHTML = h;
								document.getElementById(id + "_lbl").style.display = "block";
								document.getElementById("properties_shown").style.display="block";
							}
							catch(e){}
						}
					}
				}
			} catch (err) {}
		}
	}
	this.checkRangeAvailability = function()
	{	
		$("#all_msg").hide();
		if(this.availabilityCounter <= 15)
		{
			if(typeof(this.propertiesArray[this.limitFrom]) != "undefined")
			{
				var i = this.getHotelRooms(this.propertiesArray[this.limitFrom].id ,false,true);
				if(i == -1)
				{
					showMsg(search_trans["ajax_error_text"]);
					return;
				}
			}
			else if(this.limitFrom >= this.propertiesArray.length)
			{
				$("#allworking").css("display","none");
				$("#show_more_div").css("display","none");
				if(this.availabilityCounter == 0)
				{
					var m = document.getElementById("all_msg");
					if(m!=null)
					{
						var msg_lnk = search_trans["city_no_availability"].replace(/%city%/gi,this.city);	
						if(booking_id != 0)
						{
							var dtm = new Date(this.date.getFullYear(),this.date.getMonth(),this.date.getDate());
							dtm.setDate(dtm.getDate() + this.nights);
							var booking_lnk = "http://www.booking.com/searchresults.html?aid=327218&city="+booking_id+"&checkin_monthday="+this.date.getDate()+"&checkin_year_month="+this.date.getFullYear()+"-"+(this.date.getMonth()+1)+"&checkout_monthday="+dtm.getDate()+"&checkout_year_month="+dtm.getFullYear()+"-"+(dtm.getMonth()+1)+"&do_availability_check=1&order=price&lang="+_sys_lang;
							if(m!=null)
							{
								msg_lnk = msg_lnk + "<center><a href='%booking_link%'><img src='"+_sys_url+"images/bookingcom.png' /></a></center>";
								msg_lnk = msg_lnk.replace(/%booking_link%/gi,booking_lnk);
							}
						}
						else
						{
							msg_lnk = msg_lnk + "<center><a href='%booking_link%'><img src='"+_sys_url+"images/bookingcom.png' /></a></center>";
							msg_lnk = msg_lnk.replace(/%booking_link%/gi,"http://www.booking.com/?aid=327218");
						}
						m.innerHTML = msg_lnk;
					}
					if(!this.tracked)
					{
						//alert("1-" + this.limitFrom + "-" +this.availabilityCounter);
						trackit(this.city + ' no availability message', '15 - city no availability', this.city);
						if(booking_id != 0)
						{
							var dtm = new Date(this.date.getFullYear(),this.date.getMonth(),this.date.getDate());
							dtm.setDate(dtm.getDate() + this.nights);
							trackit(this.city + ' no availability message , booking.com link shown', '15 - city no availability' +this.city , this.city);
							var booking_lnk = "http://www.booking.com/searchresults.html?aid="+bookingcom_id+"&city="+booking_id+"&checkin_monthday="+this.date.getDate()+"&checkin_year_month="+this.date.getFullYear()+"-"+(this.date.getMonth()+1)+"&checkout_monthday="+dtm.getDate()+"&checkout_year_month="+dtm.getFullYear()+"-"+(dtm.getMonth()+1)+"&do_availability_check=1&order=price&lang="+_sys_lang;
							//setTimeout('window.location.href = booking_lnk',3000);
							redirectBooking(booking_lnk);
						}
						else 
						{
							trackit(this.city + ' no availability message , no booking.com link shown', '15 - city no availability' +this.city , this.city);
							redirectBooking("http://www.booking.com/?aid=" + bookingcom_id);
							//window.location.href = "http://www.booking.com/?aid=327218";
						} 
						this.tracked = true;
					}
					$("#all_msg").show();
				}
				return;
			}
		}
		else if(this.availabilityCounter >= 14)
		{
			document.getElementById("allworking").style.display = "none";
			document.getElementById("show_more_div").style.display = "block";
		}
	}
	this.showHostel = function(id ,onlyrooms)
	{
		if(typeof(this.hotelRooms[id]) != "undefined")
		{
			if(onlyrooms == false)
			{
				var hp = this.buildHostelTable(id,this.shown,true);
				hp = hp.replace(/%rooms_content%/gi,this.buildRoomsTable(this.hotelRooms[id],id));
				this.shown ++;
				var cnt = document.getElementById("content_"+id) ;
				if(cnt != null && typeof(cnt) != "undefined")
				{
					cnt.innerHTML = cnt.innerHTML.replace(/%rooms_content%/gi,this.buildRoomsTable(this.hotelRooms[id],id));
				}
				else
				{
					$("#filter_container").append(hp);
				}
				document.getElementById("ajaxrooms_"+id).style.display = "block";
				
			}
			else
			{
				$("#ajaxrooms_"+id).css("display","none");
				var x = this.buildRoomsTable(this.hotelRooms[id],id);
				document.getElementById("content_"+id).innerHTML = x;
				//$("#ajaxrooms_"+id).slideDown("slow");
				$("#content_"+id).css("display","block");
				document.getElementById("ajaxrooms_"+id).style.display = "block";
			}
		}
	}
	/** check the availability of the hostels with id , and hide it or not if there is no availability **/
    this.checkAvailability = function (id, hide ,showall,limit) 
	{
		
        var me = this;
        var hide_unavailable = false;
        if (typeof(hide) != "undefined") {
            hide_unavailable = true;
        }
        if (this.remember == true) {
            var browserName = navigator.appName;
            var today = new Date();
            if (this.date < today) {
                alert(this.alert_dates);
                return -1;
            }
			var r = document.getElementById("reviews_"+id);
			if(r!= null && typeof(r) != 'undefined')
			{
				r.style.display = "none";
			}
			document.getElementById("ajaxrooms_"+id).style.display = "block";
			//document.getElementById("ajaxrooms_"+id).style.display = "none";
			var des = document.getElementById("desc_"+id);
			if(des != null && typeof(des) != 'undefined')
			{
				des.style.display = "none";
			}
			var lmk = document.getElementById("hotel_menu_"+id);
			if(lmk != null)
			{
				document.getElementById("hotel_menu_"+id).style.display = "none"; 
				document.getElementById("content_"+id).innerHTML = wheelAnimate();
				document.getElementById("hotel_menu_"+id).style.display = "block"; 
			}
			else
			{
				document.getElementById("content_"+id).innerHTML = wheelAnimate();
			}
			this.getHotelRooms(id,true,false);
			if(!this.dateUpdated)
			{
				this.updateSearchForm();
			}
        } else {
			var r = document.getElementById("reviews_"+id);
			if(r!= null && typeof(r) != 'undefined')
			{
				r.style.display = "none";
			}
			document.getElementById("ajaxrooms_"+id).style.display = "none";
			var des = document.getElementById("desc_"+id);
			if(des != null && typeof(des) != 'undefined')
			{
				des.style.display = "none";
			}
			this.dateUpdated = false;
			var l = document.getElementById("hotel_menu_"+id);
			if(l != null)
			{
				l.style.display = "none"; 
				this.showAvailabilityForm(id);
				l.style.display = "block"; 
			}
			else
			{
				this.showAvailabilityForm(id);
			}
        }
        return 1;
    } /** show global map , used to show maps of all or some hostels **/
    this.showMap = function () {
        var obj = document.getElementById('gMap');
        var browserName = navigator.appName;
        if (browserName == "Microsoft Internet Explorer") {
            obj.style.position = "absolute";
            obj.style.top = ($(window).scrollTop() + 100) + "px";
            obj.style.left = "110px";
        } else {
            obj.style.position = "fixed";
            obj.style.top = '130px';
            z = ((screen.width / 2) - 400);
            obj.style.left = z + "px";
        }
        obj.style.display = 'block';
        if (GBrowserIsCompatible()) {
            var zoom = 14;
            if (this.totalProperties == 1) {
                zoom = 16;
            }
            var map = new GMap2(document.getElementById("map"));
            map.setMapType(G_NORMAL_MAP);
            var property = null;
            for (var property_id in this.properties) {
                property = this.properties[property_id];
                if (typeof(property) != "undefined" && property.title.replace(/^\s+|\s+$/g, '') != "") {
                    break;
                }
            }
            if (typeof(property) == "undefined") {
                return;
            }
            var point = new GLatLng(property.map_latitude, property.map_longitude);
            map.setCenter(point, zoom);
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            var mainIcon = new GIcon();
            mainIcon.image = "images/map_mainIcon_big.png";
            mainIcon.shadow = "images/map_mainIconShadow.png";
            mainIcon.iconSize = new GSize(22, 26);
            mainIcon.shadowSize = new GSize(0, 0);
            mainIcon.iconAnchor = new GPoint(20, 20);
            mainIcon.infoWindowAnchor = new GPoint(20, 20);
            markerOptions1 = {
                icon: mainIcon
            };
            var tinyIcon = new GIcon();
            tinyIcon.image = "images/map_tinyIcon.png";
            tinyIcon.shadow = "images/map_tinyIconShadow.png";
            tinyIcon.iconSize = new GSize(17, 20);
            tinyIcon.shadowSize = new GSize(0, 0);
            tinyIcon.iconAnchor = new GPoint(15, 15);
            tinyIcon.infoWindowAnchor = new GPoint(15, 15);
            markerOptions2 = {
                icon: tinyIcon
            };
            if (this.totalProperties > 2) {
                for (var property_id in this.properties) {
                    var property = this.properties[property_id];
                    if (typeof(property) != "undefined" && property.title.replace(/^\s+|\s+$/g, '') != "") {
                        var point = new GLatLng(property.map_latitude, property.map_longitude);
                        map.addOverlay(createMarker(map, point, property, markerOptions2));
                    }
                }
            } else if (this.totalProperties == 1) {
                map.addOverlay(createMarker(map, point, property, markerOptions1));
            }
        }
    } /** check if the user selected 1 or more rooms **/
    this.checkRooms = function (property_id) {
        var frm = $("div.stRooms #formstRooms_" + property_id);
        if (frm.length == 1) {
            var selects = frm.find(".hc-lightgreybg-select select");
            if (selects.length > 0) {
                for (var i = 0; i < selects.length; i++) {
                    try {
                        var x = parseInt($(selects[i]).find("option:selected").val(),10);
                        if (x > 0) {
                            return true;
                        }
                    } catch (e) {}
                }
            }
        } /*alert(this.alert_rooms);*/
        animateRooms(frm, 0);
        return false;
    } /** calculate the total rooms, daily price and total beds **/
    this.showBillPanel = function (property_id) {
        var frm = $("#ajaxrooms_" + property_id);
        var totalRooms = 0;
        var totalBeds = 0;
        var dailyPrice = 0;
        if (frm.length == 1) {
            frm.find("td.hc-lightgreybg-select").each(function () {
                try {
                    var m = $(this).find("select").first();
                    var x = parseInt(m.find("option:selected").val(), 10);
                    var p = $(this).find("input").val();
                    p = p.split(",");
                    if (x > 0 && p.length == 4) {
                        var price = parseFloat(p[0]);
                        var nobed = parseInt(p[2], 10);
                        dailyPrice = dailyPrice + x * price * nobed;
                        totalBeds = totalBeds + nobed * x;
                        var private_room = parseInt(p[3], 10);
                        if (private_room == 0) {
                            totalRooms = totalRooms + parseInt(x, 10);
                        } else {
                            totalRooms++;
                        }
                    }
                } catch (e) {}
            });
            dailyPrice = Math.round(dailyPrice * 100) / 100;
            if (totalRooms > 0) {
				var bmsg = search_trans["room_selection_msg"];
				bmsg = bmsg.replace(/%totalRooms%/gi,totalRooms);
				bmsg = bmsg.replace(/%totalBeds%/gi,totalBeds);
				bmsg = bmsg.replace(/%nights%/gi,this.nights);
                document.getElementById("tdbooknow_" + property_id).innerHTML = "<div class='bill_panel'>"+ bmsg +"<div style='position:relative'  ><div id='billinfo_" + property_id + "' class='billinfo'>"+search_trans["totalprice_help_msg"] +"<center><input type='submit' value='"+ search_trans["booknow_rooms_button"] +"' class='but_avail_book'/> </center></div>"+ search_trans["estimated_price_label"] +" <a href='javascript:showToolTip(\"billinfo_" + property_id + "\");'><img style='margin:0 3px -3px;' src='images/alwaysAsk.png' /></a> <b class='bill_price'>" + dailyPrice + " " + this.currency + "</b></div></div>";
                $("#tdbooknow_" + property_id).slideDown();
                frm.find("#lnk_"+property_id).attr("class", "but_book");
                frm.find("td.hc-lightgreybg-select").css("background", "transparent");
            } else {
                  document.getElementById("tdbooknow_" + property_id).innerHTML = this.help_book;
                frm.find("#lnk_"+property_id).attr("class", "but_book disabled");
                frm.find("td.hc-lightgreybg-select").css("background", "#F16006");
            }
            return (true);
        }
        return false;
    } 
	this.buildHostelTable = function(id,t,show)
	{
		try
		{
			var hostelbox = document.getElementById("property_matrix").innerHTML;
			var property = this.properties[id];
			hostelbox = hostelbox.replace(/%id%/gi,id);
			hostelbox = hostelbox.replace(/%body%/gi,property.description);
			hostelbox = hostelbox.replace(/%title%/gi,property.title);
			var pclass = property.category;
			hostelbox = hostelbox.replace(/%class%/gi,pclass);
			hostelbox = hostelbox.replace(/%class_url%/gi,property.category_url);
			hostelbox = hostelbox.replace(/%picture%/gi,_sys_url_static+"photos/small/"+ property.thumbnail);
			hostelbox = hostelbox.replace(/%rate_min%/gi,property.rate_min);
			hostelbox = hostelbox.replace(/%rate_max%/gi,property.rate_max);
			hostelbox = hostelbox.replace(/%price_min%/gi,property.price_shared);
			hostelbox = hostelbox.replace(/%price_max%/gi,property.price_private);
			hostelbox = hostelbox.replace(/%rate_overall%/gi,property.rating);
			hostelbox = hostelbox.replace(/%url_class%/gi,property.category_url);
			hostelbox = hostelbox.replace(/%url%/gi,property.url);
			var param = getParameter('d');
			hostelbox = hostelbox.replace(/index.html/gi,"index.html?d="+ param);
			hostelbox = hostelbox.replace(/reviews.html/gi,"reviews.html?d="+ param);
			hostelbox = hostelbox.replace(/%class_tab%/gi,'class="active_list"');
			try
			{
				var rating = parseInt(property.rating,10);
				if(rating > 0)
				{
					var rate_text = search_trans["rated_property"];
					rate_text = rate_text.replace(/%rating%/gi,rating);
					rate_text = rate_text.replace(/%rate_people%/gi,property.rate_people);
					hostelbox = hostelbox.replace(/%rate_box%/gi,rate_text);
				}
				else
				{
					var rate_text = search_trans["notrated_property"];
					hostelbox = hostelbox.replace(/%rate_box%/gi,rate_text);
				}
			}
			catch(e)
			{
				var rate_text = search_trans["notrated_property"];
				hostelbox = hostelbox.replace(/%rate_box%/gi,rate_text);
			}
			if(typeof(show)!= "undefined")
			{
				if(show == false)
				{
					return hostelbox;
				}
			}
			return hostelbox;
		}
		catch(e)
		{
			return "";
		}
	}
	this.showMore = function()
	{
		this.availabilityCounter = 0;
		$("#allworking").css("display","block");
		$("#show_more_div").css("display","none");
		this.checkRangeAvailability();
	}
	this.buildRoomsTable = function(hotel_json ,id)
	{
		var dt_lbl = search_trans["rooms_date_label"];
		dt_lbl = dt_lbl.replace(/%day%/gi,hotel_json.arrival.day);
		dt_lbl = dt_lbl.replace(/%month%/gi,hotel_json.arrival.month);
		dt_lbl = dt_lbl.replace(/%year%/gi,hotel_json.arrival.year);
		dt_lbl = dt_lbl.replace(/%nights%/gi,hotel_json.arrival.nights);
		var div_head = "<div class='stRooms'>"+
		"<div class='change_dates'>"+
			"<div class='date-middle'>"+
				"<div class='date-left'>"+
					"<div class='date-right'>"+
						"<span>"+ dt_lbl +"</span>" +
						"<a class='read_more_btn' href='javascript:void(0);' onclick='changeAvailabilityDate("+ hotel_json.hotel.code + ")'>"+search_trans["rooms_change_date_label"]+"</a>"+
					"</div>"+
				"</div>"+
			"</div>"+
			"<div class='date-bottom'></div>"+
		"</div>"+
		"<form name='rooms' id='formstRooms_"+ hotel_json.hotel.code + "' class='hcRoomsForm' onsubmit='submitIframe(this);return true;' target='bookframe' method='post' action='https://www.hostelspoint.com/res/"+this.getSiteId()+"/step03_book.php?str="+ hotel_json.hotel.code + "&lang="+_sys_lang+"&giorno="+ hotel_json.arrival.day  + "&mese="+ hotel_json.arrival.month  + "&anno="+ hotel_json.arrival.year + "&notti=" + hotel_json.arrival.nights +"&currency=1'>"+
		"<input type='hidden' value='standard' name='formtype'>"+
		"<table class='hcRoomsTable'>";
		var property = null;
		if(typeof(hotel_json.hotel.code) != "undefined")
		{
			try
			{
				property = window.st_controller.properties[hotel_json.hotel.code];
			}
			catch(e)
			{
			}
		}
		if(typeof(hotel_json.error) != "undefined")
		{
			div_head += "<tr>"+
				"<td colspan='4'>"+
				"<div id='error_msg'>";
				if(typeof(hotel_json.error) != "undefined")
				{
					for(var err in hotel_json.error)
					{
						div_head += "<h2>"+ hotel_json.error[err].description +"</h2>"+
						"<ul>"+
							"<li>" + hotel_json.error[err].message + "</li>"+
						"</ul>";
					}
				}
				div_head += "</div>"+
				"</td>"+
			"</tr>";
		}
		if(typeof(hotel_json.warning) != "undefined")
		{
			div_head += "<tr>"+
				"<td colspan='4'>"+
				"<div id='error_msg'>";
				if(typeof(hotel_json.warning) != "undefined")
				{
					for(var err in hotel_json.warning)
					{
						div_head += "<h2>"+ hotel_json.warning[err].description +"</h2>"+
						"<ul>"+
							"<li>" + hotel_json.warning[err].message + "</li>"+
						"</ul>";
					}
				}
				div_head += "</div>"+
				"</td>"+
			"</tr>";
		}
		if(typeof(hotel_json.hotel) != 'undefined')
		{
			if(typeof(hotel_json.hotel) != "undefined")
			{
				if(parseInt(hotel_json.hotel.available,10) == 0)
				{
					if(property != null && typeof(property) != "undefined")
					{
					var noavail = search_trans["property_no_availability"];
					noavail = noavail.replace(/%property_title%/gi,property.title);
					var find_another = search_trans["city_find_another_label"];
					find_another = find_another.replace(/%city%/gi,property.city);
					div_head += "<tr>"+
						"<td colspan='4'>"+
						"<center><div class='msg_box'>"+ noavail +
							"<a class='but_book' onclick=\"trackit('property no availability action', '13 - Find another place action', '"+property.title+"');\" href='javascript:checkCityAvailability(\""+_sys_city+"\",\"" + _sys_country +"\");'>"+
								"<div class='but-left'>"+
									"<div class='but-right'>"+
										"<div class='but-middle'>"+ find_another +
										"</div>"+
									"</div>"+
								"</div>"+
							"</a>"+
						"</div></center>"+
						"</td>"+
					"</tr>";
					}
				}
				else if(parseInt(hotel_json.hotel.available,10) == 1)
				{
					this.availableProperties[this.availableProperties.length] = hotel_json.hotel.code;
					var show_private = false;
					if(typeof(hotel_json.hotel.proom) != 'undefined')
					{
						show = true;
						var pr_room = "";
						pr_room += "<tr>"+
							"<td colspan='4'><b class='shared_lbl'>"+search_trans["private_rooms_label"]+"</b></td>"+
						"</tr>"+
						"<tr>"+
							"<td class='hc-greybgs'>"+search_trans["room_type_label"]+"</td>"+
							"<td class='hc-greybgs'>"+search_trans["room_price_label"]+"</td>"+
							"<td class='hc-greybgs'>"+search_trans["room_guests_label"]+"</td>"+
						"</tr>";
						for(var pr in hotel_json.hotel.proom)
						{
							if(parseInt(hotel_json.hotel.proom[pr].timestamp,10) == 0)
							{
								show_private = true;
								pr_room += "<tr>" +
								"<td class='hc-lightgreybg'>" + hotel_json.hotel.proom[pr].description + "</td>"+
								"<td class='hc-lightgreybg price_bg'><b>" + hotel_json.hotel.proom[pr].price + "</b> " + hotel_json.hotel.proom[pr].currency + "</td>"+
								"<td class='hc-lightgreybg-select'>"+
								"<input class='room-info' type='hidden' value='"+ hotel_json.hotel.proom[pr].price + ","+ hotel_json.hotel.proom[pr].currency +","+ hotel_json.hotel.proom[pr].beds +",0' id='input_"+hotel_json.hotel.code +"'/>"+
								"<select onchange='showBillPanel("+ hotel_json.hotel.code + ")' name='"+ hotel_json.hotel.proom[pr].code +"' class='hcRoomPrivate' >";
								for(var j=0;j<= parseInt(hotel_json.hotel.proom[pr].units,10);j++)
								{
									pr_room += "<option value='"+j+"'>"+ parseInt(hotel_json.hotel.proom[pr].beds,10)*j +"</option>";
								}
								pr_room += "</select>"+
								"</td>"+
								"</tr>";
							}
						}
						if(show_private == true)
						{
							div_head += pr_room;
						}
					}
					if(typeof(hotel_json.hotel.sroom) != 'undefined')
					{
						show = true;
						var show_shared = false;
						var sr_room = "";
						sr_room += "<tr>"+
							"<td colspan='4'><b class='shared_lbl'>"+search_trans["shared_rooms_label"]+"</b></td>"+
						"</tr>"+
						"<tr>"+
							"<td class='hc-greybgs'>"+search_trans["room_type_label"]+"</td>"+
							"<td class='hc-greybgs'>"+search_trans["room_price_label"]+"</td>"+
							"<td class='hc-greybgs'>"+ search_trans["room_guests_label"]+"</td>"+
						"</tr>";
						for(var pr in hotel_json.hotel.sroom)
						{
							show_shared = true;
							sr_room += "<tr>"+
								"<td class='hc-lightgreybg'>" + hotel_json.hotel.sroom[pr].description + "</td>"+
								"<td class='hc-lightgreybg price_bg'><b>" + hotel_json.hotel.sroom[pr].price + "</b> " + hotel_json.hotel.sroom[pr].currency + "</td>"+
								"<td class='hc-lightgreybg-select'>"+
								"<input class='room-info' type='hidden' value='"+ hotel_json.hotel.sroom[pr].price + ","+ hotel_json.hotel.sroom[pr].currency +","+ hotel_json.hotel.sroom[pr].beds +",1' id='input_"+hotel_json.hotel.code +"'/>"+
								"<select onchange='showBillPanel("+ hotel_json.hotel.code + ")' name='"+ hotel_json.hotel.sroom[pr].code +"' class='hcRoomPrivate' >";
								for(var j=0;j<= parseInt(hotel_json.hotel.sroom[pr].units,10);j++)
								{
									sr_room += "<option value='"+j+"'>"+ j +"</option>";
								}
								sr_room += "</select>"+
								"</td>"+
							"</tr>";
						}
						if(show_shared == true)
						{
							div_head += sr_room;
						}
						
					}
					if(show == true)
					{
						var style = "";
						div_head += "<tr>"+
							"<td style='text-align:right;border:0;"+style+"' colspan='4' id='tdbooknow_"+ hotel_json.hotel.code +"'>"+this.help_book+"</td>"+
						"</tr>"+
						"<tr>"+
							"<td colspan='4'>"+
							"<center>"+
							"<a id='lnk_"+hotel_json.hotel.code+"' class='but_book disabled' href='javascript:checkRooms("+hotel_json.hotel.code+");'><div class='but-left'><div class='but-right'><div class='but-middle'>"+search_trans["booknow_rooms_button"]+"</div></div></div></a>"+
							"</center>"+
							"</td>"+
						"</tr>";
					}
				}
			}
		}
		div_head += "</table>"+
		"</form>"+
		"</div>";
		//$("#but_ajaxrooms_"+id).css("display","none");
		return div_head;
	}
	this.getSiteId = function ()
	{
		try
		{
			if(typeof(aff_id) != 'undefined' )
			{
				aff_id = parseInt(aff_id,10);
				if(aff_id != 0)
				{
					return aff_id;
				}
			}
		}
		catch(e)
		{
			return 250;
		} 
		return 250;
		/*try
		{
			if(typeof(_sys_lang) != "undefined" && _sys_lang != null)
			{
				if(_sys_lang.toLowerCase() == "en")
				{
					return 610;
				}
				if(_sys_lang.toLowerCase() == "it")
				{
					return 611;
				}
				if(_sys_lang.toLowerCase() == "es")
				{
					return 612;
				}
				if(_sys_lang.toLowerCase() == "fr")
				{
					return 613;
				}
				if(_sys_lang.toLowerCase() == "de")
				{
					return 614;
				}
				return 610;
			}
			else
			{
				return 250;
			}
		}
		catch(e)
		{
			return 250;
		}*/
	}
	/** show the availability form for each property **/
    this.showAvailabilityForm = function (id) {
        //$(".hostels_box .ajax_rooms").hide();
		//document.getElementById("but_ajaxrooms_"+id).style.display = "none";
		//document.getElementById("ajaxrooms_"+id).style.display = "none";
		$(".hostels_box .read_more_btn").show();
        //var close_div = "<div class='availability_form'><div class='close_div'><a href='javascript:hide_div(\"ajaxrooms_" + id + "\");'><div class='close_img'></div></a></div>";
		var close_div  = "";
        var frmchk = close_div + "<div class='changedates'><form id='frm_avail_" + id + "' action='' method='post'>" + "<input type='hidden' name='str' value='" + id + "'/>" + "<input type='hidden' name='ajax_command' value='ajax_hotel_avail'/>" + "<input type='hidden' name='currency' value='EUR'/>" + "<table width='100%'><tr><td> " + this.arrival_date_lbl + "&nbsp; </td><td>" + "<SELECT name='giorno' id='giorno' >";
        for (var day = 1; day <= getDaysInMonth(this.date.getMonth()+1, this.date.getFullYear()); day++) {
            if (day == this.date.getDate()) {
                frmchk = frmchk + "<option selected='selected' value='" + day + "'>" + day + "</option>";
            } else {
                frmchk = frmchk + "<option value='" + day + "'>" + day + "</option>";
            }
        }
        frmchk = frmchk + "</SELECT><SELECT id='mese' name='mese' onchange='fixDates(\"giorno\",\"mese\",\"anno\");'> "; /*var mese_array =new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");		*/
        for (var mese = 0; mese <= 11; mese++) {
            if (mese == this.date.getMonth()) {
                frmchk = frmchk + "<option selected='selected' value='" + (mese + 1) + "'>" + (mese + 1) + "</option>";
            } else {
                frmchk = frmchk + "<option value='" + (mese + 1) + "'>" + (mese + 1) + "</option>";
            }
        }
        frmchk = frmchk + "</SELECT><SELECT name='anno' id='anno'>";
        for (var anno = 2010; anno <= 2012; anno++) {
            if (anno == this.date.getFullYear()) {
                frmchk = frmchk + "<option selected='selected' value='" + anno + "'>" + anno + "</option>";
            } else {
                frmchk = frmchk + "<option value='" + anno + "'>" + anno + "</option>";
            }
        }
        frmchk = frmchk + "</SELECT></td></tr><tr><td> " + this.nights_lbl + "&nbsp; </td><td> <SELECT id='notti' name='notti'>";
        for (var notti = 1; notti <= 7; notti++) {
            if (notti == this.nights) {
                frmchk = frmchk + "<option selected='selected' value='" + notti + "'>" + notti + "</option>";
            } else {
                frmchk = frmchk + "<option value='" + notti + "'>" + notti + "</option>";
            }
        }
        frmchk = frmchk + "</SELECT></td></tr><tr><td colspan='2' style='text-align:right'><a class='read_more_btn' onclick=\"trackit('check availability form action', '10 - check availability property form action','"+ window.st_controller.properties[id].title+"');\"  href='javascript:checkAvailability(" + id + ");' >"+search_trans["check_avail_label"]+"</a></td></tr></table></form></div></div>";
        document.getElementById("content_" + id).innerHTML = frmchk; /*$("#ajaxrooms_"+id).css("display","block");*/
        document.getElementById("ajaxrooms_" + id).style.display = "block";
    } /** update the top search form incase of date change or nights **/
    this.updateSearchForm = function () {
        var s = this.date;
        var n = this.nights;
		this.dateUpdated = true;
        $("#dDateY option").each(function () {
            if (s.getFullYear() == parseInt($(this).val(),10)) {
                $(this).attr("selected", "selected");
            } else {
                $(this).attr("selected", "");
            }
        });
        $("#dDateM option").each(function () {
            if ((s.getMonth() + 1) == parseFloat($(this).val())) {
                $(this).attr("selected", "selected");
            } else {
                $(this).attr("selected", "");
            }
        });
        fixDates('dDateD', 'dDateM', 'dDateY');
        $("#dDateD option").each(function () {
            if (s.getDate() == parseFloat($(this).val())) {
                $(this).attr("selected", "selected");
            } else {
                $(this).attr("selected", "");
            }
        });
        $("#dNights option").each(function () {
            if (n == parseInt($(this).val(),10)) {
                $(this).attr("selected", "selected");
            } else {
                $(this).attr("selected", "");
            }
        });
    } 

 /** change the rating range **/
    this.setRatingRange = function (min, max) {
        this.ratingRangeMin = min;
        this.ratingRangeMax = max;
    } /** change the price private range **/
    this.setPricePRange = function (min, max) {
        this.pricepRangeMin = min;
        this.pricepRangeMax = max;
    } /** change the price shared range **/
    this.setPriceSRange = function (min, max) {
        this.pricesRangeMin = min;
        this.pricesRangeMax = max;
    } /** filter the properties by ranges(price,rating) **/
    this.filterByRange = function (arr) {
        if (this.properties.length > 1) {
            var htmlArray = new Array();
			var showhostels = 1;
			var showhotels = 1;
			var showbabs = 1;
			var showguesthouse = 1;
			var showapartment = 1;
			var showcamping = 1;
			var chkhostels = document.getElementById("chk_hostels");
			if(chkhostels != null && typeof(chkhostels)!="undefined")
			{
				 if(chkhostels.checked == false)
				 {
					showhostels = 0;
				 }
			}
			var chkbabs = document.getElementById("chk_babs");
			if(chkbabs != null && typeof(chkbabs)!="undefined")
			{
				 if(chkbabs.checked == false)
				 {
					showbabs = 0;
				 }
			}
			var chkhotels = document.getElementById("chk_hotel");
			if(chkhotels != null && typeof(chkhotels)!="undefined")
			{
				 if(chkhotels.checked == false)
				 {
					showhotels = 0;
				 }
			}
			var chkguesthouse = document.getElementById("chk_guesthouse");
			if(chkguesthouse != null && typeof(chkguesthouse)!="undefined")
			{
				 if(chkguesthouse.checked == false)
				 {
					showguesthouse = 0;
				 }
			}
			var chkapartment = document.getElementById("chk_apartment");
			if(chkapartment != null && typeof(chkapartment)!="undefined")
			{
				 if(chkapartment.checked == false)
				 {
					showapartment = 0;
				 }
			}
			var chkcamping = document.getElementById("chk_camping");
			if(chkcamping != null && typeof(chkcamping)!="undefined")
			{
				 if(chkcamping.checked == false)
				 {
					showcamping = 0;
				 }
			}
            for (var property_id in this.properties) {
                var id = this.properties[property_id].id;
				var category = this.properties[property_id].category_url;
				if(category == "hostel" && showhostels == 0)
				{
					$("#container_" + id).css("display", "none");
					continue;
				}
				else if(category == "hotel" && showhotels == 0)
				{
					$("#container_" + id).css("display", "none");
					continue;
				}
				else if(category == "bed_and_breakfast" && showbabs == 0)
				{
					$("#container_" + id).css("display", "none");
					continue;
				}
				else if(category == "guest_house_limited_service" && showguesthouse == 0)
				{
					$("#container_" + id).css("display", "none");
					continue;
				}
				else if(category == "apartment" && showapartment == 0)
				{
					$("#container_" + id).css("display", "none");
					continue;
				}
				else if(category == "camping" && showcamping == 0)
				{
					$("#container_" + id).css("display", "none");
					continue;
				}
                var rating = this.properties[property_id].rating;
                var price_private = this.properties[property_id].price_private;
                var price_shared = this.properties[property_id].price_shared;
                if (typeof(rating) != "undefined" && typeof(price_private) != "undefined" && typeof(price_shared) != "undefined") {
                    if (parseFloat(rating) >= this.ratingRangeMin && parseFloat(rating) <= this.ratingRangeMax && parseFloat(price_private) >= this.pricepRangeMin && parseFloat(price_private) <= this.pricepRangeMax && parseFloat(price_shared) >= this.pricesRangeMin && parseFloat(price_shared) <= this.pricesRangeMax) {
							$("#container_" + id).css("display", "block");
                    } else {
                        $("#container_" + id).css("display", "none");
                    }
                }
            }
        }
    }
    this.load();
}
/** change the class of the sort item clicked **/
function toggleSort() {
        $("div.oderdby-mid a").each(function () {
            $(this).attr("class", "");
        });
    }
/** sort the hostels by rating **/
var ratingSort = "ASC";
function sortByRating(item) {
	try
	{
		
        toggleSort();
		$(item).attr("class", "active");
		var ratings = [];
		var prop = null;
		try
		{
			prop = window.st_controller.properties.slice();
		}
		catch(e)
		{
			try
			{
				window.st_controller = new st_controller();
				prop = window.st_controller.properties.slice();
			}
			catch(e)
			{
				return
			}
		}
		
		var htmlArray = new Array();
		for(var p in prop)
		{
			var container = document.getElementById("container_" + p);
			if(typeof(container) != "undefined" && container != null)
			{
				try
				{
					ratings[ratings.length] = parseInt(document.getElementById("rating_" + p).innerHTML,10)+"_,_"+p;
				}
				catch(e)
				{
					ratings[ratings.length] = 0+"_,_"+p;
				}
				htmlArray[p] = "<div class='hostels_box' id='container_" + p + "' style='display:"+ $("#container_" + p).css("display") +";'>" + document.getElementById("container_" + p).innerHTML + "</div>";
				$("#container_" + p).remove();
			}
		}
        var sortBy = ratingSort;
        if (ratings.length > 1) {
            ratings.sort(function (a, b) {
                if (typeof(a) != "undefined") {
                    if (typeof(b) != "undefined") {
						var ra =  parseInt(a.substring(0, a.indexOf("_,_")),10);
						var rb =  parseInt(b.substring(0, b.indexOf("_,_")),10);
                        if (rb > ra) {
                            if (sortBy == "DESC") {
                                return -1;
                            } else {
                                return 1;
                            }
                        } else if (rb < ra) {
                            if (sortBy == "DESC") {
                                return 1;
                            } else {
                                return -1;
                            }
                        } else {
                            return 0;
                        }
                    }
                } else if (typeof(b) != "undefined") {
                    if (sortBy == "DESC") {
                        return -1;
                    } else {
                        return 1;
                    }
                } else {
                    return 0;
                }
            });
			var m_unsorted = [];
			for(var i in ratings)
			{
				if(typeof(ratings[i]) != "undefined")
				{
					var pid = ratings[i].substring(ratings[i].indexOf("_,_")+3,ratings[i].length);
					if(typeof(htmlArray[pid]) != "undefined")
					{
						if(ratings[i].substring(0, ratings[i].indexOf("_,_")) > 0)
						{
							$("#filter_container").append(htmlArray[pid]);
						}
						else
						{
							m_unsorted[m_unsorted.length] = htmlArray[pid];
						}
					}
				}
			}
			if(m_unsorted.length > 0)
			{
				for(var i in m_unsorted)
				{
					$("#filter_container").append(m_unsorted[i]);
				}
			}
            if (ratingSort == "DESC") {
                ratingSort = "ASC";
            } else {
                ratingSort = "DESC";
            }
        }
        window.st_controller.filterByRange();
		}
		catch(e)
		{
		}
}
/** sort the properties by name **/
var nameSort = "ASC";
function sortByName(item) {
	try
	{
		
        toggleSort();
		$(item).attr("class", "active");
		var names = [];
        var sortBy = nameSort;
		var prop = null;
		try
		{
			prop = window.st_controller.properties.slice();
		}
		catch(e)
		{
			try
			{
				window.st_controller = new st_controller();
				prop = window.st_controller.properties.slice();
			}
			catch(e)
			{
				return
			}
		}
		var htmlArray = new Array();
		for(var p in prop)
		{
			var container = document.getElementById("container_" + p);
			if(typeof(container) != "undefined" && container != null)
			{
				try
				{
					names[names.length] = document.getElementById("title_" + p).innerHTML.trim() + "_,_" + p;
				}
				catch(e)
				{
					names[names.length] = " _,_"+p;
				}
				htmlArray[p] = "<div class='hostels_box' id='container_" + p + "' style='display:"+ $("#container_" + p).css("display") +";'>" + document.getElementById("container_" + p).innerHTML + "</div>";
				$("#container_" + p).remove();
			}
		}
        if (names.length > 1) {
            names.sort(function (a, b) {
                if (typeof(a) != "undefined") {
                    if (typeof(b) != "undefined") {
						var ra = a.substring(0, a.indexOf("_,_"));
						var rb = b.substring(0, b.indexOf("_,_"));
						
                        if (rb.trim().toLowerCase() > ra.trim().toLowerCase()) {
                            if (sortBy == "DESC") {
                                return -1;
                            } else {
                                return 1;
                            }
                        } else if (rb.trim().toLowerCase() < ra.trim().toLowerCase()) {
                            if (sortBy == "DESC") {
                                return 1;
                            } else {
                                return -1;
                            }
                        } else {
                            return 0;
                        }
                    }
                } else if (typeof(b) != "undefined") {
                    if (sortBy == "DESC") {
                        return -1;
                    } else {
                        return 1;
                    }
                } else {
                    return 0;
                }
            });
			var m_unsorted = [];
			for(var i in names)
			{
				if(typeof(names[i]) != "undefined")
				{
					var pid = names[i].substring(names[i].indexOf("_,_")+3,names[i].length);
					if(typeof(htmlArray[pid]) != "undefined")
					{
						if(names[i].substring(0, names[i].indexOf("_,_")) > 0)
						{
							$("#filter_container").append(htmlArray[pid]);
						}
						else
						{
							m_unsorted[m_unsorted.length] = htmlArray[pid];
						}
					}
				}
			}
			if(m_unsorted.length > 0)
			{
				for(var i in m_unsorted)
				{
					$("#filter_container").append(m_unsorted[i]);
				}
			}
            if (nameSort == "DESC") {
                nameSort = "ASC";
            } else {
                nameSort = "DESC";
            }
        }
        window.st_controller.filterByRange();
	}
	catch(e){}
}
 /** sort the properties by private price **/
var pricepSort = "ASC";
function sortByPPrivate(item) {
	try
	{
		
        toggleSort();
		$(item).attr("class", "active");
        var sortBy = pricepSort;
		var pprice = [];
		var prop = null;
		try
		{
			prop = window.st_controller.properties.slice();
		}
		catch(e)
		{
			try
			{
				window.st_controller = new st_controller();
				prop = window.st_controller.properties.slice();
			}
			catch(e)
			{
				return
			}
		}
		var htmlArray = new Array();
		for(var p in prop)
		{
			var container = document.getElementById("container_" + p);
			if(typeof(container) != "undefined" && container != null)
			{
				try
				{
					pprice[pprice.length] = document.getElementById("pp_" + p).innerHTML.trim() + "_,_" + p;
				}
				catch(e)
				{
					pprice[pprice.length] = " _,_"+p;
				}
				htmlArray[p] = "<div class='hostels_box' id='container_" + p + "' style='display:"+ $("#container_" + p).css("display") +";'>" + document.getElementById("container_" + p).innerHTML + "</div>";
				$("#container_" + p).remove();
			}
		}
        if (pprice.length > 1) {
            pprice.sort(function (a, b) {
                try {
                    if (typeof(a) != "undefined") {
                        if (typeof(b) != "undefined") {
							var ra =  parseFloat(a.substring(0, a.indexOf("_,_")));
							var rb =  parseFloat(b.substring(0, b.indexOf("_,_")));
							if(ra == 0)
							{
								return 1;
							}
							if (rb > ra) {
								if (sortBy == "DESC") {
									return -1;
								} else {
									return 1;
								}
							} else if (rb < ra) {
								if (sortBy == "DESC") {
									return 1;
								} else {
									return -1;
								}
							} else {
								return 0;
							}
                        }
                    } else if (typeof(b) != "undefined") {
                        if (sortBy == "DESC") {
                            return -1;
                        } else {
                            return 1;
                        }
                    } else {
                        return 0;
                    }
                } catch (e) {
                    return 0;
                }
            });
			var m_unsorted = [];
			for(var i in pprice)
			{
				if(typeof(pprice[i]) != "undefined")
				{
					var pid = pprice[i].substring(pprice[i].indexOf("_,_")+3,pprice[i].length);
					if(typeof(htmlArray[pid]) != "undefined")
					{
						if(pprice[i].substring(0, pprice[i].indexOf("_,_")) > 0)
						{
							$("#filter_container").append(htmlArray[pid]);
						}
						else
						{
							m_unsorted[m_unsorted.length] = htmlArray[pid];
						}
					}
				}
			}
			if(m_unsorted.length > 0)
			{
				for(var i in m_unsorted)
				{
					$("#filter_container").append(m_unsorted[i]);
				}
			}
            if (pricepSort == "DESC") {
                pricepSort = "ASC";
            } else {
                pricepSort = "DESC";
            }
        }
        window.st_controller.filterByRange();
		}catch(e){}
} 
  /** sort the properties by price shared **/
  var pricesSort = "ASC";
function sortByPShared(item) {
	try
	{
        toggleSort();
		$(item).attr("class", "active");
        var sortBy = pricesSort;
		var sprice = [];
		var prop = null;
		try
		{
			prop = window.st_controller.properties.slice();
		}
		catch(e)
		{
			try
			{
				window.st_controller = new st_controller();
				prop = window.st_controller.properties.slice();
			}
			catch(e)
			{
				return
			}
		}
		var htmlArray = new Array();
		for(var p in prop)
		{
			var container = document.getElementById("container_" + p);
			if(typeof(container) != "undefined" && container != null)
			{
				try
				{
					sprice[sprice.length] = document.getElementById("ps_" + p).innerHTML.trim() + "_,_" + p;
				}
				catch(e)
				{
					sprice[sprice.length] = " _,_"+p;
				}
				htmlArray[p] = "<div class='hostels_box' id='container_" + p + "' style='display:"+ $("#container_" + p).css("display") +";'>" + document.getElementById("container_" + p).innerHTML + "</div>";
				$("#container_" + p).remove();
			}
		}
        if (sprice.length > 1) {
            sprice.sort(function (a, b) {
                 try {
                    if (typeof(a) != "undefined") {
                        if (typeof(b) != "undefined") {
						var ra = parseFloat(a.substring(0, a.indexOf("_,_")));
						var rb =  parseFloat(b.substring(0, b.indexOf("_,_")));
                            if (rb > ra) {
                                if (sortBy == "DESC") {
                                    return -1;
                                } else {
                                    return 1;
                                }
                            } else if (rb < ra) {
                                if (sortBy == "DESC") {
                                    return 1;
                                } else {
                                    return -1;
                                }
                            } else {
                                return 0;
                            }
                        }
                    } else if (typeof(b) != "undefined") {
                        if (sortBy == "DESC") {
                            return -1;
                        } else {
                            return 1;
                        }
                    } else {
                        return 0;
                    }
                } catch (e) {
                    return 0;
                }
            });
			var m_unsorted = [];
			for(var i in sprice)
			{
				if(typeof(sprice[i]) != "undefined")
				{
					var pid = sprice[i].substring(sprice[i].indexOf("_,_")+3,sprice[i].length);
					if(typeof(htmlArray[pid]) != "undefined")
					{
						if(sprice[i].substring(0, sprice[i].indexOf("_,_")) > 0)
						{
							$("#filter_container").append(htmlArray[pid]);
						}
						else
						{
							m_unsorted[m_unsorted.length] = htmlArray[pid];
						}
					}
				}
			}
			if(m_unsorted.length > 0)
			{
				for(var i in m_unsorted)
				{
					$("#filter_container").append(m_unsorted[i]);
				}
			}
            if (pricesSort == "DESC") {
               pricesSort = "ASC";
            } else {
                pricesSort = "DESC";
            }
            window.st_controller.filterByRange();
        }
		}
		catch(e){}
} 

function animateRooms(frm, i) {
    frm.find(".hc-lightgreybg-select").animate({
        opacity: 0.25
    }, "fast", function () {
        frm.find(".hc-lightgreybg-select").animate({
            opacity: 1
        }, "fast", function () {
            if (i <= 2) {
                i++;
                animateRooms(frm, i);
            }
        })
    });
} /** prototype to check if a string strats with another string **/
String.prototype.startsWith = function (str) {
    return (this.toLowerCase().indexOf(str.toLowerCase()) === 0);
} /** google map marker **/
String.prototype.trim = function () {
	if(typeof(this) != "undefined")
	{
		return this.replace(/^\s+|\s+$/g, '');
	}
	else
	{
		return '';
	}
}

function createMarker(map, latlng, property, markerOptions) {
    var marker = new GMarker(latlng, markerOptions);
    marker.value = 1;
    GEvent.addListener(marker, "click", function () {
		var r = "";
		if(property.rating > 0)
		{
			r = "<div class='rating_small'><span class='rbig'>"+property.rating+"%</span></div>";
		}
		var d = getParameter('d');
		if(d.trim != "")
		{
			d = "?d="+d;
		}
		else
		{
			d = "";
		}
        var myHtml = "<table cellpadding=0 cellspacing=0 width=290><tr><td rowspan='2' width=90 height=90 align=center><a href='" + _sys_url + _sys_lang + "/" + _sys_country + "/" + _sys_city + "/" + property.url + "/index.html"+d+"'><img src='"+_sys_url_static+"photos/small/" + property.thumbnail + "' width=80 height=80 border=0></a></td><td valign=top><a href='" + _sys_url + _sys_lang + "/" + _sys_country + "/" + _sys_city + "/" + property.url + "/index.html"+d+"'><b class='map_h_title'>" + property.title + "</b></a> ("+property.category+")<br/>" + property.address + "</td><td>"+r+"</td><td style='width:10px'></td></tr><tr><td colspan='2'><a onclick=\"trackit('map property action', '6 - click on read more and book', '"+property.title+"');\" rel=\"nofollow\" href='" + _sys_url + _sys_lang + "/" + _sys_country + "/" + _sys_city + "/" + property.url + "/index.html"+d+"' class=\"read_more_btn\">"+search_trans["map_read_more_label"]+"</a></td></table>";
        map.openInfoWindowHtml(latlng, myHtml);
    });
    return marker;
} /** Document onReady Event st_controller: Load the properties controllersliders: initialize the slider layouts jQuery corners: load the jQuery corners plugin**/
$(document).click(function () {
	$("#find_property").hide();
	$("#box").hide();
	$("#newsLetter").hide();
	hideToolTip('billinfo');
	//hideBookingFrame();
});
$(document).ready(function () {
    initializeSliders();
    $('.boxli, .tab, .rounded').corners("5px"); /**	hide all windows if any , when the document is clicked	**/
 /**	javascript search for the hostel by name , no ajax involved	**/
    $("#find_property_name").keyup(function () {
        $("#find_property").html("");
        if ($(this).val() == "") {
            $("#find_property").hide();
            return;
        }
        if (typeof(window.st_controller) != 'undefined') {
            if (window.st_controller.properties.length > 0) {
                for (var property_id in window.st_controller.properties) {
                        var m = document.getElementById("title_"+property_id);
						if(typeof(m) != "undefined" && m!= null)
						{
							if (m.innerHTML.trim().startsWith($(this).val().trim())) {
								$("#find_property").html($("#find_property").html() + "<a href='javascript:scrollTo(" + property_id + ")'>" + m.innerHTML + "</a>");
								$("#find_property").show();
							}
						}
                }
            }
        }
    }); /**	prettyphoto plugin settings	**/
    $("a[rel^='prettyPhoto']").prettyPhoto({
        animationSpeed: 'fast',
        padding: 40,
        opacity: 0.35,
        showTitle: true,
        allowresize: true,
        counter_separator_label: '/',
        theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
    });
}); /** Map Functions show_map :: show the map for the property if id is defined else it shows the overall map**/

function startprettyphoto(id)
{
    $("a[rel^='prettyPhoto"+id+"']").prettyPhoto({
        animationSpeed: 'fast',
        padding: 40,
        opacity: 0.35,
        showTitle: true,
        allowresize: true,
        counter_separator_label: '/',
        theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
    });
}
function show_map(property_id) {
    try {
        if (typeof(property_id) != 'undefined') {
            if (typeof(window.st_controller) != 'undefined') {
                var property = window.st_controller.properties[property_id];
                if (typeof(property) != "undefined") {
                    property.showMap();
                } else {
                    var json = _json_properties[property_id];
                    window.st_controller.properties[property_id] = new st_property(json);
                    window.st_controller.properties[property_id].showMap();
                }
            } else {
                window.st_controller = new st_controller();
                var property = window.st_controller.properties[property_id];
                if (typeof(property) != "undefined") {
                    property.showMap();
                } else {
                    var json = _json_properties[property_id];
                    window.st_controller.properties[property_id] = new st_property(json);
                    window.st_controller.properties[property_id].showMap();
                }
            }
        } else {
            if (typeof(window.st_controller) != 'undefined') {
                window.st_controller.showMap();
            } else {
                window.st_controller = new st_controller();
                window.st_controller.showMap();
            }
        }
    } catch (e) {
    }
} /** Map Functions hide_map :: hide the map**/


function hide_map() {
    var obj = document.getElementById('gMap');
    obj.style.display = 'none';
    GUnload();
} /** availability:: show the availability form if no dates are specified or remeber is false else it checks for property availability @param:: property_id (id of the property) @param:: remember (remembers the availability date and nights , true by default) **/


function availability(property_id, remember) {
    try {
		selectTab(2,property_id);
        if (typeof(window.st_controller) != 'undefined') {
            window.st_controller.checkAvailability(property_id);
            if (remember == false) {
                window.st_controller.remember = false;
            }
        } else {
            window.st_controller = new st_controller();
            window.st_controller.checkAvailability(property_id);
            if (remember == false) {
                window.st_controller.remember = false;
            }
        }
    } catch (e) {
    }
} /** checkAvailability:: checks for property availability, and updates the date settings (from the availability form) @param:: property_id (id of the property) **/


function checkAvailability(property_id) {
	selectTab(2,property_id);
    var frm = $("#frm_avail_" + property_id);
    var values = $("#frm_avail_" + property_id).serialize();
    var fields = $("#frm_avail_" + property_id).serializeArray();
    var info_date = new Array();
    var currentTime = new Date();
    info_date["giorno"] = currentTime.getDate();
    info_date["mese"] = currentTime.getMonth();
    info_date["anno"] = currentTime.getFullYear();
    info_date["notti"] = 1;
    for (var i = 0; i < fields.length; i++) {
        if (typeof(fields[i]["name"]) != "undefined" && typeof(fields[i]["value"]) != "undefined") {
            if (fields[i]["name"] == "giorno") {
                info_date["giorno"] = fields[i]["value"];
            } else if (fields[i]["name"] == "mese") {
                info_date["mese"] = fields[i]["value"];
            } else if (fields[i]["name"] == "anno") {
                info_date["anno"] = fields[i]["value"];
            } else if (fields[i]["name"] == "notti") {
                info_date["notti"] = fields[i]["value"];
            }
        }
    }
    if (typeof(window.st_controller) != 'undefined') {
        window.st_controller.setDate(info_date["giorno"], info_date["mese"], info_date["anno"]);
        window.st_controller.setNumberOfNights(info_date["notti"]);
        window.st_controller.checkAvailability(property_id);
    }
} /** checkAllAvailability:: checks All the properties for availability, and updates the date settings (from the availability form) **/
var properties_id = [];
var ia = 0;
var totalAvailable = 0;
var totalProperties = 0;
var totalhostels = 0;
var totalbabs = 0;
var totalguesthouse = 0;
var totalhotels = 0;
var totalapartment = 0;
var totalcamping = 0;

function checkAllAvailability(remember, custom_date) {
    properties_id = new Array();
    
    try {
        var day = 0;
        var month = 0;
        var year = 0;
        var nights = 1;
        if (typeof(custom_date) != "undefined") {
            var d = custom_date.split("-");
            if (d.length > 3) {
                day = parseInt(d[2], 10);
                month = parseInt(d[1], 10);
                year = parseInt(d[0], 10);
                nights = parseInt(d[3], 10);
            }
        } else {
            day = $("#giorno_all option:selected").val();
            month = $("#mese_all option:selected").val();
            year = $("#anno_all option:selected").val();
            nights = $("#notti_all option:selected").val();
        }
        if (typeof(window.st_controller) != 'undefined') {
            if (typeof(remember) == "undefined" || remember == false) {
				window.st_controller.setNumberOfNights(nights);
                window.st_controller.setDate(day, month, year);
            }
            
            for (var property_id in window.st_controller.properties) {
                properties_id[properties_id.length] = window.st_controller.properties[property_id].id;
            }
        } else {
            window.st_controller = new st_controller();
            if (typeof(remember) == "undefined" || remember == false) {
				window.st_controller.setNumberOfNights(nights);
                window.st_controller.setDate(day, month, year);
            }
            window.st_controller.setNumberOfNights(nights);
            for (var property_id in window.st_controller.properties) {
                properties_id[properties_id.length] = window.st_controller.properties[property_id].id;
            }
        }
    } catch (e) {
        window.st_controller = new st_controller();
        if (typeof(remember) == "undefined" || remember == false) {
            window.st_controller.setDate(day, month, year);
        }
        window.st_controller.setNumberOfNights(nights);
        for (var property_id in window.st_controller.properties) {
            properties_id[properties_id.length] = window.st_controller.properties[property_id].id;
        }
    }
    $("#ajaxrooms_all #all_msg").hide();
    $("#ajaxrooms_all .changedates").hide();
    $("#allworking").show();
    totalAvailable = 0;
    totalProperties = 0;
	totalhostels = 0;
	totalbabs = 0;
	totalguesthouse = 0;
	totalhotels = 0;
	totalapartment = 0;
	totalcamping = 0;
	ia = 0;
	window.st_controller.checkRangeAvailability();
	return;
} /** checkAll:: loop through all the available properties and check them for availability **/

function abortAll()
{
	ia = 99999;
}
var url_city = "";
function checkCityAvailability(city,country)
{
	try
	{
		var dt = window.st_controller.date;
		url_city = _sys_url + _sys_lang + "/" + country.toLowerCase() + "/" + city.toLowerCase() + "/search-index.html?d=" + dt.getFullYear() + "-" + (dt.getMonth()+1) + "-" + dt.getDate() + "-" + window.st_controller.nights;
		setTimeout( "window.location.href = url_city", 0 );
	}
	catch(e)
	{
	}
}

/** changeAvailabilityDate:: resets the availability date , and shows the availability form @param:: property_id (id of the property) **/


function changeAvailabilityDate(property_id) {
    try {
        if (typeof(window.st_controller) != 'undefined') {
            window.st_controller.changeDate(property_id);
        } else {
            window.st_controller = new st_controller();
            window.st_controller.changeDate(property_id);
        }
    } catch (e) {
    }
	trackit('change book date action', '12 - change date - rooms table ', window.st_controller.properties[property_id].title);
} 
function showMore()
{
    try {
        if (typeof(window.st_controller) != 'undefined') {
            window.st_controller.showMore();
        } else {
           window.st_controller.showMore();
        }
    } catch (e) {
    }
}

/** scrollTo::scroll to the position of the property in the page @param:: property_id (id of the property) **/


function scrollTo(property_id) {
    var s = $("#container_" + property_id);
    $('html, body').animate({
        scrollTop: s.offset().top - 10
    }, 'slow');
    $("#find_property").hide();
} /** showBillPanel::show the bill panel of the property @param:: property_id (id of the property) **/


function showBillPanel(property_id) {
    var values = window.st_controller.showBillPanel(property_id);
} /** checkRooms::check the rooms prior to the booking process @param:: property_id (id of the property) **/


function checkRooms(property_id) {
    var a = window.st_controller.checkRooms(property_id);
    if (a == true) {
        $('#formstRooms_' + property_id).submit();
		trackit('check rooms action', '8 - rooms selected', window.st_controller.properties[property_id].title);
    }
	else
	{
		trackit('check rooms action', '9 - rooms not selected', window.st_controller.properties[property_id].title);
	}
} 

function getPropertyReviews(property_id)
{
    try {
		selectTab(1,property_id);
        if (typeof(window.st_controller) != 'undefined') {
            window.st_controller.getPropertyReviews(property_id);
        } else {
            window.st_controller = new st_controller();
            window.st_controller.getPropertyReviews(property_id);
        }
    } catch (e) {
    }
}
function getPropertyDescription(property_id)
{
    try {
		selectTab(0,property_id);
        if (typeof(window.st_controller) != 'undefined') {
            window.st_controller.getPropertyDescription(property_id);
        } else {
            window.st_controller = new st_controller();
            window.st_controller.getPropertyDescription(property_id);
        }
    } catch (e) {
    }
}

function selectTab(index,id)
{
	for(var i=0;i<3;i++)
	{
		var d= document.getElementById("tab-"+i+"-"+id);
		if(typeof(d)!= 'undefined' && d!=null)
		{
			if(i==index)
			{
				d.className = "active_list";
			}
			else
			{
				d.className="";
			}
		}
	}
}
/** country_change_sel::loads the cities when the country selection is changed on the top form @param:: id (id of the country) @param:: sel (optional , city id) **/


function country_change_sel(id, sel) {
    try {
        if (typeof(window.st_search) != 'undefined') {
            window.st_search.countryChange(id, sel);
        } else {
            window.st_search = new st_search();
            window.st_search.countryChange(id, sel);
        }
    } catch (e) {
	try
	{
        window.st_search = new st_search();
        window.st_search.countryChange(id, sel);
		}
		catch(e){}
}
}
function country_change(id) {
    country_change_sel(id, '');
} /** search:: find the cities and list them on the top form **/
var t = null;

function search() {
    $("#box").html("<span>Searching...</span>");
    $("#box").show("slow");
    try {
        if (typeof(window.st_search) != 'undefined') {
            if (t != null) {
                clearTimeout(t);
            }
            t = setTimeout("window.st_search.search()", 300);
        } else {
            window.st_search = new st_search();
            if (t != null) {
                clearTimeout(t);
            }
            t = setTimeout("window.st_search.search()", 300);
        }
    } catch (e) {
    }
} /** selectCityCountry::select the country and it's city @param::city_id(id of the city) @param::country_id(id of the country) **/


function selectCityCountry(city_id, country_id) {
    try {
        if (typeof(window.st_search) != 'undefined') {
            window.st_search.selectCountryCity(city_id, country_id);
            $("#text_content").val("");
        } else {
            window.st_search = new st_search();
            window.st_search.selectCountryCity(city_id, country_id);
            $("#text_content").val("");
        }
    } catch (e) {
    }
} /** getDaysInMonth::returns the total days in month , year @param::iMonth(month) @param::iYear(year) **/


function getDaysInMonth(iMonth, iYear) {
    var days = 32 - new Date(iYear, iMonth - 1, 32).getDate();
    return days;
} /** fixDates::fix the dates for the given selects @param::day (the select date day id) @param::month (the select date month id) @param::yeat (the select date year id) **/


function fixDates(day, month, year) {
    var iMonth = $("#" + month).find("option:selected").val();
    var iYear = $("#" + year).find("option:selected").val();
    var iDay = $("#" + day).find("option:selected").val();
    var days = getDaysInMonth(iMonth, iYear);
    $("#" + day).find("option").remove();
    var found = false;
    for (var i = 1; i <= days; i++) {
        if (iDay == i) {
            found = true;
            $("#" + day).append('<option selected="selected" value="' + i + '">' + i + '</option>');
        } else {
            if (i == days && found == false) {
                $("#" + day).append('<option selected="selected" value="' + i + '">' + i + '</option>');
            } else {
                $("#" + day).append('<option value="' + i + '">' + i + '</option>');
            }
        }
    }
} /** gotoBooking:: check the top form for valid dates and submit them  **/


function gotoBooking() {
    if ($("#dCountry option:selected").val() == 0) {
        alert("Please select a valid country");
        return false;
    }
    if ($("#dCountry option:selected").val() == 0) {
        alert("Please select a valid city");
        return false;
    }
    var year = parseInt($("#dDateY option:selected").val(),10);
    var month = parseInt($("#dDateM option:selected").val(),10);
    var day = parseInt($("#dDateD option:selected").val(),10);
    var d = new Date(year, month - 1, day + 1);
    var today = new Date();
    if (today <= d) {
        return true;
    } else {
        alert(search_trans["alert_invalid_date"]);
        return false;
    }
}

function startSearching() {
    try {
        if (typeof(window.st_search) != 'undefined') {
            window.st_search.selectCountryCity();
            return window.st_search.startSearching();
        } else {
            window.st_search = new st_search();
            return window.st_search.startSearching();
        }
    } catch (e) {
    }
}

function getParameter(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null) return "";
    else return results[1];
} /** submitIframe::submit the request of the reservation to an iframe instead of a new window @param::frm (the form to submit) **/

var idframe = false;
function submitIframe(frm) {
		if(frm != null)
		{
			idframe = frm.id;
		}
		else
		{
			idframe = false;
		}
        document.getElementById("bookingframe").innerHTML = "<center><div class='close_frame'><a href='javascript:hideBookingFrame();'><span style='font-size:15px'><b>CLOSE</b> </span><img src='images/imageclose.gif'/></a></div><iframe class='book_frame' src='https://www.hostelspoint.com' name='bookframe'></iframe><center><div class='close_frame'><a href='javascript:hideBookingFrame();'><span style='font-size:15px'><b>CLOSE</b> </span><img src='images/imageclose.gif'/></a></div></center>";
        document.getElementById("bookingframe").style.display = "block";
		document.getElementById("backgroundframe").style.display = "block";
		document.getElementById("main").style.display = "none";
		   $('html, body').animate({
            scrollTop: 0
        }, 'slow');
        return true;
} /** hideBookingFrame::hide the booking iframe **/


function hideBookingFrame() {
    document.getElementById("bookingframe").style.display = "none";
	document.getElementById("backgroundframe").style.display = "none";
	document.getElementById("main").style.display = "block";
	if(idframe != false)
	{
		var m = $("#" + idframe);
		if(m != null)
		{
			var top = m.offset().top;
			$('html, body').animate({scrollTop: top - 100}, 'slow');
		}
	}
} /** scrollup::scrolls to the top of the page **/


function scrollup() {
    var top = $(".orng_full_btn").first().offset().top;
    $('html, body').animate({
        scrollTop: top - 10
    }, 'slow');
    try {
        if (typeof(window.st_controller) != 'undefined') {
            for (var property_id in window.st_controller.properties) {
                availability(property_id, true);
                return;
            }
        } else {
            window.st_controller = new st_controller();
            for (var property_id in window.st_controller.properties) {
                availability(property_id, true);
                return;
            }
        }
    } catch (e) {
        }
} /** map_show::show the overall map (right top of the screen map) **/


function map_show() {
    try {
        if (typeof(window.st_controller) != 'undefined') {
            window.st_controller.showMap();
        } else {
            window.st_controller = new st_controller();
            window.st_controller.showMap();
        }
    } catch (e) {
    }
}
/** filterRange::filter the range selected(price private range, price shared range and rating range) **/


function filterRange() {
    try {
        var pprange = $("#ppricep").val().split("-");
        var psrange = $("#pprices").val().split("-");
        var prrange = $("#prating").val().split("-");
        if (typeof(window.st_controller) != 'undefined') {
            if (pprange.length == 2) {
                window.st_controller.setPricePRange(pprange[0], pprange[1]);
            }
            if (psrange.length == 2) {
                window.st_controller.setPriceSRange(psrange[0], psrange[1]);
            }
            if (prrange.length == 2) {
                window.st_controller.setRatingRange(prrange[0], prrange[1]);
            }
            window.st_controller.filterByRange();
        } else {
            window.st_controller = new st_controller();
            if (pprange.length == 2) {
                window.st_controller.setPricePRange(pprange[0], pprange[1]);
            }
            if (psrange.length == 2) {
                window.st_controller.setPriceSRange(psrange[0], psrange[1]);
            }
            if (prrange.length == 2) {
                window.st_controller.setRatingRange(prrange[0], prrange[1]);
            }
            window.st_controller.filterByRange();
        }
        //$(item).attr("class", "active");
		trackit('filter action', '11 - change filter range', 'pp_range('+pprange[0]+','+ pprange[1]+') - ps_range('+psrange[0]+','+ psrange[1]+') - prating_range('+prrange[0]+','+ prrange[1]+')');
    } catch (e) {}
} /** showNewsLetter::show the news letter iframe **/
function toggle_category(item , category)
{
	var properties = window.st_controller.properties;
	if(category == "hostel")
	{
		if(item.checked == true)
		{
			for(var id in properties)
			{
				var pid = properties[id].id;
				var cat = document.getElementById("category_"+ pid);
				if(cat != null && typeof(cat)!= "undefined")
				{
					if(cat.innerHTML.trim().toLowerCase() == "hostel")
					{
						$("#container_"+pid).css("display","block");
					}
				}
			}
		}
		else
		{
			for(var id in properties)
			{
				var pid = properties[id].id;
				var cat = document.getElementById("category_"+ pid);
				if(cat != null && typeof(cat)!= "undefined")
				{
					if(cat.innerHTML.trim().toLowerCase() == "hostel")
					{
						$("#container_"+pid).css("display","none");
					}
				}
			}
		}
	}
	if(category == "hotel")
	{
		if(item.checked == true)
		{
			for(var id in properties)
			{
				var pid = properties[id].id;
				var cat = document.getElementById("category_"+ pid);
				if(cat != null && typeof(cat)!= "undefined")
				{
					if(cat.innerHTML.trim().toLowerCase() == "hotel")
					{
						$("#container_"+pid).css("display","block");
					}
				}
			}
		}
		else
		{
			for(var id in properties)
			{
				var pid = properties[id].id;
				var cat = document.getElementById("category_"+ pid);
				if(cat != null && typeof(cat)!= "undefined")
				{
					if(cat.innerHTML.trim().toLowerCase() == "hotel")
					{
						$("#container_"+pid).css("display","none");
					}
				}
			}
		}
	}
	if(category == "bed_and_breakfast")
	{
		if(item.checked == true)
		{
			for(var id in properties)
			{
				var pid = properties[id].id;
				var cat = document.getElementById("category_"+ pid);
				if(cat != null && typeof(cat)!= "undefined")
				{
					if(cat.innerHTML.trim().toLowerCase() == "bed_and_breakfast")
					{
						$("#container_"+pid).css("display","block");
					}
				}
			}
		}
		else
		{
			for(var id in properties)
			{
				var pid = properties[id].id;
				var cat = document.getElementById("category_"+ pid);
				if(cat != null && typeof(cat)!= "undefined")
				{
					if(cat.innerHTML.trim().toLowerCase() == "bed_and_breakfast")
					{
						$("#container_"+pid).css("display","none");
					}
				}
			}
		}
	}
	if(category == "apartment")
	{
		if(item.checked == true)
		{
			for(var id in properties)
			{
				var pid = properties[id].id;
				var cat = document.getElementById("category_"+ pid);
				if(cat != null && typeof(cat)!= "undefined")
				{
					if(cat.innerHTML.trim().toLowerCase() == "apartment")
					{
						$("#container_"+pid).css("display","block");
					}
				}
			}
		}
		else
		{
			for(var id in properties)
			{
				var pid = properties[id].id;
				var cat = document.getElementById("category_"+ pid);
				if(cat != null && typeof(cat)!= "undefined")
				{
					if(cat.innerHTML.trim().toLowerCase() == "apartment")
					{
						$("#container_"+pid).css("display","none");
					}
				}
			}
		}
	}
	if(category == "guest_house_limited_service")
	{
		if(item.checked == true)
		{
			for(var id in properties)
			{
				var pid = properties[id].id;
				var cat = document.getElementById("category_"+ pid);
				if(cat != null && typeof(cat)!= "undefined")
				{
					if(cat.innerHTML.trim().toLowerCase() == "guest_house_limited_service")
					{
						$("#container_"+pid).css("display","block");
					}
				}
			}
		}
		else
		{
			for(var id in properties)
			{
				var pid = properties[id].id;
				var cat = document.getElementById("category_"+ pid);
				if(cat != null && typeof(cat)!= "undefined")
				{
					if(cat.innerHTML.trim().toLowerCase() == "guest_house_limited_service")
					{
						$("#container_"+pid).css("display","none");
					}
				}
			}
		}
	}
	if(category == "camping")
	{
		if(item.checked == true)
		{
			for(var id in properties)
			{
				var pid = properties[id].id;
				var cat = document.getElementById("category_"+ pid);
				if(cat != null && typeof(cat)!= "undefined")
				{
					if(cat.innerHTML.trim().toLowerCase() == "camping")
					{
						$("#container_"+pid).css("display","block");
					}
				}
			}
		}
		else
		{
			for(var id in properties)
			{
				var pid = properties[id].id;
				var cat = document.getElementById("category_"+ pid);
				if(cat != null && typeof(cat)!= "undefined")
				{
					if(cat.innerHTML.trim().toLowerCase() == "camping")
					{
						$("#container_"+pid).css("display","none");
					}
				}
			}
		}
	}
	trackit(' filter ', '16 - filter by '+ category, category);
}
var redirectlnk = "";
function redirectBooking(lnk)
{
	redirectlnk = lnk;
	setTimeout('window.location.href = redirectlnk',3000);
}
function showNewsLetter() {
    $("#newsLetter").hide();
    $("#newsLetter").html("<iframe src='newsletter.html'></iframe>");
    $("#newsLetter").show("slow");
}

function showFaderDiv(html)
{
	$("#newsLetter").hide();
    $("#newsLetter").html(html);
    $("#newsLetter").show("slow");
}

function hide_div(id) {
    $("#" + id).hide();
} /** **/


function showFeedback() {
    $("#iframe-feedback").show("slow");
}

function submitFeedbackForm()
{
	$("#feedbackformbt").hide();
	$("#feedback_msg").hide();
	$("#fb_loading").show();
	var name = $("#id_name").val();
	var email = $("#id_email").val();
	var txt = $("#id_text").val();
	if(name.trim() == "")
	{
		$("#fb_loading").hide();
		$("#feedbackformbt").show();
		$("#feedback_msg").html(search_trans["feedback_invalid_name"]);
		$("#feedback_msg").show();
		return;
	}
	else if(!checkemail(email))
	{
		$("#fb_loading").hide();
		$("#feedbackformbt").show();
		$("#feedback_msg").html(search_trans["feedback_invalid_email"]);
		$("#feedback_msg").show();
		return;
	}
	else if(txt.trim() == "")
	{
		$("#fb_loading").hide();
		$("#feedbackformbt").show();
		$("#feedback_msg").html(search_trans["feedback_invalid_text"]);
		$("#feedback_msg").show();
		return;
	}
	var dataString = "name="+name+"&email="+email+"&text="+txt+"&submit_but=1";
	$.ajax({  
	  type: "POST",  
	  url: "feedback/index.php",  
	  data: dataString,  
	  success: function(msg) {  
	  if(msg.trim() !=="")
	  {
		var json = eval('('+msg+')');
		if(typeof(json.value) != "undefined")
		{
			if(typeof(json.msg) != "undefined")
			{
				$("#fb_loading").hide();
				$("#feedbackformbt").show();
				$("#feedback_msg").html(json.msg);
				$("#feedback_msg").show();
				return
			}
		}
	  }
	  return  
	  },
	  error:function(){
	  $("#fb_loading").hide();
	  $("#feedbackformbt").show();
	  $("#feedback_msg").html("unknown Error");
	  $("#feedback_msg").show();
	  }
	  
	  
	  });
}

function checkemail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str))
	{
		return true;
	}
	return false;
}

function hide_div(id) {
    $("#" + id).hide();
	$("#but_"+id).css("display","");
} /** **/
/** **/
var timeout = -1;

function showToolTip(id) {
    $("#" + id).show("slow");
    if (timeout == -1) {
        timeout = setTimeout("hideToolTip('" + id + "')", 5000);
    }
}

function hideToolTip(id) {
    $("#" + id).hide("slow");
    timeout = -1;
} /** trackit::track the events @param:: a @param::b @param::c @param::d **/


function trackit(a, b, c, d) {
    if (d > -1) {
        _gaq.push(['_trackEvent',_sys_lang+" - " + page_at + " page - " + a, b, c, d]);
    } else {
        _gaq.push(['_trackEvent', _sys_lang+" - " + page_at + " - " + a, b, c]);
    }
	//alert(_sys_lang+" - " + page_at + " page - " + a + ' | ' + b + ' | ' + c + ' | ' + d);
} 
function showMsg(msg)
{
	var m = document.getElementById("error_msg");
	if(m != null)
	{
		m.innerHTML = msg;
		m.style.display = "block";
	}
}
function hideMsg()
{
	var m = document.getElementById("error_msg");
	if(m != null)
	{
		m.innerHTML = "";
		m.style.display = "none";
	}
}

/** initializeSliders::initialize the range sliders **/



function initializeSliders() {
    var sliders = {
        sliders: false,
        data: false,
        init: function (data) {
            this.data = data;
            for (q = 0; q < data.length; q++) this.make(data[q]);
        },
        make: function (data) {
            var s;
            step = Math.round(data.max / (data.values[1] - data.values[0]));
            s = YAHOO.widget.Slider.getHorizDualSlider("sliderbg" + data.id, "minthumb" + data.id, "maxthumb" + data.id, data.max, step, data.range);
            s.subscribe('ready', this.report);
            s.subscribe('change', this.report);
            s.subscribe("slideEnd", this.send);
            this.sliders[data.id] = s;
        },
        report: function (s) {
            var id = s.activeSlider.toString().substring(23, 24);
            step = Math.round(sliders.data[id].max / (sliders.data[id].values[1] - sliders.data[id].values[0]));
            mi = Math.round(sliders.data[id].values[0] + ((this.minVal / sliders.data[id].max) * (sliders.data[id].values[1] - sliders.data[id].values[0])));
            ma = Math.round(sliders.data[id].values[0] + ((this.maxVal / sliders.data[id].max) * (sliders.data[id].values[1] - sliders.data[id].values[0])));
            document.getElementById("sliderstatusi" + id).innerHTML = mi;
            document.getElementById("sliderstatusa" + id).innerHTML = ma;
            document.getElementById(sliders.data[id].field).value = mi + '-' + ma;
        },
        send: function (s) {
            filterRange();
        },
        realval: function (id, fmin, fmax) {
            mi = fmin * sliders.data[id].values[1] / sliders.data[id].max;
            ma = fmax * sliders.data[id].values[1] / sliders.data[id].max;
        }
    }
    sliders.init([{
        id: 0,
        max: 180,
        step: 0,
        range: [0, 180],
        values: [0, 200],
        field: "ppricep"
    },
    {
        id: 1,
        max: 180,
        step: 0,
        range: [0, 180],
        values: [0, 50],
        field: "pprices"
    },
    {
        id: 2,
        max: 180,
        step: 0,
        range: [0, 180],
        values: [0, 100],
        field: "prating"
    }]);
}

var current = 0;
var img_count = 0;
function loop_fader()
{
	
	if(typeof(js_fader_top) != undefined)
	{
		var html = "";
		for(var i = 0;i< js_fader_top.length;i++)
		{
			var new_window = "";
			if(js_fader_top[i].new_window == true)
			{
				new_window = " target='_blank' ";
			}
			var link = js_fader_top[i].url;
			if(js_fader_top[i].link == false)
			{
				link = "javascript:showFaderDiv(\""+ js_fader_top[i].content.replace(/'/g, "&rsquo;") +"\");";
			}
			var on_click = js_fader_top[i].click_event;
			html = html + "<div id='fader_"+i+"' style='position:absolute;overflow:hidden;'><a "+ new_window +" onclick='" + on_click + "' href='"+ link +"'>"+js_fader_top[i].name +"</a></div>";
		}
		img_count = js_fader_top.length - 1;
		$( "#box-nl" ).html(html + "<div id='newsLetter'></div>");
	}
	if(img_count > 0)
	{
		show_image();
	}
}
function show_image()
{
    for(var j =0 ;j<= img_count; j++)
    {
        if(current == j)
        {
			$( "#fader_" + j + " a").css('background-image','url("'+js_fader_top[j].img+'")');
			$( "#fader_" + j).css('display','block');
            $( "#fader_" + j ).animate({'opacity':1},1000); 
			
        }
		else
		{
			$( "#fader_" + j ).animate({'opacity':0},1000,function(){$( this).css('display','none');}); 
		}
    }
    if( current == img_count)
    {
        current = 0;
    }
    else
    {
        current ++;
    }
	setTimeout('show_image()',5000);
}
