var TAGS_WITH_CONTEXT_MENU=['a','input','textarea','button','img'];

function getMsg(msgCode)
{
 var msg="";
 if(msgHash[msgCode])
 {
  msg=msgHash[msgCode];
 }
 else
 {
  msg=msgCode;
 };
 return msg;
};
function clearElement(element)
{
 if(element)
 {
  while (element.childNodes[0]) {
    element.removeChild(element.childNodes[0]);
  };
 };
};
function addToMyFavourites(propertyId)
{
	var form=$("form");
	form.attr("method","post");
	form.attr("action","/customer/my-favourites/add/"+propertyId+"/");
	$("body").append(form);
	
	form[0].submit();
};
function removeFromMyFavourites(propertyId)
{
	var form=$("form");
	form.attr("method","post");
	form.attr("action","/customer/my-favourites/remove/"+propertyId+"/");
	$("body").append(form);
	
	form[0].submit();
};
function requestFormSendMessage()
{
	var name="";
	var email="";
	var telephone="";
	var comments="";
	
	var nodeRequestFormName=document.getElementById("requestFormName");
	if(nodeRequestFormName)
		name=nodeRequestFormName.value;
	
	var nodeRequestFormEmail=document.getElementById("requestFormEmail");
	if(nodeRequestFormEmail)
		email=nodeRequestFormEmail.value;

	var nodeRequestFormTelephone=document.getElementById("requestFormTelephone");
	if(nodeRequestFormTelephone)
		telephone=nodeRequestFormTelephone.value;
	
	var nodeRequestFormComments=document.getElementById("requestFormComments");
	if(nodeRequestFormComments)
		comments=nodeRequestFormComments.value;

	msgArr=Array();
	if(name.length==0)
		msgArr[msgArr.length]=getMsg("err_blank_name");

	var matches=email.match("^\\s*\\S+\\@\\S+\\s*$");
	if(matches==null)
		msgArr[msgArr.length]=getMsg("err_email_format");

	if(telephone.length==0)
		msgArr[msgArr.length]=getMsg("err_blank_telephone");

	if(msgArr.length>0){
		var str="";
		for(var i=0;i<msgArr.length;i++){
			str+=msgArr[i];
			if(i<msgArr.length-1)
				str+="\n";
		};
		alert(str);
	}else{
		$.ajax({
			type: 'POST',
			url: '/json/message/',
			data: {
				name:name,
				email:email,
				telephone:telephone,
				comments:comments
			},
			success: function(data, textStatus, jqXHR) {
				alert(getMsg("requestSendMessageOnSuccess"));
			},
			error: function(jqXHR, textStatus, errorThrown) {
				var obj = jQuery.parseJSON(jqXHR.responseText);
				alert(getMsg(obj.faultstring));
			},
			dataType: "json",
			contentType: "application/x-www-form-urlencoded; charset=UTF-8"
		});
	};
};
//---------------------------------------
SearchForm=function(){
	this.saleRent=null;
	this.propertyTypeRent=null;
	this.propertyTypeSale=null;
	this.location=null;
	
	/**
	 * Location urlpart < Area SearchForm
	 */
	this.areas={};

	this.bedrooms=null;
	this.bathrooms=null;
	this.sleepsMax=null;

	this.arrival=null;
	this.departure=null;

	this.shortRentPriceMin=null;
	this.shortRentPriceMax=null;

	this.longRentPriceMin=null;
	this.longRentPriceMax=null;

	this.salePriceMin=null;
	this.salePriceMax=null;
	
	this.checkboxes=$("#searchFormCheckboxes");
	this.freeWiFi=this.checkboxes.find('input[name="freeWiFi"]');
	this.seaView=this.checkboxes.find('input[name="seaView"]');
	this.seaFront=this.checkboxes.find('input[name="seaFront"]');
	
	this.search=$(".search-form-button button");
	
	this.search.click(
		$.proxy(
			function(){
				this.submit();
			},
			this
		)
	);
};
SearchForm.prototype.registerSaleRent=function(saleRent){
	this.saleRent=saleRent;
};
SearchForm.prototype.registerPropertyTypeRent=function(propertyTypeRent){
	this.propertyTypeRent=propertyTypeRent;
};
SearchForm.prototype.registerPropertyTypeSale=function(propertyTypeSale){
	this.propertyTypeSale=propertyTypeSale;
};
SearchForm.prototype.registerLocation=function(loc){
	this.location=loc;
};
SearchForm.prototype.registerAreas=function(areas){
	this.areas=areas;
};
SearchForm.prototype.registerBedrooms=function(bedrooms){
	this.bedrooms=bedrooms;
};
SearchForm.prototype.registerBathrooms=function(bathrooms){
	this.bathrooms=bathrooms;
};
SearchForm.prototype.registerSleepsMax=function(sleepsMax){
	this.sleepsMax=sleepsMax;
};
SearchForm.prototype.registerArrival=function(arrival){
	this.arrival=arrival;
};
SearchForm.prototype.registerDeparture=function(departure){
	this.departure=departure;
};
SearchForm.prototype.registerShortRentPriceMin=function(shortRentPriceMin){
	this.shortRentPriceMin=shortRentPriceMin;
};
SearchForm.prototype.registerShortRentPriceMax=function(shortRentPriceMax){
	this.shortRentPriceMax=shortRentPriceMax;
};
SearchForm.prototype.registerLongRentPriceMin=function(longRentPriceMin){
	this.longRentPriceMin=longRentPriceMin;
};
SearchForm.prototype.registerLongRentPriceMax=function(longRentPriceMax){
	this.longRentPriceMax=longRentPriceMax;
};
SearchForm.prototype.registerSalePriceMin=function(salePriceMin){
	this.salePriceMin=salePriceMin;
};
SearchForm.prototype.registerSalePriceMax=function(salePriceMax){
	this.salePriceMax=salePriceMax;
};
SearchForm.prototype.select=function(cmp,value){
	this.refreshVisibility();
};
SearchForm.prototype.refreshVisibility=function(){
	var saleRent=this.saleRent.getValue();
	
	this.propertyTypeRent.setVisibility(saleRent == 'SHORT_RENT' || saleRent == 'LONG_RENT');
	this.propertyTypeSale.setVisibility(saleRent == 'SALE');
	
	var locationUrlpart=this.location.getValue();
	for(currentLocationUrlpart in this.areas){
		var areaBox=this.areas[currentLocationUrlpart];
		areaBox.setVisibility(currentLocationUrlpart == locationUrlpart);
	}
	
	this.sleepsMax.setVisibility(saleRent == 'SHORT_RENT' || saleRent == 'LONG_RENT');
	var sleepsMaxLine=this.sleepsMax.getBox().parent();
	if(saleRent == 'SHORT_RENT' || saleRent == 'LONG_RENT'){
		sleepsMaxLine.removeClass("lineFor2");
		sleepsMaxLine.addClass("lineFor3");
	}else{
		sleepsMaxLine.removeClass("lineFor3");
		sleepsMaxLine.addClass("lineFor2");
	}
	
	var periodLine=this.arrival.getBox().parent();
	if(saleRent == 'SHORT_RENT'){
		periodLine.removeClass("hidden");
	}else{
		periodLine.addClass("hidden");
	}

	var shortRentPriceLine=this.shortRentPriceMin.getBox().parent();
	if(saleRent == 'SHORT_RENT'){
		shortRentPriceLine.removeClass("hidden");
	}else{
		shortRentPriceLine.addClass("hidden");
	}

	var longRentPriceLine=this.longRentPriceMin.getBox().parent();
	if(saleRent == 'LONG_RENT'){
		longRentPriceLine.removeClass("hidden");
	}else{
		longRentPriceLine.addClass("hidden");
	}

	var salePriceLine=this.salePriceMin.getBox().parent();
	if(saleRent == 'SALE'){
		salePriceLine.removeClass("hidden");
	}else{
		salePriceLine.addClass("hidden");
	}
	
	if(saleRent == 'SHORT_RENT' || saleRent == 'LONG_RENT'){
		this.checkboxes.removeClass("hidden");
	}else{
		this.checkboxes.addClass("hidden");
	}
};
SearchForm.prototype.submit=function(){
	try{
		var saleRent=this.saleRent.getValue();
		
		var path='/search/';
		var typeUrlpart=null;
		switch(saleRent)
		{
			case 'SALE':
				path+='sale/';
				typeUrlpart=this.propertyTypeSale.getValue();
				break;
			case 'SHORT_RENT':
				path+='rent/';
				typeUrlpart=this.propertyTypeRent.getValue();
				break;
			case 'LONG_RENT':
				path+='longtermrent/';
				typeUrlpart=this.propertyTypeRent.getValue();
				break;
			default:
				throw new Error(locale['fillInInterestedIn']);
		};
		
		if(typeUrlpart)
			path+='type/'+typeUrlpart+'/';

		var bedrooms=this.bedrooms.getValue();
		if(bedrooms)
			path+='bedrooms/'+bedrooms+'/';
		
		var bathrooms=this.bathrooms.getValue();
		if(bathrooms)
			path+='bathrooms/'+bathrooms+'/';
		
		if(saleRent=='SHORT_RENT' || saleRent=='LONG_RENT')
		{
			var sleepsMax=this.sleepsMax.getValue();
			if(sleepsMax)
				path+='sleepsmax/'+sleepsMax+'/';
		};

		var locationUrlpart=this.location.getValue();
		if(locationUrlpart){
			path+='location/'+locationUrlpart+'/';
			var area=this.areas[locationUrlpart].getValue();
			if(area)
				path+='area/'+area+'/';
		}

		if(saleRent=='SALE')
		{
			var salePriceMin=this.salePriceMin.getValue();
			if(salePriceMin)
				path+='pricefrom/'+salePriceMin+'/';

			var salePriceMax=this.salePriceMax.getValue();
			if(salePriceMax)
				path+='priceto/'+salePriceMax+'/';
		};

		if(saleRent=='SHORT_RENT')
		{
			var periodFrom=this.arrival.getValue();
			if(periodFrom)
			{
				var year = periodFrom.getFullYear().toString();
				var month = (periodFrom.getMonth() + 1).toString(); month = (month.length == 1) ? "0" + month : month;
				var date = periodFrom.getDate().toString(); date = (date.length == 1) ? "0" + date : date;
				var periodFromStr=year + "-" + month + "-" + date;
				path+='arrival/'+periodFromStr+'/';
			};

			var periodTo=this.departure.getValue();
			if(periodTo)
			{
				var year = periodTo.getFullYear().toString();
				var month = (periodTo.getMonth() + 1).toString(); month = (month.length == 1) ? "0" + month : month;
				var date = periodTo.getDate().toString(); date = (date.length == 1) ? "0" + date : date;
				var periodToStr=year + "-" + month + "-" + date;
				path+='departure/'+periodToStr+'/';
			};

			var priceRentFrom=this.shortRentPriceMin.getValue();
			if(priceRentFrom)
				path+='pricefrom/'+priceRentFrom+'/';

			var priceRentTo=this.shortRentPriceMax.getValue();
			if(priceRentTo)
				path+='priceto/'+priceRentTo+'/';
		};

		if(saleRent=='LONG_RENT')
		{
			var longRentPriceMin=this.longRentPriceMin.getValue();
			if(longRentPriceMin)
				path+='pricefrom/'+longRentPriceMin+'/';

			var longRentPriceMax=this.longRentPriceMax.getValue();
			if(longRentPriceMax)
				path+='priceto/'+longRentPriceMax+'/';
		};

		if(saleRent=='SHORT_RENT' || saleRent=='LONG_RENT'){
			var freeWiFi=this.freeWiFi[0].checked;
			if(freeWiFi)
				path+='freewifi/1/';

			var seaView=this.seaView[0].checked;
			if(seaView)
				path+='seaview/1/';

			var firstBeachLine=this.seaFront[0].checked;
			if(firstBeachLine)
				path+='firstline/1/';
		};
	
		location.href=path;
	}
	catch(e)
	{
		alert(e);
	};

	return false;
};

