aki.edt=new Object();
aki.edt.wordEncode="utf8";
aki.edt.mainID=false;
aki.edt.mode="Design";
aki.edt.btn=false;
aki.edt.iconPath="icon/";
aki.edt.width=new Array();
aki.edt.height=new Array();
aki.edt.newbuttonmenu=16;
aki.edt.config=function(){
													this.btn={	"outdent":           ["outdent","aki.edt.action(this.id,'"+aki.edt.mainID+"');","outdent.jpg","ooutdent.jpg"],
																		"indent":           ["indent","aki.edt.action(this.id,'"+aki.edt.mainID+"');","indent.jpg","oindent.jpg"],
																		"justifycenter":           ["justifycenter","aki.edt.action(this.id,'"+aki.edt.mainID+"');","fcenter.jpg","ofcenter.jpg"],
																		"justifyleft":           ["justifyleft","aki.edt.action(this.id,'"+aki.edt.mainID+"');","fleft.jpg","ofleft.jpg"],
																		"justifyright":           ["justifyright","aki.edt.action(this.id,'"+aki.edt.mainID+"');","fright.jpg","ofright.jpg"],
																		"bold":			["<b></b>",						"aki.edt.action(this.id,'"+aki.edt.mainID+"');","bold.jpg","obold.jpg"],
																		 "italic":			["<i></i>",						"aki.edt.action(this.id,'"+aki.edt.mainID+"');","italic.jpg","oitalic.jpg"],
																		"underline":			["<u></u>",				"aki.edt.action(this.id,'"+aki.edt.mainID+"');;","underline.jpg","ounderline.jpg"],
																		"strikethrough":			["<strike><strike>",				"aki.edt.action(this.id,'"+aki.edt.mainID+"');;","strick.jpg","ostrick.jpg"],
																		"subscript":			["<sub></sub>",						"aki.edt.action(this.id,'"+aki.edt.mainID+"');;","sub.jpg","osub.jpg"],
																		"superscript":			["<sup></sup>",						"aki.edt.action(this.id,'"+aki.edt.mainID+"');;","sup.jpg","osup.jpg"],
																		"InsertImage":		["<img src=>",			"aki.edt.action(this.id,'"+aki.edt.mainID+"');","image.jpg","oimage.jpg"],
																		"CreateLink":		["<a href=></a>","aki.edt.action(this.id,'"+aki.edt.mainID+"');","link.jpg","olink.jpg"],
																		"ForeColor":["<font color=></font>",		"aki.edt.action(this.id,'"+aki.edt.mainID+"');","color.jpg","ocolor.jpg"],
																		"BackColor":["background-color",		"aki.edt.action(this.id,'"+aki.edt.mainID+"');","bgcolor.jpg","obgcolor.jpg"],
																		"InsertTable":		["<table></table>",		"aki.edt.action(this.id,'"+aki.edt.mainID+"');;","table.jpg","otable"],
																		"file":           ["Upload File for download link.","aki.edt.action(this.id,'"+aki.edt.mainID+"');","file.jpg","ofile.jpg"],
																		"falsh":           ["Upload File Flash.","aki.edt.action(this.id,'"+aki.edt.mainID+"');","flash.jpg","oflash.jpg"],
																		"mode":		["View source or Design Mode",					"aki.edt.loadoutput('mode_"+aki.edt.mainID+"');","code.jpg","ocode.jpg"]
																		,"SaveAs":		["Save",						"aki.edt.action(this.id,'"+aki.edt.mainID+"');","save.jpg","osave.jpg"]};
													this.fontnames = {
																						"Arial":           "arial, helvetica, sans-serif",
																						"Courier New":     "courier new, courier, mono",
																						"Georgia":         "Georgia, Times New Roman, Times, Serif",
																						"MS Sans serif":"MS Sans serif",
																						"Tahoma":          "Tahoma, Arial, Helvetica, sans-serif",
																						"Times New Roman": "times new roman, times, serif",
																						"Verdana":         "Verdana, Arial, Helvetica, sans-serif",
																						"WingDings":       "WingDings"};

																			this.fontsizes = {
																				"1 (8 pt)":  "1",
																				"2 (10 pt)": "2",
																				"3 (12 pt)": "3",
																				"4 (14 pt)": "4",
																				"5 (18 pt)": "5",
																				"6 (24 pt)": "6",
																				"7 (36 pt)": "7"
																			  };
																			  this.fontstyle={
																				 "<p>":"Normal",
																				 "<h1>":"Heading 1 <H1>",
																				 "<h2>":"Heading 2 <H2>",
																				 "<h3>":"Heading 3 <H3>",
																				"<h4>":"Heading 4 <H4>",
																				"<h5>":"Heading 5 <H5>",
																				"<h6>":"Heading 6 <H6>",
																				"<address>":"Address <ADDR>",
																				"<pre>":"Formatted <PRE>"
																			  };
												}
