/*function badcharMatch(ascii_value) {
	if(ascii_value!=46 && (ascii_value<48 || ascii_value>57)) {
		returnValue = true;
	} else {
		returnValue = false;
	}
	return returnValue;
} */

function badcharMatch(ascii_value) {
	if(ascii_value==34 || ascii_value==35 || ascii_value==36 || ascii_value==37 || ascii_value==38 || ascii_value==40 || ascii_value==41 || ascii_value==42 || ascii_value==63 || ascii_value==94) {
		returnValue = true;
	} else {
		returnValue = false;
	}
	return returnValue;
}

function afterNumEntry(obj,decplaces) {
   // routine called after a number is entered
   var expr = parseFloat(obj.value)
   if (isNaN(expr)) {
     alert("The value entered must be a number.")
     obj.value = ''
   }
   if (expr < 0) {
     alert("The value entered must be positive.")
     obj.value = ''
   }
   if (obj.value!='') {
	   expr = formatNum(expr,decplaces)
	   obj.value = expr
	}
   
}

function formatNum(expr, decplaces) {
   // usually called after a number is entered
   var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
   while (str.length <= decplaces) {
     str = "0" + str
   }
   var decpoint = str.length - decplaces
   if (decplaces != 0) {
     return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length)
   } else {
     return str.substring(0,decpoint)
   }
}


function phone(obj) {
  // entry could include special characters. get rid of them
  var baseNum = iconv(obj.value);
  baseNum.toString();
  var baseLength = baseNum.length;
  if (baseLength != 10 && baseLength != 0) {
	alert("Please enter a ten digit number (include area code).");
	rtnVal = ""
	obj.focus()
  } else {
	rtnVal = ""
	if (baseLength == 10) {
	  rtnVal  = "(" + baseNum.substring(0,3) + ") " + baseNum.substring(3,6)
	  rtnVal += "-" + baseNum.substring(6,baseLength);
	}
	/*if (baseLength == 7) {
	  rtnVal = baseNum.substring(0,3) + "-" + baseNum.substring(3,7)
	} */
  }
  obj.value = rtnVal
}

function iconv(val) {
  var strLength = val.length;
  var rtnVal = '';
  for (var i=0; i <strLength; i++) {
	curVal = val.charAt(i);
	if ( isNaN(curVal) != true && curVal != " ") { rtnVal += val.charAt(i); }
  }
  return rtnVal;
}

function validateNotEmptyOrAlert(obj, alertText) {
	if (obj.value == "") { ; alert(alertText) ; obj.focus() ; return false; } ;
	return true;
}
