<?php
/*
=====================================================
 Модуль создал: REZER (http://rezer.net)
=====================================================
 Файл: functions.js.php
=====================================================
 Данный код защищен авторскими правами
=====================================================
 Назначение: Необходимые js функции
=====================================================
*/

if( !defined( "DATALIFEENGINE" ) ) die( "Hacking attempt!" );

if( version_compare( $config['version_id'], "8.3", ">" ) )
	$JSCat = "/engine/classes/js";
else
	$JSCat = "/engine/ajax";

function EchoAJAX( $Jquery = false ){
	global $JSCat;
	
	if( $Jquery )
		{

$return = <<<HTML
<link rel="stylesheet" type="text/css" href="engine/skins/default.css">
<link rel="stylesheet" type="text/css" href="engine/skins/jquery-ui.css">
<script type="text/javascript" src="engine/classes/js/jquery.js"></script>
<script type="text/javascript" src="engine/classes/js/jqueryui.js"></script>
HTML;
		}
	
return <<<HTML
{$return}
<script language="javascript" type="text/javascript">
	
	if( !UpdateUrl ) var UpdateUrl = "main";
	var UpdateButton = "<img src=\"engine/inc/board/style/images/ajax.png\" alt=\"Обновить\" title=\"Обновить\" style=\"cursor: pointer;\" onclick=\"UpdateList(); return false;\" border=\"0\" />";
	function UpdateList( url, otherData, result, preloder ){
		
		if( !url ) url = UpdateUrl;
		if( url == "main" && !otherData ) otherData = UpdateUrlMainData;
		if( preloder )
			{
				document.getElementById( preloder ).innerHTML = "<div style=\"padding: 30px; text-align: center;\"><img src=\"engine/inc/board/style/images/ajax_preloader.gif\" alt=\"Загрузка\" border=\"0\" /></div>";
			}
		
		document.getElementById( "UpdateStatus" ).innerHTML = "<img src=\"engine/inc/board/style/images/ajax.gif\" alt=\"Загрузка\" border=\"0\" />";
		
		$.ajax({
			url: "/engine/ajax/board/admin/list.update.php",
			data: otherData + "&action=" + url,
			success: function( data ){
				var idEcho = ( result ) ? result : url;
				$( "#" + idEcho ).html( data );
				document.getElementById( "UpdateStatus" ).innerHTML = "<img src=\"engine/inc/board/style/images/ajax.png\" alt=\"Обновить\" title=\"Обновить\" style=\"cursor: pointer;\" onclick=\"UpdateList(); return false;\" border=\"0\" />";
			},
			dataType: "html",
			type: "POST"
		});
		
	}
	
	function CleareCache(){
		
		document.getElementById( "cache_btn" ).value = "Очистить кэш...";
		$.ajax({
			url: "/engine/ajax/board/admin/other.options.php",
			data: "type=clear_cache",
			success: function( data ){
				document.getElementById( "cache_btn" ).value = "Очистить кэш (очищен)";
			},
			dataType: "html",
			type: "POST"
		});
		
	}
	
	function EmptyAlbum(){
		
		var title = document.getElementById( "new_album_name" ).value;
		var alt_name = document.getElementById( "new_album_alt_name" ).value;
		
		if( !title && !alt_name )
			{
				document.getElementById( "btn_empty_album" ).value = "Введите название";
				setTimeout( function(){
					document.getElementById( "btn_empty_album" ).value = "Проверить свободность";				 
				}, 1000 );
				return false;
			}
		
		var Album = ( !alt_name ) ? title : alt_name;
				
		$.ajax({
			url: "/engine/ajax/board/admin/other.options.php",
			data: "album=" + Album + "&type=empty_album",
			success: function( data ){
				$( "#empty_status" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function SetStatusAlbum( type, id ){
		
		document.getElementById( "album_status_" + id ).innerHTML = "<img src=\"engine/inc/board/style/images/mini-ajax.gif\" alt=\"Загрузка\" border=\"0\" />";
		
		$.ajax({
			url: "/engine/ajax/board/admin/other.options.php",
			data: "album_id=" + id + "&type=status_album&status=" + type,
			success: function( data ){
				$( "#album_status_" + id ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function DelAlbum( id ){
		
		var Quest = confirm( "Вы уверены, что хотите удалить данный альбом со всеми его фотографиями?" );
		if( Quest )
			{
				document.getElementById( "DelAlbum_" + id ).innerHTML = "<img src=\"engine/inc/board/style/images/ajax_preloader.gif\" alt=\"Удаление\" border=\"0\" />";
								
				$.ajax({
					url: "/engine/ajax/board/admin/other.options.php",
					data: "album_id=" + id + "&type=del_album",
					success: function( data ){
						$( "#DelAlbum_" + id ).html( data );
					},
					dataType: "html",
					type: "POST"
				});
			}
	}
		
	function SetFormSubmit( nameForm ){
		
		if( document.getElementById( "action_" + nameForm ).value == "" )
			{
				document.getElementById( "status_" + nameForm ).innerHTML = "<span style=\"color: #F00; font-weight: bold; text-decoration: blink;\">Выберите действие!</span>";
				setTimeout( function(){
					document.getElementById(  "status_" + nameForm ).innerHTML = "";				 
				}, 2000 );
			}
				else
			{
				if( document.getElementById( "action_" + nameForm ).value == "sort" )
					formSubmit( nameForm, "action.php", "status_" + nameForm, "status.gif", "status_" + nameForm, "UpdateStatus", UpdateButton );
				else
					formSubmit( nameForm, "action.php", nameForm, "status.gif", "status_" + nameForm, "UpdateStatus", UpdateButton );
			}
	}
	
	function formSubmit( nameForm, file, IdResult, img, imgId, onCompletion, onCompletionValue ){		
		
		if( !IdResult ) IdResult = "MassEdit";
		if( !img ) img = "ajax.gif";
		if( !imgId ) imgId = "MassEditLink";
		if( !file ) file = "massaction.php";
		
		var Url = "";
		var formSend = document.forms[ nameForm ];
		
		document.getElementById( imgId ).innerHTML = "<img src=\"engine/inc/board/style/images/" + img + "\" border=\"0\" alt=\"Загрузка\" />";
		
		for( var i=0; i < formSend.elements.length; i++ )
			{
				var radio = false;
				var ElementForm = formSend.elements[i];
				switch( ElementForm.type )
					{
						case "checkbox": {
							if( ElementForm.checked == true )
								{
									Url += "&" + ElementForm.name + "=" + ElementForm.value;
								}
							break
						}
						
						case "select-multiple": {
							for( var imultiple=0; imultiple < ElementForm.options.length; imultiple++ )
								{
									if ( ElementForm.options[imultiple].selected)
										{
											Url += "&" + ElementForm.name + "=" + ElementForm.options[imultiple].value;
										}
								}
							break
						}
						
						case "radio": {
							var radioObj = formSend[ ElementForm.name ];
							for( var imultiple=0; imultiple < radioObj.length; imultiple++ )
								{
									if ( radioObj[imultiple].checked == true )
										{
											Url += "&" + ElementForm.name + "=" + radioObj[imultiple].value;
											radio = true;
										}
								}
								
							// if( !radio ){ ajax.setVar( ElementForm.name, ajax.encodeVAR( ElementForm.value ) ); }
							break
						}
						
						case "hidden": {
							Url += "&" + ElementForm.name + "=" + ElementForm.value;
							break
						}
						
						case "text": {
							Url += "&" + ElementForm.name + "=" + ElementForm.value;
							break
						}
						
						default: {
							Url += "&" + ElementForm.name + "=" + ElementForm.value;
							break
						}
					}
			}
		
		$.ajax({
			url: "/engine/ajax/board/admin/" + file,
			data: Url,
			success: function( data ){
				$( "#" + IdResult ).html( data );
				if( onCompletion != null )
					{
						if( document.getElementById( onCompletion ) != null )
							{
								if( !onCompletionValue ) onCompletionValue = "";
								document.getElementById( onCompletion ).innerHTML = onCompletionValue;
							}
					}
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function getDocumentHeight(){
		return ( document.body.scrollHeight > document.body.offsetHeight ) ? document.body.scrollHeight : document.body.offsetHeight;

	}
	
	function getDocumentWidth(){
		return ( document.body.scrollWidth > document.body.offsetWidth ) ? document.body.scrollWidth  : document.body.offsetWidth;
	}
	
	function LeftWindow( width ){
		var DocumentWidth = document.body.offsetWidth;
		var ContentWidth = ( DocumentWidth / 100 ) * width;
		var Return = ( DocumentWidth - ContentWidth ) / 2;
		return Return;
	}
	
	function CheckboxAllSelect( form ){
		
		var SearchForm = document.forms[ form ];
		var Check = SearchForm.ChecboxAll.checked == true ? true : false;
		
		for( var i = 0; i < SearchForm.elements.length; i++ )
			{
				var ElementForm = SearchForm.elements[i];
				switch( ElementForm.type )
					{
						case "checkbox": {
							if( ElementForm.name != "ChecboxAll" ) ElementForm.checked = Check;
							break
						}
					}
			}
	}
	
	function AddBanners(){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Добавление баннера";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
		
		$.ajax({
			url: "/engine/ajax/board/admin/banners/add.banners.php",
			data: "",
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function EditBanners( id ){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Редактирование баннера";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
		
		$.ajax({
			url: "/engine/ajax/board/admin/banners/edit.banners.php",
			data: "id=" + id,
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function DelBanners( id ){
		
		var Quest = confirm( "Вы действительно желаете удалить данный баннер?" );
		if( Quest )
			{
				document.getElementById( "StatusIDBanners_" + id ).innerHTML = "<img src=\"engine/inc/board/style/images/mini-ajax.gif\" alt=\"...\" border=\"0\" />";
				
				$.ajax({
					url: "/engine/ajax/board/admin/banners/del.banners.php",
					data: "id=" + id,
					success: function( data ){
						$( "#del_Currency_" + id ).html( data );
						var Element = document.getElementById( "del_Banners_" + id );
						Element.parentNode.removeChild( Element );
					},
					dataType: "html",
					type: "POST"
				});				
			}
		
	}
	
	
	function AddBlocks(){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Добавление блока";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
				
		$.ajax({
			url: "/engine/ajax/board/admin/blocks/add.blocks.php",
			data: "",
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function EditBlocks( id ){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Редактирование блока";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
		
		$.ajax({
			url: "/engine/ajax/board/admin/blocks/edit.blocks.php",
			data: "id=" + id,
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function CodeBlocks( id ){
		prompt( "Вставьте данный код в шаблон:", "{include file=\"engine/modules/board/block.php?id=" + id + "\"}" );
	}
	
	function DelBlocks( id ){
		
		var Quest = confirm( "Вы действительно желаете удалить данный блок?" );
		if( Quest )
			{
				document.getElementById( "StatusIDBlocks_" + id ).innerHTML = "<img src=\"engine/inc/board/style/images/mini-ajax.gif\" alt=\"...\" border=\"0\" />";
				
				$.ajax({
					url: "/engine/ajax/board/admin/blocks/del.blocks.php",
					data: "id=" + id,
					success: function( data ){
						$( "#del_Currency_" + id ).html( data );
						var Element = document.getElementById( "del_Blocks_" + id );
						Element.parentNode.removeChild( Element );
					},
					dataType: "html",
					type: "POST"
				});				
			}
		
	}
	
	function AddBoardType(){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Добавление типа предложений";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
		
		$.ajax({
			url: "/engine/ajax/board/admin/board/add.board_type.php",
			data: "",
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
		
	}
	
	function EditBoardType( id ){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Редактирование типа предложений";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
		
		$.ajax({
			url: "/engine/ajax/board/admin/board/edit.board_type.php",
			data: "id=" + id,
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function DelBoardType( id ){
		
		var Quest = confirm( "Вы действительно желаете удалить данный тип предложений?" );
		if( Quest )
			{
				document.getElementById( "StatusIDBoardType_" + id ).innerHTML = "<img src=\"engine/inc/board/style/images/mini-ajax.gif\" alt=\"...\" border=\"0\" />";
				
				$.ajax({
					url: "/engine/ajax/board/admin/board/del.board_type.php",
					data: "id=" + id,
					success: function( data ){
						$( "#del_BoardType_" + id ).html( data );
						var Element = document.getElementById( "del_BoardType_" + id );
						Element.parentNode.removeChild( Element );
					},
					dataType: "html",
					type: "POST"
				});
			}
	}
	
	function AddCurrency(){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Добавление валюты";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
				
		$.ajax({
			url: "/engine/ajax/board/admin/currency/add.currency.php",
			data: "",
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function EditCurrency( id ){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Редактирование валюты";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
		
		$.ajax({
			url: "/engine/ajax/board/admin/currency/edit.currency.php",
			data: "id=" + id,
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function DelCurrency( id ){
		
		var Quest = confirm( "Вы действительно желаете удалить данную валюту?" );
		if( Quest )
			{
				document.getElementById( "StatusIDCurrency_" + id ).innerHTML = "<img src=\"engine/inc/board/style/images/mini-ajax.gif\" alt=\"...\" border=\"0\" />";
				
				$.ajax({
					url: "/engine/ajax/board/admin/currency/del.currency.php",
					data: "id=" + id,
					success: function( data ){
						$( "#del_Currency_" + id ).html( data );
						var Element = document.getElementById( "del_Currency_" + id );
						Element.parentNode.removeChild( Element );
					},
					dataType: "html",
					type: "POST"
				});				
			}
		
	}
	
	function AddCountry(){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Добавление страны";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
		
		$.ajax({
			url: "/engine/ajax/board/admin/country/add.country.php",
			data: "",
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function EditCountry( id ){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Редактирование страны";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
		
		$.ajax({
			url: "/engine/ajax/board/admin/country/edit.country.php",
			data: "id=" + id,
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function DelCountry( id ){
		
		var Quest = confirm( "Вы действительно желаете удалить данную страну со всеми её вложенными городами?" );
		if( Quest )
			{
				document.getElementById( "StatusCountryId_" + id ).innerHTML = "<img src=\"engine/inc/board/style/images/mini-ajax.gif\" alt=\"...\" border=\"0\" />";
				
				$.ajax({
					url: "/engine/ajax/board/admin/country/del.country.php",
					data: "id=" + id,
					success: function( data ){
						$( "#delCountry_" + id ).html( data );
						var Element = document.getElementById( "delCountry_" + id );
						Element.parentNode.removeChild( Element );
					},
					dataType: "html",
					type: "POST"
				});
			}
		
	}
	
	function AddCity(){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Добавление города";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
		
		$.ajax({
			url: "/engine/ajax/board/admin/city/add.city.php",
			data: "",
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function EditCity( id, country ){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Редактирование города";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
		
		$.ajax({
			url: "/engine/ajax/board/admin/city/edit.city.php",
			data: "id=" + id + "&country=" + country,
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function DelCity( id, country ){
		
		var Quest = confirm( "Вы действительно желаете удалить данный город?" );
		if( Quest )
			{
				document.getElementById( "StatusIDCity_" + id ).innerHTML = "<img src=\"engine/inc/board/style/images/mini-ajax.gif\" alt=\"...\" border=\"0\" />";
				
				$.ajax({
					url: "/engine/ajax/board/admin/city/del.city.php",
					data: "id=" + id + "&country=" + country,
					success: function( data ){
						$( "#del_City_" + id ).html( data );
						var Element = document.getElementById( "del_City_" + id );
						Element.parentNode.removeChild( Element );
					},
					dataType: "html",
					type: "POST"
				});
			}
		
	}
	
	function AddCategory(){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Добавление категории";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
		
		$.ajax({
			url: "/engine/ajax/board/admin/category/add.category.php",
			data: "",
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function EditCategory( id ){
		OpenCloseLightWindow();
		document.getElementById( "LightWindow-title" ).innerHTML = "Редактирование категории";
		document.getElementById( "LightWindow-content" ).innerHTML = "<div style=\"padding: 15px; text-align: center;\"><img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" /></div>";
		
		$.ajax({
			url: "/engine/ajax/board/admin/category/edit.category.php",
			data: "id=" + id,
			success: function( data ){
				$( "#LightWindow-content" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function AddField(){
		
		var OpenWindow = window.open( "{$PHP_SELF}?mod=board&action=field&show_action=add", "AddField", "toolbar=0, location=0, status=0, left=300, top=100, menubar=0, scrollbars=yes, resizable=0, width=700, height=405" );
		OpenWindow.focus();
	}
	
	function EditField( id ){
		
		var OpenWindow = window.open( "{$PHP_SELF}?mod=board&action=field&show_action=edit&id=" + id, "EditField_" + id, "toolbar=0, location=0, status=0, left=300, top=100, menubar=0, scrollbars=yes, resizable=0, width=700, height=405" );
		OpenWindow.focus();
		
	}
	
	function TagField( id ){
		
		var OpenWindow = window.open( "{$PHP_SELF}?mod=board&action=field&show_action=tag&id=" + id, "TagField_" + id, "toolbar=0, location=0, status=0, left=300, top=150, menubar=0, scrollbars=yes, resizable=0, width=700, height=265" );
		OpenWindow.focus();
		
	}
	
	function DelField( id ){
		
		var Quest = confirm( "Вы действительно желаете удалить данное поле?" );
		if( Quest )
			{
				document.getElementById( "StatusIDField_" + id ).innerHTML = "<img src=\"engine/inc/board/style/images/mini-ajax.gif\" alt=\"...\" border=\"0\" />";
								
				$.ajax({
					url: "/engine/ajax/board/admin/field/del.field.php",
					data: "id=" + id,
					success: function( data ){
						$( "#del_Field_" + id ).html( data );
						var Element = document.getElementById( "del_Field_" + id );
						Element.parentNode.removeChild( Element );
					},
					dataType: "html",
					type: "POST"
				});
			}
		
	}
	
	function DelBoardPost( id ){
		
		var Quest = confirm( "Вы действительно желаете удалить данное объявление со всеми его комментариями?" );
		if( Quest )
			{
				document.getElementById( "StatusIDBoardPost_" + id ).innerHTML = "<img src=\"engine/inc/board/style/images/mini-ajax.gif\" alt=\"...\" border=\"0\" />";
				
				$.ajax({
					url: "/engine/ajax/board/admin/board_post/del.board_post.php",
					data: "id=" + id,
					success: function( data ){
						$( "#del_BoardPost_" + id ).html( data );
						var Element = document.getElementById( "del_BoardPost_" + id );
						Element.parentNode.removeChild( Element );
					},
					dataType: "html",
					type: "POST"
				});
			}
	}
	
	function EditBoardPost( id ){
		
		var OpenWindow = window.open( "{$PHP_SELF}?mod=board&action=post_edit&id=" + id + "", "EditPost_" + id + "", "toolbar=0, location=0, status=0, left=200, top=50, menubar=0, scrollbars=yes, resizable=0, width=900, height=605" );
		OpenWindow.focus();
	}
	
	function ShowUser( id ){
		
		var OpenWindow = window.open('{$PHP_SELF}?mod=editusers&action=edituser&id=' + id,'User','toolbar=0,location=0,status=0, left=0, top=0, menubar=0,scrollbars=yes,resizable=0,width=540,height=500')
		OpenWindow.focus();
	}
	
	function SelectCountry(){
		
		var CountryID = document.getElementById( "SelectListCountry" ).value;
		document.getElementById( "SelectCity" ).disabled = true;
		document.getElementById( "FormSelectCityStatus" ).innerHTML = "<img src=\"engine/inc/board/style/images/arrow-ajax.gif\" alt=\"Загрузка...\" border=\"0\" align=\"absmiddle\" />";
				
		$.ajax({
			url: "/engine/ajax/board/set.country.php",
			data: "country_id=" + CountryID,
			success: function( data ){
				$( "#FormSelectCity" ).html( data );
			},
			dataType: "html",
			type: "POST"
		});
	}
	
	function CategorySelect(){
		BoardTypeSetCategory();
		BoardFieldsSetCategory();
	}
	
	function BoardTypeSetCategory(){
		
		var Select = "";
		var SelectCategory = document.getElementById( "BoardSelectCategory" ).value;
		var SelectType = document.getElementById( "BoardTypeSelect" ).value;
		for( var i = 0; i < BoardTypeCat[ SelectCategory ].length; i++ )
			{
				var id = BoardTypeCat[ SelectCategory ][ i ];
				var name = BoardTypeName[ id ];
				var selected = SelectType == id ? " selected=\"selected\"" : "";
				Select += "<option value=\"" + id + "\"" + selected + ">" + name + "</option>";
			}
		
		Select = "<select name=\"board_type\" id=\"BoardTypeSelect\">" + Select + "</select>";
		document.getElementById( "boardType" ).innerHTML = Select;
	}
	
	function BoardFieldsSetCategory(){
	
		var SelectCategory = document.getElementById( "BoardSelectCategory" ).value;
		var field_search = document.getElementById( "BoardFields" );
		var field_id = field_search.getElementsByTagName( "tr" );
		var count_field = field_id.length;
		for( var i = 0; i < count_field; i++ )
			{
				if( field_id[ i ] != null )
					{
						if( /BoardField_[0-9]/i.exec( field_id[ i ].id ) != null )
							{
								field_id[ i ].style['display'] = "none";
								var this_field_id = field_id[ i ].id.match( /[0-9]{1,50}/ );
								
								if( BoardFields[ SelectCategory ] != null )
									{
										for( var c = 0; c < BoardFields[ SelectCategory ].length; c++ )
											{
												if( this_field_id == BoardFields[ SelectCategory ][ c ] )
													{
														field_id[ i ].style['display'] = "";
													}
											}
									}
								
								if( field_id[ i ].style['display'] != "" && BoardFields['all'] != null )
									{
										for( var c = 0; c < BoardFields['all'].length; c++ )
											{
												if( this_field_id == BoardFields['all'][ c ] )
													{
														field_id[ i ].style['display'] = "";
													}
											}
									}
							}
					}
			}
	}
	
	var EchoCityListOk = new Array();
	function EchoCityList( country_id, clear ){
		
		if( clear == "yes" ) EchoCityListOk[ country_id ] = false;
		if( EchoCityListOk[ country_id ] !== true )
			{
				EchoCityListOk[ country_id ] = true;
				document.getElementById( "StatusUpdateCityList_" + country_id ).innerHTML = "<img src=\"engine/inc/board/style/images/load.gif\" alt=\"Идёт загрузка городов\" border=\"0\" />";
				UpdateList( "country", "country_id=" + country_id, "country_" + country_id );
			}
	}
	
</script>
HTML;

}

function ThisClose(){

return <<<HTML
<script language="javascript" type="text/javascript">

	function UpdateFields( NotClose ){
		
		window.opener.UpdateList( "fields" );
		if( !NotClose )
			{
				window.close();
				window.opener.focus();
			}
	}
	
	function CloseWindow( type ){
		
		UpdateList( type );
		setTimeout( function(){
			OpenCloseLightWindow();	 
		}, 1000 );
	}
	
	function CloseCityWindow( type ){
		
		UpdateList( "country", "country_id=" + type, "country_" + type );
		setTimeout( function(){
			OpenCloseLightWindow();	 
		}, 1000 );
	}

</script>
HTML;

}

function echoMenu(){
	global $JSCat;
	
return  <<<HTML
<script type="text/javascript" src="{$JSCat}/menu.js"></script>
<script language="javascript" type="text/javascript">

	function MenuBoardType( id ){
		
		var menu = new Array();
		
			menu[0] = "<a href=\"javascript:void(0);\" onclick=\"EditBoardType( '" + id + "' ); return false;\">Редактировать</a>";
			menu[1] = "<a href=\"javascript:void(0);\" onclick=\"DelBoardType( '" + id + "' ); return false;\">Удалить</a>";
			
		return menu;
	}
	
	function MenuCurrency( id ){
		
		var menu = new Array();
		
			menu[0] = "<a href=\"javascript:void(0);\" onclick=\"EditCurrency( '" + id + "' ); return false;\">Редактировать</a>";
			menu[1] = "<a href=\"javascript:void(0);\" onclick=\"DelCurrency( '" + id + "' ); return false;\">Удалить</a>";
			
		return menu;
	}
	
	function MenuCity( id, country ){
		
		var menu = new Array();
		
			menu[0] = "<a href=\"javascript:void(0);\" onclick=\"EditCity( '" + id + "', '" + country + "' ); return false;\">Редактировать</a>";
			menu[1] = "<a href=\"javascript:void(0);\" onclick=\"DelCity( '" + id + "', '" + country + "' ); return false;\">Удалить</a>";
			
		return menu;
	}
	
	function MenuCountry( id ){
		
		var menu = new Array();
		
			menu[0] = "<a href=\"javascript:void(0);\" onclick=\"EditCountry( '" + id + "' ); return false;\">Редактировать</a>";
			menu[1] = "<a href=\"javascript:void(0);\" onclick=\"DelCountry( '" + id + "' ); return false;\">Удалить</a>";
			
		return menu;
	}
	
	function MenuCategory( id ){
		
		var menu = new Array();
		
			menu[0] = "<a href=\"javascript:void(0);\" onclick=\"EditCategory( '" + id + "' ); return false;\">Редактировать</a>";
		return menu;
	}
	
	function MenuField( id ){
		
		var menu = new Array();
		
			menu[0] = "<a href=\"javascript:void(0);\" onclick=\"EditField( '" + id + "' ); return false;\">Редактировать</a>";
			menu[1] = "<a href=\"javascript:void(0);\" onclick=\"TagField( '" + id + "' ); return false;\">Получить тег</a>";
			menu[2] = "<a href=\"javascript:void(0);\" onclick=\"DelField( '" + id + "' ); return false;\">Удалить</a>";
			
		return menu;
	}
	
	function MenuBoardPost( id ){
		
		var menu = new Array();
		
			menu[0] = "<a href=\"javascript:void(0);\" onclick=\"EditBoardPost( '" + id + "' ); return false;\">Редактировать</a>";
			menu[1] = "<a href=\"javascript:void(0);\" onclick=\"DelBoardPost( '" + id + "' ); return false;\">Удалить</a>";
			
		return menu;
	}
	
	function MenuBanners( id ){
		
		var menu = new Array();
		
			menu[0] = "<a href=\"javascript:void(0);\" onclick=\"EditBanners( '" + id + "' ); return false;\">Редактировать</a>";
			menu[1] = "<a href=\"javascript:void(0);\" onclick=\"DelBanners( '" + id + "' ); return false;\">Удалить</a>";
			
		return menu;
	}
	
	function MenuBlocks( id ){
		
		var menu = new Array();
		
			menu[0] = "<a href=\"javascript:void(0);\" onclick=\"EditBlocks( '" + id + "' ); return false;\">Редактировать</a>";
			menu[1] = "<a href=\"javascript:void(0);\" onclick=\"CodeBlocks( '" + id + "' ); return false;\">Получить код</a>";
			menu[2] = "<a href=\"javascript:void(0);\" onclick=\"DelBlocks( '" + id + "' ); return false;\">Удалить</a>";
			
		return menu;
	}
	
</script>
HTML;
	
}


//----------------------------------------------------
//  Конструктор цвета
//----------------------------------------------------

function EchoJSColor(){

return <<<HTML

<link rel="stylesheet" href="engine/inc/board/js/color/colorpicker.css" type="text/css" />
<script type="text/javascript" src="engine/inc/board/js/color/colorpicker.js"></script>
<script type="text/javascript" src="engine/inc/board/js/color/eye.js"></script>
<script type="text/javascript" src="engine/inc/board/js/color/layout.js?ver=1.0.2"></script>

HTML;

}

//----------------------------------------------------
//  JQuery загрузка файла
//----------------------------------------------------

function EchoJQueryUpload(){

return <<<HTML

<script type="text/javascript" src="engine/inc/board/js/ajaxupload.3.5.js"></script>
<script language="JavaScript" type="text/javascript">
	
	var NotImgAlbum = "<table width=\"100%\" border=\"0\" style=\"margin: 4px 0px 0px 0px;\"><tr><td colspan=\"2\" background=\"engine/skins/images/mline.gif\" height=\"1\"></td></tr></table>";
	var CountImgAlbum = 0;
	
	function NewBtnToUpload( Btn, Status, Album ){
		$(function(){
			var btnUpload = $( "#" + Btn + "" );
			var status = $( "#" + Status + "" );
			new AjaxUpload( btnUpload, {
				action: "engine/ajax/board/admin/upload.php",
				name: 	"Filedata",
				
				data: {
	//				upload_name : $("[name=upload_name]").val(),
					album : Album,
				},
	
				onSubmit: function( file, ext ){
					 if( !( ext && /^(jpg|png|jpeg|gif|swf)$/.test( ext ) ) )
						{ 
							status.html( "<span style=\"color: #F00; font-weight: bold;\">Только JPG, PNG, GIF или SWF!</span>" );
							return false;
						}
						
					status.html( "<img src=\"engine/inc/board/style/images/preloader.gif\" alt=\"Загрузка...\" border=\"0\" />" );
				},
				
				onComplete: function( file, response ){
					
					if( CountImgAlbum == 0 ) document.getElementById( "images" ).innerHTML = NotImgAlbum;
					var id = Math.floor( Math.random() * ( 100 - 5 + 1 ) ) + 5;
					var Element = document.createElement( "div" );
					document.getElementById( "images" ).appendChild( Element );
					//Element.id = "img_" + id;
					Element.innerHTML = response;
					status.html( "" );
					CountImgAlbum++;
				}
			});
			
		});
	}
</script>

HTML;

}

function CalendarSetup(){
	
return <<<HTML
<link rel="stylesheet" type="text/css" media="all" href="engine/inc/board/style/calendar.css" />
<script type="text/javascript" src="engine/skins/calendar.js"></script>
<script type="text/javascript" src="engine/skins/calendar-en.js"></script>
<script type="text/javascript" src="engine/skins/calendar-setup.js"></script>
HTML;
	
}

function CalendarSearch(){
	
return <<<HTML
<link rel="stylesheet" type="text/css" media="all" href="engine/inc/board/style/calendar.css" />
<script type="text/javascript">
	
	Calendar.setup({
      inputField     :    "date_ot",     // id of the input field
      ifFormat       :    "%Y-%m-%d %H-%M-%S",      // format of the input field
      button         :    "date_ot_calendar",  // trigger for the calendar (button ID)
      align          :    "Br",           // alignment 
		  timeFormat     :    "24",
		  showsTime      :    true,
      singleClick    :    true
    });
	
	Calendar.setup({
      inputField     :    "date_do",     // id of the input field
      ifFormat       :    "%Y-%m-%d %H-%M-%S",      // format of the input field
      button         :    "date_do_calendar",  // trigger for the calendar (button ID)
      align          :    "Br",           // alignment 
		  timeFormat     :    "24",
		  showsTime      :    true,
      singleClick    :    true
    });
	
	Calendar.setup({
      inputField     :    "end_date_ot",     // id of the input field
      ifFormat       :    "%Y-%m-%d %H-%M-%S",      // format of the input field
      button         :    "end_date_ot_calendar",  // trigger for the calendar (button ID)
      align          :    "Br",           // alignment 
		  timeFormat     :    "24",
		  showsTime      :    true,
      singleClick    :    true
    });
	
	Calendar.setup({
      inputField     :    "end_date_do",     // id of the input field
      ifFormat       :    "%Y-%m-%d %H-%M-%S",      // format of the input field
      button         :    "end_date_do_calendar",  // trigger for the calendar (button ID)
      align          :    "Br",           // alignment 
		  timeFormat     :    "24",
		  showsTime      :    true,
      singleClick    :    true
    });

</script>
HTML;
	
}

function CalendarPostEdit(){
	
return <<<HTML
<link rel="stylesheet" type="text/css" media="all" href="engine/inc/board/style/calendar.css" />
<script type="text/javascript">
	
	Calendar.setup({
      inputField     :    "date",     // id of the input field
      ifFormat       :    "%Y-%m-%d %H:%M:%S",      // format of the input field
      button         :    "date_calendar",  // trigger for the calendar (button ID)
      align          :    "Br",           // alignment 
		  timeFormat     :    "24",
		  showsTime      :    true,
      singleClick    :    true
    });
	
	Calendar.setup({
      inputField     :    "end_date",     // id of the input field
      ifFormat       :    "%Y-%m-%d %H:%M:%S",      // format of the input field
      button         :    "end_date_calendar",  // trigger for the calendar (button ID)
      align          :    "Br",           // alignment 
		  timeFormat     :    "24",
		  showsTime      :    true,
      singleClick    :    true
    });
	
	Calendar.setup({
      inputField     :    "vip_date",     // id of the input field
      ifFormat       :    "%Y-%m-%d %H:%M:%S",      // format of the input field
      button         :    "vip_date_calendar",  // trigger for the calendar (button ID)
      align          :    "Br",           // alignment 
		  timeFormat     :    "24",
		  showsTime      :    true,
      singleClick    :    true
    });
	
	Calendar.setup({
      inputField     :    "super_vip_date",     // id of the input field
      ifFormat       :    "%Y-%m-%d %H:%M:%S",      // format of the input field
      button         :    "super_vip_date_calendar",  // trigger for the calendar (button ID)
      align          :    "Br",           // alignment 
		  timeFormat     :    "24",
		  showsTime      :    true,
      singleClick    :    true
    });
	
	Calendar.setup({
      inputField     :    "color_date",     // id of the input field
      ifFormat       :    "%Y-%m-%d %H:%M:%S",      // format of the input field
      button         :    "color_date_calendar",  // trigger for the calendar (button ID)
      align          :    "Br",           // alignment 
		  timeFormat     :    "24",
		  showsTime      :    true,
      singleClick    :    true
    });
	
</script>
HTML;
	
}

function LightWindow(){

return <<<HTML

<script type="text/javascript">

	var LightWindowWidth = 40;
	function LightWindowPosition(){
		
		var LightWindowBG = document.getElementById( "LightWindow-bg" );
		var LightWindowDisplay = document.getElementById( "LightWindowDisplay" );
		
		if( LightWindowBG.style['display'] != "none" )
			{
				LightWindowBG.style['height'] = getDocumentHeight() + "px";
				//LightWindowBG.style['width'] = getDocumentWidth() + "px";
				LightWindowDisplay.style['left'] = LeftWindow( LightWindowWidth ) + "px";
				LightWindowDisplay.style['width'] = LightWindowWidth + "%";
				setTimeout( "LightWindowPosition()", 10 );
				return true;
			}
		
		return false;
	}
	
	function OpenCloseLightWindow(){
		
		var LightWindowBG = document.getElementById( "LightWindow-bg" );
		var LightWindowDisplay = document.getElementById( "LightWindowDisplay" );
		
		// Открытие
		if( LightWindowBG.style['display'] == "none" )
			{
				LightWindowBG.onclick = new Function( "OpenCloseLightWindow()" );
				LightWindowBG.style['display'] = "";
				LightWindowDisplay.style['display'] = "";
				LightWindowPosition();			
			}
		// Закрытие
				else
			{
				LightWindowBG.style['display'] = "none";
				LightWindowDisplay.style['display'] = "none";
				LightWindowBG.onclick = "";
			}
		
	}
</script>
<div class="LightWindow-bg" id="LightWindow-bg" style="display: none;"></div>
<div class="LightWindow-content" id="LightWindowDisplay" style="display: none;">
	<a href="javascript:void(0);" class="close" onclick="OpenCloseLightWindow(); return false;" title="Закрыть">&nbsp;</a>
	<div class="WindowTitle" id="LightWindow-title"></div>
	<div id="LightWindow-content"></div>
</div>

HTML;
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  Создание доп. поля
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function FieldsType( $AllowType = array() ){
	
	$i = 0;
	$AllowShow = "";
	foreach( $AllowType as $type )
		{
			$AllowShow .= "AllowShowType[{$i}] = \"{$type}\";\n";
			$i++;
		}

return <<<HTML
<script language="JavaScript" type="text/javascript">
	var AllowShowType = new Array();
	$AllowShow
	
	function showtype(){
		
		var ThisShow = document.getElementById( "type" ).value;
		for( var i = 0; i < AllowShowType.length; i++ )
			{
				document.getElementById( "filed_" + AllowShowType[ i ] ).style['display'] = ThisShow == AllowShowType[ i ] ? "" : "none";
			}
	}
	
	function FieldRequired(){
		if( document.getElementById( "allow_edit" ).checked === true || document.getElementById( "show_create" ).checked === true )
			{
				document.getElementById( "required" ).disabled = false; 
			}
				else 
			{ 
				document.getElementById( "required" ).checked = false;
				document.getElementById( "required" ).disabled = true;
			}
	}
	
</script>
HTML;
} 

?>