function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
        result = true;
  }
  return result;
}

function validate_form() {
 var val=true;
 var str="";
 var str1="";
 if (check_equal(document.order_form.pw1.value, document.order_form.pw2.value)==false) {
  str+="- The password and confirmation are not the same.\n";
 }
 var pw1= document.order_form.pw1.value;
 if (pw1.indexOf(" ")>=0) {
  str+="- No spaces in the password.\n";
 }
 if ((pw1.length<4) || (pw1.length>12)) {
  str+="- Password length should be between 4-12 characters long.\n";
 }
 var user= document.order_form.username.value;
 if (user.indexOf(" ")>=0) {
  str+="- No spaces in the username.\n";
 }
 if ((user.length<4) && (user.length>12)) {
  str+="- Username length should be between 4-12 characters long.\n";
 }
 if (check_equal(document.order_form.email.value, document.order_form.confemail.value)==false) {
  str+="- The email and confirmation are not the same.\n";
 }
 if (isEmailAddr(document.order_form.email.value)==false) {
  str+="- You have not supplied a valid email address.\n";
 }
 str1 = check_required();
 if ((str.length >0) || (str1.length >0)) {
  str1+="\n"+str;
  alert(str1);
  return false; }
}

function check_equal(text1, text2)  {
     var valid=true;
     if (text1!=text2) {
         valid=false;
     }
     return valid;
}

function check_required() {
  var str="You have forgotten to fill out:\n";
  validity = true; // assume valid
  if (!check_empty(document.order_form.username.value))
        { validity = false;
        str+="  - Username\n"; }
  if (!check_empty(document.order_form.pw1.value))
        { validity = false;
        str+="  - Password\n";  }
  if (!check_empty(document.order_form.pw2.value))
        { validity = false;
        str+="  - Password Confirmation\n"; }
  if (!check_empty(document.order_form.name.value))
        { validity = false;
        str+="  - Name\n";  }
  if (!check_empty(document.order_form.email.value))
        { validity = false;
        str+="  - Email Address\n";  }
  if (!check_empty(document.order_form.confemail.value))
        { validity = false;
        str+="  - Email Confirmation\n";   }
  if (!check_empty(document.order_form.reminder.value))
        { validity = false;
        str+="  - Reminder Question\n";   }
  if (!check_empty(document.order_form.reminder_answer.value))
        { validity = false;
        str+="  - Reminder Answer\n";   }
 if (validity)
  return "";
 else {
  return str; }
}
function check_length(text, length) {
  if (text.length >= length) return true;
  return false;
}
function check_empty(text) {
  return (text.length > 0);
}