// JScript File

var objLeaveApplication = null;

function EmployeeNamesForLeaveApplication()
{
        try
        {
             objLeaveApplication = new XMLHttpRequest();
        }
        catch(ex)
        {
            try
            {
                objLeaveApplication=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    objLeaveApplication=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e1)
                {
                    objLeaveApplication=null;
                }
            }
        }
        
        if(objLeaveApplication!=null)
        {
        
            var k=Math.floor(Math.random()*111);
            objLeaveApplication.onreadystatechange=Process_Response_EmployeesLeaveApplication;
            objLeaveApplication.open("GET","AjaxEmployeeForLeaveApplication.aspx?Sid="+k,true);
            objLeaveApplication.send(null);
        }
        
        return false;
    }

 
function Process_Response_EmployeesLeaveApplication()
{
    if (document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').options.length != null)
	{				
        for (var count = document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').options.length-1;count >-1; count--)
		{
		    document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').options[count] = null;
		}	
    }
		
	if(objLeaveApplication.readyState == 4)
	{
        if(objLeaveApplication.status == 200)
		{
            if(objLeaveApplication.responseText=="Fail" || objLeaveApplication.responseText=="")
			{
			    var newOptSelect = new Option('-Select-','-Select-',  false, false);
                document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').options[0]=newOptSelect;
                document.aspnetForm.ctl00_CP_Transaction_txtFromDate.value="";
                document.aspnetForm.ctl00_CP_Transaction_txtToDate.value="";
				alert("No Records");
				return;
			}
			else
			{
			    //alert(objLeaveApplication.responseTEXT);
				var xml=objLeaveApplication.responseXML;
				var dsRoot=xml.documentElement.getElementsByTagName("Details");  
				var totalRec = dsRoot.length;
                var newOptSelect = new Option('-Select-','-Select-',  false, false);
                document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').options[0]=newOptSelect;
                        
                for(i=0; i<totalRec; i++)
                {
                    var ConId = xml.getElementsByTagName("Employee_x0020_Name")[i];
                    var EmpId=xml.getElementsByTagName("Employee_Id")[i];
                    var Employee_Code_Id=xml.getElementsByTagName("Employee_Code_Id")[i];
                    //var newOpt=new Option(ConId.text,EmpId.text);
                    var newOpt=new Option(Employee_Code_Id.text+ ' - ' + ConId.text,EmpId.text);
                    document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').options[i+1]=newOpt;
                }
                
                document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').focus();
            }
        }
        else
		{
		    alert("Error in retriving details");
		}
			
    }
}


//Display Leave Types, Restricted Holidays, Global Holidays and Encashment details in ddl_LeaveType

var objLeaveTypes = null;

function leaveOptions(leaveSource)
{
      document.aspnetForm.ctl00_CP_Transaction_ddl_SessionTo.selectedIndex=0;
	  
	  document.aspnetForm.ctl00_CP_Transaction_ddl_SessionFrom.selectedIndex=0;
	  
	  //Hide division Borrow Leave
	  
	  document.getElementById('ctl00_CP_Transaction_divBorrowLeave').style.display="none"; 
	  document.getElementById('ctl00_CP_Transaction_chkBorrowLeave').checked=false; 
	  
    if(leaveSource=="-Select-")
    {
        //alert("Select a type of Leave");
        if (document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options.length != null)
        {				
            for (var count = document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options.length-1;count >-1; count--)
            {
                document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[count] = null;
            }	
        }
        
        document.aspnetForm.ctl00_CP_Transaction_txtFromDate.value="";
        document.aspnetForm.ctl00_CP_Transaction_txtToDate.value="";
        document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value="";
        document.getElementById('ctl00_CP_Transaction_txt_Numberofdays').value="";
        
        var newOptSelect = new Option('-Select-','-Select-',  false, false);
        document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[0]=newOptSelect;
        return;   
    }
    else if(leaveSource=="Restricted Holiday")
    {
        document.aspnetForm.ctl00_CP_Transaction_txtFromDate.value="";
        document.aspnetForm.ctl00_CP_Transaction_txtToDate.value="";
        document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value="";
        document.getElementById('ctl00_CP_Transaction_txt_Numberofdays').value=""; 
    }
     else if(leaveSource=="Encashment")
    {
        var enK=Math.floor(Math.random()*111);
        var EmployeeId=document.getElementById('ctl00_CP_Transaction_hdnEmployeeId').value;
        location.replace("TA_UI_Transaction_Encashment.aspx?EmployeeId=" + EmployeeId  + "&k="  + enK);
        return;   
    }
    else if(leaveSource=="ESI")
    {
        var EmployeeId=document.getElementById('ctl00_CP_Transaction_hdnEmployeeId').value;
        
        if(EmployeeId=="")
        {
        alert("Select an Employee");
        }
        document.aspnetForm.ctl00_CP_Transaction_txtFromDate.value="";
        document.aspnetForm.ctl00_CP_Transaction_txtToDate.value="";
        
        document.getElementById('tr_RemainingNoOfLeave').style.display="none";
        document.getElementById('ctl00_CP_Transaction_txt_Numberofdays').value="";
        
        if (document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options.length != null)
        {				
            for (var count = document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options.length-1;count >-1; count--)
            {
                document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[count] = null;
            }	
        }
       
        
       // var newOptSelect = new Option('-Select-','-Select-',  false, false);
       // document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[0]=newOptSelect;
    
        var newOpt=new Option("Others","Others"); 
        
        document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[0]=newOpt;
        document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').selectedIndex=0;
        return;
    }

   
    document.getElementById('tr_RemainingNoOfLeave').style.display="block";

    try
    {
        objLeaveTypes = new XMLHttpRequest();
    }
    catch(ex)
    {
        try
            {
                objLeaveTypes=new ActiveXObject("Msxml2.XMLHTTP");
            }
        catch(e)
            {
                try
                    {
                        objLeaveTypes=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                catch(e1)
                    {
                        objLeaveTypes=null;
                    }
            }
    }

    if(objLeaveTypes!=null)
    {
        var k=Math.floor(Math.random()*111);
        var EmpId=document.getElementById('ctl00_CP_Transaction_hdnEmployeeId').value;
      
        if(EmpId==null || EmpId==0 || EmpId=="-Select-")
        {
            alert("Select an Employee");
            return;
            document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=0.0;     
        }
        if(leaveSource=="Comp Off")
        {
            objLeaveTypes.onreadystatechange=Process_Response_EmployeesLeaveCompOff;
            objLeaveTypes.open("GET","AjaxLeaveCompOff.aspx?leaveSource=" + leaveSource + "&EmpId="+ EmpId + "&k="  + k,true);
            objLeaveTypes.send(null);
        }
        else
        {
            objLeaveTypes.onreadystatechange=Process_Response_EmployeesLeaveOptions;
            objLeaveTypes.open("GET","AjaxLeaveOptions.aspx?leaveSource=" + leaveSource + "&EmpId="+ EmpId + "&k="  + k,true);
            objLeaveTypes.send(null);
        }
    }
        
    return false;
}

 
function Process_Response_EmployeesLeaveOptions()
{
    if (document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options.length != null)
	{				
	    for (var count = document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options.length-1;count >-1; count--)
		{
		    document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[count] = null;
		}	
    }
			
	if(objLeaveTypes.readyState == 4)
	{
	    if(objLeaveTypes.status == 200)
		{
		    if(objLeaveTypes.responseText=="Fail" || objLeaveTypes.responseText=="")
			{
			
			    if(document.getElementById('ctl00_CP_Transaction_ddl_Type').selectedIndex==4)
			    {
			        alert("LOP not defined");
			    }
			    else
			    {
			        alert("Leave Policy not defined");
			    }
			    
			    var newOptSelect = new Option('-Select-','-Select-',  false, false);
                document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[0]=newOptSelect;
                
                document.aspnetForm.ctl00_CP_Transaction_txtFromDate.value="";
                document.aspnetForm.ctl00_CP_Transaction_txtToDate.value="";
                
                document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value="";
                document.getElementById('ctl00_CP_Transaction_txt_Numberofdays').value="";
				return;
			}
			else
			{
			    var xml=objLeaveTypes.responseXML;
				var dsRoot=xml.documentElement.getElementsByTagName("Details");  
				var totalRec = dsRoot.length;
				var newOptSelect = new Option('-Select-','-Select-',  false, false);
                document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[0]=newOptSelect;
          
                for(i=0; i<totalRec; i++)
                {
                    if(document.getElementById('ctl00_CP_Transaction_ddl_Type').selectedIndex==2)
                    {
                        var HolidayDescription=xml.getElementsByTagName("Holiday_Description")[i];
                        var HolidayId=xml.getElementsByTagName("Holiday_Id")[i];
                        
                        var newOptHoliday=new Option(HolidayDescription.text,HolidayId.text);
                        document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[i+1]=newOptHoliday;
                        
                        document.getElementById('ctl00_CP_Transaction_hdnTxtLeaveTypeId').value=HolidayId.text;
                     
                    }
                    else
                    {
                        document.aspnetForm.ctl00_CP_Transaction_txtFromDate.value="";
                        document.aspnetForm.ctl00_CP_Transaction_txtToDate.value="";
                        var ConId = xml.getElementsByTagName("LeaveType")[i];
                        var LeaveTypeId=xml.getElementsByTagName("LeaveType_Id")[i];
                        
                        var newOpt=new Option(ConId.text,LeaveTypeId.text);
                        document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[i+1]=newOpt;
                        
                        document.getElementById('ctl00_CP_Transaction_hdnTxtLeaveTypeId').value=LeaveTypeId.text;
                    }
                   
               }
               document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').focus();
            }
        }
        else
	    {
	        alert("Error in retriving details");
        }
    }
}

//Get Compensation off days from Ajax page

function Process_Response_EmployeesLeaveCompOff()
{
    if (document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options.length != null)
	{				
	    for (var count = document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options.length-1;count >-1; count--)
		{
		    document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[count] = null;
		}	
    }
   //Hide division Borrow Leave
   document.getElementById('ctl00_CP_Transaction_divBorrowLeave').style.display="none"; 
   document.getElementById('ctl00_CP_Transaction_chkBorrowLeave').checked=false; 
			
	if(objLeaveTypes.readyState == 4)
	{
	    if(objLeaveTypes.status == 200)
		{

		    
		    if(objLeaveTypes.responseText=="Fail" || objLeaveTypes.responseText=="")
			{
						
			   	alert("Leave Policy not defined");
			    			    
			    var newOptSelect = new Option('-Select-','-Select-',  false, false);
                document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[0]=newOptSelect;
                
                document.aspnetForm.ctl00_CP_Transaction_txtFromDate.value="";
                document.aspnetForm.ctl00_CP_Transaction_txtToDate.value="";
                
                document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value="";
                document.getElementById('ctl00_CP_Transaction_txt_Numberofdays').value="";
				return;
			}
			else
			{
			    var xml=objLeaveTypes.responseXML;
				var dsRoot=xml.documentElement.getElementsByTagName("Details");  
				var totalRec = dsRoot.length;
                document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=xml.getElementsByTagName("CompOffDays")[0].text;
                
                var newOpt=new Option("Others","Others"); 
        
                document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').options[0]=newOpt;
                document.getElementById('ctl00_CP_Transaction_ddl_LeaveType').selectedIndex=0;
                   
             }
               
            
        }
        else
	    {
	        alert("Error in retriving details");
        }
    }
}

// Get Remaining no of leaves per leave type

var objRemainingNoOfLeaves = null;

function RemainingNoOfLeaves(leaveTypeId)
{
       	 //Hide division Borrow Leave
       	document.getElementById('ctl00_CP_Transaction_divBorrowLeave').style.display="none"; 
		document.getElementById('ctl00_CP_Transaction_chkBorrowLeave').checked=false; 
		
      //Change From Session and To Session to Default 
      document.aspnetForm.ctl00_CP_Transaction_ddl_SessionTo.selectedIndex=0;
	  document.aspnetForm.ctl00_CP_Transaction_ddl_SessionFrom.selectedIndex=0;
	  document.getElementById('ctl00_CP_Transaction_txt_Numberofdays').value="";
    
    // alert(leaveTypeId);
    if(leaveTypeId=='-Select-')
    {
        document.aspnetForm.ctl00_CP_Transaction_txtFromDate.value="";
        document.aspnetForm.ctl00_CP_Transaction_txtToDate.value="";
        document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value="";
        document.getElementById('ctl00_CP_Transaction_txt_Numberofdays').value="";
        return;
    }
    else if(leaveTypeId=="Others")
    {
   
        return;
    }  

    try
        {
             objRemainingNoOfLeaves = new XMLHttpRequest();
        }
        catch(ex)
                  {
                    try
                        {
                            objRemainingNoOfLeaves=new ActiveXObject("Msxml2.XMLHTTP");
                        }
                    catch(e)
                        {
                            try
                                {
                                    objRemainingNoOfLeaves=new ActiveXObject("Microsoft.XMLHTTP");
                                }
                            catch(e1)
                                {
                                    objRemainingNoOfLeaves=null;
                                }
                        }
                 }
        
if(objRemainingNoOfLeaves!=null)
{
    var k=Math.floor(Math.random()*111);
    var EmpId=document.getElementById('ctl00_CP_Transaction_hdnEmployeeId').value;
           
    // if restricted Holidays selected then go to the corresponding remote page 
    if(document.getElementById('ctl00_CP_Transaction_ddl_Type').selectedIndex==2)
    {
        // leaveTypeId="Restricted Holiday";
        objRemainingNoOfLeaves.onreadystatechange=Process_Response_RestrictedHolidays;
        document.getElementById('ctl00_CP_Transaction_hdnTxtLeaveTypeId').value=leaveTypeId;
        objRemainingNoOfLeaves.open("GET","AjaxRemainingNoOfHolidays.aspx?leaveTypeId=" + leaveTypeId + "&EmpId="+ EmpId + "&k="  + k,true);
        objRemainingNoOfLeaves.send(null);
    }
    else if(document.getElementById('ctl00_CP_Transaction_ddl_Type').selectedIndex==4)
    {
        document.getElementById('ctl00_CP_Transaction_hdnTxtLeaveTypeId').value=leaveTypeId;
        objRemainingNoOfLeaves.onreadystatechange=Process_Response_EmployeesRemainingNoOfLOPDays;
        objRemainingNoOfLeaves.open("GET","AjaxRemainingNoOfLOPDays.aspx?leaveTypeId=" + leaveTypeId + "&EmpId="+ EmpId + "&k="  + k,true);
        objRemainingNoOfLeaves.send(null);
    }
        
    else
    {
        document.getElementById('ctl00_CP_Transaction_hdnTxtLeaveTypeId').value=leaveTypeId;
        objRemainingNoOfLeaves.onreadystatechange=Process_Response_EmployeesRemainingNoOfLeaves;
        objRemainingNoOfLeaves.open("GET","AjaxRemainingNoOfLeaves.aspx?leaveTypeId=" + leaveTypeId + "&EmpId="+ EmpId + "&k="  + k,true);
        objRemainingNoOfLeaves.send(null);
    }
}
        
return false;
}

 
function Process_Response_EmployeesRemainingNoOfLeaves()
{
    if(objRemainingNoOfLeaves.readyState == 4)
	{
	    if(objRemainingNoOfLeaves.status == 200)
		{
		    var xml=objRemainingNoOfLeaves.responseXML;
		        
		        //Hide division Borrow Leave
				document.getElementById('ctl00_CP_Transaction_divBorrowLeave').style.display="none"; 
			    document.getElementById('ctl00_CP_Transaction_chkBorrowLeave').checked=false;
			    
			if(objRemainingNoOfLeaves.responseText=="Fail" || objRemainingNoOfLeaves.responseText=="")
			{

			    document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=0.0;
				return;
			}
			else if(objRemainingNoOfLeaves.responseText=="BorrowExist")
			{
			 //show division Borrow Leave
			document.getElementById('ctl00_CP_Transaction_divBorrowLeave').style.display="block"; 
			document.getElementById('ctl00_CP_Transaction_chkBorrowLeave').checked=false;
			
		    document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=0.0;
			return;
			}
			else if(objRemainingNoOfLeaves.responseText=="BorrowNotExist")
			{
			document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=0.0;
			return;
			}
			else if(xml.getElementsByTagName("RemainingNoOfLeaves")[0].text=="R")
			{
			    document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=0.0;
				alert("Presently not eligible for this Leave");
				return;
			}
			else
			{
			    var dsRoot=xml.documentElement.getElementsByTagName("Details"); 
				//alert(xml.getElementsByTagName("RemainingNoOfLeaves")[0].text);		
				var totalRec = dsRoot.length;
				document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=xml.getElementsByTagName("RemainingNoOfLeaves")[0].text;
                // document.getElementById('ctl00_CP_Transaction_divRemainingNoOfLeave').innerHTML=xml.getElementsByTagName("RemainingNoOfLeaves")[0].text;
            }
        }
        else
		{
		    alert("Error in retriving details");
		}
			
	}
}

// Fill Remaining Number of LOP Days

function Process_Response_EmployeesRemainingNoOfLOPDays()
{
    if(objRemainingNoOfLeaves.readyState == 4)
	{
	    if(objRemainingNoOfLeaves.status == 200)
		{
		    var xml=objRemainingNoOfLeaves.responseXML;
			
			document.getElementById('ctl00_CP_Transaction_divBorrowLeave').style.display="none"; 
			document.getElementById('ctl00_CP_Transaction_chkBorrowLeave').checked=false;
			if(objRemainingNoOfLeaves.responseText=="Fail" || objRemainingNoOfLeaves.responseText=="")
			{
			    document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=0.0;
				return;
			}
			else 
			{
			    document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=xml.getElementsByTagName("RemainingNoOfLOPDays")[0].text;
				
			}
			
        }
        else
		{
		    alert("Error in retriving details");
		}
			
	}
}

//To fill Restricted Holiday Details

function Process_Response_RestrictedHolidays()
{
    if(objRemainingNoOfLeaves.readyState == 4)
	{
	    if(objRemainingNoOfLeaves.status == 200)
		{
		    var xml=objRemainingNoOfLeaves.responseXML;
		    
		    document.getElementById('ctl00_CP_Transaction_divBorrowLeave').style.display="none"; 
			document.getElementById('ctl00_CP_Transaction_chkBorrowLeave').checked=false;
		   
			if(objRemainingNoOfLeaves.responseText=="Fail" || objRemainingNoOfLeaves.responseText=="")
			{
			    document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=0.0;
				return;
			}
//				else if(xml.getElementsByTagName("RemainingNoOfLeaves")[0].text=="R")
//				{
//				document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=0.0;
//				alert("Presently not eligible for this Leave");
//				return;
//				}
					
			else
			{
			    var HolidayDetails=objRemainingNoOfLeaves.responseText;
				var HolidayDetailsArray=HolidayDetails.split(",");
				 
				//alert(xml.getElementsByTagName("RemainingNoOfLeaves")[0].text);		
				//var totalRec = dsRoot.length;
				
				document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=HolidayDetailsArray[0];
                document.getElementById('ctl00_CP_Transaction_txtFromDate').value=HolidayDetailsArray[1];
                document.getElementById('ctl00_CP_Transaction_txtToDate').value=HolidayDetailsArray[2];
             }
    }
    else
	{
	    alert("Error in retriving details");
    }
  }
}

function hiderows()
{
    document.getElementById('tr_RemainingNoOfLeave').style.display="none";
}



var objPermissionApplication = null;

function EmployeeNamesForPermissionApplication()
{
    try
        {
             objPermissionApplication = new XMLHttpRequest();
        }
    catch(ex)
        {
            try
                {
                    objPermissionApplication =new ActiveXObject("Msxml2.XMLHTTP");
                }
            catch(e)
                {
                    try
                        {
                            objPermissionApplication =new ActiveXObject("Microsoft.XMLHTTP");
                        }
                    catch(e1)
                        {
                            objPermissionApplication =null;
                        }
                }
        }
        
        
        if(objPermissionApplication !=null)
        {
            var k=Math.floor(Math.random()*111);
            objPermissionApplication .onreadystatechange=Process_Response_EmployeesPermissionApplication;
            objPermissionApplication .open("GET","AjaxEmployeeForLeaveApplication.aspx?Sid="+k,true);
            objPermissionApplication .send(null);
        }
        
        return false;
}

function Process_Response_EmployeesPermissionApplication()
{
    if (document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').options.length != null)
	{				
	    for (var count = document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').options.length-1;count >-1; count--)
		    {
			    document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').options[count] = null;
			}	
    }
			
	if(objPermissionApplication .readyState == 4)
	{
	    if(objPermissionApplication .status == 200)
		{
		    if(objPermissionApplication .responseText=="Fail" || objPermissionApplication .responseText=="")
			{
			    var newOptSelect = new Option('-Select-','-Select-',  false, false);
                document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').options[0]=newOptSelect;
                //document.aspnetForm.ctl00_CP_Transaction_txtFromDate.value="";
                //document.aspnetForm.ctl00_CP_Transaction_txtToDate.value="";
				alert("No Records");
				return;
			}
			else
			{
			    //alert(objPermissionApplication .responseTEXT);
			    var xml=objPermissionApplication .responseXML;
				var dsRoot=xml.documentElement.getElementsByTagName("Details");  
				var totalRec = dsRoot.length;
				
                var newOptSelect = new Option('-Select-','-Select-',  false, false);
                document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').options[0]=newOptSelect;
                        
                for(i=0; i<totalRec; i++)
                {
                    var ConId = xml.getElementsByTagName("Employee_x0020_Name")[i];
                    var EmpId=xml.getElementsByTagName("Employee_Id")[i];
                    
                    var newOpt=new Option(ConId.text,EmpId.text);
                    document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').options[i+1]=newOpt;
                 }
   
                    document.getElementById('ctl00_CP_Transaction_ddlEmployeeNames').focus();
                    
                    
             }
        }
        else
		{
		    alert("Error in retriving details");
		}
    }
}

// Get Remaining no of Borrow leaves per leave type

var objRemainingNoOfBorrowLeaves = null;

function RemainingNoOfBorrowLeaves()
{
     //alert(document.getElementById('ctl00_CP_Transaction_hdnTxtLeaveTypeId').value);  		
	
	if(document.getElementById('ctl00_CP_Transaction_chkBorrowLeave').checked==false)
	{
	document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=0.0;
	return;
	}
			
	//document.getElementById('ctl00_CP_Transaction_txt_Numberofdays').value="";
     try
        {
             objRemainingNoOfBorrowLeaves = new XMLHttpRequest();
        }
        catch(ex)
                  {
                    try
                        {
                            objRemainingNoOfBorrowLeaves =new ActiveXObject("Msxml2.XMLHTTP");
                        }
                    catch(e)
                        {
                            try
                                {
                                    objRemainingNoOfBorrowLeaves =new ActiveXObject("Microsoft.XMLHTTP");
                                }
                            catch(e1)
                                {
                                    objRemainingNoOfBorrowLeaves =null;
                                }
                        }
                 }
        
if(objRemainingNoOfBorrowLeaves !=null)
{

    var k=Math.floor(Math.random()*111);

    var EmpId=document.getElementById('ctl00_CP_Transaction_hdnEmployeeId').value;
    var leaveTypeId= document.getElementById('ctl00_CP_Transaction_hdnTxtLeaveTypeId').value;     
       

    objRemainingNoOfBorrowLeaves.onreadystatechange=Process_Response_EmployeesRemainingNoOfBorrowLeaves;

    objRemainingNoOfBorrowLeaves.open("GET","AjaxRemainingNoOfBorrowLeaves.aspx?leaveTypeId=" + leaveTypeId + "&EmpId="+ EmpId + "&k="  + k,true);

    objRemainingNoOfBorrowLeaves.send(null);
    
}
//return false;

}

 
function Process_Response_EmployeesRemainingNoOfBorrowLeaves()
{
    if(objRemainingNoOfBorrowLeaves.readyState == 4)
	{
	    if(objRemainingNoOfBorrowLeaves.status == 200)
		{
		    var xml=objRemainingNoOfBorrowLeaves.responseXML;
		        
		        
			    
			if(objRemainingNoOfBorrowLeaves.responseText=="Fail" || objRemainingNoOfBorrowLeaves.responseText=="")
			{

				document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=0.0;
				return;
			}
			
			else
			{
				
				var dsRoot=xml.documentElement.getElementsByTagName("Details"); 
			
				//alert(xml.getElementsByTagName("RemainingNoOfLeaves")[0].text);		
			
				var totalRec = dsRoot.length;
				
				document.getElementById('ctl00_CP_Transaction_txtRemainingNoOfLeave').value=xml.getElementsByTagName("RemainingNoOfBorrowLeaves")[0].text;
		
            }
        }
        else
		{
		    alert("Error in retriving details");
		}
			
	}
}


//For Pop up windows

function OpenWindowLeaveQuota()
{
        var EmpId=document.getElementById('ctl00_CP_Transaction_hdnEmployeeId').value;
         
        if(EmpId!='' || EmpId=='undefined')
        {
         
        var url='PopUp_EmployeeLeaveQuota.aspx?EmpId=' + EmpId +'&rndValue=' + Math.random();
    
        window.open(url,'','left=250px, top=245px, width=400px, height=400px, scrollbars=no, status=no, resizable=no');
        }
        else
        {
        alert('Select an employee');
        }
        return false;
    
}