/*
/	Author: Joel Docking
/	Date: 22.6.2011
/	Site specific Javascript	
/	* Requires jQuery Framework
*/

$(document).ready(function(){   
	
	/* Load nivoSlider
	$('#slider').nivoSlider({
		animSpeed:1000,
		pauseTime:4000,
		directionNav:false,
		captionOpacity:1.0
	}); */
	
	////////////////////////////////////////////////////////////////////////
	// AJAX Contact Form Handler
	/////////////////////////////////////////////////////////////////////////
    $('#submit').click(function () {
		
		$("#fb-form").validate({
			
			submitHandler: function(form) {
         
			//Get the data from all the fields
			var name = $('input[name=name]');
			var cottage = $('select[name=cottage]');
			var method = $('select[name=method]');
			var phone = $('input[name=phone]');
			var email = $('input[name=email]');
			var state = $('input[name=state]');
			var country = $('input[name=country]');
			var checkin = $('input[name=checkin]');
			var checkout = $('input[name=checkout]');
			var adults = $('input[name=adults]');
			var children = $('input[name=children]');
			var arrival = $('input[name=arrival]');
			var comment = $('textarea[name=comment]');
	
			//organize the data properly
			var data = 
			'name=' + name.val() +
			'&cottage=' + cottage.val() +
			'&method=' + method.val() +
			'&phone=' + phone.val() +
			'&email=' + email.val() +
			'&state=' + state.val() + 
			'&country=' + country.val() + 
			'&checkin=' + checkin.val() + 
			'&checkout=' + checkout.val() +
			'&adults=' + adults.val() +
			'&children=' + children.val() +
			'&arrival=' + arrival.val() +
			'&comment=' + encodeURIComponent(comment.val());
			 
			//disabled all the text fields
			$('.text').attr('disabled','true');
			 
			//show the loading graphic
			$('#submit').hide();
			$('.loading').show();
			 
			//start the ajax
			$.ajax({
				//this is the php file that processes the data and send mail
				url: "http://www.theshingles.com.au/theme/Shingles/inc/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(html);
				}      
			});
			
        	return false;
			
			} // end submitHandler
			
		}); // end validate function
    }); 
	/////////////////////////////////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////
  
});  
