// JScript File
var ConfirmDelete = "Are you sure, to delete?";
var SelectItemsToDelete = "Select Item(s) To Delete";
var SelectItemssync = "Select Item(s) To sync";
var ConfirmDeletePermanent = "Are you sure, to delete?";
var ConfirmRestore = "Are you sure, to restore?";
var SelectItemsToRestore = "Select Item(s) To Restore";
var NorecordtoForward = "Select Item(s) To Forward";
var NorecordtoApproved = "Select Item(s) To Approve";
function SetAlertMessages_DeleteRestore(confirmDelete, selectItemsToDelete, confirmDeletePermanent, confirmRestore, selectItemsToRestore, norecordtoForward, norecordtoApproved)
{
   ConfirmDelete = confirmDelete;
   SelectItemsToDelete = selectItemsToDelete;
   ConfirmDeletePermanent = confirmDeletePermanent;
   ConfirmRestore = confirmRestore;
   SelectItemsToRestore = selectItemsToRestore;
   NorecordtoForward = norecordtoForward;
   NorecordtoApproved = norecordtoApproved;
}
function select_all(chkval,idval)
{
var frm=document.forms[0];
var idCheckBox;
	for (i=0;i<frm.length;i++)
	{
	    if (idval.indexOf('checkall')!=-1)  //==0 true
	        {
	            if (chkval==true)
		            {
                           if(frm.elements[i].disabled !=true)
		                    frm.elements[i].checked=true;
		            }
	            else
		            {
		                frm.elements[i].checked=false;
		            }
	        }
	    else if (idval.indexOf('deletethis')!=-1)		
	        {
		        if(frm.elements[i].checked==false)
		        {
		            frm.elements[4].checked=false;
		        }
		         if(i>1 && i<10)
		        {
		        idCheckBox="ctl00_BodyContentPH_grv_EmpDetails_ctl0" + i + "_deletethis";
		        }
		        else if(i>9)
		        {
		        idCheckBox="ctl00_BodyContentPH_grv_EmpDetails_ctl" + i + "_deletethis";
		        }
		        if(document.getElementById(idCheckBox)!=null)
		        {
		        if(document.getElementById(idCheckBox).checked==false)
		        {
		          frm.elements[8].checked=false;
		        }
		        }
	        }
	}
}
function designation_select_all(chkval,idval)
{
var frm=document.forms[0];
var idCheckBox;
	for (i=0;i<frm.length;i++)
	{
	    if (idval.indexOf('checkall')!=-1)  //==0 true
	        {
	            if (chkval==true)
		            {
                           if(frm.elements[i].disabled !=true)
		                    frm.elements[i].checked=true;
		            }
	            else
		            {
		                frm.elements[i].checked=false;
		            }
	        }
	    else if (idval.indexOf('deletethis')!=-1)		
	        {
		        if(frm.elements[i].checked==false)
		        {
		            frm.elements[7].checked=false;
		        }
		         if(i>1 && i<10)
		        {
		        idCheckBox="ctl00_BodyContentPH_grv_EmpDetails_ctl0" + i + "_deletethis";
		        }
		        else if(i>9)
		        {
		        idCheckBox="ctl00_BodyContentPH_grv_EmpDetails_ctl" + i + "_deletethis";
		        }
		        if(document.getElementById(idCheckBox)!=null)
		        {
		        if(document.getElementById(idCheckBox).checked==false)
		        {
		        frm.elements[8].checked=false;
		        }
		        }
	        }
	}
}
function confirmdelete(frm)
{   
    var status = "";
    var stausForAll = "";
    var frm=document.forms[0];
    for (i=0;i<frm.length;i++)
    {
        if (frm.elements[i].name.indexOf('chkSelectAll')!=-1)
         {
            if(frm.elements[i].checked)
            {
                stausForAll = true;	    
            }
         }
        if (frm.elements[i].name.indexOf('chkSelectAll')==-1)
        {
            if ((frm.elements[i].name.indexOf('chkSelect'))!=-1)
            {	
    	        if(frm.elements[i].checked)
		        {
	                status = true;	    
		        }
            }
        }
    }
    if(stausForAll == true && status == "")
    {
      alert('No records to delete');
      return false;
    }
    if(status == true)
    {
        return confirm(ConfirmDelete);
    }		
    else
    {
        alert(SelectItemsToDelete);
        return false;
    }
}

function confirmForward(frm, val) {
    var status = "";
    var stausForAll = "";
    var frm = document.forms[0];
    for (i = 0; i < frm.length; i++) {
        if (frm.elements[i].name.indexOf('chkSelectAll') != -1) {
            if (frm.elements[i].checked) {
                stausForAll = true;
            }
        }
        if (frm.elements[i].name.indexOf('chkSelectAll') == -1) {
            if ((frm.elements[i].name.indexOf('chkSelect')) != -1) {
                if (frm.elements[i].checked) {
                    status = true;
                }
            }
        }
    }
    if (val == 1) {
        if (stausForAll == true && status == "") {
            alert(NorecordtoApproved);
            return false;
        }
        if (status == true) {
            //return confirm(ConfirmDelete);
        }
        else {
            alert(NorecordtoApproved);
            return false;
        }
    }
    else {
        if (stausForAll == true && status == "") {
            alert(NorecordtoForward);
            return false;
        }
        if (status == true) {
            //return confirm(ConfirmDelete);
        }
        else {
            alert(NorecordtoForward);
            return false;
        }
    }

}