SelectBox=function(name,med){
	this.name=name;
	this.med=med;
	
	this.box=$("#selectBox"+this.name);
	this.valueInput=this.box.find("input");
	this.selectButton=this.box.find(".selectButton");
	this.selectField=this.box.find(".selectField");
	this.list=this.box.find("ul");
	
	this.selectButton.click($.proxy(this.toggle,this));
	this.selectField.click($.proxy(this.toggle,this));
	
	var items=this.list.find("li");
	items.click(
		$.proxy(
			function(event){
				var targetDom=event.target;
				var value=targetDom.id.substr(13+this.name.length);
				if(value != this.valueInput.val()){
					var target=$(targetDom);
					var text=target.text();
					
					this.valueInput.val(value);
					this.selectField.text(text);
					
					this.med.select(this,value);
				}
				this.close();
			},
			this
		)
	);
	
	$("body").click(
		$.proxy(
			function(event){
				var target=$(event.target);
				if(target.closest("#"+this.box[0].id).length == 0)
					this.close();
			},
			this
		)
	);
};
SelectBox.prototype.open=function(){
	this.list.removeClass("hidden");
	
	this.list.find("li").removeClass("hover");
	this.list.find("#selectList"+this.name+"Li_"+this.valueInput.val()).addClass("hover");
};
SelectBox.prototype.close=function(){
	this.list.addClass("hidden");
};
SelectBox.prototype.isOpened=function(){
	return !this.list.hasClass("hidden");
};
SelectBox.prototype.show=function(){
	this.box.removeClass("hidden");
};
SelectBox.prototype.hide=function(){
	this.box.addClass("hidden");
};
SelectBox.prototype.toggle=function(){
	if(this.isOpened())
		this.close();
	else
		this.open();
};
SelectBox.prototype.setVisibility=function(visibility){
	if(visibility)
		this.show();
	else
		this.hide();
};
SelectBox.prototype.getValue=function(){
	return this.valueInput.val();
};
SelectBox.prototype.getBox=function(){
	return this.box;
};

