﻿
$(document).ready(function() {

$("#btnClear").click(function () {ClearFields(); });

   // LoadCat();


//    function LoadHomeImage(){
    
//$("#divResults").append("<u><b>Quick Start Instructions</b></u><ul><li>Start typing in the City you would like to search.<br/>(Auto populate function will start to narrow your selections.)</li><li>Select the City from the auto populated list.<br />(Categories with display how many entries are available for viewing?)</li><li>Check the box of the Categories you would like to view.<br />(You may select Select all Categories to all Categories.)</li><li>Click Search to display your selections.</li><li>Use the interior scroll bar to view the results.</li></ul>");
    
    
  $("#divResults").append("<u><b>Quick Start Instructions</b></u><ol><li>Begin by typing a city name or zip code.</li><li>Click on a city or zip code from the populated list.</li><li>If you select a city, you will then have the option to narrow your search by borough.</li><li>Select the categories you would like to view.</li><li>Click Search to display your selections.</li><li>Use the interior scroll bar to view the results.</li></ol>For detailed instructions, please <a href='help.html' target='_blank'><i>Click here</i></a>");
      
    
    
    
//    }

    var category_count = 0;
    function LoadCat(){
            

            var divResults = document.getElementById("divResults");
            

         $.get("category_get.aspx", { }, function(data) {	
    					    
					        var lblCount = document.createElement('label');
                                lblCount.setAttribute("id","lblCount");
                                lblCount.style.visibility = 'hidden';
                                
                                
                                   var divSelectAll = document.createElement('div');
                                       divSelectAll.setAttribute("id","divSelectAll");
//                                       divSelectAll.style.width = "300px";
//                                       divSelectAll.style.height = "28px"; 
                                       
                                   var lblSelectAll = document.createElement('label');
                                       lblSelectAll.setAttribute("id","lblSelectAll");
                                       lblSelectAll.setAttribute("class", "lblSelectAll");
                                       
                                   var chkSelectAll = document.createElement('input');
                                       chkSelectAll.setAttribute("type","checkbox");
                                       chkSelectAll.setAttribute("id","chkSelectAll");
                                       chkSelectAll.setAttribute("class", "chkSelectAll");
                                       chkSelectAll.onclick = function() { SelectAll(); }
//                                       chkSelectAll.setAttribute("checked", "checked");

                                   var spcr2 = document.createElement('label');
                                       spcr2.innerHTML = "&nbsp;";
                                       
                                       lblSelectAll.innerHTML = "<i><u>Select All Categories</u></i>";
                                                                              
                                       divSelectAll.appendChild(chkSelectAll); 
                                       divSelectAll.appendChild(spcr2); 
                                       divSelectAll.appendChild(lblSelectAll);                                       
                                       divResults.appendChild(divSelectAll);
                                
    					    
					         $('Table', data).each(function(data) {                    
                        
                                
                                var cat = $(this).find("catName").text(); 
                                var active = $(this).find("catActive").text();
                                var priority = $(this).find("catPriority").text();                          
                                var id = $(this).find("catID").text();
                                if(active=="true"){   
                                        category_count = category_count + 1;
                                                                            
                                   var resultDiv = document.createElement('div');
                                       resultDiv.setAttribute("id","div" + id);
                                       resultDiv.style.width = "300px";
                                       resultDiv.style.height = "25px";   
                                       
                                   var catCount = document.createElement('label');
                                       catCount.setAttribute("id","lblCount" + id);
                                       catCount.setAttribute("class", "resultSet");
                                       
                                   var result = document.createElement('label');
                                       result.setAttribute("id","lblResult" + category_count);
                                       result.setAttribute("class", "resultSet");
                                       
                                   var chk = document.createElement('input');
                                       chk.setAttribute("type","checkbox");
                                       chk.setAttribute("id","chk" + category_count);
                                       chk.setAttribute("class", "resultSet");
//                                       chk.setAttribute("checked", "checked");
                                       
                                   var spcr = document.createElement('label');
                                       spcr.innerHTML = "&nbsp;";
                                       
                                       
                                       
                                       lblCount.innerHTML = category_count;
                                       catCount.innerHTML = "(0)";
                                       result.innerHTML = cat;  
                                       
                                                                              
                                       resultDiv.appendChild(chk);                                       
                                       resultDiv.appendChild(result);
                                       resultDiv.appendChild(catCount);
                                       
                                       $("#navMenu").append(lblCount)
//                                       resultDiv.appendChild(lblCount);                                     
                                       divResults.appendChild(resultDiv);
                                       
                                       
                                }
                                
                            });


        });



}

function SelectAll(){

    var tempCheck = $("#chkSelectAll").attr('checked');
    
    if(tempCheck == true){
    
        for(c=1;c<=category_count;c++){
            $("#chk" + c).attr("checked",true);
        }
    }else{
        for(c=1;c<=category_count;c++){
            $("#chk" + c).attr("checked",false);
        }
    
    }

}

function ClearFields(){
        
           window.location = 'default.aspx';
            
        }


});//End Docunemt Ready
