/* Author: Machinegunkelly@twistedbydesigns.com
*/
$(document).ready(function () {
	//if submit button is clicked
	$('#submit').click(function () {
		//Get the data from all the fields
		var name = $('input[name=name]');
		var email = $('input[name=email]');
		var website = $('input[name=website]');
		var comment = $('textarea[name=comment]');
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;


		if (name.val() == '') {
			$('.nameerror').slideDown('slow');
			return false;
		}
		else $('.nameerror').slideUp('slow');
		
		
		
		
		if (email.val() == '') {
			$('.emailerror').slideDown('slow');
			return false;
		}
		else $('.emailerror').slideUp('slow');

		if (!/^[A-Z0-9._%+-]+@[A-Z0-9][A-Z0-9.-]*\.[A-Z]{2,4}$/i.test(document.getElementById('email').value)) {
			$('.emailerrorinvalid').slideDown('slow');
   		return false;

		}
		else $('.emailerrorinvalid').slideUp('slow');

		if (comment.val() == '') {
			$('.messageerror').slideDown('slow');
			return false;
		}
		else $('.messageerror').slideUp('slow');
		//organize the data properly
		var data = 'name=' + name.val() + '&email=' + email.val() + '&website=' + website.val() + '&comment=' + encodeURIComponent(comment.val());
		//disabled all the text fields
		$('.text').attr('disabled', 'true');
		//show the loading sign
		$('.loading').show();
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "process.php",
			//GET method is used
			type: "GET",
			//pass the data			
			data: data,
			//Do not cache the page
			cache: false,
			//success
			success: function (html) {
				//if process.php returned 1/true (send mail success)
				if (html == 1) {
					//hide the form
					$('.form').slideUp('slow');
					//show the success message
					$('.done').slideDown('slow');
					setTimeout("jQuery.fancybox.close()", 3000);
					setTimeout("$('.done').slideUp('slow')", 3100);
					setTimeout("$('.form').slideDown('slow')", 3100);
					//if process.php returned 0/false (send mail failed)
				}
				else alert('Sorry, unexpected error. Please try again later.');
			}
		});
		//cancel the submit button default behaviours
		return false;
	});
});
$(document).ready(function () {
	$("#Contact").fancybox({
		'transitionIn': 'elastic',
		'transitionOut': 'elastic',
		'overlayColor': '#000',
		'hideOnOverlayClick': false,
	});
});



