window.onerror = null;
var tips_attr_name = "tips";
var tips_blank_text = "";
var tips_newline_entity = "  ";
var tips_max_width = 0;

window.onload = function(e){
	if (document.createElement && document.getElementsByTagName) tips.d();
}

tips = {

	t: document.createElement("DIV"),
	c: null,
	g: false,

	m: function(e){
		if (tips.g){
			oCanvas = document.getElementsByTagName(
			(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
			)[0];
			x = window.event ? event.clientX + oCanvas.scrollLeft : e.pageX;
			y = window.event ? event.clientY + oCanvas.scrollTop : e.pageY;
			tips.a(x, y);
		}
	},

	d: function(){
		tips.t.setAttribute("id", "tips");
		tips.t.style.filter = "alpha(opacity=80)";
		document.body.appendChild(tips.t);
		a = document.all ? document.all : document.getElementsByTagName("*");
		aLength = a.length;
		for (var i = 0; i < aLength; i++){

			//if (a[i].tagName == "A" || a[i].tagName == "BUTTON" || (a[i].tagName == "INPUT" && (a[i].type == "submit" || a[i].type == "button" || a[i].type == "reset"))) a[i].onclick = self.focus;

			if (!a[i]) continue;

			tips_title = a[i].getAttribute("title");
			tips_alt = a[i].getAttribute("alt");
			tips_blank = a[i].getAttribute("target") && a[i].getAttribute("target") == "_blank" && tips_blank_text;
			if (tips_title || tips_blank){
				a[i].setAttribute(tips_attr_name, tips_blank ? (tips_title ? tips_title + " " + tips_blank_text : tips_blank_text) : tips_title);
				if (a[i].getAttribute(tips_attr_name)){
					a[i].removeAttribute("title");
					if (tips_alt && a[i].complete) a[i].removeAttribute("alt");
					tips.l(a[i], "mouseover", tips.s);
					tips.l(a[i], "mouseout", tips.h);
				}
			}else if (tips_alt && a[i].complete){
				a[i].setAttribute(tips_attr_name, tips_alt);
				if (a[i].getAttribute(tips_attr_name)){
					a[i].removeAttribute("alt");
					tips.l(a[i], "mouseover", tips.s);
					tips.l(a[i], "mouseout", tips.h);
				}
			}
			if (!a[i].getAttribute(tips_attr_name) && tips_blank){
				//
			}
		}
		document.onmousemove = tips.m;
		window.onscroll = tips.h;
		tips.a(-99, -99);
	},

	s: function(e){
		d = window.event ? window.event.srcElement : e.currentTarget;
		if (!d.getAttribute(tips_attr_name)) return;
		s = d.getAttribute(tips_attr_name);
		if (tips_newline_entity){
			s = s.replace(/\&/g,"&amp;");
			s = s.replace(/\</g,"&lt;");
			s = s.replace(/\>/g,"&gt;");
			s = s.replace(eval("/" + tips_newline_entity + "/g"), "<br />");
			tips.t.innerHTML = s;
		}else{
			if (tips.t.firstChild) tips.t.removeChild(tips.t.firstChild);
			tips.t.appendChild(document.createTextNode(s));
			//tips.t.innerText = s;
		}
		tips.c = setTimeout("tips.t.style.visibility = 'visible';", 100);
		tips.g = true;
	},

	h: function(e){
		tips.t.style.visibility = "hidden";
		if (!tips_newline_entity && tips.t.firstChild) tips.t.removeChild(tips.t.firstChild);
		clearTimeout(tips.c);
		tips.g = false;
		tips.a(-99, -99);
	},

	l: function(o, e, a){
		if (o.addEventListener) o.addEventListener(e, a, false);
		else if (o.attachEvent) o.attachEvent("on" + e, a);
			else return null;
	},

	a: function(x, y){
		oCanvas = document.getElementsByTagName(
		(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
		)[0];

		w_width = window.innerWidth ? window.innerWidth + window.pageXOffset : oCanvas.clientWidth + oCanvas.scrollLeft;
		w_height = window.innerHeight ? window.innerHeight + window.pageYOffset : oCanvas.clientHeight + oCanvas.scrollTop;

		tips.t.style.width = "auto";

		t_width = window.event ? tips.t.clientWidth : tips.t.offsetWidth;
		t_height = window.event ? tips.t.clientHeight : tips.t.offsetHeight;

		if ((tips_max_width) && (t_width > tips_max_width)){
			tips.t.style.width = tips_max_width + "px";
			t_width = window.event ? tips.t.clientWidth : tips.t.offsetWidth;
		}

		t_extra_width = 7;
		t_extra_height = 5;

		tips.t.style.left = x + 15 + "px";
		tips.t.style.top = y + 15 + "px";

		while (x + t_width + t_extra_width > w_width){
			--x;
			tips.t.style.left = x + "px";
			t_width = window.event ? tips.t.clientWidth : tips.t.offsetWidth;
		}

		while (y + t_height + t_extra_height > w_height){
			--y;
			tips.t.style.top = y + "px";
			t_height = window.event ? tips.t.clientHeight : tips.t.offsetHeight;
		}
	}
}




