$(document).ready(function() {
	
	//if submit button is clicked
	$('#submit').click(function () {		
		
		//Get the data from all the fields
		var smsphone = $('input[name=smsphone]');
		var smsname = $('input[name=smsname]');

		
		if (smsphone.val()=='') {
			$('#sms-error').fadeIn('slow');
			return false;
		} else smsphone.removeClass('highlight');
		
		if (smsname.val()=='') {
			$('#sms-error').fadeIn('slow');
			return false;
		} else smsname.removeClass('highlight');
		
		//organize the data properly
		var data = '&smsphone=' + smsphone.val() + '&smsname='  + smsname.val();
		
		//disabled all the text fields
		$('.text').attr('disabled','true');
		
		$('#sendsms').fadeOut('slow');
		
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "sendsms.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
					$('#sendsms').fadeOut('slow');					
					$('#sms-error').fadeOut('fast');
					//show the success message
					$('#sms-sent').fadeIn('slow');
					
				//if process.php returned 0/false (send mail failed)
				} else 
				$('#sendsms').fadeOut('slow');					
					$('#sms-error').fadeOut('fast');
					//show the success message
					$('#sms-sent').fadeIn('slow');
			}		
		});
		
		//cancel the submit button default behaviours
		return false;
	});	
});	

