//based on TinyMce color map plugin - modified by wooya
function showMapColor(color, mapId) {
    document.getElementById("selectedMapColor" + mapId).style.backgroundColor = color;
    document.getElementById("selectedMapColorBox" + mapId).value = color;
}
//based on TinyMce color map plugin - modified by wooya
function ColorMap(elname, formname) {
	var html = "";
	var colors = new Array(
		"#cccc00","#cccc33","#cccc66","#cccc99","#cccccc","#ccccff","#ffcc00","#ffcc33",
		"#ffcc66","#ffcc99","#ffcccc","#ffccff","#00ff00","#00ff33","#00ff66","#00ff99",
		"#00ffcc","#00ffff","#33ff00","#33ff33","#33ff66","#33ff99","#33ffcc","#33ffff",
		"#66ff00","#66ff33","#66ff66","#66ff99","#66ffcc","#66ffff","#99ff00","#99ff33",
		"#99ff66","#99ff99","#99ffcc","#99ffff","#ccff00","#ccff33","#ccff66","#ccff99",
		"#ccffcc","#ccffff","#ffff00","#ffff33","#ffff66","#ffff99","#ffffcc","#ffffff"
	);
	
	html += '<table class="colorjs"><tr>';
	for (var i=0; i<colors.length; i++) {
		if (formname == undefined) {
			html += "<td style='width:10px;height:10px;cursor:crosshair;background-color:" + colors[i] + "' onclick=\"addText('" + elname + "', '[color=" + colors[i] + "]', '[/color]');return false;\" onfocus=\"showMapColor('" + colors[i] +  "', '" + elname + "');\" onmouseover=\"showMapColor('" + colors[i] + "', '" + elname + "');\">"
		} else {
			html += "<td style='width:10px;height:10px;cursor:crosshair;background-color:" + colors[i] + "' onclick=\"addText('" + elname + "', '[color=" + colors[i] + "]', '[/color]', '" + formname + "');return false;\" onfocus=\"showMapColor('" + colors[i] +  "', '" + elname + "');\" onmouseover=\"showMapColor('" + colors[i] + "', '" + elname + "');\">"
		}
		html += '</td>';
		if ((i+1) % 18 == 0)	html += '</tr><tr>';
	}
	html += '<tr><td colspan="18">'
	+ '<table width="100%" border="0" cellspacing="0" cellpadding="0">'
	+ '<tr><td id="selectedMapColor' + elname + '" width="50%" height="16">'
	+ '</td><td width="50%">'
	+ '<input id="selectedMapColorBox' + elname + '" name="selectedMapColorBox' + elname + '" type="text" size="7" maxlength="7" style="background-color:#333750;border:0;text-align:center;color:#fff;width:100%" value="" />'
	+ '</td></tr>'
	+ '</table>'
	+ '</td></tr>'
	+ '</table>';

	document.write(html);
}
