﻿//Made by mat

function MM_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i>d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function insertTag(MyString)
{
fontbegin='[color=' + MyString + ']'
fontend='[/color]'
fontchuli();
}

function fontchuli(){
if ((document.selection)&&(document.selection.type == "Text")) {
var range = document.selection.createRange();
var ch_text=range.text;
range.text = fontbegin + ch_text + fontend;
} 
else {
document.all.txtContent.value=fontbegin+document.all.txtContent.value+fontend;
document.all.txtContent.focus();
}
}

var base_hexa = "0123456789ABCDEF";
function dec2Hexa(number)
{
   return base_hexa.charAt(Math.floor(number / 16)) + base_hexa.charAt(number % 16);
}

function RGB2Hexa(TR,TG,TB)
{
  return "#" + dec2Hexa(TR) + dec2Hexa(TG) + dec2Hexa(TB);
}
function lightCase(MyObject,objName)
{
	MM_findObj(objName).bgColor = MyObject.bgColor;
}

function lightCase1(MyObject,objName)
{
	MM_findObj(objName).value = MyObject.bgColor;
}

col = new Array;
col[0] = new Array(255,0,255,-1,255,-1);
col[1] = new Array(255,0,0,1,0,0);
col[2] = new Array(255,-1,255,0,0,0);
col[3] = new Array(0,0,255,0,0,1);
col[4] = new Array(0,0,255,-1,255,0);
col[5] = new Array(0,1,0,0,255,0);
col[6] = new Array(255,-1,0,0,255,-1);

function rgb(pas,w,h){
	for (j=0;j<6+1;j++){
		for (i=0;i<pas+1;i++){
			r = Math.floor(col[j][0]+col[j][1]*i*(255)/pas);
			g = Math.floor(col[j][2]+col[j][3]*i*(255)/pas);
			b = Math.floor(col[j][4]+col[j][5]*i*(255)/pas);
		  codehex = r + '' + g + '' + b;
		  document.write('<td bgColor=\"' + RGB2Hexa(r,g,b) + '\" onClick=\"insertTag(this.bgColor);lightCase(this,\'ColorUsed\');\" width=\"'+w+'\" height=\"'+h+'\"><IMG height='+h+' width='+w+' border=0 title=\"<FONT COLOR='+RGB2Hexa(r,g,b)+'>字体颜色：'+RGB2Hexa(r,g,b)+'</FONT>\"></TD>\n');
		}
	}
}

function rgb1(pas,w,h){
for (j=0;j<6+1;j++){
    for (i=0;i<pas+1;i++)
	{
	r = Math.floor(col[j][0]+col[j][1]*i*(255)/pas);
	g = Math.floor(col[j][2]+col[j][3]*i*(255)/pas);
	b = Math.floor(col[j][4]+col[j][5]*i*(255)/pas);
  codehex = r + '' + g + '' + b;
  document.write('<td bgColor=\"' + RGB2Hexa(r,g,b) + '\" onClick=\"lightCase(this,\'ColorHead\');lightCase1(this,\'ChenTopicColor\');\" width=\"'+w+'\" height=\"'+h+'\"><IMG height='+h+' width='+w+' border=0 title=\"<FONT COLOR='+RGB2Hexa(r,g,b)+'>标题颜色：'+RGB2Hexa(r,g,b)+'</FONT>\"></TD>\n');
	}}}

