﻿$(document).ready(function(){
			
			$("#submit").click(function(){
			var name = $("#name").fieldValue();
			var company = $("#company").fieldValue();
			var phone = $("#phone").fieldValue();
			var email = $("#email").fieldValue();
			var comment = $("#comment").fieldValue();
			$("#myForm").validate({
			submitHandler: function(form) {
				// prepare Options Object 
				var options = { 
					type: 'post',
					url: 'send.php',
					data: "name="+name+"&amp;company="+company+"&amp;phone="+phone+"&amp;email="+email+"&amp;comment="+comment+"",
					clearForm: true,
					resetForm: true,
					success:	function(msg) { 
						$("#sendEmail").html('<p class="thankyou">Thank you for your enquiry. One of our team<br />will contact you very shortly to discuss your requirements further.</p><br /><br /><a href="index.html" class="cancel">&nbsp;</a>');
						$('#contact .intro').hide();
						$('#contact #details').hide();
						$('#form').hide('slow');
						
						$("#cancel").click(function(){
						  $("#myForm").resetForm();
						  $("#myForm").clearForm();
						  name = "";
						  company = "";
						  phone = "";
						  email = "";
						  comment = "";
						  $('#main').fadeIn("slow");
						  $('#contact').fadeOut("slow");
						  $('#rotator').cycle('resume', true); 
						});
						
					} 
				}; 
				 
				// pass options to ajaxForm 
				//if(name!="" &amp;&amp; email!="" &amp;&amp; comment!="")
				$(form).ajaxSubmit(options); 
				},
				errorElement: "div",
			errorPlacement: function(error, element) {
					 error.appendTo( element.next('span'));
				   },
			rules: {
				name: {
				required: true,
				rangelength: [2, 30]
				},
				company: {
				rangelength: [2, 60]
				},
				phone: {
				digits: true,
				rangelength: [9, 14]
				},
				email: {
				required: true,
				email: true
				},
				comment: {
				required: true,
				rangelength: [10, 200]
				}
				}
			}).form();
			});
			
			$("#contact_form").click(function(){
			  $("#myForm").resetForm();
			  $("#myForm").clearForm();
			  name = "";
			  company = "";
			  phone = "";
			  email = "";
			  comment = "";
			  $('#main').fadeOut("slow");
			  $('#contact').fadeIn("slow");
			  $('#rotator').cycle('pause');
			});
			$("#cancel").click(function(){
			  $("#myForm").resetForm();
			  $("#myForm").clearForm();
			  name = "";
			  company = "";
			  phone = "";
			  email = "";
			  comment = "";
			  $('#main').fadeIn("slow");
			  $('#contact').fadeOut("slow");
			  $('#rotator').cycle('resume', true); 
			});
			
			$('#rotator').cycle({ 
				fx: 'scrollLeft',
				speed:    3000, 
				timeout:  10500 
			});
		  });