var ua = navigator.userAgent.toLowerCase();
var isW3C = document.getElementById;
var isIE  = document.all, isIE4 = isIE && !isW3C, isIE5 = isIE && isW3C;
var isNS  = document.layers, isNS4 = isNS && !isW3C, isNS6 = !isIE && isW3C;
var isGecko = ua.indexOf('gecko') > -1;
var Opera = ua.indexOf('opera') > -1;
var Netscape = navigator.appName.indexOf('netscape') > -1;
var MSIE = ua.indexOf('msie') > 1 && !Opera && ua.indexOf('webtv') == -1;
var Mozilla = ua.indexOf('mozilla/5.') == 0 && !Opera;
var Safari = ua.indexOf('safari') > -1;
var Konqueror = ua.indexOf('konqueror') > -1;
var divTT = false;
var mouseOverTT = false, autoHideLoaded = false, autoHideDiv = false, useFloatDiv = true;
var timeToHideDiv = null;
var getMouseX = getMouseY = 0;
var onLoad = '';
function urlencode(str){ return(escape(str).replace(/\+/g,'%2B').replace(/\//g,'%2F').replace(/\?/g,'%3F').replace(/=/g,'%3D').replace(/&/g,'%26').replace(/@/g,'%40')); }
function urldecode(str){ return(unescape(str).replace(/%2B/g,'+').replace(/%2F/g,'/').replace(/%3F/g,'?').replace(/%3D/g,'=').replace(/%26/g,'&').replace(/%40/g,'@')); }
function is_empty(src){ return src && src.length == 0; }
function is_array(src){ return typeof src == 'array'; }
function is_object(src){ return typeof src == 'object'; }
function is_numeric(src){ return !isNaN(src); }
function is_string(src){ return typeof src == 'string'; }
function is_function(src){ return typeof src == 'function'; }
function is_bool(src){ return typeof src == 'boolean'; }
function is_null(src){ return src == null; }
function is_def(src){ return typeof src != 'undefined'; }
function is_set(src){ return !is_null(src) && !is_empty(src); }
function ltrim(str){ return str.replace(/^\s*/, ''); }
function rtrim(str){ return str.replace(/\s*$/, ''); }
function trim(str){ return ltrim(rtrim(str.replace(/ +/g, ' '))); }
function setAttribute(e, a){ for(var p in a) eval('e.' + p + ' = a[p];'); return(e); }
function changeCSS(c, k, v) {
	var t;
	if(document.all) t = 'rules'; else if(document.getElementById) t = 'cssRules';
	for(var s = 0; s < document.styleSheets.length; s++){
		for(var r = 0; r < document.styleSheets[s][t].length; r++)
			if(document.styleSheets[s][t][r].selectorText == c)
				document.styleSheets[s][t][r].style[k] = v;
	}
}
Array.prototype.unset = function array_unset(i){
	for(i; i < this.length - 1; i++)
		this[i] = this[i + 1];
	this.length = Math.max(this.length - 1, 0);
};
function in_array(v, a){
	for(var i = 0; i < a.length; i++)
		if(a[i] == v) return(i);
return (i < a.length) ? i : -1;
}
function $(i){ return(document.getElementById(i)); }
function gebi(i){	return(is_object(i) ? i : document.getElementById(i)); }
function gebt(t, p){
	var list = new Array(); t = t || '*'; p = p || document;
	if(is_def(p.getElementsByTagName)){
		list = p.getElementsByTagName(t);
		if(t == '*' && !list.length) list = p.all;
	}else{
		if(t == '*') list = p.all; else if(p.all && p.all.tags) list = p.all.tags(t);
	}
return(list);
}
function gebc(c, p, t, f){
	var i, r = new Array(), re = new RegExp("(^|\\s)" + c + "(\\s|$)"), e = gebt(t, p);
	for(i = 0; i < e.length; ++i){ if(re.test(e[i].className)){ r[r.length] = e[i]; if(f) f(e[i]); } }
return(r);
}
function mkNode(n){ return(document.createTextNode(n)); }
function mkElem(e, a){ var el = document.createElement(e); return(a ? setAttribute(el, a) : el); }
function findObj(n, d){
	if(is_object(n)) return(n);
	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]) && isIE) 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 = findObj(n, d.layers[i].document);7
	if(!x && isW3C) x = gebi(n);
return(x);
}
function $_(n, d){ return(findObj(n, d)); }
function toggle(){
	var i, obj, args = toggle.arguments;
	for(i = 0; i < args.length; i += 2) if((obj = gebi(args[i])) != null) obj.style.display = args[i + 1];
}
function toggleC(){
	var i, obj, args = toggleC.arguments, p = getParent(args[0], args[1]);
	for(i = 2; i < args.length; i += 3) if((obj = gebc(args[i], p, args[i + 2])) != null) obj[0].style.display = args[i + 1];
}
function chgClass(){
	var i, obj, args = chgClass.arguments;
	for(i = 0; i < args.length; i += 2) if((obj = gebi(args[i])) != null) obj.className = args[i + 1];
}
function ShowHide(){
  var i, v, obj, args = ShowHide.arguments;
  for(i = 0; i < args.length; i += 2)
		if((obj = findObj(args[i])) != null){
			v = args[i+1];
	    if(obj.style){ obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
	    obj.visibility = v;
		}
}
function ShowHideBlock(){
  var i, v, d, obj, args = ShowHideBlock.arguments;
  for(i = 0; i < args.length; i += 2)
		if((obj = findObj(args[i])) != null){
			v = args[i+1];
	    if(obj.style){
				obj = obj.style;
				d = (v == 'show') ? 'block' : 'none';
				v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v;
			}
	    obj.display = d;
	    obj.visibility = v;
		}
}
function floatDiv(id, sx, sy){
	var o = findObj(id);
	window[id + '_obj'] = o;
	if(document.layers) o.style = o;
	o.cx = o.sx = sx; o.cy = o.sy = sy;
	o.sP = function(x,y){ this.style.left = x + 'px'; this.style.top = y + 'px';};
	o.floatIt = function(speed, steps){
		var pX, pY, d = document; if(!speed) speed = 10; if(!steps) steps = 4;
		if(d.body) d = d.body; if(d.documentElement) d = d.documentElement;
		pX = (this.sx >= 0) ? 0 : Netscape ? innerWidth : d.clientWidth;
		pY = Netscape ? pageYOffset : d.scrollTop;
		if(this.sy < 0) pY += Netscape ? innerHeight : d.clientHeight;
		this.cx += (pX + this.sx - this.cx) / steps; this.cy += (pY + this.sy - this.cy) / steps;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + '_obj.floatIt(' + speed  + ',' + steps + ')', speed);
	}
return o;
}
function setMouseXY(e){ getMouseX = scrollX(e); getMouseY = scrollY(e); }
function setDivIdXY(div, id, x, y){ div.id = id; div.style.left = x + 'px'; div.style.top  = y + 'px'; }
function createDiv(id, x, y){
	var div = null; autoHideStop();
	if(!(div = findObj(id))){
		var fragment = document.createDocumentFragment();
		div = document.createElement('div');
		void(document.getElementsByTagName('body')[0].appendChild(div));
	}
	setDivIdXY(div, id, x ? x : (getMouseX + 5), y ? y : (getMouseY + 5));
return(div);
}
function writeDiv(e, txt){
	if(!is_object(e)) e = findObj(e);
	if(!e) return;
	if(!txt) txt = '';
	if(isW3C){ e.innerHTML = txt;
	}else if(isIE){ e.innerHTML = txt;
	}else if(isNS){ e.document.open(); e.document.write(txt); e.document.close(); }
}
function autoHideReset(){ timeToHideDiv = setTimeout('hideDiv()', 300); }
function autoHideStart(){ autoHideLoaded = true; clearTimeout(timeToHideDiv); }
function autoHideStop(){ autoHideLoaded = false; }
function getOffsetLeft(e){ var l = e.offsetLeft; while((e = e.offsetParent) != null) l += e.offsetLeft; return l; }
function getOffsetTop(e){ var t = e.offsetTop; while((e = e.offsetParent) != null) t += e.offsetTop; return t; }
var ttPaddingX = 0, ttPaddingY = 0;
function updateTT(e){
	setMouseXY(e);
	if(divTT && !mouseOverTT){
		if(!useFloatDiv){
			if(divTT.style.visibility == 'visible'){
				var p = Position.get('tooltip');
				if(getMouseX >= p.left && getMouseX <= p.x && getMouseY >= p.top && getMouseY <= p.y)
					autoHideStart();
				else if(autoHideLoaded)
					autoHideReset();
			}
		}else{
			var x = isIE && document.body.scrollLeft ? document.body.scrollLeft : 0;
			var y = isIE && document.body.scrollTop ? document.body.scrollTop : 0;
			setDivIdXY(divTT, divTT.id, getMouseX + x + 5 - ttPaddingX, getMouseY + y + 5 - ttPaddingY);
		}
	}
}
function showTT(txt){
	mouseOverTT = false;
	if(divTT = findObj('tooltip')){ writeDiv(divTT, txt); ShowHideBlock('tooltip', 'show'); }
	autoHideStop();
}
function hideDiv(){ ShowHideBlock('tooltip', 'hide'); }
function hideTT(){ if(divTT && !mouseOverTT) hideDiv(); }
function showTTClick(txt, close){
	showTT((!close ? "<a href='javascript:hideTTClick()'><img src='/ico/close.gif' name='ttIcoClose' border='0' alt='' align='top'></a>" : '') + txt);
	mouseOverTT = true;
}
function hideTTClick(){ mouseOverTT = false; hideTT(); }
function getDocSize(w){
	var s = {'obj':null,'width':0,'height':0}, d = w.document;
	if(d.height){
		s.obj = document.getElementById(w.name);
		s.height = d.height;
		s.width = d.width;
	}else if(document.all){
		d = (d.compatMode && d.compatMode != 'BackCompat') ? d.documentElement : d.body;
		s.obj = document.all[w.name];
		s.height = d.scrollHeight;
		s.width = d.scrollWidth;
	}
return s;
}
function setIFrameSize(w, h){ var d = getDocSize(w); if(d.obj) d.obj.style.height = d.height > h ? h : d.height; }
function maximizeIFrame(f, w, h){ var x = 0; while(!findObj(f) && ++x < 100){ } findObj(f).height = document.body.clientHeight - h; }
function scrollX(e){
	if(!e) e = window.event;
	if(e.pageX) return e.pageX;
	else if(e.clientX){
		try{ var x = document.documentElement.scrollLeft; }catch(e){ var x = document.body.scrollLeft };
	return e.clientX + x;
	}
return 0;
}
function scrollY(e){
	if(!e) e = window.event;
	if(e.pageY) return e.pageY;
	else if(e.clientY){
		try{ var y = document.documentElement.scrollTop; }catch(e){ var y = document.body.scrollTop };
	return e.clientY + y;
	}
return 0;
}
function getX(e){ if(!e) e = window.event; return(isIE ? e.x + document.body.scrollLeft : e.pageX); }
function getY(e){ if(!e) e = window.event; return(isIE ? e.y + document.body.scrollTop  : e.pageY); }
function getKey(e){ return(isIE ? event.keyCode : e.which); }
function getCode(k){ return(String.fromCharCode(k)); }
function getKeyCode(e){
	if(isNS) return(e.which);
	else if(isIE) return(event.keyCode);
	else if(isW3C) return(e.keyCode);
return(0);
}
function protectSource(){
	document.oncontextmenu = function(e){ return false; }
	if(isNS){
		window.captureEvents(Event.MOUSEDOWN);
		window.onmousedown = function(e){ if(e.target == document) return false; }
	}else
		document.onmousedown = function(e){return false;}
}
function delay(milliseconds){ var then = new Date().getTime(), now = then; while((now - then) < milliseconds) now = new Date().getTime(); }
function getParent(el, pTagName, first){
	first = first || el;
	if(el == null) return null;
	else if(el.nodeType == 1 && el.tagName.toUpperCase() == pTagName.toUpperCase()) return el;
	else return getParent(el.parentNode, pTagName, first);
}
/*
var gsc, calendarDiv;
document.onmouseup = function(e){
	if(gsc && gsc.hide)
		gsc.hide();
	if(calendarDiv)
		closeCalendar();
}
*/
function addWindowEvent(){
	var i, args = addWindowEvent.arguments;
	for(i = 0; i < args.length; i += 2){
		if(window.attachEvent) window.attachEvent('on' + args[i], args[i + 1]);
		else window.addEventListener(args[i], args[i + 1], false);
	}
}
function addDocumentEvent(){
	var i, args = addDocumentEvent.arguments;
	for(i = 0; i < args.length; i += 2){
		if(document.attachEvent) document.attachEvent('on' + args[i], args[i + 1]);
		else document.addEventListener(args[i], args[i + 1], false);
	}
}
addDocumentEvent('mousemove', updateTT);
