jQuery(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 phone = $('input[name=phone]');
		var timeframe = $('select[name=timeframe]');
		var emplcount = $('select[name=emplcount]');
		var supcount = $('select[name=supcount]');
		var coname = $('input[name=coname]');
		var coaddress = $('input[name=coaddress]');
		var cocitystatezip = $('input[name=cocitystatezip]');
		var comment = $('textarea[name=comment]');
		var current_method = $("select[name='current_method']");
		var numberclocks = $('select[name=numberclocks]');
		var itstaff = $('select[name=itstaff]');
		var punch = $('select[name=punch]');
		var wknds = $('select[name=wknds]');
		var shiftdiff = $('select[name=shiftdiff]');
		var week = $('select[name=week]');
		var softlocation = $('select[name=softlocation]');

		

		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		if (name.val()=='') {
			name.addClass('hightlight');
			return false;
		} else name.removeClass('hightlight');
		
		if (email.val()=='') {
			email.addClass('hightlight');
			return false;
		} else email.removeClass('hightlight');
		
		if (phone.val()=='') {
			phone.addClass('hightlight');
			return false;
		} else phone.removeClass('hightlight');
		
		if (current_method.val()=='') {
			current_method.addClass('hightlight');
			return false;
		} else current_method.removeClass('hightlight');
		
		if (emplcount.val()=='') {
			emplcount.addClass('hightlight');
			return false;
		} else emplcount.removeClass('hightlight');
		
		//organize the data properly
		var data = 'name=' + name.val() + '&email=' + email.val() + '&phone=' + phone.val() + '&timeframe=' + timeframe.val() + '&emplcount=' + emplcount.val() + '&supcount=' + supcount.val() + '&coname=' + coname.val() + '&coaddress=' + coaddress.val() + '&cocitystatezip=' + cocitystatezip.val() + '&comment='  + encodeURIComponent(comment.val()) + '&current_method=' + current_method.val() + '&numberclocks=' + numberclocks.val() + '&itstaff=' + itstaff.val() + '&punch=' + punch.val() + '&wknds=' + wknds.val() + '&shiftdiff=' + shiftdiff.val() + '&week=' + week.val() + '&softlocation=' + softlocation.val();
		

		
		//show the loading sign
		$('.loading').show();
		
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "../js/process_cardswipe.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-rfq').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;
	});	
});	
