﻿var showtools=0;
function Scrolling(){
	var csdnScrollTop=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
	if(document.getElementById("Menu01")!=null)
	{
		document.getElementById("Menu01").style.top=csdnScrollTop+'px';
		if(showtools!=0&&showtools!=1)
		{
			var h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
			document.getElementById("Tools").style.top=(csdnScrollTop+(h-document.getElementById("Tools").offsetHeight)/2)+'px';
		}
		setTimeout("Scrolling();",10);
	}
}
function clicktools(){
	if(toolcontrol!=null)
	{
		toolcontrol.className='div_ctc';
		toolcontrol=null;
	}
	if(showtools!=0)
	{
		var div_editor=document.getElementsByName("div_editor");
		for(var i=0;i<div_editor.length;i++)
		{
			if(div_editor[i].getAttribute("right")==null||div_editor[i].getAttribute("right")!=null&&IsConsistent(div_editor[i].getAttribute("right"),GetCookie("Member_InGroup")))
			{
				var obj=document.createElement("div");
				obj.innerHTML="";
				for(j=0;j<div_editor[i].childNodes.length;j++)
				{
					obj.innerHTML+=div_editor[i].childNodes[j].innerHTML;
	
					var obj1=document.createElement("div");
					obj1.innerHTML="<br><span class='ACTX'></span>";
					var s=obj1.innerHTML;
					obj.innerHTML=obj.innerHTML.split(s)[0];
	
					if(j!=div_editor[i].childNodes.length-1)
					{
						var div=document.createElement("div");
						div.setAttribute("split","itoscar");
						obj.appendChild(div);
					}
				}
				div_editor[i].innerHTML=obj.innerHTML;
				div_editor[i].className="div_noborder";
				ChangeAllEditor(div_editor[i],false);
			}
		}
		document.getElementById("Tools").style.display="none";
		showtools=0;
	}
	else
	{
		var div_editor=document.getElementsByName("div_editor");
		for(var i=0;i<div_editor.length;i++)
		{
			if(div_editor[i].getAttribute("right")==null||div_editor[i].getAttribute("right")!=null&&IsConsistent(div_editor[i].getAttribute("right"),GetCookie("Member_InGroup")))
			{
				var obj=document.createElement("div");
				obj.innerHTML="<div split=\"itoscar\"></div>";
				var s=obj.innerHTML;
				var tmpcontrol=div_editor[i];
				try
				{
					if(div_editor[i].firstChild.tagName.toLowerCase()=="span"&&div_editor[i].firstChild.getAttribute("txt")=="itoscar")
						tmpcontrol=div_editor[i].firstChild;
				}
				catch(ex){}
				var tmphtml=tmpcontrol.innerHTML.split(s);
				div_editor[i].innerHTML="";
				for(var j=0;j<tmphtml.length;j++)
				{
					if(tmphtml[j].length!=0&&(tmphtml[j].length!=2||tmphtml[j].replace(/\r\n/g,"")!=""))
					{
						var div=document.createElement("div");
						div.id="div_minieditor";
						div.name="div_minieditor";
						div.className="div_minishowborder";
						if(div_editor[i].style.fontSize!="")
							div.style.fontSize=div_editor[i].style.fontSize;
						if(div_editor[i].style.fontFamily!="")
							div.style.fontFamily=div_editor[i].style.fontFamily;
						div.onclick=function(){editoronClick(this);};
						div.innerHTML=tmphtml[j];
	
						var br=document.createElement("br");
						div.appendChild(br);
	
						var span=document.createElement("span");
						span.className="ACTX";
						div.appendChild(span);
	
						div_editor[i].appendChild(div);
					}
				}
				if(div_editor[i].innerHTML.length==0)
				{
					var div=document.createElement("div");
					div.id="div_minieditor";
					div.name="div_minieditor";
					div.className="div_minishowborder";
					if(div_editor[i].style.fontSize!="")
						div.style.fontSize=div_editor[i].style.fontSize;
					if(div_editor[i].style.fontFamily!="")
						div.style.fontFamily=div_editor[i].style.fontFamily;
					div.onclick=function(){editoronClick(this);};
	
					var br=document.createElement("br");
					div.appendChild(br);
	
					var span=document.createElement("span");
					span.className="ACTX";
					div.appendChild(span);
	
					div_editor[i].appendChild(div);
				}
				div_editor[i].className="div_showborder";
				ChangeAllEditor(div_editor[i],true);
			}
		}
		showtools=1;
	}
}
_OnLoadStr+="Scrolling();\n";
var toolcontrol=null;
var toolwidth=null;
var toolheight=null;
function toolonClick(control)
{
	if(toolcontrol!=null)toolcontrol.className='div_ctc';
	if(toolcontrol==control)
	{
		toolcontrol=null;
		toolwidth=null;
		toolheight=null;
		control.className='div_ctc';
	}
	else
	{
		toolcontrol=control;
		control.className='div_utc';
	}
}
function toolonMouseOut(control)
{
	if(toolcontrol!=control)control.className='div_ctc';
}
function toolonMouseOver(control)
{
	if(toolcontrol!=control)control.className='div_utc';
}

