function strReplace(s, r, w)
{
	return s.split(r).join(w);
}

function addslashes(str) 
{
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) 
{
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

function trim(str)
{ 
	str = str.replace(/&nbsp;/g, '');
	return str.replace(/(^\s+)|(\s+$)/g, '');
}



window.onresize = function()
{
	var width = document.documentElement.clientWidth;
}
       

function getObj(nid)
{
	if (document.getElementById(nid))
	{
		return document.getElementById(nid);
	}
	else
	{
		return false;
	}
}

function getObjValue(nid)
{
	var ret = "";
	if (document.getElementById(nid).type == "checkbox")
	{
		if (document.getElementById(nid).checked == true)
		{
			ret = document.getElementById(nid).value;
		}
	}
	else
	{
		ret = document.getElementById(nid).value;
	}
	return ret;
}

function getValFromUrl(url, varname)
{
	var vars = new Array();
	vars = url.split("&");
	var ret = "error";

	for (i = 0; i < vars.length; i++)
	{
		var value = new Array();
		value = vars[i].split("=");
		if (value[0] == varname)
		{
			ret = value[1];
		}
	}
	return ret;	
}


var editor, event_editor;
var upload1, upload_cover, upload_video, upload_event_images;
function makeRequest(url) 
{
	var http_request = false;

	if(document.all)
	{
		var yOffset = document.documentElement.scrollTop;
	}
	else
	{
		var yOffset = window.pageYOffset;
	}

	if (window.XMLHttpRequest) 
	{ // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/html');
			// Читайте ниже об этой строке
		}
	} 
	else if (window.ActiveXObject) 
	{ // IE
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{
			}
		}
	}


	if (!http_request) 
	{
		alert('Unfortunatly your browser doesn\'t support XMLHTTP.');
		return false;
	}

	http_request.onreadystatechange = function() 
	{ 
		if (http_request.readyState == 4)
		{
         if (http_request.status == 200)
			{
				$("#curtain").css("display", "none");
				
				var answer = eval('(' + http_request.responseText + ')');
				//alert(http_request.responseText);
				if (answer.callback[0] == "login")
				{
					var errors = getObj("errors");
					var childs = errors.childNodes;
					$.each(childs, function()
					{
						errors.removeChild(this);
					});
				
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{	
						var ul = document.createElement("ul");	
						$.each(answer.user_error, function()
						{
							var li = document.createElement("li");
							li.innerHTML = this;
							ul.appendChild(li);
						});
						errors.appendChild(ul);
					}				
					else
					{
						document.location.reload();
					}
				}
				else if (answer.callback[0] == "moveNode")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{	
					}				
					else
					{
						$.tree.focused().lock(false);
					}
				}
				else if (answer.callback[0] == "createNode")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{	
					}
					else
					{
						$.tree.focused().lock(false);
						obj = $("a.clicked")[0];
						obj.parentNode.id = "phtml_" + answer.new_id[0];
						obj.setAttribute("onclick", "makeRequest('getEditorArea', " + answer.new_id[0] + ")");
					}
				}
				else if (answer.callback[0] == "copyNode")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
					}
					else
					{
						$.tree.focused().lock(false);
						obj = getObj(answer.src_id[0]);
						obj.id = "phtml_" + answer.new_id[0];
						a = $("a.clicked")[0];
						a.setAttribute("onclick", "makeRequest('getEditorArea', " + answer.new_id[0] + ")");
						$.tree.focused().refresh();
					}
				}
				else if (answer.callback[0] == "renameNode")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
					}
					else
					{
					}
				}
				else if (answer.callback[0] == "removeNodeAll")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
					}
					else
					{
						$.tree.focused().refresh();
					}
				}
				
				else if (answer.callback[0] == "removeImage")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						var src = answer.src[0];
						$(".a_img_delete[rel=\"" + src + "\"]").parent().remove();
					}
				}
				
				else if (answer.callback[0] == "removeImage_cover")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						var src = answer.src[0];
						$(".a_img_delete[rel=\"" + src + "\"]").parent().remove();
					}
				}
				
				
				else if (answer.callback[0] == "removeFile")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						var src = answer.src[0];
						$(".a_img_delete[rel=\"" + src + "\"]").parent().parent().remove();
					}
				}
				
				else if (answer.callback[0] == "removeImage_event_image")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						var src = answer.src[0];
						$(".a_img_delete[rel=\"" + src + "\"]").parent().remove();
					}
				}
				
				else if (answer.callback[0] == "getPageGallery")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						$("#thumbnails").html(answer.content[0]);
						
						$("#thumbnails").dragsort(
						{
							dragSelector: "li > div", 
							dragBetween: true, 
							placeHolderTemplate: "<div></div>",
							dragEnd: saveGalleryOrder
						});
						
						$.each($(".ul_attached_images .a_img_delete"), function ()
						{
							$(this).parent().mouseover(function()
							{
								$(this).children("a").css("display", "block");
							});
							$(this).parent().mouseout(function()
							{
								$(this).children("a").css("display", "none");
							});
						});
						
						$(".navi").slider({
							value: answer.offset[0],
							min: answer.min[0],
							max: answer.max[0],
							change: function(event, ui) 
							{
								makeRequest("getPageGallery", answer.id[0], ui.value, answer.min[0], answer.max[0]);
							},
							animate: "fast"
						});
					}
				}
				else if (answer.callback[0] == "getEditorArea" || answer.callback[0] == "changePageModule")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
					}
					else
					{
						if (answer.callback[0] == "changePageModule")
						{
							$.tree.focused().refresh();
						}
	
						try
						{
									
							if (upload1)
							{
								upload1.destroy();
							}
							if (upload_cover)
							{
								upload_cover.destroy();
							}
							if (upload_video)
							{
								upload_video.destroy();
							}
							if (upload_event_images)
							{
								upload_event_images.destroy();
							}
							
							if (editor)
							{
								editor.destroy();
								event = null;
							}							
							if (event_editor)
							{
								event_editor.destroy();
								event_editor = null;
							}
										
							$("#right").html(answer.content[0]);
							
							
							var current_date = new Date();
							var day = current_date.getDate();
							var month = current_date.getMonth() + 1;
							if (month < 10)
							{
								month = "0" + month.toString();
							}
							var year = current_date.getFullYear();
							$("#event_date").val(day + "." + month + "." + year);
						
							$("#event_date").DatePicker({
								format:'d.m.Y',
								date: current_date,
								view: "days",
								position: 'bottom',
								onBeforeShow: function(){
									$('#event_date').DatePickerSetDate($('#event_date').val(), true);
								},
								onChange: function(formated, dates){
									$('#event_date').val(formated);
								}
							});
							
							
							
							$("#t_tags").fcbkcomplete({
            				json_url: "/libs/jquery/textboxlist/tags.php",
            				cache: false,
            				filter_case: false,
            				filter_hide: true,
								firstselected: true,
            				filter_selected: true,
            				newel: true,
            				complete_text: "Начните печатать..."
          				});
          				
          				
          				$("#event_tags").fcbkcomplete({
            				json_url: "/libs/jquery/textboxlist/tags.php",
            				cache: false,
            				filter_case: false,
            				filter_hide: true,
								firstselected: true,
            				filter_selected: true,
            				newel: true,
            				complete_text: "Начните печатать..."
          				});
							
          				
							
							
													
							//setupTinyMCE("txt");
							
							if ( $("#txt").length > 0 )
							{
								$("#txt").ckeditor( 
									function () 
									{
										editor = $("#txt").ckeditorGet();
										CKFinder.SetupCKEditor( editor, "/libs/ckeditor/plugins/ckfinder/");
									},
								
									{
										toolbar:
										[
											['Source','-','Undo','Redo','-','Maximize', 'ShowBlocks','-','NewPage','Preview','-'],
											['Cut','Copy','Paste','PasteText','PasteFromWord','-'],
											['Find','Replace','-','SelectAll','RemoveFormat','Styles','Format'],
											'/',
											['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
											['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
											['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
											['Link','Unlink','Anchor'],
											['Image','Flash','Table','SpecialChar']
										],
										
										on :
        								{
            								instanceReady : function( ev )
            								{
                								this.dataProcessor.writer.setRules( 'p',
                    								{
                        								indent : false,
                        								breakBeforeOpen : true,
                        								breakAfterOpen : true,
                        								breakBeforeClose : true,
                        								breakAfterClose : true
                    								});
            								}
        								}        								
									}
									
								);
							}
							
							
							if ( $("#event_txt").length > 0 )
							{
								$("#event_txt").ckeditor( 
									function () 
									{
										event_editor = $("#event_txt").ckeditorGet();
										CKFinder.SetupCKEditor( event_editor, "/libs/ckeditor/plugins/ckfinder/");
									},
								
									{
										toolbar:
										[
											['Source','-','Undo','Redo','-','Maximize', 'ShowBlocks','-','NewPage','Preview','-'],
											['Cut','Copy','Paste','PasteText','PasteFromWord','-'],
											['Find','Replace','-','SelectAll','RemoveFormat','Styles','Format'],
											'/',
											['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
											['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
											['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
											['Link','Unlink','Anchor'],
											['Image','Flash','Table','SpecialChar']
										]
									}
								);
							}

						
							var settings = {
								// Backend Settings
								upload_url: "/libs/swfupload/upload.php",
								post_params: {"page_id": answer.page_id[0]},
								// File Upload Settings
								file_size_limit : "1024",	// 1MB
								file_types : "*.jpg;",
								file_types_description : "JPG",
								file_upload_limit : "0",
								file_queue_limit : "0",
								// Event Handler Settings - these functions as defined in Handlers.js
								//  The handlers are not part of SWFUpload but are part of my website and control how
								//  my website reacts to the SWFUpload events.
								file_queue_error_handler : fileQueueError,
								file_queued_handler : fileQueued,
								file_dialog_complete_handler : fileDialogComplete,
								upload_start_handler : uploadStart,
								upload_progress_handler : uploadProgress,
								upload_error_handler : uploadError,
								upload_success_handler : uploadSuccess,
								upload_complete_handler : uploadComplete,
								// Button Settings
								button_image_url : "/libs/swfupload/images/SmallSpyGlassWithTransperancy_17x18.png",
								button_placeholder_id : "browseButton",
								button_width: 180,
								button_height: 18,
								button_text : '<span class="button">Обзор... <small>(1 MB Max)</small></span>',
								button_text_style : '.button { font-family:Arial; font-size:12px; } small { font-size: 10px; }',
								button_text_top_padding: 0,
								button_text_left_padding: 18,
								button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
								button_cursor: SWFUpload.CURSOR.HAND,
								// Flash Settings
								flash_url : "/libs/swfupload/swfupload.swf",
								custom_settings : {
									progressTarget : "fsUploadProgress1",
									cancelButtonId : "btnCancel1"
								},
								// Debug Settings
								debug: false
							};	
							upload1 = new SWFUpload(settings);
							
								
							
							if ($("#browseButton_cover").length > 0)
							{
								var settings = {
									// Backend Settings
									upload_url: "/libs/swfupload/upload_cover.php",
									post_params: {"page_id": $("#thumbnails_cover").attr("rel"), "session" : $("#browseButton_cover").attr("rel")},
									// File Upload Settings
									file_size_limit : "1024",	// 1MB
									file_types : "*.jpg;",
									file_types_description : "JPG",
									file_upload_limit : "0",
									file_queue_limit : "1",
									// Event Handler Settings - these functions as defined in Handlers.js
									//  The handlers are not part of SWFUpload but are part of my website and control how
									//  my website reacts to the SWFUpload events.
									file_queue_error_handler : fileQueueError,
									file_queued_handler : fileQueued,
									file_dialog_complete_handler : fileDialogComplete,
									upload_start_handler : uploadStart,
									upload_progress_handler : uploadProgress,
									upload_error_handler : uploadError,
									upload_success_handler : uploadSuccess_cover,
									upload_complete_handler : uploadComplete,
									// Button Settings
									button_image_url : "/libs/swfupload/images/SmallSpyGlassWithTransperancy_17x18.png",
									button_placeholder_id : "browseButton_cover",
									button_width: 180,
									button_height: 18,
									button_text : '<span class="button">Обзор... <small>(1 MB Max)</small></span>',
									button_text_style : '.button { font-family:Arial; font-size:12px; } small { font-size: 10px; }',
									button_text_top_padding: 0,
									button_text_left_padding: 18,
									button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
									button_cursor: SWFUpload.CURSOR.HAND,
									// Flash Settings
									flash_url : "/libs/swfupload/swfupload.swf",
									custom_settings : {
										progressTarget : "fsUploadProgress_cover",
										cancelButtonId : "btnCancel_cover"
									},
									// Debug Settings
									debug: false
								};	
								upload_cover = new SWFUpload(settings);
							}
							

							if ($("#browseButton_video").length > 0)
							{
								var settings = {
									// Backend Settings
									upload_url: "/libs/swfupload/upload_video.php",
									post_params: {"page_id": $("#thumbnails_files").attr("rel"), "session" : $("#browseButton_video").attr("rel")},
									// File Upload Settings
									file_size_limit : "51200",	// 50MB
									file_types : "*.flv;",
									file_types_description : "Flash видео",
									file_upload_limit : "0",
									file_queue_limit : "1",
									// Event Handler Settings - these functions as defined in Handlers.js
									//  The handlers are not part of SWFUpload but are part of my website and control how
									//  my website reacts to the SWFUpload events.
									file_queue_error_handler : fileQueueError,
									file_queued_handler : fileQueued,
									file_dialog_complete_handler : fileDialogComplete,
									upload_start_handler : uploadStart,
									upload_progress_handler : uploadProgress,
									upload_error_handler : uploadError,
									upload_success_handler : uploadSuccess_video,
									upload_complete_handler : uploadComplete,
									// Button Settings
									button_image_url : "/libs/swfupload/images/SmallSpyGlassWithTransperancy_17x18.png",
									button_placeholder_id : "browseButton_video",
									button_width: 180,
									button_height: 18,
									button_text : '<span class="button">Обзор... <small>(50 MB Max)</small></span>',
									button_text_style : '.button { font-family:Arial; font-size:12px; } small { font-size: 10px; }',
									button_text_top_padding: 0,
									button_text_left_padding: 18,
									button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
									button_cursor: SWFUpload.CURSOR.HAND,
									// Flash Settings
									flash_url : "/libs/swfupload/swfupload.swf",
									custom_settings : {
										progressTarget : "fsUploadProgress_video",
										cancelButtonId : "btnCancel_video"
									},
									// Debug Settings
									debug: false
								};	
								upload_video = new SWFUpload(settings);
							}
							
							
							
							if ($("#browseButton_event_images").length > 0)
							{
								var settings = {
									// Backend Settings
									upload_url: "/libs/swfupload/upload_event_images.php",
									post_params: {"page_id": answer.page_id[0], "session" : $("#browseButton_event_images").attr("rel")},
									// File Upload Settings
									file_size_limit : "1024",	// 50MB
									file_types : "*.jpg;",
									file_types_description : "Изображения",
									file_upload_limit : "0",
									file_queue_limit : "0",
									// Event Handler Settings - these functions as defined in Handlers.js
									//  The handlers are not part of SWFUpload but are part of my website and control how
									//  my website reacts to the SWFUpload events.
									file_queue_error_handler : fileQueueError,
									file_queued_handler : fileQueued,
									file_dialog_complete_handler : fileDialogComplete,
									upload_start_handler : uploadStart,
									upload_progress_handler : uploadProgress,
									upload_error_handler : uploadError,
									upload_success_handler : uploadSuccess_event_images,
									upload_complete_handler : uploadComplete,
									// Button Settings
									button_image_url : "/libs/swfupload/images/SmallSpyGlassWithTransperancy_17x18.png",
									button_placeholder_id : "browseButton_event_images",
									button_width: 180,
									button_height: 18,
									button_text : '<span class="button">Обзор... <small>(1 MB Max)</small></span>',
									button_text_style : '.button { font-family:Arial; font-size:12px; } small { font-size: 10px; }',
									button_text_top_padding: 0,
									button_text_left_padding: 18,
									button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
									button_cursor: SWFUpload.CURSOR.HAND,
									// Flash Settings
									flash_url : "/libs/swfupload/swfupload.swf",
									custom_settings : {
										progressTarget : "fsUploadProgress_event_images",
										cancelButtonId : "btnCancel_event_images"
									},
									// Debug Settings
									debug: false
								};	
								upload_event_images = new SWFUpload(settings);
							}
							
						
							$("#thumbnails").dragsort(
							{
								dragSelector: "li > div", 
								dragBetween: true, 
								placeHolderTemplate: "<div></div>",
								dragEnd: saveGalleryOrder
							});
						
							$.each($(".ul_attached_images .a_img_delete"), function ()
							{
								$(this).parent().mouseover(function()
								{
									$(this).children("a").css("display", "block");
								});
								$(this).parent().mouseout(function()
								{
									$(this).children("a").css("display", "none");
								});
							});
						
							$(".navi").slider({
								value: answer.gallery_offset[0],
								min: answer.gallery_min[0],
								max: answer.gallery_max[0],
								change: function(event, ui) 
								{
									makeRequest("getPageGallery", answer.page_id[0], ui.value, answer.gallery_min[0], answer.gallery_max[0]);
								},
								animate: "fast"
							});
							
							
							$.each($("#thumbnails_cover .a_img_delete"), function ()
							{
								$(this).parent().mouseover(function()
								{
									$(this).children("a").css("display", "block");
								});
								$(this).parent().mouseout(function()
								{
									$(this).children("a").css("display", "none");
								});
							});
							
							var n = 0;
							$.each($(".d_logic_group"), function()
							{
								if (n > 0)
								{
									$(this).css("height", "30px");
									$(this).css("overflow", "hidden");
									$(this).attr("rel", "closed");
								}
								else
								{
									$(this).attr("rel", "expanded");
								}
								$(this).find("h2").before("<div class=\"d_collapse_group\"></div>");
								$(this).find("h2").click(function()
								{
									toggleLogicGroup($(this));
								});
								n++;
							});
							
							$("#params_table").tableDnD({
								onDrop: function(table, row)
								{
            					makeRequest("sortParams", encodeURIComponent($.tableDnD.serialize()));
       						}
       					});
							//$("#right").jqTransform();
							
						}
						catch(e)
						{
						}
					}
				}
				else if (answer.callback[0] == "savePage")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
					}
					getObj("sendBtn").disabled = false;
					//tinyMCE.get('txt').setProgressState(false);
					$.tree.focused().refresh();					
				}
				
				else if (answer.callback[0] == "saveGalleryOrder")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						//alert(answer.content[0]);
					}
				}
				
				else if (answer.callback[0] == "getModules" || answer.callback[0] == "addModule")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						$("#right").html(answer.content[0]);
					}
				}
				
				
				
				else if (answer.callback[0] == "addCatalogField")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						$("#prod_params").html(answer.content[0]);
						
					}
				}
				
				
				
				else if (answer.callback[0] == "getGeo" || 
							answer.callback[0] == "addOkrug" || 
							answer.callback[0] == "addRegion" ||
							answer.callback[0] == "saveRegion" || 
							answer.callback[0] == "addCity" || 
							answer.callback[0] == "geoPutRegionIntoOkrug" ||
							answer.callback[0] == "geoPutCityIntoRegion")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						$("#right").html(answer.content[0]);
						
						$(".ul_geo li a[lvl='2']").draggable(
						{
							revert: "invalid",
							opacity: 0.55,
							drag: function(event, ui)
							{
								$(this).attr("was_dragged", "true"); 
							}
						});
						$(".ul_geo li[lvl='1']").droppable(
						{
							accept: ".ul_geo li a[lvl='2']",
							drop: function(event, ui)
							{ 
								var okr_id = $(this).attr("id");
								if (jConfirm("Вы уверены, что хотите переместить\n" + ui.draggable.attr("title") + " внутрь " + $(this).attr("title"), "Подтвердите перемещение", function(r)
								{
									if (r == true)
									{
										makeRequest("geoPutRegionIntoOkrug", ui.draggable.attr("id"), okr_id, ui.draggable.attr("s_okr"), ui.draggable.attr("s_reg"));
									}
									else
									{
										makeRequest("getGeo", ui.draggable.attr("s_okr"), ui.draggable.attr("s_reg"));
									}
								}));
							}
						});						
						/////
						$(".ul_geo li a[lvl='3']").draggable(
						{
							revert: "invalid",
							opacity: 0.55,
							drag: function(event, ui)
							{
								$(this).attr("was_dragged", "true"); 
							}
						});
						$(".ul_geo li[lvl='2']").droppable(
						{
							accept: ".ul_geo li a[lvl='3']",
							drop: function(event, ui)
							{ 
								var okr_id = $(this).attr("id");
								if (jConfirm("Вы уверены, что хотите переместить\n" + ui.draggable.attr("title") + " внутрь " + $(this).attr("title"), "Подтвердите перемещение", function(r)
								{
									if (r == true)
									{
										makeRequest("geoPutCityIntoRegion", ui.draggable.attr("id"), okr_id, ui.draggable.attr("s_okr"), ui.draggable.attr("s_reg"));
									}
									else
									{
										makeRequest("getGeo", ui.draggable.attr("s_okr"), ui.draggable.attr("s_reg"));
									}
								}));
							}
						});
					}
					$.each($(".ul_geo input[rel='sendBtn']"), function ()
					{
						$(this).attr("disabled", "")
					});
				}
				
				else if (answer.callback[0] == "getUsers" || answer.callback[0] == "addUser")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						$("#right").html(answer.content[0]);
						
						var current_date = new Date();
						var day = current_date.getDate();
						var month = current_date.getMonth() + 1;
						if (month < 10)
						{
							month = "0" + month.toString();
						}
						var year = current_date.getFullYear();
						$("#birthday").val(day + "." + month + "." + year);
						
						$("#birthday").DatePicker({
							format:'d.m.Y',
							date: current_date,
							view: "years",
							position: 'bottom',
							onBeforeShow: function(){
								$('#birthday').DatePickerSetDate($('#birthday').val(), true);
							},
							onChange: function(formated, dates){
								$('#birthday').val(formated);
							}
						});
					}
				}
				
				else if (answer.callback[0] == "getCitySelection")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						$("#" + answer.container[0]).html(answer.content[0]);
					}
				}
				
				
				else if (answer.callback[0] == "getRegionSelection")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						$("#" + answer.container[0]).html(answer.content[0]);
					}
				}
				
				
				else if (answer.callback[0] == "getUsersTable")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						$("#" + answer.container[0]).html(answer.content[0]);
					}
				}
				
				
				else if (answer.callback[0] == "getUserEditor")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						$.each($("tr[rel='user_line'] td"), function ()
						{
							$(this).css("display", "table-cell");
						});
						$.each($("td[rel='user_editor']"), function ()
						{
							$(this).css("display", "none");
						});
						$.each($("#user_line" + answer.user_id[0] + " td"), function ()
						{
							$(this).css("display", "none");
						});
						$("#user_editor" + answer.user_id[0]).css("display", "table-cell");
						$("#user_editor" + answer.user_id[0]).html(answer.content[0]);
						
						$("#birthday_" + answer.user_id[0]).DatePicker({
							format:'d.m.Y',
							date: $('#birthday_' + answer.user_id[0]).val(),
							view: "years",
							position: 'bottom',
							onBeforeShow: function(){
								$('#birthday_' + answer.user_id[0]).DatePickerSetDate($('#birthday_' + answer.user_id[0]).val(), true);
							},
							onChange: function(formated, dates){
								$('#birthday_' + answer.user_id[0]).val(formated);
							}
						});
					}
				}
				
				else if (answer.callback[0] == "updateUser")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						$.each($("tr[rel='user_line'] td"), function ()
						{
							$(this).css("display", "table-cell");
						});
						$.each($("td[rel='user_editor']"), function ()
						{
							$(this).css("display", "none");
						});
						//$("#" + answer.container[0]).html(answer.content[0]);
					}
				}
				
				else if (answer.callback[0] == "addEvent")
				{
					if (answer.system_error.length > 0)
					{	
						var error = "<ul>";	
						$.each(answer.system_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Системная ошибка");
					}
					else if (answer.user_error.length > 0)
					{
						var error = "<ul>";	
						$.each(answer.user_error, function()
						{
							error += "<li>" +  this + "</li>";
						});
						error += "</ul>";
						jAlert(error, "Ошибка");
					}
					else
					{
						makeRequest("getEditorArea", answer.page_id[0]);
						$.tree.focused().refresh();
					}
					$("#sendEventBtn").removeAttr("disabled");
				}
			}
			else
			{
				alert("Не удалось получить ответ от сервера");
			}
		}
	};


	$("#curtain").css("display", "block");
	//************** ОБРАБАТЫВАЕМ КЛИКИ
	var args = "";
	for (var i = 0; i < arguments.length; i++)
	{
		args += "&p" + i + "=" + arguments[i];
	}
	
	http_request.open('POST', "getAnswer.php", true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Connection", "close");	
	http_request.send("q=" + url + args);
}