DatePicker=function(name,med){
	this.name=name;
	this.med=med;
	
	this.box=$("#selectBox"+this.name);
	this.selectButton=this.box.find(".selectButton");
	this.selectField=this.box.find(".selectField");
	this.valueInput=this.selectField.find("input");
	
	this.valueInput.datepicker({
		dateFormat:'dd/mm/yy',
		showOtherMonths: true,
		selectOtherMonths: true,
		changeMonth: true,
		changeYear: true
	});
	
	this.selectButton.click(
		$.proxy(
			function(){
				this.valueInput.datepicker("show");
			},
			this
		)
	);
	
	this.valueInput.blur(
		$.proxy(
			function(){
				var val=this.valueInput.val();
				if(val == null || val.length == 0)
					this.valueInput.val(this.name+"...");
			},
			this
		)
	);
};
DatePicker.prototype.getBox=function(){
	return this.box;
};
DatePicker.prototype.getValue=function(){
	var dateStr=this.valueInput.val();
	return checkDate(dateStr);
};

/**
 * Returns Date instance if dateStr is correct date in dd/MM/yyyy format.
 * Returns null otherwise.
 * @param dateStr
 * @returns
 */
function checkDate(dateStr){
	var date=null;
	
	try{
		var matches=/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.exec(dateStr);
		if(matches == null || matches.length != 4)
			throw new Error("Wrong date format.");
		
		var day=parseInt(matches[1],10);
		var month=parseInt(matches[2],10);
		var year=parseInt(matches[3],10);
		
		var tmp=new Date(year,month-1,day,0,0,0,0);
		
		if(tmp.getFullYear() != year || tmp.getMonth()+1 != month || tmp.getDate() != day)
			throw new Error("Wrong date.");
		
		date=tmp;
	}catch(e){
	}
	
	return date;
};

