function Help(daLink)
  {
  var helpWnd=window.open(daLink,"help","width=400,height=500,scrollbars=yes,dependent=yes");
  }

function isEmail(string)
  {
  if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    return true;
  else
    return false;
  }

function isProper(string, allowspace)
  {
  if (allowspace)
    {
//    if (string.search(/^\w+( \w+)?$/) != -1) // allow only one space character.
    if (string.search(/^(\w+( |-)?\w+)*$/) != -1)
      return true;
    }
  else
    {
    if (string.search(/^\w+$/) != -1)
      return true;
    }
  return false;
  }

function isValidUserid(userid)
  {
  if(userid.length == 0)
    {
    alert("You must choose a user Id.");
    document.NCRegister.userid.focus()
    document.NCRegister.userid.select()
    return false;
    }

  if(userid.length > 32 || userid.length < 6)
    {
    alert("Your userid must be between 6 and 30 characters.");
    document.NCRegister.userid.focus()
    document.NCRegister.userid.select()
    return false;
    }
  if (isProper(userid, false) == false)
    {
    alert("Please enter a valid username.  User Id's can contain only alphanumeric characters and the underscore.");
    document.NCRegister.userid.focus();
    document.NCRegister.userid.select();
    return false;
    }
  return true;
  }

function isValidPasswd(pw, userid, fn, ln, pwqa_a)
  {
  if(pw.length == 0)
    {
    alert("Please choose a password.");
    document.NCRegister.passwd.focus()
    document.NCRegister.passwd.select()
    return false;
    }
  else if (pw.length > 32)
    {
    alert("Your new password must be no greater than 32 characters.");
    document.NCRegister.passwd.focus()
    document.NCRegister.passwd.select()
    return false;
    }
  else if (pw.length < 8)
    {
    alert("Your new password must be at least 8 characters.");
    document.NCRegister.passwd.focus()
    document.NCRegister.passwd.select()
    return false;
    }
  else if (userid.length != 0 && (userid.indexOf(pw) >= 0 || pw.indexOf(userid) >= 0))
    {
    alert("Your new password is too similar to your User ID.");
    document.NCRegister.passwd.focus()
    document.NCRegister.passwd.select()
    return false;
    }
  else if ((fn.length > 2) && (pw.indexOf(fn) >= 0) )
    {
    alert("Your new password is too similar to your first name.");
    document.NCRegister.passwd.focus()
    document.NCRegister.passwd.select()
    return false;
    }
  else if ( (ln.length > 2) && (pw.indexOf(ln) >=0) )
    {
    alert("Your new password is too similar to your last name.");
    document.NCRegister.passwd.focus()
    document.NCRegister.passwd.select()
    return false;
    }
  else if ( pwqa_a == pw )
    {
    alert("Your Security Answer is too similar to your password. Please choose a different answer for your Security Question.");
    document.NCRegister.passwd.focus()
    document.NCRegister.passwd.select()
    return false;
    }
  else
    {
    return true;
    }
  }

function lyear(a)
  {
  if(((a % 4 == 0) && (a % 100 != 0)) || (a % 400 == 0))
    return true;
  else
    return false;
  }

function DateValid(bmon, bday, byear)
  {
  // check month
  if (bmon == "" || bmon < 1 || bmon > 12)
    {
    alert ("Please enter a valid Birth Date.");
    return false;
    }

  // check days
  if (bday == "" || bday < 1)
    {
    alert ("Please enter a valid Birth Date.");
    return false;
    }

  if (bmon == 2) // february
    {
    if ((bday > 29) || (bday == 29 && !lyear(byear)))
      {
      alert ("Please enter a valid Birth Date.");
      return false;
      }
    }

  if (bmon == 1 || bmon == 3 || bmon == 5 || bmon == 7 || bmon == 8 || bmon == 10 || bmon == 12)   
    {
    if (bday > 31)
      {
      alert ("Please enter a valid Birth Date.");
      return false;
      }
    }
  if (bmon == 4 || bmon == 6 || bmon == 9 || bmon == 11)   
    {
    if (bday > 30)
      {
      alert ("Please enter a valid Birth Date.");
      return false;
      }
    }

  // check year
  if (byear == "" || byear < 1900 || byear > 2040)
    {
    alert ("Please enter a valid Birth Date.");
    return false;
    }

// entered fields validated, now is user at least 13.
  days   = new Date();
  gdate  = days.getDate();
  gmonth = days.getMonth()+1;
  gyear  = days.getYear();

  if (gyear < 2000) gyear += 1900;
  age = gyear - byear;
  if(bmon > gmonth)
    {
    age = age - 1;
    }
  if ((bmon == gmonth) && (bday > parseInt(gdate)))
    {
    age = age -1;
    }
  if (age < 13)
    {
    alert ("You must be at least 13 years old to register an account.  Entering misleading information is a violation of the terms of use agreement and can lead to revokation of the account.");
    return false;
    }
  return true;
  }


