
var FormHelper={showExtra:function(id){FormHelper.hideExtra();$('.extra[for='+id+']').fadeIn(250);},hideExtra:function(){$('.extra').hide();},validate:function(formSelector){$('label.error').remove();var formValid=true;$(formSelector+' input').each(function(){if($(this).is(':visible')){var valid=FormHelper.isValid(this);if(!valid){formValid=false;FormHelper.displayError(this);}}});$(formSelector+' textarea').each(function(){if($(this).is(':visible')){var valid=FormHelper.isValid(this);if(!valid){formValid=false;FormHelper.displayError(this);}}});return formValid;},isValid:function(element){if($(element).attr('required')!==undefined){if($(element).val()===''){return false;}
if($(element).attr('type')=='email'||($(element).attr('type')=='text'&&$(element).hasClass('type-email'))){return FormHelper.isValidUrl($(element).val());}
if($(element).attr('type')=='url'||($(element).attr('type')=='text'&&$(element).hasClass('type-url'))){return FormHelper.isValidUrl($(element).val());}}else{if($(element).val()!==''){if($(element).attr('type')=='email'||($(element).attr('type')=='text'&&$(element).hasClass('type-email'))){return FormHelper.isValidUrl($(element).val());}
if($(element).attr('type')=='url'||($(element).attr('type')=='text'&&$(element).hasClass('type-url'))){return FormHelper.isValidUrl($(element).val());}}}
return true;},isValidUrl:function(url){var regex=/(((http|https):\/\/)?([a-z0-9]+)(([\-\.]{1})[a-z0-9]+)*\.[a-z]{2,5}((:[0-9]{1,5})?\/?))([\w\d\/.\%]+)?((\?)?([\.?#=&]?[\w\/\-])*)?/i;return regex.test(jQuery.trim(url));},isValidEmail:function(email){var regex=/^[A-Z0-9\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\.\{\|\}\~]{1,64}@(?:[A-Z0-9\-]{1,63}\.){1,}[A-Z0-9]{2,6}$/i;return regex.test(jQuery.trim(email));},displayError:function(element){$(element).after('<label for="'+$(element).attr('id')+'" class="error" title="Incomplete or invalid field">Incomplete or invalid field</label>');}};$('input').focus(function(){FormHelper.showExtra($(this).attr('id'));});$('textarea').focus(function(){FormHelper.showExtra($(this).attr('id'));});$('select').focus(function(){FormHelper.showExtra($(this).attr('id'));});$('div.input').focus(function(){FormHelper.showExtra($(this).attr('id').replace(/form-/,''));});$('input').blur(function(){FormHelper.hideExtra();});$('textarea').blur(function(){FormHelper.hideExtra();});$('select').blur(function(){FormHelper.hideExtra();});$('div.input').blur(function(){FormHelper.hideExtra();});$('form').submit(function(){return FormHelper.validate('form');});$(document).ready(function(){if($('#hire-me').length>0&&$('#talk-to-me').length>0){$('#hire-me').click(function(){$('#hire-me').addClass('current');$('#talk-to-me').removeClass('current');$('#form-message label.primary').html('Description<span class="required"> (required)</span>');$('#form-subject').fadeOut(100);$('#form-url').slideDown(250);$('#form-company').slideDown(250);$('#form-timeframe').slideDown(250);$('#form-budget').slideDown(250);$('legend').html('Oh, this is exciting—I love making web sites. Tell me more about it!');$('.contact-form').attr('action',$('.contact-form').attr('action')+'/hire-me');return false;});$('#talk-to-me').click(function(){$('#talk-to-me').addClass('current');$('#hire-me').removeClass('current');$('#form-message label.primary').html('Message<span class="required"> (required)</span>');$('#form-subject').fadeIn(100);$('#form-url').slideUp(250);$('#form-company').slideUp(250);$('#form-timeframe').slideUp(250);$('#form-budget').slideUp(250);$('legend').html('I’d love to hear from you, so just type away!');$('.contact-form').attr('action',$('.contact-form').attr('action').replace(/\/hire-me/,''));return false;});}});