﻿
function isNumeric(e)
{
   var keynum;
   var keychar;
   var numcheck;

   if(window.event) // IE
   {
     keynum = e.keyCode;
   }
   else if(e.which) // Netscape/Firefox/Opera
   {
     keynum = e.which;
   }
   keychar = String.fromCharCode(keynum);
   numcheck = /\d/;
   return numcheck.test(keychar);
}

function isDecimal(e)
{
   var keynum;
   var keychar;
   var numcheck;

   if(window.event) // IE
   {
     keynum = e.keyCode;
   }
   else if(e.which) // Netscape/Firefox/Opera
   {
     keynum = e.which;
   }
   keychar = String.fromCharCode(keynum);
   numcheck = /\d/;
   numcheck1 = /\./;
   return (numcheck.test(keychar)||numcheck1.test(keychar));
}

function Trim (inputString, removeChar) 
{ 
    var returnString = inputString; 
    
    if (removeChar.length) 
    {
        while(''+returnString.charAt(0)==removeChar)
        {
            returnString=returnString.substring(1,returnString.length);
        }
        while(''+returnString.charAt(returnString.length-1)==removeChar)
        {
            returnString=returnString.substring(0,returnString.length-1);
        }
    }
    
    return returnString;
}

function isValidEmail(email)
{
     var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
	 var returnval=emailfilter.test(email);
	 return returnval;
}

function CheckImage(ctl)
{

	var filePath = ctl.value;
 
	var validExtensions = new Array();
	var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase(); 

	validExtensions[0] = 'jpg';
	validExtensions[1] = 'jpeg';

	validExtensions[2] = 'bmp';
	validExtensions[3] = 'png';

	validExtensions[4] = 'gif';
	validExtensions[5] = 'tif'; 

	for(var i = 0; i < validExtensions.length; i++) 
	{
		if(ext == validExtensions[i]) return true;
	}

	alert('Please upload an image');
	return false;
}

function IsGridSelected(grdId, chkId, startVal)
{
    var chk;
    
    if(startVal>9)
    {
        chk = document.getElementById(grdId + startVal + '_' + chkId);
    }
    else
    {
        chk = document.getElementById(grdId + '0' + startVal + '_' + chkId);
    }
    
    while(chk!=null)
    {
        if(chk.checked)
        {
            return true;
        }
        
        startVal++;
        
        if(startVal>9)
        {
            chk = document.getElementById(grdId + startVal + '_' + chkId);
        }
        else
        {
            chk = document.getElementById(grdId + '0' + startVal + '_' + chkId);
        }
    }
    
    return false;
}

function valGridDelete(gridId)
{
    if(!IsGridSelected(gridId + '_ctl', 'chk', 2))
    {
        alert("Please select an item");
        return false;
    }
    
    return confirm('Are you sure?');    
}

function isEmpty(ctl)
{
    if(Trim(ctl.value, ' ') == "")
    {
        return true;
    }
    return false;
}

function isNull(ctl)
{
    if(ctl.value == null)
    {
        return true;
    }
    return false;
}

function isEmail(ctl)
{
    if(isValidEmail(Trim(ctl.value, ' ')))
    {
        return true;
    }
    return false;
}

function isMatch(ctl1, ctl2)
{
    if(Trim(ctl1.value, ' ') == Trim(ctl2.value, ' '))
    {
        return true;
    }
    else
    {
        return false;
    }
}

function isSelected(ctl)
{
    if(Trim(ctl.value, ' ') == "-1")
    {
        return false;
    }
    return true;
}

function controlEnter(obj, event)
{
    var key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    
    if(key == 13)
    {
        document.getElementById(obj).click();
        return false;
    }
    else
        return true;
}

function isZipcode(ctl)
{
    if(Trim(ctl.value, ' ').length == 5)
    {
        return true;
    }
    return false;
}

function isPhone(ctl)
{
    if(Trim(ctl.value, ' ').length == 10)
    {
        return true;
    }
    return false;
}

function mkVisible(id)
{
    var ctl = document.getElementById(id);
    
    if(ctl == null)
    {
        ctl = document.getElementById("ctl00_content_" + id);
    }
    if(ctl != null)
    {
        ctl.style.visibility='visible';
        ctl.style.display='block';
    }
}

function mkHide(id)
{
    var ctl = document.getElementById(id);
    
    if(ctl == null)
    {
        ctl = document.getElementById("ctl00_content_" + id);
    }
    if(ctl != null)
    {
        ctl.style.display='none';
        ctl.style.visibility='hidden';
    }
}

function valChkList(id)
{
    var ctl;
    var index = 0;
    var status = 0;
    
    ctl = document.getElementById(id + index);
    
    while(ctl != null)
    {
        if(ctl.checked == true)
        {
            status = 1;
        }
        
        index++;
        
        ctl = document.getElementById(id + index);
    }
    
    if(status == 0)
    {
        return false;
    }
    return true;
}

function isDecimalValue(id)
{
    var ctl = document.getElementById(id);    
    var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
    
    return reFloat.test(Trim(document.getElementById(id).value, ' '));
}

function chkAll(gridId, chkId)
{
    var chkAll = document.getElementById(chkId);    
    
    var ctlStr = gridId + "_ctl";
    
    var chk = document.getElementById(ctlStr + "02_chk");
    
    var index = 2;
    
    var chkCtlStr;
    
    while(chk != null)
    {
        if(chkAll.checked == true)
        {
            chk.checked = true;
        }
        else
        {
            chk.checked = false;
        }
        
        index++;
        
        if(index < 10)
        {
            chkCtlStr = ctlStr + "0" + index + "_chk";
        }
        else
        {
            chkCtlStr = ctlStr + index + "_chk";
        }
        
        chk = document.getElementById(chkCtlStr);
    }
}