// JavaScript Document

$(document).ready(function(){
	
	$('p.navcontact').click(function()
		{
			$('div.toggle').slideToggle(100);
			//toggle class
			//$(this).toggleClass('upArrow');
		}
	);
	
});

$(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 comment = $('textarea[name=comment]');
		
		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		var errors = 0;
		if (name.val()==''||name.val()=='name') {
			name.addClass('highlight');
			//return false;
			errors = errors + 1;
		} else name.removeClass('highlight');
		
		if (email.val()==''||email.val()=='email') {
			email.addClass('highlight');
			//return false;
			errors = errors + 1;
		} else email.removeClass('highlight');
		
		if (comment.val()==''||comment.val()=='your message') {
			comment.addClass('highlight');
			//return false;
			errors = errors + 1;
		} else comment.removeClass('highlight');
		if( errors > 0 )
		{
			return false;
		}
		
		
		//organize the data properly
		var data = 'name=' + name.val() + '&email=' + email.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: "send.php",
			
			//GET method is used
			type: "GET",
			
			//pass the data
			data: data,
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function (html) {
				//if send.php returned 1/true (send mail success)
				//alert( 'result: "' + html + '"' );
				if (html==1) {
					//hide the form
					$('.toggle').fadeOut('slow', function () {  
													$('.done').fadeIn('slow');
												}
					);
					
					//show the success message
					//$('.done').fadeIn('slow');
					
				//if send.php returned 0/false (send mail failed)
				} else alert('Sorry, unexpected error. Please try again later.');
			}
		});  

		//cancel the submit button default behaviours
		return false;
	});
});
