function valDate(theMonth, theDay){
  if(theMonth == "February" && parseInt(theDay,10) > 28){
    alert("Invalid Date: February has only 28 days.");
    return false;
  }
  if(theMonth == "April" || theMonth == "June" || theMonth == "September" || theMonth == "November"){
    if(parseInt(theDay,10) > 30) { alert("Invalid Date: " + theMonth + " has only 30 days."); return false; }
  }
  return true;
}

function formatFloat(expr, decplaces){
  var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
  while (str.length <= decplaces) {str = "0" + str;}
  var decpoint = str.length - decplaces;
  return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

function valTilde(field){
  var re = /~/g;
  if (field.value.indexOf("~") != -1){
    field.focus();
    alert('The tilde ( ~ ) character is not allowed.');
    field.value = field.value.replace(re, "");
  }
}

function valSIN(field){
  var re = /\D/;
  var result = 0;
  if(field.value.length != 9){ return false; }
  if(re.test(field.value)) { return false; }
  var arDigits = field.value.split("");
  for(var i = 1; i < 9; i += 2){
    arTemp = (parseInt(arDigits[i],10) * 2).toString().split("");
    for(var j = 0; j < arTemp.length; j++){
      result += parseInt(arTemp[j],10);
    }
  }
  result += parseInt(arDigits[0],10) + parseInt(arDigits[2],10) + parseInt(arDigits[4],10) + parseInt(arDigits[6],10);
  if(result < 11) {
    result = 10;
  } else {
    var checkNum = Math.ceil(result / 10) * 10 - result;
  }
  if(checkNum != arDigits[8]) { return false; }
  return true;
}

function valNumber(field){
  if(!valNotBlank(field)) { return false; };
  var re = /\D/;
  var re2 = /^\d+\.\d+$/;
  if(!re.test(field.value)) { return foo=1; }
  if(re2.test(field.value)) { return foo=1; }
  
  return false;
}

function valNoSpaceNum(field){
  if(!valNotBlank(field)) { return false; };
  var re = /\D/;
  if(field.value.length == 9){
    return (!re.test(field.value));
  } else {
    return false;
  }
}

function valBankNum(field){
  var re = /\D/;
  return (!re.test(field.value));
}

function valEmail(field){
  var reA = /\W+/;
  var reB = /[A-Za-z]/g;
  var reC = /-|\./gi;
  
  var arA = field.value.split("@");
  if (arA.length != 2) { return false; }
  if (arA[0].length == 0) { return false; }
  var arB = arA[1].split(".");
  if (arB.length < 2) { return false; }

  if (reA.test(arA[0].replace(reC,""))) { return false; }
  for(var i = 0; i < arB.length-1; i++){
    if (arB[i].length == 0) { return false; }
    if (reA.test(arB[i].replace(reC,""))) { return false; }
  }

  if (arB[arB.length-1].length == 0) { return false; }
  if (arB[arB.length-1].replace(reB,"").length > 0) { return false; }

  return true;
}

function valNotBlank(field){
  if (field.value == "" || field.value == null) { return false; }
  
  return foo=1;
}

function valPostalCode(field){
  var re = /[a-z]\d[a-z]\d[a-z]\d/i;
  var re2 = / /g;  
  if(!re.test(field.value.replace(re2,""))) { return false; }
  
  return foo=1;
}

function valPhoneNumber(num){
  var re = /\d{10}/;
  if(!re.test(num)) { return false; }
  
  return foo=1;  
}
