
$(document).ready(function() {
	
	//if submit button is clicked
	$('#submit').click(function () {		
		
		//Get the data from all the fields
		var a1 = $('input[name=a1]');
		var a2 = $('input[name=a2]');
		var a3 = $('select[name=a3]');
		var a4 = $('select[name=a4]');
		var a5 = $('select[name=a5]');
		var aa = $('select[name=aa]');
		var ab = $('select[name=ab]');
		var ac = $('select[name=ac]');
		var human = $('input[name=human]');
		
		
	

		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		if (a2.val()=='') {
			a2.addClass('hightlight');
			alert('please enter your Email.');
			return false;
		} else a2.removeClass('hightlight');

		if (a3.val()=='' || a3.val()=='No-Selection') {
			alert('Please enter your Top Deck color.');
			return false;
		} 
		
		if (a4.val()=='' || a4.val()=='No-Selection') {
			alert('Please enter your Bottom Deck color.');
			return false;
		} 

		if (a5.val()=='' || a4.val()=='No-Selection') {
			alert('Please enter your Hood color.');
			return false;
		} 

		if (aa.val()=='' || aa.val()=='No-Selection') {
			alert('Please enter a color comp option.');
			return false;
		}
		

		
		//organize the data properly
		var data = 
		'a1=' + a1.val() 
		+ '&a2=' + a2.val() 
		+ '&a3=' + a3.val()
		+ '&a4=' + a4.val()
		+ '&a5=' + a5.val()
		+ '&aa=' + aa.val() 
		+ '&ab=' + ab.val()
		+ '&ac=' + ac.val()
		+ '&human=' + human.val();
		

		
		//disabled all the text fields
		$('.text').attr('disabled','true');

		setTimeout (function(){
					$('.loading-form').fadeIn(250); },500);
		
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "http://www.ipdjetskigraphics.com/color-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
					 
					
					
					$('.myform').hide(0);					
					
							//show the loading sign
						setTimeout (function(){
					$('.loading-form').fadeOut(0); },2800);
				 
				 
					
					
					
					
					setTimeout (function(){
					//show the success message
					$('.done').fadeIn(1000); },2800);
					
					
					
					//show the loading sign
					$('#start-now-submit-btn').hide('fast');		
					
				//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;
	});	
});	

