// JavaScript Document

function load_dialog(object_id, cmd, valObject, target, errorContainer)
{
	$( '#'+object_id ).dialog({
		modal: true,
		width: 350,
		buttons: {
			"Save": function() {
				if($.trim($('#'+valObject).val()) == '')
				{
					$('#'+errorContainer).html('Name is required.').addClass('ui-state-error');
				} else { 
					$.post('action.php?dynamic', 
						{ command: cmd, name: $('#'+valObject).val() }, 
						function(data) { 
							$('#'+target).append('<option value="'+$.trim(data)+'" selected="selected">'+$('#'+valObject).val()+'</option>');
							$( '#'+object_id ).dialog( "close" );
							$( '#'+errorContainer ).html( "" );
						}
					); 
				}
			},
			Cancel: function() {
				$( this ).dialog( "close" );
				$( '#'+errorContainer ).html( "" );
			}
		}
	});
}

//used only for content module to generate content code
function generate_content_code()
{
	var PageTitle = $.trim($('#title').val());
	var PageTitle = PageTitle.replace(/ /g, "-");
	re = /\$|,|@|#|~|`|\%|\*|\/|\^|\&|\(|\)|\+|\=|\[|\;|\_|\]|\[|\}|\--|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
	var PageTitle = PageTitle.replace(re, "");
	$('#content_code').val(PageTitle.toLowerCase());
}

$(document).ready(function() {
	if(document.getElementById('info_panel') && document.getElementById('info_panel').style.display == '')
	{
		$('#info_panel').fadeIn().delay(6000).slideUp('slow');
	}
});

function confirm_box()
{
	var cmd = confirm('Are you sure you want to cancel? There is no undo/redo?');
	if(cmd)
	{
		//javascript:history.back(1);
		window.location = 'index.php';
	} else { return false; }
}
