function valOptionSelected(oField,sError,o){
  var i=0;
  while(oField[i] != null){
    if (oField[i].checked){
      return o;
    }
    i++;
  }
  return _displayError(oField,o,sError);
}

function valOptionSelectedCheck(oField){
  var i=0;
  while(oField[i] != null){
    if (oField[i].checked){
      return true;
    }
    i++;
  }
  return false;
}


function valAlphaNumField(oField,sError,o){
  str = new String(oField.value);
  if (str.match("[^a-zA-Z0-9]")){
    _displayError(oField,o,sError);
  }
  return o;
}
/*
function valNumberField(oField,sAlert,o){
  str = new String(oField.value);
  if (str.match("[^0-9\.]")){
    _doError(oField,o,sAlert);
  }
  return o;
}
*/
function valMinLength(oField,sError,o,tl){
  var txt=oField.value;
  if (txt.length < tl){
    _displayError(oField,o,sError);
  }
  return o;
}


function valPhoneNumberField(oField,sAlert,o){
  str = new String(oField.value);
  if (str.match("[^0-9\.\+ \(\)]")){
    _doError(oField,o,sAlert);
  }
  return o;
}
/*
function valNotNullField(oField,sAlert,o){
  if (oField.value == null || oField.value == ""){
    _doError(oField,o,sAlert);
  }
  return o;
}
*/

function valNumberField(oField,sError,o){
  str = new String(oField.value);
  if (str.match("[^0-9\.]")){
    _displayError(oField,o,sError);
  }
  return o;
}

function valNotNullField(oField,sError,o){
  if (oField.value == null || oField.value == ""){
    _displayError(oField,o,sError);
  }
  return o;
}

function valSameString(oField1,oField2,sError,o){
  if (oField1.value != oField2.value){
    _displayError('',o,sError);
  }
  return o;
}

function getRadioValue(obj){
  var i;
  for (i=0;obj[i] != null && i<100; i++){
    if (obj[i].checked){
      return obj[i].value;
      alert(obj[i].value);
    }
  }
  //_displayError(oField,o,sError);
  return o;  
  //return "";
}

function _displayError(oField,oRes,sError){
  var e = document.getElementById(sError);
	e.style.display = 'block';
  
  if (oRes.bResult){//focus on first error
    //oField.focus(); //doesnt seem to work in IE - maybe due to the fact the form doesnt exist?
    oRes.bResult = false;
  }
  return oRes;
}

function displayError(sError){
  var e = document.getElementById(sError);
	e.style.display = 'block';
}


function valEmailField(oField,sError,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) ){
        b = false;
        _displayError(oField,o,sError);
        break;
      }
    }
    var ap = s.indexOf("@");
    var dp = s.lastIndexOf(".");
    b = b && (ap > 1 && s.length > 5 && dp != -1 && dp > ap);
    if (!b){
      _displayError(oField,o,sError);
    }
  }
  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;
}

function sendForm(oForm){
  if(formValidate(oForm)){
    oForm.submit();
  }
}
function _doError(oField,oRes,sAlert){
  oRes.sAlert += sAlert;
  if (oRes.bResult){//focus on first error
    //oField.focus(); //doesnt seem to work in IE - maybe due to the fact the form doesnt exist?
    oRes.bResult = false;
  }
  return oRes;
}
function CheckEmail(oField, who){
  if (oField.value == ""){
    alert("Woops! Please enter "+who+" e-mail address.")
    return false;
  }
  if ((oField.value.indexOf("@") < 1 || oField.value.indexOf(".") == -1 || oField.value.indexOf(".") == oField.value.length -1 || oField.value.indexOf('.',oField.value.indexOf('@')) == -1)
    || oField.value.indexOf('"') != -1 || oField.value.indexOf("'") != -1 || oField.value.indexOf(" ") != -1) {
    alert("Woops! "+who+" e-mail address that you entered is invalid. Please try again.")
    return false;
  }
  return true;
}