﻿
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 expand = true;



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();
        $j('#aspnetForm')[0].submit();
        return false;

    },
    SaveFormVariables: function () {
        var cookieContent;
        $j('#searchBox_Form :input').each(function (index) {
            var jid = '#' + this.id;
            cookieContent += this.id + '=' + encodeURIComponent($j(jid).val()) + '&';
            //alert(this.id);
        });
        cookieContent += 'browsePageID=' + 2393;

        //alert(cookieContent);
        $j.cookie('tmc_browseForm', cookieContent);
        //alert(cookieContent)
        return false;
    }
};

function SearchSortByClick(sort) {
    $j("#searchBox_action").val(sort);
    listingPage.SaveFormVariables();
    $j('#aspnetForm')[0].submit();
    return false;
}
function SearchCurrencyClick(currency) {
    $j('#searchBox_action').val(currency + '|AsCurrency');
    $j('#searchBox_Currency').val(currency);
    listingPage.SaveFormVariablesSubmit(); 
    return false;
}

function SearchPriceClick(tier,min, max) {
    $j("#searchBox_action").val(tier);
    $j("#searchBox_minPriceIndex").val(min);
    $j("#searchBox_maxPriceIndex").val(max);
    listingPage.SaveFormVariablesSubmit();
    return false;
}
function CurrentFiltersLocationClick(lnk) {
    $j("#searchBox_action").val('');
    $j("searchBox_changeValue").val('{name}|{id}');
    $j('#aspnetForm')[0].action = lnk;
    listingPage.SaveFormVariables();
	$j("#__VIEWSTATE").val("");
    $j('#aspnetForm')[0].submit(); 
    return false;
}

function DetailsButtonClick(lnk) {
    $j('#aspnetForm')[0].action = lnk;        
    $j('#aspnetForm')[0].submit();
    return false;
}

function TopSearchedTypeFilterClick(lnk) {
    $j("#searchBox_action").val('');
    $j('#aspnetForm')[0].action = lnk;
    listingPage.SaveFormVariables();
    $j('#aspnetForm')[0].submit();
    return false;
}

function DetailsButtonClick(lnk) {

    $j('#aspnetForm')[0].action = lnk;
    $j('#aspnetForm')[0].submit();
    return false;
}



function TypeFilterClick(lnk, typeID) {

    //alert(dummyHtml);
    if (typeID != 59) {
        if ($j("li[parentID=" + typeID + "]").length > 0) {//check if this type have any subtypes

            if ($j("li[parentID=" + typeID + "]").is(":visible")) //if subtypes are expended then unexpend subtypes
            {
            $j("li[parentID=" + typeID + "]").slideUp(); //unexpend                
            }
            else //if subtypes are unexpended make them expended
            {
                $j("li[parentID=" + typeID + "]").slideDown().fadeIn(400); //expend suntypes
                $j("li[parentID!=" + typeID + "][rel='TypesFilter'][parentID!=-1][parentID!=59]").slideUp(); //make all other expended sub types unexpended                                       
            }

            return true;

        }
    }
   
    
    //go to the selected type page
    $j("#searchBox_action").val('');    
    $j('#aspnetForm')[0].action = lnk;
    listingPage.SaveFormVariables();
    $j('#aspnetForm')[0].submit();
    return false;
}

function CurrentFiltersTypeClick(lnk) {
    var CategoryID = $j("#searchBox_categoryID").val();
    var SubCategoryIDs = $j("searchBox_subCategoryIDs").val();
    CategoryID = '';
    $j("#searchBox_categoryID").val(CategoryID);
    SubCategoryIDs = '';
    $j("#searchBox_subCategoryIDs").val('');
    $j("#searchBox_featureID").val('');
    $j("#searchBox_featureIDs").val('');
    $j('#aspnetForm')[0].action = lnk;
    listingPage.SaveFormVariables();
    $j('#aspnetForm')[0].submit(); 
    return false;
}

function CurrentFiltersMinPriceClick() {
    $j("#searchBox_action").val('FilterRemoved');
    $j("#searchBox_minPriceIndex").val('0');
    $j("#searchBox_MinPrice").val(0);
    $j("#searchBox_maxPriceIndex").val('0');
    $j("#searchBox_MaxPrice").val(0);
    listingPage.SaveFormVariables();
    $j('#aspnetForm')[0].submit(); 
    return false;
}
function CurrentFiltersMaxPriceClick() {
    $j("#searchBox_action").val('FilterRemoved');
    $j("#searchBox_minPriceIndex").val('0');
    $j("#searchBox_MinPrice").val(0);
    $j("#searchBox_maxPriceIndex").val('0');
    $j("#searchBox_MaxPrice").val(0);
    listingPage.SaveFormVariables();
    $j('#aspnetForm')[0].submit();
    return false;
}




$j(document).ready(function () {
    
    //alert($j("#searchBox_categoryID").val());
    $j("li[rel='TypesFilter'][parentID!=-1][parentID!=59][parentID!=" + $j("#searchBox_categoryID").val() + "]").hide(); //hid all sub types excluding residential subtypes
    $j('.FiltersHeader').click(function () {
        // now get list id that's related to this group header
        var listID = this.id.replace('_Group', '');
        var imgID = '#' + this.id + ' img';

        if ($j('#' + listID).is(':visible')) {
            $j('#' + listID).slideUp();
            $j(imgID).attr('src', 'http://www.themovechannel.com/images/art/bulletDown.gif');
        }
        else {
            $j('#' + listID).slideDown();
            $j(imgID).attr('src', 'http://www.themovechannel.com/images/art/bulletLeftRed.gif');
        }
    });
});


function TopSingleProperty_Click() {
    window.location = ($j("a[id$='_lnkTopPropertyMore']").attr('href'));
}


function SearchBedsClick(beds) {
    $j("#searchBox_BedsFilter").val(beds);    
    listingPage.SaveFormVariablesSubmit();
    return false;
}
