//////////////////// THE ACCESSORY CHARACTER MAP (OPTIONAL) ////////////////////
// List the character codes for each row separated by commas as follows:
// row[n] = "code1, code2, code3, , , code4";
// Use either decimal (no leading zero) or hexidecimal (like 0x1F00) codes.
// Begin with row[0] and number consecutively.  Rows must be continuous, without line breaks.
// Extra commas will produce empty cells.  Spaces and empty cells on the right are ignored.

row2[0] = "976, 977, 981, 982, 983, 1008, 1009, 1010, 1011, 1012, 1013, 1014";
row2[1] = "8189, 8175, 8128, 8127, 8142, 8141, 8143, 8190, 8158, 8157, 8159, 8174, 8173, 8129";
row2[2] = "994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007";

//////////////////// THE PAGE APPEARANCE (IF YOU HAVE NOTHING ELSE TO DO) ////////////////////
// font sizes (choices:  xx-small, x-small, small, medium, large, x-large, xx-large):
var page = "x-small";
var character_map = "large";
var Unicode_keys = "medium";
var standard_keys = "small";
var text_area = "small";
var text_boxes = "small";

// colors:
// var table_color = "#ddbb99";
// var background_color = "#fff9f0";

//////////////////// ALTER CODE BELOW AT YOUR OWN RISK ////////////////////

var cntrlvalue = "32";  // This is the value at and below which are assumed to be control characters.


function matchlist(matc1, matc2) {
var re = eval("/\\|" + matc1 + "\\|/");
if (matc2.replace(re, "") != matc2) return true;
}