function search(text,caract)
{
	for(i=0;i<text.length;i++)
	{
		if (caract == text.substring(i,i+1))
		return i+1;
	}
}
document.write("<SELECT style=\"width:80px;\" name=font id=font onchange=\"if(this.options[this.selectedIndex].value!=''){showfont(this.options[this.selectedIndex].value);this.options[0].selected=true;}else {this.selectedIndex=0;}\"><OPTION selected value=宋体>字体类型</OPTION><OPTION>========</OPTION><OPTION value=宋体>宋体</OPTION><OPTION value=楷体_GB2312>楷体</OPTION><OPTION value=新宋体>新宋体</OPTION><OPTION value=黑体>黑体</OPTION><OPTION value=隶书>隶书</OPTION><OPTION value=Andale Mono>Andale Mono</OPTION><OPTION value=Arial>Arial</OPTION><OPTION value=Arial Black>Arial Black</OPTION><OPTION value=Book Antiqua>Book Antiqua</OPTION><OPTION value=Century Gothic>Century Gothic</OPTION><OPTION value=Comic Sans MS>Comic Sans MS</OPTION><OPTION value=Courier New>Courier New</OPTION><OPTION value=Georgia>Georgia</OPTION><OPTION value=Impact>Impact</OPTION><OPTION value=Tahoma>Tahoma</OPTION><OPTION value=Times New Roman>Times New Roman</OPTION><OPTION value=Trebuchet MS>Trebuchet MS</OPTION><OPTION value=Script MT Bold>Script MT Bold</OPTION><OPTION value=Stencil>Stencil</OPTION><OPTION value=Verdana>Verdana</OPTION><OPTION value=Lucida Console>Lucida Console</OPTION></SELECT>&nbsp;");
document.write("<SELECT name=size id=size onchange=\"if(this.options[this.selectedIndex].value!=''){showsize(this.options[this.selectedIndex].value);this.options[0].selected=true;}else {this.selectedIndex=0;}\"><OPTION selected value=3>字体大小</OPTION><OPTION>=====</OPTION><OPTION value=1>1</OPTION><OPTION value=2>2</OPTION><OPTION value=3>3</OPTION><OPTION value=4>4</OPTION></SELECT>&nbsp;");
document.write("<IMG alt=粗体 border=0 height=15 onclick=Cbold() src=images/199.gif width=17> <IMG alt=斜体 border=0 height=15 onclick=Citalic() src=images/198.gif width=17> <IMG alt=下划线 border=0 height=15 onclick=Cunder() src=images/197.gif width=17> <IMG alt=居中 border=0 height=15 onclick=Ccenter() src=images/196.gif width=17> <IMG alt=超级连接 border=0 height=15 onclick=Curl() src=images/195.gif width=17> <IMG alt=Email连接 border=0 height=15 onclick=Cemail() src=images/194.gif width=17> <IMG alt=图片 border=0 height=15 onclick=Cimage() src=images/193.gif width=17>  <IMG alt=图片 border=0 height=15 onclick='createFacePanel(this)' src=images/200.gif width=17> ");
document.write("<IMG alt=音乐 border=0 height=15 onclick='Cmusic()' src=images/201.gif width=17> <br>");
function createFacePanel(o)
{
	if(document.getElementById("face")==null)
	{
	var facePanel=document.createElement("div");
	facePanel.id="face";
	facePanel.style.cssText="position:absolute;z-index:997;width:410px;background:#ffffff;border:1px solid #cccccc";
	facePanel.style.left=getoffset((document.all)?o.parentElement:o.parentNode)[1]+"px";
	facePanel.style.top=(getoffset(o)[0]+20)+"px";
	document.body.appendChild(facePanel);
    var emstr = '';
    for(var i = 0;i<52;i++)
    {
        emstr +='<span style=\"margin:5 5 5 0;\" onmouseover=\"this.style.backgroundColor=\'#d8d8d8\'\" onmouseout=\"this.style.backgroundColor=\'#ffffff\'\">[em'+(i>9?i:'0'+i)+']</span>';
    }
    var emformat=/\[em([0-6])([0-9])\]/gi;
    var result="<img onclick=\"insertsmilie(this.title);closeFace()\" title=\"[em$1$2]\" src=\"\/face\/$1$2.gif\">";
	facePanel.innerHTML = emstr.replace(emformat,result);
	}
	else
	{
		closeFace();	
	}
	
}
function getoffset(e) 
{  
 var t=e.offsetTop;  
 var l=e.offsetLeft;  
 while(e=e.offsetParent) 
 {  
  t+=e.offsetTop;  
  l+=e.offsetLeft;  
 }  
 var rec = new Array(1); 
 rec[0]  = t; 
 rec[1] = l; 
 return rec 
}
function closeFace()
{
	document.body.removeChild(document.getElementById('face'));
}