//------------listeners------------------
function mainMenuOnMousOver(elem)
{
 elem.className="selected";
};
function mainMenuOnMousOut(elem)
{
 elem.className="";
};
function mainMenuOnClick(elem)
{
 for(var i=0;i<elem.parentNode.childNodes.length;i++)
 {
  if(elem.parentNode.childNodes[i].nodeName.toLowerCase()=="ul")
  {
   var nodeUl=elem.parentNode.childNodes[i];
   if(nodeUl.style.display==""||nodeUl.style.display=="none") nodeUl.style.display="block";
   else nodeUl.style.display="none";
  };
 };
};
function showBigImage(node,imgSrc)
{
 var nodePropertyBigImage=document.getElementById("propertyBigImage");
 if(nodePropertyBigImage)
 {
  clearElement(nodePropertyBigImage);
  //var imgSrc=node.getAttribute("bigImage");
  if(imgSrc)
  {
   var title=node.getAttribute("alt");
   var nodeImg=document.createElement("img");
   nodeImg.setAttribute("src",imgSrc);
   nodeImg.setAttribute("alt",title);
   nodePropertyBigImage.appendChild(nodeImg);
   var nodeBr=document.createElement("br");
   nodePropertyBigImage.appendChild(nodeBr);
   var textNode=document.createTextNode(title);
   nodePropertyBigImage.appendChild(textNode);
  };
 };
};
function searchByReferenceNumber()
{
 var nodeInput=document.getElementById("referenceNumberInput");
 if(nodeInput)
 {
  var matches=(""+nodeInput.value).match("^\\d+$");
  if(matches!=null) location.href="/property/"+nodeInput.value+"/";
 };
};
function clearReferenceNumberField(interObj)
{
 if(!interObj.modified||interObj.modified=="false")
 {
  if(!interObj.titleText) interObj.titleText=interObj.value;
  interObj.value="";
  interObj.modified=true;
 };
};
function referenceNumberFieldOnBlur(interObj)
{
 if(interObj.value.length==0&&interObj.titleText)
 {
  interObj.value=interObj.titleText;
  interObj.modified=false;
 };
};
function getWmid()
{
	var wmid=null;
	var cookieArr=document.cookie.split(';');
	for(var i=0,n=cookieArr.length;i<n&&wmid==null;i++)
	{
		var pair=cookieArr[i].split('=');
		if(pair.length == 2 && pair[0] == 'wmid'){
			var tempWmid=parseInt(pair[1],10);
			if(!isNaN(tempWmid))
				wmid=tempWmid;
		};
	};
	return wmid;
};
function addWmidToMailLinks(wmid)
{
	if(wmid)
	{
		var links=document.getElementsByTagName('a');
		for(var i=0,n=links.length;i<n;i++)
		{
			var nodeA=links[i];
			var href=nodeA.getAttribute('href');
			if(href && href.substr(0,7)=='mailto:')
			{
				var strArr=href.substr(7).split('?');
				if(strArr.length==1)
				{
					var email=strArr[0];
					nodeA.setAttribute('href','mailto:'+email+'?subject='+encodeURIComponent('wmid:'+wmid));
				};
			};
		};
	};
};

//***************************************************************************************************************************************************************

//StatCounter
sc_project=3731656; 
sc_invisible=0; 
sc_partition=45; 
sc_security="7953aff6";

$(
	function()
	{
		/*
		 * Making some areas unselectable.
		 */
		var unsel=$('.unsel');
		unsel.mousedown
		(
				function(event){
					event.preventDefault();
				}
		);
		
		$("body").bind
		(
			'contextmenu',
			function(event){
				var target=$(event.target);
				var selector=TAGS_WITH_CONTEXT_MENU.join(",");
				
				if(!target.is(selector) && target.closest(selector).length == 0){
					event.preventDefault();
					alert(locale['function_disabled']);
				}
			}
		);

		var elemMaMt0=$("#ma_mt_0");
		if(elemMaMt0.length == 1 && email)
		{
			elemMaMt0.attr("href","mailto:"+email);
			elemMaMt0.text(email);
		};
		var elemMaMt0=$("#ma_sf_0");
		if(elemMaMt0.length == 1 && email)
			elemMaMt0.attr("href","mailto:"+email);

		createCounters();

		$("#requestFormArrivalDate").datepicker({
			dateFormat:'dd/mm/yy',
			showOtherMonths: true,
			selectOtherMonths: true,
			changeMonth: true,
			changeYear: true
		});
		$("#requestFormDepartureDate").datepicker({
			dateFormat:'dd/mm/yy',
			showOtherMonths: true,
			selectOtherMonths: true,
			changeMonth: true,
			changeYear: true
		});

		//add webmaster id to mailto: links
		var wmid=getWmid();
		if(wmid)
			addWmidToMailLinks(wmid);
		
		if($("div.searchFormLine").length > 0)
			createSearchForm();
	}
);