var keytext = ""; var max = 0;
for (i=0; i<keys.length; i++) {
	keys[i] = keys[i].replace(/\s/g, "").replace(/,*$/, "").split(",");
	if (keys[i].length > max)  max = keys[i].length;
	for (j=0; j<keys[i].length; j++) {
		keys[i][j] = keys[i][j].split("<>");
		if (keys[i][j][0].match(/&#\d+;/))  keys[i][j][0] = String.fromCharCode(keys[i][j][0].match(/\d+/));
		if (keys[i][j][1] && keys[i][j][1].match(/&#\d+;/))  keys[i][j][1] = String.fromCharCode(keys[i][j][1].match(/\d+/));
	}
}
function mouse() {
return 'onMouseOver = "window.status =  \' ' + keys[i][j][1] + ' \'"; ' +
	'onMouseOut = "window.status = \'\'"';
}
keytext = "<tr>"; i=0;
for (j=0; j<max; j++) {
	if (keys[i][j] && keys[i][j][0]) {
		if (keys[i][j][1] && keys[i][j][1] != " ")  keytext += '<td class="kbm" ' + mouse() + '>&nbsp;' + String.fromCharCode(keys[i][j][1]) + '</td><td>&nbsp;' + keys[i][j][0] + '</td>';
		else keytext += '<td class="kb">&nbsp;' + keys[i][j][0] + '</td><td>&nbsp;' + keys[i][j][0] + '</td>';
	}
	else keytext += '<td>&nbsp;</td><td>&nbsp;</td>';
	if (j<max-1)  keytext += '<td rowspan="' + (keys.length+Math.floor((keys.length-1)/2)) + '" class="blank"></td>';
}
keytext  += "</tr>\n";
for (i=1; i<keys.length; i++) {
	keytext += "<tr>";
	for (j=0; j<max; j++) {
	if (keys[i][j] && keys[i][j][0]) {
		if (keys[i][j][1] && keys[i][j][1] != " ")  keytext += '<td class="kbm" ' + mouse() + '>&nbsp;' + String.fromCharCode(keys[i][j][1]) + '</td><td>&nbsp;' + keys[i][j][0] + '</td>';
		else keytext += '<td class="kb">&nbsp;' + keys[i][j][0] + '</td><td>&nbsp;' + keys[i][j][0] + '</td>';
	}
	else keytext += '<td>&nbsp;</td><td>&nbsp;</td>'; }
	keytext  += "</tr>\n";
	if (i%2 != 0 && i<keys.length-1)  keytext += '<tr><td colspan="' + ((2*max)-1) + '" class="blank"></td></tr>\n';
}

var maptext2 = ""; max = 0;
for (i=0; i<row2.length; i++) {
	row2[i] = row2[i].replace(/\s/g, "").replace(/,*$/, "").split(",");
	if (row2[i].length > max)  max = row2[i].length;
}
for (i=0; i<row2.length; i++) {
	maptext2 += "<tr>";
	for (j=0; j<max; j++) {
		if (row2[i][j])
		maptext2 += '<td class="mp"><a class="ch" href="javascript: ' + row2[i][j] + ';" onClick="insert(document.form.characters, \'' + row2[i][j] + '\'); return false">' + String.fromCharCode(row2[i][j]) + '</a></td>';
		else maptext2 += '<td>&nbsp;</td>';
	}
	maptext2 += "</tr>";
}

var combotext = "1000,945|1001,8115|1010,8049|1011,8116|1020,8048|1021,8114|1030,8118|1031,8119|1100,7936|1101,8064|1110,7940|1111,8068|1120,7938|1121,8066|1130,7942|1131,8070|1200,7937|1201,8065|1210,7941|1211,8069|1220,7939|1221,8067|1230,7943|1231,8071|1444,8112|1555,8113|2000,949|2010,8051|2020,8050|2100,7952|2110,7956|2120,7954|2200,7953|2210,7957|2220,7955|3000,951|3001,8131|3010,8053|3011,8132|3020,8052|3021,8130|3030,8134|3031,8135|3100,7968|3101,8080|3110,7972|3111,8084|3120,7970|3121,8082|3130,7974|3131,8086|3200,7969|3201,8081|3210,7973|3211,8085|3220,7971|3221,8083|3230,7975|3231,8087|4000,953|4010,8055|4020,8054|4030,8150|4100,7984|4110,7988|4120,7986|4130,7990|4200,7985|4210,7989|4220,7987|4230,7991|4300,970|4310,8147|4320,8146|4330,8151|4444,8144|4555,8145|5000,959|5010,8057|5020,8056|5100,8000|5110,8004|5120,8002|5200,8001|5210,8005|5220,8003|6000,961|6100,8164|6200,8165|7000,965|7010,8059|7020,8058|7030,8166|7100,8016|7110,8020|7120,8018|7130,8022|7200,8017|7210,8021|7220,8019|7230,8023|7300,971|7310,8163|7320,8162|7330,8167|7444,8160|7555,8161|8000,969|8001,8179|8010,8061|8011,8180|8020,8060|8021,8178|8030,8182|8031,8183|8100,8032|8101,8096|8110,8036|8111,8100|8120,8034|8121,8098|8130,8038|8131,8102|8200,8033|8201,8097|8210,8037|8211,8101|8220,8035|8221,8099|8230,8039|8231,8103|9000,913|9010,8123|9020,8122|9100,7944|9110,7948|9120,7946|9130,7950|9200,7945|9210,7949|9220,7947|9230,7951|9444,8120|9555,8121|10000,917|10010,8137|10020,8136|10100,7960|10110,7964|10120,7962|10200,7961|10210,7965|10220,7963|11000,919|11010,8139|11020,8138|11100,7976|11110,7980|11120,7978|11130,7982|11200,7977|11210,7981|11220,7979|11230,7983|12000,921|12010,8155|12020,8154|12100,7992|12110,7996|12120,7994|12130,7998|12200,7993|12210,7997|12220,7995|12230,7999|12300,938|12444,8152|12555,8153|13000,927|13010,8185|13020,8184|13100,8008|13110,8012|13120,8010|13200,8009|13210,8013|13220,8011|14000,929|14200,8172|15000,933|15010,8171|15020,8170|15200,8025|15210,8029|15220,8027|15230,8031|15300,939|15444,8168|15555,8169|16000,937|16010,8187|16020,8186|16100,8040|16110,8044|16120,8042|16130,8046|16200,8041|16210,8045|16220,8043|16230,8047"
var combos = new Array (combotext.split("|"), new Array());
for (i=0; i<combos[0].length; i++) combos[0][i] = combos[0][i].split(",");
for (j=0; j<combos[0].length; j++) combos[1][combos[0][j][0]] = combos[0][j][1];

function asgn(x, n) { with (Math) {
if (x > 300)  var y = n%1000;
else {
var pl = floor(log(x)/LN10);
var y = round(n%pow(10, pl+1) - n%pow(10, pl)); }
if (x==y)  n = n-x;
	else n = n-y+x/1;
return n;
} }

var keycodes = new Array(new Array(), new Array());
for (i=0; i<keys.length; i++) {
	for (j=0; j<keys[i].length; j++) {
		if (keys[i][j][1]) keycodes[0][keys[i][j][0].charCodeAt()] = new Array (keys[i][j][1]);
		if (keys[i][j][2]) keycodes[0][keys[i][j][0].charCodeAt()][1] = keys[i][j][2]; }
}
for (i=0; i<keys.length; i++) {
	for (j=0; j<keys[i].length; j++) if (keys[i][j][1] && keys[i][j][1] != " ") keycodes[1][keys[i][j][1]] = keys[i][j][1];
}
for (i=0; i<row2.length; i++) {
	for (j=0; j<row2[i].length; j++) if (row2[i][j]) keycodes[1][row2[i][j]] = row2[i][j];
}
for (i=0; i<combos[0].length; i++)  keycodes[1][combos[0][i][1]] = combos[0][i][1];

/////////////////// Kibology ///////////////////

var val = 0; var m = 0;

function cursor(textar) {
if (textar.createTextRange)
	textar.cursorPos = document.selection.createRange().duplicate();
}

function insert (textar, text) { if (document.form.C1.checked) {
text = String.fromCharCode(text);
if (textar.createTextRange && textar.cursorPos) {
	var rang = textar.cursorPos;
	rang.text = (rang.text.charAt(rang.text.length - 1) == ' ' ? text + ' ' : text);
	rang.collapse(false); rang.scrollIntoView(true);
	}
	else textar.value += text;
textar.focus(); val = 0;
} }

function insert2 (textar, event) {
var kc = (event.which ? event.which : event.keyCode);

if ((matchlist(kc, "|13|32|41|44|45|46|59|93|125|") || (keycodes[0][kc] && keycodes[0][kc][0] == 903))
		&& val == 963) {
	if (kc == 13)  var text = String.fromCharCode(962);
		else var text = String.fromCharCode(962) + String.fromCharCode(kc);
	val = kc; m = -1; }

else if ((!matchlist(kc, "|13|32|41|44|45|46|59|93|125|") && (keycodes[0][kc] && keycodes[0][kc][0] != 903))
		&& val == 962) {
	if (keycodes[0][kc] && keycodes[0][kc][0] != " ")
		var text = String.fromCharCode(963) + String.fromCharCode(keycodes[0][kc][0]);
	else var text = String.fromCharCode(963) + String.fromCharCode(kc);
	if (matchlist(keycodes[0][kc][0], "|962|963|"))  val = keycodes[0][kc][0];
	else val = kc;
	m = -1;}

else if (keycodes[0][kc]) {
	if (keycodes[0][kc][0] != " ") var text = String.fromCharCode(keycodes[0][kc][0]);
	if (keycodes[0][kc][1]) {
		if (keycodes[0][kc][1] > 999)  val = keycodes[0][kc][1];
		else if (val > 999 && combos[1][asgn(keycodes[0][kc][1], val)]) {
			val = asgn(keycodes[0][kc][1], val);
			text = String.fromCharCode(combos[1][val]);
			m = -1; }
		else if (val > 999)  text = "";
		else if (keycodes[0][kc][0] == " ") { var text = String.fromCharCode(kc); val = kc; }
		else val = kc;
		}
	else if (matchlist(keycodes[0][kc][0], "|962|963|"))  val = keycodes[0][kc][0];
	else val = kc;
		}
else {	var text = String.fromCharCode(kc);
	val = kc; }

if (textar.createTextRange && textar.cursorPos) {
	var rang = textar.cursorPos;
	rang.moveStart("character", m);
	rang.text = (rang.text.charAt(rang.text.length - 1) == ' ' ? text + ' ' : text);
	rang.collapse(false); rang.scrollIntoView(true);
	}
else {	if (m==0) textar.value += text;
	else textar.value = textar.value.substring(0, textar.value.length-1) + text;  }
textar.focus(); m=0;
}

/////////////////////////////////////////////////////////

function Uni(event) {
if ((event.which > 31 || event.keyCode > 31) && document.form.characters.style.fontFamily==font && document.form.C2.checked)
	return true; else return false;
}

function reval(event) {
	if (event.keyCode == 123) 
	{ document.form.C2.checked = !(document.form.C2.checked); } 
 	var temp = (event.which ? event.which : event.keyCode);
	if (temp==13 && val==963) insert2(document.form.characters, event);
 	else if (matchlist(temp, "|8|9|13|37|38|39|40|"))  val = 0; 
}

var mem = ""; var isithtml = "";
function stor(i) {
if (i)  mem = document.form.characters.value;
else {	if (isithtml==2)  resetfont();
	document.form.characters.value = mem; }
isithtml = i;
}

function repl(a, b) {
a = a.replace(/([\\\^\$\*\+\?\.\[\]()'"\/\|])/g, "\\$1");
b = b.replace(/([\\\^\$\*\+\?\.\[\]()'"\/\|])/g, "\\$1");
document.form.characters.value = eval("document.form.characters.value.replace(/" + a + "/g, '" + b + "')");
}

function resetfont() {
(document.form.characters.style.fontFamily==font) ? toHTML() : fromHTML();
document.form.characters.style.fontSize = ((document.form.characters.style.fontFamily==font) ? "" : text_area);
document.form.A1.style.fontSize = ((document.form.characters.style.fontFamily==font) ? "" : text_boxes);
document.form.B1.style.fontSize = ((document.form.characters.style.fontFamily==font) ? "" : text_boxes);
document.form.A1.style.fontFamily = ((document.form.characters.style.fontFamily==font) ? "" : font);
document.form.B1.style.fontFamily = ((document.form.characters.style.fontFamily==font) ? "" : font);
document.form.characters.style.fontFamily = ((document.form.characters.style.fontFamily==font) ? "" : font);
document.form.characters.style.backgroundColor = ((document.form.characters.style.fontFamily==font) ? "" : "#eeeeee");
}

function toHTML() {
var HTMLtext = ""; var len = document.form.characters.value.length;
for (i=0; i<len; i++) {
	if ((document.form.enc[0].checked && keycodes[1][document.form.characters.value.charCodeAt(i)]) ||
		(document.form.enc[1].checked && document.form.characters.value.charCodeAt(i) > cntrlvalue) ||
		(document.form.enc[2].checked))
		HTMLtext += "&#" + document.form.characters.value.charCodeAt(i) + ";";
	else HTMLtext += document.form.characters.value.charAt(i);
	}
if (document.form.C3.checked)  HTMLtext = HTMLtext.replace(/  /g, "&nbsp; ").replace(/(\r?\n)/g, "<br>$1");
document.form.characters.value = HTMLtext;
}

function enable() { document.form.C3.disabled = (document.form.enc[2].checked ? true : false) }

var toChar = function (match, p1) { return String.fromCharCode(p1); }
function fromHTML() {
document.form.characters.value = document.form.characters.value.replace(/&#(\d+);/g, toChar).replace(/&nbsp;/gi, " ").replace(/<br>/gi, "");
}