﻿
var _cboQuickSearchCommunity;
var _cboQuickSearchSubCommunity;
function initializeQuickSearchForm()
{
    if($get("ctl00_search1_drpCommunity") && $get("ctl00_search1_drpSubCommunity"))
    {
        _cboQuickSearchCommunity = $get("ctl00_search1_drpCommunity");
        _cboQuickSearchSubCommunity = $get("ctl00_search1_drpSubCommunity");    
    }
    else if($get("ctl00_ContentPlaceHolder1_drpCommunity") && $get("ctl00_ContentPlaceHolder1_drpSubCommunity"))
    {
        _cboQuickSearchCommunity = $get("ctl00_ContentPlaceHolder1_drpCommunity");
        _cboQuickSearchSubCommunity = $get("ctl00_ContentPlaceHolder1_drpSubCommunity");   
    }
    else
    {
        _cboQuickSearchCommunity = $get("search1_drpCommunity");
        _cboQuickSearchSubCommunity = $get("search1_drpSubCommunity"); 
    }
    if(_cboQuickSearchCommunity != null)
    {
        _cboQuickSearchCommunity.onchange = function(){getQuickSearchSubCommunities(this);};
    }
    
}
//*****************************************************
function getQuickSearchSubCommunities(object)
{
    makeQuickSearchSubCommunityEmpty();
    var CommunityId = object.options[object.selectedIndex].value;
    var curTime = new Date();    
     //if(CommunityId != -1)
    //{       
        PageMethods.getSubCommunity_By_CommunityId(CommunityId, curTime.toString(), onSuccessQuiCkSearchSubCommunityInfo, onFailureQuickSearchSubCommunityInfo, curTime.toString())        
    //}    
}
function onSuccessQuiCkSearchSubCommunityInfo(result, context, method)
{
    var SubCommunityInfo = result;
    var objSubCommunity= _cboQuickSearchSubCommunity;
    var SubCommunityIndex = 0;    
    if(SubCommunityInfo != null)
    {
        if(SubCommunityInfo.length > 0)
        { 
             var optnSubCommunity;                     
            for(SubCommunityIndex = 0; SubCommunityIndex < SubCommunityInfo.length; SubCommunityIndex++)
            {                     
                if(SubCommunityInfo[SubCommunityIndex].SubCommunityId > 0)
                {
                    optnSubCommunity = document.createElement("OPTION");
                    optnSubCommunity.text = SubCommunityInfo[SubCommunityIndex].SubCommunityName;
                    optnSubCommunity.value =  SubCommunityInfo[SubCommunityIndex].SubCommunityId;
                    objSubCommunity.options.add(optnSubCommunity);
                }
            }
        }
    }
}

function onFailureQuickSearchSubCommunityInfo(result, context, method)
{
   makeQuickSearchSubCommunityEmpty();
}
function makeQuickSearchSubCommunityEmpty()
{
   var objQuickSearchSlcSubCommunity = _cboQuickSearchSubCommunity;
    
    var i;
    for (i = objQuickSearchSlcSubCommunity.length - 1; i>0; i--)
    {
       objQuickSearchSlcSubCommunity.remove(i);
    }
    for (i = objQuickSearchSlcSubCommunity.length - 1; i>0; i--)
    {
       objQuickSearchSlcSubCommunity.remove(i);
    }
}
//***************************************************************************************