var editorcontrol=null;
var minidiv=null;
var showtoolstype=null;
function editoronClick(control)
{
	toolwidth=null;
	toolheight=null;
	if(control.id=="div_editor"&&control.className=="div_showborder")
	{
		toolcontrol=null;
		if(showtools!=1)
			showtools.className="div_showborder";
		showtools=control;
		showtools.className="div_showeborder";
		if(showtools.getAttribute("type")!=null)
			showtoolstype=showtools.getAttribute("type");

		var obj1=document.createElement("div");
		obj1.innerHTML="<br><span class='ACTX'></span>";
		var s=obj1.innerHTML;
		var s1=showtools.firstChild.innerHTML.split(s)[0];
		for(var i=0;i<99;i++)
		{
			try
			{
				if(showtools.getAttribute("type")==null||showtools.getAttribute("type").indexOf("-"+(i+"").format(2)+"-")!=-1)
				{
					document.getElementById("TS"+(i+"").format(2)).style.display="block";
					document.getElementById("TS"+(i+"").format(2)).className='div_ctc';
					if(toolcontrol==null&&s1=="")toolonClick(document.getElementById("TS"+(i+"").format(2)));
				}
				else
					document.getElementById("TS"+(i+"").format(2)).style.display="none";
			}
			catch(e){}
		}
		document.getElementById("Tools").style.display="block";
	}
	else if(toolcontrol!=null&&control.id=="div_editor"&&toolcontrol.id.indexOf("TS")==0&&control.className=="div_showeborder")
	{
		if(toolcontrol.getAttribute("width")!=null)toolwidth=toolcontrol.getAttribute("width");
		if(toolcontrol.getAttribute("height")!=null)toolheight=toolcontrol.getAttribute("height");
		minidiv=document.createElement("div");
		minidiv.id="div_minieditor";
		minidiv.name="div_minieditor";
		minidiv.className="div_minishowborder";
		if(control.style.fontSize!="")
			minidiv.style.fontSize=control.style.fontSize;
		if(control.style.fontFamily!="")
			minidiv.style.fontFamily=control.style.fontFamily;
		minidiv.onclick=function(){editoronClick(this);};

		editorcontrol=control;
		if(toolwidth==null)
			toolwidth=editorcontrol.clientWidth+30;
		if(toolheight==null)
			toolheight=500;
		ShowDialog("/toolsbar/"+toolcontrol.id+".html",toolwidth,toolheight,minidiv.style.fontSize,minidiv.style.fontFamily,control.getAttribute("tb"),control.getAttribute("fn"),control.getAttribute("tid"));
	}
	else if(toolcontrol==null&&control.id=="div_minieditor"&&control.parentNode.className=="div_showeborder")
	{
		editorcontrol=control;
		var url="/toolsbar/TS"+showtoolstype.split("-")[1].split("-")[0]+".html";
		for(var i=99;i>-1;i--)
		{
			try
			{
				if(eval("check_TS"+(i+"").format(2)+"()"))
				{
					if(document.getElementById("TS"+(i+"").format(2)).getAttribute("width")!=null)toolwidth=document.getElementById("TS"+(i+"").format(2)).getAttribute("width");
					if(document.getElementById("TS"+(i+"").format(2)).getAttribute("height")!=null)toolheight=document.getElementById("TS"+(i+"").format(2)).getAttribute("height");
					url="/toolsbar/TS"+(i+"").format(2)+".html";
					break;
				}
			}
			catch(e){}
		}
		if(toolwidth==null)
			toolwidth=editorcontrol.clientWidth+30;
		if(toolheight==null)
			toolheight=500;
		ShowDialog(url,toolwidth,toolheight,editorcontrol.style.fontSize,editorcontrol.style.fontFamily,editorcontrol.parentNode.getAttribute("tb"),editorcontrol.parentNode.getAttribute("fn"),editorcontrol.parentNode.getAttribute("tid"));
	}
}
function Todiv_editor()
{
	var div_editor=document.getElementsByName("div_editor");
	for(var i=0;i<div_editor.length;i++)
	{
		div_editor[i].className="div_noborder";
		div_editor[i].onclick=function(){editoronClick(this);};
	}
}
_OnLoadStr+="Todiv_editor();\n";
function Todiv_table()
{
	var div_table=document.getElementsByName("div_table");
	for(var i=0;i<div_table.length;i++)
	{
		div_table[i].innerHTML="<img onload=\"this.parentNode.style.width=this.parentNode.parentNode.width+'px';\" src=\"/images/t.gif\" width=\"0\">";
	}
}
_OnLoadStr+="Todiv_table();\n";
function ChangeAllEditor(_Control,_Open)
{
	for(var i=0;i<_Control.childNodes.length;i++)
	{
		ChangeAllEditor(_Control.childNodes[i],_Open);
	}
	if(_Open)
	{
		if(typeof _Control.tagName!='undefined'&&(typeof _Control.name=='undefined'||typeof _Control.name!='undefined'&&_Control.name.indexOf("div_editor")==-1&&_Control.name.indexOf("div_minieditor")==-1)&&(typeof _Control.id=='undefined'||typeof _Control.id!='undefined'&&_Control.id.indexOf("div_editor")==-1&&_Control.id.indexOf("div_minieditor")==-1))
		{
			if(_Control.getAttribute("onClick")!=null&&_Control.getAttribute("onClick").toString()!="")
			{
				var onclick=_Control.getAttribute("onClick").toString();
				if(window.showModalDialog!=null)
					onclick=onclick.substring(onclick.indexOf("{")+1,onclick.lastIndexOf("}")).replace(/\r/g,"").replace(/\n/g,"");
				_Control.setAttribute("itoscaronClick",onclick);
				_Control.onclick=function(){return false;};
			}
			else if(_Control.getAttribute("onclick")!=null&&_Control.getAttribute("onclick").toString()!="")
			{
				var onclick=_Control.getAttribute("onclick").toString();
				if(window.showModalDialog!=null)
					onclick=onclick.substring(onclick.indexOf("{")+1,onclick.lastIndexOf("}")).replace(/\r/g,"").replace(/\n/g,"");
				_Control.setAttribute("itoscaronclick",onclick);
				_Control.onclick=function(){return false;};
			}
			if(_Control.getAttribute("onClick")==null||_Control.getAttribute("onClick").toString()==""||_Control.getAttribute("onclick")==null||_Control.getAttribute("onclick").toString()=="")
			{
				_Control.onclick=function(){return false;};
			}
			if(_Control.getAttribute("onload")!=null&&_Control.getAttribute("onload").toString()!="")
			{
				var onload=_Control.getAttribute("onload").toString();
				if(window.showModalDialog!=null)
					onload=onload.substring(onload.indexOf("{")+1,onload.lastIndexOf("}")).replace(/\r/g,"").replace(/\n/g,"");
				_Control.setAttribute("itoscaronload",onload);
				_Control.onload=function(){};
			}
			if(_Control.tagName.toLowerCase()!="img"&&_Control.getAttribute("href")!=null&&_Control.getAttribute("href").toString()!="")
			{
				_Control.setAttribute("itoscarhref",_Control.getAttribute("href").toString());
				//_Control.setAttribute("href","#");
				_Control.setAttribute("itoscartarget","_self");
				if(_Control.getAttribute("target")!=null&&_Control.getAttribute("target").toString()!="")
				{
					_Control.setAttribute("itoscartarget",_Control.getAttribute("target").toString());
				}
			}
		}
	}
	else
	{
		if(typeof _Control.tagName!='undefined'&&(typeof _Control.name=='undefined'||typeof _Control.name!='undefined'&&_Control.name.indexOf("div_editor")==-1&&_Control.name.indexOf("div_minieditor")==-1)&&(typeof _Control.id=='undefined'||typeof _Control.id!='undefined'&&_Control.id.indexOf("div_editor")==-1&&_Control.id.indexOf("div_minieditor")==-1))
		{
			if(_Control.getAttribute("itoscaronClick")!=null&&_Control.getAttribute("itoscaronClick").toString()!="")
			{
				eval("_Control.onclick=function(){"+_Control.getAttribute("itoscaronClick").toString()+"};");
			}
			else if(_Control.getAttribute("itoscaronclick")!=null&&_Control.getAttribute("itoscaronclick").toString()!="")
			{
				eval("_Control.onclick=function(){"+_Control.getAttribute("itoscaronClick").toString()+"};");
			}
			else
			{
				_Control.onclick=function(){};
			}
			if(_Control.getAttribute("itoscaronload")!=null&&_Control.getAttribute("itoscaronload").toString()!="")
			{
				eval("_Control.onload=function(){"+_Control.getAttribute("itoscaronload").toString()+"};");
			}
			if(_Control.getAttribute("itoscarhref")!=null&&_Control.getAttribute("itoscarhref").toString()!="")
			{
				_Control.href=_Control.getAttribute("itoscarhref").toString();
			}
			if(_Control.getAttribute("itoscartarget")!=null&&_Control.getAttribute("itoscartarget").toString()!="")
			{
				_Control.target=_Control.getAttribute("itoscartarget").toString();
			}
		}
	}
}
