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

function getChild_getOrg(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 (aspnetForm.ctl00_BodyContentPH_hdf_orgLevel!=null)
                    {
	                aspnetForm.ctl00_BodyContentPH_hdf_orgLevel.value=para2;
	            }
    	        
    	        
	            curDDL = para1;	   
		        var url
		        obj.onreadystatechange = ProcessResponse_getOrg;
   		     if (para2 == 'Select' && para1!=1 ){       
                   para2 = FindElt_Id_getOrg("ddlLevel"+(para1-2)).value;
    	    }		 

		        //url=geturl()					
		        //obj.open("POST", "../Masters/TA_UI_Master_getOrg.aspx?level="+para2+"&levelno"+para3,  false);
		        obj.open("POST", "../Masters/TA_UI_Master_getOrg.aspx?level="+para2,  false);
		        obj.send(null); 
		//}
	return false;
	}
	
}


function chckLevel1_getOrg(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_getOrg;
		url=geturl_getOrg()			
		obj.open("POST", url+"level="+para1,  true);
		obj.send(null);     
	    createDDL_getOrg();
	}
	return false;
	
}


function geturl_getOrg()
{
  var str
  str="../Masters/TA_UI_Master_getOrg.aspx?"
  return str
}


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


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


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


function ProcessResponse_getOrg()
{
    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_getOrg()		
			if (ddlOrders != null){				
			    for (var count = ddlOrders.options.length-1;count >-1; count--)
			    {
				    ddlOrders.options[count] = null;
			    }			
    			
			    var tagVal = getTag_Name_getOrg('id')
			    var tagNam = getTag_Name_getOrg('name')    			
    	        
			    //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);
				    //alert("text =" +text);
				    listItem = new Option(text,valu,  false, false);
				    ddlOrders.options[ddlOrders.length] = listItem;
			    }	
			    		    
			}
			if (document.getElementById("ctl00_BodyContentPH_ddl_Designation")!=null)
			    {
			    GetEmployeeData();              //fill designation ddl
			    }
		}   
		else
		{
		    clearDDL_getOrg();
			//alert("Error retrieving data!" );
		}	    
	}
}



function createDDL_getOrg()
{    

    var htm='';
    
    htm += "<table cellpadding='0' cellspacing='1' border='0' width='100%'><tr>";
    var chVal = 0;
    var val=0;
    //for (i=1;i<=totLevels-1;i++)
    for (i=0;i<=totLevels-1;i++)
    {
    
        if (chVal>=2){
            chVal=0
            htm += "</tr><tr>"
        }
        //else{
            chVal += 1;
        //}
        val = parseFloat(i)+1           
       htm += "<td class='td' width='10%' align='left'>" + levelNameArray[i] + " </td><td  width='40%' class='td' align='left'>";       
       htm += "<select name=ddlLevel" + i + " runat='server' class='dlist' onChange='getChild_getOrg("+ val +",this.value)'><option>Select</option></select>";        
       htm += "</td>";       
       //htm+="<span id='div_child" + i + "'></span>"
    }
    
    htm += "</tr></table>";    
    document.getElementById('div_child').innerHTML = htm;   
    //var frm=document.forms[0];
    //frm.elements[3].focus();
    
    //document.getElementById('ddlLevel0').focus() 
    //assignValue_getOrg();	
    
}



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

//var iloopp = 0;

function assignValue_getOrg()
{    
     for(iloopp=0;iloopp<=levelArray.length-1;iloopp++)
        {       
            getChild_getOrg(iloopp+1,levelArray[levelArray.length-(iloopp+1)]) ;
            seleDDL = FindElt_Id_getOrg("ddlLevel" + iloopp);
            seleDDL.value= levelArray[levelArray.length-(iloopp+1)];    
        }
        document.getElementById('ddlLevel0').focus() ;
 
//        getChild_getOrg(iloopp+1,levelArray[levelArray.length-(iloopp+1)]) ;   
//        seleDDL = FindElt_Id_getOrg("ddlLevel" + iloopp);
//        seleDDL.value= levelArray[levelArray.length-(iloopp+1)];     
//        if(iloopp < levelArray.length )
//        {
//            iloopp = iloopp + 1;
//            assignValue_getOrg();
//        }

}
