var IE = document.all?true:false; 
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) { 
	if (IE) {
		tempX = event.clientX + document.body.scrollLeft; 
		tempY = event.clientY + document.body.scrollTop; 
	} else { 
		tempX = e.pageX; 
		tempY = e.pageY; 
	}
}

function $(id) {
	return document.getElementById(id);
}

function hint(msg) {
	if (!msg) {
		if ($('hint')) {
			$('hint').style.display = 'none';
		}
	} else if (msg != 1) {
		$('hint').style.display = '';
		$('hint').style.position = 'absolute';
		$('hint').style.left = tempX;
		$('hint').style.top = tempY;
		$('hint').innerHTML = msg;
	}
}

function getAC() {
	var res;
	if (window.XMLHttpRequest) {
		try {
			res = new XMLHttpRequest();
	   } catch(e) {
			res = false;
	   }
	} else if (window.ActiveXObject) {
	   try {
	   	res = new ActiveXObject("Microsoft.XMLHTTP");
	  	} catch(e) {
			try {
				res =  new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
		  		res = false;
			}
		}
	}
	return res;
}

function createMethodReference(object, method) {
    if (!(method instanceof Function)) {
        method = object[method];
	}
	
    return function () {
        method.apply(object, arguments);
    };
}

var attachEvent = function (o, sEventName, oCallback) {
    if (typeof o.addEventListener != 'undefined') {
      o.addEventListener(
        sEventName,
        oCallback,
        false
      );
    } else if (typeof o.attachEvent != 'undefined') {
      o.attachEvent(
        'on' + sEventName,
        oCallback
      );
    }
};

var TConnection = function (sUrl, fOnData) {
	this.onData = null;
	this.oConn = getAC();
	this.sMethod = 'GET';
	this.sUrl = '';
	
	this.oConn.onreadystatechange = createMethodReference(this, function () {
		if (this.oConn.readyState == 4) {
			if (this.onData) {
				this.onData(this.oConn);
			}
		}
	});
	
	//fast call
	if (sUrl && fOnData) {
		this.sUrl = sUrl;
		this.onData = fOnData;
		this.open();
	}
};
TConnection.prototype.onData = null;
TConnection.prototype.sMethod = 'GET';
TConnection.prototype.sUrl = '';
TConnection.prototype.bCacheProtection = true;

TConnection.prototype.open = function () {
	this.oConn.open(this.sMethod, this.sUrl + (this.bCacheProtection ? '&_t='+(new Date()).getTime() : ''));
	this.oConn.send('');
};


function select_all(id) {
	var e = getElementsByClass(id);
	for (var i = 0; i < e.length; i ++) {
		e[i].checked = true;
	}
}

function getElementsByClass(searchClass,node,tag) {
	if (document.getElementsByClassName) {
		return document.getElementsByClassName(searchClass);
	}
	
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	//var pattern = new RegExp("(^|[ 	]*)"+searchClass+"([ 	]*|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		//if ( pattern.test(els[i].className) ) {
		if (is_subclass_of(els[i], searchClass)) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function is_subclass_of(element, className) {
	return (element.className && (element.className == className || element.className.indexOf(" "+className) !== -1 || element.className.indexOf(className+" ") !== -1));
	className = new String(className);
	className = className.replace(/-/, '\\-');
	
	var pattern = new RegExp("(^|[ 	]+)"+className+"([ 	]+|$)");
	return pattern.test(element.className);
	
	return (new String(element.className)).match("/(^|[ 	]*)" + className + "([ 	]*|$)/");
}

