<!------- BEGIN

function open_window (file,width,height,toolbar) {
  // note: toolbar = yes to allow printing of pop-up window
  if (!toolbar) { toolbar = "yes"; }  
  winopt = "toolbar=" + toolbar + ",location=no,directories=no,menubar=yes,";
  winopt += "resizable=no,scrollbars=yes";
  if (width && height) { winopt += ",width=" + width + ",height=" + height; }
  newWin=window.open(file,"dummy",winopt);
}

function check_it(which,req_fields,req_fields_txt,req_email,req_email_txt,pattern_v,pattern_t,pattern_n) { 
  // which - values from form
  var ok = true; // true/false flag if pass check(s)
  if (req_fields) { required = req_fields; required_text = req_fields_txt; }
  if (req_email) { email_var = req_email; email_label = req_email_txt}
  if (pattern_v) { 
    pattern_var = pattern_v; pattern_text = pattern_t; pattern_name = pattern_n; 
  }
 
  // check required fields
  if (required.length > 0) { ok = required_fields(which); }

  // have all required fields, now check email
  if (ok && email_var.length > 0) { ok = check_email(which,form_name); } 

  // have all required fields & email, now double check patterns 
  if (ok && pattern_var.length > 0) { ok = check_patterns(which); }

  return ok;
}  

function required_fields(which) {
  // checks if all required fields are filled in
  // do not change the rest of this function
  // adapted from script by wsabstract.com posted at 
  // The JavaScript Source!! http://javascript.internet.com

  var pass = true;
  var msg = "Please make sure that entries for \n";
  var num = 0; 

  if (document.images) {
    for (i=0; i<which.length; i++) {
      var tempobj=which.elements[i]; 
      for (j = 0; j < required.length; j++) { 
        if (tempobj.name==required[j]) { 
          if (((tempobj.type=="password" ||
            tempobj.type=="text" ||
            tempobj.type=="file" ||
            tempobj.type=="hidden" ||
            tempobj.type=="textarea") && 
            tempobj.value=='') ||
            (tempobj.type.toString().charAt(0)=="s" && 
             tempobj.selectedIndex==0)) {
            pass=false;
            num += 1;
            msg += "  * " + required_text[j] + "\n";
          }
        } 
      }
    }
  }  
 
  if (!pass) {
    if (num > 1) { msg += "are entered correctly.\n"; }
    else { msg += "is entered correctly.\n"; }
    alert(msg);
    return false;
  }
  else { return true; }
}

function check_email(which) { //make sure emails are valid
  // written by Dan Jacobs
  var pass = true;
  var this_pass = true;
  var msg = "";
  var num = 0; 

  if (document.images) {
    for (i=0; i<which.length; i++) {
      var tempobj=which.elements[i];
      for (j = 0; j < email_var.length; j++) {
        if (tempobj.name == email_var[j]) { 
          this_email = tempobj.value;
          this_pass = emailCheck(this_email.toLowerCase());
          if (!this_pass) { 
            num += 1;
            //msg += "  * " + email_name + "'s email = " + this_email + "\n";
            msg += "  * " + email_label[j] + " = " + this_email + "\n";
            pass = false;
          }
        }
      } 
    } 
  }
 

  if (!pass) {
    if (num > 1) { 
      alert("The following do not appear to be valid:\n" + msg);
    }
    else { 
      alert("The following does not appear to be valid:\n" + msg);
    }
    return false;
  }
  else { return true; }
}

function emailCheck(emailStr) {
  // V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com) 
  // The JavaScript Source!! http://javascript.internet.com

  // Modified by Dan Jacobs 
  // comment out alerts - use return true/false only

  /* The following variable tells the rest of the function whether or not to
   verify that the address ends in a two-letter country   or well-known TLD. 
   1 means check it, 0 means don't. */

  var checkTLD=1;

  /* List of known TLDs that an e-mail address must end with. */

  var knownDomsPat = 
    /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

  /* The following pattern is used to check if the entered e-mail address fits the 
   user@domain format. Also used to separate the username from the domain. */

  var emailPat=/^(.+)@(.+)$/;

  /* This string represents the pattern for matching all special characters.  
   We don't want to allow special characters in the address, such as
   ( ) < > @ , ; : \ " . [ ] */

  var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

  /* The following string represents the range of characters allowed in a
   user name or domain name. 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, start 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 mold of a valid e-mail address. */
    //alert("Email address seems incorrect (check @ and .'s)");
    return false;
  }

  var user=matchArray[1];
  var domain=matchArray[2];

  // Start by checking if only basic ASCII characters are in the strings (0-127).

  for (i=0; i<user.length; i++) {
    if (user.charCodeAt(i)>127) {
      //alert("The username contains invalid characters.");  
      return false;
    }
  }
  for (i=0; i<domain.length; i++) {
    if (domain.charCodeAt(i)>127) {
      //alert("The domain name contains invalid characters.");
      return false;
    }
  }

  // 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.  Check if it's valid.
 
  var atomPat=new RegExp("^" + atom + "$");
  var domArr=domain.split(".");
  var len=domArr.length;
  for (i=0;i<len;i++) {
    if (domArr[i].search(atomPat)==-1) {
      //alert("The domain name does not seem to be valid.");
      return false;
    }
  }

  /* domain name seems valid, but now make sure that it ends in a known
   top-level domain (like com, edu, gov) or a two-letter word, representing 
   country (uk, nl), and a hostname precedes the domain or country. */

  if (checkTLD && domArr[domArr.length-1].length!=2 && 
    domArr[domArr.length-1].search(knownDomsPat)==-1) {
    //alert("The address must end in a well-known domain or two letter country.");
    return false;
  }

  // Make sure there's a host name preceding the domain.

  if (len<2) { 
    //alert("This address is missing a hostname!");
    return false;
  }

  // If we've gotten this far, everything's valid!
  return true;
}

