window.onload = function () {
  signup_page = new signup();
  signup_page.build();
}

function signup(){ 
  
  var thisobj = this;
  
  if (typeof signup._initialized == "undefined") {
    
     signup.prototype.build = function () {
       if (document.getElementById("submitted")){
         //document.getElementById("signup_sub").style.display = "none";
         //document.getElementById("captcha").style.display = "block";
       }
       this.set_form_fields();
     }
    
     
      /* 
       Set the Form Field Input Vars
     */
     signup.prototype.set_form_fields = function () {
        this.email     = document.getElementById("b4m_email");
        this.pass      = document.getElementById("b4m_pass");
        this.month     = document.getElementById("b4m_month");
        this.day       = document.getElementById("b4m_day");
        this.year      = document.getElementById("b4m_year");
        this.addy      = document.getElementById("addy");
     }
     
     
     /* 
       Check the Form Field Inputs
     */
     signup.prototype.signup_button = function () {
       //document.getElementById("signup_sub").disabled = true;
       this.focus_set = false;
       this.passed    = true;
       //run checks
       this.check_email();
       if (this.passed) this.check_pass();
       if (this.passed) this.check_birthday();
       if (this.passed) this.check_addy();
       //process check results
       if (this.passed){ 
         
         document.getElementById("signup_form").submit();
       } else { 
         this.error_tip = new YAHOO.widget.Overlay("error_tip", { 
                                                  context:[this.error_div,"tl","bl"], visible:false, width:"220px", zIndex:500 } 
                                                  );
         this.error_tip.setBody("<div class='error_message'>"+this.error_message+"</div>"); 
         this.error_tip.render(document.body); 
         this.error_tip.show();
         YAHOO.util.Event.addListener(this.error_div, "keypress", this.hide_error, this, true);
         YAHOO.util.Event.addListener(this.error_div, "blur", this.hide_error, this, true);
       }
       //document.getElementById("signup_sub").disabled = false;
     }
       
     
     
     
     /* 
       Check the Email Input
     */
     signup.prototype.check_email = function () {
       var isValidEmail = function(sText) { 
          var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
          return reEmail.test(sText);  
       };
       ////////////////////////////////////////////////// 
       if (this.email.value.length > 0){
         if (!isValidEmail(this.email.value)) {
           this.error_message = "Please enter a valid email address.";
           this.error_div     = "b4m_email";
           if(!this.focus_set) { this.email.focus(); this.focus_set = true; }
           this.passed = false;
         } 
       }else{  
         this.error_message = "Please enter your email address.";
         this.error_div     = "b4m_email";
         if(!this.focus_set) { this.email.focus(); this.focus_set = true; }
         this.passed = false;
       }
     }
     
     
     /* 
       Check the Password Input
     */
     signup.prototype.check_pass = function () {
       var isValidPass = function(sText, type) {
          if (type == "alpha"){
            var rePass =  /^[a-zA-Z]*$/;
          }else{
            var rePass =  /^[0-9]*$/;
          }
          return rePass.test(sText);  
       };
       //////////////////////////////////////////////////   
       if (this.pass.value.length > 0){
         if (this.pass.value.length < 6){
           this.error_message = "Please enter a password between 6 and 20 characters in length.";
           this.error_div     = "b4m_pass";
           if(!this.focus_set) { this.pass.focus(); this.focus_set = true; }
           this.passed = false;
         }else{
           if (isValidPass(this.pass.value, 'alpha')) {
             this.error_message = "Your password must contain at least one number.";
             this.error_div     = "b4m_pass";
             if(!this.focus_set) { this.pass.focus(); this.focus_set = true; }
             this.passed = false;
           } else if (isValidPass(this.pass.value, 'num')) {
             this.error_message = "Your password must contain at least one letter.";
             this.error_div     = "b4m_pass";
             if(!this.focus_set) { this.pass.focus(); this.focus_set = true; }
             this.passed = false;
           } 
         }
       }else{
         this.error_message = "Please enter a password.";
         this.error_div     = "b4m_pass";
         if(!this.focus_set) { this.pass.focus(); this.focus_set = true; }
         this.passed = false;
       }
     }
     
     
      /* 
       Check the Full Name Input
     */
     signup.prototype.check_addy = function () {
       if (this.addy.value.length == 0){
         this.error_message = "Please enter a web address.";
         this.error_div     = "addy";
         this.addy.focus(); this.focus_set = true;
         this.passed = false;
       }
     }
     
      
     /* 
       Check the Birthday Input
     */
     signup.prototype.check_birthday = function () {
       if (this.day.value == -1 || this.month.value == -1 || this.year.value == -1 ){
         this.error_message = "Please enter your birthday.";
         this.error_div     = "b4m_month";
         if(!this.focus_set) { this.month.focus(); this.focus_set = true; }
         this.passed = false;
       }
     }
     
     
     /* 
       Hide the error tip
     */
     signup.prototype.hide_error = function () {
       YAHOO.util.Event.removeListener(this.error_div, "keypress", this.hide_error);
       YAHOO.util.Event.removeListener(this.error_div, "blur", this.hide_error);
       this.error_tip.hide();
     } 
     
     
     signup._initialized = true;
  } 
}








var cleared  = false; 
function clearInput(){
  if (!cleared){
    document.getElementById("v_in").value = "";
    document.getElementById("v_in").maxLength = 4;
    cleared = true;
  }
} 