// JavaScript Document<script type="text/javascript">

$(document).ready(function() {
						   
			   
		
	
		$('.error').hide();
		
		$("div.panel_button").click(function(){
		$("div#panel").animate({
			height: "400px"
		})
		.animate({
			height: "400px"
		}, "fast");
		$("div.panel_button").toggle();
	
	});	
	
   $("div#hide_button").click(function(){
		$("div#panel").animate({
			height: "0px"
		}, "fast");
		//$('.login').show();
	
   });
	//if submit button is clicked
	$('#submit').click(function () {
			
			
			$('.error').hide();
		
		
		//Get the data from all the fields
		var name = $('input[name=name]');
		var phone = $('input[name=phone]');
		var email = $('input[name=email]');
		var comments = $('textarea[name=comments]');
		var option = $('select[name=option]');

		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		if (name.val()=='') {
			 $("label#name_error").show();
			 $("label#submit_error").show();
     		 name.focus();
      		return false;
		
		} else name.removeClass('hightlight');
		
		if (phone.val()=='') {
			$("label#phone_error").show();
			$("label#submit_error").show();
     		 phone.focus();
			return false;
		} else phone.removeClass('hightlight');
		
		if (email.val()=='') {
			$("label#email_error").show();
			$("label#submit_error").show();
     		 email.focus();
			return false;
		} else email.removeClass('hightlight');
		
		
		//organize the data properly
		var data = 'name=' + name.val() + '&phone=' + phone.val() + '&email=' + 
		email.val() + '&comments='  + encodeURIComponent(comments.val())  + '&option='  + encodeURIComponent(option.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: "form/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
					$('.login').fadeOut('slow');					
					
					//show the success message
					$('.done').fadeIn('slow');
					
				//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;
	});	
});	
