jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('.status_alert').hide();
jQuery('.mystatus_loading').hide();
	
	//if submit button is clicked
	jQuery('#submit').click(function () {		
		
		//Get the data from all the fields
		var status = jQuery('input[name=status]');
		var uid = jQuery('input[name=uid]');
		
		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		if (status.val()=='') {
			status.addClass('invalid_field');
			return false;
		} else status.removeClass('invalid_field');
		
						
		//organize the data properly
		var data = 'uid='+ uid.val() + '&status=' + status.val();
		
		jQuery('.text').attr('disabled','true');
				
		//show the loading sign
		jQuery('.validation_loading').show();
		
		//start the ajax
		jQuery.ajax({
			//this is the php file that processes the status
			url: "process-mystatus.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
				if (html==1) {		

					//Fanciness - update the current status on change without pulling it from the Database... yes, trickery hobitses
					jQuery('#currentstatus').replaceWith('<div class="showstatus">' + status.val() + '</div>');				
					
					//show the success message
					jQuery('.status_alert').fadeIn('slow');

					//empty the text box
					jQuery('.text').attr('value','');

					//re-hide the loading symbol
					jQuery('.mystatus_loading').hide();

					
				//if process.php returned 0/false (db update failure)
				} else alert('Sorry, unexpected error. Please try again later.');	
				
			}		
		});
		
		//cancel the submit button default behaviours
		return false;
	});	
});	
