var tout = null;

function setClassName(obj,clsname)
{
	try
	{
		if (document.all) obj.setAttribute("className",clsname);
		else obj.setAttribute("class",clsname);
	}
	catch (e) {	}
}

function getClassName(obj)
{
	if (obj.getAttribute("class")) return obj.getAttribute("class");
	else return obj.getAttribute("className");
}

function hilite(obj,on)
{
	if (obj)
	{
		hili = obj.getElementsByTagName("DIV")[1];
		if (on) hili.style.display = "block";
		else hili.style.display = "none";
	}
}

function findPos(obj)
{
	var curleft = curtop = 0;
	
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} 
		while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

/*
function setRaidMotion(obj)
{
	obj.onmousemove = function(e) {

		var mpx = 0;
		var mpy = 0;
		var evt = e || window.event;
		
		if (evt.pageX || evt.pageY)
		{
			mpx = evt.pageX;
			mpy = evt.pageY;
		}
		else
		{
			mpx = evt.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
			mpy = evt.clientY + document.documentElement.scrollTop + document.body.scrollTop;
		}
//		document.getElementById("wowbox_frame").style.top = (mpy+10)+"px";
		document.getElementById("wowbox_frame").style.left = (mpx-220)+"px";
		
		wh = document.documentElement.clientHeight || document.body.clientHeight;
		wst = document.documentElement.scrollTop || document.body.scrollTop;
		objh = document.getElementById("wowbox_frame").clientHeight;
		objt = wh+wst-objh;
		if ((mpy+10) < objt) objt = mpy+10;
		document.getElementById("wowbox_frame").style.top = objt+"px";

		ww = document.documentElement.clientWidth || document.body.clientWidth;
		wsl = document.documentElement.scrollLeft || document.body.scrollLeft;
		objw = document.getElementById("wowbox_frame").clientWidth;
		objl = ww+wsl-objw;
		if ((mpx+5) < objl) objl = mpx-220-10;
//		document.getElementById("wowbox_frame").style.left = objl+"px";
	}
} */

var whs_to = null;
var whs_last = "";
var whs_setup = "";

function wowheadget(text,link)
{
	whtooltipoff();


	if (document.getElementById("wowheadresult"))
	{
		window.clearTimeout(whs_to);
		whres = document.getElementById("wowheadresult");

		if (document.getElementById("chkitems")) items_on = document.getElementById("chkitems").checked?1:0;
		else items_on = 1;
		if (document.getElementById("chkspells")) spells_on = document.getElementById("chkspells").checked?1:0;
		else spells_on = 0;
		if (document.getElementById("chkachievements")) achievements_on = document.getElementById("chkachievements").checked?1:0;
		else achievements_on = 0;
		if (document.getElementById("chknpcs")) npcs_on = document.getElementById("chknpcs").checked?1:0;
		else npcs_on = 0;
		setup = "&item="+items_on+"&spell="+spells_on+"&achievement="+achievements_on+"&npc="+npcs_on;
		
		if (text.length && (items_on || spells_on || achievements_on || npcs_on))
		{
			
			if (whs_last == text && whs_setup == setup)
			{
				whres.style.display = "block";
			}
			else
			{
				url = "/wowhead/whsearch.php?text="+text;
				if (link) url += "&whlink=1";
				url += setup;
				doit = function(rekk)
				{
					whs_last = text;
					whs_setup = setup;
					document.getElementById("wowheadresult").style.display = "block";
					document.getElementById("wowheadresult").innerHTML = rekk;
				}
				whs_to = window.setTimeout(function() { whsajax(url,doit); },300);
			}
		}
		else
		{
			whs_to = window.setTimeout(function() { whres.style.display = "none"; },100);
		}
	}
}

var wht_to = null;
var wht_db = new Array();
wht_db['item'] = new Array();
wht_db['spell'] = new Array();
wht_db['achievement'] = new Array();

function whtooltipon(event,type,id,icon)
{
	window.clearTimeout(wht_to);
	if (wht_db[type][id])
	{
		wht_to = window.setTimeout(function() { $WowheadPower.showTooltip(event, wht_db[type][id], icon); },200);
	}
	else
	{
		$WowheadPower.showTooltip(event, "loading...");
		url = "/wowhead/whtooltipdata.php?"+type+"="+id;
		doit = function(rekk)
		{
			$WowheadPower.showTooltip(event, rekk, icon);
			wht_db[type][id] = rekk;
		}
		wht_to = window.setTimeout(function() { whsajax(url,doit); },200);
	}
}

function whtooltipoff()
{
	window.clearTimeout(wht_to);
	$WowheadPower.hideTooltip();
}


function whsajax(url,doit)
{
	if (window.XMLHttpRequest) { var req = new XMLHttpRequest(); } 
	else if (window.ActiveXObject) { var req = new ActiveXObject("Microsoft.XMLHTTP"); }

	req.onreadystatechange = function() 
	{ 
		if (req.readyState > 0 && req.readyState < 4)
		{	
			
		}
		if (req.readyState == 4 && req.status == 200 ) 
		{	
			doit(req.responseText);
		}
	};
	req.open('GET', url); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-2");
	req.send(null);
}

function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}
