/*
 * contactable 1.2.1 - jQuery Ajax contact form
 *
 * Copyright (c) 2009 Philip Beel (http://www.theodin.co.uk/)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Revision: $Id: jquery.contactable.js 2010-01-18 $
 *
 */

(function ($) { $.fn.contactable = function (options) { var defaults = { url: '/SendContactable', name: 'Name', email: 'Email', message: 'Message', subject: 'A contactable message', submit: 'L&#228;het&#228; yhteydenotto', recievedMsg: 'Kiitos yhteydenotostasi!', notRecievedMsg: 'Virhe yhteydenoton lähettämisessä.<br />Yritä myöhemmin uudelleen tai ota yhteyttä puhelimitse.', disclaimer: 'Please feel free to get in touch, we value your feedback', hideOnSubmit: true }; var options = $.extend(defaults, options); return this.each(function () { var this_id_prefix = '#' + this.id + ' '; $(this).html('<div id="contactable_inner"></div><form id="contactForm" method="post" action="/SendContactable"><div id="loading"></div><div id="callback"></div><div class="holder"><h2>Ota yhteytt&#228; asiakaspalveluumme!</h2><p><label for="name">Nimi<span class="red"> * </span></label><br /><input id="name" class="contact" name="name"/></p><p><label for="email">S&#228;hk&#246;postiosoite <span class="red"> * </span></label><br /><input id="email" class="contact" name="email" /></p><p><label for="message">Viesti <span class="red"> * </span></label><br /><textarea id="message" name="message" class="message" rows="4" cols="30" ></textarea></p><p><input class="OrangeButton" class="submit" type="submit" value="L&#228;het&#228; yhteydenottosi"/></p><p class="disclaimer"><table border="0"><tr><td><b>Positiivarit Oy</b><br />Positiivarit<br />PL 136<br />15101 LAHTI</td><td><br />(03) 882 160<br />positiivarit@positiivarit.fi</td></tr></table></p></div></form>'); $(this_id_prefix + 'div#contactable_inner').toggle(function () { $(this_id_prefix + '#overlay').css({ display: 'block' }); $(this).animate({ "marginLeft": "-=5px" }, "fast"); $(this_id_prefix + '#contactForm').animate({ "marginLeft": "-=0px" }, "fast"); $(this).animate({ "marginLeft": "+=387px" }, "slow"); $(this_id_prefix + '#contactForm').animate({ "marginLeft": "+=390px" }, "slow") }, function () { $(this_id_prefix + '#contactForm').animate({ "marginLeft": "-=390px" }, "slow"); $(this).animate({ "marginLeft": "-=387px" }, "slow").animate({ "marginLeft": "+=5px" }, "fast"); $(this_id_prefix + '#overlay').css({ display: 'none' }) }); $(this_id_prefix + "#contactForm").validate({ rules: { name: { required: true, minlength: 2 }, email: { required: true, email: true }, message: { required: true} }, messages: { name: "", email: "", message: "" }, submitHandler: function () { $(this_id_prefix + '.holder').hide(); $(this_id_prefix + '#loading').show(); $.ajax({ type: 'POST', url: options.url, data: { subject: options.subject, name: $(this_id_prefix + '#name').val(), email: $(this_id_prefix + '#email').val(), message: $(this_id_prefix + '#message').val() }, success: function (data) { $(this_id_prefix + '#loading').css({ display: 'none' }); if (data.success) { $(this_id_prefix + '#callback').show().append(options.recievedMsg); if (options.hideOnSubmit == true) { $(this_id_prefix + '#contactForm').animate({ dummy: 1 }, 2000).animate({ "marginLeft": "-=450px" }, "slow"); $(this_id_prefix + 'div#contactable_inner').animate({ dummy: 1 }, 2000).animate({ "marginLeft": "-=447px" }, "slow").animate({ "marginLeft": "+=5px" }, "fast"); $(this_id_prefix + '#overlay').css({ display: 'none' }) } } else { $(this_id_prefix + '#callback').show().append(options.notRecievedMsg); setTimeout(function () { $(this_id_prefix + '.holder').show(); $(this_id_prefix + '#callback').hide().html('') }, 2000) } }, error: function () { $(this_id_prefix + '#loading').css({ display: 'none' }); $(this_id_prefix + '#callback').show().append(options.notRecievedMsg) } }) } }) }) } })(jQuery);
