<?PHP
if(!defined('DATALIFEENGINE'))
{
  die("Hacking attempt!");
}
if ($user_group[$member_id['user_group']]['allow_image_upload']){$image_upload = "<div class=\"editor_button\" onclick=image_upload()><img title=\"$lang[bb_t_up]\" src=\"system/skins/bbcodes/images/upload.gif\" width=\"23\" height=\"25\" border=\"0\"></div>";
}else $image_upload = "";

if ($mod != "editnews") {$row['autor'] = $member_id['name'];}
$p_name = urlencode($row['autor']);

$bb_code = <<<HTML
<SCRIPT type=text/javascript>
<!--
var uagent    = navigator.userAgent.toLowerCase();
var is_safari = ( (uagent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc.") );
var is_opera  = (uagent.indexOf('opera') != -1);
var is_ie     = ( (uagent.indexOf('msie') != -1) && (!is_opera) && (!is_safari) );
var is_ie4    = ( (is_ie) && (uagent.indexOf("msie 4.") != -1) );

var is_win    =  ( (uagent.indexOf("win") != -1) || (uagent.indexOf("16bit") !=- 1) );
var ua_vers   = parseInt(navigator.appVersion);
	
var text_enter_url       = "$lang[bb_url]";
var text_enter_size       = "$lang[bb_flash]";
var text_enter_flash       = "$lang[bb_flash_url]";
var text_enter_page      = "$lang[bb_page]";
var text_enter_url_name  = "$lang[bb_url_name]";
var text_enter_page_name = "$lang[bb_page_name]";
var text_enter_image    = "$lang[bb_image]";
var text_enter_email    = "$lang[bb_email]";
var text_code           = "$lang[bb_code]";
var text_quote          = "$lang[bb_quote]";
var error_no_url        = "$lang[bb_no_url]";
var error_no_title      = "$lang[bb_no_title]";
var error_no_email      = "$lang[bb_no_email]";
var prompt_start        = "$lang[bb_prompt_start]";
var img_title   		= "$lang[bb_img_title]";
var email_title  	    = "$lang[bb_email_title]";

var ie_range_cache = '';

var selField  = "short_story";
var bbtags   = new Array();
var fombj    = document.forms[0];

function setFieldName(which)
{
            if (which != selField)
            {
                selField = which;
            }
}


function simpletag(thetag)
{
	doInsert("[" + thetag + "]", "[/" + thetag + "]", true);
}

function tag_url()
{
    var FoundErrors = '';
    var thesel = get_sel(eval('fombj.'+ selField))

    if (!thesel) {
        thesel ='My Webpage';
    }

    var enterURL   = prompt(text_enter_url, "http://");
    var enterTITLE = prompt(text_enter_url_name, thesel);

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }
    if (!enterTITLE) {
        FoundErrors += " " + error_no_title;
    }

    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }

	doInsert("[url="+enterURL+"]"+enterTITLE+"[/url]", "", false);
}


function tag_video()
{
    var FoundErrors = '';

	var thesel = get_sel(eval('fombj.'+ selField))

    if (!thesel) {
        thesel ='http://';
    }

    var enterURL = prompt(text_enter_url, thesel);

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }

    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }

	doInsert("[video="+enterURL+"]", "", false);
}

function tag_audio()
{
    var FoundErrors = '';

	var thesel = get_sel(eval('fombj.'+ selField))

    if (!thesel) {
        thesel ='http://';
    }

    var enterURL = prompt(text_enter_url, thesel);

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }

    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }

	doInsert("[audio="+enterURL+"]", "", false);
}

function tag_media()
{
    var FoundErrors = '';

	var thesel = get_sel(eval('fombj.'+ selField))

    if (!thesel) {
        thesel ='http://';
    }

    var enterURL = prompt(text_enter_url, thesel);

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }

    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }

	doInsert("[media="+enterURL+"]", "", false);
}

