jQuery(document).ready(function(){
    jQuery("#bug_button").click(function(){
        if(jQuery(".bug_panel").is(":hidden")){
            jQuery(".bug_panel").slideDown("fast");
        }
        else{
            jQuery(".bug_panel").slideUp("fast");
        }
    });

    jQuery('.corn-2-bg-2').mouseenter(function(){
        jQuery(this).find('.comment_bot_panel').show();
    });

    jQuery('.corn-2-bg-2').mouseleave(function(){
        jQuery(this).find('.comment_bot_panel').hide();
    });
});


function Delete(id)
{
    jQuery('#comment'+id).fadeOut("fast");
}

function insert(aTag, eTag,form) {
  var input;

  if (typeof form != 'undefined')
      input = document.forms['edit_form'+form].elements['data[Comment][comment]'];
  else
      input = document.forms['add_form'].elements['data[comment]'];

  input.focus();
  /* fur Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfugen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);
    }
    range.select();
  }
  /* fur neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfugen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* fur die ubrigen Browser */
  else
  {
    /* Abfrage der Einfugeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfugen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfugen des Formatierungscodes */
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}

function Citat(id)
{
    if (id != null && id != '0'){
        var citat = document.getElementById("comment_text"+id).innerHTML;
        //citat = citat.replace(/\s/gi,"");
        citat = citat.replace(/<blockquote>.*?<\/blockquote>/gi,"");
        citat = citat.replace(/<.*?>/gi,"");
        document.getElementById("comments_area_add").value += "[quote]"+citat+"[/quote]";
        document.getElementById("comments_area_add").focus();
        Answer(id,false);
    }
}

function Edit(id,here)
{
    makePOSTRequest(here,'comment_edit='+id);
}

function Answer(id,b){
    document.getElementById('comment_pid').value = id;
    document.getElementById('otvet_cancel').style.display = 'block';
    if (b != false)
        Citat(id);
}
