	/**************
	 * 
	 * scripts for select zipcodes from map
	 *
	 *************/

	function getCommuner(regionID)
	{
		var divHtml = "";
		var c;
		var d;

		divHtml = "<ul id='chtree'>";
		divHtml += "<li id='firstLi'><input type='checkbox' id='allRegion'><label>V&aelig;lg hele regionen</label>";
		
		for (c = 0; c < commune.length; c++)
		{
			if (commune[c].regionID == regionID)
			{
				divHtml += "<li><input type='checkbox' value='" + commune[c].communeID + "' name='commune" + commune[c].communeID + "'><label for='commune" + commune[c].communeID + "'>" + commune[c].name + "</label><ul>";
				
				for (d = 0; d < city.length; d++)
				{
					if (city[d].communeID == commune[c].communeID)
					{
						divHtml += "<li><input onchange='setCity(this);' class='cityChk' type='checkbox' value='" + city[d].zipcode + "'><label>" + city[d].name + "</label>";
					}
				}
				divHtml += "</ul>";
			}
		}
		
		divHtml += "</ul>";
		
		$("#communeDiv").html(divHtml);
		$("#chtree").checkboxTree({
            initializeChecked: 'collapsed',
            initializeUnchecked: 'collapsed',
            collapseDuration: 200,
            expandDuration: 200,
            onCheck: {
                node: 'expand'
            }
        });
		
		$("#allRegion").focus();
		
		$("#allRegion").click(function(){
            if ($('#allRegion').attr('checked')) {
            	$('#chtree').checkboxTree('checkAll');
            } else {
            	$('#chtree').checkboxTree('uncheckAll');
            }
        });
		
		return false;
	}

	function setCity(chkBox) {
		var zip = $(chkBox).val();
		addCity(zip, $(chkBox).is(':checked'));
	}
	
	function addCity(zipcode, addZipcode)
	{
		// only do this, when something is in textarea
		if (document.propertyWantedForm.selByer.value.length > 0)
		{
			var newtxt = "";
			var curlist = document.propertyWantedForm.selByer.value.split(",");
			for (var i = 0; i < curlist.length; i++)
			{
				if (curlist[i] != zipcode && curlist[i] != "" )
					newtxt += curlist[i] + ",";
			}
			document.propertyWantedForm.selByer.value = "";

			if (addZipcode) {
				document.propertyWantedForm.selByer.value = newtxt + zipcode + ",";
			}
			else {
				document.propertyWantedForm.selByer.value = newtxt;
			}
		}
		else
			if (addZipcode)
				document.propertyWantedForm.selByer.value = zipcode + ",";
	}
	
	/**************
	 * 
	 * scripts for select zipcodes from map
	 *
	 *************/

	/**************
	 * 
	 * scripts for myPage
	 *
	 *************/
	
	function showTab1() {
		$.ajax({
			type: "GET",
			url: "minside/tab1",
			cache: false,
			async:false,
			success: function(html){
				$("#tab1").html("");
				$("#tab1").append(html);
			}
		});	
		doShowSearchAgentList("minside/searchAgent", "0", "");
		$("#searchfilter").show();
		$("#filterdefault").attr('checked', true);
	};
	
	function showTab2() {
		$.ajax({
			type: "GET",
			url: "minside/tab2",
			cache: false,
			async:false,
			success: function(html){
				$("#tab2").html("");
				$("#tab2").append(html);
			}
		});	
		doShowSearchAgentList("minside/showCustomSearchResult", "0", "");
		$("#searchfilter").hide();
	};

	function showMyUserProfile() {
		$.ajax({
			type: "GET",
			url: "minside/myuserprofile",
			cache: false,
			async:false,
			success: function(html){
				$("#searchresult").html("");
				$("#tab3").html("");
				$("#tab3").append(html);
			}
		});	
		$("#searchfilter").hide();
	};
	
	function showSearchAgentList(filter, sorter) {
		doShowSearchAgentList("minside/searchAgent", filter, sorter, "0", "");
	}
	
	function showPagerSearchAgentList(currentPager, backForwardPager) {
		doShowSearchAgentList("minside/searchAgent", currentPager, backForwardPager);
		return false;
	}

	function doShowSearchAgentList(ajaxUrl, currentPager, backForwardPager) {
		$.ajax({
			type: "GET",
			url: ajaxUrl,
			cache: false,
			async:false,
			data:{ currentPager:currentPager, backForwardPager:backForwardPager},
			success: function(html){
				$("#searchresult").html("");
				$("#searchresult").append(html);
			}
		});	
	} 

	function doFilterSearchAgentList(filter) {
		$.ajax({
			type: "GET",
			url: "minside/filterSearchAgent",
			cache: false,
			async:false,
			data:{ filter:filter},
			success: function(html){
				$("#searchresult").html("");
				$("#searchresult").append(html);
			}
		});	
	} 

	function doSortSearchAgentList(sorter) {
		$.ajax({
			type: "GET",
			url: "minside/sorterSearchAgent",
			cache: false,
			async:false,
			data:{ sorter:sorter},
			success: function(html){
				$("#searchresult").html("");
				$("#searchresult").append(html);
			}
		});	
	} 

	function setFavouriteStatus(ownerUserProfileId, propertyForSaleId, statusId) {
		var tag = "#fav" + propertyForSaleId;
		statusTxt = $(tag).html();

		if (statusTxt == "Husk bolig") {
			$.post("minside/setFavouriteStatus", { ownerUserProfileId: ownerUserProfileId, propertyForSaleId: propertyForSaleId, statusId: 1 } );
			$(tag).html("");
			$(tag).append("Fjern fra min huskeliste");
		} else {
			$.post("minside/setFavouriteStatus", { ownerUserProfileId: ownerUserProfileId, propertyForSaleId: propertyForSaleId, statusId: 0 } );
			$(tag).html("");
			$(tag).append("Husk bolig");
		}
	}

	function addDreamProperty(propertyForSaleId) {
		$.ajax({
			type: "GET",
			data: { propertyForSaleId: propertyForSaleId },
			url: "minside/addDreamPropertyConfirm",
			cache: false,
			async:false,
			success: function(html){

				$("#modal-profile-standard").html("");
				$("#modal-profile-standard").append(html);
				
				$.fn.center = function () {
					var top = ($(window).height() - $(this).outerHeight()) / 2;
                    var left = ($(window).width() - $(this).outerWidth()) / 2;
			        this.css({position:'fixed', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
			        return this;
			      };
			 
			    $('#modal-lightsout').css("height", jQuery(document).height()); 
			 
			    $("#modal-profile-standard").center();
		        $('#modal-profile-standard').fadeIn("slow");
		        $('#modal-lightsout').fadeTo("slow", .5);
			 
				$('.modal-close-profile').click(function() { 
			        $('#modal-profile-standard').fadeOut("slow");
			        $('#modal-lightsout').fadeOut("slow");
			        $(".checkbox").attr('checked', false);
			        return false;
				});
				
				$('#cancel').click(function() { 
			        $('#modal-profile-standard').fadeOut("slow");
			        $('#modal-lightsout').fadeOut("slow");
			        $(".checkbox").attr('checked', false);
			        return false;
				});

			}
		});	

	}

	function removeDreamProperty(matchId) {
		$.post("minside/setDreamPropertyStatus", { matchId: matchId, statusId: 0 } );
		location.href= "minside";
	}

	function addToGarbage(matchId, rowid) {
		$.post("minside/addToGarbage", { matchId: matchId } );
		$(".tr" + rowid).remove();
        return false;
	}

	function removeFromGarbage(matchId, rowid) {
		$.post("minside/removeFromGarbage", { matchId: matchId } );
		$("#tr" + rowid).remove();
		return false;
	}

//	function showSearchForm() {
//		if ($(".searchform").is(':visible')) {
//			$(".searchform").hide();
//		} else {
//			$(".searchform").show();
//		}
//		return false;
//	}
//

	function buyPropertyConfirm(matchId, propertyForSaleId) {
		$.ajax({
			type: "GET",
			data: { matchId: matchId, propertyForSaleId: propertyForSaleId },
			url: "minside/buyPropertyConfirm",
			cache: false,
			async:false,
			success: function(html){

				$("#modal-profile-standard").html("");
				$("#modal-profile-standard").append(html);
				
				$.fn.center = function () {
					var top = ($(window).height() - $(this).outerHeight()) / 2;
                    var left = ($(window).width() - $(this).outerWidth()) / 2;
			        this.css({position:'fixed', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
			        return this;
			      };
			 
			    $('#modal-lightsout').css("height", jQuery(document).height()); 
			 
			    $("#modal-profile-standard").center();
		        $('#modal-profile-standard').fadeIn("slow");
		        $('#modal-lightsout').fadeTo("slow", .5);
			 
				$('.modal-close-profile').click(function() { 
			        $('#modal-profile-standard').fadeOut("slow");
			        $('#modal-lightsout').fadeOut("slow");
			        $(".checkbox").attr('checked', false);
			        return false;
				});

				$('#cancel').click(function() { 
			        $('#modal-profile-standard').fadeOut("slow");
			        $('#modal-lightsout').fadeOut("slow");
			        $(".checkbox").attr('checked', false);
			        return false;
				});

			}
		});	

	}

	function requireBuyerHelp(url) {
		
		$.ajax({
			type: "GET",
			url: url,
			cache: false,
			async:false,
			success: function(html){

				$("#modal-profile").html("");
				$("#modal-profile").append(html);
				
				$.fn.center = function () {
					var top = ($(window).height() - $(this).outerHeight()) / 2;
                    var left = ($(window).width() - $(this).outerWidth()) / 2;
			        this.css({position:'fixed', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
			        return this;
			      };
			 
			    $('#modal-lightsout').css("height", jQuery(document).height()); 
			 
			    $("#modal-profile").center();
		        $('#modal-profile').fadeIn("slow");
		        $('#modal-lightsout').fadeTo("slow", .5);
			 
				$('.modal-close-profile').click(function() { 
			        $('#modal-profile').fadeOut("slow");
			        $('#modal-lightsout').fadeOut("slow");
			        return false;
				});
				
			}
		});
		
	}


	