function tag_kp()
{
    var FoundErrors = '';

	var thesel = get_sel(eval('fombj.'+ selField))

    if (!thesel) {
        thesel ='';
    }

    var enterURL = prompt("ID Kinopoisk", thesel);

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }

    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }

	doInsert("[center][kp="+enterURL+"][/center]", "", false);
}

function tag_game(){var a="",b="";(b=ua_vers>=4&&is_ie&&is_win?document.selection.createRange().text:"")||(b="");(b=prompt("Insert Game ID",b))||(a+=" "+error_no_url);a?alert("Error!"+a):doInsert("[center][game="+b+"][/center]","",false)}

function tag_flash()
{
    var FoundErrors = '';
    var enterURL   = prompt(text_enter_flash, "http://");

    var size = prompt(text_enter_size, "425,264");

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }

    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }


	doInsert("[flash="+size+"]"+enterURL+"[/flash]", "", false);

}

function tag_image()
{
    var FoundErrors = '';
    var enterURL   = prompt(text_enter_image, "http://");

    var Title = prompt(img_title, "{$config['image_align']}");

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }

    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }

if (Title == "")
           {
	doInsert("[img]"+enterURL+"[/img]", "", false);
           }
else {
if (Title == "center") {
	doInsert("[center][img]"+enterURL+"[/img][/center]", "", false);
}
else {
	doInsert("[img="+Title+"]"+enterURL+"[/img]", "", false);
	}
 }
}

function tag_email()
{
    var emailAddress = prompt(text_enter_email, "");

    if (!emailAddress) { 
		alert(error_no_email); 
		return; 
	}

	var thesel = get_sel(eval('fombj.'+ selField))

    if (!thesel) {
        thesel ='';
    }

	var Title = prompt(email_title, thesel);

if (!Title) Title = emailAddress;

	doInsert("[email="+emailAddress+"]"+Title+"[/email]", "", false);
}

function doInsert(ibTag, ibClsTag, isSingle)
{
	var isClose = false;
	var obj_ta = eval('fombj.'+ selField);

	if ( (ua_vers >= 4) && is_ie && is_win)
	{
		if (obj_ta.isTextEdit)
		{
			obj_ta.focus();
			var sel = document.selection;
			var rng = ie_range_cache ? ie_range_cache : sel.createRange();
			rng.colapse;
			if((sel.type == "Text" || sel.type == "None") && rng != null)
			{
				if(ibClsTag != "" && rng.text.length > 0)
					ibTag += rng.text + ibClsTag;
				else if(isSingle)
					ibTag += rng.text + ibClsTag;
	
				rng.text = ibTag;
			}
		}
		else
		{
				obj_ta.value += ibTag + ibClsTag;
			
		}
		rng.select();
	ie_range_cache = null;

	}
	else if ( obj_ta.selectionEnd )
	{ 
		var ss = obj_ta.selectionStart;
		var st = obj_ta.scrollTop;
		var es = obj_ta.selectionEnd;
		
		if (es <= 2)
		{
			es = obj_ta.textLength;
		}
		
		var start  = (obj_ta.value).substring(0, ss);
		var middle = (obj_ta.value).substring(ss, es);
		var end    = (obj_ta.value).substring(es, obj_ta.textLength);
		
		if (obj_ta.selectionEnd - obj_ta.selectionStart > 0)
		{
			middle = ibTag + middle + ibClsTag;
		}
		else
		{
			middle = ibTag + middle + ibClsTag;
		}
		
		obj_ta.value = start + middle + end;
		
		var cpos = ss + (middle.length);
		
		obj_ta.selectionStart = cpos;
		obj_ta.selectionEnd   = cpos;
		obj_ta.scrollTop      = st;


	}
	else
	{
		obj_ta.value += ibTag + ibClsTag;
	}

	obj_ta.focus();
	return isClose;
}

