/**
 * JavaScript to check for changes on a page and question if the user really wants to leave.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package clearFusionCMS
 * @copyright Copyright (c) 2012 fusionLib. All rights reserved.
 * @link http://clearfusioncms.com
 * @depreciated New code should use cfBackendController::confirmLeavePage
 */

$fl(document).ready(function() {
	var contentChanged = false;

	function setContentChanged(e) {
		contentChanged = e.target.type == 'submit' ? false : true;
	}

	$fl('form input').bind('change', setContentChanged).bind('click', setContentChanged);
	$fl('form select').bind('change', setContentChanged);
	$fl('form textarea').bind('change', setContentChanged);

	$fl(window).bind('beforeunload', function(e) {
		if(contentChanged)
			return e.returnValue = 'You have made changes on this page that have not been saved and will be lost if you navigate away from this page.';
	});
});