/***********************************************
*  Plan Drill down functions                   *
************************************************
*  Change history                              *
* 07/30/2009  KA Initial creation              *
***********************************************/

// ready event
$(document).ready(function() {
    $('#sqft').change(function() {
        getCount();
    });
    $('#br').change(function() {
        getCount();
    });
    $('#ba').change(function() {
        getCount();
    });
    $('#hs').change(function() {
        getCount();
    });
    $('#btnLocate').click(function() {
        getList();
    });
    getCount();
    $("[rel='carousel']").live('click', function() {$("#divMainImage").html('<img src="'+$(this).attr('href')+'" >'); return false;});
    //$("[rel='carousel']").click(function() { alert('running'); });
});

function getCount() {
    var filters = getFilters();//gets data from filters

    //The posts to ajax file to check for results
    $.post("PlanCnt.php", {type: 'run', check: 'true', filters: filters},
        function(data){
            if(data == 0){
                // 0 results found
                $('#spnCount').html('Your search produced no results. <br />Please limit your criteria.');
                $('#btnLocate').css('display','none');
            } else {
                $('#spnCount').html(data);
                $('#btnLocate').css('display','inline');
            }
        }, 'text');
}

function getList() {
    var filters = getFilters();//gets data from filters

    //The posts to ajax file to check for results
    $.post("get_plan_list.php", {type: 'run', check: 'true', filters: filters},
        function(data){
            if(data == 0){
                // 0 results found
                $('#divList').html('Your search produced no results. <br />Please limit your criteria.');

            } else {
                $('#divList').html(data);

            }
        }, 'text');
}

function getFilters(){
    var filter = '{';
    if($("#sqft option:selected").val()!= '') { filter += "'sqft' : '"+$("#sqft option:selected").val()+"',"; }
    if($("#br option:selected").val()!= '') { filter += "'br' : '"+$("#br option:selected").val()+"',"; }
    if($("#ba option:selected").val()!= '') { filter += "'ba' : '"+$("#ba option:selected").val()+"',"; }
    if($("#hs option:selected").val()!= '') { filter += "'hs' : '"+$("#hs option:selected").val()+"',"; }
    filter = filter.substr(0, filter.length-1); //remove comma from end
    if (filter != '') { filter += '}'; }
    return filter;
}
