var SignupPage = {  
  setupSubdomainPreview: function() {
    Event.observe($('subdomain'), 'blur', this.updateAccountSubdomain.bind(this));
    Event.observe($('subdomain'), 'keyup', this.updateAccountSubdomain.bind(this));
    
    // update it the first time
    this.updateAccountSubdomain();
  },
  
  updateAccountSubdomain: function() {
    var subdomain = $F('subdomain');
    
    if (subdomain.match(/^www\./i)) {
      $('subdomain_tip').innerHTML = "URL can not start with 'www.'";
      new Effect.Shake('subdomain_tip');
    } else if (subdomain.match(/[^a-z0-9\-]/i)) {
      $('subdomain_tip').innerHTML = "URL can only contain letters, numbers, and hyphens"
      new Effect.Shake('subdomain_tip');
    }
    
    subdomain = subdomain.replace(/^www\./i, "").replace(/[^a-z0-9\-]/i,"");
    
    $('subdomain').value = subdomain;
    
    $('account_subdomain').innerHTML = "";
    
    if(subdomain.match(/^\s*$/)) {
      $('account_subdomain').innerHTML = "<i>YOURURL</i>";
    } else {
      $('account_subdomain').appendChild(document.createTextNode(subdomain));
    }
  },
  
  toggleSubmit: function(checkbox) {
    $('submit_button').disabled = !checkbox.checked;
  }
}