function valOptionSelected(oField,sAlert,o){
  var i=0;
  while(oField[i] != null){
    if (oField[i].checked){
      return o;
    }
    i++;
  }
  _doError(oField[0],o,sAlert);
  return o;
}
function valIsChecked(oField,sAlert,o){
  if(!oField.checked){
    _doError(oField,o,sAlert);
  }
  return o;
}
function valAlphaNumField(oField,sAlert,o){
  str = new String(oField.value);
  if (str.match("[^a-zA-Z 0-9]")){
    _doError(oField,o,sAlert);
  }
  return o;
}
function valNumberField(oField,sAlert,o){
  str = new String(oField.value);
  if (str.match("[^0-9\.]")){
    _doError(oField,o,sAlert);
  }
  return o;
}
function valNumberRange(oField,sAlert,o,iMin,iMax){
  n = new Number(oField.value);
  if (n>iMax || n<iMin){
    _doError(oField,o,sAlert);
  }
  //alert(n +''+ iMin+' '+iMax);
  return o;
}
function valNotNullField(oField,sAlert,o){
  if (oField.value == null || oField.value == ""){
    _doError(oField,o,sAlert);
  }
  return o;
}
function valPhoneNumberField(oField,sAlert,o){
  str = new String(oField.value);
  if (str.match("[^0-9\.\+ \(\)]")){
    _doError(oField,o,sAlert);
  }
  return o;
}
function valEmailField(oField,sAlert,o){
  var iChars = "*|,\":<>[]{}`\';()&$#%";
  var b = true;
  var sErr = "";
  if(oField.value.length){
    s = oField.value;
    for (var i = 0; i < s.length; i++) {
      if ((iChars.indexOf(s.charAt(i)) != -1) ){
        sErr = "You can't have "+s.charAt(i)+" in an email address. ";
        b = false;
        break;
      }
    }
    var ap = s.indexOf("@");
    var dp = s.lastIndexOf(".");
    b = b && (ap > 1 && s.length > 5 && dp != -1 && dp > ap);
    if (!b){
      _doError(oField,o,sAlert+sErr+"\n");
    }
  }
  return o;
}
function valMaxWordCount(oField,sAlert,o,wc){
  var txt=oField.value
  txt=txt.split(" ")
  if (txt.length > wc){
    _doError(oField,o,sAlert);
  }
  return o;
}
/** BB: was this ever finished - Have finished it below 
function valExtension(oField,sAlert,o,aExts){
  var txt=oField.value;
  txt=txt.split(" ")
  if (txt.length > wc){
    _doError(oField,o,sAlert);
  }
  return o;
}
**/
function valExtension(oField,sAlert,o,aExts) {
	var i;
	var sExt = '';
	for( i=0; i < aExts.length; i++ ) {
		sExt += aExts[i]+',';
	}
	sExt = sExt.substring( 0 , (sExt.length-1) );
	return checkExtenstion(oField,sAlert,o,sExt);
}

// Copied from NickJR
function checkExtenstion(oField,sAlert,o,sExt) {
  var sFE = oField.value;
  var aExt = sExt.split(',');

  //sFE.lastIndexOf('.') // The point of this?
  sFE = sFE.substring(sFE.lastIndexOf('.')+1,sFE.length);
  sFE = sFE.toLowerCase();
  
  for(var i = 0; i < aExt.length; i++) {
    if(aExt[i] == sFE){
      return o;
    }
  }
  _doError(oField,o,sAlert);
  return o;
}

function getRadioValue(obj){
  var i;
  for (i=0;obj[i] != null && i<100; i++){
    if (obj[i].checked){
      return obj[i].value;
    }
  }
  return "";
}
function sendForm(oForm){
  if(formValidate(oForm)){
    oForm.submit();
  }
}
function _doError(oField,oRes,sAlert){
  oRes.sAlert += sAlert;
  if (oRes.bResult){//focus on first error
    if(oField.focus && oField.style.enabled != false && oField.style.visibility != "hidden" && oField.style.display != "none" ){// except hiddens for ie
      oField.focus();
    }
    oField.style.border = "1px solid red";
    oRes.bResult = false;
  }
  return oRes;
}