aki.edt.href=function(xhref){return window.location=xhref;}
aki.edt.loadEditor=function(objframe,objname,btn)
									{		aki.edt.btn=btn.split(",");
											frmEdit=aki.getid(objframe);
											objtext=aki.getid(objname);	
											aki.edt.mainID=objname;
											aki.edt.width[objname]=objtext.style.width;
											aki.edt.height[objname]=objtext.style.height;
											var html="<table border=0 cellpadding=0 cellspacing=0 style=\"border-collapse:collapse;border:#F2F0E0 1px solid;\" bordercolor=\"#111111\" class=\"editor\" id=\"ctb"+objname+"\">"
													html +="<tr><td width=\"100%\" bgcolor=\"#F2F0E0\" style=\"padding-bottom:5px;\">"+aki.edt.loadMenu()+"</td></tr>";
													html +="<tr><td width=\"100%\" bgcolor=\"#F2F0E0\" style=\"padding-bottom:5px;\">"+aki.edt.loadTemplate()+"</td></tr>";
													html +="<tr>";
													html +="<td width=\"100%\" height=\"40\" id=\"subframe_"+aki.edt.mainID+"\">";
																		if(aki.edt.mode.toLowerCase()=="design")
																			{		var fhtml="<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset="+aki.edt.wordEncode+";\"><link rel=\"stylesheet\" type=\"text/css\" href=\"../library/function.css\"></head><body>"+objtext.value+"</body></html>";
																					html +="<iframe style=\"width:"+objtext.style.width+";height:"+objtext.style.height+";background-Color:#FFFFFF;\" id=\"iframe_"+objname+"\" frameborder=\"0\"></iframe>";
																					html +="</td></tr><tr><td width=\"100%\" height=\"20\" bgcolor=\"#F2F0E0\" style=\"font-family:MS Sans serif;font-size:8px;color:#000000;\" id=\"mode_"+aki.edt.mainID+"\">&nbsp;{ "+aki.edt.mode+" }</td></tr></table>";
																					frmEdit.innerHTML=html;
																					var ifrmEdit=aki.getid("iframe_"+objname).contentWindow.document;
																							ifrmEdit.designMode="on";
																							ifrmEdit.open();
																							ifrmEdit.write(fhtml);
																							ifrmEdit.close();
																							aki.getid("iframe_"+objname).contentWindow.focus();
																					
																			}
																			
												
											
								}
aki.edt.useTemplate=function(xid,xval){
			
			var fhtml="<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset="+aki.edt.wordEncode+";\"><link rel=\"stylesheet\" type=\"text/css\" href=\"../library/function.css\"></head><body>"+aki.getid(xval).innerHTML+"</body></html>";
																						var ifrmEdit=aki.getid("iframe_"+xid).contentWindow.document;
																							ifrmEdit.designMode="on";
																							ifrmEdit.open();
																							ifrmEdit.write(fhtml);
																							ifrmEdit.close();
																							aki.getid("iframe_"+xid).contentWindow.focus();
															
	}
aki.edt.loadTemplate=function(){
																		
																		var thtml="<table border=0 cellpadding=2 cellspacing=0 style=\"border-collapse:collapse;\" bordercolor=\"#111111\">";
																				thtml +="<tr><td width=\"100%\" height=\"20\">";
																				thtml +="<table border=0 cellpadding=2 cellspacing=0 style=\"border-collapse:collapse;\" bordercolor=\"#111111\"><tr>";
																		for(i=1;i<=5;i++){
																				thtml +="<td width=\"22\"><img src=\""+aki.edt.iconPath+"set"+i+".jpg\" title=\"แม่แบบโครงสร้างเอกสาร แบบที่ "+i+"\" style=\"cursor:pointer;\" onclick=\"aki.edt.useTemplate('"+aki.edt.mainID+"','set"+i+"');\" width=\"16\" height=\"16\"></td>";
																		}
																		thtml +="</tr></table>";
																return thtml;}