function hash(form)
  {
  // rudimentary check for a 4.x brower. should catch IE4+ and NS4.*
  // netscape BSD does not allow JS to change pw field.
//  if (navigator.userAgent.indexOf('Mozilla/4')==0 &&
//     (navigator.userAgent.indexOf('X11') < 0))
//    {
  var pw = form['passwd'].value;
  var pwconf = form['pwconf'].value;
  var fn = "";
  var ln = "";
  var userid = "";
  var pwqa_a = "";
  if(isValidUserid(form.userid.value))
    {
    userid = form.userid.value;
    }
  else
    {
    return false;
    }

  if(pw != pwconf)
    {
    alert("Your password entries did not match.");
    document.NCRegister.passwd.focus()
    document.NCRegister.passwd.select()
    return false;
    }

  if(isValidPasswd(pw, userid, fn, ln, pwqa_a) == false)
    { 
    return false;
    }
  // check security checks.
  // check security question.
  if ( form['sec_question'].value == "" )
    {
    alert('Please select a Security Question.');
    document.NCRegister.sec_question.focus()
    return false;
    }

  if ( form.sec_answer.value.length == 0 )
    {
    alert('Please enter an answer for the selected Security Question.');
    document.NCRegister.sec_answer.focus()
    document.NCRegister.sec_answer.select()
    return false;
    }

  if ( isProper(form['sec_answer'].value, true ) == false)
    {
    alert('Please re-enter a security answer.  Answers can only use alphanumeric characters, spaces, or the underscore.');
    document.NCRegister.sec_answer.focus()
    document.NCRegister.sec_answer.select()
    return false;
    }
  if(form['sec_answer'])
    {
    pwqa_a = form['sec_answer'].value;
    }

  form.action = 'https://secure.netcove.net/registration.asp';

  // check b-day
  if (DateValid(form['bdaymon'].value, form['bdayday'].value, form['bdayyear'].value) == false)
    {
    document.NCRegister.bdaymon.focus()
    return false;
    }

  // check email
  if (isEmail(form.email.value) == false)
    {
    alert("Please enter a valid Email address.");
    document.NCRegister.email.focus()
    document.NCRegister.email.select()
    return false;
    }

  // check optional info: name, address, city, state, zip, and phone
  // just check these for valid characters.
  if(form['fname'])
    {
    fn = form['fname'].value;
    }
  if(form['lname'])
    {
    ln = form['lname'].value;
    }

  if ( isProper(form['city'].value, true ) == false)
    {
    alert('Please re-enter a city name.  City names can only use alphanumeric characters.');
    document.NCRegister.sec_answer.focus()
    document.NCRegister.sec_answer.select()
    return false;
    }
  if (form['zip'].value)
    {
    zlen = form['zip'].value.length;
    if (zlen >= 5 && zlen < 9)
      {
      if (form['zip'].value.search(/^\d\d\d\d\d$/) == -1)
        {
        alert("Please enter a 5 or 9 digit (zip + 4) zip code.")
        document.NCRegister.zip.focus()
        document.NCRegister.zip.select()
        return false;
        }
      }
    if (zlen == 9 || zlen == 10)
      {
      if (form['zip'].value.search(/^\d\d\d\d\d( |-)?\d\d\d\d$/) == -1)
        {
        alert("Please enter a 5 or 9 digit (zip + 4) zip code.")
        document.NCRegister.zip.focus()
        document.NCRegister.zip.select()
        return false;
        }
     if (zlen < 5 || zlen > 10)
        {
        alert("Please enter a 5 or 9 digit (zip + 4) zip code.  A space or hyphen are allowed after the 5th digit.")
        document.NCRegister.zip.focus()
        document.NCRegister.zip.select()
        return false;
        }
      }
    }
  if ( form['phone'].value)
    {
    // first check general format of string.
    if (form['phone'].value.search(/^(\()?(\d\d\d)(\))?( |-|.)?(\d\d\d)( |-|.)?(\d\d\d\d)$/) == -1)
      {
      alert("Please enter a 10 digit (area code + 7 digit) phone number.")
      document.NCRegister.phone.focus()
      document.NCRegister.phone.select()
      return false;
      }
    // now make sure we have the correct number of digits.
    plen = 0;
    for (i = 0; i < form['phone'].value.length; i=i+1)
      {
      c = form['phone'].value.charAt(i);
      if (c.search(/^\d$/) != -1)
        {
        plen=plen+1;
        }
      }
    if (plen != 10)
      {
      alert("Please enter a 10 digit (area code + 7 digit) phone number.")
      document.NCRegister.phone.focus()
      document.NCRegister.phone.select()
      return false;
      }
    }

  // prevent from running this again. Allow the server 
  // response to submit the form directly
  form.onsubmit = null;

  // after all values have been verified, hash password before sending.
  var pwHash = pw;
  pwHash = hex_md5(pw);
  if(form['passwd'] && form['passwd'].type != 'hidden')
    {
    form['passwd'].value = pwHash;
    } 
  if(form['pwconf'] && form['pwconf'].type != 'hidden')
    {
    form['pwconf'].value = pwHash;
    } 

  md5_string = form['userid'].value + pwHash + form['sec_question'].value + form['sec_answer'].value + form['zip'].value
  md5_string = md5_string + form['fname'].value + form['lname'].value + form['city'].value + form['email'].value + form['address'].value + form['address2'].value
  md5_string = md5_string + form['bdaymon'].value + form['bdayday'].value + form['bdayyear'].value + form['phone'].value
  form['MD5_Form'].value = hex_md5(md5_string);
  return true;
  }
