function IsNotNumbersOrLetters(textField, msg) {
  var s = textField.value;
  var IllegalChars = /[\W_]/;  

  if (s.match(IllegalChars)) {
    alert (msg);
    textField.focus();
    textField.select();
    return true;
  }
  return false;
}

function IsEmpty(textField, msg) {
  var s=textField.value;
  for (var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t'))
      return false;
  }
  alert (msg);
  textField.focus();
  textField.select();
  return true;
}

function IsEmpty2(textField) {
  var s = textField.value;
  for (var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t'))
    return false;
  }
  return true;
}

function IsNotNumber(textField, msg) {
  if (isNaN(textField.value)) {
    alert (msg);
    textField.focus();
    textField.select();
    return true;
  }
  else return false;
}

function CheckMinLength(textField, minchars, msg) {
  if (Number(textField.value.length) < Number(minchars)) {
    alert(msg);
    textField.focus();
    textField.select();
    return true;
  }
  return false;
}

function CheckMaxLength(textField, maxchars, msg) {
  if (Number(textField.value.length) > Number(maxchars)) {
    alert(msg);
    textField.focus();
    textField.select();
    return true;
  }
  return false;
}

function CheckMaxLength_beta(formName, Field) { //Review
 if (Field.value.length == Field.size) {
  for (i = 0; i < formName.elements.length; i++) {
   var NAME = formName.elements[i].name;
   if (NAME == Field.name) {
    i++;
    if (formName.elements[i].type != "hidden")
     formName.elements[i].focus();
   }
  }
 }
}

function emailBAD(name, msg) {
  var txt=name.value;
  txt=txt.toLowerCase();
  
  if (txt.indexOf("@")<1) {
    alert(msg);
	name.focus();
    name.select();
    return true;
  }
//  if ((txt.indexOf(".com")<4)&&(txt.indexOf(".org")<4)&&
//      (txt.indexOf(".gov")<4)&&(txt.indexOf(".net")<4)&&
//      (txt.indexOf(".mil")<4)&&(txt.indexOf(".edu")<4)){
//    alert("I'm sorry. This email address seems wrong. Please check the suffix for accuracy. (It should include a .com, .edu, .net, .org, .gov or .mil)");
//    return(true);
//  }
  return false;
}

function CheckRange(textField, minval, maxval, msg) 
{
 if ((textField.value < minval) || (textField.value > maxval)) {
   alert(msg);
   textField.focus();
   textField.select();
   return true;
  }
  return false;
}

function Check_chk_txt(checkbox, textField, msg) {
  if (checkbox.checked) {
    if (IsEmpty2(textField)) {
      alert(msg);
      textField.focus();
      textField.select();
      return true;
	}
    else {	
	  return false;
	}
  }	   
  else {
    if (IsEmpty2(textField)) {
      return false; 
	}
    else {	
	  //alert("Please check Other");
      checkbox.checked=true;
	  checkbox.focus();
      return true;
	} 
  }
}

function IsNotSelected(ListMenu,msg) {
  if (ListMenu.options[0].selected) {
    alert (msg);
    ListMenu.focus();
    return(true);
  }
  else return (false);
}

function IsNotChecked(checkbox,msg) {
  if (checkbox.checked) {
    return(false);
  }
  else {
    alert (msg);
    checkbox.focus();
	return (true);
  }
}

function FormatNumber(num, decimalNum, bolLeadingZero, bolParens, bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}

function FormatCurrency(num, decimalNum, bolLeadingZero, bolParens, bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.										
 
	RETVAL:
		The formatted number!		
 **********************************************************************/
{
	var tmpStr = new String(FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas));

	if (tmpStr.indexOf("(") != -1 || tmpStr.indexOf("-") != -1) {
		// We know we have a negative number, so place '$' inside of '(' / after '-'
		if (tmpStr.charAt(0) == "(")
			tmpStr = "($"  + tmpStr.substring(1,tmpStr.length);
		else if (tmpStr.charAt(0) == "-")
			tmpStr = "-$" + tmpStr.substring(1,tmpStr.length);
			
		return tmpStr;
	}
	else
		return "$" + tmpStr;		// Return formatted string!
}


function GetRadioValue(radGrp) {
  var rad, i = 0;
  while (rad = radGrp[i++])
    if (rad.checked) 
      return rad.value;
  return '';
}








