﻿var ID_City;
var filterboolean;
var loadparameter;
var supressDropDownClosing = false;
var cancelDropDownClosing = false;
            
function StopPropagation(e)
{
    //cancel bubbling
    e.cancelBubble = true;
    if (e.stopPropagation)
    {
        e.stopPropagation();
    }
}
function OnClientDropDownOpening(sender, eventArgs) {
    supressDropDownClosing = true;
}
function onDropDownClosing()
{
    cancelDropDownClosing = false;
}

function onCheckBoxClick(chk, combo)
{
    //holds the text of all checked items
    var text = "";
    //holds the values of all checked items
    var values = "";
    //get the collection of all items
    var items = combo.get_items();
    //uncheck the select all checkbox
    var selectall = $get(combo.get_id() + "_Header_chkSelectAll");
    selectall.checked = false;
    //enumerate all items
    for (var i = 0; i < items.get_count(); i++)
    {
        var item = items.getItem(i);
        //get the checkbox element of the current item
        var chk1 = $get(combo.get_id() + "_i" + i + "_chk1");
        if (chk1.checked)
        {
            if (text.length > 0) {
                text += ", " + item.get_text();
                values += "," + item.get_value();
            }
            else
            {
                text += item.get_text();
                values += item.get_value();
            }

        }
    }
            
    if (text.length > 0)
    {
        //set the text of the combobox
        combo.set_text(text);
        combo.set_value(values);
    }
    else
    {
        //all checkboxes are unchecked
        //so reset the controls
        combo.set_text(AnyText);
        combo.set_value("0");
    }
}

function UncheckAll(combo) {
    var items = combo.get_items();

    for (var i = 0; i < items.get_count(); i++) {
        var item = items.getItem(i);
        //get the checkbox element of the current item
        var chk1 = $get(combo.get_id() + "_i" + i + "_chk1");
        chk1.checked = false;
    }
    combo.set_text(AnyText);
    ($get(combo.get_id() + "_Header_chkSelectAll")).checked = true;
}

function LoadAreas(combo, eventArqs) {
    var item = eventArqs.get_item();
    // AreaCombo.set_text("Loading...");

    // if a City is selected
    if (item.get_index() > 0) {
        // this will fire the ItemsRequested event of the ddlArea combobox 
        // passing the value of ddlCity (ID_City) as a parameter
        ID_City = item.get_value();
        filterboolean = true;
        loadparameter = ID_City + "/" + filterboolean;
        AreaCombo.requestItems(loadparameter, false);
        document.getElementById("filterdiv").style.display = "";
    }
    else {
        // the -Any- item was chosen
        AreaCombo.set_text(AnyText);
        AreaCombo.clearItems();
    }
}

function VillageFilter() {
    if (this.checked) {
        this.checked = false;
        filterboolean = true;
        loadparameter = ID_City + "/" + filterboolean;
        AreaCombo.requestItems(loadparameter, false);
        UncheckAll(AreaCombo)
    } else {
        this.checked = true;
        filterboolean = false;
        loadparameter = ID_City + "/" + filterboolean;
        AreaCombo.requestItems(loadparameter, false);
    }
    ($get(AreaCombo.get_id() + "_Header_chkSelectAll")).checked = true;
    AreaCombo.set_text(AnyText);
}
