// JScript File
var objLeaveApplication = null;
function FillLeavePolicyDropDown(employeeCategory,employeeType,gender,employeeReligion)
{
    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)
        {
            //document.getElementById('ctl00_BodyContentPH_hdnEmployeeId').value='';
            var k=Math.floor(Math.random()*111);
            if(window.ActiveXObject)
            {
                objLeaveApplication.onreadystatechange=Process_Response_EmployeesLeaveApplication;
                objLeaveApplication.open("GET","AjaxLeavePolicy.aspx?EmployeeCategory=" +employeeCategory+"&EmployeeType="+employeeType+"&Gender="+gender+"&Religion="+employeeReligion+ "&Sid="+k,true);
                objLeaveApplication.send(null);
            }
            else if(window.XMLHttpRequest)
            {
                objLeaveApplication.open("GET","AjaxLeavePolicy.aspx?EmployeeCategory=" +employeeCategory+"&EmployeeType="+employeeType+"&Gender="+gender+"&Religion="+employeeReligion+ "&Sid="+k,true);
                objLeaveApplication.send(null);
                objLeaveApplication.onreadystatechange=Process_Response_EmployeesLeaveApplication();
            }
        }
        return false;
    }
function Process_Response_EmployeesLeaveApplication()
{
//    if (document.getElementById('ctl00_BodyContentPH_ddl_LeavePolicy').options.length != null)
//	{				
//        for (var count = document.getElementById('ctl00_BodyContentPH_ddl_LeavePolicy').options.length-1;count >-1; count--)
//		{
//		    document.getElementById('ctl00_BodyContentPH_ddl_LeavePolicy').options[count] = null;
//		}	
//    }
//		alert(objLeaveApplication.readyState);
	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_ddl_LeavePolicy').options[0]=newOptSelect;
                document.aspnetForm.ctl00_BodyContentPH_txtFromDate.value="";
                document.aspnetForm.ctl00_BodyContentPH_txtToDate.value="";
				//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_ddl_LeavePolicy').options[0]=newOptSelect;
                for(i=0; i<totalRec; i++)
                {
                    //var EmpId=xml.getElementsByTagName("Employee_Id")[i];
                    var PolicyId=xml.getElementsByTagName('Policy_Id')[i].childNodes[0].nodeValue;
                    //var Employee_Code_Id=xml.getElementsByTagName("Employee_Code_Id")[i];
                    var PolicyName=xml.getElementsByTagName('PolicyName')[i].childNodes[0].nodeValue;
                    //var newOpt=new Option(ConId.text,EmpId.text);
                    var newOpt=new Option(PolicyName,PolicyId);
                    document.getElementById('ctl00_BodyContentPH_ddl_LeavePolicy').options[i+1]=newOpt;
                }                  
                if(document.getElementById('ctl00_BodyContentPH_ddl_LeavePolicy') != null)
                {
//                    if(document.getElementById('ctl00_BodyContentPH_ddl_LeavePolicy').style.visibility == '')
//                    {
//                        document.getElementById('ctl00_BodyContentPH_ddl_LeavePolicy').style.visibility = 'visible';
//                    }
                    document.getElementById('ctl00_BodyContentPH_ddl_LeavePolicy').focus();
                }
                //document.getElementById('ctl00_BodyContentPH_ddl_LeavePolicy').value=xml.getElementsByTagName("Policy_Id")[0].childNodes[0].nodeValue;
            }
        }
        else
		{
		   // alert("Error in retriving details");
		    alert(ErrorinRetrive);
		}
    }
}
