function submitPosting() {
	
 	toggleActivityIndicator();
	
	//process description
	$.post(root+"/library/process_ajax.php",{
		'type': 'posting',
		'heading': $("#post_form  input[name=heading]").val(),
		'abstract' : $("#post_form  textarea[name=abstract]").val(),
		'url' : $("#post_form  input[name=url]").val(),
		'image_ID' : $("#post_form  input[name=image_ID]").val(),
		'email' : $("#post_form  input[name=email]").val()
   	}, function(xml) {
		var success = $("success",xml).text();
		var success_message = $("success_message",xml).text();
		var error_message = $("error_message",xml).text();
		
		toggleSubmissionForm();
		if(success) {
			//$('#post_form .success').text(success_message).fadeIn();
			statusAlert('Your headline was successfully submitted for approval!');
			return true;
		}
		else {
			statusAlert('Unable to save your headline! :(');
			return false;
		}
		
		
	}, toggleActivityIndicator());
		
}//submitPosting()

function resetPostingValues() {
	$("#post_form input[name=heading]").val('Headline'),
	$("#post_form textarea[name=abstract]").val('Abstract'),
	$("#post_form input[name=url]").val('Link URL'),
	$("#post_form input[name=email]").val('Email')
}//resetPostingValues()
	
	
	
	$(document).ready(function(){

		var button = $('#uploadImage'), interval;
		new AjaxUpload(button,{
			action: '/library/process_ajax.php', 
			name: 'postingImage',
			data: {
				type: 'postingImage'
			},
			onSubmit : function(file, ext){
				// change button text, when user selects file
				button.text('Uploading');
		
				// If you want to allow uploading only 1 file at time,
				// you can disable upload button
				this.disable();
		
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = button.text();
					if (text.length < 13){
						button.text(text + '.');
					} else {
						button.text('Uploading');		
					}
				}, 200);
			},
			onComplete: function(file, response){
				var success_message = $("success_message",response).text();
				var error_message = $("error_message",response).text();
			
				var ID = $("ID",response).text();
				var filename = $("filename",response).text();
				//alert("ID: "+ID+" filename: "+filename);
				$('#image_ID').val(ID);
			
				//button.text('Upload');
				//alert("file: "+file+" response:"+response);
				 button.html("<img src='/images/postings/"+filename+"' />");
			
				window.clearInterval(interval);
			
				// enable upload button
				//this.enable();
		
				// add file to the list
				//$('<li></li>').appendTo('#example1 .files').text(file);			
			}
		});
		
		
		
		/*  The following controls the submit posting form behaviors and functionality  */	
		
		var headline = $('#inp_headline');
		var headlineInput = $('input[name=heading]');
		var abstract = $('#inp_abstract');
		var abstractInput = $('textarea[name=abstract]');
		var url = $('#inp_url');
		var urlInput = $('input[name=url]');
		var email = $('#inp_email');
		var emailInput = $('input[name=email]');
		
		$('#inp_headline, #inp_abstract').css('display', 'none');
		headline.click(function(){
			$(this).fadeOut('fast', function(){ headlineInput.fadeIn()});
		})
		headlineInput.focus(function(){
			var val = $(this).val();
			if(val == 'Headline') {
				$(this).val('');
				$(this).addClass('active');
			}//if()
			
		}).change(function(){
			var val = $(this).val();
			if(val != 'Headline') {
				headline.children('span').text(val);
				$(this).fadeOut('fast', function(){ headline.fadeIn()});
			}//if()
		});
			
		abstract.click(function(){
			$(this).fadeOut('fast', function(){ abstractInput.fadeIn()});
		})
		abstractInput.focus(function(){
			var val = $(this).val();
			if(val == 'Abstract') {
				$(this).val('');
				$(this).addClass('active');
			}//if()
			
		}).change(function(){
			var val = $(this).val();
			if(val != 'Abstract') {
				abstract.children('span').text(val);
				$(this).fadeOut('fast', function(){ abstract.fadeIn()});
			}//if()
		});
			
		url.click(function(){
			$(this).fadeOut('fast', function(){ urlInput.fadeIn()});
		})
		urlInput.focus(function(){
			var val = $(this).val();
			if(val == 'Link URL') {
				$(this).val('');
				$(this).addClass('active');
			}//if()
		}).change(function(){
			var val = $(this).val();
			if(val != 'Link URL') {
				url.children('span').text(val);
				$(this).fadeOut('fast', function(){ url.fadeIn()});
			}//if()
		});
		
			
		email.click(function(){
			$(this).fadeOut('fast', function(){ emailInput.fadeIn()});
		});	
		emailInput.focus(function(){
			var val = $(this).val();
			if(val == 'Email') {
				$(this).val('');
				$(this).addClass('active');
			}//if()
		}).change(function(){
			var val = $(this).val();
			if(val != 'Email') {
				email.children('span').text(val);
				$(this).fadeOut('fast', function(){ email.fadeIn()});
			}//if()
		});
			
		$('#headline_edit').click(function(){
			headline.fadeOut('fast', function(){ headlineInput.fadeIn()});
		})
		$('#abstract_edit').click(function(){
			abstract.fadeOut('fast', function(){ abstractInput.fadeIn()});
		})		
		$('#url_edit').click(function(){
			url.fadeOut('fast', function(){ urlInput.fadeIn()});
		})
		$('#email_edit').click(function(){
			email.fadeOut('fast', function(){ emailInput.fadeIn()});
		})	
		
		
	});