// JScript File
var objLPMod = null;
var retval='';
function removeRow(Id, con,EmpId)
{
        try
        {
             objLPMod = new XMLHttpRequest();
        }
        catch(ex)
        {
            try
            {
                objLPMod=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    objLPMod=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e1)
                {
                    objLPMod=null;
                }
            }
         }
//    var cel = con.parentElement;
//    var row = cel.parentElement;
//    var tbl = row.parentElement;
    var cel = con.parentNode;
    var row = cel.parentNode;
    var tbl = row.parentNode;
    var hid = '';
    tbl.deleteRow(row.rowIndex);
     var str = "";
     str = document.getElementById('ctl00_BodyContentPH_hdf_Policy').value;
     var arr_List = new Array();
     arr_List = str.split("*");
     for(var i=0; i < arr_List.length; i++)
     {    
        var p =  arr_List[i].lastIndexOf(',');     
        var len=arr_List[i].length;     
        var id=arr_List[i].substring(p+1,len);     
        var intId=parseInt(id);
        if(Id == intId)
        {
        var arr_LeavePolicyDates=new Array();
        arr_LeavePolicyDates=arr_List[i].split(",");
        var LeavePolicyFromDate=arr_LeavePolicyDates[0];
        var LeavePolicyToDate=arr_LeavePolicyDates[1];
        //Check the Policy already mapped in Leave  Application and Permission
         if(objLPMod!=null)
         {
         var k=Math.floor(Math.random()*111);
         objLPMod.onreadystatechange=Process_Response_LeavePolicy_Mod_Remove;
         objLPMod.open("GET","LeavePolicy_RemoteDelete.aspx?EmpId=" + EmpId + "&LeavePolicyFromDate=" + LeavePolicyFromDate +"&LeavePolicyToDate=" + LeavePolicyToDate +"&Random=" +k,true);
         //objLPMod.open("GET","LeavePolicy_RemoteModify.aspx?type=2&EmpID=" + EmpID+"&PolicyName=Test_Policy&PolicyId=124"&Random="+k ,true);
         objLPMod.send(null);
         }
         alert(retval);
         if(retval=='0' && objLPMod.readyState == 4)
         {
            arr_List[i] = null;
            break;
         }
         else
         {
            alert('Cannot delete, Since Leave or Permission is mapped');
         }
        }
     }    
     str = "";
     for(var i=0; i < arr_List.length; i++)
     {
        if(arr_List[i] != null && arr_List[i] != "0")
        {
            if(str == "")
            {
                str = arr_List[i];
            }
            else
            {
                str = str + "*" + arr_List[i];
            }
        }
     }
    document.getElementById('ctl00_BodyContentPH_hdf_Policy').value = str;
    if(document.getElementById('div_LeavePolicydetails')!=null)
    {
        document.getElementById('div_LeavePolicydetails').style.display="none";
    }
    if(document.getElementById('tbl_emp')!=null)
    {
        document.getElementById('tbl_emp').style.display="none";
    }
    assign_hidden_policy_ModAdd();
}
function Process_Response_LeavePolicy_Mod_Remove()
{
        if(objLPMod.readyState == 4)
		{
			if(objLPMod.status == 200)
			{
				retval=objLPMod.responseText;
            }
        }
}
function removeRowAdd(Id, con)
{
    //alert("hi");
//    var cel = con.parentElement;
//    var row = cel.parentElement;
//    var tbl = row.parentElement;
    var cel = con.parentNode;
    var row = cel.parentNode;
    var tbl = row.parentNode;
    var hid = '';
    tbl.deleteRow(row.rowIndex);
     var str = "";
     str = document.getElementById('ctl00_BodyContentPH_hdf_Policy').value;
     var arr_List = new Array();
     arr_List = str.split("*");
     for(var i=0; i < arr_List.length; i++)
     {    
        var p =  arr_List[i].lastIndexOf(',');     
        var len=arr_List[i].length;     
        var id=arr_List[i].substring(p+1,len);     
        var intId=parseInt(id);
        if(Id == intId)
        {
            arr_List[i] = null;
            break;
        }
     }    
     str = "";
     for(var i=0; i < arr_List.length; i++)
     {
        if(arr_List[i] != null && arr_List[i] != "0")
        {
            if(str == "")
            {
                str = arr_List[i];
            }
            else
            {
                str = str + "*" + arr_List[i];
            }
        }
     }
    document.getElementById('ctl00_BodyContentPH_hdf_Policy').value = str;
    if(document.getElementById('div_LeavePolicydetails')!=null)
    {
        document.getElementById('div_LeavePolicydetails').style.display="none";
    }
    if(document.getElementById('tbl_emp')!=null)
    {
        document.getElementById('tbl_emp').style.display="none";
    }
    assign_hidden_policyAdd();
}