var msgHash=
{
"err_wrong_request":"Wrong request.",
"err_wrong_request_format":"Wrong request format.",
"err_wrong_property_id":"Wrong property id.",
"err_db":"Database error.",
"err_blank_name":"Name is not specified",
"err_email_format":"Wrong e-mail format",
"err_blank_telephone":"Telephone number is not specified",
"err_wrong_arrival_date_format":"Wrong arrival date format",
"err_wrong_departure_date_format":"Wrong departure date format",
"err_wrong_number_of_guests_format":"Wrong number of guests format",
"requestSendOnError":"The property request has not been sent because of an error.",
"requestSendMessageOnError":"The message has not been sent because of an error.",
"err_send_mail":"E-mail has not been sent.",
"err_parse":"Wrong server response.",
"requestSendOnSuccess":"The property request has been sent successfully.",
"requestSendMessageOnSuccess":"The message has been sent successfully.",
"err_wrong_book_period":"Departure date is before arrival date",
"err":"Error"
};
function requestFormSend()
{
	var saleRent="";
	var propertyId="";
	var name="";
	var email="";
	var telephone="";
	var numberOfGuests="";
	var comments="";

	msgArr=Array();

	var nodeRequestFormSaleRent=document.getElementById("requestFormSaleRent");
	if(nodeRequestFormSaleRent)
		saleRent=nodeRequestFormSaleRent.value;
	if(saleRent!="SALE" && saleRent!="SHORT_RENT" && saleRent!="LONG_RENT")
		msgArr[msgArr.length]=getMsg("err");

	var nodeRequestFormPropertyId=document.getElementById("requestFormPropertyId");
	if(nodeRequestFormPropertyId)
		propertyId=nodeRequestFormPropertyId.value;

	var nodeRequestFormName=document.getElementById("requestFormName");
	if(nodeRequestFormName)
		name=nodeRequestFormName.value;

	var nodeRequestFormEmail=document.getElementById("requestFormEmail");
	if(nodeRequestFormEmail)
		email=nodeRequestFormEmail.value;

	var nodeRequestFormTelephone=document.getElementById("requestFormTelephone");
	if(nodeRequestFormTelephone)
		telephone=nodeRequestFormTelephone.value;

	var nodeRequestFormComments=document.getElementById("requestFormComments");
	if(nodeRequestFormComments)
		comments=nodeRequestFormComments.value;

	if(name.length==0)
		msgArr[msgArr.length]=getMsg("err_blank_name");

	var matches=email.match("^\\s*\\S+\\@\\S+\\s*$");
	if(matches==null)
		msgArr[msgArr.length]=getMsg("err_email_format");

	if(telephone.length==0)
		msgArr[msgArr.length]=getMsg("err_blank_telephone");

	var arrivalDate=null;
	var departureDate=null;
	if(saleRent=="SHORT_RENT" || saleRent=="LONG_RENT"){
		var arrivalDateObj=checkDate($("#requestFormArrivalDate").val());
		if(arrivalDateObj)
			arrivalDate=arrivalDateObj.getFullYear()+"-"+(arrivalDateObj.getMonth()+1)+"-"+arrivalDateObj.getDate();
		else
			msgArr[msgArr.length]=getMsg("err_wrong_arrival_date_format");

		var departureDateObj=checkDate($("#requestFormDepartureDate").val());
		if(departureDateObj)
			departureDate=departureDateObj.getFullYear()+"-"+(departureDateObj.getMonth()+1)+"-"+departureDateObj.getDate();
		else
			msgArr[msgArr.length]=getMsg("err_wrong_departure_date_format");

		numberOfGuests=$("#requestFormNumberOfGuests").val();
		matches=numberOfGuests.match("^\\s*\\d+\\s*$");
		if(matches==null)
			msgArr[msgArr.length]=getMsg("err_wrong_number_of_guests_format");
	};

	if(msgArr.length>0){
		var str="";
		for(var i=0;i<msgArr.length;i++){
			str+=msgArr[i]+".";
			if(i<msgArr.length-1)
				str+="\n";
		};
		alert(str);
	}else{
		parameters={
				saleRent:saleRent,
				propertyId:propertyId,
				name:name,
				email:email,
				telephone:telephone,
				comments:comments
		};
		var url=null;
		if(saleRent=='SHORT_RENT' || saleRent=='LONG_RENT'){
			parameters['arrivalDate']=arrivalDate;
			parameters['departureDate']=departureDate;
			parameters['numberOfGuests']=numberOfGuests;
		
			url='/json/booking-for-renting/';
		}else{
			url='/json/booking-for-buying/';
		};

		$.ajax({
			type: 'POST',
			url: url,
			data: parameters,
			success: function(data, textStatus, jqXHR) {
			    alert(getMsg("requestSendOnSuccess"));
			},
			error: function(jqXHR, textStatus, errorThrown) {
				var obj = jQuery.parseJSON(jqXHR.responseText);
				alert(getMsg(obj.faultstring));
			},
			dataType: "json",
			contentType: "application/x-www-form-urlencoded; charset=UTF-8"
		});
	};
};

//for counter1
/*
* $Revision: 1.16 $
* $Date: 2008/03/26 13:07:46 $
*/

/******************************************************************************/
var _go_track_img;
var _go_track_src;
var _go_escape;

if (typeof (encodeURIComponent) == 'function')
  _go_escape = 2;
else if (typeof (encodeURI) == 'function')
  _go_escape = 1;
else
  _go_escape = 0;

/******************************************************************************/
function _GoStatsEscape (_go_str)
{
  switch (_go_escape)
  {
      case 2:
          return encodeURIComponent (_go_str);
      case 1:
          return encodeURI (_go_str);
      default:
          return escape (_go_str);
  }
}

/******************************************************************************/
function _GoStatsClick (event)
{
  var _go_href;

  if (window.addEventListener)
  {
      _go_href = (event.target.tagName)
                  ? event.target.href
                  : event.target.parentNode.href;
  }
  else if (window.attachEvent)
  {
      _go_href = event.srcElement.href;
  }

  if (!_go_href)
      return;

  _go_track_img.src = _go_track_src + '&r=' + _GoStatsEscape (_go_href);
}

/******************************************************************************/
function _GoStatsTrack ()
{
  var _go_list = document.getElementsByTagName ('a');

  _go_track_img = new Image;
  _go_track_src = 'http' +
                  (document.location.protocol == 'https:'
                   ? 's://ssl.gostats.com' : '://' + _gos) +
                  '/bin/xcount?' + Math.random () +
                  (document.location.protocol == 'https:'
                   ? '&ssl=' + _gos : '') +
                  '&a=' + _goa;

  if (window.attachEvent)
  {
      for (var _go_j = 0; _go_j < _go_list.length; _go_j++)
          _go_list[_go_j].attachEvent ('onClick', _GoStatsClick);
  }
  else if (window.addEventListener)
  {
      for (var _go_j = 0; _go_j < _go_list.length; _go_j++)
          _go_list[_go_j].addEventListener ('click', _GoStatsClick, false);
  }
}

/******************************************************************************/
/*function _GoStatsGetJsVersion ()
{
  var _js = '<scr'+'ipt language="javascr'+'ipt">_go_js="1.0";</scr'+'ipt>';
  _js += '<scr'+'ipt language="javascr'+'ipt1.1">_go_js="1.1";</scr'+'ipt>';
  _js += '<scr'+'ipt language="javascr'+'ipt1.2">_go_js="1.2";</scr'+'ipt>';
  _js += '<scr'+'ipt language="javascr'+'ipt1.3">_go_js="1.3";</scr'+'ipt>';
  _js += '<scr'+'ipt language="javascr'+'ipt1.4">_go_js="1.4";</scr'+'ipt>';
  _js += '<scr'+'ipt language="javascr'+'ipt1.5">_go_js="1.5";</scr'+'ipt>';
  _js += '<scr'+'ipt language="javascr'+'ipt1.6">_go_js="1.6";</scr'+'ipt>';
  _js += '<scr'+'ipt language="javascr'+'ipt1.7">_go_js="1.7";</scr'+'ipt>';
  _js += '<scr'+'ipt language="javascr'+'ipt1.8">_go_js="1.8";</scr'+'ipt>';
  _js += '<scr'+'ipt language="javascr'+'ipt1.9">_go_js="1.9";</scr'+'ipt>';
  _js += '<scr'+'ipt language="javascr'+'ipt"></scr'+'ipt>';
  document.write (_js);

  return _go_js;
}*/

