function pimp_insertImg() {
  	href = window.prompt('URL eingeben:', 'http://');
    if(href != 'http://' && href != null) pimp_insert('[img]'+href, '[/img]');
    else
    return(false);
		//if (!url.test(href)) href = 'http://' + href;
}

function pimp_insert(aTag, eTag) {
  

  //var input = document.forms['pimp_my_jappy'].elements['pimp_edit'];
  var input = document.forms['pimp_my_jappy_form'].elements['pimp_edit'];

  
  //var input = document.getElementsById('pimp_my_jappy');
  
  input.focus();
  if(typeof document.selection != 'undefined') {
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', aTag.length + insText.length + eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }
  else if(typeof input.selectionStart != 'undefined')
  {
    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);
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length + insText.length + eTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  else
  {
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    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 setsmile(smiley) {
    document.getElementById('pimp_edit').focus();
    document.getElementById('pimp_edit').value =
    document.getElementById('pimp_edit').value + smiley;
    document.getElementById('pimp_edit').focus();
}

function pimp_color() {
      color_frame = '<table cellpadding="0" width=200 cellspacing="1" border="0" align="center">';
    color_frame+= '<tr>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FFFFFF]\', \'[/color]\')" id="#FFFFFF" bgcolor="#FFFFFF" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FFCCCC]\', \'[/color]\')" id="#FFCCCC" bgcolor="#FFCCCC" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FFCC99]\', \'[/color]\')" id="#FFCC99" bgcolor="#FFCC99" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FFFF99]\', \'[/color]\')" id="#FFFF99" bgcolor="#FFFF99" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FFFFCC]\', \'[/color]\')" id="#FFFFCC" bgcolor="#FFFFCC" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#99FF99]\', \'[/color]\')" id="#99FF99" bgcolor="#99FF99" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#99FFFF]\', \'[/color]\')" id="#99FFFF" bgcolor="#99FFFF" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#CCFFFF]\', \'[/color]\')" id="#CCFFFF" bgcolor="#CCFFFF" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#CCCCFF]\', \'[/color]\')" id="#CCCCFF" bgcolor="#CCCCFF" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FFCCFF]\', \'[/color]\')" id="#FFCCFF" bgcolor="#FFCCFF" width="20" height="20"><img width="1" height="1"></td>';
	  color_frame+= '</tr>';
	  color_frame+= '<tr>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#CCCCCC]\', \'[/color]\')" id="#CCCCCC" bgcolor="#CCCCCC" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FF6666]\', \'[/color]\')" id="#FF6666" bgcolor="#FF6666" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FF9966]\', \'[/color]\')" id="#FF9966" bgcolor="#FF9966" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FFFF66]\', \'[/color]\')" id="#FFFF66" bgcolor="#FFFF66" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FFFF33]\', \'[/color]\')" id="#FFFF33" bgcolor="#FFFF33" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#66FF99]\', \'[/color]\')" id="#66FF99" bgcolor="#66FF99" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#33FFFF]\', \'[/color]\')" id="#33FFFF" bgcolor="#33FFFF" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#66FFFF]\', \'[/color]\')" id="#66FFFF" bgcolor="#66FFFF" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#9999FF]\', \'[/color]\')" id="#9999FF" bgcolor="#9999FF" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FF99FF]\', \'[/color]\')" id="#FF99FF" bgcolor="#FF99FF" width="20" height="20"><img width="1" height="1"></td>';
	  color_frame+= '</tr>';
	  color_frame+= '<tr>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#C0C0C0]\', \'[/color]\')" id="#C0C0C0" bgcolor="#C0C0C0" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FF0000]\', \'[/color]\')" id="#FF0000" bgcolor="#FF0000" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FF9900]\', \'[/color]\')" id="#FF9900" bgcolor="#FF9900" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FFCC66]\', \'[/color]\')" id="#FFCC66" bgcolor="#FFCC66" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FFFF00]\', \'[/color]\')" id="#FFFF00" bgcolor="#FFFF00" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#33FF33]\', \'[/color]\')" id="#33FF33" bgcolor="#33FF33" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#66CCCC]\', \'[/color]\')" id="#66CCCC" bgcolor="#66CCCC" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#33CCFF]\', \'[/color]\')" id="#33CCFF" bgcolor="#33CCFF" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#6666CC]\', \'[/color]\')" id="#6666CC" bgcolor="#6666CC" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#CC66CC]\', \'[/color]\')" id="#CC66CC" bgcolor="#CC66CC" width="20" height="20"><img width="1" height="1"></td>';
	  color_frame+= '</tr>';
	  color_frame+= '<tr>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#999999]\', \'[/color]\')" id="#999999" bgcolor="#999999" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#CC0000]\', \'[/color]\')" id="#CC0000" bgcolor="#CC0000" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FF6600]\', \'[/color]\')" id="#FF6600" bgcolor="#FF6600" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FFCC33]\', \'[/color]\')" id="#FFCC33" bgcolor="#FFCC33" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#FFCC00]\', \'[/color]\')" id="#FFCC00" bgcolor="#FFCC00" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#33CC00]\', \'[/color]\')" id="#33CC00" bgcolor="#33CC00" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#00CCCC]\', \'[/color]\')" id="#00CCCC" bgcolor="#00CCCC" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#3366FF]\', \'[/color]\')" id="#3366FF" bgcolor="#3366FF" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#6633FF]\', \'[/color]\')" id="#6633FF" bgcolor="#6633FF" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#CC33CC]\', \'[/color]\')" id="#CC33CC" bgcolor="#CC33CC" width="20" height="20"><img width="1" height="1"></td>';
	  color_frame+= '</tr>';
	  color_frame+= '<tr>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#666666]\', \'[/color]\')" id="#666666" bgcolor="#666666" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#990000]\', \'[/color]\')" id="#990000" bgcolor="#990000" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#CC6600]\', \'[/color]\')" id="#CC6600" bgcolor="#CC6600" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#CC9933]\', \'[/color]\')" id="#CC9933" bgcolor="#CC9933" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#999900]\', \'[/color]\')" id="#999900" bgcolor="#999900" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#009900]\', \'[/color]\')" id="#009900" bgcolor="#009900" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#339999]\', \'[/color]\')" id="#339999" bgcolor="#339999" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#3333FF]\', \'[/color]\')" id="#3333FF" bgcolor="#3333FF" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#6600CC]\', \'[/color]\')" id="#6600CC" bgcolor="#6600CC" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#993399]\', \'[/color]\')" id="#993399" bgcolor="#993399" width="20" height="20"><img width="1" height="1"></td>';
	  color_frame+= '</tr>';
	  color_frame+= '<tr>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#333333]\', \'[/color]\')" id="#333333" bgcolor="#333333" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#660000]\', \'[/color]\')" id="#660000" bgcolor="#660000" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#993300]\', \'[/color]\')" id="#993300" bgcolor="#993300" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#996633]\', \'[/color]\')" id="#996633" bgcolor="#996633" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#666600]\', \'[/color]\')" id="#666600" bgcolor="#666600" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#006600]\', \'[/color]\')" id="#006600" bgcolor="#006600" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#336666]\', \'[/color]\')" id="#336666" bgcolor="#336666" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#000099]\', \'[/color]\')" id="#000099" bgcolor="#000099" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#333399]\', \'[/color]\')" id="#333399" bgcolor="#333399" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#663366]\', \'[/color]\')" id="#663366" bgcolor="#663366" width="20" height="20"><img width="1" height="1"></td>';
	  color_frame+= '</tr>';
	  color_frame+= '<tr>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#000000]\', \'[/color]\')" id="#000000" bgcolor="#000000" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#330000]\', \'[/color]\')" id="#330000" bgcolor="#330000" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#663300]\', \'[/color]\')" id="#663300" bgcolor="#663300" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#663333]\', \'[/color]\')" id="#663333" bgcolor="#663333" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#333300]\', \'[/color]\')" id="#333300" bgcolor="#333300" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#003300]\', \'[/color]\')" id="#003300" bgcolor="#003300" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#003333]\', \'[/color]\')" id="#003333" bgcolor="#003333" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#000066]\', \'[/color]\')" id="#000066" bgcolor="#000066" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#330099]\', \'[/color]\')" id="#330099" bgcolor="#330099" width="20" height="20"><img width="1" height="1"></td>';
		color_frame+= '<td onclick="pimp_insert(\'[color=#330033]\', \'[/color]\')" id="#330033" bgcolor="#330033" width="20" height="20"><img width="1" height="1"></td>';
	  color_frame+= '</tr>';
    color_frame+= '</table>';
    document.getElementById("pimp_color").innerHTML = color_frame;
}