aki.edt.loadoutput=function(mnid){ var html="";obj_id="";
																	objid=mnid.split("_");
																			for(i=1;i<objid.length;i++)
																					{obj_id +=objid[i];
																						if(i<objid.length-1){obj_id +="_";}
																						}
																			obj=aki.getid("subframe_"+obj_id);
																			smode=aki.getid(mnid).innerHTML.replace("&nbsp;{ ","");
																			smode=smode.replace(" }","");
															if(smode.toLowerCase()=="html code"){
																					var fhtml="<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset="+aki.edt.wordEncode+";\"><link rel=\"stylesheet\" type=\"text/css\" href=\"../library/function.css\"></head><body>"+aki.getid(obj_id).value+"</body></html>";
																					html +="<iframe style=\"background-color:#FFFFFF;width:"+aki.edt.width[obj_id]+";height:"+aki.edt.height[obj_id]+";\" id=\"iframe_"+obj_id+"\" frameborder=\"0\"></iframe>";
																					obj.innerHTML=html;
																		var iframeobj=aki.getid("iframe_"+obj_id).contentWindow.document;
																					iframeobj.designMode="on";
																					iframeobj.open();
																					iframeobj.write(fhtml);
																					iframeobj.close();
																aki.edt.mode="&nbsp;{ Design }";
																aki.getid(mnid).innerHTML=aki.edt.mode;
															}
															else
															{	var iframeobj=aki.getid("iframe_"+obj_id).contentWindow.document;
																html +="<textarea name=\""+obj_id+"\" id=\""+obj_id+"\" style=\"width:"+aki.edt.width[obj_id]+";height:"+aki.edt.height[obj_id]+";border:#EEEEEE 1px dotted;\">"+iframeobj.body.innerHTML+"</textarea>";
																obj.innerHTML=html;
																aki.edt.mode="&nbsp;{ HTML Code }";
																aki.getid(mnid).innerHTML=aki.edt.mode;
																}
														}
aki.edt.loadMenu=function(){
															if(aki.edt.btn==false && aki.edt.btn=="")
																{return aki.edt.status=false;}
															config=new aki.edt.config();
															var pr=0;
															//var fhtml="<table border=0 cellpadding=0 cellspacing=0 style=\"border-collapse:collapse;\" bordercolor=\"#111111\" height=\"20\" bgcolor=\"#F2F0E0\"><tr>";
															var fhtml="";
															var mhtml="<table border=0 cellpadding=0 cellspacing=0 style=\"border-collapse:collapse;\" bordercolor=\"#111111\" height=\"20\" bgcolor=\"#F2F0E0\"><tr>";
																	for(a=0;a<aki.edt.btn.length;a++)
																	{		
																			for(var str in config.btn){
																				if(aki.edt.btn[a].toLowerCase()==str.toLowerCase())
																				{	
																						if(aki.edt.btn[a].toLowerCase()=="forecolor" || aki.edt.btn[a].toLowerCase()=='backcolor')
																								{
																									mhtml +="<td id=\""+aki.edt.mainID+"_"+aki.edt.btn[a].toLowerCase()+"\">";
																									mhtml +="<img src=\""+aki.edt.iconPath+config.btn[str][2]+"\" style=\"cursor:pointer;\" onmousedown=\""+config.btn[str][1]+"\" onmouseover=\"aki.edt.changeSRC(this,'"+aki.edt.iconPath+config.btn[str][3]+"');\" onmouseout=\"aki.edt.changeSRC(this,'"+aki.edt.iconPath+config.btn[str][2]+"');\" id=\""+str+"\" title=\""+str+"\">";
																									mhtml +=aki.edt.loadTBcolor(aki.edt.mainID+"_"+str.toLowerCase())+"</td>";
																									}
																							
																							else
																							{
																								mhtml +="<td><img src=\""+aki.edt.iconPath+config.btn[str][2]+"\" style=\"cursor:pointer;\" onclick=\""+config.btn[str][1]+"\" onmouseover=\"aki.edt.changeSRC(this,'"+aki.edt.iconPath+config.btn[str][3]+"');\" onmouseout=\"aki.edt.changeSRC(this,'"+aki.edt.iconPath+config.btn[str][2]+"');\" id=\""+str+"\"  title=\""+str+"\"></td>";
																							}
																					
																					}//End if		
																					
																				}//End loopstr
																				
																					if(a%aki.edt.newbuttonmenu==0 && a>0){mhtml +="</tr><tr>";}
																				if(aki.edt.btn[a].toLowerCase()=="font")
																					{
																						var fnt="";
																								for(var font in config.fontnames)
																										{				fnt += '<option value="' +config.fontnames[font]+ '">' +font+ '</option>';	}
																														fhtml +="<td><select id=\"fontname\" onChange=\"aki.edt.action(this.id,'"+aki.edt.mainID+"',this.options[this.selectedIndex].value)\" unselectable=\"on\" style=\"margin: 1 2 0 2; font-size: 12px;\"><option value=\"\">Font</option>"+fnt+"</select></td>";
																					}
																					else if(aki.edt.btn[a].toLowerCase()=="fontsize")
																					{
																							var fnt="";
																									for(var fontsize in config.fontsizes)
																											{			fnt += '<option value="' +config.fontsizes[fontsize]+ '">' +fontsize+ '</option>';	}
																														fhtml +="<td><select id=\"fontsize\" onChange=\"aki.edt.action(this.id,'"+aki.edt.mainID+"',this.options[this.selectedIndex].value)\" unselectable=\"on\" style=\"margin: 1 2 0 2; font-size: 12px;\"><option value=\"\">Font Size</option>"+fnt+"</select></td>";
																					}
																					else if(aki.edt.btn[a].toLowerCase()=="fontstyle"){
																							
																							var fnt="";
																									for(var fontstyle in config.fontstyle)
																										{fnt += '<option value="' +fontstyle+ '">' +config.fontstyle[fontstyle]+ '</option>';	}
																														fhtml +="<td><select id=\"formatblock\" onChange=\"aki.edt.action(this.id,'"+aki.edt.mainID+"',this.options[this.selectedIndex].value)\" unselectable=\"on\" style=\"margin: 1 2 0 2; font-size: 12px;\"><option value=\"\">Style</option>"+fnt+"</select></td>";
																					}
																			
																	}//Endloop a
																	mhtml +=fhtml+"</tr></table>";
									return mhtml;}
