function submitForm() { //load values org_type=$("#organization_type").val(); username=$("#username").val(); username_valid=$("#username_valid").val(); password=$("#password").val(); email=$("#email").val(); referral_affiliate_id=$("#referral_affiliate_id").val(); company=$("#company").val(); fname=$("#fname").val(); lname=$("#lname").val(); website=$("#website").val(); agreement=$("#agreement").is(':checked'); //validate values error=validateValues( org_type, username, username_valid, password, email, company, fname, lname, website, referral_affiliate_id, agreement ); if (error==null) { //submit post $.post("/publishers/submit",{ org_type: org_type, username: username, password: password, email: email, referral_affiliate_id: referral_affiliate_id, company: company, fname: fname, lname: lname, website: website },function(data) { $("#application_form").html(data); }); } else { //display error on page $("#error_message").remove(); //$("#application_description").hide(); $("#inset").html("
"+error+"
"); return false; } } function org_switch () { if ($("#organization_type").val()!='Company') { $("#company_input").hide(); } else { $("#company_input").show(); } } function validateValues(org_type,username,username_valid,password,email,company,fname,lname,website,referral_affiliate_id,agreement) { error=''; if (org_type=='') { error+='
  • Organization Type is required.
  • '; } if (username=='') { error+='
  • Username is required.
  • '; } if (username!='' && username_valid=='false') { error+='
  • Please choose a different username.
  • '; } if (password=='') { error+='
  • Password is required.
  • '; } if (email=='') { error+='
  • Email is required.
  • '; } if (org_type=='Company' && company=='') { error+='
  • Company is required.
  • '; } if (fname=='') { error+='
  • First Name is required.
  • '; } if (lname=='') { error+='
  • Last Name is required.
  • '; } if (website=='') { error+='
  • Website is required.
  • '; } if (agreement!=true) { error+='
  • You must read and agree to the Publisher Agreement terms.
  • '; } if (error!='') { error = "

    Whoops!

    "; } else { error=null; } return error; } function searchUsernames() { $('#username_availability').load('/publishers/username_check_ajax/'+$('#username').val()); if ($('#username_availability').html()) { //set username_valid to false $("#username_valid").val('false'); } else { //set username_valid to true $("#username_valid").val('true'); } } $(document).ready(function() { $('#organization_type').change(function() {org_switch();}); $("#send").click(function() { submitForm(); return false; }); $("#username").keyup(function () { if (undefined===window.timerid) { } else { window.clearTimeout(timerid); } timerid = window.setTimeout('searchUsernames()', 800); }); });