﻿/*
* 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 $
*
*/




//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
        };


        $.fn.idle = function(time) {
            var o = $(this);
            o.queue(function() {
                setTimeout(function() {
                    o.dequeue();
                }, time);
            });
            return this;
        };




        //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=""><div id="closeit4" class="close3"></div><div id="callit2left"><label for="nme">**Your Name</label> <br /><input type="text" name="Name" id="nme"  class="required" minlength="2"  value="" /><br /><label for="eml">**Your EMail</label><br /><input type="text" id="eml" name="Email"  class="required email" value="" /><br /><label for="tel">Your Telephone (ideal)</label><br /><input type="text" name="Telephone" value="" id="tel" /></div><div id="callit2mid"><label for="com">Order or Message</label><br /><textarea name="comments_and_or_questions" id="com" class="required" rows="8" cols="30"></textarea><br /></div><div id="callit2right"><input type="submit" name="submit" value=" Submit " id="sub" /><br /><br /><input type="reset" name="Reset" value=" Clear Form " onclick="clearMail()" /><input type="hidden" name="config" value="0" /><input type="hidden" name="MAX_FILE_SIZE" value="100000" /></p></div><p id="wewill">We will contact you to confirm details and to arrange payment through PayPal.</p></form>');
            $(this).html('<div id="callit2"></div><form id="mail2" method="post" action=""><div id="closeit4" class="close3"></div><div id="callit2left"><label for="nme">**Your Name</label> <br /><input type="text" name="Name" id="nme"  class="required" minlength="2"  value="" /><br /><label for="eml">**Your EMail</label><br /><input type="text" id="eml" name="Email"  class="required email" value="" /><br /><label for="tel">Your Telephone (ideal)</label><br /><input type="text" name="Telephone" value="" id="tel" /></div><div id="callit2mid"><label for="com">Order or Message</label><br /><textarea name="comments_and_or_questions" id="com" class="required" rows="6" cols="30"></textarea><br /><br /><input type="submit" name="submit" value=" Submit " id="sub" /><span style="margin-left:25px;"><input type="reset" name="Reset" value=" Clear Form " onclick="clearMail()" /></span><input type="hidden" name="config" value="0" /><input type="hidden" name="MAX_FILE_SIZE" value="100000" /></p></div><p id="wewill">We will contact you to confirm details and to arrange payment through PayPal.</p></form>');

      
            //show / hide function
            $('#com').val("I am interested in the Optimum Event Watch, please send me ( -- number --) to this address.");
            



            //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() {

                    $.post('mail2.php', { name2: $('#nme').val(), email2: $('#eml').val(), comment2: $('#com').val(), subject2: 'From Your Website' },
					function(data) {

					    if (data == 'success') {
					        if (defaults.hideOnSubmit2 == true) {
					            $('#com').text('Thank you for your message').idle(1000).fadeOut('slow', function() {

					                $('#nme').val('');
					                $('#eml').val('');
					                $('#com').val('');

					                $("#overlayinner").hide('blind', 1200);

					                $('#mail2').hide();

					            });
					        }
					    } else {

					        $('#nme').val('');
					        $('#eml').val('');
					        $('#com').val('');
					        $('#mail2 label.error').text('');
					        $("#overlayinner").hide('blind', 1200);
					        $('#mail2').hide(4000);
					    }
					});
                }
            });
        });
    };
})(jQuery);        
