function checkTextareaLength() {
  if (document.emailform.emailBody.value.length>1024) {
    alert('The message you have typed has been limited to 1,000 characters, please edit and resend');
    document.emailform.operation.disabled = true;
    return 0;
  } else {
    document.emailform.operation.disabled = false;
    return 1;
  }
}

//automatically selects the text of an input type=text element when it is selected
function autoSelect(form){
  elems = form.elements;
  for (i=0; i<elems.length; i++)
    if (elems[i].type == 'text') elems[i].onfocus = "this.select();";
}

function checkLength(name, value, length) {
  if (value.value == '') return -1;
  if (value.value.length > length){
    alert(name+" : Too long, must be at most "+length+"characters");
    value.value = '';
    value.focus();
    return 1;
  }
  return 0;
}

//checks that an input field has only alphanumeric characters
function checkAlphaNum(name, value, length) {
  return checkLength(name, value, length);

  if (value.value == '') return -1;
  if (value.value.length > length){
    alert(name+" : Too long, must be at most "+length+" characters");
    value.value = '';
    value.focus();
    return 1;
  }
  var re = /^([a-z0-9\s]{1,})$/i;
  if(!re.exec(value.value)){
    alert(name+" : Must be alphanumeric");
    value.value = '';
    value.focus();
    return 1;
  }
  return 0;
}

//checks that an input field only has alpha characters
function checkName(name,value,length) {
  return checkLength(name, value, length);

  if (value.value == '')
    return -1;

 if (value.value.length > length){
   alert(name+" : Too long, must be at most "+length+"characters");
    value.value = '';
    value.focus();
    return 1;
 }
 var re = /^([a-z\s]{1,})$/i;
 if(!re.exec(value.value)){
   alert(name+" : Incorrect symbol");
   value.value = '';
   value.focus();
   return 1;
 }
 return 0;
}

//checks that an input field has only numeric characters
function checkNum(name,value, length) {
  return checkLength(name, value, length);

  if (value.value == '')
    return -1;
  if (value.value.length > length){
    alert(name+" : Too long, must be at most "+length+"characters");
    value.value = '';
    value.focus();
    return 1;
  }
  var re = /^(\d{1,})$/;
  if (!re.exec(value.value)){
    alert(name+" : Numerals only!");
    value.value = '';
    value.focus();
    return 1;
  }
  return 0;
}

//checks that an inmput field contains a valid email address
function checkEmail(name,value,length) {
  if (value.value == '')
    return -1;
  if (value.value.length > length){
    alert(name+" : Too long, must be at most "+length+"characters");
    value.value = '';
    value.focus();
    return 1;
  }
  var re = /^([\w\.\-]{1,}@{1}[\w\.\-]{1,})$/i;
  if (!re.exec(value.value)){
    alert(name+" : Must be in xx@yy.zz");
    value.value = '';
    value.focus();
    return 1;
  }
  return 0;
}

//checks that all member fields are filled in properly
function checkMemberFields(form){

  // must accept terms and conditions
  if (!form.terms.checked){
    alert('You must accept the terms and conditions!');
    return 0;
  }

  //email fields must match
  if (form.email.value != form.vemail.value){
    alert('Both e-mail fields must mach!');
    form.email.focus();
    return 0;
  }

  //all text fields must be filled in
  elems = form.elements;
  for (i=0; i<elems.length; i++){
    if (elems[i].type == 'text' && !elems[i].value.length){
      alert("Signup form incomplete!");
      elems[i].focus();
      return 0;
    }
  }
  return 1;
}

function validateEmail()
{
	form = document.emailform;

	if (form.emailtype.selectedIndex == 0)
	{
		alert('Please select a subject type');
		return;
	}
	else
		form.submit();
}
