//JQUERY - ADD POPUP METHOD
$(function(){
  $('.popWindow').click(function(){
   relPieces=this.rel.split(',');
   parameters = "width=650, height=700, scrollbars=yes";
   switch(relPieces[0]){
    case 'tall':
      parameters = 'width=410, height=600, scrollbars=yes';
    break;
    
    case 'short':
      parameters = 'width=410, height=300, scrollbars=yes';
    break;

    case 'contact':
      parameters = 'width=650, height=700, scrollbars=yes';
    break;
    
    case 'wide':
      parameters = 'width=850, height=700, scrollbars=yes, menubar=0, status=0, left = 0,top = 0';
    break;
    
    case 'seals':
      parameters = 'width=590, height=440, scrollbars=yes, menubar=0, status=0, left = 0,top = 0';
    break;
   }
   newWindow=window.open(this.href, this.rel, parameters).focus();
   //newWindow.moveTo(0, 0);
   return false;
  });
});

//CHARACTER REPLACE FUNCTION
function replaceChars(value, filter){
  switch(filter){
    case 'numbersOnly':
      re = /\$|,|@|[a-z]|\>|\s|\<|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\_|\]|\[|\}|\{|\;|\:|\.|\'|\"|\<|\>|\?|\/|\||\\|\!|\$/g;
    break;
    
    case 'alphanumNoWhite':
      re = /\$|,|@|\>|\s|\<|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\_|\]|\[|\}|\{|\;|\:|\.|\'|\"|\<|\>|\?|\/|\||\\|\!|\$/g;
    break;
    
    case 'alphanum':
      re = /\$|,|@|\>|\<|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\_|\]|\[|\}|\{|\;|\:|\.|\'|\"|\<|\>|\?|\/|\||\\|\!|\$/g;
    break;

    case 'alpha':
      re = /\$|,|[0-9]|@|\>|\<|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\/|\||\\|\!|\$/g;
    break;

    case 'email':
      re = /\$|,|\>|\<|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\/|\||\\|\!|\$/g;
    break;

    default:
      alert('no filter defined');
    break;
  }
  value=value.replace(re, '');
  return value;
}

 $(document).ready(function(){
      $("#signupForm").validate({
        rules:{
          username:{ minlength: 5, required: true },
          password:{ minlength: 8, required: true },
          email:{ required: true, email: true }          
        }

      });

      $("input[type=text]:not(#email)").blur(function(){
        this.value=replaceChars(this.value, 'alphanumNoWhite');
      });
      $("#email").blur(function(){
        this.value=replaceChars(this.value, 'email');
      });
});

