﻿/*
* contactable2 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 $
*
*/


$.fn.idle = function(time) {
    var o = $(this);
    o.queue(function() {
        setTimeout(function() {
            o.dequeue();
        }, time);
    });
    return this;
};

//extend the plugin
(function($) {

    //define the new for the plugin ans how to call it	
    $.fn.con2 = function(options) {
        //set default options  
        var defaults = {
            //      name: 'Name',
            //      email: 'Email',
            //      message: 'Message',
            //      subject: 'A contactable message',
            //      recievedMsg: 'Thank you for your message',
            //      notRecievedMsg: 'Sorry but your message could not be sent, try again later',
            //      disclaimer: 'Please feel free to get in touch, we value your feedback',
            hideOnSubmit2: true
        };




        //call in the default otions
        var options = $.extend(defaults, options);
        //act upon the element that is passed into the design    
        return this.each(function(options) {
            //construct the form
            $(this).html('<div id="callit2"></div><form id="mail2" method="post" action=""><h3>Send Pam A Message</h3><p><label for="mname">Name (required, at least 2 characters)</label><br /><input id="mname" name="mname" class="required" minlength="2" /></p><p><label for="memail">E-Mail (required)</label><br /><input id="memail" name="memail" class="required email" /></p><p><label for="mcomment">Your comment (required)</label><br /><textarea id="mcomment" name="mcomment" class="required" rows="5" cols="18"></textarea></p><p><input class="submit" type="submit" value="Submit (thank you)"/></p><p id="dism2">or Dismiss</p></form>');
            //show / hide function
          //  $(this).draggable();

            $('#dism2').click(function() {
                $('#mail2 label.error').text('');
                //     $('#overlay').css({ display: 'none' });
                //       if ($('#ttl').text() == '') {
                //          $("#foropac").show();
                //      } else {
                //           $("#foropac").hide('slow');
                //           $('#footer').css('position', 'relative');
                //       }
                $('#mname').val('');
                $('#memail').val('');
                $('#mcomment').val('');
             //   $('#callit2').hide();
               $('#mail2').hide('slow');
                $("#backgroundPopup").fadeOut("slow");
           //     $('#rightpinner').css({ visibility: 'visible' });
            });





            //validate the form 
            $("#mail2").validate({
                //set the rules for the field names
                rules: {
                    name2: {
                        required: true,
                        minlength: 2
                    },
                    email2: {
                        required: true,
                        email: true
                    },
                    comment2: {
                        required: true
                    }
                },
                //set messages to appear inline
                messages: {
                    name2: "",
                    email2: "",
                    comment2: ""
                },

                submitHandler: function() {
                    //    $('.holder').hide();
                    //    $('#loading').show();
                    //subject: defaults.subject, 
                    $.post('mail2.php', { name2: $('#mname').val(), email2: $('#memail').val(), comment2: $('#mcomment').val(), subject2: 'From Your Website' },
					function(data) {

					    //    $('#loading').css({ display: 'none' });
					    if (data == 'success') {
					        //    $('#callback2').show().append(defaults.recievedMsg);
					        if (defaults.hideOnSubmit2 == true) {
					            //     $('#overlay').css({ display: 'none' });
					            $('#mcomment').text('Thank you for your message').idle(3000).fadeOut('slow', function() {
					           //     $('#mail2').animate({ "marginTop": "-=860px" }, "slow");
					           //     $('#mail2').css("margin-left", "0px");
					                $('#callit2').css("margin-left", "0px");

					                //           if ($('#ttl').text() == '') {
					                //               $("#foropac").show();
					                //               $('#footer').css('position', 'relative');
					                /////   //    $('#footer').css('top', '796px');


					                //            } else {
					                //                $("#foropac").hide('slow');
					                //            }
					                $('#mname').val('');
					                $('#memail').val('');
					                $('#mcomment').val('');
					             //   $('#callit2').hide();
					                $('#mail2').hide('slow');
					                $("#backgroundPopup").fadeOut("slow");
					          //      $('#rightpinner').css({ visibility: 'visible' });

					            });


					            //   $("#foropac").show();
					        }
					    } else {

					        //    $('#callback2').show().append(defaults.notRecievedMsg);

					        //   $('#overlay').css({ display: 'none' });
					        $('#mail2 label.error').text('');
					    //    $('#mail2').animate({ "marginTop": "-=660px" }, "slow");
					    //    $('#mail2').css("margin-left", "0px");
					        $('#callit2').css("margin-left", "0px");

					        //     if ($('#ttl').text() == '') {
					        //          $("#foropac").show();
					        //         $('#footer').css('position', 'relative');
					        //////         //    $('#footer').css('top', '796px');


					        //     } else {
					        //        $("#foropac").hide('slow');
					        //    }
					        $('#mname').val('');
					        $('#memail').val('');
					        $('#mcomment').val('');
					        $('#mail2 label.error').text('');
					     //   $('#callit2').hide(4000);
					        $('#mail2').hide(4000);
					        $("#backgroundPopup").fadeOut("slow");
					 //       $('#rightpinner').css({ visibility: 'visible' });

					        //   $("#foropac").show();



					    }
					});
                }
            });
        });
    };
})(jQuery);

