﻿
var currentPageAllPropertyCount = 23379;
var currentPageIndex = 0;
var currentPageSize = 50;
var currentPageSorting = 'SortByPropertyRank';
var currentPageFreshness = 'Freshness_AllTime';
var currentPageSortBy = 11;
var currentPageSortOrder = 1;
var currentPageCurrency = 'GBP';
var currentPageDaysWithin = 0;
var currentPageMinPrice = 0;
var currentPageMaxPrice = 0;
var currentPageMinBeds = 0;
var currentPageMaxBeds = 0;
var currentPropertyRef = '';
var currentPropertyName = '';
var currentLocationID = 5663;
var currentCountryName = 'France';
var currentLocation = 'France';
var currentLocationPath = 'France';
var strCurrPageRequestPath = '';

Array.prototype.exists = function (o) {
    for (var i = 0; i < this.length; i++)
        if (this[i] === o)
            return true;
    return false;
}

var listingPage = {
    pageTitle: 'Title',
    openedPanels: new Array(), //new Array('Filters_SortBy','Filters_Freshness'),
    isOpenedPanel: function (listName) {
        return listingPage.openedPanels.exists(listName);
    },
    SaveFormVariablesSubmit: function () {
        listingPage.SaveFormVariables();
        jQuery('#aspnetForm')[0].submit();
        return false;

    },
    SaveFormVariables: function () {
       
        return false;
    }
};

function SearchSortByClick(sort) {
    jQuery("#searchBox_action").val(sort);
    listingPage.SaveFormVariables();
    jQuery('#aspnetForm')[0].submit();
    return false;
}

function BedsFilterClick(beds) {
    jQuery('#searchBox_BedsFilter').val(beds);
    listingPage.SaveFormVariables();
    jQuery('#aspnetForm')[0].submit();
    return false;
}
function FreshnesClick(freshness) {
    jQuery('#searchBox_action').val(freshness);
    listingPage.SaveFormVariables();
    jQuery('#aspnetForm')[0].submit();
    return false;
}

function SearchCurrencyClick(currency) {

    jQuery('#searchBox_Currency').val(currency);
    listingPage.SaveFormVariables();
    jQuery('#aspnetForm')[0].submit();
    return false;
}


function SearchPriceClick(Index) {
    jQuery('#aspnetForm')[0].action = '';
    jQuery("#searchBox_MinPrice").val(0);
    jQuery("#searchBox_MaxPrice").val(0);
    jQuery("#searchBox_PriceIndex").val(Index);    
    listingPage.SaveFormVariablesSubmit();
    return false;
}

function CurrentFiltersMinPriceClick() {
    jQuery("#searchBox_MinPrice").val(0);
    jQuery("#searchBox_PriceIndex").val(0);    
    listingPage.SaveFormVariables();
    jQuery('#aspnetForm')[0].action = '';
    jQuery('#aspnetForm')[0].submit();
    return false;
}
function CurrentFiltersMaxPriceClick() {
    jQuery("#searchBox_MaxPrice").val(0);
    jQuery("#searchBox_PriceIndex").val(0);    
    listingPage.SaveFormVariables();
    jQuery('#aspnetForm')[0].action = '';
    jQuery('#aspnetForm')[0].submit();
    return false;
}


function TypeFilterClick(lnk) {
   
    //go to the selected type page     
    jQuery('#aspnetForm')[0].action = lnk;
    listingPage.SaveFormVariables();
    jQuery('#aspnetForm')[0].submit();
    return false;
}

function AddFeature(feature_id) {
    strFeatureIds = jQuery('#searchBox_featureIDs').val();  
    if (strFeatureIds == "")
        strFeatureIds = feature_id
    else
        strFeatureIds = strFeatureIds + "," + feature_id;


    jQuery('#searchBox_featureIDs').val(strFeatureIds);
    jQuery('#aspnetForm')[0].action = '';
    listingPage.SaveFormVariables();
    //alert(jQuery('#searchBox_featureIDs').val());    
    jQuery('#aspnetForm')[0].submit();
	return false;

}

function RemoveType(url) {	
	strSubmitPath = strCurrPageRequestPath.replace("/" + url + "/", "/");
    if (strSubmitPath == "/property/")
        strSubmitPath =  "/property/all/";
    jQuery('#aspnetForm')[0].action = strSubmitPath;
    listingPage.SaveFormVariables();
    jQuery('#aspnetForm')[0].submit();
    return false;
}
function RemoveFeature(feature_id,feature_url) {

    strFeatureIds = jQuery('#searchBox_featureIDs').val();    
    arrFeatureIds = strFeatureIds.split(',');
    strFeatureIds = "";
    strSubmitPath = strCurrPageRequestPath.replace("/" + feature_url + "/", "/");
    for (i = 0; i < arrFeatureIds.length; i++){
        if (arrFeatureIds[i] != "" && arrFeatureIds[i] != feature_id) {
            if (strFeatureIds == "")
                strFeatureIds = arrFeatureIds[i];
            else
                strFeatureIds = strFeatureIds + "," + arrFeatureIds[i];
        }
        
    }
    jQuery('#searchBox_featureIDs').val(strFeatureIds);
    //alert(strFeatureIds)
    //return false;
    jQuery('#aspnetForm')[0].action = strSubmitPath; 
    listingPage.SaveFormVariables();
    jQuery('#aspnetForm')[0].submit();
    return false;
}

function CurrentFiltersTypeClick(lnk) {
    var CategoryID = jQuery("#searchBox_categoryID").val();
    var SubCategoryIDs = jQuery("searchBox_subCategoryIDs").val();
    CategoryID = '';
    jQuery("#searchBox_categoryID").val(CategoryID);
    SubCategoryIDs = '';
    jQuery("#searchBox_subCategoryIDs").val('');
    jQuery("#searchBox_featureID").val('');
    jQuery("#searchBox_featureIDs").val('');
    jQuery('#aspnetForm')[0].action = lnk;
    listingPage.SaveFormVariables();
    jQuery('#aspnetForm')[0].submit(); 
    return false;
}



function restore_image(property_id, imgUrl) {
    jQuery("#listingThumb_" + property_id).attr("src", imgUrl);

}

function swap_image(property_id,img) {

    jQuery("#listingThumb_" + property_id).attr("src", img.src.replace("_thumb", ""));
}

jQuery(document).ready(function () {
    //alert(jQuery("#searchBox_categoryID").val());
   // jQuery("li[rel='TypesFilter'][parentID!=-1][parentID!=59][parentID!=" + jQuery("#searchBox_categoryID").val() + "]").hide(); //hid all sub types excluding residential subtypes
    jQuery('.FiltersHeader').click(function () {
        // now get list id that's related to this group header
        var listID = this.id.replace('_Group', '');
        if (listID == 'Filters_Price' || listID == 'Filters_Currency' || listID == 'Filters_SortBy' || listID == 'Filters_Freshness')
        listID = "ContentPlaceHolder1_" + listID;
        var imgID = '#' + this.id + ' img';

        if (jQuery('#' + listID).is(':visible')) {
            jQuery('#' + listID).slideUp();
            jQuery(imgID).attr('src', '/images/bulletDown.30.png');
        }
        else {
            jQuery('#' + listID).slideDown();
            jQuery(imgID).attr('src', '/images/bulletLeft.30.png');
        }
    });
});
