function isBlank(str)
{
    if (str == "") {
        return(true);
    } else {
        return(false);
    }
}

function isDigit(ch)
{
   switch(ch)
   {
   case '0':
   case '1':
   case '2':
   case '3':
   case '4':
   case '5':
   case '6':
   case '7':
   case '8':
   case '9':
      return(true);
   default:
      return(false);
   }
}

function isMathSymbols(ch)
{
   switch(ch)
   {
   case '+':
   case '-':
   case '.':
      return(true);
   default:
      return(false);
   }
}

function isNumber(value) {
  for (var i=0; i < value.length; i++) {
    a = parseInt(value.charAt(i));
    if (isNaN(a)) {
      return false;
      break;
    }
  }
  return true;
}

function isRealNumeric(n)
{
   var i;
   var iLen=0;
   var rv=true;
   iLen = n.length;
   if(iLen>0)
   {
      for(i=0;i<iLen;i++)
      {
         ch = n.charAt(i);
         if(isDigit(ch)==true || isMathSymbols(ch)==true)
            rv=true;
         else
            return(false);
      }
   }
   return(rv);
}

function isWholeNumeric(n)
{
   var i;
   var iLen=0;
   var start=0;
   iLen = n.length;
   if(iLen>0)
   {
      switch(n.charAt(0))
      {
      case '+':
      case '-':
         start=1;
      default:
         start=0;
      }

      for(i=start;i<iLen;i++)
      {
         if(isDigit(n.charAt(i)) == false)
            return(false);
      }
   }
   return(true);
}

function bCheckByte(n)
{
   var nByte;
   var bool;
   bool = isWholeNumeric(n);
   if(bool == true)
   {
      nByte = parseInt(n);
      if(nByte>=0 && nByte<256)
         return(true);
      else
         return(false);
   }
   return(false);
}

function bCheckInteger(n)
{
   var nInteger;
   var bool;
   bool = isWholeNumeric(n);
   if(bool == true)
   {
      nInteger = parseInt(n);
      if(nInteger>=-32767 && nInteger<32768)
         return(true);
      else
         return(false);
   }
   return(false);
}

function bCheckLong(n)
{
   var nLong;
   var bool;
   bool = isWholeNumeric(n);
   if(bool == true)
   {
      nLong = parseInt(n);
      if(nLong>=-2147483648 && nLong<2147483647)
         return(true);
      else
         return(false);
   }
   return(false);
}

function set_cursor()
{
   var i;
   var j;

   i = 0;
   j = document.forms[0].elements.length;

   do
   {
      show = '1';

      if (document.forms[0].elements[i].disabled == 'undefined'
         || !document.forms[0].elements[i].disabled)
      {
         show = '1';
      }
      else
      {
         show = '0';
      }

      if (document.forms[0].elements[i].type != 'hidden' && show == '1')
      {
         eval('document.forms[0].' + document.forms[0].elements[i].name + '.focus();');
         break;
      }
      i++;

   }
   while(i<j)
}

function allowKeys( obj, keys ) {
  var bAllowKey = false;
  for( var i = 0; i < keys.length; i++ ) {
  if( keys.charAt( i )==String.fromCharCode( window.event.keyCode ) ) {
  bAllowKey = true;
  break;
  }
  }
  if( !bAllowKey ) {
  window.event.cancelBubble = true;
  window.event.keyCode = 0;
  }
}

function insert_date_today(ele)
{
   var dtNewDate = new Date();
   var sDate = dtNewDate.getMonth()+1;
   sDate = dtNewDate.getMonth()+1+'/'+dtNewDate.getDate()+'/'+dtNewDate.getYear();
   document.form1.elements[ele].value=sDate;
}


// Closes Popup & sends parent/openner to new url
function CloseGo(url,closeIt,delay) {
    opener.location.href = url;
	if (closeIt == true)setTimeout('self.close()',delay);
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

// Radio Button Validation
// Usage Example:
//[script]
//var btn = valButton(form.group1);
//if (btn == null) alert('No radio button selected');
//else alert('Button value ' + btn + ' selected'); 
//[/script]

function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
                  

//    The function below formats numbers by adding commas
//    Format the number 5762325
//    document.write( numberFormat( 5762325 ) );
//    Result: 5,762,325 

//    Format the number 5762325.2534
//    document.write( numberFormat( 5762325.2534 ) );
//    Result: 5,762,325.2534

//    Format the number 5762325.25 as a US dollar amount.
//    document.write( numberFormat( 5762325.25, "$" ) );
//    Result: $5,762,325.25 

function numberFormat(nStr,prefix){
    var prefix = prefix || '';
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1))
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    return prefix + x1 + x2;
}

// Validate ABA Routing Number
function ValidateRouting(aba) {
  var valid = "0123456789";
  var len = aba.length;
  var bNum = true;
  var iABA = parseInt(aba);
  var sABA = aba.toString();
  var iTotal = 0;
  var bResult = false;
  var temp;

  for (var j=0; j<len; j++) {
  temp = "" + document.profileform.RoutingNumber.value.substring(j, j+1);
  if (valid.indexOf(temp) == "-1") bNum = false;
  }
  if(!bNum){
     alert("Not a Number");
     document.profileform.RoutingNumber.focus();
  }
  if(len !=0) {  // if there's no number we can just bypass
    if(len != 9) {
      alert("Sorry, the Routing Number is not a proper ABA length.");
      document.profileform.RoutingNumber.focus();
    } else {
      for (var i=0; i<len; i += 3) {
        iTotal += parseInt(sABA.charAt(i),     10) * 3
          +  parseInt(sABA.charAt(i + 1), 10) * 7
          +  parseInt(sABA.charAt(i + 2), 10);
        }
    if (iTotal != 0 && iTotal % 10 == 0){
      bResult = true;
    } else {
      alert("Sorry, this is NOT a valid ABA Routing Number");
      bResult = false;
      document.profileform.RoutingNumber.focus();
    }
  }
  } else {
    // zero length do nothing
      bResult = true;
  }
  return bResult;
}