aki.edt.loadTBcolor=function(idt){
																ctype=idt.substr(idt.lastIndexOf("_")+1);
																ar_color=new Array("FF","CC","99","66","33","00");
																var r=0,g=0,p=0;
																		(document.all)?bwf="margin:30 -32;":bwf="";
																		var html ="<table border=1 cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse:collapse;display:none;"+bwf+"\" bordercolor=\"#FFFFFF\" Bgcolor=\"#FFFFFF\" id=\"tb_"+idt+"\" width=\"216\" class=\"tablecolor\"><tr>";
																					for(i=1;i<217;i++){
																							if(r%6==0 && r>0)
																									{g++;r=0;}
																							zrgp=ar_color[r]+ar_color[g]+ar_color[p];
																							if(i%6==0)
																								{r++;p=0;}
																							else
																								{p++;}
																						html +="<td width=\"12\" height=\"12\" id=\"cell_tbcolor\"><img src=\""+aki.edt.iconPath+"color.gif\"	style=\"background-color:#"+zrgp+";\" onClick=\"aki.edt.action('"+ctype+"','"+aki.edt.mainID+"','#"+zrgp+"');\" ></td>";
																						if(i%18==0 && i>0)
																							{html +="</tr><tr>";}
																					}
																		html +="</tr></table>";			
													return html;}
	
		
aki.edt.changeSRC=function(e,v){e.src=v;}
aki.edt.opentap=function(xmod,xw,xh){return document.open("plugin_editor.php?mod="+xmod,'blank','top=0,width='+xw+',height='+xh);}
aki.edt.getevent=function getevent(e){
																			if(document.all)
																			{	this.event=window.event;}
																		else
																			{	this.event=e;}}
