function bb_code (object_id, bbcode) {

	var object_p = document.getElementById (object_id);
	object_p.focus();

	if (document.selection) {

	    var selection_p = document.selection.createRange();
	    selection_p.text = '[' + bbcode + ']' + selection_p.text + '[/' + bbcode + ']';

	} else if (typeof(object_p.selectionStart) == "number") {

	    if (object_p.selectionStart!=object_p.selectionEnd) {
	        var start = object_p.selectionStart;
	        var end = object_p.selectionEnd;

	        var rs = '[' + bbcode + ']' + object_p.value.substr(start, end-start) + '[/' + bbcode + ']';
			object_p.value = object_p.value.substr(0, start) + rs + object_p.value.substr(end);
		}

	}

	object_p.focus();

}

function bb_url (object_id) {

	var object_p = document.getElementById (object_id);
	object_p.focus();

    var prompt_link = "Ââåäèòå àäðåñ ññûëêè (Input target url)";
    var prompt_text = "Ââåäèòå çàãîëîâîê ññûëêè (Input target title)";

	if (document.selection) {

	    var selection_p = document.selection.createRange();
	    var text = selection_p.text;

	    var url_link = prompt (prompt_link, (text == "") ? "http://" : text);
	    var url_text = prompt (prompt_text, '');

	    selection_p.text = '[url=' + url_link + ']' + url_text + '[/url]';

	} else if (typeof(object_p.selectionStart) == "number") {

        var start = object_p.selectionStart;
        var end = object_p.selectionEnd;

        var text = object_p.value.substr(start, end-start);

        var url_link = prompt (prompt_link, (text == "") ? "http://" : text);
        var url_text = prompt (prompt_text, '');

        object_p.value = object_p.value.substr(0, start) + '[url=' + url_link + ']' + url_text + '[/url]' + object_p.value.substr(end);

	}

}

function bb_image (object_id) {

	var object_p = document.getElementById (object_id);
	object_p.focus();

    var prompt_link = "Ââåäèòå àäðåñ êàðòèíêè (Input image url)";
    var prompt_text = "Ââåäèòå êðàòêîå îïèñàíèå êàðòèíêè (Input image short description)";

	if (document.selection) {

	    var selection_p = document.selection.createRange();
	    var text = selection_p.text;

	    var url_link = prompt (prompt_link, (text == "") ? "http://" : text);
	    var url_text = prompt (prompt_text, '');

	    selection_p.text = '[img alt="' + url_text + '"]' + url_link + '[/img]';

	} else if (typeof(object_p.selectionStart) == "number") {

        var start = object_p.selectionStart;
        var end = object_p.selectionEnd;

        var text = object_p.value.substr(start, end-start);

        var url_link = prompt (prompt_link, (text == "") ? "http://" : text);
        var url_text = prompt (prompt_text, '');

        object_p.value = object_p.value.substr(0, start) + '[img alt="' + url_text + '"]' + url_link + '[/img]' + object_p.value.substr(end);

	}

}

function quote(objc){
    var name = document.selection.createRange();
	var input = objc;
	if (name.text!="") input.value = input.value + "[quote]" + name.text + "[/quote]";
}


function toggleLine(obj) {
   if (obj.style.display == "none") { obj.style.display = ""; } else { obj.style.display = "none"; };
}

function message_onload () {
	setTimeout('message_change(255)', 1000);
}

function message_change (i) {
	mb = document.getElementById('message-box');
    ii = i - 1;
    j = 220 - 20 * (ii-220)/35;
    mb.style.background = 'rgb('+j+','+j+','+ii+')';
   	if (i > 220) setTimeout('message_change('+ii+')', 20);
}
