﻿// JScript File

function UpdateControlList(r) 
{ 
    if(r.ReadyState==4)
    {
        ClearAndSetControlListItems(r.ResponseText);
	}
    
}
//function ClearAndSetControlListItems(categoryNode)
//{
//    var xmlDom=new ActiveXObject("Microsoft.XMLDOM");
//        var stateList = document.getElementById("ctl00_PageWebPartsList1_ddlControls");
//        
//	    //Clears the state combo box contents.
//	    for (var count = stateList.options.length-1; count >-1; count--)
//	    {
//		    stateList.options[count] = null;
//	    }
//	    
//        xmlDom.loadXML(categoryNode);
//        
//        xmlDom.async=false;
//        var stateNodes = xmlDom.selectNodes("category/usercontrol")
//	    
//	    var textValue; 
//	    var optionItem;
//	    //Add new states list to the state combo box.
//	    for (var count = 0; count < stateNodes.length; count++)
//	    {
//   		    textValue = stateNodes[count].attributes.getNamedItem("path").value;
//		    optionItem = new Option( stateNodes[count].text,textValue ,  false, false);
//		    stateList.options[stateList.length] = optionItem;
//	    }
//	    if(stateList.length > 0)
//	    {
//	        stateList.options[0].selected=true;
//	    }
//}
////Returns the node text value 
//function GetInnerText (node)
//{
//	 return (node.textContent || node.innerText || node.text) ;
//}

function invokeControlListPopulationAspx(categoryListID,url,query)
{

    var categoryList = document.getElementById(categoryListID);
    if(categoryList)
    {
        var categoryID = categoryList.options[categoryList.selectedIndex].value;
        var categoryName = categoryList.options[categoryList.selectedIndex].text;
        //alert(categoryName);
        //alert(categoryID);
            var ajaxRequest;
            var pageRequest;
            var connection;

            ajaxRequest=new System.Net.Ajax.Request();
            ajaxRequest.URL=url+"?cID="+encodeURI(categoryID)+"&cName="+encodeURI(categoryName)+"&"+query;
//            alert(ajaxRequest.URL);
            ajaxRequest.Callback=UpdateControlList;
            ajaxRequest.Method="GET";
            pageRequest=new System.Net.Ajax.PageRequests(ajaxRequest);
            connection=new System.Net.Ajax.Connection(pageRequest);
            
            connection.Open();
  }

}
