//**********************************************************************************************************************
/**
* DOCUMENT: /core/plugins/events/front/projects.back.js
* DEVELOPED BY: Ryan Stemkoski
* COMPANY: Zipline Interactive
* EMAIL: ryan@gozipline.com
* PHONE: 509-321-2849
* DATE: 4/28/2010
* DESCRIPTION: This document has all of the javascript functions required for the events  plugin.
*/
//***********************************************************************************************************************

//***********************************************************************************************************************
//ON DOCUMENT READY FUNCTIONS
//***********************************************************************************************************************
$(function() {

	//***********************************************************************************************************************
	//THIS FUNCTION USES AJAX TO CREATE A PERMALINK
	//***********************************************************************************************************************
	function content_update_permalink(change) {
	
		var current_permalink = $('#permalink').val();
		var updated_permalink = $('#permalink_input').val();
		var current_title = $('#title').val();
		var current_id = $('#id').val();
		
		//TOGGLE VALUE TO USE BASED ON POSITION
		if(updated_permalink) {
			title = updated_permalink;
		} else {
			title = current_title
		}	
		
		//IF THERE IS NO PERMALINK OR WE ARE UPDATING IT RUN FUNCTION.  IF THERE IS A PERMALINK SET DON'T TRY TO SET IT
		if(change == true) {
			if(title != "") {
				$.post("index.php?plugin=content&page=form", { action: "content_permalink", text: title, id: current_id },
					function(data){
						if(data != "" && data != "-") {
							$('#permalink').val(data);
							$('#permalink_text').html(data);
						}
					}
				);
			}
		}
	}
	

	//***********************************************************************************************************************
	//IF TITLE CHANGES CHECK TO SEE IF PERMALINK NEEDS UPDATING
	//***********************************************************************************************************************
	$('#title').change(function() {
		var current_permalink = $('#permalink').val();
		if(current_permalink == "") {
			content_update_permalink(true);
		}
	});

});
