function checkall()
{
    for(intCounter=0; intCounter<(document.getElementsByName('chkBox').length); intCounter++)
    {
        document.getElementsByName("chkBox")[intCounter].checked = document.getElementById("chkAll").checked;
    }
}

function checkManual()
{
    var intCheckVal;
    intCheckVal = 1;
    for(intCounter=0; intCounter<(document.getElementsByName('chkBox').length); intCounter++)
    {
        if(document.getElementsByName("chkBox")[intCounter].checked == false)
            intCheckVal = 0;
    }
    if(intCheckVal == 1)
        document.getElementById("chkAll").checked = true;
    else
        document.getElementById("chkAll").checked = false;
}

function ConfirmForDelete()
{
    return confirm('Are you sure you want to delete record?');
}

function selected(string)
{           
    var intCountControls=0;
    for(intCounter=0; intCounter<(document.getElementsByName('chkBox').length); intCounter++)
    {               
        if(document.getElementsByName("chkBox")[intCounter].checked == true)
        {
           intCountControls++;
        }
    }    
    if(intCountControls == 0)
    {            
        if (string == "delete")
            alert('Please Select a Record(s) to delete');
        else if (string == "active")
            alert('Please Select a Record(s) to change the status');
        else if (string == "inactive")
            alert('Please Select a Record(s) to change the status');
        else if (string == "new")
            alert('Please Select a Record(s) to change the status');
        else if (string == "approve")
            alert('Please Select a Record(s) to change the status');
        else if (string == "deny")
            alert('Please Select a Record(s) to change the status');
        else if (string == "success")
            alert('Please Select a Record(s) to change the status');
        else if (string == "fail")
            alert('Please Select a Record(s) to change the status');
        else if (string == "unasaign")
            alert('Please Select a Record(s) to change the status');
        return false;
    }   
    else if (intCountControls > 1000)
    {
        if (string == "delete")
            alert('You can delete only 1000 Records at a time.');
        else if (string == "active")
            alert('You can active only 1000 Records at a time.');
        else if (string == "inactive")
            alert('You can inactive only 1000 Records at a time.');
        else if (string == "new")
            alert('You can make new only 1000 Records at a time.');
        else if (string == "approve")
            alert('You can approve only 1000 Records at a time.');
        else if (string == "deny")
            alert('You can deny only 1000 Records at a time.');
        else if (string == "success")
            alert('You can make success only 1000 Records at a time.');
        else if (string == "fail")
            alert('You can make fail only 1000 Records at a time.');
        else if (string == "unasaign")
            alert('You can unasaign only 1000 Records at a time.');
        return false;
    } 
    else if(intCountControls > 0)
    {         
         if (string == "delete")
        {            
           return confirm('Are you sure you want to delete record?');
        }
        else if(string=="active")
        {
           return confirm('Are you sure you want to active record?');
        }  
        else if (string=="inactive")        
        {
           return confirm('Are you sure you want to inactive record?');
        }
        else if (string == "new")
        {            
           return confirm('Are you sure you want to merk these as New?');
        }
        else if(string=="approve")
        {
           return confirm('Are you sure you want to mark these as Approved?\n');
        }  
        else if (string=="deny")        
        {
           return confirm('Are you sure you want to mark these as Denied?\n');
        }          
        else if(string=="success")
        {
           return confirm('Are you sure you want to mark these as a Success?');
        }  
        else if (string=="fail")        
        {
           return confirm('Are you sure you want to mark these as Failed?');
        }          
        else if (string=="unassign")        
        {
           return confirm('Are you sure you want to mark these as Unassign?');
        }          
    }
}

function SearchValidation(objddlSearchField,objtxtSearchVal)
{
    if (document.getElementById(objddlSearchField).value == '0')
    {
        alert('Please select any value for search!');
        document.getElementById(objddlSearchField).focus();
        return false;
    }
    
    if(document.getElementById(objtxtSearchVal))
    {
        if (Trim(document.getElementById(objtxtSearchVal).value)=='' && document.getElementById(objddlSearchField).value != 'IsStatus' && document.getElementById(objddlSearchField).value != 'Status')
        {
            alert('Please enter any value for search!');
            document.getElementById(objtxtSearchVal).focus();
            return false;
        }
    }
    	        
    return true;
}

