// JScript File
var obj;
var curDDL=0;

function getChild(para1, para2)
{
	try
	{
	    
		obj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e1)
		{
			obj = null;
		}
	}
	if(obj!=null)
	{
	   // if (getElt_Id().selectedIndex!=0){
	        /*
            if (document.getElementById('hdf_orgLevel')!=null)
            {
	        document.getElementById('hdf_orgLevel').value=para2;
	        }
	        
	        if (document.getElementById('hdf_depth')!=null)
            {
	        document.getElementById('hdf_depth').value=para1;
	        }
	        */
	        curDDL = para1;	   
		    var url
		    obj.onreadystatechange = ProcessResponse;
		    //url=geturl()					
		    obj.open("POST", "../Masters/getLevel.aspx?level="+para2,  true);
		    obj.send(null);     		 
		//}
	
	}
	
	return false;
}


function chckLevel1(para1, para2)
	{ 	
		
	try
	{
		obj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e1)
		{
			obj = null;
		}
	}
	if(obj!=null)
	{
		var url
		obj.onreadystatechange = ProcessResponse;
		url=geturl()			
		obj.open("POST", url+"level="+para1,  true);
		obj.send(null);     
	    createDDL();
	}
	return false;
	
}


function geturl()
{
  var str
  str="../Masters/getlevel.aspx?"
  return str
}


function FindElt_Id(para)
{
	return document.getElementById(para);
}


function getElt_Id()
{
	return document.getElementById("ddlLevel"+curDDL);
}


function getTag_Name(para)
{
    
	var dsRoot=obj.responseXML.documentElement;  	
	if (obj.responseXML.documentElement==null){
	   clearDDL();
	   return false;
	}else{
	for(iloop=(curDDL+1);iloop<=totLevels-1;iloop++)
	    {	        
	        seleDDL = FindElt_Id("ddlLevel"+iloop);
	        for (var count = seleDDL.options.length-1;count >0; count--){
				    seleDDL.options[count] = null;
			    }	
//	        document.getElementById('div_child'+ iloop).innerHTML = "";
	    }
	return dsRoot.getElementsByTagName(para);
	}
}


function ProcessResponse()
{
    if(obj.readyState == 4)
	{	    
	    if(obj.status == 200)
		{
		
	        
//	        var htm	        
//	        if (curDDL != 0 && curDDL<totLevels) 
//	        {	            
//	            val = curDDL + 1;
//	            htm = "<br><select name=ddlLevel" + curDDL + " runat='server' onChange='getChild("+ val +",this.value)'><option>Select Below</option></select><br>";	            
//	            document.getElementById('div_child'+ curDDL).innerHTML = htm;
//	         }  
			var ddlOrders = getElt_Id()		
			if (ddlOrders != null){				
			    for (var count = ddlOrders.options.length-1;count >-1; count--)
			    {
				    ddlOrders.options[count] = null;
			    }			
    			
			    var tagVal = getTag_Name('levelID')
			    var tagNam = getTag_Name('levelName')
    			
    	        
			    //var span1 = document.getElementById("ss");
			    var html = "";			
			    var text; 
			    var valu;
			    var listItem;    
    			
			    listItem = new Option('Select','Select',  false, false);
				ddlOrders.options[ddlOrders.length] = listItem;       			
				
                for (var count = 0; count < tagNam.length; count++)
			    {
			        			    
				    text = (tagNam[count].textContent || tagNam[count].innerText || tagNam[count].text);
				    valu=(tagVal[count].textContent || tagVal[count].innerText || tagVal[count].text);
				    
				    listItem = new Option(text,valu,  false, false);
				    ddlOrders.options[ddlOrders.length] = listItem;
			    }
			}
		}   
		else
		{
		    clearDDL();
			//alert("Error retrieving data!" );
		}	    
	}
}



function createDDL()
{    
    var htm='';
    
    htm += "<table cellpadding='0' cellspacing='0'>";
    
    var val=0;
    for (i=1;i<=totLevels-1;i++)
    {
    val = parseFloat(i)+1    
       
       htm += "<tr><td class='td'align='center'>";
       htm += "<select name=ddlLevel" + i + " runat='server' class='dlist' onChange='getChild("+ val +",this.value)'><option>Select</option></select>"; 
       htm += "</td></tr>";
       //htm+="<span id='div_child" + i + "'></span>"
    }
    
    htm += "</table>";    
    document.getElementById('ddlLevel1').focus();
    document.getElementById('div_child').innerHTML = htm;
}



function clearDDL()
{
    for(iloop=curDDL;iloop<=totLevels-1;iloop++)
	    {	  
	        seleDDL = FindElt_Id("ddlLevel"+iloop);
	        for (var count = seleDDL.options.length-1;count >0; count--){
				    seleDDL.options[count] = null;
			    }	      
	        //document.getElementById('div_child'+ iloop).innerHTML = "";
	    }
	return false
}