﻿var DistrictName = ""
function LoadLocation(variables) 
{ 
      document.getElementById("lblMsg").innerHTML = "";
      DistrictName = variables.split("&")[1].split("=")[1];
      document.getElementById("ctl00_ContentPlaceHolder1_hdnDistrictName").value=DistrictName;
      //document.getElementById("lblDistrictTitle").innerHTML = DistrictName;
      //document.getElementById("ancDistrict").innerHTML = "<b>Search entire " + DistrictName+"</ b>";
      document.getElementById("ctl00_ContentPlaceHolder1_hdnDistrictNameForSearch").value = DistrictName; 
      document.getElementById("lblDistrictTitle").innerHTML = DistrictName.replace(/_/g, " ");    
      document.getElementById("ancDistrict").innerHTML = "<b>Search entire " + DistrictName.replace(/_/g, " ")+"</ b>";
      LoadCommunities(DistrictName);
}

function LoadSearch()
{
    var selectedcommunities;
    selectedcommunities = GetSelectedCommunities()
    if(selectedcommunities == "")
    {
        document.getElementById("lblMsg").innerHTML = "Please select atleast one community to search.";
        return false;
    }
    else
    {
        //window.location = "Search-Results.aspx?CommunityIds="+GetSelectedCommunities();
        __doPostBack('ctl00$ContentPlaceHolder1$lnkDummyMapCommunitySearch','')   
             
    }
}

function LoadSearchAll()
{
    //window.location = "Search-Results.aspx?DistrictName="+DistrictName;
    __doPostBack('ctl00$ContentPlaceHolder1$lnkDummyMapDistrictSearch','')
    
}
    
function LoadCommunities(DistrictName)
{//alert(DistrictName);
   var curTime = new Date();
   PageMethods.getCommunityByDistrictName(DistrictName, curTime.toString(), onSuccessCommunityInfo, onFailureCommunityInfo, curTime.toString());
}

function onSuccessCommunityInfo(result, context)
{
    var CommunityInfo = result;
    var CommunityIndex = 0;  
    if(CommunityInfo != null)
    {
        if(CommunityInfo.length > 0)
        { 
            document.getElementById("tblCommunityPanel").style.display = "";
            document.getElementById("tblNoCommunities").style.display = "none";
            var browserName=navigator.appName;
            if (browserName=="Microsoft Internet Explorer")
            {
                if(document.getElementById("tblCommnities").innerText != null)
                {
                    document.getElementById("tblCommnities").innerText = "";
                }
            }
            else
            {
                if(document.getElementById("tblCommnities").innerHTML != null)
                {
                    document.getElementById("tblCommnities").innerHTML = "";
                }
            }
            var myTable = document.getElementById("tblCommnities");
            //myTable.innerHTML = ''; 
            var myTbody = document.createElement("tbody");          
            for(CommunityIndex = 0; CommunityIndex < CommunityInfo.length - 1; CommunityIndex++)
            { 
                  var myRow = document.createElement("tr");
                  var myCell = document.createElement("td");                 
                  myCell.className = "bluetext";
                  myCell.innerHTML = "<input type='checkbox' id='chkCommunity"+CommunityIndex+"' title='' value='"+CommunityInfo[CommunityIndex].CommunityId+"' accesskey='' />&nbsp;"+CommunityInfo[CommunityIndex].CommunityName;
                  myRow.appendChild(myCell);
                  myTbody.appendChild(myRow);
            }
            myTable.appendChild(myTbody);  
            //alert(myTable.innerHTML);      
        }
    }
    else
    {
        document.getElementById("tblCommunityPanel").style.display = "none";
        document.getElementById("tblNoCommunities").style.display = "";
    }
    $find("bMPESearch").show();
    //document.getElementById("imgLoadingCommunity").style.display = "none";
}

function onFailureCommunityInfo(result, context)
{
  document.getElementById("tblCommunityPanel").style.display = "none";
  document.getElementById("tblNoCommunities").style.display = "";
}

function GetSelectedCommunities()
{
    var  CommunitieIds = "";
    var table = document.getElementById("tblCommnities");
    cells = table.getElementsByTagName("TD");
    for (var i=0; i<cells.length; i++)  
    {
      if(cells[i].getElementsByTagName("input")[0].checked)
      {
        if(CommunitieIds == "")
        {
         CommunitieIds = cells[i].getElementsByTagName("input")[0].value;
        }
        else
        {
            CommunitieIds = CommunitieIds + "," + cells[i].getElementsByTagName("input")[0].value;
        }        
      }
    }
    document.getElementById("ctl00_ContentPlaceHolder1_hdnCommunity").value=CommunitieIds;
    return CommunitieIds;
}