function confirmApproved(frm) {
    var status = "";
    var stausForAll = "";
    var frm = document.forms[0];
    for (i = 0; i < frm.length; i++) {
        if (frm.elements[i].name.indexOf('chkSelectAll') != -1) {
            if (frm.elements[i].checked) {
                stausForAll = true;
            }
        }
        if (frm.elements[i].name.indexOf('chkSelectAll') == -1) {
            if ((frm.elements[i].name.indexOf('chkSelect')) != -1) {
                if (frm.elements[i].checked) {
                    status = true;
                }
            }
        }
    }
    if (stausForAll == true && status == "") {
        alert(NorecordtoApproved);
        return false;
    }
    if (status == true) {
    }
    else {
        alert(NorecordtoApproved);
        return false;
    }


}

function Permanentconfirmdelete(frm)
{  
    var status = "";
    var stausForAll = "";
    var frm=document.forms[0];
    for (i=0;i<frm.length;i++)
    {
         if (frm.elements[i].name.indexOf('chkSelectAll')!=-1)
         {
            if(frm.elements[i].checked)
            {
                stausForAll = true;	    
            }
         }
        if (frm.elements[i].name.indexOf('chkSelectAll')==-1)
        {
            if (frm.elements[i].name.indexOf('chkSelect')!=-1)
            {	
    	        if(frm.elements[i].checked)
		        {
	                status = true;	    
		        }
            }
        }
    }
    if(stausForAll == true && status == "")
    {
      alert('No records to delete');
      return false;
    }
    if(status == true)
    {
        return confirm(ConfirmDeletePermanent);
    }		
    else
    {
        alert(SelectItemsToDelete);
        return false;
    }
}


function TermialSave(frm)
{  
    var status = "";
    var stausForAll = "";
    var frm=document.forms[0];
    for (i=0;i<frm.length;i++)
    {
         if (frm.elements[i].name.indexOf('chkSelectAll')!=-1)
         {
            if(frm.elements[i].checked)
            {
                stausForAll = true;	    
            }
         }
        if (frm.elements[i].name.indexOf('chkSelectAll')==-1)
        {
            if (frm.elements[i].name.indexOf('chkSelect')!=-1)
            {	
    	        if(frm.elements[i].checked)
		        {
	                status = true;	    
		        }
            }
        }
    }
    if(stausForAll == true && status == "")
    {
      alert('No records to sync');
      return false;
    }
    if(status == true)
    {
        return true;
    }		
    else
    {
        alert(SelectItemssync);
        return false;
    }
}



function confirmrestore(frm)
{
    var status = "";
     var stausForAll = "";
     var frm=document.forms[0];
    for (i=0;i<frm.length;i++)
    {
        if (frm.elements[i].name.indexOf('chkSelectAll')!=-1)
         {
            if(frm.elements[i].checked)
            {
                stausForAll = true;	    
            }
         }
        if (frm.elements[i].name.indexOf('chkSelectAll')==-1)
        {
            if (frm.elements[i].name.indexOf('chkSelect')!=-1)
            {	
    	        if(frm.elements[i].checked)
		        {
	                status = true;	    
		        }
            }
        }
    }
    if(stausForAll == true && status == "")
    {
      alert('No records to restore');
      return false;
    }
    if(status == true)
    {
        return confirm(ConfirmRestore);
    }		
    else
    {
        alert(SelectItemsToRestore);
        return false;
    }
}
function select_all_ShiftAllocation(chkval,idval)
{
var frm=document.forms[0];
var idCheckBox;
	for (i=0;i<frm.length;i++)
	{
	    if (idval.indexOf('checkall')!=-1)  //==0 true
	        {
	            if (chkval==true)
		            {
                           if(frm.elements[i].disabled !=true)
		                    frm.elements[i].checked=true;
		            }
	            else
		            {
		                frm.elements[i].checked=false;
		            }
	        }
	    else if (idval.indexOf('deletethis')!=-1)		
	        {
		        if(i>1 && i<10)
		        {
		        idCheckBox="ctl00_BodyContentPH_grv_EmpDetails_ctl0" + i + "_deletethis";
		        }
		        else if(i>9)
		        {
		        idCheckBox="ctl00_BodyContentPH_grv_EmpDetails_ctl" + i + "_deletethis";
		        }
		        if(document.getElementById(idCheckBox)!=null)
		        {
		        if(document.getElementById(idCheckBox).checked==false)
		        {
		        frm.elements[8].checked=false;
		        }
		        }
	        }
	}
}
function CheckGridList()
       {      
        var count=0;
        for (i=0; i < document.forms[0].elements.length; i++)
            {           
                if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('deletethis') > -1))
                {
                    if (document.forms[0].elements[i].checked == true)
                    {                                   
                        count++;                         
                    }
                }
            }
            if (count > 1)
            {                       
            return true;
            }
            else { 
            alert(SelectItemsToRestore);
            return false;
            }
        }