
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');});var CommentFormHelper={previewVisible:false,preview:function(){if(FormHelper.isValidUrl($('#url').val())){var url=jQuery.trim($('#url').val());if(url.substr(0,7)!=='http://'){url='http://'+url;}
$('.comment-preview cite').html('<a href="'+url+'" class="no-mark-extenral" rel="nofollow external">'+$('#name').val()+'</a>&nbsp;');}else{$('.comment-preview cite').html($('#name').val()+'&nbsp;');}
$('.comment-preview .comment-content').html($('#comment').val().replace(/\n/g,'<br>').replace(/\r/g,''));},togglePreview:function(){if(CommentFormHelper.previewVisible){$('.comment-preview').slideUp();CommentFormHelper.previewVisible=false;$('#preview-button').html('&nbsp;Show Preview&nbsp;');}else{$('.comment-preview').slideDown();CommentFormHelper.previewVisible=true;$('#preview-button').html('&nbsp;Hide Preview&nbsp;');}}};$(document).ready(function(){$('#comment-form #name').keyup(function(){CommentFormHelper.preview();});$('#comment-form #url').keyup(function(){CommentFormHelper.preview();});$('#comment-form textarea').keyup(function(){CommentFormHelper.preview();});$('#preview-button').click(function(){CommentFormHelper.togglePreview();});});