
/*
 * Mit dieser Funktion wird der BB-Code hinzugef�gt
 */

function insert(format, textarea) {
  var input = document.getElementById(textarea);

  input.focus();
  /* f�r Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einf�gen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    if(insText == "")
    {
        insText=prompt("Bitte Text eingeben","");
    }

    if(insText == "" || insText == null)
    {
        return;
    }

    range.text = '['+format+']' + insText + '[/'+format+']';
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -4);
    } else {
      range.moveStart('character', 3 + insText.length +4);
    }
    range.select();
  }
  /* f�r neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einf�gen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    if(insText == "")
    {
        if(format == "img")
        {
            insText=prompt("Bitte Bildurl eingeben","");
        }
        else
        {
            insText=prompt("Bitte Text eingeben","");
        }

    }

    if(insText == "" || insText == null)
    {
        return;
    }
    input.value = input.value.substr(0, start) + '['+format+']' + insText + '[/'+format+']' + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + 3;
    } else {
      if(format == "img")
      {
        pos = start + 3 + insText.length + 8;
      }
      else
      {
        pos = start + 3 + insText.length + 4;
      }

    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
}

/*
 * Mit dieser Funktion wird der BB-Code f�r Farbe hinzugef�gt
 */
function insert_color(textarea) {
  var input = document.getElementById(textarea);

  input.focus();
  /* f�r Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einf�gen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    if(insText == "")
    {
        insText=prompt("Bitte Text eingeben","");
    }

    var color = prompt("Bitte Farbe eingeben (Hex oder ausgeschrieben)","");

    if(insText == "" || insText == null)
    {
        return;
    }
    if(color == "" || color == null)
    {
        return;
    }
    else
    {
        range.text = '[color='+color+']' + insText + '[/color]';
    }

    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -8);
    } else {
      range.moveStart('character', 8+color.length + insText.length + 8);
    }
    range.select();
  }
  /* f�r neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einf�gen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    if(insText == "")
    {
        insText=prompt("Bitte Text eingeben","");
    }

    if(insText == "" || insText == null)
    {
        return;
    }
    var color = prompt("Bitte Farbe eingeben (Hex oder ausgeschrieben)","");

    if(insText == "" || insText == null)
    {
        return;
    }
    if(color == "" || color == null)
    {
        return;
    }
    else
    {
       input.value = input.value.substr(0, start) + '[color='+color+']' + insText + '[/color]' + input.value.substr(end);
    }

    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + color.length+9;
    } else {
      pos = start + color.length+9 + insText.length + 8;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
}

/*
 * Mit dieser Funktion wird der BB-Code f�r URL hinzugef�gt
 */

function insert_url(textarea) {
  var input = document.getElementById(textarea);

  input.focus();
  /* f�r Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einf�gen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    if(insText == "")
    {
        insText=prompt("Bitte Linknamen eingeben","");
    }

    var url = prompt("Bitte URL eingeben","");

    if(insText == "" || insText == null)
    {
        return;
    }
    if(url == "" || url == null)
    {
        return;
    }
    else
    {
        range.text = '[url='+url+']' + insText + '[/url]';
    }

    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -6);
    } else {
      range.moveStart('character', 6+url.length + insText.length + 6);
    }
    range.select();
  }
  /* f�r neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einf�gen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    if(insText == "")
    {
        insText=prompt("Bitte Linknamen eingeben","");
    }

    if(insText == "" || insText == null)
    {
        return;
    }
    var url = prompt("Bitte URL eingeben","");

    if(insText == "" || insText == null)
    {
        return;
    }
    if(url == "" || url == null)
    {
        return;
    }
    else
    {
       input.value = input.value.substr(0, start) + '[url='+url+']' + insText + '[/url]' + input.value.substr(end);
    }

    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + 5+url.length;
    } else {
      pos = start + 6+url.length + insText.length + 6;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
}



/**
* show_startext
* @param {string} text
*/
function show_startext(text) {
    $('star_text').innerHTML = text;
}

/**
* set_starrating
* @param {int} stars
*/
function set_starrating(id,stars) {

    var tmp_id ="";

    for (i=1; i<=5; i++)
    {
        tmp_id = 's'+i;
        $(tmp_id).className ="";
        $(tmp_id).style.Width ="20px";
    }

    $('s'+stars).style.width = stars*20+"px";
    $('s'+stars).className ="current-rating";

    $(id).value = stars;
}


/**
 * postaction
 * @param string action
 * @param string postid
 */
 function postaction(action,id) {
 	switch (action) {
 		case "freischalten":
 			    document.getElementById("gb1_"+id).className = "white";
 			    document.getElementById("gb2_"+id).className = "white";
 			    document.getElementById("gb3_"+id).className = "white";
 			break;
        case "zurueck":
                document.getElementById("gb1_"+id).className = "gelb";
                document.getElementById("gb2_"+id).className = "gelb";
                document.getElementById("gb3_"+id).className = "gelb";
            break;
 		case "loeschen":
                document.getElementById("gb1_"+id).style.display = "none";
                document.getElementById("gb2_"+id).style.display = "none";
                document.getElementById("gb3_"+id).style.display = "none";
            break;
 	}
 }