// JScript File
var objLPMod = null;
var type;
    function ajaxLeavePolicyMod(EmpID,type1,ErrorinretrivingdetailsfromLeavepolicymodify,Gender,EmployeeCategory,EmployeeType,Religion)
    {
    type=type1;
        if(window.ActiveXObject)
        {    
	        try
	        {
		        objLPMod = new ActiveXObject("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objLPMod = new ActiveXObject("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objLPMod = null;
		        }
	        }
        }  
         else if(window.XMLHttpRequest)
         {
	        try
	        {
		        objLPMod = new XMLHttpRequest("Msxml2.XMLHTTP");
	        }
	        catch(e)
	        {
		        try
		        {
			        objLPMod = new XMLHttpRequest("Microsoft.XMLHTTP");
		        }
		        catch(e1)
		        {
			        objLPMod = null;
		        }
	        }
        }
//        try
//        {
//             objLPMod = new XMLHttpRequest();
//        }
//        catch(ex)
//        {
//            try
//            {
//                objLPMod=new ActiveXObject("Msxml2.XMLHTTP");
//            }
//            catch(e)
//            {
//                try
//                {
//                    objLPMod=new ActiveXObject("Microsoft.XMLHTTP");
//                }
//                catch(e1)
//                {
//                    objLPMod=null;
//                }
//            }
//        }
        if(objLPMod!=null)
         {
         var k=Math.floor(Math.random()*111);
//for new policy
            if (type=='2')
            { 
                var PolicyId=document.getElementById("ctl00_BodyContentPH_hdf_PolicyID").value
                var PolicyName=document.getElementById("ctl00_BodyContentPH_hdf_PolicyName").value
                if(window.ActiveXObject)
                {
                    objLPMod.onreadystatechange=Process_Response_LeavePolicy_Mod;
                    objLPMod.open("GET","LeavePolicy_RemoteModify.aspx?type=2&EmpID=" + EmpID+"&PolicyName="+PolicyName+"&PolicyId="+PolicyId+"&Random="+k + "&Gender=" + Gender + "&EmployeeCategory=" + EmployeeCategory + "&EmployeeType=" + EmployeeType + "&Religion=" + Religion,true);
                    objLPMod.send(null);
                }
                else if(window.XMLHttpRequest)
                {
                    objLPMod.open("GET","LeavePolicy_RemoteModify.aspx?type=2&EmpID=" + EmpID+"&PolicyName="+PolicyName+"&PolicyId="+PolicyId+"&Random="+k + "&Gender=" + Gender + "&EmployeeCategory=" + EmployeeCategory + "&EmployeeType=" + EmployeeType + "&Religion=" + Religion ,false);
                    objLPMod.send(null);
                    objLPMod.onreadystatechange=Process_Response_LeavePolicy_Mod();
                }
            }
         //for preloading   
            if (type=='1')
            {
                if(window.ActiveXObject)
                {
                    objLPMod.onreadystatechange=Process_Response_LeavePolicy_Mod;
                    objLPMod.open("GET","LeavePolicy_RemoteModify.aspx?type=1&EmpID=" + EmpID+"&Random="+k ,true);
                    objLPMod.send(null);
                }
                else if(window.XMLHttpRequest)
                {
                    objLPMod.open("GET","LeavePolicy_RemoteModify.aspx?type=1&EmpID=" + EmpID+"&Random="+k ,false);
                    objLPMod.send(null);
                    objLPMod.onreadystatechange=Process_Response_LeavePolicy_Mod();
                }
            }
         }
         else
         {
            document.getElementById('ctl00_BodyContentPH_div_policy').innerHTML="";
         }
        return false;
    }
    function Process_Response_LeavePolicy_Mod()
	{
		if(objLPMod.readyState == 4)
		{
			if(objLPMod.status == 200)
			{
				var retval=objLPMod.responseText;
				if (retval.length > 0)
				{
				    if(retval == "LeavePolicyNotExists")
				    {
				       alert("Select valid leave policy");
				    }
				    else
				    {
				        var no_of_rows= parseInt(document.getElementById("ctl00_BodyContentPH_hdf_RowsMod").value);
                        var data="";
                        var FromDate='';
                        var ToDate='';
                        var Fromarray=new Array();
                        var Toarray=new Array();
                        for(var i=1; i<= no_of_rows; i++)
                        {
                            var from = "txt_From" + i;
                            var to = "txt_To" + i;
                            var id = "div_" + i;                             
                            if(document.getElementById(from)!=null && document.getElementById(to)!=null && document.getElementById(id)!=null)
                             {
                                if(FromDate.length != 0)
                                {
                                FromDate=FromDate+ ","  + document.getElementById(from).value;
                                }
                                else
                                {
                                FromDate=document.getElementById(from).value+ ",";
                                }
                                if(ToDate.length != 0)
                                {
                                ToDate=ToDate+ "," + document.getElementById(to).value;
                                }
                                else
                                {
                                ToDate=document.getElementById(to).value+ ",";
                                }
                             }
                             else
                             {
                                FromDate=FromDate+",";
                                ToDate=ToDate+ ",";
                             }
                        }                        
                        Fromarray=FromDate.split(",");
                        Toarray=ToDate.split(",");
				        var arr=retval.split('~#~');
				        if(arr[1]=='MappedPolicy@~%')
				        {
				          document.getElementById("ctl00_BodyContentPH_hdf_Policy").value='MappedPolicy@~%';
				        }
				        else
				        {
				          document.getElementById('ctl00_BodyContentPH_hdf_RowsMod').value=arr[1];
				        }
				           document.getElementById('ctl00_BodyContentPH_div_policy').innerHTML+=arr[0];
				           if (arr[2]!= undefined)
				           {
				            document.getElementById("ctl00_BodyContentPH_hdf_Policy").value=arr[2];
				            }
				           if (type=='2')
				           {
				                if(document.getElementById('div_LeavePolicydetails')!=null)
				                {
				                  document.getElementById('div_LeavePolicydetails').style.display="none";
				                }
				           }
				           for(var i=1; i<= no_of_rows; i++)
                            {
                                var from = "txt_From" + i;
                                var to = "txt_To" + i;
                                var id = "div_" + i; 
                                if(document.getElementById(from)!=null && document.getElementById(to)!=null && document.getElementById(id)!=null)
                                {
                                    if(Fromarray.length >0)
                                    {
                                        document.getElementById(from).value=Fromarray[i-1];
                                    }
                                    if(Toarray.length>0)
                                    {
                                        document.getElementById(to).value=Toarray[i-1];
                                    }
                                }
                            }
				       }
				}
				else
				{
				    //alert("No Details found in Emp Leave Policy Modify!");
				}
			}
			else
			{
				//alert("Error in retriving details from Leave policy modify");
				alert(ErrorinretrivingdetailsfromLeavepolicymodify);
			}
		}
	}
