$(document).ready(function () { 
	
	$(".trigger").click(function(){
		$(".panel").toggle("fast");
		$(this).toggleClass("active");

        $('.form').show();                   
        
        $('.done').hide();
        $('.check').hide();
        $('.loading').hide();
		
		return false;
	});
	
	//Handler for when Feedback Form is submitted  
	 $('#feedbackForm').submit(function () {
	       
	     //VALIDATE form fields
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		var emailFromVal = $('input[name="email"]').val();

		//if(emailFromVal == '') {
		//	$('.check').show();
		//	$('.check').text('You forgot to enter the email address to send to');
		//	return false;
		//} else if(!emailReg.test(emailFromVal)) {
		if(!emailReg.test(emailFromVal)) {
			$('.check').show();
			$('.check').text('Enter a valid email address to send to, or leave it blank to be anonymous.');
			return false;
		}
		var feedback = $('input[name="feedback"]').val();

		if(feedback == '') {
			$('.check').show();
			$('.check').text('You forgot to enter some feedback');
			return false;
		}
		$('.check').hide();
		
		 var data = $(this).serialize();
		 
	     //disabled all the text fields  
	     $('.text').attr('disabled','true');  
	       
	     //show the loading sign  
	     $('.loading').show();  
	       
	     //start the ajax  
	     $.ajax({  
	         //this is the namespace and action that processes the comments  
	         url: "/feedback/submit",   
	           
	         //GET method is used  
	         type: "GET",  
	   
	         //pass the data           
	         data: data,       
	           
	         //Do not cache the page  
	         cache: false,  
	           
	         //success  
	         success: function (message) {                
                
	    	 	if(message == "1"){
		    	 	$('.form').fadeOut('slow');                   
	                   
	                //show the success message  
		    	 	$('.done').text("Thank you ! We have received your comments.");
		    	 	$('.done').fadeIn('slow'); 
	    	 	}else{
		    	 	$('.form').fadeOut('slow');                   
	                   
	                //show the error message  
		    	 	$('.done').text(message);
		    	 	$('.done').fadeIn('slow'); 
	    	 	}
	         }     
	     });  
	       
	     //cancel the submit button default behaviours  
	     return false;  
	 }); 
}); 