$(function(){$('.add-facility-tab').click(function(event){event.preventDefault();var addFacilityForm='<div id="facility-lead-form-content" style="display:none;"><form method="post" action="'+CONFIG.baseUri+'_account/lead/"  ><h2>Add Your Facility</h2><p>Start driving more tenants to your facility. Add your storage company today and get seen by millions of self-storage shoppers each month.</p><p>Getting started is easy:</p><div class="error"></div><p><label>First Name </label><br /><input type="text" name="first_name" id="facility-lead-first-name" value=""></p><p><label>Last Name </label><br /><input type="text" name="last_name" value=""></p><p><label>Company </label><br /><input type="text" name="company" value=""></p><p><label>Email Address </label><br /><input type="text" name="email" value=""></p><p><label>Phone Number </label><br /><input type="text" name="phone" value=""></p><input type="submit" id="facility-lead-submit" class="green-button submit" value="Next &raquo;" /></form></div>';$('body').append(addFacilityForm);jQuery.facebox({div:'#facility-lead-form-content',loadingImage:CONFIG.baseUri+'images/global/facebox/loading.gif',closeImage:CONFIG.baseUri+'images/global/facebox/closelabel.png'});_gaq.push(['_trackEvent','Add Your Facility Tab','Click']);});$(document).bind('reveal.facebox',function(){$('#facebox form').submit(function(event){event.preventDefault();saveFacilityLead();});});});function saveFacilityLead(){var firstName=$('#facebox input[name$="first_name"]').val();var lastName=$('#facebox input[name$="last_name"]').val();var company=$('#facebox input[name$="company"]').val();var email=$('#facebox input[name$="email"]').val();var phone=$('#facebox input[name$="phone"]').val();$.ajax({type:"POST",url:basePath+"_account/lead/",data:{firstName:firstName,lastName:lastName,company:company,email:email,phone:phone},beforeSend:function(){$("#facebox #facility-lead-submit").replaceWith('<div id="facility-lead-submit"><img src="'+CONFIG.baseUri+'images/global/loaders/large.gif" /></div>');},success:function(msg){if(msg.match(/^\s*Error/)){$("#facebox #facility-lead-submit").replaceWith('<input id="facility-lead-submit" type="submit" value="Contact Us" class="green-button">');$('#facebox .error').html(msg);$('#facebox form').submit(function(event){event.preventDefault();saveFacilityLead();});}else{alert("Thanks. We'll get back to you in a jiffy!");_gaq.push(['_trackEvent','Add Your Facility Tab','Submission']);location.reload(true);}},error:function(xhr,ajaxOptions,thrownError){$("#facebox #facility-lead-form-content").html('There was an error contacting us. Please try again later.');}});}
