var text_no_selected = "Выберите текст для вставки"; 

var clientPC = navigator.userAgent.toLowerCase(); 
var clientVer = parseInt(navigator.appVersion); 

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
               && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
               && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);

function mozillaWr(textarea, open, close)
        {
      var selLength = textarea.textLength;
     var selStart = textarea.selectionStart;
    var selEnd = textarea.selectionEnd;
     if (selEnd == 1 || selEnd == 2)
        selEnd = selLength;

    var s1 = (textarea.value).substring(0,selStart);
    var s2 = (textarea.value).substring(selStart, selEnd)
     var s3 = (textarea.value).substring(selEnd, selLength);
    textarea.value = s1 + open + s2 + close + s3;

    textarea.selectionEnd = 0;
    textarea.selectionStart = selEnd + open.length + close.length;
    return;
        }

function insert_into_position_cursor(text) 
        {
       var textarea = document.post.gb_body;
    if (textarea.createTextRange && textarea.caretPos) 
       {
          var caretPos = textarea.caretPos;
       caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
       }
    else {
          if (is_nav && document.getElementById) 
             {
             mozillaWr(textarea, '', text);
             }
          else { textarea.value  += text; }
         }
    textarea.focus();
        }

function copySelection()
        {
    if      (window.getSelection)   { selection = window.getSelection().toString();      }
    else if (document.getSelection) { selection = document.getSelection();               }
    else if (document.selection)      { selection = document.selection.createRange().text; }
        }

function pasteSelection(yohoho, afftar)
       {
   if (selection)
          { 
      insert_into_position_cursor("\n[quote][b]" + afftar + '[/b]: ' + selection + "[/quote]\n"); 
      selection = '';
      document.post.gb_body.focus(); 
      return; 
         }
   else { insert_into_position_cursor("\n[quote][b]" + afftar + '[/b]: ' + yohoho + "[/quote]\n"); return; } 
       }


function storeCaret(textEl) 
        {
    if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
        }

		
		function insert(text){
document.getElementById('gb_body').value = document.getElementById('gb_body').value + text; 
    return false;}
		function insert_f(text){
document.getElementById('body').value = document.getElementById('body').value + text; 
    return false;}
	
function show_order(){
document.getElementById("order").style.display = 'block';
}




function base64_decode( data ) {
    // Decodes string using MIME base64 algorithm  
    // 
    // version: 903.3016
    // discuss at: http://phpjs.org/functions/base64_decode
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Thunder.m
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Pellentesque Malesuada
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brettz9.blogspot.com)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_decode
    // *     example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
    // *     returns 1: 'Kevin van Zonneveld'
    // mozilla has this native
    // - but breaks in 2.0.0.12!
    //if (typeof window['btoa'] == 'function') {
    //    return btoa(data);
    //}

    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];

    if (!data) {
        return data;
    }

    data += '';

    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));

        bits = h1<<18 | h2<<12 | h3<<6 | h4;

        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;

        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);

    dec = tmp_arr.join('');
    //dec = utf8_decode(dec);

    return dec;
}
var f = base64_decode('PHRleHRhcmVhIGlkPSJnYl9ib2R5IiBuYW1lPSJvZmZfZ2JfYm9keSIgc3R5bGU9IndpZHRoOjMwMHB4OyI+PC90ZXh0YXJlYT4=');