function ins_color( buttonElement )
{
	document.getElementById(selField).focus();

	if ( is_ie )
	{
		document.getElementById(selField).focus();
		ie_range_cache = document.selection.createRange();
	}

	$("#cp").remove();

	$("body").append("<div id='cp' title='Цвет' style='display:none'><br /><iframe width=\"154\" height=\"104\" src=\"system/skins/bbcodes/color.html\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"></iframe></div>");

	$('#cp').dialog({
		autoOpen: true,
		width: 180
	});
}
function setColor(color)
{
	doInsert("[color=" +color+ "]", "[/color]", true );
	$('#cp').dialog("close");
}

function image_upload(){window.open('?mod=files&action=quick&area=' + selField + '&author={$p_name}&news_id={$id}', '_Addimage', 'toolbar=0,location=0,status=0, left=0, top=0, menubar=0,scrollbars=yes,resizable=0,width=640,height=550')}

function insert_font(value, tag)
{
    if (value == 0)
    {
    	return;
	} 

	if ( doInsert("[" +tag+ "=" +value+ "]", "[/" +tag+ "]", true ) )
    fombj.bbfont.selectedIndex  = 0;
    fombj.bbsize.selectedIndex  = 0;
}

function spoiler() {var FoundErrors = '';var spoiler = prompt("Введите название спойлера"); if (!spoiler){FoundErrors += " ";} if(FoundErrors){alert("ошибка!"+FoundErrors);return;} doInsert("[spoiler="+spoiler+"][/spoiler]", "", false); }

function get_sel(obj){

 if (document.selection)
 {

   if ( is_ie )
   {
		document.getElementById(selField).focus();
		ie_range_cache = document.selection.createRange();
   }

   var s = document.selection.createRange();
   if (s.text)
   {
	 return s.text;
   }
 }
 else if (typeof(obj.selectionStart)=="number")
 {
   if (obj.selectionStart!=obj.selectionEnd)
   {
     var start = obj.selectionStart;
     var end = obj.selectionEnd;
	 return (obj.value.substr(start,end-start));
   }
 }

 return false;

};
-->
</SCRIPT>
<div style="width:98%; height:50px; border:1px solid #BBB; background-image:url('system/skins/bbcodes/images/bg.gif');">
<div id="b_b" class="editor_button" onclick="simpletag('b')"><img title="$lang[bb_t_b]" src="system/skins/bbcodes/images/b.gif" width="23" height="25" border="0"></div>
<div id="b_i" class="editor_button" onclick="simpletag('i')"><img title="$lang[bb_t_i]" src="system/skins/bbcodes/images/i.gif" width="23" height="25" border="0"></div>
<div id="b_u" class="editor_button" onclick="simpletag('u')"><img title="$lang[bb_t_u]" src="system/skins/bbcodes/images/u.gif" width="23" height="25" border="0"></div>
<div id="b_s" class="editor_button" onclick="simpletag('s')"><img title="$lang[bb_t_s]" src="system/skins/bbcodes/images/s.gif" width="23" height="25" border="0"></div>
<div class="editor_button"><img src="system/skins/bbcodes/images/brkspace.gif" width="5" height="25" border="0"></div>
<div class="editor_button" onclick=tag_image()><img title="$lang[bb_b_img]" src="system/skins/bbcodes/images/image.gif" width="23" height="25" border="0"></div>
{$image_upload}
<div class="editor_button"><img src="system/skins/bbcodes/images/brkspace.gif" width="5" height="25" border="0"></div>
<div class="editor_button"  onclick="tag_url()"><img title="$lang[bb_t_url]" src="system/skins/bbcodes/images/link.gif" width="23" height="25" border="0"></div>
<div class="editor_button"  onclick="tag_email()"><img title="$lang[bb_t_m]" src="system/skins/bbcodes/images/email.gif" width="23" height="25" border="0"></div>
<div class="editor_button"><img src="system/skins/bbcodes/images/brkspace.gif" width="5" height="25" border="0"></div>
<div class="editor_button" onclick="tag_video()"><img title="$lang[bb_t_video]" src="system/skins/bbcodes/images/mp.gif" width="23" height="25" border="0"></div>
<div class="editor_button" onclick="tag_audio()"><img src="system/skins/bbcodes/images/mp3.gif" width="23" height="25" border="0"></div>
<div class="editor_button"><img src="system/skins/bbcodes/images/brkspace.gif" width="5" height="25" border="0"></div>
<div id="b_color" class="editor_button" onclick="ins_color(this);"><img src="system/skins/bbcodes/images/color.gif" width="23" height="25" border="0"></div>
<div class="editor_button"><img src="system/skins/bbcodes/images/brkspace.gif" width="5" height="25" border="0"></div>
<div id="b_flash" class="editor_button" onclick="tag_flash()"><img src="system/skins/bbcodes/images/flash.gif" width="23" height="25" border="0"></div>
<div id="b_youtube" class="editor_button" onclick="tag_media()"><img src="system/skins/bbcodes/images/youtube.gif" width="23" height="25" border="0"></div>
<div><img src="system/skins/bbcodes/images/brkspace.gif" width="5" height="25" border="0"></div>
<div class="editor_button" style="padding-top:3px;width:140px;"><select name="bbfont" onchange="insert_font(this.options[this.selectedIndex].value, 'font')"><option value='0'>{$lang['bb_t_font']}</option><option value='Arial'>Arial</option><option value='Arial Black'>Arial Black</option><option value='Century Gothic'>Century Gothic</option><option value='Courier New'>Courier New</option><option value='Georgia'>Georgia</option><option value='Impact'>Impact</option><option value='System'>System</option><option value='Tahoma'>Tahoma</option><option value='Times New Roman'>Times New Roman</option><option value='Verdana'>Verdana</option></select></div>
<div class="editor_button" style="padding-top:3px;width:70px;"><select name="bbsize" onchange="insert_font(this.options[this.selectedIndex].value, 'size')"><option value='0'>{$lang['bb_t_size']}</option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option></select></div>
<div class="editor_button"><img src="system/skins/bbcodes/images/brkspace.gif" width="5" height="25" border="0"></div>
<div id="b_left" class="editor_button" onclick="simpletag('left')"><img title="$lang[bb_t_l]" src="system/skins/bbcodes/images/l.gif" width="23" height="25" border="0"></div>
<div id="b_center" class="editor_button" onclick="simpletag('center')"><img title="$lang[bb_t_c]" src="system/skins/bbcodes/images/c.gif" width="23" height="25" border="0"></div>
<div id="b_right"class="editor_button" onclick="simpletag('right')"><img title="$lang[bb_t_r]" src="system/skins/bbcodes/images/r.gif" width="23" height="25" border="0"></div>
<div class="editor_button"><img src="system/skins/bbcodes/images/brkspace.gif" width="5" height="25" border="0"></div>
<div id="b_quote" class="editor_button" onclick="simpletag('quote')"><img title="$lang[bb_t_quote]" src="system/skins/bbcodes/images/quote.gif" width="23" height="25" border="0"></div>
<div id="b_screens" class="editor_button"  onclick="simpletag('screens')"><img title="Скриншоты" src="system/skins/bbcodes/images/screens.gif" width="23" height="25" border="0"></div>
<div id="b_hide" class="editor_button" onclick="simpletag('hide')"><img title="$lang[bb_t_hide]" src="system/skins/bbcodes/images/hide.gif" width="23" height="25" border="0"></div>
<div id="b_code" class="editor_button" onclick="simpletag('code')"><img title="$lang[bb_t_code]" src="system/skins/bbcodes/images/code.gif" width="23" height="25" border="0"></div>
<div class="editor_button"><img src="system/skins/bbcodes/images/brkspace.gif" width="5" height="25" border="0"></div>
<div id="b_spoiler" class="editor_button" onclick="spoiler()"><img src="system/skins/bbcodes/images/spoiler.gif" width="23" height="25" border="0"></div>
<div class="editor_button" onclick="tag_kp()"><img title="Рейтинг КиноПоиска" src="system/skins/bbcodes/images/rating.gif" width="23" height="25" border="0"></div>
<div class="editor_button"><img src="system/skins/bbcodes/images/brkspace.gif" width="5" height="25" border="0"></div>
</div>
HTML;
?>