function initHandler (){
	handle = new handler ()
}

function handler (){
	this.hAssObj=hAssObj;
	this.hGetInfo=hGetInfo;
	this.hPrint=hPrint;
	this.hClose=hClose;
	this.hHover=hHover;
	this.hRHover=hRHover;
}

function hAssObj(id, s, u){
	var ref_onclick = function (){
		handle.hGetInfo(this.id, this.s, this.u);
	};
	var ref_onmouseover = function (){
		handle.hHover(true);
		document.getElementById(this.id).style.cursor='pointer';
	};
	
	(function(){
	var ref = document.getElementById (id);
		ref.id = id;
		ref.s = s;
		ref.u = u;
		ref.onclick = ref_onclick;
		ref.onmouseover = ref_onmouseover;
	})();
	
}

function hAssObjSC(id, s, al){
	
	var ref_onchange = function (){
		handle.hGetInfo(id, s, "&v="+document.getElementById(id).value);	
	};
	
	(function (){
		var ref = document.getElementById (id);
		ref.id = id;
		ref.s = s;
		ref.ref = ref;
		ref.onchange = ref_onchange;
		if (al == 1) { 
			handle.hGetInfo(id, s, "&v="+document.getElementById(id).value);
		};
	})();
	
}
function hGetInfo (id, s, u){
	var request_onreadystatechange = function () { self.hPrint(self); };
	(function (){
		this.request = ajaxObject();
//			alert ("includes/javascript/handler.php?i="+id+"&s="+s+u);
		this.request.open("GET", "/includes/javascript/handler.php?i="+id+"&s="+s+u, true);
		var self = this.request;
		
		this.request.onreadystatechange = request_onreadystatechange;
	
		this.request.send(null);
	})();
}

function hPrint(obj){
	if (obj.request.readyState == 4){
		if (!obj.request.responseXML) {return;}
		var result = obj.request.responseXML.getElementsByTagName("request");
		var ref = result[0].getElementsByTagName("ref")[0].firstChild.nodeValue;
		var ins = result[0].getElementsByTagName("ins");
		var pos = ins[0].getElementsByTagName("pos")[0].firstChild.nodeValue;
		var cor = ins[0].getElementsByTagName("corner")[0].firstChild.nodeValue;
		var data = result[0].getElementsByTagName("data")[0].firstChild.nodeValue;
		var js = result[0].getElementsByTagName("js")[0].firstChild.nodeValue;
		var refObj = document.getElementById(ref);
		
	
		var sp = document.createElement("span");
		sp.innerHTML = data;

		var x = getXPos(refObj);
		var y = getYPos(refObj);
		if (refObj.width) {
			w = refObj.width;
			h = refObj.height;
		} else if (refObj.style.width){
			w = refObj.style.width;
			h = refObj.height.width;

		}

		var p = 0;
		if (sp.firstChild.style){
			if (sp.firstChild.style.borderWidth){
				p += parseInt(sp.firstChild.style.borderWidth)*2;
			}
			if (sp.firstChild.style.padding){
				p += parseInt(sp.firstChild.style.padding)*2;
			} else {
				if (sp.firstChild.style.paddingLeft){
					p += parseInt(sp.firstChild.style.paddingLeft);
				}
				
				if (sp.firstChild.style.paddingRight){
					p += parseInt(sp.firstChild.style.paddingRight);
				}
			}
		}
		
		switch (cor){
			case "ul":
				break;
			case "ulo":
				x = x-parseInt(sp.firstChild.style.width)-p;
				break;
			case "ur":
				x = x-parseInt(sp.firstChild.style.width)+w;
				break;
			case "bl":
				y += parseInt(h);
				break;
			case "br":
				x = x-parseInt(sp.firstChild.style.width)+w;
				y += parseInt(h);
				break;
		}
		
			
		if (pos == "abs") { 
			sp.id = ref+"l";
			sp.style.position = "absolute"; 
			sp.style.top = y+"px";
			sp.style.left = x+"px";
			handle.hClose(sp.id);
		} else { 
//			sp.style.position = "static" 
			while (refObj.firstChild){
				refObj.removeChild(refObj.firstChild);
			}
		}
		
		if (pos == "abs"){
			if (handle.hRHover())
				document.getElementsByTagName('body')[0].appendChild(sp);
		} else {
			refObj.appendChild(sp);
		}
		window.eval (js);
		resetHelpBoxLocation();
	}
}

function hClose (id){
	if (document.getElementById(id)){
		var obj = document.getElementById(id);
		obj.parentNode.removeChild(obj);
	}
}

function hHover (status){
	this.hover = status;
}

function hRHover (status){
	return this.hover;
}

function ajaxObject (){
	if (window.ActiveXObject){
		var a = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest){
		var a = new XMLHttpRequest();
	} else {
		var a = false;
	}
	return a;	
}

function getXPos (obj){
	x = 0; 
	do {
		x += obj.offsetLeft; 
	} while (obj=obj.offsetParent); 
	return x;
}

function getYPos (obj){
	y = 0; 
	do { 
		y += obj.offsetTop; 
	} while (obj=obj.offsetParent);	
	return y;
}

function hR(iid, lid, sid, ce, u){
	
	function star_onmousemove (obj){
		var ce;
		(obj)?ce = obj: ce = event;
		var x = ce.clientX-getXPos(this);
		var nr = Math.ceil((x)/18)
		if (nr > 0 && nr < 6){
			var src = "http://www.staysopen.com/images/ratings/ustars"+nr+".gif"
			if (this.src != src)this.src = src;
		}
	}
	
	function star_onclick (obj){
		var ce;
		(obj)?ce = obj:ce = event;
		var x = ce.clientX-getXPos(this);
		var nr = Math.ceil((x)/18)
		if (nr > 0 && nr < 6){
			this.src = "http://www.staysopen.com/images/ratings/ustars"+nr+".gif"
		}
		hGetInfo ("rate", 0, "&lid="+this.id+"&r="+nr);
		this.id = "ul"+lid+"s"+nr;
	}
	
	function star_onmouseout (){
		var sp = new Array();
		sp = this.id.split('s')
		if (this.id.charAt(0) == "u"){
			this.src = "http://www.staysopen.com/images/ratings/ustars"+sp[1]+".gif"
		} else {
			this.src = "http://www.staysopen.com/images/ratings/stars"+sp[1]+".gif"
		}		
	}
	
	if (u){
		var star = document.getElementById(iid);
		star.style.cursor='pointer';
	//	alert (iid+"  "+star);
		star.onmousemove = star_onmousemove;
		star.onclick = star_onclick;
		star.onmouseout = star_onmouseout;
	}
}

function comm(id){
	handle.hHover(true);
	handle.hGetInfo ('comm', 0, '&cid='+id);
}

function kcomm(id){
	handle.hHover(false);
	handle.hClose (id+"l");
}

initHandler ();