/*
* 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 $
*
*
*/
//extend the plugin
(function($){
//define the new for the plugin ans how to call it
$.fn.contactable = function(options) {
//set default options
var defaults = {
url: 'http://www.mpc-capital.de/contell/cms/server/mpc-capital_de/actions/startseite_kontaktform_sendmail.act',
name: 'Name',
email: 'Email',
fon: 'Telefon',
rueckruf: 'Bitte um Rückruf',
message: 'Nachricht',
subject: 'Nachricht von www.mpc-capital.de',
submit: 'Abschicken',
recievedMsg: 'Vielen Dank für Ihre Nachricht.',
notRecievedMsg: 'Fehler - Bitte versuchen Sie es später noch mal.',
disclaimer: '
MPC Münchmeyer Petersen Capital AG
Palmaille 71 | 22767 Hamburg
+49 (40) 3 80 22 -4200
kontakt@mpc-capital.com',
hideOnSubmit: false
};
//call in the default otions
var options = $.extend(defaults, options);
//act upon the element that is passed into the design
return this.each(function() {
//construct the form
var this_id_prefix = '#'+this.id+' ';
$(this).html('
');
//show / hide function
$(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'});
});
//validate the form
$(this_id_prefix+"#contactForm").validate({
//set the rules for the fild names
rules: {
name: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
message: {
required: true
}
},
//set messages to appear inline
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(), fon:$(this_id_prefix+'#fon').val(), rueckruf:$(this_id_prefix+'#rueckruf').attr('checked'), 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) {
//hide the tab after successful submition if requested
$(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 {
// console.debug('2');
$(this_id_prefix+'#callback').show().append(options.recievedMsg);
setTimeout(function(){
$(this_id_prefix+'.holder').show();
$(this_id_prefix+'#callback').hide().html('');
},2000);
// $(this_id_prefix+'#name').val('');
// $(this_id_prefix+'#email').val('');
// $(this_id_prefix+'#message').val('');
$(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'});
}
},
error:function(request, status, error) {
$(this_id_prefix+'#loading').css({display:'none'});
$(this_id_prefix+'#callback').show().append(options.notRecievedMsg);
}
});
}
});
});
};
})(jQuery);