//assign the policy details to hidden field
	function assign_hidden_policy_Mod()
    {
        var no_of_rows= parseInt(document.getElementById("ctl00_BodyContentPH_hdf_RowsMod").value);
        var data="";
        for(var i=1; i<= no_of_rows; i++)
            {
                var from = "txt_From" + i;
                var to = "txt_To" + i;
                var id = "div_" + i;            
                if(data == "")
                {
                    if(document.getElementById(from)!=null && document.getElementById(to)!=null && document.getElementById(id)!=null)
                    {
                        data = document.getElementById(from).value + "," + document.getElementById(to).value + "," + document.getElementById(id).innerHTML;
                    }
                }
                else
                {
                    if(document.getElementById(from)!=null && document.getElementById(to)!=null && document.getElementById(id)!=null)
                    {
                        data = data + "*" + document.getElementById(from).value + "," + document.getElementById(to).value + "," + document.getElementById(id).innerHTML;
                    }
                }
            }
            //alert(data)
            document.getElementById("ctl00_BodyContentPH_hdf_Policy").value=data;
    } 
    function assign_hidden_policy_ModAdd()
    {
        var no_of_rows= parseInt(document.getElementById("ctl00_BodyContentPH_hdf_RowsMod").value)+1;
        var data="";
        for(var i=1; i<= no_of_rows; i++)
            {
                var from = "txt_From" + i;
                var to = "txt_To" + i;
                var id = "div_" + i;            
                if(data == "")
                {
                    if(document.getElementById(from)!=null && document.getElementById(to)!=null && document.getElementById(id)!=null)
                    {
                        data = document.getElementById(from).value + "," + document.getElementById(to).value + "," + document.getElementById(id).innerHTML;
                    }
                }
                else
                {
                    if(document.getElementById(from)!=null && document.getElementById(to)!=null && document.getElementById(id)!=null)
                    {
                        data = data + "*" + document.getElementById(from).value + "," + document.getElementById(to).value + "," + document.getElementById(id).innerHTML;
                    }
                }
            }
            document.getElementById("ctl00_BodyContentPH_hdf_Policy").value=data;
    } 
