// 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(window.ActiveXObject)
    {    
        try
        {
	        obj = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
	        try
	        {
		        obj = new ActiveXObject("Microsoft.XMLHTTP");
	        }
	        catch(e1)
	        {
		        obj = null;
	        }
        }
    }  
     else if(window.XMLHttpRequest)
     {
        try
        {
	        obj = new XMLHttpRequest("Msxml2.XMLHTTP");
        }
        catch(e)
        {
	        try
	        {
		        obj = new XMLHttpRequest("Microsoft.XMLHTTP");
	        }
	        catch(e1)
	        {
		        obj = null;
	        }
        }
    }     
    if(obj!=null)
    {
       // if (getElt_Id().selectedIndex!=0){
               //document.write("<br>../Masters/TA_UI_Master_getOrg.aspx?level="+para2+"<BR>")
            curDDL = para1;	   
	        var url
	        ses=0;
	        if(window.ActiveXObject)
    {    
	        obj.onreadystatechange = ProcessResponse_getOrg;
	         if (para2 == 'Select' && para1!=1 ){       
//                   para2 = FindElt_Id_getOrg("ddlLevel"+(para1-2)).value;
                   pp = para1-1;
                   para2 = FindElt_Id_getOrg("ddlLevel"+(pp)).value;
                   ses = FindElt_Id_getOrg("ddlLevel"+(para1-2)).value;
	        }
	        if (aspnetForm.ctl00_BodyContentPH_hdf_orgLevel!=null)
            {
                aspnetForm.ctl00_BodyContentPH_hdf_orgLevel.value=para2;
            }
	        //url=geturl()					
	        //obj.open("POST", "../Masters/TA_UI_Master_getOrg.aspx?level="+para2+"&levelno"+para3,  false);
	        obj.open("POST", "../Masters/TA_UI_Master_getOrg_MailPopup.aspx?level="+para2 + "&ctr="+ para1 + "&ses=" + ses ,  false);
	        obj.send(null);  
	        }
	        else if(window.XMLHttpRequest)
     {
	         if (para2 == 'Select' && para1!=1 ){       
//                   para2 = FindElt_Id_getOrg("ddlLevel"+(para1-2)).value;
                   pp = para1-1;
                   para2 = FindElt_Id_getOrg("ddlLevel"+(pp)).value;
                   ses = FindElt_Id_getOrg("ddlLevel"+(para1-2)).value;
	        }
	        if (document.getElementById("ctl00_BodyContentPH_hdf_orgLevel")!=null)
            {
                document.getElementById("ctl00_BodyContentPH_hdf_orgLevel").value=para2;
            }
	        //url=geturl()					
	        //obj.open("POST", "../Masters/TA_UI_Master_getOrg.aspx?level="+para2+"&levelno"+para3,  false);
	        obj.open("POST", "../Masters/TA_UI_Master_getOrg_MailPopup.aspx?level="+para2 + "&ctr="+ para1 + "&ses=" + ses ,  false);
	        obj.send(null);  
	        obj.onreadystatechange = ProcessResponse_getOrg();
     }	        
/*	        
	    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(window.ActiveXObject)
    {    
        try
        {
	        obj = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
	        try
	        {
		        obj = new ActiveXObject("Microsoft.XMLHTTP");
	        }
	        catch(e1)
	        {
		        obj = null;
	        }
        }
    }  
     else if(window.XMLHttpRequest)
     {
        try
        {
	        obj = new XMLHttpRequest("Msxml2.XMLHTTP");
        }
        catch(e)
        {
	        try
	        {
		        obj = new XMLHttpRequest("Microsoft.XMLHTTP");
	        }
	        catch(e1)
	        {
		        obj = null;
	        }
        }
    }     
    if(obj!=null)
    {
	    var url
	    if(window.ActiveXObject)
    {   
	    obj.onreadystatechange = ProcessResponse_getOrg;
	    url=geturl_getOrg()			
	    obj.open("POST", url+"level="+para1,  false);
	    obj.send(null);   
	    }
	    else if(window.XMLHttpRequest)
     {
	    url=geturl_getOrg()			
	    obj.open("POST", url+"level="+para1,  false);
	    obj.send(null);  
	    obj.onreadystatechange = ProcessResponse_getOrg();
     }  
    }	
    createDDL_getOrg();	
    return false;
}
function geturl_getOrg()
{
  var str
  str="../Masters/TA_UI_Master_getOrg_MailPopup.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)
{
    if(obj.responseXML==null)
    {
    clearDDL_getOrg();
    return false;
    }
    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);
			        text = text.replace('&amp;','&'); 
			        listItem = new Option(text,valu,  false, false);
			        ddlOrders.options[ddlOrders.length] = listItem;
		        }
		    }
		    //alert(document.getElementById("ctl00_BodyContentPH_rbtnFlexibleTimingsYes")); 
		    if (document.getElementById("ctl00_BodyContentPH_rbtnFlexibleTimingsYes")!=null)
		    {
		    if (checkPageLoad==1)
		    {
		    GetFlexibleEmployeeData();
		    }
		    }
//			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
////		                    for (iDesg=0;iDesg<document.getElementById("ctl00_BodyContentPH_hidEmpDesg").length;iDesg++)
////		                    {
////		                        if (document.aspnetForm.ctl00_BodyContentPH_ddl_Designation.options[iDesg].value==document.getElementById("ctl00_BodyContentPH_hidEmpDesg").value)
////		                        {
////		                            document.getElementById("ctl00_BodyContentPH_ddl_Designation").value = document.getElementById("ctl00_BodyContentPH_hidEmpDesg").value;
////		                        }
////		                    }
////			                }
//		            }   		
//			     }
	    }   
	    else
	    {
	        clearDDL_getOrg();
		    //alert("Error retrieving data!" );
	    }	    
    }
}
function createDDL_getOrg()
{    
    var htm='';
    htm += "<div class='row'>";
    var chVal = 0;
    var val=0;    
    for (i=0;i<=totLevels-1;i++)
    {
        if (chVal>=2)
        {
            chVal=0
            htm += "</div><div class='row'>"
        }
        chVal += 1;
       val = parseFloat(i)+1           
       htm += "<div class='col-md-3'>" + levelNameArray[i] + " </div><div class='col-md-3'>";
       htm += "<select id=ddlLevel" + i + " runat='server' class='form-control' onChange='getChild_getOrg("+ val +",this.value)'><option>"+ Sel +"</option></select>";
       htm += "</div>";
    }   
    if (chVal<2)
    {
      htm += "<div class='col-md-3'></div><div class='col-md-3'></div>";
    }
    htm += "</div>";
    //Adding if condition for checking whether this values is null or not by -Added by MAnjula.P on 27-Jan-2014 for javascript error
   if(document.getElementById('div_child')!=null)
   {
    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)
        }
}
