// JScript File
var objLeaveApplication = null;
function EmployeeNamesForEncashment(NoRecords,Errorinretrivingdetails,Select)
{
   if(window.ActiveXObject)
    {    
	    try
	    {
		    objLeaveApplication = new ActiveXObject("Msxml2.XMLHTTP");
	    }
	    catch(e)
	    {
		    try
		    {
			    objLeaveApplication = new ActiveXObject("Microsoft.XMLHTTP");
		    }
		    catch(e1)
		    {
			    objLeaveApplication = null;
		    }
	    }
    }  
     else if(window.XMLHttpRequest)
     {
	    try
	    {
		    objLeaveApplication = new XMLHttpRequest("Msxml2.XMLHTTP");
	    }
	    catch(e)
	    {
		    try
		    {
			    objLeaveApplication = new XMLHttpRequest("Microsoft.XMLHTTP");
		    }
		    catch(e1)
		    {
			    objLeaveApplication = null;
		    }
	    }
    }
//        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);
            if(window.ActiveXObject)
            {
                objLeaveApplication.onreadystatechange=Process_Response_EmployeesEncashment;
                objLeaveApplication.open("GET","AjaxEmployeeForLeaveApplication.aspx?Sid="+k,true);
                objLeaveApplication.send(null);
            }
            else if(window.XMLHttpRequest)
            {
                objLeaveApplication.open("GET","AjaxEmployeeForLeaveApplication.aspx?Sid="+k,false);
                objLeaveApplication.send(null);
                objLeaveApplication.onreadystatechange=Process_Response_EmployeesEncashment();
            }
        }
        return false;
}
function Process_Response_EmployeesEncashment()
{
    if (document.getElementById('ctl00_BodyContentPH_ddlEmployeeNames').options.length != null)
	{				
        for (var count = document.getElementById('ctl00_BodyContentPH_ddlEmployeeNames').options.length-1;count >-1; count--)
		{
		    document.getElementById('ctl00_BodyContentPH_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);
			    var newOptSelect = new Option(Select,'-Select-',  false, false);
                document.getElementById('ctl00_BodyContentPH_ddlEmployeeNames').options[0]=newOptSelect;
           		//alert("No Records");
           		alert(NoRecords);
				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);
                 var newOptSelect = new Option(Select,'-Select-',false, false);
                document.getElementById('ctl00_BodyContentPH_ddlEmployeeNames').options[0]=newOptSelect;
                for(i=0; i<totalRec; i++)
                {
                    //var ConId = xml.getElementsByTagName("Employee_x0020_Name")[i];
                    var ConId = xml.getElementsByTagName('Employee_x0020_Name')[i].childNodes[0].nodeValue;
                    //var EmpId=xml.getElementsByTagName("Employee_Id")[i];
                    var EmpId = xml.getElementsByTagName('Employee_Id')[i].childNodes[0].nodeValue;
                    //var Employee_Code_Id=xml.getElementsByTagName("Employee_Code_Id")[i];
                    var Employee_Code_Id = xml.getElementsByTagName('Employee_Code_Id')[i].childNodes[0].nodeValue;
                    //var newOpt=new Option(ConId.text,EmpId.text);
                    var newOpt=new Option(Employee_Code_Id+ ' - ' + ConId,EmpId);
                    document.getElementById('ctl00_BodyContentPH_ddlEmployeeNames').options[i+1]=newOpt;
                }
                document.getElementById('ctl00_BodyContentPH_ddlEmployeeNames').focus();
            }
        }
        else
		{
		    //alert("Error in retriving details");
		    alert(Errorinretrivingdetails);
		}
    }
}
function assignEmployeeIdEncashment(empid)
{
  document.getElementById('ctl00_BodyContentPH_hdnEmployeeId').value=empid;
  alert(empid);
  document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').focus();
}
var objLeaveTypes = null;
function leaveOptionsEncashment(empid,SelectEmployee,NoRecords,Errorinretrivingdetails,Select)
{
    document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').selectedIndex=0;
    if(document.getElementById('ctl00_BodyContentPH_txt_RemainingNoOfDays')!=null)
    {
    document.getElementById('ctl00_BodyContentPH_txt_RemainingNoOfDays').value='';
    }
       if (document.getElementById('ctl00_BodyContentPH_ddlEmployeeNames').selectedIndex==0)
       {
            //alert("Select Employee");
            alert(SelectEmployee);
            if (document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options.length != null)
        {				
            for (var count = document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options.length-1;count >-1; count--)
            {
                document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options[count] = null;
            }	
        }
            return;   
       }
    if(leaveSource=="-Select-")
    {
        //alert("Select a type of Leave");
        if (document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options.length != null)
        {				
            for (var count = document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options.length-1;count >-1; count--)
            {
                document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options[count] = null;
            }	
        }
        //var newOptSelect = new Option('-Select-','-Select-',  false, false);
         var newOptSelect = new Option(Select,'-Select-',false, false);
        document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options[0]=newOptSelect;
        return;   
    }
        document.getElementById('ctl00_BodyContentPH_hdnEmployeeId').value=empid;
        //alert(empid);
        //document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').focus();
     if(window.ActiveXObject)
        {    
	        try
	        {
		        objLeaveTypes = new ActiveXObject("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objLeaveTypes = new ActiveXObject("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objLeaveTypes = null;
		        }
	        }
        }  
         else if(window.XMLHttpRequest)
         {
	        try
	        {
		        objLeaveTypes = new XMLHttpRequest("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objLeaveTypes = new XMLHttpRequest("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objLeaveTypes = null;
		        }
	        }
        }
//    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_BodyContentPH_hdnEmployeeId').value;
        var leaveSource="Encashment";
        if(EmpId==null || EmpId==0 || EmpId=="-Select-")
        {
            return;
            document.getElementById('ctl00_BodyContentPH_txtRemainingNoOfLeave').value=0.0;     
        }
         if(window.ActiveXObject)
         {
            objLeaveTypes.onreadystatechange=Process_Response_EmployeesLeaveOptionsEncashment;
            objLeaveTypes.open("GET","AjaxLeaveOptions.aspx?leaveSource=" + leaveSource + "&EmpId="+ EmpId + "&k="  + k,true);
            objLeaveTypes.send(null);
         }
         else if(window.XMLHttpRequest)
         {
            objLeaveTypes.open("GET","AjaxLeaveOptions.aspx?leaveSource=" + leaveSource + "&EmpId="+ EmpId + "&k="  + k,false);
            objLeaveTypes.send(null);
            objLeaveTypes.onreadystatechange=Process_Response_EmployeesLeaveOptionsEncashment();
         }
    }
    return false;
}
//Fill Leave Types
function Process_Response_EmployeesLeaveOptionsEncashment()
{
    if (document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options.length != null)
	{				
	    for (var count = document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options.length-1;count >-1; count--)
		{
		    document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options[count] = null;
		}	
    }
	if(objLeaveTypes.readyState == 4)
	{
	    if(objLeaveTypes.status == 200)
		{
		    if(objLeaveTypes.responseText=="Fail" || objLeaveTypes.responseText=="")
			{
			    //var newOptSelect = new Option('-Select-','-Select-',  false, false);
			     var newOptSelect = new Option(Select,'-Select-',false, false);
                document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options[0]=newOptSelect;
				//alert("No Records");
				alert(NoRecords);
				return;
			}
			else
			{
			    var xml=objLeaveTypes.responseXML;
				var dsRoot=xml.documentElement.getElementsByTagName("Details");  
				var totalRec = dsRoot.length;
				//var newOptSelect = new Option('-Select-','-Select-',  false, false);
				var newOptSelect = new Option(Select,'-Select-',false, false);
                document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options[0]=newOptSelect;
                for(i=0; i<totalRec; i++)
                {                     
                        //var ConId = xml.getElementsByTagName("LeaveType")[i];
                        var ConId = xml.getElementsByTagName('LeaveType')[i].childNodes[0].nodeValue;
                        //var LeaveTypeId=xml.getElementsByTagName("LeaveType_Id")[i];
                        var LeaveTypeId = xml.getElementsByTagName('LeaveType_Id')[i].childNodes[0].nodeValue;
                        var newOpt=new Option(ConId,LeaveTypeId);
                        document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').options[i+1]=newOpt;
               }
               document.getElementById('ctl00_BodyContentPH_ddl_Leavetype').focus();
            }
        }
        else
	    {
	        //alert("Error in retriving details");
	         alert(Errorinretrivingdetails);
        }
    }
}
// Get Remaining no of leaves per leave type
var objRemainingNoOfLeaves = null;
function RemainingNoOfEncashmentLeaves(leaveTypeId,Errorinretrivingdetails)
{
    if(leaveTypeId=='-Select-')
    {
        document.getElementById('ctl00_BodyContentPH_txt_RemainingNoOfDays').value="";
        document.getElementById('ctl00_BodyContentPH_hdnLeaveTypeId').value="";
        return;
    }
       if(window.ActiveXObject)
        {    
	        try
	        {
		        objRemainingNoOfLeaves = new ActiveXObject("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objRemainingNoOfLeaves = new ActiveXObject("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objRemainingNoOfLeaves = null;
		        }
	        }
        }  
         else if(window.XMLHttpRequest)
         {
	        try
	        {
		        objRemainingNoOfLeaves = new XMLHttpRequest("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objRemainingNoOfLeaves = new XMLHttpRequest("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objRemainingNoOfLeaves = null;
		        }
	        }
        }
//    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_BodyContentPH_hdnEmployeeId').value;
    document.getElementById('ctl00_BodyContentPH_hdnLeaveTypeId').value=leaveTypeId;
    //alert(EmpId + leaveTypeId);
    if(window.ActiveXObject)
    {
        objRemainingNoOfLeaves.onreadystatechange=Process_Response_EmployeesRemainingNoOfEncashmentDays;
        objRemainingNoOfLeaves.open("GET","AjaxRemainingNoOfEncashmentDays.aspx?leaveTypeId=" + leaveTypeId + "&EmpId="+ EmpId + "&k="  + k,true);
        objRemainingNoOfLeaves.send(null);
    }
    else if(window.XMLHttpRequest)
    {
        objRemainingNoOfLeaves.open("GET","AjaxRemainingNoOfEncashmentDays.aspx?leaveTypeId=" + leaveTypeId + "&EmpId="+ EmpId + "&k="  + k,false);
        objRemainingNoOfLeaves.send(null);
        objRemainingNoOfLeaves.onreadystatechange=Process_Response_EmployeesRemainingNoOfEncashmentDays();
    }
}
return false;
}
function Process_Response_EmployeesRemainingNoOfEncashmentDays()
{
    if(objRemainingNoOfLeaves.readyState == 4)
	{
	    if(objRemainingNoOfLeaves.status == 200)
		{
		    var xml=objRemainingNoOfLeaves.responseXML;
			if(objRemainingNoOfLeaves.responseText=="Fail" || objRemainingNoOfLeaves.responseText=="")
			{
			    document.getElementById('ctl00_BodyContentPH_txt_RemainingNoOfDays').value=0.0;
			    document.getElementById('ctl00_BodyContentPH_hdnRemainingNoOfDays.Value').value="0";
				return;
			}
			else
			{
			    var dsRoot=xml.documentElement.getElementsByTagName("Details"); 
				//alert(xml.getElementsByTagName("RemainingNoOfLeaves")[0].text);	                      
				var totalRec = dsRoot.length;
				document.getElementById('ctl00_BodyContentPH_txt_RemainingNoOfDays').value=xml.getElementsByTagName("RemainingNoOfLeaves")[0].childNodes[0].nodeValue;
                document.getElementById('ctl00_BodyContentPH_hdnRemainingNoOfDays').value=xml.getElementsByTagName("RemainingNoOfLeaves")[0].childNodes[0].nodeValue;
                // document.getElementById('ctl00_BodyContentPH_divRemainingNoOfLeave').innerHTML=xml.getElementsByTagName("RemainingNoOfLeaves")[0].text;
            }
        }
        else
		{
		    //alert("Error in retriving details");
		     alert(Errorinretrivingdetails);
		}
	}
}