// JScript File

var objLPMod = null;
var type;

    function ajaxLeavePolicyMod(EmpID,type1)
    {

    type=type1;

        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
       
            objLPMod.onreadystatechange=Process_Response_LeavePolicy_Mod;

            objLPMod.open("GET","LeavePolicy_RemoteModify.aspx?type=2&EmpID=" + EmpID+"&PolicyName="+PolicyName+"&PolicyId="+PolicyId+"&Random="+k ,true);

            objLPMod.send(null);

            }
            
         //for preloading   
            if (type=='1')
            {

            objLPMod.onreadystatechange=Process_Response_LeavePolicy_Mod;

            objLPMod.open("GET","LeavePolicy_RemoteModify.aspx?type=1&EmpID=" + EmpID+"&Random="+k ,true);

            objLPMod.send(null);

            }
            
         }
         
         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)
				{
				
				//alert(retval)
				
				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];
				}
				
				//alert(document.getElementById('ctl00_BodyContentPH_hdf_RowsMod').value)
				
				//alert(document.getElementById('ctl00_BodyContentPH_div_policy'))
				
				   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('tbl_LeavePolicydetails')!=null)
				        {
				          document.getElementById('tbl_LeavePolicydetails').style.display="none";
				        }
				   }
				}
				
				else
				{
				    //alert("No Details found in Emp Leave Policy Modify!");
				}
			}
			
			else
			{
				alert("Error in retriving details from Leave policy modify");
			}
			
		}
	}


//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;
                    }
                }
            }
            //alert(data)
            document.getElementById("ctl00_BodyContentPH_hdf_Policy").value=data;
            
    } 


