function AsciiArtEditor() {
	
	this.version = "1.71";
	this.title = "JSAAE v"+ this.version;
	this.website = "http://jsaae.netfirms.com/";
	
	this.mainCanvasX = 2;
	this.mainCanvasY = 3;
	this.toolboxWidth = 200;
	
	this.box = new Array(
		"charset",
		"tracer",
		"tracer2",
		"browser",
		"setup"
	);
	
	this.boolitem = new Array(
		"doubleSpace",
		"gridLineDraw",
		"saveCookie",
		"spaceVisible",
		"spaceAllVisible",
		"spaceLineVisible",
		"newlineVisible",
		"exitClipBoard",
		"imageSizeFixed",
		"bsMenuBar",
		"bsCount",
		"bsLink",
		"bsResLink",
		"fileAutoWrite",
		"fileAutoRead",
		"replaceRegExp",
		"replaceLineFord",
		"skipNewLine",
		"encodeLineFord"
	);
	
	this.textitem = new Array(
		"gridLineColor",
		"cookieExpires",
		"autoBackupLimit",
		"canvasColor",
		"moveValue",
		"moveValue2",
		"transParent",
		"clipTopPlus",
		"clipRightPlus",
		"clipBottomPlus",
		"clipLeftPlus",
		"traceImgWidth",
		"traceImgHeight",
		"filePath"
	);
	
	this.selectitem = new Array(
		"charSet1",
		"charSet2",
		"charSelectType"
	);
	
	this.slideitem = new Array(
		"tracerPositionX",
		"tracerPositionY",
		"tracer2PositionX",
		"tracer2PositionY"
	);
	
	this.cdb = new Array();
	this.cdb["base1"] = new Array("基本（1）","∧","Λ","∨","∀","Д","д","´","｀","`","'","ﾟ","゜","°");
	this.cdb["base2"] = new Array("基本（2）","ﾞ","゛","¨","′","″","丶","ヽ","ヾ","ゝ","ゞ","〃");
	this.cdb["base3"] = new Array("基本（3）","⌒","￣","／","＼","⊂","⊃","∪","∩","∈","∋","⊆","⊇");
	this.cdb["base4"] = new Array("基本（4）","ω","ε","θ","σ","彡","巛","≡","〆","","∠","∇","Å");
	this.cdb["base5"] = new Array("基本（5）","¬","‖","〓","∫","∬","√","⊥","∴","∵","※");
	this.cdb["base6"] = new Array("基本（6）","†","‡","¶","♭","♪","℃","¢","£","‰");
	this.cdb["base7"] = new Array("基本（7）","↑","→","←","↓","⇒","⇔","±","×","÷","≠","≒");
	this.cdb["base8"] = new Array("基本（8）","≦","≧","≪","≫","∞","∽","∝","§");
	this.cdb["base9"] = new Array("基本（9）","仝","个","亠","彳","〒","Τ","丁","了","Π","凵","Ц","匚");
	this.cdb["greece1"] = new Array("ギリシャ(小)","α","β","γ","δ","ε","ζ","η","θ","ι","κ","λ","μ","ν","ξ","ο","π","ρ","σ","τ","υ","φ","χ","ψ","ω");
	this.cdb["greece2"] = new Array("ギリシャ(大)","Α","Β","Γ","Δ","Ε","Ζ","Η","Θ","Ι","Κ","Λ","Μ","Ν","Ξ","Ο","Π","Ρ","Σ","Τ","Υ","Φ","Χ","Ψ","Ω");
	this.cdb["russia1"] = new Array("ロシア(小)","а","б","в","г","д","е","ё","ж","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ч","ш","щ","ъ","ы","ь","э","ю","я");
	this.cdb["russia2"] = new Array("ロシア(大)","А","Б","В","Г","Д","Е","Ё","Ж","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ч","Ш","Щ","Ъ","Ы","Ь","Э","Ю","Я");
	this.cdb["line1"] = new Array("罫線（1）","─","│","┌","┐","┘","└","├","┬","┤","┴","┼");
	this.cdb["line2"] = new Array("罫線（2）","━","┃","┏","┓","┛","┗","┣","┳","┫","┻","╋");
	this.cdb["line3"] = new Array("罫線（3）","┠","┯","┨","┷","┿","┝","┰","┥","┸","╂");
	
	switch(navigator.appName) {
		case "Microsoft Internet Explorer":
			this.UA = "IE";
			break;
		case "Netscape":
			this.UA = "Mozilla";
			break;
		default:
			this.UA = "Unknown";
	}
	
	with (location.pathname) {
		if (substring(length -3, length) == "hta") {
			this.mode = "HTA";
		} else {
			this.mode = "HTML";
		}
	}
	
	document.writeln('<link rel="stylesheet" href="JSAAE_sys.css">');
	document.writeln('<link rel="stylesheet" href="JSAAE_des.css">');
	
	this.init = function() {
		document.title = this.title;
		this.backup = [];
		this.toolbox = [];
		for (var i in this.box) {
			this.toolbox[this.box[i]] = false;
			this.getId(this.box[i] +"Bar").unselectable = "on";
		}
		this.grid = [];
		this.tracer = [];
		this.tracer.code = this.getId("traceBGImg").outerHTML;
		this.tracer2 = [];
		this.tracer2.code = this.getId("traceImgSelect").outerHTML;
		this.simulator = [];
		this.simulator.count = 0;
		this.fullscreen = [];
		this.fullscreen.button = [];
		this.simple = [];
		this.simple.id = "";
		this.simple.button = "";
		this.file = [];
		this.file.code = this.getId("fileGetButton").outerHTML;
		this.clip = [];
		this.slidebar = [];
		JSAAE.CSC(1);
		JSAAE.CSC(2);
		if (document.cookie != "") {
			this.cookie = [];
			this.getCookie();
			if (this.cookie.version == this.version) {
				for(var i in this.box) {
					var bool = this.getBool(this.cookie[this.box[i]]);
					this.setToolBox(this.box[i], bool);
					this.toolbox[this.box[i]] = bool;
				}
				for(var i in this.boolitem) {
					this.setCheckBox(this.boolitem[i], this.cookie[this.boolitem[i]]);
				}
				for(var i in this.textitem) {
					this.getId(this.textitem[i]).value = this.cookie[this.textitem[i]];
				}
				for(var i in this.selectitem) {
					this.getId(this.selectitem[i]).selectedIndex = this.cookie[this.selectitem[i]];
				}
				this.fullscreen.button.x = this.cookie.returnX;
				this.fullscreen.button.y = this.cookie.returnY;
			} else {
				alert("バージョンの異なるクッキーが検出されました。\n\n"+
					"デフォルトの設定を適用します。\n"+
					"現在のバージョンを継続して使用する場合はクッキーを上書きしてください。\n\n"+
					"ロード中のプログラムのバージョン: "+ this.version +"\n"+
					"保存されているクッキーのバージョン: "+ this.cookie.version);
				this.fullscreen.button.x = 0;
				this.fullscreen.button.y = 0;
			}
		}
		this.getId("mainCanvas").style.posLeft = this.mainCanvasX;
		this.getId("mainCanvas").style.posTop = this.mainCanvasY;
		this.getId("baseCanvas").style.posLeft = this.mainCanvasX;
		this.getId("baseCanvas").style.posTop = this.mainCanvasY;
		this.getId("nowLoading").style.visibility = "hidden";
		this.getId("main").style.visibility = "visible";
		this.backup.limit = parseInt(this.getId("autoBackupLimit").value) +1;
		this.backup.data = new Array(this.backup.limit);
		for (var i = 0; i < this.backup.limit; i++) {
			this.backup.data[i] = "";
		}
		this.undoMoveLimit = 1;
		this.undoMovedValue = 0;
		this.backup.offsetTop = this.mainCanvasY +7;
		this.backup.offsetLeft = this.mainCanvasX +7;
		this.traceImgX = this.mainCanvasX +1;
		this.traceImgY = this.mainCanvasY +1;
		this.traceImgLoaded = false;
		this.clipTop = 0;
		this.clipRight = 0;
		this.clipBottom = 0;
		this.clipLeft = 0;
		this.clipBaseTop = 0;
		this.clipBaseLeft = 0;
		JSAAE.TBC(true);
		this.resize();
		JSAAE.CEC();
		JSAAE.MBC();
		JSAAE.GLD();
		JSAAE.CCC(1);
		JSAAE.CCC(2);
		JSAAE.SAS("center");
		this.getId("undoButton").disabled = true;
		this.getId("redoButton").disabled = true;
		this.setStatus("Now loaded JSAAE ver "+ this.version);
		if (this.id("fileAutoRead").checked) JSAAE.FLO(true);
		JSAAE.FAW(true);
		this.inited = true;
	}
	
	this.destroy = function() {
		if (this.getId("exitClipBoard").checked)
			this.getId("mainCanvas").createTextRange().execCommand("Copy");
		if(this.getId("saveCookie").checked) JSAAE.CSS();
		if (this.simulator.loaded) this.simulator.window.close();
	}
	
	this.resize = function(view) {
		if (document.body.clientHeight < 100 || 
			document.body.clientWidth < this.toolboxWidth * 2) return;
		if (!this.fullscreen.enabled) {
			this.getId("canvas").style.height = document.body.clientHeight - this.getId("toolbar").offsetHeight -4;
			this.getId("leftArea").style.width = document.body.clientWidth - this.toolboxWidth;
			this.clipBaseRight = document.body.clientWidth - this.toolboxWidth - this.mainCanvasX;
			this.clipBaseBottom = document.body.clientHeight - this.getId("toolbar").offsetHeight - this.mainCanvasY -4;
		} else {
			this.getId("canvas").style.height = document.body.clientHeight - this.mainCanvasY -2;
			this.getId("leftArea").style.width = document.body.clientWidth - this.mainCanvasX -2;
			this.clipBaseRight = document.body.clientWidth - this.mainCanvasX;
			this.clipBaseBottom = document.body.clientHeight - this.mainCanvasY -4;
		}
		if (this.traceImgLoaded == true) JSAAE.MCR();
		this.GLD();
		this.RBC();
		this.TBR();
		if (view == true) this.setStatus(document.body.clientHeight +" "+ document.body.clientWidth);
	}
	
	this.mouseup = function() {
		if (!this.inited) return;
		if (this.fullscreen.button.loaded) this.fullscreen.button.loaded = false;
		if (this.slidebar.started) this.slidebar.started = false;
	}
	
	this.mousemove = function() {
		if (!this.inited) return;
		if (this.fullscreen.button.loaded) JSAAE.RBR();
		if (this.slidebar.started) {
			this.setSlideBar(this.slidebar.id, event.clientX - (document.body.clientWidth - this.toolboxWidth + this.getId(this.slidebar.id +"Bar").offsetLeft + 12), true);
			if (this.tracer.loaded && (this.slidebar.id == "tracerPositionX" || this.slidebar.id == "tracerPositionY")) this.TIM();
			if (this.traceImgLoaded && (this.slidebar.id == "tracer2PositionX" || this.slidebar.id == "tracer2PositionY")) this.MIM();
		}
	}
	
	this.scroll = function() {
		this.GLD();
	}
	
	this.getId = this.id = function(id) {
		if (document.getElementById) {
			return document.getElementById(id);
		} else if (document.all) {
			return document.all(id);
		} else {
			alert("このブラウザではJSAAE"+ this.version +"は使えません\n");
		}
	}
	
	this.setCookie = function(name, value) {
		document.cookie = name +"="+ value +"; "+
			//"path="+ location.pathname +"; "+
			"expires="+ this.cookieExpires +"; ";
	}
	
	this.getCookie = function() {
		var cookies = document.cookie.split(";");
		var sub, pair, temp;
		for(var c in cookies) {
			sub = cookies[c].replace(/ /g, "").split("=");
			pair = sub[1].split(",");
			for(var p in pair) {
				temp = pair[p].split("-");
				this.cookie[temp[0]] = unescape(temp[1]);
			}
		}
	}
	
	this.getBool = function(bool) {
		switch(bool) {
			case "1":
				return true;
				break;
			case "0":
				return false;
				break;
		}
	}
	
	this.setCheckBox = function(name, value) {
		switch(value) {
			case "1":
				this.getId(name).checked = true;
				break;
			case "0":
				this.getId(name).checked = false;
				break;
		}
	}
	
	this.setToolBox = function(id, bool) {
		switch (bool) {
			case true:
				with (this.getId(id).style) {
					visibility = "visible";
					position = "static";
				}
				with (this.getId(id +"Bar").style) {
					background = "threedhighlight";
				}
				this.SAS(null);
				break;
			case false:
				with (this.getId(id).style) {
					visibility = "hidden";
					position = "absolute";
				}
				with (this.getId(id +"Bar").style) {
					background = "threedface";
				}
				this.SAS(null);
				break;
		}
	}
	
	this.setSlideBar = function(id, x, view) {
		var max = this.getId(id +"Bar").offsetWidth - 10;
		if (x != null) {
			if (x < 0) x = 0;
			if (x > max) x = max;
		}
		if (x == "center") {
			x = (this.getId(id +"Bar").offsetWidth - 10) / 2;
		}
		with (this.getId(id).style) {
			posTop = this.getId(id +"Bar").offsetTop - 7 + this.getId(id +"Bar").offsetParent.offsetTop;
			if (x != null) posLeft = x + this.getId(id +"Bar").offsetLeft;
		}
		this.slidebar[id] = x;
		if (view) this.setStatus(this.slidebar[id]);
	}
	
	this.setStatus = function(comment, time) {
		if (!time) time = 2000;
		clearTimeout(this.statusTimer);
		if (this.mode == "HTA") {
			document.title = "JSAAE - "+ comment;
			this.statusTimer = setTimeout('document.title = JSAAE.title', time);
		} else {
			status = comment;
			this.statusTimer = setTimeout('status = defaultStatus', time);
		}
	}
	
	//SlideBar All Settings
	this.SAS = function(value) {
		for (var i in this.slideitem) {
			this.setSlideBar(this.slideitem[i], value);
		}
	}
	
	//SlideBar Slide Start
	this.SSS = function(id) {
		this.slidebar.started = true;
		this.slidebar.id = id;
	}
	
	//ToolBox Button Call
	this.TBC = function(view) {
		if (view) {
			this.getId("toolBoxSlot").innerHTML = 
				'<div unselectable="on" style="float:left;" '+
				'onmouseover="this.style.background = \'threedhighlight\'" '+
				'onmouseout="this.style.background = \'threedface\'" '+
				'onclick="JSAAE.TAV(true)">全て表示</div>'+
				'<div unselectable="on" '+
				'onmouseover="this.style.background = \'threedhighlight\'" '+
				'onmouseout="this.style.background = \'threedface\'" '+
				'onclick="JSAAE.TAV(false)">全て隠す</div>';
		} else {
			this.getId("toolBoxSlot").innerHTML = '';
		}
	}
	
	//ToolBox Button Repaint
	this.TBR = function() {
		with (this.getId("toolBoxSlot")) {
			style.posTop = document.body.clientHeight - offsetHeight;
			style.posLeft = document.body.clientWidth - this.toolboxWidth + 1;
			style.zIndex = 6;
		}
	}
	
	//ToolBox Single Visibility
	this.TSV = function(id) {
		switch (this.toolbox[id]) {
			case true:
				this.setToolBox(id, false);
				this.toolbox[id] = false;
				break;
			case false:
				this.setToolBox(id, true);
				this.toolbox[id] = true;
				break;
		}
	}
	
	//ToolBox All Visibility
	this.TAV = function(view) {
		for (var i in this.box) {
			if (view) {
				this.setToolBox(this.box[i], true);
				this.toolbox[this.box[i]] = true;
			} else {
				this.setToolBox(this.box[i], false);
				this.toolbox[this.box[i]] = false;
			}
		}
	}
	
	//ToolBox Mouse Event
	this.TME = function(id) {
		with (this.getId(id +"Bar").style) {
			if (event.type == "mouseover") {
				if (!this.toolbox[id]) {
					background = "threedhighlight";
				}
			} else if (event.type == "mouseout") {
				if (!this.toolbox[id]) {
					background = "threedface";
				}
			}
		}
	}
	
	//MainCanvas Control Unit
	this.MCU = function() {
		if (this.getId("doubleSpace").checked) JSAAE.MDD();
		if (this.getId("spaceVisible").checked) {
			if (this.getId("spaceAllVisible").checked) JSAAE.MSV();
				else if (this.getId("spaceLineVisible").checked) JSAAE.MLV();
		} else {
			this.getId("spaceVisibleSlot").innerHTML = '';
		}
		if (this.getId("newlineVisible").checked) JSAAE.MNV();
			else this.getId("newlineVisibleSlot").innerHTML = '';
		if (this.simulator.loaded) JSAAE.BSU();
		if (this.getId("mainCanvas").value != this.backup.data[0]) JSAAE.MBH();
		if (event.type != "blur") JSAAE.MBP();
		if (this.id("fileAutoWrite").checked) JSAAE.FLS(true);
	}
	
	//MainCanvas DoubleSpace Delete
	this.MDD = function() {
		var text = this.getId("mainCanvas").value;
		if(!text.match(/^ /m) && !text.match(/ {2}/)) return;
		var range = document.selection.createRange();
		var top = range.offsetTop;
		var left = range.offsetLeft;
		while(text.match(/^ /m)) {
			text = text.replace(/^ /gm, "");
		}
		while(text.match(/ {2}/)) {
			text = text.replace(/ {2}/g, " ");
		}
		this.getId("mainCanvas").value = text;
		range.moveToPoint(left, top);
		range.move("character", -1);
		range.select();
		this.getId("mainCanvas").focus();
	}
	
	//MainCanvas Space Visible
	this.MSV = function() {
		var range, source = "";
		var p = this.getId("mainCanvas").value.indexOf(" ");
		for (var i = 0; p > -1; p = this.getId("mainCanvas").value.indexOf(" ", i)) {
			range = this.getId("mainCanvas").createTextRange();
			var lf = this.getId("mainCanvas").value.substring(0, p).match(/\n/g);
			if (lf != null) range.move("character", p - lf.length);
				else range.move("character", p);
			i = p + 1;
			if (this.getId("mainCanvas").offsetWidth + this.mainCanvasX < range.offsetLeft ||
				this.getId("mainCanvas").offsetHeight + this.mainCanvasY - 12 < range.offsetTop) continue;
			source += '<div style="position: absolute;'+
				'top: '+ (range.offsetTop -2) +';'+
				'left: '+ (range.offsetLeft -2) +';'+
				'background: threedface;'+
				'z-index: 4;'+
				'">&nbsp;</div>';
		}
		this.getId("spaceVisibleSlot").innerHTML = source;
	}
	
	//MainCanvas LineSpace Visible
	this.MLV = function() {
		var range = document.selection.createRange();
		range.moveStart("textedit", -1);
		var lf = range.text.match(/\n/g);
		var text = this.getId("mainCanvas").value;
		var s = 0, e;
		if (lf != null) {
			for (var i = 0; i < lf.length; i++) {
				s = text.indexOf("\n", s +1);
			}
			e = text.indexOf("\n", s +1);
		} else {
			e = text.indexOf("\n");
		}
		if (e < 0) e = text.length;
		var source = "";
		var p = text.indexOf(" ", s);
		for (var i = s; p > -1; p = text.indexOf(" ", i)) {
			range = this.getId("mainCanvas").createTextRange();
			if (lf != null) range.move("character", p - lf.length);
				else range.move("character", p);
			i = p + 1;
			if (i > e) break;
			if (this.getId("mainCanvas").offsetWidth + this.mainCanvasX < range.offsetLeft ||
				this.getId("mainCanvas").offsetHeight + this.mainCanvasY - 12 < range.offsetTop) continue;
			source += '<div style="position: absolute;'+
				'top: '+ (range.offsetTop -2) +';'+
				'left: '+ (range.offsetLeft -2) +';'+
				'background: threedface;'+
				'z-index: 4;'+
				'">&nbsp;</div>';
		}
		this.getId("spaceVisibleSlot").innerHTML = source;
	}
	
	//MainCanvas Newline Visible
	this.MNV = function() {
		var range, source = "";
		var p = this.getId("mainCanvas").value.indexOf("\n");
		var n = 0;
		for (var i = 0; p > -1; p = this.getId("mainCanvas").value.indexOf("\n", i)) {
			range = this.getId("mainCanvas").createTextRange();
			n++;
			range.move("character", p - n);
			i = p + 1;
			if (this.getId("mainCanvas").offsetWidth + this.mainCanvasX < range.offsetLeft + 10 ||
				this.getId("mainCanvas").offsetHeight + this.mainCanvasY - 12 < range.offsetTop) continue;
			source += '<div style="position: absolute;'+
				'top: '+ (range.offsetTop +1.5) +';'+
				'left: '+ (range.offsetLeft -1) +';'+
				'color: threedface;'+
				'font-size: 10pt;'+
				'z-index: 4;'+
				'">←</div>';
		}
		this.getId("newlineVisibleSlot").innerHTML = source;
	}
	
	//MainCanvas Backup History
	this.MBH = function() {
		var bufs = new Array(this.backup.limit);
		for (var i = 0; i < this.backup.limit; i++) {
			bufs[i] = this.backup.data[i];
		}
		for (var i = 0; i < this.backup.limit -1; i++) {
			this.backup.data[i +1] = bufs[i];
		}
		this.backup.data[0] = this.getId("mainCanvas").value;
		this.undoMovedValue = 0;
		if (this.undoMoveLimit < this.backup.limit) this.undoMoveLimit++;
		this.getId("undoButton").disabled = false;
		this.getId("redoButton").disabled = true;
	}
	
	//MainCanvas Backup Pointer
	this.MBP = function() {
		var range = document.selection.createRange();
		this.backup.offsetTop = range.offsetTop;
		this.backup.offsetLeft = range.offsetLeft;
	}
	
	//Grid Line Draw
	this.GLD = function() {
		switch(this.getId("gridLineDraw").checked) {
			case true:
				var cols, rows;
				cols = parseInt(this.getId("mainCanvas").offsetHeight / 37);
				rows = parseInt(this.getId("mainCanvas").offsetWidth / 42);
				if (this.id("gridLine")) {
					this.id("gridLine").style.posTop = this.mainCanvasY + 4 - (this.id("mainCanvas").scrollTop % 37 + this.id("mainCanvas").scrollTop / 37);
				}
				if (this.grid.cols == cols && this.grid.rows == rows) return;
				this.grid.cols = cols;
				this.grid.rows = rows;
				var grid = '<table id="gridLine">';
				for(var c = 0; c < this.grid.cols; c++) {
					grid += '<tr>';
					for(var r = 0; r < this.grid.rows; r++) {
						grid += '<td></td>';
					}
					grid += '</tr>';
				}
				grid += '</table>';
				this.getId("gridLineSlot").innerHTML = grid;
				with(this.getId("gridLine").style) {
					position = "absolute";
					posLeft = this.mainCanvasX + 4;
					posTop = this.mainCanvasY + 4 - (this.id("mainCanvas").scrollTop % 37 + this.id("mainCanvas").scrollTop / 37);
					zIndex = 4;
				}
				JSAAE.GCC();
				break;
			case false:
				this.getId("gridLineSlot").innerHTML = '';
				this.grid.cols = 0;
				this.grid.rows = 0;
				break;
		}
	}
	
	//Grid Color Change
	this.GCC = function() {
		if (!this.getId("gridLineDraw").checked) return;
		try {
			this.getId("gridLine").style.borderColor = this.getId("gridLineColor").value;
		} catch(ex) {
			this.setStatus("グリッドの色が無効です");
		}
	}
	
	//Undo Limit Change
	this.ULC = function() {
		this.backup.limit = parseInt(this.getId("autoBackupLimit").value) +1;
	}
	
	//MainCanvas BGColor Change
	this.MBC = function() {
		try {
			this.getId("baseCanvas").style.backgroundColor = this.getId("canvasColor").value;
		} catch(ex) {
			this.setStatus("背景色が無効です");
		}
	}
	
	//Cookie Setup Saving
	this.CSS = function() {
		var bool;
		var temp = "";
		for(var i in this.box) {
			this.toolbox[this.box[i]] ?bool = "1" :bool = "0";
			temp += this.box[i] +"-"+ bool +",";
		}
		temp = temp.substring(0, temp.length - 1);
		this.setCookie("JSAAE_BOX", temp);
		temp = "";
		for(var i in this.boolitem) {
			this.getId(this.boolitem[i]).checked ?bool = "1" :bool = "0";
			temp += this.boolitem[i] +"-"+ bool +",";
		}
		temp = temp.substring(0, temp.length - 1);
		this.setCookie("JSAAE_BOOLITEM", temp);
		temp = "";
		for(var i in this.textitem) {
			temp += this.textitem[i] +"-"+ escape(this.getId(this.textitem[i]).value).replace("-","%2D") +",";
		}
		temp = temp.substring(0, temp.length - 1);
		this.setCookie("JSAAE_TEXTITEM", temp);
		temp = "";
		for(var i in this.selectitem) {
			temp += this.selectitem[i] +"-"+ this.getId(this.selectitem[i]).selectedIndex +",";
		}
		temp = temp.substring(0, temp.length - 1);
		this.setCookie("JSAAE_SELECTITEM", temp);
		
		temp = "returnX-"+ this.fullscreen.button.x +",returnY-"+ this.fullscreen.button.y +";";
		this.setCookie("JSAAE_OTHER", temp);
		this.setCookie("JSAAE_VERSION", "version-"+ this.version);
	}
	
	//Cookie Expires Change
	this.CEC = function() {
		var time = new Date();
		time.setTime(time.getTime() + (this.getId("cookieExpires").value * 1000 * 60 * 60 * 24));
		this.cookieExpires = time.toGMTString();
	}
	
	//Collection Selecter Call
	this.CSC = function(id) {
		var collset="";
		for(var i in this.cdb) {
			collset += "<option value="+ i +">"+ this.cdb[i][0] +"\n";
		}
		this.getId("charSetField"+id).innerHTML = 
			'<select id="charSet'+id+'" onchange="JSAAE.CCC('+id+')">\n'+
			collset +'</select>\n';
	}
	
	//Character Collection Call
	this.CCC = function(id) {
		with(this.getId("charSet"+id)) {
			var option = options[selectedIndex].value;
		}
		var charset="";
		for(var i in this.cdb[option]) {
			if(i == 0) continue;
			charset += "<option>"+ this.cdb[option][i] +"\n";
		}
		this.getId("charField"+id).innerHTML = 
			'<select id="charCollection'+id+'" size="4" onclick="JSAAE.SCS('+id+')">\n'+
			charset +'</select>\n';
	}
	
	//Single Character Select
	this.SCS = function(id) {
		with(this.getId("charCollection"+id)) {
			var option = options[selectedIndex].text;
		}
		this.getId("charDisp"+id).value = option;
		with(this.getId("charSelectType")) {
			var mode = options[selectedIndex].value;
		}
		switch(mode) {
			case "selectonly":
				break;
			case "clipboard":
				this.getId("charDisp"+id).createTextRange().execCommand("Copy");
				break;
			case "canvaspaste":
				var range = this.getId("mainCanvas").createTextRange();
				range.moveToPoint(this.backup.offsetLeft, this.backup.offsetTop);
				range.text = option;
				this.backup.offsetTop = range.offsetTop;
				this.backup.offsetLeft = range.offsetLeft;
				range.select();
				this.getId("mainCanvas").focus();
				break;
		}
	}
	
	//Character List Call
	this.CLC = function() {
		var table="";
		for(var f in this.cdb) {
			table += '<tr>\n<th>'+ this.cdb[f][0] +'</th>\n';
			for(var s in this.cdb[f]) {
				if(s == 0) continue;
				table += '<td onmouseover="this.style.background = \'threedhighlight\'" onmouseout="this.style.background = \'threedface\'" '+
				'onclick="JSAAE.CLS(\''+ f +'\', '+ s +')">'+ this.cdb[f][s] +'</td>\n';
			}
			table += '</tr>\n';
		}
		this.getId("charListSlot").style.position = "static";
		this.getId("charListSlot").innerHTML = 
			'<div id="charList">\n'+
			'<div id="charListBar">文字リスト&nbsp;&nbsp;<span id="closeButton" '+
			'onmouseover="this.style.borderStyle = \'groove\'; this.style.background = \'threedhighlight\'"'+
			'onmouseout="this.style.borderStyle = \'none\'; this.style.background = \'threedface\'"'+
			'onclick="JSAAE.CLH()">×</span></div><hr>\n'+
			'<table>\n'+ table +'</table>\n'+
			'</div>\n';
		with(this.getId("charList").style) {
			position = "absolute";
			posLeft = 30;
			posTop = 20;
			zIndex = 6;
		}
		this.setToolBox('charset', false);
	}
	
	//Character List Visible
	this.CLV = function() {
		if (this.charListLoaded) {
			with(this.getId("charList").style) {
				visibility = 'visible';
				this.setToolBox('charset', false);
			}
		} else {
			JSAAE.CLC();
			this.charListLoaded = true;
		}
	}
	
	//Character List Hidden
	this.CLH = function() {
		with(this.getId("charList").style) {
			visibility = "hidden";
			this.setToolBox('charset', this.toolbox.charset);
		}
	}
	
	//Character List Select
	this.CLS = function(f, s) {
		with(this.getId("charSelectType")) {
			var mode = options[selectedIndex].value;
		}
		switch(mode) {
			case "selectonly":
				this.getId("charDisp1").value = this.cdb[f][s];
				break;
			case "clipboard":
				clipboardData.setData("Text", this.cdb[f][s]);
				break;
			case "canvaspaste":
				var range = this.getId("mainCanvas").createTextRange();
				range.moveToPoint(this.backup.offsetLeft, this.backup.offsetTop);
				range.text = this.cdb[f][s];
				this.backup.offsetTop = range.offsetTop;
				this.backup.offsetLeft = range.offsetLeft;
				range.select();
				this.getId("mainCanvas").focus();
				break;
		}
		JSAAE.CLH();
	}
	
	//Tracer Image Loading
	this.TIL = function() {
		with(this.getId("baseCanvas").style) {
			backgroundImage = "url("+ this.getId("traceBGImg").value +")";
			backgroundRepeat = "no-repeat";
		}
		this.setSlideBar("tracerPositionX", "center");
		this.setSlideBar("tracerPositionY", "center");
		this.tracer.defx = (this.getId("tracerPositionXBar").offsetWidth - 10) / 2;
		this.tracer.defy = (this.getId("tracerPositionYBar").offsetWidth - 10) / 2;
		this.tracer.loaded = true;
	}
	
	//Tracer Image Move
	this.TIM = function() {
		var move = parseInt(this.getId("moveValue").value);
		if (!move) return;
		with(this.getId("baseCanvas").style) {
			backgroundPositionX = (this.slidebar.tracerPositionX - this.tracer.defx) * move;
			backgroundPositionY = (this.slidebar.tracerPositionY - this.tracer.defy) * move;
		}
	}
	
	//Tracer Image Clear
	this.TIC = function() {
		with(this.getId("baseCanvas").style) {
			backgroundImage = "none";
			backgroundPositionX = 0;
			backgroundPositionY = 0;
		}
		this.setSlideBar("tracerPositionX", "center");
		this.setSlideBar("tracerPositionY", "center");
		this.getId("traceBGImg").outerHTML = this.tracer.code;
		this.tracer.loaded = false;
	}
	
	//MultiTracer Image Loading
	this.MIL = function() {
		this.getId("tracerImgSlot").innerHTML = 
			'<img src="'+ this.getId("traceImgSelect").value +'" id="traceImg">';
		with(this.getId("traceImg").style) {
			position = "absolute";
			zIndex = 2;
			width = this.getId("traceImgWidth").value;
			height = this.getId("traceImgHeight").value;
		}
		with(this.getId("coverCanvas").style) {
			visibility = "visible";
			filter = "Alpha(opacity=0)";
		}
		this.setSlideBar("tracer2PositionX", "center");
		this.setSlideBar("tracer2PositionY", "center");
		this.tracer2.defx = (this.getId("tracer2PositionXBar").offsetWidth - 10) / 2;
		this.tracer2.defy = (this.getId("tracer2PositionYBar").offsetWidth - 10) / 2;
		this.traceImgLoaded = true;
		JSAAE.MIM();
		JSAAE.MOC();
	}
	
	//MultiTracer Image Move
	this.MIM = function(direc) {
		var move = parseInt(this.getId("moveValue2").value);
		if (!move) return;
		this.clipTop = 0 - (this.slidebar.tracer2PositionY - this.tracer2.defy) * move;
		this.clipBottom = 0 - (this.slidebar.tracer2PositionY - this.tracer2.defy) * move;
		this.clipRight = 0 - (this.slidebar.tracer2PositionX - this.tracer2.defx) * move;
		this.clipLeft = 0 - (this.slidebar.tracer2PositionX - this.tracer2.defx) * move;
		if (!this.traceImgLoaded) return;
		with(this.getId("traceImg").style) {
			posLeft = (this.slidebar.tracer2PositionX - this.tracer2.defx) * move + this.traceImgX;
			posTop = (this.slidebar.tracer2PositionY - this.tracer2.defy) * move + this.traceImgY;
		}
		JSAAE.MCR();
	}
	
	//MultiTracer Opacity Change
	this.MOC = function() {
		if(this.traceImgLoaded == false) return;
		var value = parseInt(this.getId("transParent").value);
		if (0 > value || value > 100) {
			this.setStatus("透明度の値は0から100までの間に設定してください", 4000);
			return;
		}
		with(this.getId("traceImg").style) {
			filter = "Alpha(opacity="+ (100 - value) +")";
		}
	}
	
	//MultiTracer Image Resize
	this.MIR = function(mode) {
		if(this.traceImgLoaded == false) return;
		try {
			with(this.getId("traceImg").style) {
				if(this.getId("imageSizeFixed").checked) {
					switch(mode) {
						case "w":
							width = height = this.getId("traceImgHeight").value = this.getId("traceImgWidth").value;
							break;
						case "h":
							width = height = this.getId("traceImgWidth").value = this.getId("traceImgHeight").value;
							break;
					}
				} else {
					width = this.getId("traceImgWidth").value;
					height = this.getId("traceImgHeight").value;
				}
			}
		} catch(ex) {
			this.setStatus("画像サイズが不正です");
		}
	}
	
	//MultiTracer Clip Repaint
	this.MCR = function() {
		try {
			this.getId("traceImg").style.clip = "rect("+
				(this.clipTop + parseInt(this.getId("clipTopPlus").value)) +"px,"+
				(this.clipRight + this.clipBaseRight + parseInt(this.getId("clipRightPlus").value)) +"px,"+
				(this.clipBottom + this.clipBaseBottom + parseInt(this.getId("clipBottomPlus").value)) +"px, "+
				(this.clipLeft + parseInt(this.getId("clipLeftPlus").value)) +"px)";
		} catch(ex) {
			this.setStatus("補正値が不正です");
		}
	}
	
	//MultiTracer Image Clear
	this.MIC = function() {
		this.getId("tracerImgSlot").innerHTML = '';
		with(this.getId("coverCanvas").style) {
			visibility = "hidden";
			filter = "";
		}
		this.traceImgX = this.mainCanvasX +1;
		this.traceImgY = this.mainCanvasY +1;
		this.clipTop = 0;
		this.clipRight = 0;
		this.clipBottom = 0;
		this.clipLeft = 0;
		this.setSlideBar("tracer2PositionX", "center");
		this.setSlideBar("tracer2PositionY", "center");
		this.getId("traceImgSelect").outerHTML = this.tracer2.code;
		this.traceImgLoaded = false;
	}
	
	//Browser Simulator Open
	this.BSO = function() {
		if (!this.simulator.loaded) {
			var menubar; 
			this.getId("bsMenuBar").checked == true ?menubar = "yes" :menubar = "no";
			this.simulator.window = window.open("JSAAE_sim.html","_blank","toolbar=no,location=no,directories=no,status=no,menubar="+ menubar +",scrollbars=yes,resizable=yes,width=500,height=400");
			this.simulator.loaded = true;
			this.getId("bsMenuBar").disabled = true;
		} else {
			this.simulator.window.close();
		}
	}
	
	//Browser Simulator Update
	this.BSU = function() {
		if (!this.simulator.loaded) return;
		if (this.getId("bsCount").checked == true) this.simulator.count++;
			else if (this.simulator.count == 0) this.simulator.count = 1;
		var time = new Date();
		var year = time.getYear().toString().substring(2);
		var month = time.getMonth() +1;
		var date = time.getDate();
		var hour = time.getHours();
		var min = time.getMinutes();
		if (month.toString().length < 2) month = "0" + month.toString();
		if (date.toString().length < 2) date = "0" + date.toString();
		if (hour.toString().length < 2) hour = "0" + hour.toString();
		if (min.toString().length < 2) min = "0" + min.toString();
		var text = this.getId("mainCanvas").value;
		text = text.replace(/</g,"&lt;");
		text = text.replace(/>/g,"&gt;");
		text = text.replace(/\r\n?/g,"<br>");
		text = text.replace(/\n/g,"<br>");
		if (this.getId("bsResLink").checked == true) {
			var link = new RegExp("&gt;&gt;[0-9]+", "g");
			var res = text.match(link);
			if (res != null) {
				text = text.replace(link, "<match>");
				for (var i = 0; i < res.length; i++) {
					text = text.replace("<match>", '<a href="'+ res[i].replace("&gt;&gt;", "") +'" target="_blank">'+ res[i] +'</a>');
				}
			}
		}
		if (this.getId("bsLink").checked == true) {
			var link = new RegExp("(https?|ftp)://[a-zA-Z0-9]+\\.[a-zA-Z0-9_!\"#$%&'=~\\|\\-\\+\\^\\\\`;:,\\./\\*]+", "g");
			var url = text.match(link);
			if (url != null) {
				text = text.replace(link, "<match>");
				for (var i = 0; i < url.length; i++) {
					text = text.replace("<match>", '<a href="'+ url[i] +'" target="_blank">'+ url[i] +'</a>');
				}
			}
		}
		var source = "<dl>"+
			"<dt>"+ this.simulator.count +" ：<font color=green><b>（*ﾟДﾟ）さん</b></font> ："+
			year + "/"+ month +"/"+ date +" "+ hour +":"+ min +" ID:JsAaEv"+ this.version.replace(".","").substring(0,2) +
			"<dd>"+ text +"<br></dl>";
		this.simulator.window.JSAAE_SIM.outPutHTML(source);
	}
	
	//Simple Tools Visibility
	this.STV = function(id, button) {
		if(id == 'allclear') {
			if(this.simple.id != "") {
				with(this.getId(this.simple.id).style) {
					position = "absolute";
					visibility = "hidden";
				}
				with(this.getId(this.simple.button).style) {
					background = "threedface";
					borderStyle = "";
				}
			}
			this.simple.id = "";
			this.simple.button = "";
		} else if(this.simple.id == id) {
			with(this.getId(id).style) {
				position = "absolute";
				visibility = "hidden";
			}
			with(this.getId(button).style) {
				background = "threedface";
				borderStyle = "";
			}
			this.simple.id = "";
			this.simple.button = "";
		} else {
			if(this.simple.id != "") {
				with(this.getId(this.simple.id).style) {
					position = "absolute";
					visibility = "hidden";
				}
				with(this.getId(this.simple.button).style) {
					background = "threedface";
					borderStyle = "";
				}
			}
			with(this.getId(id).style) {
				position = "static";
				visibility = "visible";
			}
			with(this.getId(button).style) {
				background = "threedhighlight";
				borderStyle = "groove";
			}
			this.simple.id = id;
			this.simple.button = button;
		}
		this.resize();
	}
	
	//All Screen Displays
	this.ASD = function() {
		with (this.getId("rightArea").style) {
			visibility = "hidden";
			position = "absolute";
			posTop = "-"+ document.body.clientHeight;
		}
		with (this.getId("toolbar").style) {
			visibility = "hidden";
			position = "absolute";
			posTop = 0;
		}
		JSAAE.STV("allclear");
		JSAAE.TBC(false);
		document.body.style.background = "threedface";
		this.fullscreen.enabled = true;
		if(this.traceImgLoaded == true) {
			with(this.getId("traceImg").style) {
				this.getId("traceImg").style.clip = "rect("+
					(this.clipTop + parseInt(this.getId("clipTopPlus").value)) +"px, 100%, 100%, "+
					(this.clipLeft + parseInt(this.getId("clipLeftPlus").value)) +"px)";
			}
		}
		this.getId("allScrDispSlot").style.position = "static";
		this.getId("allScrDispSlot").innerHTML = 
			'<div id="displayReturn" unselectable="on" '+
			'onmouseover="this.style.background = \'threedhighlight\'" '+
			'onmouseout="this.style.background = \'threedface\'" '+
			'onmousedown="JSAAE.fullscreen.button.loaded = true" '+
			'ondblclick="JSAAE.OSD()">元に戻す</div>';
		with (this.getId("displayReturn")) {
			style.posTop = this.fullscreen.button.y;
			style.posLeft = this.fullscreen.button.x;
		}
		this.resize();
	}
	
	//Original Screen Displays
	this.OSD = function() {
		with (this.getId("rightArea").style) {
			visibility = "visible";
			position = "static";
		}
		with (this.getId("toolbar").style) {
			visibility = "visible";
			position = "static";
		}
		JSAAE.TBC(true);
		document.body.style.background = "";
		this.fullscreen.enabled = false;
		if(this.traceImgLoaded == true) JSAAE.MCR();
		this.getId("allScrDispSlot").style.position = "absolute";
		this.getId("allScrDispSlot").innerHTML = '';
		this.resize();
	}
	
	//Return Button Moving
	this.RBR = function() {
		with (this.getId("displayReturn")) {
			style.posTop = this.fullscreen.button.y = event.clientY - (offsetHeight / 2);
			style.posLeft = this.fullscreen.button.x = event.clientX - (offsetWidth / 2);
		}
		this.RBC();
	}
	
	//Return Button Correction
	this.RBC = function() {
		if (!this.fullscreen.enabled) return;
		with (this.getId("displayReturn")) {
			var maxx = document.body.clientWidth - offsetWidth;
			var maxy = document.body.clientHeight - offsetHeight;
			if (style.posLeft > maxx) style.posLeft = maxx;
			if (style.posTop > maxy) style.posTop = maxy;
			if (style.posLeft < 0) style.posLeft = 0;
			if (style.posTop < 0) style.posTop = 0;
		}
	}
	
	//Simple Tool Copy
	this.STC = function() {
		this.getId("mainCanvas").select();
		this.getId("mainCanvas").createTextRange().execCommand("Copy");
	}
	
	//Simple Tool Undo
	this.UND = function() {
		this.undoMovedValue++;
		this.getId("mainCanvas").value = this.backup.data[this.undoMovedValue];
		this.backup.data[0] = this.getId("mainCanvas").value;
		if (this.undoMoveLimit -1 <= this.undoMovedValue) this.getId("undoButton").disabled = true;
		this.getId("redoButton").disabled = false;
		JSAAE.MCU();
	}
	
	//Simple Tool Redo
	this.RED = function() {
		this.undoMovedValue--;
		this.getId("mainCanvas").value = this.backup.data[this.undoMovedValue];
		this.backup.data[0] = this.getId("mainCanvas").value;
		if (this.undoMovedValue == 0) this.getId("redoButton").disabled = true;
		this.getId("undoButton").disabled = false;
		JSAAE.MCU();
	}
	
	//FileSystem LocalFile Get
	this.FLG = function() {
		this.id("filePath").value = this.id("fileGetButton").value;
		this.id("fileGetButton").outerHTML = this.file.code;
	}
	
	//FileSystem LocalFile Open
	this.FLO = function(bool) {
		if (this.id("mainCanvas").value != "" && !bool) {
			if (!confirm("\""+ this.getId("filePath").value +
				"\"\nを開こうとしています。現在の編集データは破棄されます。\n"+
				"（破棄されたデータは[元に戻す]ボタンで復帰させることができます）\n"+
				"\n選択されたファイルを開きますか？")) return;
		}
		var fs, f;
		try {
			fs = new ActiveXObject("Scripting.FileSystemObject");
			f = fs.openTextFile(this.getId("filePath").value, 1);
			this.getId("mainCanvas").value = f.readAll();
			f.close();
		} catch(ex) {
			this.setStatus("ファイルの読み込みエラー");
		}
	}
	
	//FileSystem LocalFile Save
	this.FLS = function(bool) {
		if (!bool) {
			if (!confirm("\""+ this.getId("filePath").value +
				"\"\nに編集データを保存します。"+
				"ファイルの内容は上書きされます。\nよろしいですか？")) return;
		}
		var fs, f;
		try {
			fs = new ActiveXObject("Scripting.FileSystemObject");
			f = fs.createTextFile(this.getId("filePath").value, true);
			f.write(this.getId("mainCanvas").value);
			f.close();
		} catch(ex) {
			this.setStatus("ファイルの書き込みエラー");
		}
	}
	
	//FileSystem Auto Write
	this.FAW = function(bool) {
		if (this.id("fileAutoWrite").checked) {
			if (!bool) {
				if (!confirm("\""+ this.getId("filePath").value +
					"\"\nへの自動バックアップを開始します。"+
					"ファイルの内容は上書きされます。\nよろしいですか？"
				)) {
					this.id("fileAutoWrite").checked = false;
					return;
				}
			}
			this.id("fileOpenButton").disabled = true;
			this.id("fileSaveButton").disabled = true;
			this.id("fileGetButton").disabled = true;
			this.id("filePath").disabled = true;
			this.id("filePath").style.backgroundColor = "threedface";
		} else {
			this.id("fileOpenButton").disabled = false;
			this.id("fileSaveButton").disabled = false;
			this.id("fileGetButton").disabled = false;
			this.id("filePath").disabled = false;
			this.id("filePath").style.backgroundColor = "";
		}
	}
	
	//Simple Tool Replace
	this.STR = function() {
		var text = this.getId("mainCanvas").value;
		var before = this.getId("replaceBefore").value;
		var after = this.getId("replaceAfter").value;
		if (before == "") return;
		if(this.getId("replaceLineFord").checked) {
			text = text.replace(/\r\n?/g, "\n");
		}
		if(this.getId("replaceRegExp").checked) {
			eval("text = text.replace(/"+ before +"/gm, \""+ after +"\");");
		} else {
			before = before.replace(/\\/g,"\\\\");
			while(text.match(before)) {
				eval("text = text.replace(\""+ before +"\", \"\\t\\r\\r\\t\");");
			}
			text = text.replace(/\t\r\r\t/g, after);
		}
		this.getId("mainCanvas").value = text;
		JSAAE.MCU();
	}
	
	//Simple Tool Surround
	this.STS = function() {
		var front = this.getId("frontSurround").value;
		var rear = this.getId("rearSurround").value;
		var text = this.getId("mainCanvas").value;
		if(this.getId("replaceLineFord").checked) {
			text = text.replace(/\r\n?/g, "\n");
		}
		var lines = text.split("\n");
		var surr = "";
		for(var l in lines) {
			surr += front + lines[l] + rear +"\n";
		}
		this.getId("mainCanvas").value = surr.substring(0, surr.length -1);
		JSAAE.MCU();
	}
	
	//Unicode ReferenceCharacter Encode
	this.URE = function() {
		var text = this.getId("mainCanvas").value;
		var unicode = "";
		if(this.getId("encodeLineFord").checked) {
			text = text.replace(/\r\n?/g, "\n");
		}
		for(var i = 0; i < text.length; i++) {
			if(this.getId("skipNewLine").checked && text.charAt(i).match(/[\r\n]/)) {
				unicode += text.charAt(i);
				continue;
			}
			unicode += "&#"+ text.charCodeAt(i) +";";
		}
		this.getId("mainCanvas").value = unicode;
		JSAAE.MCU();
	}
	
	//Unicode ReferenceCharacter Decode
	this.URD = function() {
		var unicode = this.getId("mainCanvas").value;
		var text = "";
		var matches;
		if(this.getId("skipNewLine").checked) {
			matches = unicode.match(/(&#\d+;|[\r\n])/g);
		} else {
			matches = unicode.match(/&#\d+;/g);
		}
		if (!matches) return;
		var code;
		for(var i = 0; i < matches.length; i++) {
			if(matches[i].match(/(\d+)/)) {
				code = RegExp.$1;
				text += String.fromCharCode(code);
			} else if(matches[i].match(/([\r\n])/)) {
				text += RegExp.$1;
			}
		}
		if(this.getId("encodeLineFord").checked) {
			text = text.replace(/\r\n?/g, "\n");
		}
		this.getId("mainCanvas").value = text;
		JSAAE.MCU();
	}
	
	//Simple Tool URL-Encode/Decode
	this.STU = function(mode) {
		var text = this.getId("mainCanvas").value;
		switch(mode) {
			case "en":
				text = encodeURI(text);
				break;
			case "de":
				try {
					text = decodeURI(text);
				} catch(ex) {
					this.setStatus("デコード失敗");
					return;
				}
				break;
		}
		this.getId("mainCanvas").value = text;
		JSAAE.MCU();
	}
	
	//Barya Trap Convert
	this.BTC = function() {
		var text = this.getId("mainCanvas").value;
		text = text.replace(/　 　 　 　 /g, "　　　　    ");
		text = text.replace(/　 　 　 /g, "　　　   ");
		text = text.replace(/　 　 /g, "　　  ");
		text = text.replace(/　{5}/g, "           ");
		text = text.replace(/  /g, "&nbsp; ");
		text = text.replace(/  /g, " &nbsp;");
		this.getId("mainCanvas").value = text;
		JSAAE.MCU();
	}
	
	//Barya Trap Deconvert
	this.BTD = function() {
		var text = this.getId("mainCanvas").value;
		text = text.replace(/&nbsp;/g, " ");
		text = text.replace(/ {11}/g, "　　　　　");
		text = text.replace(/　　  /g, "　 　 ");
		text = text.replace(/　　　   /g, "　 　 　 ");
		text = text.replace(/　　　　    /g, "　 　 　 　 ");
		text = text.replace(/　　 　  /g, "　 　 　 ");
		var i = 0;
		while(text.match(/ {2}/)) {
			text = text.replace(/　  /g, " 　 ");
			if(++i >= 5) {
				var error = "変換できない２重半角スペースが検出されました。\n\n"+
					"全角スペースで置き換えますか？\n（該当箇所が1pxズレてしまいます。）\n\n"+
					"手動で修正する場合はキャンセルを押してください。";
				if(confirm(error)) {
					alert("全角スペースで置き換えました。\n");
					this.getId("mainCanvas").value = text.replace(/ {2}/g, "　");
					return;
				} else {
					alert("該当箇所の保護のため、２重半角スペース抑止機能が働いている場合はオフにします。\n");
					this.getId("doubleSpace").checked = false;
					this.getId("mainCanvas").value = text;
					return;
				}
			}
		}
		this.getId("mainCanvas").value = text;
		JSAAE.MCU();
	}
	
	//Version Information Display
	this.VID = function() {
		if(this.getId("verInfoSlot").innerHTML == "") {
			var browser;
			switch (this.UA) {
				case "IE":
					browser = '<span class="better">Internet Explorer</span>';
					break;
				case "Mozilla":
					browser = '<span class="warning">Mozilla</span>';
					break;
				case "Unknown":
					browser = '<span class="warning">Unknown</span>';
					break;
			}
			var cookie = "";
			if (document.cookie != "") {
				cookie = 'Cookie: ';
				if (this.cookie && this.cookie.version) cookie += 'ver'+ this.cookie.version +" / ";
				cookie += "約 "+ document.cookie.length +"byte";
			}
			this.getId("verInfoSlot").style.position = "static";
			this.getId("verInfoSlot").innerHTML = 
				'<div id="verInfo">\n'+
				'<div id="verInfoTitle">\n'+
				'バージョン情報 &nbsp;&nbsp;'+
				'<span id="verInfoClose"'+
				' onmouseover="this.style.borderStyle = \'groove\'; this.style.background = \'threedhighlight\'"'+
				' onmouseout="this.style.borderStyle = \'none\'; this.style.background = \'threedface\'"'+
				' onclick="JSAAE.VIC()">×</span>\n'+
				'</div><hr>\n'+
				'<div id="verInfoBody">\n'+
				'	<div id="verInfoName">JSAAE ver '+ this.version +'</div>\n'+
				'	Windows＋IE6.0で動作確認'+
				'	<a href="'+ this.website +'" target="_blank">'+ this.website +'</a>\n'+
				'	<div class="information">'+
				'	ブラウザ: '+ browser +'<br>'+
				'	起動モード: '+ (this.mode == "HTA" ?"HTML Application" :"HTML") +'<br>'+
				cookie +
				'	'+
				'	</div>'+
				'</div>\n'+
				'</div>\n';
			with(this.getId("verInfoButton").style) {
				background = "threedhighlight";
				borderStyle = "groove";
			}
		} else {
			JSAAE.VIC();
		}
	}
	
	//Version Information Close
	this.VIC = function() {
		this.getId("verInfoSlot").style.position = "absolute";
		this.getId("verInfoSlot").innerHTML = '';
		with(this.getId("verInfoButton").style) {
			background = "threedface";
			borderStyle = "";
		}
	}
}

var JSAAE = new AsciiArtEditor();