function toggleLogicGroup(obj)
{
	if (obj.parent().attr("rel") == "closed")
	{
		obj.parent().css("height", "auto");
		obj.parent().css("overflow", "none");
		obj.parent().attr("rel", "expanded");
	}
	else
	{
		obj.parent().css("height", "30px");
		obj.parent().css("overflow", "hidden");
		obj.parent().attr("rel", "closed");
	}
}


function swfUploadLoaded(swf_upload_instance)
{

}




function addslashes (str)
{
    return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\u0000/g, "\\0");
}
function stripslashes (str)
{
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':
                return '\0';
            case '':
                return '';
            default:
                return n1;
        }
    });
}

function htmlspecialchars(str)
{
	return $('<span>').text(str).html();
}



function setupTinyMCE(id)
{
	tinyMCE.init({
		// General options
		editor_selector : "tinymce",		
		mode : "exact",
		elements: id,
		theme : "advanced",
		file_browser_callback : "tinyBrowser",
		force_br_newlines : true,
		forced_root_block : '',
		
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,tinyBrowser",
	
		// Theme options
		theme_advanced_buttons1 : "code,preview,cleanup,|,undo,redo,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,removeformat",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,|,image,media,",
		theme_advanced_buttons3 : "tablecontrols,|,hr,visualaid,|,sub,sup,|,charmap,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,pagebreak",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_blockformats : "h1,h2",
		theme_advanced_resizing : false,
		width: "100%",
		height: 400,
		
		apply_source_formatting : true,		
		
		relative_urls : true,
		remove_script_host : false,
		convert_urls : false,		
		document_base_url : "http://aurora.mainstudio.ru/",
		
		
		
		valid_elements : ""
		+"a[accesskey|charset|class|coords|dir<ltr?rtl|href|hreflang|id|lang|name"
		  +"|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup"
		  +"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|rel|rev"
		  +"|shape<circle?default?poly?rect|style|tabindex|title|target|type],"
		+"abbr[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"acronym[class|dir<ltr?rtl|id|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"address[class|align|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown"
		  +"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
		  +"|onmouseup|style|title],"
		+"applet[align<bottom?left?middle?right?top|alt|archive|class|code|codebase"
		  +"|height|hspace|id|name|object|style|title|vspace|width],"
		+"area[accesskey|alt|class|coords|dir<ltr?rtl|href|id|lang|nohref<nohref"
		  +"|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup"
		  +"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup"
		  +"|shape<circle?default?poly?rect|style|tabindex|title|target],"
		+"base[href|target],"
		+"basefont[color|face|id|size],"
		+"bdo[class|dir<ltr?rtl|id|lang|style|title],"
		+"big[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"blockquote[cite|class|dir<ltr?rtl|id|lang|onclick|ondblclick"
		  +"|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout"
		  +"|onmouseover|onmouseup|style|title],"
		+"body[alink|background|bgcolor|class|dir<ltr?rtl|id|lang|link|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onload|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|onunload|style|title|text|vlink],"
		+"br[class|clear<all?left?none?right|id|style|title],"
		+"button[accesskey|class|dir<ltr?rtl|disabled<disabled|id|lang|name|onblur"
		  +"|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup|onmousedown"
		  +"|onmousemove|onmouseout|onmouseover|onmouseup|style|tabindex|title|type"
		  +"|value],"
		+"caption[align<bottom?left?right?top|class|dir<ltr?rtl|id|lang|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|style|title],"
		+"center[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"cite[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"code[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"col[align<center?char?justify?left?right|char|charoff|class|dir<ltr?rtl|id"
		  +"|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown"
		  +"|onmousemove|onmouseout|onmouseover|onmouseup|span|style|title"
		  +"|valign<baseline?bottom?middle?top|width],"
		+"colgroup[align<center?char?justify?left?right|char|charoff|class|dir<ltr?rtl"
		  +"|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown"
		  +"|onmousemove|onmouseout|onmouseover|onmouseup|span|style|title"
		  +"|valign<baseline?bottom?middle?top|width],"
		+"dd[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup"
		  +"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],"
		+"del[cite|class|datetime|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown"
		  +"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
		  +"|onmouseup|style|title],"
		+"dfn[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"dir[class|compact<compact|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown"
		  +"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
		  +"|onmouseup|style|title],"
		+"div[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|style|title],"
		+"dl[class|compact<compact|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown"
		  +"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
		  +"|onmouseup|style|title],"
		+"dt[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup"
		  +"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],"
		+"em/i[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"fieldset[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"font[class|color|dir<ltr?rtl|face|id|lang|size|style|title],"
		+"form[accept|accept-charset|action|class|dir<ltr?rtl|enctype|id|lang"
		  +"|method<get?post|name|onclick|ondblclick|onkeydown|onkeypress|onkeyup"
		  +"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onreset|onsubmit"
		  +"|style|title|target],"
		+"frame[class|frameborder|id|longdesc|marginheight|marginwidth|name"
		  +"|noresize<noresize|scrolling<auto?no?yes|src|style|title],"
		+"frameset[class|cols|id|onload|onunload|rows|style|title],"
		+"h1[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|style|title],"
		+"h2[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|style|title],"
		+"h3[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|style|title],"
		+"h4[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|style|title],"
		+"h5[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick"
	
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|style|title],"
		+"h6[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|style|title],"
		+"head[dir<ltr?rtl|lang|profile],"
		+"hr[align<center?left?right|class|dir<ltr?rtl|id|lang|noshade<noshade|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|size|style|title|width],"
		+"html[dir<ltr?rtl|lang|version],"
		+"iframe[align<bottom?left?middle?right?top|class|frameborder|height|id"
		  +"|longdesc|marginheight|marginwidth|name|scrolling<auto?no?yes|src|style"
		  +"|title|width],"
		+"img[align<bottom?left?middle?right?top|alt|border|class|dir<ltr?rtl|height"
		  +"|hspace|id|ismap<ismap|lang|longdesc|name|onclick|ondblclick|onkeydown"
		  +"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
		  +"|onmouseup|src|style|title|usemap|vspace|width],"
		+"input[accept|accesskey|align<bottom?left?middle?right?top|alt"
		  +"|checked<checked|class|dir<ltr?rtl|disabled<disabled|id|ismap<ismap|lang"
		  +"|maxlength|name|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onselect"
		  +"|readonly<readonly|size|src|style|tabindex|title"
		  +"|type<button?checkbox?file?hidden?image?password?radio?reset?submit?text"
		  +"|usemap|value],"
		+"ins[cite|class|datetime|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown"
		  +"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
		  +"|onmouseup|style|title],"
		+"isindex[class|dir<ltr?rtl|id|lang|prompt|style|title],"
		+"kbd[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"label[accesskey|class|dir<ltr?rtl|for|id|lang|onblur|onclick|ondblclick"
		  +"|onfocus|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout"
		  +"|onmouseover|onmouseup|style|title],"
		+"legend[align<bottom?left?right?top|accesskey|class|dir<ltr?rtl|id|lang"
		  +"|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|style|title],"
		+"li[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup"
		  +"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title|type"
		  +"|value],"
		+"link[charset|class|dir<ltr?rtl|href|hreflang|id|lang|media|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|rel|rev|style|title|target|type],"
		+"map[class|dir<ltr?rtl|id|lang|name|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"menu[class|compact<compact|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown"
		  +"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
		  +"|onmouseup|style|title],"
		+"meta[content|dir<ltr?rtl|http-equiv|lang|name|scheme],"
		+"noframes[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"noscript[class|dir<ltr?rtl|id|lang|style|title],"
		+"object[align<bottom?left?middle?right?top|archive|border|class|classid"
		  +"|codebase|codetype|data|declare|dir<ltr?rtl|height|hspace|id|lang|name"
		  +"|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|standby|style|tabindex|title|type|usemap"
		  +"|vspace|width],"
		+"ol[class|compact<compact|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown"
		  +"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
		  +"|onmouseup|start|style|title|type],"
		+"optgroup[class|dir<ltr?rtl|disabled<disabled|id|label|lang|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|style|title],"
		+"option[class|dir<ltr?rtl|disabled<disabled|id|label|lang|onclick|ondblclick"
		  +"|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout"
		  +"|onmouseover|onmouseup|selected<selected|style|title|value],"
		+"p[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|style|title],"
		+"param[id|name|type|value|valuetype<DATA?OBJECT?REF],"
		+"pre/listing/plaintext/xmp[align|class|dir<ltr?rtl|id|lang|onclick|ondblclick"
		  +"|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout"
		  +"|onmouseover|onmouseup|style|title|width],"
		+"q[cite|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"s[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup"
		  +"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],"
		+"samp[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"script[charset|defer|language|src|type],"
		+"select[class|dir<ltr?rtl|disabled<disabled|id|lang|multiple<multiple|name"
		  +"|onblur|onchange|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup"
		  +"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|size|style"
		  +"|tabindex|title],"
		+"small[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"span[align<center?justify?left?right|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown"
		  +"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
		  +"|onmouseup|style|title],"
		+"strike[class|class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown"
		  +"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
		  +"|onmouseup|style|title],"
		+"strong/b[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"style[dir<ltr?rtl|lang|media|title|type],"
		+"sub[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"sup[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title],"
		+"table[align<center?left?right|bgcolor|border|cellpadding|cellspacing|class"
		  +"|dir<ltr?rtl|frame|height|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|rules"
		  +"|style|summary|title|width],"
		+"tbody[align<center?char?justify?left?right|char|class|charoff|dir<ltr?rtl|id"
		  +"|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown"
		  +"|onmousemove|onmouseout|onmouseover|onmouseup|style|title"
		  +"|valign<baseline?bottom?middle?top],"
		+"td[abbr|align<center?char?justify?left?right|axis|bgcolor|char|charoff|class"
		  +"|colspan|dir<ltr?rtl|headers|height|id|lang|nowrap<nowrap|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|rowspan|scope<col?colgroup?row?rowgroup"
		  +"|style|title|valign<baseline?bottom?middle?top|width],"
		+"textarea[accesskey|class|cols|dir<ltr?rtl|disabled<disabled|id|lang|name"
		  +"|onblur|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup"
		  +"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onselect"
		  +"|readonly<readonly|rows|style|tabindex|title],"
		+"tfoot[align<center?char?justify?left?right|char|charoff|class|dir<ltr?rtl|id"
		  +"|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown"
		  +"|onmousemove|onmouseout|onmouseover|onmouseup|style|title"
		  +"|valign<baseline?bottom?middle?top],"
		+"th[abbr|align<center?char?justify?left?right|axis|bgcolor|char|charoff|class"
		  +"|colspan|dir<ltr?rtl|headers|height|id|lang|nowrap<nowrap|onclick"
		  +"|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove"
		  +"|onmouseout|onmouseover|onmouseup|rowspan|scope<col?colgroup?row?rowgroup"
		  +"|style|title|valign<baseline?bottom?middle?top|width],"
		+"thead[align<center?char?justify?left?right|char|charoff|class|dir<ltr?rtl|id"
		  +"|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup|onmousedown"
		  +"|onmousemove|onmouseout|onmouseover|onmouseup|style|title"
		  +"|valign<baseline?bottom?middle?top],"
		+"title[dir<ltr?rtl|lang],"
		+"tr[rel|abbr|align<center?char?justify?left?right|bgcolor|char|charoff|class"
		  +"|rowspan|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title|valign<baseline?bottom?middle?top],"
		+"tt[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup"
		  +"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],"
		+"u[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress|onkeyup"
		  +"|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style|title],"
		+"ul[class|compact<compact|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown"
		  +"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
		  +"|onmouseup|style|title|type],"
		+"var[class|dir<ltr?rtl|id|lang|onclick|ondblclick|onkeydown|onkeypress"
		  +"|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|style"
		  +"|title]",
		
		
		// Example content CSS (should be your site CSS)
		content_css : "/style/style.css",
	
		// Drop lists for link/image/media/template dialogs
		
		//template_external_list_url : "js/template_list.js",
		//external_link_list_url : "js/link_list.js",
		//external_image_list_url : "js/image_list.js",
		//media_external_list_url : "js/media_list.js",
		
		language : "en"
	});
}



function saveGalleryOrder()
{
 	var data = Array();
 	i = 0;
	$("#thumbnails li").each(function(i, elm) 
	{
		data[i] = $(elm).attr("item_id");
	});
	
	makeRequest("saveGalleryOrder", data, $("#g_settings_offset").val(), $("#g_settings_step").val(), $("#g_settings_range").val(), $("#g_settings_page_id").val());
}




function initAddUserForm()
{
	$('#userManager').css('display', 'block');
}

function cancelUserEdit()
{
	$.each($("tr[rel='user_line'] td"), function ()
	{
		$(this).css("display", "table-cell");
	});
	$.each($("td[rel='user_editor']"), function ()
	{
		$(this).css("display", "none");
	});
}
