$(document).ready(function() {

	//if submit button is clicked submit our ecard form
	$('#submit').click(function () {		
		
		//Get the data from all the fields
		var a1 = $('input[name=a1]');
		var email1 = $('input[name=email1]');
		var inquiry = $('textarea[name=inquiry]');
		var human1 = $('input[name=human1]');
		

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

		if (email1.val()=='') {
			email1.addClass('hightlight');
		alert('Please enter your Email Adress.');
			return false;
		} else email1.removeClass('hightlight');
		
		if (inquiry.val()=='') {
			inquiry.addClass('hightlight');
		alert('Please enter your Inquiry.');
			return false;
		} else inquiry.removeClass('hightlight');
				
		//organize the data properly
		var data = 
		'a1=' + a1.val()
		+ '&email1=' + email1.val()
		+ '&inquiry=' + encodeURIComponent(inquiry.val())
		+ '&human1=' + human1.val();

		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "../form-processes/approved-digital-signature-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) {	
				
					 
					$('.myform').fadeOut();
					
					setTimeout (function(){
					//show the success message and the thank-you message
					$('.thank-you-text').fadeIn(400); },500);
									

				//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;
	});	
});	