aki.edt.saveALL=function(xform){var chrid="";
																
																tobj=aki.gettag("table");
																idhtml="";
																for(i=0;i<tobj.length;i++){
																	if(tobj[i].className=="editor")
																	{chrid=tobj[i].id.substr(3,tobj[i].id.length-3);
																			/// Check Mode
																			smode=aki.getid("mode_"+chrid).innerHTML.replace("&nbsp;{ ","");
																			smode=smode.replace(" }","");
																			/// End
																			
																				if(smode=="HTML Code"){

																					var fhtml="<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset="+aki.edt.wordEncode+";\"></head><body>";
																							fhtml +=aki.getid(chrid).value+"</body></html>";
																					var html="<iframe style=\"width:"+aki.edt.width[chrid]+";height:"+aki.edt.height[chrid]+";border:#EEEEEE 1px dotted;\" id=\"iframe_"+chrid+"\" frameborder=\"0\"></iframe>";
																					aki.getid("subframe_"+chrid).innerHTML=html;
																					var iframeobj=aki.getid("iframe_"+chrid).contentWindow.document;
																							iframeobj.designMode="on";
																							iframeobj.open();
																							iframeobj.write(fhtml);
																							iframeobj.close();
																							aki.edt.mode="&nbsp;{ Design }";
																							aki.getid("mode_"+chrid).innerHTML=aki.edt.mode;
																					}
																				shortobj=aki.getid("iframe_"+chrid).contentWindow.document;
																				content=shortobj.body.innerHTML;
																																						
																			aki.getid("subframe_"+chrid).innerHTML +="<textarea style=\"width:"+aki.edt.width[chrid]+";height:"+aki.edt.height[chrid]+";display:none;\" name=\""+chrid+"\" id=\""+chrid+"\">"+content+"</textarea>";
																		

																		}
																}
															var com="false";
															tagform=aki.gettag("form");
															for(a=0;a<tagform.length;a++){
																if(tagform[a].name==xform){com=a;break;}
															}
															if(com!="false"){document.forms[com].submit();
															}
															
													}
aki.edt.action=function(e,cid,val){
																shortobj=aki.getid("iframe_"+cid).contentWindow.document;
																if(e.toLowerCase()=="createlink")
																	{	var url=prompt("Insert Url (You can use your URL) : ", "http://");
																		if(url!=null) {shortobj.execCommand(e,false,url);}}
																
																else if(e.toLowerCase()=="forecolor" || e.toLowerCase()=="backcolor")
																	{				str=e;
																					if(val){	
																									if(!document.all && e.toLowerCase()=="backcolor"){e="hilitecolor";}
																										return shortobj.execCommand(e,false,val);}
																					strnm="tb_"+cid+"_"+e.toLowerCase();
																					tagCo=aki.gettag("table");
																					for(i=0;i<tagCo.length;i++){if(tagCo[i].className=="tablecolor"){tagCo[i].style.display='none';}}
																					cobj=aki.getid(strnm);
																						
																						if(cobj.style.display=="none")
																							{	cobj.style.display="block";
																								cobj.style.position="absolute";}
																						else
																							{	cobj.style.display="none";}
																				
																							document.onclick=function(e)
																													{			
																																	cfg=new aki.edt.getevent(e);
																																	var target=null;
																																		if(cfg.event.target){
																																		target=cfg.event.target;}
																																		else
																																			{target=cfg.event.srcElement;}
																																		if(target.id!=str)
																																			{cobj.style.display='none';
																																				}
																																	
																																}
																					
																	}
															   else if(e.toLowerCase()=="insertimage"){
																		aki.edt.opentap('insertimage&id=iframe_'+cid,'800','600');
																	}
																else if(e.toLowerCase()=="file"){
																		aki.edt.opentap('insertfile&id=iframe_'+cid,'800','600');
																	}
																else if(e.toLowerCase()=="inserttable")
																	{
																			aki.edt.opentap("inserttable&id=iframe_"+cid,"800","600");
																	}
																else if(e.toLowerCase()=="saveas")
																{
																		content=shortobj.body.innerHTML;
																		content=content.replace(/\r\n/g,"<br>");
																		content=content.replace(/\r/g,"<br>");
																			aki.getid("subframe_"+cid).innerHTML +="<textarea style=\"width:"+aki.edt.width[cid]+";height:"+aki.edt.height[cid]+";display:none\" name=\""+cid+"\" id=\""+cid+"\">"+content+"</textarea>";
																		
																	}
																	else if(e.toLowerCase()=="fontname" || e.toLowerCase()=="fontsize" || e.toLowerCase()=="formatblock")
																		{
																			shortobj.execCommand(e,false,val);
																		}
																else
																	{	shortobj.execCommand(e,false,false);}
													}
	
