/*
 * 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.feedback = 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',
			hideOnSubmit: 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) {
			//show / hide function
			$('div#contactable').toggle(function() {
				$('#overlay').css({display: 'block'});
				$(this).animate({"marginLeft": "-=5px"}, "fast"); 
				$('#contactForm').animate({"marginLeft": "-=5px"}, "fast");
				$(this).animate({"marginLeft": "+=390px"}, "slow"); 
				$('#contactForm').animate({"marginLeft": "+=390px"}, "slow"); 
			}, 
			function() {
				$('#contactForm').animate({"marginLeft": "-=390px"}, "slow").animate({"marginLeft": "+=5px"}, "fast");
				$(this).animate({"marginLeft": "-=390px"}, "slow").animate({"marginLeft": "+=5px"}, "fast"); 
				$('#overlay').css({display: 'none'});
			});
			
			//validate the form 
			$("#contactForm").validate({
				//set the rules for the fild names
				rules: {
					name: {
						required: true,
						minlength: 2
					},
					email: {
						required: true,
						email: true
					},
					comment: {
						required: true
					}
				},
				//set messages to appear inline
					messages: {
						name: "",
						email: "",
						comment: ""
					},			

				submitHandler: function() {
					$('.holder').hide();
					$('#loading').show();
					$.post('mail.php',{subject:defaults.subject, name:$('#name').val(), email:$('#email').val(), comment:$('#comment').val(), rating:$('#rating').val()},
					function(data){
						$('#loading').css({display:'none'}); 
						if( data == 'success') {
							$('#callback').show().append(defaults.recievedMsg);
							if(defaults.hideOnSubmit == true) {
								//hide the tab after successful submition if requested
								$('#contactForm').animate({dummy:1}, 2000).animate({"marginLeft": "-=450px"}, "slow");
								$('div#contactable').animate({dummy:1}, 2000).animate({"marginLeft": "-=447px"}, "slow").animate({"marginLeft": "+=5px"}, "fast"); 
								$('#overlay').css({display: 'none'});	
							}
						} else {
							$('#callback').show().append(defaults.notRecievedMsg);
						}
					});		
				}
			});
		});
	};
})(jQuery);

// quickquote
(function($){

	//define the new for the plugin ans how to call it	
	$.fn.quickquote = function(options) {
		//set default options  
		var defaults = {
			name: 'Name',
			email: 'Email',
			message : 'Message',
			subject : 'A contactable message',
			recievedMsg : 'Thank you for your request, one of our team will be in touch with you shortly.',
			notRecievedMsg : 'Sorry but your message could not be sent, try again later',
			disclaimer: 'Please feel free to get in touch, we value your feedback',
			hideOnSubmit: 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) {
			//show / hide function
			$('div#contactTab').toggle(function() {
				$('#overlay').css({display: 'block'});
				$(this).animate({"marginRight": "-=5px"}, "fast"); 
				$('#quoteForm').animate({"marginRight": "-=5px"}, "fast");
				$(this).animate({"marginRight": "+=630px"}, "slow"); 
				$('#quoteForm').animate({"marginRight": "+=630px"}, "slow"); 
			}, 
			function() {
				$('#quoteForm').animate({"marginRight": "-=630px"}, "slow").animate({"marginRight": "+=5px"}, "fast");
				$(this).animate({"marginRight": "-=630px"}, "slow").animate({"marginRight": "+=5px"}, "fast"); 
				$('#overlay').css({display: 'none'});
			});
			
			//validate the form 
			$("#quoteForm").validate({
				//set the rules for the fild names
				rules: {
					name: {
						required: true,
					},
					organisation: {
						required: true,
					},
					email: {
						required: true,
						email: true
					},
					producttype: {
						required: true,
					},
					papertype: {
						required: true,
					},
					papersize: {
						required: true,
					},
					quantity: {
						required: true,
					},
					deliverydate: {
						required: true,
					}
				},
				//set messages to appear inline
					messages: {
					  name: "",
					  organisation: "",
					  email: "",
					  producttype: "",
					  papertype: "",
					  papersize: "",
					  quantity: "",
					  deliverydate: ""
					},			

				submitHandler: function() {
				    $("#quoteFormHolder").hide();
					$.post('quotemail.php',{
						subject:defaults.subject,
						name:$('#quoteForm_name').val(),
						organisation_name:$('#quoteForm_organisation').val(),
						organisation_type:$('#quoteForm_organisationtype').val(),
						housenumber:$('#quoteForm_housenumber').val(),
						town:$('#quoteForm_town').val(),
						postcode:$('#quoteForm_postcode').val(),
						tel:$('#quoteForm_telephone').val(),
						email:$('#quoteForm_email').val(),
						product_type:$('#quoteForm_producttype').val(),
						paper_type:$('#quoteForm_papertype').val(),
						paper_size:$('#quoteForm_papersize').val(),
						quantity:$('#quoteForm_quantity').val(),
						folding:$('#quoteForm_folding').val(),
						artwork:$('#quoteForm_artwork').val(),
						delivery_date:$('#quoteForm_deliverydate').val(),
						usedbefore:$('#quoteForm_usedbefore').val()
					},
					function(data){
						if( data == 'success') {
							$('#quotecallback').show().append(defaults.recievedMsg);
							if(defaults.hideOnSubmit == true) {
								//hide the tab after successful submition if requested
								$('#quoteForm').animate({dummy:1}, 2000).animate({"marginRight": "-=680px"}, "slow");
								$('div#contactTab').animate({dummy:1}, 2000).animate({"marginRight": "-=680px"}, "slow").animate({"marginRight": "+=5px"}, "fast"); 
								$('#quoteoverlay').css({display: 'none'});	
							}
						} else {
							$('#quotecallback').show().append(defaults.notRecievedMsg);
						}
					});		
				}
			});
		});
	};
})(jQuery);