/******************************************************************************/
function _GoStatsGetCookieEnabled ()
{
  document.cookie =
      'gostats=1; expires=Thu, 31-Dec-2037 23:55:55 GMT; path=/';

  if (document.cookie)
  {
      document.cookie =
          'gostats=1; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';

      return 'y';
  }
  else
  {
      return 'n';
  }
}

/******************************************************************************/
function _GoStatsRun (nodeContainer)
{
  var _go_page     = _GoStatsEscape (window.location.href);
  var _go_referrer = _GoStatsEscape (document.referrer);
  //var _go_js_ver   = _GoStatsGetJsVersion ();
  var _go_cookie   = _GoStatsGetCookieEnabled ();
  var _go_swidth   = 0;
  var _go_sheight  = 0;
  var _go_sdepth   = 0;
  var _go_java     = 'n';
  var _go_width    = 0;
  var _go_height   = 0;
  var _go_tld      = _gos.match (/([^.]+\.[^.]+)$/g);

  /*switch (_go_js_ver)
  {
      default:

      case '1.2':
          _go_swidth  = screen.width;
          _go_sheight = screen.height;
          _go_sdepth  = (navigator.appName.substring (0,3) == 'Mic')
                        ? screen.colorDepth
                        : screen.pixelDepth;
      case '1.1':
          _go_java = navigator.javaEnabled () ? 'y' : 'n';

      case '1.0':
  }*/

  if(screen.width&&screen.height)
  {
          _go_swidth  = screen.width;
          _go_sheight = screen.height;
  };
  if(navigator.appName&&screen.colorDepth&&screen.pixelDepth)
          _go_sdepth  = (navigator.appName.substring (0,3) == 'Mic')
                        ? screen.colorDepth
                        : screen.pixelDepth;


  if(typeof navigator.javaEnabled =='function') _go_java = navigator.javaEnabled () ? 'y' : 'n';

  if (_got == 1 || _got == 2)
  {
      _go_width  = 88;
      _go_height = 31;
  }
  else if (_got == 3)
  {
      _go_width  = 88;
      _go_height = 100;
  }
  else if (_got == 6)
  {
      _go_width  = 80;
      _go_height = 15;
  }

  var _go_fix_png = false;
  var _go_render  = '';

  if (_go_width && _go_height && navigator.appVersion.indexOf ("MSIE") != -1)
  {
      var _go_app_version_array = navigator.appVersion.split ("MSIE");
      var _go_app_version       = parseFloat (_go_app_version_array[1]);

      if (_go_app_version >= 5.5 && _go_app_version < 7.0)
      {
          _go_fix_png  = true;
          _go_referrer = _GoStatsEscape (_go_referrer);
          _go_page     = _GoStatsEscape (_go_page);
      }
  }

  var _go_img_src = 'http' +
                    ((document.location.protocol == 'https:')
                     ? 's://ssl.gostats.com' : '://' + _gos) +
                    '/bin/count?' + Math.random () +
                    '&a=' + _goa +
                    '&t=' + _got +
                    '&i=' + _goi +
                    '&r=' + _go_referrer +
                    '&p=' + _go_page +
                    '&c=' + _go_cookie +
                    '&j=' + _go_java +
                    '&w=' + _go_swidth +
                    '&h=' + _go_sheight +
                    '&d=' + _go_sdepth +
                    //'&js=' + _go_js_ver +
                    ((document.location.protocol == 'https:')
                     ? '&ssl=' + _gos : '') +
                    (_goz ? '&z=1' : '');

  if (_got == 5)
  {
      var _go_img = new Image;
      _go_img.src = _go_img_src;

      return;
  }

/*    _go_render = '<a target="_blank" href="http://' + _go_tld +
               '" title="' + _gol + '">';*/
  _go_render = document.createElement('a');
  _go_render.setAttribute('href','http://' + _go_tld);
  _go_render.setAttribute('title',_gol);

  var _go_img_id = '_go_render_' + _goa + parseInt (Math.random () * 100);

  if (_go_fix_png)
  {
      /*_go_render += '<span id="' + _go_img_id + '" title="' + _gol +
                    '" style="display:inline-block;border-width:0px;width:' +
                    _go_width + 'px;height:' + _go_height + 'px' +
                    ';cursor:hand;filter:progid:DXImageTransform.Microsoft' +
                    '.AlphaImageLoader(src=\'' + _go_img_src +
                    '\',sizingMethod=\'scale\')"></span>';*/

	var nodeSpan=document.createElement('span');
	nodeSpan.setAttribute('id',_go_img_id);
	nodeSpan.setAttribute('title',_gol);

	nodeSpan.style.cssText='display:inline-block;border-width:0px;width:' +
                    _go_width + 'px;height:' + _go_height + 'px' +
                    ';cursor:hand;filter:progid:DXImageTransform.Microsoft' +
                    '.AlphaImageLoader(src=\'' + _go_img_src +
                    '\',sizingMethod=\'scale\')';

	_go_render.appendChild(nodeSpan);

  }
  else
  {
      /*_go_render += '<img id="' + _go_img_id +
                    '" alt="'   + _gol +
                    '" title="' + _gol +
                    '" border="0" style="border-width:0px';*/

	var nodeImg=document.createElement('img');
	nodeImg.setAttribute('id',_go_img_id);
	nodeImg.setAttribute('alt',_gol);
	nodeImg.setAttribute('title',_gol);
	nodeImg.setAttribute('style','width:'+_go_width+'px;height:'+_go_height+'px');
	_go_render.appendChild(nodeImg);

      /*if (_go_width && _go_height)
          _go_render += ';width:' + _go_width + 'px;height:' + _go_height +
                        'px" width="' + _go_width + '" height="' + _go_height;

      _go_render += '" />';*/
  }

  //_go_render += '</a>';

  //document.write (_go_render);
	nodeContainer.appendChild(_go_render);

  if (!_go_fix_png)
  {
      _go_img_element = document.getElementById (_go_img_id);

      if (_go_img_element)
          _go_img_element.src = _go_img_src;
  }
};


