function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function queryField(opt)
{
  /*var keyloc		// The location of the start of "key=value"
  var nextkey 		// The start of the next key
  var start 		// The start of the value
  var opts			// The options specified by the search string
  var optval		// The value of the selected option
	var sval
	*/
	// Determine the options/search string
  opts=location.search
  // Most keys start after an & and are followed by an = sign
  keyloc = opts.indexOf("&" + opt + "=")
  // If a string isn't found, indexOf returns -1.  So, we try the "first"
  // key, which appears right after the initial question mark
  if(keyloc == -1) {
    keyloc = opts.indexOf("?" + opt + "=")
  }
  // If, at this point, we still haven't found the key, stop.
  if (keyloc == -1) {
    return ""
  } 
  // The value normally ends with an ampersand (which marks the start of the next key/value pair)
  nextkey = opts.indexOf("&",keyloc+1)  
  // But sometimes there is no next pair
  if (nextkey == -1) {
    nextkey = opts.length
  }
  // Okay, what next?  Verify that it's reasonable
  if (nextkey < keyloc) {
    return ""
  }  
  // Get and return the value
	sval = keyloc+2+opt.length
  optval = plustospace(unescape(opts.substring(sval,nextkey)))
  return optval
} // getOption()

function plustospace(txt)
{
  // Sanity check on empty string
  if (txt == "") { return txt }
  
  // Variables
  var newtxt=""  // The txt without the spaces
  var pos=0      // The position of the plus sign
  var prev=0     // The position of the previous plus sign
  var done=false // sentinel for loop
  var tmp        // Used for debugging
  
  // Repeatedly find the next + sign, stopping when no more
  // are found
  // alert("Text is '" + txt + "'") // DEBUG
  while (!done) {
    pos = txt.indexOf("+",prev)
    // tmp = prompt("Plus found at '" + pos + "'", "OK")  // DEBUG
    // if (tmp != "OK") { done = 1 }// DEBUG
    if (prev >= txt.length) {
      done = true
    }
    else if (pos == 0) {
      prev=1
      newtxt += " "
    }
    else if ((pos < 0) || (pos == "")) {
      // Not found ... exit
      done = true
    }
    else {
      // Copy text
      if (pos>prev) { newtxt += txt.substring(prev,pos) }
      newtxt += " "
      // And move on
      prev=pos+1
    }
  }
  // Get the last little bit
  newtxt += txt.substring(prev,txt.length)
  return newtxt  
} // plustospace()

// Form validation - checks that required fields are completed
// To make a field required:
//    1. Add an 'ID' attribute to field object (e.g. text input).
//    2. Set value of ID attribute to a plain English name for the data, e.g. "First name". If the field is omitted, this label will be displayed in a prompt box.
function checkForm(frm)
{
  // check for required fields (any field with id="required" must be completed)
  var valid=true;
	var emailstring;
  requiredStr="Please complete the following boxes,\nthen click the Send button:\n";
  for (var i=0;i<frm.length;i++) {
    var fld=frm.elements[i];
    if ((fld.id!="") && (fld.value=="")) {
      requiredStr+="\n  - "+fld.id;
	  	valid=false;
		}
		if ((fld.name=="email_address") && (fld.value!="")){
			emailstring=fld.value;
		}
  }
  if (valid==false) 
		alert(requiredStr);
	else if (emailstring!=null) {
		if (emailCheck(emailstring)==false)
			valid=false;
		else if (MM_findObj('email')!=null)
			frm.email.value=emailstring;
	}
  return valid; 
}

function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>4) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three- or four-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//  End -->
