
 function IsAbsent(obj, objname) {
      var retval = true;
      for (var i = 0; i < obj.value.length; i++) {
         if (obj.value.substring(i, i + 1) != " ") {
            retval = false;
            break;
         }
      }
      if (retval && (objname != "")) {
        alert("'" + objname + "' may not be left empty");
		obj.select();
		obj.focus();
      }
      return retval;
   }
   
   function TrimAll(obj) {
      var startpos = 0, endpos = obj.value.length - 1;
      // null string, done
      if (endpos == -1) return;
      // find first non-blank character
      while (startpos <= obj.value.length && obj.value.substring(startpos, startpos + 1) == " ")
	     startpos++;
      // find last non-blank character
      while (endpos >= 0 && obj.value.substring(endpos, endpos + 1) == " ") endpos--;
      // trim the blanks
      if (startpos > endpos) obj.value = "";
      else obj.value = obj.value.substring(startpos, endpos + 1);
   }
   
 function IsANumberString(TheString) {
   var testChar;
   var ok = true;   
   for (var i = 0; i < TheString.length; i++) {
      testChar = TheString.charAt(i);
      if ('0123456789'.indexOf(testChar) == -1) {
	     // minus sign in first position is only legal non-digit char
	     if ((testChar != '-') || (i != 0)) {
            ok = false;
            break;
		 }
      }
   }
   return ok;
 }  
   
 function chkbox (field, desc)
  {
	 haveChecked = false;
   	 for (i=0; i < field.length; i++) {
		if (field[i].checked) {
		   haveChecked = true;
		   return true;
		   break;
		}
   	 }
	 if (!haveChecked) {
	    alert('Please select at least one value for \n\n' + desc);
		return false;		
	 }
  }
   
 function ChkEmail(obj, objname) {
	var i,strLen,atPos1,atPos2,periodPos1,periodPos2,strEnd2,strEnd3,testChar;
	//var illegalChars = ", *()<>;:\'\";
	var illegalChars = ", *()<>;:\'\"";
	TrimAll(obj);
	strLen = obj.value.length;
	atPos1 = obj.value.indexOf("@");
	if (atPos1 == -1) {
		alert("\'" + objname + "\' is missing the \'@\' character");
		obj.focus();
		return true;
	}
	if (atPos1 == 0) {
		alert("\'" + objname + "\' may not have \'@\' as the first character");
		obj.focus();
		return true;
	}
	if (atPos1 == strLen-1) {
		alert("\'" + objname + "\' may not have \'@\' as the last character");
		obj.focus();
		return true;
	}
	atPos2 = obj.value.indexOf("@",atPos1+1);
	if (atPos2 !=-1) {
		alert("\'" + objname + "\' may not have more than one \'@\' character");
		obj.focus();
		return true;
	}
	periodPos1 = obj.value.indexOf(".");
	if (periodPos1 == -1) {
		alert("\'" + objname + "\' must contain a \'.\' character");
		obj.focus();
		return true;
	}
 	if (periodPos1 == strLen-1) {
		alert("\'" + objname + "\' may not have \'.\' as the last character");
		obj.focus();
		return true;
	}
	if (periodPos1 == 0) {
		alert("\'" + objname + "\' may not have \'.\' as the first character");
		obj.focus();
		return true;
	}
	periodPos2 = obj.value.indexOf(".",atPos1+1);
	if (periodPos2 == atPos1+1) {
		alert("'" + objname + "\' must have characters between \'@\' and \'.\'");
		obj.focus();
		return true;
	}
	strEnd3 = obj.value.substring(strLen-3,strLen).toLowerCase(); // last three characters
	strEnd2 = obj.value.substring(strLen-2,strLen).toLowerCase(); // last two characters

	for (i=0; i < illegalChars.length; i++) {
		if (obj.value.indexOf(illegalChars.charAt(i)) != -1) {
			alert("\'" + objname + "\' may not contain a \'" + illegalChars.charAt(i) + "\'");
			obj.focus();
			return true;
		}
	}
	return false;
}
  