function check_patterns(which) { // double check the patterns
  // written by Dan Jacobs
  var pass = true;
  var num = 0;
  var msg = ""; 
 
  for (var j = 0; j < pattern_var.length; j++) {
    pass = 
      pattern_check(which,pattern_var[j],pattern_text[j],pattern_name[j],'1'); 
   if (!pass) { 
      num += 1;
      msg += "  * " + pattern_text[j] + "\n";
    }
  }
 
  if (!pass) {
    var tt = "appear to be valid";
    if (num > 1) { 
      alert("The following do not " + tt + ":\n" + msg);
    }
    else { 
      alert("The following does not " + tt + ":\n" + msg);
    }
    return false;
  }
  else { return true; }
}

function pattern_check(which,this_var,this_string,pattern,this_flag) {   
  // written by Dan Jacobs 
  var this_value, this_match, this_msg, this_indx, this_num; 
  //var this_var = eval('document' + '.' + form_name + '.' + this_var + '.value');
  //this_value = eval('document' + '.' + 'paper' + '.' + this_var + '.value');
 
  for (i=0; i<which.length; i++) {
    var tempobj=which.elements[i]; 
    if (tempobj.name == this_var) { this_value = tempobj.value; }
  }
  
  if (!this_value) { return true; }
  if (!pattern) { return true; }
  if (pattern == "phone") { // xxx-xxx-xxxx
    this_match = this_value.match(/^(\d{3})\-(\d{3})\-(\d{4})$/);
    this_msg = "The pattern is xxx-xxx-xxxx, where each x is a number ";
    this_msg += "between 0-9.";  
  }
  else if (pattern == 'zipcode') { // xxxxx or xxxxx-xxxx
    this_match = this_value.match(/^(\d{5})\-(\d{4})$/);
    if (!this_match) { this_match = this_value.match(/^(\d{5})$/); } 
    this_msg = "The pattern is either xxxxx or xxxxx-xxxx, ";
    this_msg += "where each x is a number between 0-9."; 
  }
  else if (pattern == "mmyyyy") { // mm - 1-2 digit month yyyy - 4 digit year
    this_match = this_value.match(/^(\d{1,2})\/(\d{4})$/);
    if (this_match) { // check limits
      this_indx = this_value.indexOf('/');
      this_num = this_value.substring(0,this_indx) * 1;
      if (this_num > 12) { this_match = ""; }
      this_indx += 1;
      this_num = this_value.substring(this_indx,this_value.length) * 1;
      if (this_num < 1960 || this_num > 2030) { this_match = ""; }
    }
    this_msg = "The pattern is mm/yyyy, where mm is the month (01-12) ";
    this_msg += "and yyyy is the year (e.g, 2003).";
  }
  else { return true; }
 
  if (!this_match) { 
    if (this_flag) { // call from double check on submit
      return false;
    }
    else {
      alert('Please correct your ' + this_string + '.\n' + this_msg + '\n');
    }
  }
  else { return true; }
}

// checkbox/radio selection functions

function clear_radio_item(form,item) {
  // reset (turn off) radio buttons named item in form
  for (j = 0; j < eval('document.' + form + '.' + item).length; j++) {
    eval('document.' + form + '.' + item + '[' + j + '].checked = false'); 
  }
}

function save_text(form,new_text,item) {
  // form - name of the form
  // new_text - selected item from <SELECT>
  // item - text item in form to get selected item value
  var ii, str;
  ii = eval('document.' + form + '.' + new_text).selectedIndex;
  if (ii == 0) { str = ''; }
  else { 
    str = eval('document.' + form + '.' + new_text + '.options[' + ii + ']').text;   
  }
  eval('document.' + form + '.' + item).value =  str;
} 

function CheckboxChoice(form_name, prefix, all_name, flag) {
  // form_name - name of the form
  // prefix - array name
  // all_name - name of checkbox for all items
  // flag - only set if checkbox for all item
  var this_item, this_value; 
  var all_item = 'document.' + form_name + '.' + all_name;
  if (flag) { // clicked on 'all' item 
    this_value = eval('document.' + form_name + '.' + all_name).checked;
    if (this_value == true) { // selected, turn off rest of checkboxes
      for (j = 0; j < eval(prefix).length; j++) { 
        this_item = 'document.' + form_name + '.' + eval(prefix + '[' + j + ']');
        eval(this_item).checked = false;  
      } 
      eval(all_item).checked = true;
    }
  }
  else { // other checkbox selected - turn off 'all' checkbox, none - all on
    for (j = 0; j < eval(prefix).length; j++) { 
      this_item = 'document.' + form_name + '.' + eval(prefix + '[' + j + ']');
      if (eval(this_item).checked) { flag = true; }  
    } 
    if (flag) { eval(all_item).checked = false; } 
    else { eval(all_item).checked = true; }
  }
  return;
}

function set_layer_location1(n_layer,pxleft,pxtop) {  
  if (!pxleft) { pxleft = 25; }
  if (!pxtop) { pxtop = 105; }
  if (!n_layer) { n_layer = 1; }
  //if (document.all) { pxtop = 0; }
  var this_layer = "m" + n_layer; 
  var thisObj = layerRef + this_layer + layerStyle;  
  eval(thisObj).left = pxleft + pxunits; 
  eval(thisObj).top  = pxtop + pxunits; 
}

function noCR(thisEvent) {
  var key = window.event ? thisEvent.keyCode : thisEvent.which;
  var keychar = String.fromCharCode(key);
  var reg = /\r/; // key = 13 
  // reg.test is true if \r and false otherwise 
  // return the opposite of the reg.test value (true --> false, false --> true)
  return !reg.test(keychar);
}

//END----------->