$(document).ready(function() {
	 
     

	//if submit button is clicked
	$('#btn_submit').click(function () {		
		
		//Get the data from all the fields
		var fname = $('input[id=fname]');
		var lname = $('input[id=lname]');
		var zip = $('input[id=zip]');
		var email = $('input[id=email]');


		
		//organize the data properly
		var data = 'fname=' + fname.val() + '&lname=' + lname.val() + '&zip=' + 
		zip.val() + '&email=' + email.val();
		
		//disabled all the text fields
		$('.input').attr('disabled','true');
		
		//show the loading sign
		$('#content').hide();
		$('#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: "POST",

			//pass the data			
			data: data,		
			
			//Do not cache the page
			cache: false,
			beforeSend: function() {
			$('#FormContainer').fadeTo("fast", 0.2);
			},
			//success
			success: function () {				
				
					$('#content').hide();					
					
					$('#done').fadeIn(1500);  
    				$('#loading').hide();
					
				//if process.php returned 0/false (send mail failed)
							
			}		
		});
		
		//cancel the submit button default behaviours
		return false;
	});	
	
	
			
	var current_data = new Array();

	$('.field').each(function(i){
		$(this).removeClass('field').addClass('field'+i);
		current_data.push($(this).val());

		$(this).focus(function(){
			if($(this).val() == current_data[i]) {
				$(this).val('');
			}
		});
		$(this).blur(function(){
			var stored_data = current_data[i];
			if($(this).val()==''){
				$(this).val(stored_data);
			}
		})
	});

	

});	