function SearchOption(objddlSearchField,objtxtSearchVal,objddlSearchVal)
{
    var ddlSearchFieldValue = document.getElementById(objddlSearchField).value;

    objtxtSearchVal = document.getElementById(objtxtSearchVal)
    objddlSearchVal = document.getElementById(objddlSearchVal)
    
    if(ddlSearchFieldValue == "IsStatus" || ddlSearchFieldValue == "Status")
    {
          objtxtSearchVal.style.display = 'none';
          objddlSearchVal.style.display = 'block';
          objtxtSearchVal.value ='t';
    }
    else
    {
        objtxtSearchVal.style.display = 'block';
        objddlSearchVal.style.display = 'none';
         objtxtSearchVal.value ='';
    }
    return false;
}


//Remove space from given Text
function Trim(s) 
{
    // Remove leading spaces and carriage returns
    while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
    {
        s = s.substring(1,s.length);
    }
    // Remove trailing spaces and carriage returns
    while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
    {
        s = s.substring(0,s.length-1);
    }
    return s;
} 

function popitup(url)
{
    newwindow=window.open(url,'name','height=405,width=555,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1');
    if (window.focus)
    {
        newwindow.focus();
    }
    return false;
}

function IsValidEmail(str)
{
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (filter.test(str))
        return true;
        
    return  false;
}     

function NumericValidation(e)    //Only Numeric value
{	
    var KeyID = (window.event) ? event.keyCode : e.which;	
   
    if ((KeyID >= 48 && KeyID <= 57)|| (KeyID == 8)|| (KeyID == 0))
    {
        return true;
    }
    else
    {
        return false;
    }
}

function KeyNumeric(e)    //This is for PostCode textbox. Only Numeric value
{	
    var KeyID = (window.event) ? event.keyCode : e.which;	

    if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47 && KeyID != 46) ||
        (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126) ) 
        {
            return false;
        }
    if(KeyID == 32)
    {
        return false;
    }	
}            
 
function checkWordLimit(targetid,feedbackid,maxWords)
{
    var rx = RegExp('([a-zA-Z]+\\S+\\s+){'+maxWords+'}','g');      
    var counter = document.getElementById(feedbackid);
        
    var totalWords = targetid.value.split(/\s+/), L= maxWords - totalWords.length;
    if (targetid.value == '') 
    {
        if (counter)
        {
            counter.innerHTML = maxWords + " Palabras";
        }
         
    } 
    else 
    {
        if (L < 0) 
        {
         targetid.value = totalWords.slice(0, maxWords).join(' ');               
          L = 0;            
        }
        if (counter)
        {
            if (counter.innerHTML != L) 
            {
                counter.innerHTML = "<strong>" + L + "</strong> Palabras permitidas";            
            }
        }
    }
}

function SetWordLimit(targetid,feedbackid,maxWords)
{
    var rx = RegExp('([a-zA-Z]+\\S+\\s+){'+maxWords+'}','g');      
    var counter = document.getElementById(feedbackid);
    var target = document.getElementById(targetid);
    if(target)
    {    
        var totalWords = target.value.split(/\s+/), L= maxWords - totalWords.length;
        if (target.value == '') 
        {
            if (counter)
            {
                counter.innerHTML = maxWords + " Palabras";
            }         
        } 
        else 
        {
            if (L < 0) 
            {
             target.value = totalWords.slice(0, maxWords).join(' ');               
              L = 0;            
            }
            if (counter)
            {
                if (counter.innerHTML != L) 
                {
                    counter.innerHTML = "<strong>" + L + "</strong> Palabras permitidas";            
                }
            }
        }
    }
}
