// 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 (aspnetForm.ctl00_BodyContentPH_hdf_orgLevel!=null)
            {
	            aspnetForm.ctl00_BodyContentPH_hdf_orgLevel.value=para2;
	        }
	        
	   // if (getElt_Id().selectedIndex!=0){
	   
               //document.write("<br>../Masters/TA_UI_Master_getOrg.aspx?level="+para2+"<BR>")

            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);  	        
/*	        
		if (para2 != 'Select'){
	        curDDL = para1;	   
		    var url
		    obj.onreadystatechange = ProcessResponse_getOrg;
		    //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()
{
//document.write("<br>Check =  " +obj.readyState + " <br>")
    //alert(obj.readyState);
    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 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)
	            {
		             if (checkPageLoad==1){
		             
		             //alert(checkPageLoad + " evefvef")
		                var indexdesgn=document.aspnetForm.ctl00_BodyContentPH_ddl_Designation.selectedIndex;
                        var designation=document.aspnetForm.ctl00_BodyContentPH_ddl_Designation.options[indexdesgn].value; 
                    
//			                if (designation=="-Select-")
//			                {
		                    //alert(designation)
		                    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='500'><tr>";
    var chVal = 0;
    var val=0;    
    for (i=0;i<=totLevels-1;i++)
    {
        if (chVal>=2){
            chVal=0
            htm += "</tr><tr>"
        }
            chVal += 1;
        
        val = parseFloat(i)+1           
       htm += "<td class='td' width='50%' align='left'>" + levelNameArray[i] + " </td><td align='left' width='50%' class='td'>";       
       htm += "<select name=ddlLevel" + i + " runat='server' class='dlist' onChange='getChild_getOrg("+ val +",this.value)'><option>Select</option></select>";        
       htm += "</td>";              
    }
    
    htm += "</tr></table>";
    
    document.getElementById('div_child').innerHTML = htm;        
    //checkPageLoad=1;
    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;
			    }
	    }
	    
	return false
}

function assignValue_getOrg()
{      
        //alert("Loading Organization Levels....");
     getChild_getOrg(0,0);   
     for(iloopp=0;iloopp<=orgArray.length-2;iloopp++)
        {   
           getChild_getOrg(iloopp+1,orgArray[iloopp]) ;            
           seleDDL = FindElt_Id_getOrg("ddlLevel" + iloopp);                
           if (orgArray[iloopp]!=0){
                seleDDL.value= orgArray[iloopp];                
           }
        }
        checkPageLoad=1;
        
}
function assignValue_getOrg2(iloopp){
            alert("hi");
           
            if (iloopp==null){
                iloopp=0
            }
           document.write(iloopp+1 + " " + orgArray[iloopp])
           getChild_getOrg(iloopp+1,orgArray[iloopp]) ;
             
           seleDDL = FindElt_Id_getOrg("ddlLevel" + iloopp);    
                 
          
           if (orgArray[iloopp]!=0){
                seleDDL.value= orgArray[iloopp];    
           }
           for (j=0;j<=seleDDL.length;j++){
            document.write (seleDDL.options[j])
           }
        iloopp=iloopp+1;
        if (iloopp<=orgArray.length-2){
            assignValue_getOrg(iloopp)
        }

}
