function validateEmailv2(email)
{
	var message = "Enter a valid email address"
    if(email.length <= 0)
	{
	  return message;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return message;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return message;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return message;
      }// if
	  message = "good"
      return message;
    }
return message;
}


//---------------
function passwordcheck(password) 
{ 
 var message = "The password must be between 5-10 characters and can only have numbers, letters, _ or -"

 if(password.length <5 || password.length >10)
	{
		return message;
	}
             var charpos = password.search("[^A-Za-z0-9\-_]"); 
              if(password.length > 0 &&  charpos >= 0) 
              { 
                 return message;
			  }
           		

    message = "good"
      return message;
}
//=============================

function WriteLayer(ID,parentID,sText) {
 if (document.layers) {
   var oLayer;
   if(parentID){
     oLayer = eval('document.' + parentID + '.document.' + ID + '.document');
   }else{
     oLayer = document.layers[ID].document;
   }
   oLayer.open();
   oLayer.write(sText);
   oLayer.close();
 }
 else if (parseInt(navigator.appVersion)>=5&&navigator.
appName=="Netscape") {
   document.getElementById(ID).innerHTML = sText;
 }
 else if (document.all) document.all[ID].innerHTML = sText
}
//=================================
function Validate()
{
	var isgood="yes"
	var email_chk = validateEmailv2(document.account_form.EMAIL.value);    
	var password_chk = passwordcheck(document.account_form.PASSWORD.value);

   //find out if this is a new or returning customer
   if (document.account_form.IS_NEW[0].checked)
   {
     if(password_chk !="good")
	    {
		  isgood="no"
	      WriteLayer('password_message',null,password_chk);
	    }

		document.account_form.do_what.value="login"
		document.account_form.action="account.php"
		
   }

   else
	   {
	   document.account_form.action="register.php"
	   }

	if(email_chk !="good")
	{
		isgood="no"
        WriteLayer('email_message',null,email_chk);
	}

	if(isgood=="yes")
	{
	  document.account_form.submit();
	}

}

function logout_User()
{
  document.account_form.do_what.value="logout"
  document.account_form.action="account.php"
  document.account_form.submit();
}

//======================================
//============================
function Pass_Req_Validate()
{
	var isgood="yes"
	var email_chk = validateEmailv2(document.account_form.EMAIL.value);    

	if(email_chk !="good")
	{
		isgood="no"
        WriteLayer('email_message',null,email_chk);
	}

	if(isgood=="yes")
	{
	  document.account_form.submit();
	}

}
//------------------
function Validate_Password()
{
	var isgood="yes"    
	var password_chk = passwordcheck(document.account_form.PASSWORD.value);


     if(password_chk !="good")
	 {
		  isgood="no"
	      WriteLayer('password_message',null,password_chk);
	 }

	else
	{
		document.account_form.do_what.value="login"
		document.account_form.submit();
	}

}

function goPassword()
{
	document.account_form.do_what.value="request_password"
    document.account_form.submit();
}

function go()
{
	document.account_form.submit();
}

//-----------------CHANGE PASSWORD FUNCTIONS
function cPassword_Validate()
{

	var isgood="yes"
	var curr_password_chk = passwordcheck(document.account_form.CURRENT_PASSWORD.value);
	var new_password_chk = passwordcheck(document.account_form.PASSWORD.value);
    
   //validate the length and type of the passwords entered
     if(curr_password_chk !="good")
	 {
	  isgood="no"
	  WriteLayer('currpassword_error',null,curr_password_chk);
	 }
	 else{WriteLayer('currpassword_error',null,'');}

	if(new_password_chk !="good")
	{
	 isgood="no"
	 WriteLayer('newpassword_error',null,new_password_chk);
	}
	else{WriteLayer('newpassword_error',null,'');}

	if(document.account_form.PASSWORD.value != document.account_form.PASSWORD_CONFIRM.value)
	{
	 isgood="no"
	 WriteLayer('passwordconfirm_error',null,'Your new password does not match your retyped password. Check and try again.');
	}


	if(isgood=="yes")
	{ 
	  document.account_form.submit();
	}

}

//this function will validate the form (post launch)
//and submit the form to be updates
function saveProfile()
{
   document.account_form.do_what.value="save_profile"
   document.account_form.submit();
}

//---------------------------------------------------------------------
function registerValidate()
{
	var isgood="yes"
	var email_chk = validateEmailv2(document.account_form.EMAIL.value);    
	var password_chk = passwordcheck(document.account_form.PASSWORD.value);
    var theform = document.account_form;

    //check first name
    if(document.account_form.FIRST_NAME.value.length <=0 || document.account_form.FIRST_NAME.value.length >=30)
	{
      isgood="no"
	  WriteLayer('fname_error',null,'Enter in a first name (30 characters max)');
	}
	else{WriteLayer('fname_error',null,'');}

    //check last name
	if(document.account_form.LAST_NAME.value.length <=0 || document.account_form.LAST_NAME.value.length >=30)
	{
      isgood="no"
	  WriteLayer('lname_error',null,'Enter in a last name (30 characters max)');
	}
	else{WriteLayer('lname_error',null,'');}

    //check email
	if(email_chk !="good")
	{
		isgood="no"
        WriteLayer('email_error',null,email_chk);
	}
	else{WriteLayer('email_error',null,'');}

    if(document.account_form.EMAIL.value != document.account_form.EMAIL_CONFIRM.value)
	{
		isgood="no"
        WriteLayer('emailconfirm_error',null,'This address must be the same as your email address');
	}
    else{WriteLayer('emailconfirm_error',null,'');}

    //check password
    if(password_chk !="good")
	    {
		  isgood="no"
	      WriteLayer('password_error',null,password_chk);
	    }
    else{WriteLayer('password_error',null,'');}

    if(document.account_form.PASSWORD.value != document.account_form.PASSWORD_CONFIRM.value)
	{
		isgood="no"
        WriteLayer('passwordconfirm_error',null,'The passwords do not match');
	}
    else{WriteLayer('passwordconfirm_error',null,'');}

	if(isgood=="yes")
	{
	 document.account_form.submit();
	}

}