﻿
$(document).ready(function(){

    $('#pType3').bind('click', function(){
        $('input[name=propertyType]:not([id=pType3])').removeAttr("checked");
    });
    $('input[name=propertyType]:not([id=pType3])').bind('click',function(){
        $('#pType3').removeAttr("checked");
    });

    //populate previous search
    if (typeof(search) != 'undefined')
    {
        //alert("found search object");
        //console.log(search);
        
        if (search.MinPrice>0)
        {
            $('#MinPrice').val(OLRBasicSelect.CurrencyFormatter(search.MinPrice));
            $('#MinPriceHidden').val(search.MinPrice);
        }
        if (search.MaxPrice>0)
        {
            $('#MaxPrice').val(OLRBasicSelect.CurrencyFormatter(search.MaxPrice));
            $('#MaxPriceHidden').val(search.MaxPrice);
        }

        $('input[name=neigh]').each(function(){
            if (CompareArray($(this).val().split(','), search.Neighborhood))
                $(this).attr('checked','checked');
        });
        
        $(search.Borough).each(function(){
            var val = this;
            $('input[name=boro]').each(function(){
                if ($(this).val() == val) $(this).attr('checked','checked');
            });
        });
        
        $(search.Ownerships).each(function(){
            var val = this;
            if (val == 0) val = "Coop";
            if (val == 1) val = "Condo";                        
            $('input[name=propertyType]').each(function(){
                if ($(this).val() == val) $(this).attr('checked','checked');
            });
        });
        
        $('input[name=minbeds]').each(function(){
            if ($(this).val() == search.MinBeds) $(this).attr('checked','checked');        
        });

        if (search.SearchType == 2)
            $('#pType3').attr('checked','checked');

        //aptfeatures
        $(search.AptFeatures).each(function(){
            var val = this;
            if (val == 18) $('#pType4').attr('checked','checked');
            if (val == 12) $('#pType5').attr('checked','checked');
            if (val == 20) $('#pType1').attr('checked','checked');
            if (val == 19) $('#pType2').attr('checked','checked');
        });
        
    }
    
});

//check if all values in a1 are in a2
function CompareArray(a1, a2)
{
    var compare = true;
    $(a1).each(function(i){ if (!InArray(a1[i], a2)) compare = false; });
    return compare;
}

function InArray(val, array)
{
    var ret = false;
    $(array).each(function(){ if (this == val) ret = true; });
    return ret;
}

function DisableElements(array)
{
    $.each(array, function(){
        
    });
}
