// Form Submission
// -------------------------------------------	
	$(document).ready(function() {
	$('.error').hide();
	$('.text').attr('disabled','')
	$("input.text,textarea").val('');
	//if submit button is clicked
	$('.submit').live("click", function () {	
		$('.error').hide();
		var form = $(this).parent("form");
		//Get the data from all the fields
		var errors = false;
		
		//check all the required fields (with class="required" )
		form.find(".required").each(
			function(){
				if($.trim($(this).val()) == ''){
					errors = true;
					form.find("#"+this.name+"_required").show();
				}
			}
		);
		var data = new Object();
		//get all the fields and labels from form - all fields should have "text" class
		form.find(".text").each(
			function(){
				var label = $(this).prevAll("label[class!=error]").first().text();
				var text = $.trim(encodeURIComponent($(this).val()));
				data[this.name] = label+"##"+text;

			}
		);
		if(!errors){
			//disabled all the text fields
			form.find('.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: "/php/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').fadeOut('slow');					
						
						//show the success message
						$('.done').fadeIn('slow');
						
					//if process.php returned 0/false (send mail failed)
					} else {
						alert('Problem. Please try again in a few moments. If the problem persists, contact me directly - bob@disneydispatch.com.');
						form.find('.text').attr('disabled','');;
					}	
					$('.loading').hide();
				}		
			});
		}
		//cancel the submit button default behaviours
		return false;
	});	
});	



