function addToCompareList(id, item){
    jQuery(item).hide();
    jQuery.ajax({
        url: voodooMain + "front/compare/addItemToCompareList/propertyId/" + id,
        success: function(msg){
            jQuery(".compareList").html(msg);
            jQuery(item).html("<tt>Remove From Compare List</tt>");
            jQuery(item).unbind();
            jQuery(item).bind("click", function(){
                removeFromCompareList(id, this);
            });
            jQuery("#compareListBox").show();
            jQuery(item).show();
        }
    });
};
function removeFromCompareList(id, item){
    jQuery(item).hide();
    jQuery.ajax({
        url: voodooMain + "front/compare/removeItemFromCompareList/propertyId/" + id,
        success: function(msg){
            if (msg == "") {
                jQuery(".compareList").html("");
                jQuery(".compareList").html(msg);
            }
            else {
                jQuery(".compareList").html("");
                jQuery("#compareListBox").hide();
            }
            jQuery(item).html("<tt>Add To Compare List</tt>");
            jQuery(item).unbind();
            jQuery(item).bind("click", function(){
                addToCompareList(id, this);
            });
            jQuery(item).show();
        }
    });
};
function removeFromFinalCompare(id){
    jQuery.ajax({
        url: voodooMain + "front/compare/removeItemFromCompareList/propertyId/" + id,
        success: function(msg){
            var str = document.location.href;
            str = str.replace(id, "");
            str = str.replace(/.*?compareList.html\?properties=/g, "");
            str = str.split(",");
            var newstr = new Array();
            var j = 0;
            for (i = 0; i < str.length; i++) {
                if (str[i] != "") {
                    newstr[j] = str[i];
                    j++;
                }
            }
            str = newstr;
            str = str.join(",");
            document.location.href = "compareList.html?properties=" + str;
        }
    });
};
function removeSelected(){
    jQuery("input.propertySelection:checked").each(function(){
        var id = jQuery(this).val();
        jQuery.ajax({
            url: voodooMain + "front/compare/removeItemFromCompareList/propertyId/" + jQuery(this).val(),
            success: function(msg){
                if (msg) {
                    jQuery("#compareListBox").html(msg);
                }
                else {
                    jQuery("#compareListBox").html("");
                }
                jQuery(".compareElementClass" + id).remove();
                if (jQuery(".searchedPropertyResultItem").length == 0) {
                    jQuery(".compareElementContent").html("Sorry but there are no items selected to compare.");
                }
            }
        });
    });
};
function removeAll(){
    jQuery("input.propertySelection").each(function(){
        var id = jQuery(this).val();
        jQuery.ajax({
            url: voodooMain + "front/compare/removeItemFromCompareList/propertyId/" + jQuery(this).val(),
            success: function(msg){
                jQuery("#compareListBox").html("");
                jQuery(".compareElementContent").html("Sorry but there are no items selected to compare.");
            }
        });
    });
};
function compareSelected(){
    if (jQuery("input.propertySelection:checked").length < 2) {
        alert("You must select at least 2 properties to compare them.");
        return;
    }
    var ids = "";
    jQuery("input.propertySelection:checked").each(function(){
        var id = jQuery(this).val();
        if (ids != "") {
            ids += ",";
        }
        ids += id;
    });
    document.location.href = voodooMain + "compareList.html?properties=" + ids;
};
function compareAll(){
    var ids = "";
    jQuery("input.propertySelection").each(function(){
        var id = jQuery(this).val();
        if (ids != "") {
            ids += ",";
        }
        ids += id;
    });
    document.location.href = voodooMain + "compareList.html?properties=" + ids;
};
function toggleAdvancedSearch(){
	//IE FIX
    jQuery("div.advancedSearch").toggle();
    jQuery("div.advancedSearch").toggle();
	//
	if(jQuery("div.advancedSearch").is(":visible")){
		jQuery("div.advancedSearch").css("display", "none");
	}else{
		jQuery("div.advancedSearch").css("display", "block");
	}
	
    if (jQuery("div.advancedSearch").is(":visible")) {
        jQuery("a.advSearch span").removeClass('down');
        jQuery("a.advSearch span").addClass('up');
    } else {
        jQuery("a.advSearch span").removeClass('up');
        jQuery("a.advSearch span").addClass('down');
    }
};
function cornerFix(){
    var right = jQuery(".searchCornerFixClass .round-br").css("bottom");
    var left = jQuery(".searchCornerFixClass .round-bl").css("bottom");
    jQuery(".searchCornerFixClass .round-br").css("bottom", 10);
    jQuery(".searchCornerFixClass .round-bl").css("bottom", 10);
    jQuery(".searchCornerFixClass .round-br").css("bottom", right);
    jQuery(".searchCornerFixClass .round-bl").css("bottom", left);
};
function updateAreaSelect(el, areaId){
    jQuery.ajax({
		async:false,
        url: voodooMain + "front/search/getAreaOptions/countryId/" + jQuery(el).val() + "/areaId/" + areaId,
        success: function(html){
            jQuery('.areaSelect').html(html);
            if (areaId) {
                jQuery('.areaSelect option[value=' + areaId + ']').attr('selected', 'selected');
            }
			
			updateLocationSelect(jQuery(".areaSelect"));
        }
    });
};
function updateLocationSelect(el, locationId){
    jQuery.ajax({
		async:false,
        url: voodooMain + "front/search/getLocationOptions/areaId/" + jQuery(el).val(),
        success: function(html){
            jQuery('select[name=locationIds]').html(html);
			if(locationId){
				jQuery('select[name=locationIds] option[value=' + locationId + ']').attr('selected', 'selected');
			}
        }
    });
};
