
window.addEvent('domready', function() {
  $('content').addClass('headlinebanner');
  
  // Setup the simple "Visit" boxes:
  ['pd_form', 'ac_form', 'efc_form'].each(function(el,idx) {
    $(el).link.value = $(el).default_link.value;
    $(el).link.onclick = function() {
      this.focus();
      this.select();
    };
    
    $(el).visit.onclick = function() {
      $('visitorform').action = this.form.link.value;
      window.setTimeout(function() {
        $('visitorform').submit();
      }, 50);
    };
  });
  
  // Setup the actual generator form:
  $('generator_form').onsubmit = function() {
    if( this.cbid.value.trim() == "" )
    {
      alert("ClickBank ID is required.");
      this.cbid.focus();
      return false;
    }// end if()
    
    if( this.cbid.value.trim().length < 5 || this.cbid.value.trim().length > 10 )
    {
      alert("ClickBank ID must be between 5 and 10 characters long.");
      this.cbid.focus();
      return false;
    }// end if()
    
    // Tracking id is optional - so we don't validate it.
    var argstr = "";
    var cbid = this.cbid.value.trim();
    if( this.tid.value.trim() != "" )
      argstr = "&tid=" + this.tid.value.trim();
    
    // Fill in the text boxes with the new URLS:
    ['pd_form', 'ac_form', 'efc_form'].each(function(el,idx) {
      $(el).link.value = $(el).default_link.value.replace("nickname", cbid ) + argstr;
    });
  
    // Finally:
    return false;
  };
});