function createCounters()
{
	var counter0Container=document.getElementById('counter0');
	if(counter0Container)
	{
		var sc_width=screen.width;
		var sc_height=screen.height;
		var sc_referer=""+document.referrer;
		try{sc_referer=""+parent.document.referrer;}
		catch(ex){sc_referer=""+document.referrer;}
		var sc_os="";
		var sc_title="";
		var sc_url="";
		var sc_unique=0;
		var sc_returning=0;
		var sc_returns=0;
		var sc_base_dir;
		var sc_error=0;
		var sc_remove=0;
		var sc_http_url="http";
		var sc_link_back_start="";
		var sc_link_back_end="";
		var sc_security_code="";
		if(window.sc_https)
		{
			if(sc_https==1)
			{
				sc_doc_loc=''+document.location;
				myRE=new RegExp("^https","i");
				if(sc_doc_loc.match(myRE)){sc_http_url="https";}
				else{sc_http_url="http";}
			}
			else sc_http_url="http";
		}
		if(window.sc_partition)
		{
			var sc_counter="";
			if(window.sc_partition!=34)
			{sc_counter=sc_partition+1;}
			sc_base_dir=sc_http_url+"://c"+sc_counter+".statcounter.com/";
		}
		else
		{sc_base_dir=sc_http_url+"://c1.statcounter.com/";}
		if(window.sc_text){sc_base_dir+="text.php?";}
		else{sc_base_dir+="t.php?";}
		if(window.sc_project){sc_base_dir+="sc_project="+sc_project;}
		else
			if(window.usr){sc_base_dir+="usr="+usr;}
			else{sc_error=1;}
		if(window.sc_remove_link){sc_link_back_start="";sc_link_back_end="";}
		else
		{
			/*sc_link_back_start="<a class=\"statcounter\" href=\"http://www.statcounter.com\" target=\"_blank\">";
			sc_link_back_end="<\/a>"*/
			sc_link_back=document.createElement('a');
			sc_link_back.setAttribute('class','statcounter');
			sc_link_back.setAttribute('href','http://www.statcounter.com/');
		}
		sc_date=new Date();
		sc_time=sc_date.getTime();
		sc_time_difference=60*60*1000;
		sc_title=""+document.title;
		sc_url=""+document.location;
		sc_referer=sc_referer.substring(0,255);
		sc_title=sc_title.substring(0,150);
		sc_url=sc_url.substring(0,150);
		sc_referer=escape(sc_referer);
		if(encodeURIComponent){sc_title=encodeURIComponent(sc_title);}
		else{sc_title=escape(sc_title);}
		sc_url=escape(sc_url);
		if(window.sc_security){sc_security_code=sc_security;}
		var sc_tracking_url=sc_base_dir+"&resolution="+sc_width+"&h="+sc_height+"&camefrom="+sc_referer+"&u="+sc_url+"&t="+sc_title+"&java=1&security="+sc_security_code+"&sc_random="+Math.random();
		if(window.sc_partition)
		{
			if(window.sc_project)
			{
				if((sc_project==3512438)||(sc_project==3512576)||(sc_project==3512643)||(sc_project==3512646)||(sc_project==3512649)||(sc_project==3512653)||(sc_project==3512659))
				{
					sc_remove=1;
				}
			}
		}
		if(sc_error==1)
		{
			//document.writeln("Code corrupted. Insert fresh copy.")
			var textNode=document.createTextNode("Code corrupted. Insert fresh copy.");
			counter0Container.appendChild(textNode);
		}
		else if(sc_remove==1){}
		else if(window.sc_invisible)
		{
			if(window.sc_invisible==1)
			{
				if(window.sc_call){sc_call++;}
				else{sc_call=1;}
				eval("var sc_img"+sc_call+" = new Image();sc_img"+sc_call+".src = \""+sc_tracking_url+"\"");
			}
			else
			{
				//document.writeln("<div class=\"statcounter\">"+sc_link_back_start+"<img src=\""+sc_tracking_url+"\" alt=\"StatCounter - Free Web Tracker and Counter\" BORDER=\"0\">"+sc_link_back_end+"</div>")

				var nodeDiv=document.createElement('div');
				nodeDiv.setAttribute('class','statcounter');
				var nodeImg=document.createElement('img');
				nodeImg.setAttribute('src','sc_tracking_url');
				nodeImg.setAttribute('alt','StatCounter - Free Web Tracker and Counter');
				nodeImg=sc_link_back.appendChild(nodeImg);
				sc_link_back=nodeDiv.appendChild(sc_link_back);
				counter0Container.appendChild(nodeDiv);
			}
		}else if(window.sc_text)
		{
			//document.writeln('<scr'+'ipt language="JavaScript"'+' src='+sc_tracking_url+"&text="+sc_text+'></scr'+'ipt>')
			var nodeScript=document.createElement('script');
			nodeScript.setAttribute('type','text/javascript');
			nodeScript.setAttribute('charset','utf-8');
			nodeScript.setAttribute('src',sc_tracking_url+"&text="+sc_text);
			counter0Container.appendChild(nodeScript);
		}
		else
		{
			//document.writeln("<div class=\"statcounter\">"+sc_link_back_start+"<img src=\""+sc_tracking_url+"\" alt=\"StatCounter - Free Web Tracker and Counter\" border=\"0\">"+sc_link_back_end+"</div>")

			var nodeDiv=document.createElement('div');
			nodeDiv.setAttribute('class','statcounter');

			var nodeImg=document.createElement('img');
			nodeImg.setAttribute('src',sc_tracking_url);
			nodeImg.setAttribute('alt','StatCounter - Free Web Tracker and Counter');

			nodeImg=sc_link_back.appendChild(nodeImg);
			nodeDiv.appendChild(sc_link_back);
			counter0Container.appendChild(nodeDiv);

		}
		if(window.sc_click_stat)
		{
			if(window.sc_click_stat==1)
			{
				if(clickstat_done!=1)
				{
					var clickstat_done=1;
					var clickstat_project=window.sc_project;
					var clickstat_security=window.sc_security_code;
					var dlext="7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip";
					if(typeof(window.sc_download_type)=='string')dlext=window.sc_download_type;
					var ltype="https?|ftp|telnet|ssh|ssl|mailto";
					var dl=new RegExp("\\.("+dlext+")$","i");
					var lnk=new RegExp("^("+ltype+"):","i");
					var host_name=location.host.replace(/^www\./i,"");
					var host_splitted=host_name.split(".");
					var domain=host_splitted.pop();
					domain=host_splitted.pop()+"."+domain;
					var lnklocal_mask="^https?:\/\/(.*)"+domain;
					var lnklocal=new RegExp(lnklocal_mask,"i");
					if(document.getElementsByTagName)
					{
						var anchors=document.getElementsByTagName('a');
						for(var i=0;i<anchors.length;i++)
						{
							var anchor=anchors[i];
							if(anchor.onmousedown)
							{
								var original_click=anchor.onmousedown;
								var s=original_click.toString().split("\n").join(" ");
								var bs=s.indexOf('{');
								var head=s.substr(0,bs);
								var ps=head.indexOf('(');
								var pe=head.indexOf(')');
								var params=head.substring(ps+1,pe);
								var plist=params.split(",");
								var body=s.substr(bs+1,s.length-bs-2);
								var insert="sc_clickstat_call(this);";
								var final_body=insert+body;
								var ev_head="new Function (";
								var ev_params="";
								var ev_sep="";
								for(var sc_i=0;sc_i<plist.length;sc_i++)
								{
									ev_params=ev_sep+"'"+plist[sc_i]+"'";ev_sep=",";
								}
								if(ev_sep==","){ev_params+=",";}
								var ev_foot="final_body);";
								var ev_final=ev_head+ev_params+ev_foot;
								anchor.onmousedown=eval(ev_final);
							}
							else
							{
								anchor.onmousedown=new Function("event","sc_clickstat_call(this);return true;");
							}
						}
					}
					function sc_none(){return;}
					function sc_clickstat_call(adata)
					{
						if(adata)
						{
							var clickmode=0;
							if(lnk.test(adata))
							{
								if((lnklocal.test(adata))){if(dl.test(adata))clickmode=1;}
								else{clickmode=2;}
							}
							if(clickmode!=0)
							{
								var sc_link=escape(adata);
								if(sc_link.length>0)
								{
									var sc_req=sc_http_url+"://c"+sc_counter+".statcounter.com/click.gif?sc_project="+clickstat_project+"&security="+clickstat_security+"&c="+sc_link+"&m="+clickmode+"&rand="+Math.random();
									var sc_req_image=new Image(1,1);
									sc_req_image.onload=sc_none;
									sc_req_image.src=sc_req;
									var d=typeof(window.sc_delay)!="undefined"?sc_delay:250;
									var n=new Date();
									var t=n.getTime()+d;
									while(n.getTime()<t)
										n=new Date();
								}
							}
						}
					}
				}
			}
		}

	};//counter0

	var counter1Container=document.getElementById('counter1');
	if(counter1Container)
	{
		_gos='c4.gostats.com';
		_goa=315721;
		_got=1;
		_goi=9;
		_goz=0;
		_gol='web counter';
		_GoStatsRun(counter1Container);
	};//counter1
};
function createSearchForm()
{
	var form=new SearchForm();
	form.registerSaleRent(new SelectBox("SaleRent",form));
	form.registerPropertyTypeRent(new SelectBox("PropertyTypeRent",form));
	form.registerPropertyTypeSale(new SelectBox("PropertyTypeSale",form));
	
	var locatonSearchForm=new SelectBox("Location",form);
	form.registerLocation(locatonSearchForm);
	
	var areasElements=locatonSearchForm.getBox().nextAll();
	var areas={};
	areasElements.each(
		function(index,element){
			var id=element.id.substr(9);
			var locationUrlpart=id.substr(5);
			areas[locationUrlpart]=new SelectBox(id,form);
		}
	);
	form.registerAreas(areas);
	
	form.registerBedrooms(new SelectBox("Bedrooms",form));
	form.registerBathrooms(new SelectBox("Bathrooms",form));
	form.registerSleepsMax(new SelectBox("SleepsMax",form));
	
	form.registerArrival(new DatePicker("Arrival",form));
	form.registerDeparture(new DatePicker("Departure",form));
	
	form.registerShortRentPriceMin(new SelectBox("ShortRentPriceMin",form));
	form.registerShortRentPriceMax(new SelectBox("ShortRentPriceMax",form));
	
	form.registerLongRentPriceMin(new SelectBox("LongRentPriceMin",form));
	form.registerLongRentPriceMax(new SelectBox("LongRentPriceMax",form));
	
	form.registerSalePriceMin(new SelectBox("SalePriceMin",form));
	form.registerSalePriceMax(new SelectBox("SalePriceMax",form));
};

//***************************************************************************************************************************************************************

locale={};

locale['search']='Search';
locale['fillInInterestedIn']='Please fill in the "I am interested in" field!';

locale['function_disabled']='Function disabled!';
