jQuery(document).ready(function($) { /*===================================================================================*/ /* Contact Form /*===================================================================================*/ //email validation function function isValidEmailAddress(emailAddress) { var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i); return test(emailAddress); } jQuery('#message-submit').click(function () { var name = $('input[name=name]'); var email = $('input[name=email]'); var message = $('textarea[name=message]'); var solution = $('input[name=solution]'); var receiver = $('input[name=receiver]'); var returnError = false; if (val()==='' || val()==='Name (required)') { addclass('error-contact'); returnError = true; log('errorNAME'); } else { removeclass('error-contact'); } if( !isValidEmailAddress( val() ) ) { addclass('error-contact'); returnError = true; log('errorEMAIL'); } else { removeclass('error-contact'); } if (val()==='' || val()==='Your Message') { addclass('error-contact'); returnError = true; log('errorMESSAGE'); } else { removeclass('error-contact'); } if (val()!=='3') { addclass('error-contact'); returnError = true; log('errorSOLUTION'); } else { removeclass('error-contact'); } if(returnError === true){ return false; } var data = {name: val(),email: val(), message: val(),receiver: val()}; jQuery('.text').attr('disabled','true'); jQuery('.loading').show(); ajax({ url: "http://suomi-bonus/wp-content/themes/AnchorArto/php", type: "POST", data: data, cache: false, success: function (html) { if (html==="1") { jQuery('.form').fadeOut('slow'); jQuery('.done').fadeIn('slow'); setTimeout(function(){ jQuery('.done').fadeOut('slow'); jQuery('.form').fadeIn('slow');}, 5000); } else { alert('Sorry, unexpected error. Please try again later.'); } } }); return false; }); });