// JScript File
var objLPMod = null;
var retval='';
var LeavePolicyFromDate='';
var LeavePolicyToDate='';
var arr_List = new Array();
var arrValue='';
var EmployeeId='';
var breakValue='';
var row='';
var tbl ='';
function removeRow(Id, con)
{
var valused='tbl_LeavePolicynew'+Id.toString(); 
    var div = document.getElementById(valused);
    if (div) {
    div.parentNode.removeChild(div);
    }
    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_policy_ModAdd();
}



function removeRowModify(Id, con)
{
var valused='tbl_LeavePolicy'+Id.toString(); 
    var div = document.getElementById(valused);
    if (div) {
    div.parentNode.removeChild(div);
    }
    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_policy_ModAdd();
}




//function removeRow(Id, con,EmpId)
//{
//    var cel = con.parentElement;
//    row = cel.parentElement;
//    tbl = row.parentElement;
//    var hid = '';
//     var str = "";
//     str = document.getElementById('ctl00_BodyContentPH_hdf_Policy').value;
//  
//     arr_List = str.split("*");
//     for(var i=0; i < arr_List.length; i++)
//     {  
//       alert(arr_List[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);
//        alert(Id + ' ' + intId);
//        
//        if(Id == intId)
//        {        
//            var arr_LeavePolicyDates=new Array();
//        
//            arr_LeavePolicyDates=arr_List[i].split(",");
//           
//            alert(arr_LeavePolicyDates[0] +  ' ' + arr_LeavePolicyDates[1]);
//        
//            LeavePolicyFromDate=arr_LeavePolicyDates[0];
//            LeavePolicyToDate=arr_LeavePolicyDates[1];
//        
//            arrValue=i;
//            EmployeeId=EmpId;
//            ajaxLeavePolicyDelete(); 
//            
//            if(breakValue=='true')
//            {
//            break;
//            }
//        }
////        ajaxLeavePolicyDelete(); 
//     }    
//    
//    
//}
 function ajaxLeavePolicyDelete()
 {
        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;
//                }
//            }
//         }
         //Check the Policy already mapped in Leave  Application and Permission
         if(objLPMod!=null)
         {
             var k=Math.floor(Math.random()*111);
             if(window.ActiveXObject)
             {
                 objLPMod.onreadystatechange=Process_Response_LeavePolicy_Mod_Remove;
                 objLPMod.open("GET","LeavePolicy_RemoteDelete.aspx?EmpId=" + EmployeeId + "&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);
             }
             else if(window.XMLHttpRequest)
             {
                 objLPMod.open("GET","LeavePolicy_RemoteDelete.aspx?EmpId=" + EmployeeId + "&LeavePolicyFromDate=" + LeavePolicyFromDate +"&LeavePolicyToDate=" + LeavePolicyToDate +"&Random=" +k,false);
                 //objLPMod.open("GET","LeavePolicy_RemoteModify.aspx?type=2&EmpID=" + EmpID+"&PolicyName=Test_Policy&PolicyId=124"&Random="+k ,true);
                 objLPMod.send(null);
                 objLPMod.onreadystatechange=Process_Response_LeavePolicy_Mod_Remove();
             }
         }
 }
function Process_Response_LeavePolicy_Mod_Remove()
{
        if(objLPMod.readyState == 4)
		{
			if(objLPMod.status == 200)
			{
			    retval=objLPMod.responseText;
				//alert(retval);
			    if(retval=='0' && objLPMod.readyState == 4)
                {
                    arr_List[arrValue] = null;
                    tbl.deleteRow(row.rowIndex);
                    breakValue='true';
                   // 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_policy_ModAdd();
            }
            else
            {
                    alert('Cannot delete, Since Leave or Permission is mapped');
            }
    }
    }
}
function removeRowAdd(Id, con)
{
    //alert("hi");
//    var cel = con.parentElement;
//    var row = cel.parentElement;
    //    var tbl = row.parentElement;
    var valused='tbl_LeavePolicy'+Id.toString(); 
    var div = document.getElementById(valused);
    if (div) {
    div.parentNode.removeChild(div);
    }
    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();
}