var qTipTag = "a,label";
var qTipX = 0;
var qTipY = 15;

tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null
}

function is_cjk(text)
{
	if(text.match(/[\u1100-\u11FF\u2E80-\u2EFF\u2F00-\u2FDF\u2FF0-\u2FFF\u3040-\u309F\u30A0-\u30FF\u3100-\u312F\u3130-\u318F\u3190-\u319F\u31A0-\u31BF\u31C0-\u31EF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\u9FCF\uA000-\uA48F\uA490-\uA4CF\uA4D0-\uA4FF\uA960-\uA97F\uAC00-\uD7AF\uD7B0-\uD7FF\uF900-\uFAFF\uFF00-\uFFEF]/)) return 1;
	else if(text.match(/[\u0600-\u06FF\u0750–\u077F\uFB50–\uFDFF\uFE70–\uFEFF]/)) return 1;
	else return 0;
}

tooltip.init = function () {

	for(var i=0;i<document.links.length;i++)
	{
		var t=document.links[i].text;

		if( t && is_cjk(t) )
		{
			document.links[i].setAttribute("class", "cjk");
		}
	}
	for(var i=1;i<3;i++)
	{
		var t = document.getElementById("e"+i);
		if(t && t.innerHTML && is_cjk(t.innerHTML))
		{

			t.setAttribute("class", "cjk");
		}
	}


	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "qTip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

	var a, sTitle, elements;
	
	var elementList = qTipTag.split(",");
	for(var j = 0; j < elementList.length; j++)
	{	
		elements = document.getElementsByTagName(elementList[j]);
		if(elements)
		{
			for (var i = 0; i < elements.length; i ++)
			{
				a = elements[i];
				sTitle = a.getAttribute("title");				
				if(sTitle)
				{
					a.setAttribute("tiptitle", sTitle);
					a.removeAttribute("title");
					a.removeAttribute("alt");
					a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
					a.onmouseout = function() {tooltip.hide()};
				}
			}
		}
	}
}

tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {//IE
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
		
	} else {//Good Browsers
		x = evt.pageX;
		y = evt.pageY;
	}
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
}

tooltip.show = function (text) {
	if (!this.tip) return;

	var parts = text.split("<br>")
	if(parts.length>1)
	{
		if(is_cjk(parts[0])) parts[0] = "<span class=cjk>"+parts[0]+"</span>";
		else parts[0] = "<span class=qtip_title>"+parts[0]+"</span>";
		text = parts.join("<br>");
	}

	this.tip.innerHTML = text;
	this.tip.style.display = "block";
}

tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}

window.onload = function () {


	tooltip.init ();
}

