﻿// JScript File

var xmlHttp
function GetSubCat(ctl)
{     
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }       
    var url="/AJAX/AjaxServer.aspx?CatId="+ctl.value
    //url=url+"&sid="+Math.random()    
    xmlHttp.onreadystatechange=Show_Subcategory
    xmlHttp.open("GET",url,false)
    xmlHttp.send(null)
}

function Show_Subcategory()
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete')
    { 
      if(xmlHttp.status == 200)
	  {
	    var response = xmlHttp.responseText;
	    var ctlName = document.getElementById('ddlSubcategory_Id');
	        for(var i=ctlName.options.length-1;i>=0;i--)
	        {
			    ctlName.options[i]=null;				
		    }		
            document.getElementById('ddlSubcategory_Id').options[0]= new Option('--Select--','0',false,false);	   
	    if(response.length>0)
	    {		
            var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	        xmlDoc.async = false;
	        xmlDoc.loadXML(response);	
	        var opt;
	        var Subcategories = xmlDoc.getElementsByTagName("Subcategories"); 
	        var sCat = Subcategories[0].getElementsByTagName("SubCategory");		        
	        if(Subcategories.length > 0)
	        {	        
	            for(var j=0;j<sCat.length;j++)
	            {
	                document.getElementById('ddlSubcategory_Id').options[j+1]= new Option(sCat[j].lastChild.text,sCat[j].firstChild.text,false,false); //content,value
                }    
	        }
	    }
      }
    }     
} 

function GetXmlHttpObject()
{ 
     try
    {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        //Try creating an XMLHTTP Object
       // alert(xmlHttp);
    }
    catch(Ex)
    {
        try
        {
	        //First failure, try again creating an XMLHTTP Object
	        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(Ex)
        {
	        xmlHttp = null;
        }
    }
    if(!xmlHttp&&typeof XMLHttpRequest != 'undefined')
    {
        xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}



