var tip_cache = new Array();

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	{
		curleft += obj.x;
	}
	return curleft;
}

function overlib(str)
{
	coolTip(str,PUID,'div1');
}

function compareitems(id1,slot)
{
	/*coolTip(loadandshow('http://lotro.mmodb.com/items/tooltips/'+id1+'.tt',id1),PUID,'div3');
	if(slot != "")
	{
		var slotitem = document.getElementById(slot);
		if(slotitem)
		{
			coolTip(loadandshow('http://lotro.mmodb.com/items/tooltips/'+slotitem.value+'.tt',slotitem.value),PUID,'div2',OFFSETX,200);
		}
	}*/
	compareitems(window.event,id1,slot);
}

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}

function compareitems(e,id1,slot)
{
	var offx2 = 0;
	var slotitem = document.getElementById(slot);
	var pos = getPosition(e);
	if(slotitem)
	{
		if((pos.x+420) > screen.width)
		{
			var offx = -210;
			offx2 = -420;
		}
		else
			var offx = 210;
		ajaxload('items',slotitem.value,'2',offx,0);
	} else if((pos.x+210) > screen.width)
		offx2 = -210;
	ajaxload('items',id1,3,offx2,0);
}

function ajaxload(type,id,dv,offx,offy)
{
   try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
   } catch (e) {
   }
	if(!tip_cache[type+"|"+id])
	{
		if(offx != 0 && offy != 0)
			coolTip("Loading",PUID,"div"+dv,OFFSETX,offx,OFFSETY,offy);
		else if(offx != 0)
			coolTip("Loading",PUID,"div"+dv,OFFSETX,offx);
		else if(offy != 0)
			coolTip("Loading",PUID,"div"+dv,OFFSETY,offy);
		else
			coolTip("Loading",PUID,"div"+dv);
		playanim(type+"|"+id,1,dv);	
		var http = new createRequestObject();
		http.onreadystatechange = function() {
			if(http.readyState == 4){
				tip_cache[type+"|"+id] = http.responseText;
				var response = http.responseText;
				testload(dv,response);			
			}
		}

		reqURL = "http://lotro.mmodb.com/ajaxtip.php?table=" + type+"&id="+id;
		http.open('get',reqURL,true);
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		http.send(null);
	} else
	{
		if(offx != 0 && offy != 0)
			coolTip(tip_cache[type+"|"+id],PUID,"div"+dv,OFFSETX,offx,OFFSETY,offy);
		else if(offx != 0)
			coolTip(tip_cache[type+"|"+id],PUID,"div"+dv,OFFSETX,offx);
		else if(offy != 0)
			coolTip(tip_cache[type+"|"+id],PUID,"div"+dv,OFFSETY,offy);
		else
			coolTip(tip_cache[type+"|"+id],PUID,"div"+dv);
		testload(dv,tip_cache[type+"|"+id]);
	}
}

function playanim(key,num,dv)
{
	if(!tip_cache[key])
	{
		var txt = "";
		if(num == 1)
			txt = ".";
		if(num == 2)
			txt = "..";
		if(num == 3)
			txt = "...";
		testload(dv,"Loading"+txt);
		setTimeout("playanim('"+key+"',"+((num+1)%4)+",'"+dv+"')",200);
	}
}

function testload(id,text)
{
	//document.getElementById("div"+id).innerHTML = '<table bgcolor="#61676c" border="0" cellpadding="1" cellspacing="0" width="200"><tbody><tr><td><table bgcolor="#171b1e" border="0" cellpadding="2" cellspacing="0" width="100%"><tbody><tr><td valign="top"><font color="#FFFFFF" face="Verdana,Arial,Helvetica" size="1">'+text+'</font></td></tr></tbody></table></td></tr></tbody></table>';
document.getElementById("div"+id).innerHTML = '<table bgcolor="#171b1e" border="1" cellpadding="2" cellspacing="0" width="200"><tbody><tr><td valign="top"><font color="#FFFFFF" face="Verdana,Arial,Helvetica" size="1">'+text+'</font></td></tr></tbody></table>';

}

function flipstatus(id)
{
	var node = document.getElementById("h"+id);
	if(node.style.display == "none")
	{
		node.style.display = "block";
	} else
	{
		node.style.display = "none";
	}
}

var included_files = new Array();

function include_once(script_filename) {
    if (!in_array(script_filename, included_files)) {
        included_files[included_files.length] = script_filename;
        include_dom(script_filename);
    }
}

function in_array(needle, haystack) {
    for (var i = 0; i < haystack.length; i++) {
        if (haystack[i] == needle) {
            return true;
        }
    }
    return false;

}

function loadandshow(path, id)
{
	var id2 = id;
	id = 'showtooltip' + id;
	include_once(path);
	if(window[id])
		return window[id]();
	else
	{
		//setTimeout("coolTip(loadandshow('"+path+"',"+id2+"))",800);
		return 'Loading';
	}
}

function showcoords(e,id,imgid)
{
	var img = document.getElementById("map");
	if(!img)
		img = document.getElementById("map"+id);
	if (!e) var e = window.event;
	// gets the actual click point
	x = e.clientX?(e.clientX):img.offsetLeft;
	y = e.clientY?(e.clientY):img.offsetTop;
	x = x - findPosX(img) + document.documentElement.scrollLeft;
	y = y - findPosY(img) + document.documentElement.scrollTop;
	var txt = document.getElementById("coorddis");
	if(!txt)
		txt = document.getElementById("coorddis"+id);
	var bounds = new Array();
	bounds[47] = '60.5W|32.2W|1.0S|22.2S';
	bounds[28] = '50.7W|45.2W|24.2S|28.3S';
	bounds[31] = '65.6W|37.3W|17.6S|38.8S';
	bounds[33] = '54.6W|47.8W|28.0S|33.0S';
	bounds[50] = '112.7W|86.5W|12.6S|32.4S';
	bounds[48] = '44.3W|20.9W|26.2S|43.8S';
	bounds[57] = '13.2W|11.5E|14.7S|33.2S';
	bounds[46] = '9.4W|0.3E|26.2S|33.5S';
	bounds[51] = '78.8W|59.8W|22.0S|36.3S';
	bounds[6] = '106.9W|98.7W|11.1S|17.2S';
	bounds[59] = '26.4W|0.9E|20.8S|41.3S';
	bounds[54] = '44.7W|15.77W|14.33N|7.03S';
	bounds[56] = '24.45W|7.93W|10.5S|21.8S';
	bounds[554] = '82.8W|52.5W|1.7S|24.4S';
	bounds[749] = '92.8W|51.9W|25.2N|5.4S';
	bounds[625] = '73.5W|65.8W|15.4S|21.2';
	bounds[856] = '114.1W|98.1W|2.1N|9.8S';
	bounds[818] = '23.9W|6.4E|34.9S|57.8S';
	bounds[749] = '92.8W|51.9W|24.7N|5.7S';
	bounds[823] = '121.9W|87.9W|3.1N|22.4S';
	bounds[197] = '65.3W|52.3W|29.2S|38.9S';
	bounds[940] = '109.1W|99.8W|9.3S|16.3S';
	bounds[955] = '116.2W|108.8W|8.5S|14.0S';
	bounds[949] = '112.2W|104.6W|12.0S|17.9S';
	bounds[909] = '102.9W|95.0W|10.6S|16.4S';
	bounds[954] = '141.5W|135.2W|74.0N|69.3N';
	bounds[845] = '117.3W|110.1W|4.9S|10.3S';
	bounds[961] = '9.1W|1.6W|48.3S|54.1S';
	bounds[1018] = '120.5W|106.8W|12.3S|22.5S';
	bounds[980] = '113.9W|100.7W|3.8S|13.7S';
	bounds[997] = '113.5W|105.1W|17.8N|11.5N';
	bounds[824] = '82.0W|61.2W|4.5S|20.2S';
	bounds[929] = '104.9W|94.1W|3.9S|12.2S';
	if(!bounds[imgid])
		return;
	var coords = bounds[imgid].split("|");
	var regex = new RegExp("([\\d|\\.]+)([W|E|S|N])");
	var matches = regex.exec(coords[0]);
	var west = matches[1];
	if(matches[2] == "W")
		west *= -1;
	matches = regex.exec(coords[1]);	
	var east = matches[1];
	if(matches[2] == "W")
		east *= -1;
	matches = regex.exec(coords[2]);	
	var north = matches[1];
	if(matches[2] == "S")
		north *= -1;
	matches = regex.exec(coords[3]);	
	var south = matches[1];
	if(matches[2] == "S")
		south *= -1;
	var distx = Math.abs(west-east);
	var disty = Math.abs(north-south);
	if((north < 0) && (south < 0))
		disty *= -1;		
	var percentx = x / 640;
	if(north > 0)
		y *= -1;
	var percenty = y / 480;
	var absdistx = (Math.round((distx *percentx)*10)/10)+(Math.round(west*10)/10);
	var absdisty = (Math.round((disty *percenty)*10)/10)+(Math.round(north*10)/10);
	//txt.innerHTML = east+", "+west;
	if(absdistx < 0)
		var xtxt = Math.round((absdistx*-1)*10)/10+" W";
	else
		var xtxt = Math.round(absdistx*10)/10+" E";
	if(absdisty < 0)
		var ytxt = Math.round((absdisty*-1)*10)/10+" S";
	else
		var ytxt = Math.round(absdisty*10)/10+" N";
	txt.innerHTML = xtxt+", "+ytxt;
}

function getcoords(x,y,imgid)
{
	var img = document.getElementById("map");
	if (!e) var e = window.event;
	// gets the actual click point
	var bounds = new Array();
	bounds[47] = '60.5W|32.2W|1.0S|22.2S';
	bounds[28] = '50.7W|45.2W|24.2S|28.3S';
	bounds[31] = '65.6W|37.3W|17.6S|38.8S';
	bounds[33] = '54.6W|47.8W|28.0S|33.0S';
	bounds[50] = '112.7W|86.5W|12.6S|32.4S';
	bounds[48] = '44.3W|20.9W|26.2S|43.8S';
	bounds[57] = '13.2W|11.5E|14.7S|33.2S';
	bounds[46] = '9.4W|0.3E|26.2S|33.5S';
	bounds[51] = '78.8W|59.8W|22.0S|36.3S';
	bounds[6] = '106.9W|98.7W|11.1S|17.2S';
	bounds[59] = '26.4W|0.9E|20.8S|41.3S';
	bounds[54] = '44.7W|15.77W|14.33N|7.03S';
	bounds[56] = '24.45W|7.93W|10.5S|21.8S';
	bounds[554] = '82.8W|52.5W|1.7S|24.4S';
	bounds[749] = '92.8W|51.9W|25.2N|5.4S';
	bounds[625] = '73.5W|65.8W|15.4S|21.2';
	bounds[856] = '114.1W|98.1W|2.1N|9.8S';
	bounds[818] = '23.9W|6.4E|34.9S|57.8S';
	bounds[749] = '92.8W|51.9W|24.7N|5.7S';
	bounds[823] = '121.9W|87.9W|3.1N|22.4S';
	bounds[197] = '65.3W|52.3W|29.2S|38.9S';
	bounds[940] = '109.1W|99.8W|9.3S|16.3S';
	bounds[955] = '116.2W|108.8W|8.5S|14.0S';
	bounds[949] = '112.2W|104.6W|12.0S|17.9S';
	bounds[909] = '102.9W|95.0W|10.6S|16.4S';
	bounds[954] = '141.5W|135.2W|74.0N|69.3N';
	bounds[845] = '117.3W|110.1W|4.9S|10.3S';
	bounds[961] = '9.1W|1.6W|48.3S|54.1S';
	bounds[1018] = '120.5W|106.8W|12.3S|22.5S';
	bounds[980] = '113.9W|100.7W|3.8S|13.7S';
	bounds[997] = '113.5W|105.1W|17.8N|11.5N';
	bounds[824] = '82.0W|61.2W|4.5S|20.2S';
	bounds[929] = '104.9W|94.1W|3.9S|12.2S';
	if(!bounds[imgid])
		return;
	var coords = bounds[imgid].split("|");
	var regex = new RegExp("([\\d|\\.]+)([W|E|S|N])");
	var matches = regex.exec(coords[0]);
	var west = matches[1];
	if(matches[2] == "W")
		west *= -1;
	matches = regex.exec(coords[1]);	
	var east = matches[1];
	if(matches[2] == "W")
		east *= -1;
	matches = regex.exec(coords[2]);	
	var north = matches[1];
	if(matches[2] == "S")
		north *= -1;
	matches = regex.exec(coords[3]);	
	var south = matches[1];
	if(matches[2] == "S")
		south *= -1;
	var distx = Math.abs(west-east);
	var disty = Math.abs(north-south);
	if((north < 0) && (south < 0))
		disty *= -1;		
	var percentx = x / 640;
	if(north > 0)
		y *= -1;
	var percenty = y / 480;
	var absdistx = (Math.round((distx *percentx)*10)/10)+(Math.round(west*10)/10);
	var absdisty = (Math.round((disty *percenty)*10)/10)+(Math.round(north*10)/10);
	//txt.innerHTML = east+", "+west;
	if(absdistx < 0)
		var xtxt = Math.round((absdistx*-1)*10)/10+" W";
	else
		var xtxt = Math.round(absdistx*10)/10+" E";
	if(absdisty < 0)
		var ytxt = Math.round((absdisty*-1)*10)/10+" S";
	else
		var ytxt = Math.round(absdisty*10)/10+" N";
	return xtxt+", "+ytxt;
}




function resize(id,entryid,zone,url,type)
{
	var img = document.getElementById('img'+id);
	var sizexe = document.getElementById('sizex');
	var sizeye = document.getElementById('sizey');
	if(sizexe.value == 501)
	{
		x= 751;
		sizexe.value=751;
	}
	else
	{
		x= 501;
		sizexe.value=501;
	}
	if(sizeye.value == 334)
	{
		y = 501;
		sizeye.value=501;
	}
	else
	{
		y = 334;
		sizeye.value=334;
	}
	img.src = url + "zonemap.php?"+type+"="+entryid+"&zone="+zone+"&sizex="+x+"&sizey="+y;
}

function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
}
function test()
{
	var w = document.myform.imagecount.selectedIndex;
	var chosen = document.myform.imagecount.options[w].text;
	var i;
	for(i = 0; i <= 10; i++)
	{
		var insert = document.getElementById('f'+(i-1));
		if (insert)
		{
			if (chosen < i)
			{
				insert.style.display = "none";
			} else
			{
				insert.style.display = "block";
			}
		}
	}
}
function clickapproveall(val)
{
	var cnt;
	for(cnt = 0; cnt < document.myform.length;cnt++)
	{
		var el = document.getElementById("approves"+cnt);
		if (el.type == 'checkbox')
		{
			el.checked = val;	
		}
		var el = document.getElementById("denys"+cnt);
		if (el.type == 'checkbox')
		{
			if (val != false)
			{
				el.checked = !val;	
			}
		}		
	}
}
function clickdenyall(val)
{
	var cnt;
	for(cnt = 0; cnt < document.myform.length;cnt++)
	{
		var el = document.getElementById("denys"+cnt);
		if (el.type == 'checkbox')
		{
			el.checked = val;	
		}
		var el = document.getElementById("approves"+cnt);
		if (el.type == 'checkbox')
		{
			if (val != false)
			{
				el.checked = !val;	
			}
		}		
	}
}
function addclick(map,e)
{
	if (!e) var e = window.event;
// gets the actual click point
xPosition = e.clientX?(e.clientX):document.getElementById("map"+map).offsetLeft;
yPosition = e.clientY?(e.clientY):document.getElementById("map"+map).offsetTop;
xPosition = xPosition - findPosX(document.getElementById("map"+map)) + document.documentElement.scrollLeft;
yPosition = yPosition - findPosY(document.getElementById("map"+map)) + document.documentElement.scrollTop;
//xPosition = xPosition - (document.body.scrollLeft * 2);
//yPosition = yPosition - (document.body.scrollTop * 2);
var cl = document.getElementById("click"+map);
var lvl = prompt("Level?","");
//set the hidden click input for that map
cl.value = cl.value + xPosition + "," + yPosition + ":" + lvl + "|";
document.myform.submit();
}
function setReply(id, tit)
{
	var pr = document.getElementById("parent");
	pr.value = id;
	var title = document.getElementById("title");
	title.value = "Re:" + tit;
}

function hidenodes()
{
	var type = document.getElementById("ntype").value;
	var job = document.getElementById("jtype").value;
	var mtype = document.getElementById("mtype").value;
	var cl = document.getElementById("click");
	var data = document.getElementById("data").value;
	var ename = document.getElementById("mlist").value;
	var dts = data.split("|");
	var click = cl.value;
	var clicks = click.split(";");
	var icsarr = document.getElementById("icons").value.split("|");
	var show = 0;
	for(var n = 0;n < clicks.length;n++)
	{
		if(clicks[n] == "")
			continue;
		var names = clicks[n].split("{");
		var name = names[1];
		var pos = names[0].split("|");				
		var tp = names[1].split("[");
		var cnt = 0;
		if(type != "")
		{
			while(document.getElementById("pop"+n+"s"+cnt))
			{
				var elem = document.getElementById("pop"+n+"s"+cnt);
				if(icsarr[n] != type)
				{
					show = 1;
					elem.style.display = "none";
				} else
				{
					elem.style.display = "block";
				}
				cnt++;
			}
			if(show > 0)
				continue;
		}
		cnt = 0;
		if(job != "")
		{
			while(document.getElementById("pop"+n+"s"+cnt))
			{
				var elem = document.getElementById("pop"+n+"s"+cnt);
				var txt = new String(dts[n]);
				
				if(txt == "")
				{
					elem.style.display = "none";
					cnt++;
					show = 1;
					continue;
				}
				if(txt.indexOf(job) != -1)
				{
					elem.style.display = "block";
				} else
				{
					show = 1;
					elem.style.display = "none";
				}
				cnt++;
			}
			if(show > 0)
				continue;
		
		}
		cnt = 0;
		if(mtype != "")
		{
			while(document.getElementById("pop"+n+"s"+cnt))
			{
				var elem = document.getElementById("pop"+n+"s"+cnt);
				var txt = new String(dts[n]);
				
				if((txt == "") && (mtype != ""))
				{
					elem.style.display = "none";
					cnt++;
					continue;
				}
				if(txt.indexOf(mtype) != -1)
				{
					elem.style.display = "block";
				} else
				{
					elem.style.display = "none";
				}
				cnt++;
			}
		}
		cnt = 0;
		if(ename != "")
		{
			while(document.getElementById("pop"+n+"s"+cnt))
			{
				var elem = document.getElementById("pop"+n+"s"+cnt);
				if(elem.id != ename)
					elem.style.display = "none";
				else
					elem.style.display = "block";
				cnt++;
			}
		}
		if((type == "") && (mtype == "") && (job == "") && (ename == ""))
		{
			cnt = 0;
			var elem = document.getElementById("pop"+n+"s"+cnt);
			while(elem != null)
			{
				elem.style.display = "block";
				cnt++;
				elem = document.getElementById("pop"+n+"s"+cnt);
			}
		}
	}	

}

function hidenodesnew(mapid)
{
	var type = document.getElementById("ntype"+mapid).value;
	var job = document.getElementById("jtype"+mapid).value;
	var mtype = document.getElementById("mtype"+mapid).value;
	var cl = document.getElementById("click"+mapid);
	var data = document.getElementById("data"+mapid).value;
	var dts = data.split("|");
	var click = cl.value;
	var clicks = click.split(";");
	var show = 0;
	for(var n = 0;n < clicks.length;n++)
	{
		if(clicks[n] == "")
			continue;
		var names = clicks[n].split("{");
		var name = names[1];
		var pos = names[0].split("|");				
		var tp = names[1].split("[");
		var cnt = 0;
		if(type != "")
		{
			while(document.getElementById("pop"+n+"s"+cnt+"m"+mapid))
			{
				var elem = document.getElementById("pop"+n+"s"+cnt+"m"+mapid);
				if(tp[1] != type)
				{
					show = 1;
					elem.style.display = "none";
				} else
				{
					elem.style.display = "block";
				}
				cnt++;
			}
			if(show > 0)
				continue;
		}
		cnt = 0;
		if(job != "")
		{
			while(document.getElementById("pop"+n+"s"+cnt+"m"+mapid))
			{
				var elem = document.getElementById("pop"+n+"s"+cnt+"m"+mapid);
				var txt = new String(dts[n]);
				
				if(txt == "")
				{
					elem.style.display = "none";
					cnt++;
					show = 1;
					continue;
				}
				if(txt.indexOf(job) != -1)
				{
					elem.style.display = "block";
				} else
				{
					show = 1;
					elem.style.display = "none";
				}
				cnt++;
			}
			if(show > 0)
				continue;
		
		}
		cnt = 0;
		if(mtype != "")
		{
			while(document.getElementById("pop"+n+"s"+cnt+"m"+mapid))
			{
				var elem = document.getElementById("pop"+n+"s"+cnt+"m"+mapid);
				var txt = new String(dts[n]);
				
				if((txt == "") && (mtype != ""))
				{
					elem.style.display = "none";
					cnt++;
					continue;
				}
				if(txt.indexOf(mtype) != -1)
				{
					elem.style.display = "block";
				} else
				{
					elem.style.display = "none";
				}
				cnt++;
			}
		}
		if((type == "") && (mtype == "") && (job == ""))
		{
			cnt = 0;
			var elem = document.getElementById("pop"+n+"s"+cnt+"m"+mapid);
			while(elem != null)
			{
				elem.style.display = "block";
				cnt++;
				elem = document.getElementById("pop"+n+"s"+cnt+"m"+mapid);
			}
		}
	}	

}

function detectnew(e, mapid,mpid)
{
	if (!e) var e = window.event;
	showcoords(e,mapid,mpid);
// gets the actual click point
x = e.clientX?(e.clientX):document.getElementById("map"+mapid).offsetLeft;
y = e.clientY?(e.clientY):document.getElementById("map"+mapid).offsetTop;
x = x - findPosX(document.getElementById("map"+mapid)) + document.documentElement.scrollLeft;
y = y - findPosY(document.getElementById("map"+mapid)) + document.documentElement.scrollTop;
var cl = document.getElementById("click"+mapid);
var click = cl.value;
var clicks = click.split(";");
var data = document.getElementById("data"+mapid).value;
var names2 = document.getElementById("names"+mapid).value.split("|");
var dts = data.split("|");
var txts = new Array();
txts[1] = "Mob";
txts[2] = "Object";
txts[3] = "NPC";
txts[4] = "Quest NPC";
for (var n = 0; n < clicks.length;n++)
{
	var names = clicks[n].split("{");
	var name = names[1];
	var pos = names[0].split("|");
	for(var m = 0; m < pos.length; m++)
	{
		var lvls = pos[m].split(":");
		var ps = lvls[0].split(",");
		if (names[1])
		{
			var tp = names[1].split("[");
		}
		var obj = document.getElementById("pop"+n+"s"+m+"m"+mapid);
		if ((ps[0] > (x - 10)) && (ps[0] < (x + 10)) && (ps[1] > (y - 10)) && (ps[1] < (y + 10)))
		{
			if(obj.style.display != "none")
			{
				obj.style.backgroundColor = '#FF0000';
				coolTip(dts[n], CAPTION,(names2[n] + '(' + txts[tp[1]] + ')'));
				return
			}
		} else
		{
			if(obj)
				obj.style.backgroundColor = '';
			//nd();
		}
	}
}
}

function buildnodesnew(mapid,mpid)
{
var cl = document.getElementById("click"+mapid);
var click = cl.value;
var clicks = click.split(";");
var data = document.getElementById("data"+mapid).value;
var ids = document.getElementById("ids"+mapid).value;
var names2 = document.getElementById("names"+mapid).value.split("|");
var idsa = ids.split("|");
var dts = data.split("|");
var icsarr = document.getElementById("icons"+mapid).value.split("|");
var ics = new Array();
ics[1] = 'barrel.gif';
ics[2] = 'chest.gif'
ics[3] = 'dragon.gif';
ics[4] = 'monster.gif';
ics[5] = 'node.gif';
ics[6] = 'quest.gif';
ics[7] = 'shrine.gif';
ics[8] = 'trap.gif';
ics[9] = 'human.gif';
ics[10] = 'ring.gif';
ics[11] = 'eye.gif';

var scale = '16x16';
if (clicks.length > 10) { scale = '12x12'; }
if (clicks.length > 20) { scale = '12x12'; }
if (clicks.length > 30) { scale = '10x10'; }

//new icons
ics[1] = 'icon-new/'+scale+'/ico-o.gif';
ics[2] = 'icon-new/'+scale+'/ico-c.gif';
ics[3] = 'icon-new/'+scale+'/ico-b.gif';
ics[4] = 'icon-new/'+scale+'/ico-m.gif';
ics[5] = 'icon-new/'+scale+'/ico-o.gif';
ics[6] = 'icon-new/'+scale+'/ico-q.gif';
ics[9] = 'icon-new/'+scale+'/ico-n.gif';
ics[10] = 'icon-new/'+scale+'/ico-q.gif';

var txt = '';
for (var n = 0; n < clicks.length;n++)
{
	var names = clicks[n].split("{");
	var name = names[1];
	var pos = names[0].split("|");
	for(var m = 0; m < pos.length; m++)
	{
		var lvls = pos[m].split(":");
		var ps = lvls[0].split(",");
		if (names[1])
		{
			var tp = names[1].split("[");
		}
		if((ps[0] == 'undefined') || (ps[1] == 'undefined') || (ps[0] == 0) || ( ps[1] == 0) || (ps[0] < 0) || (ps[1] < 0))
		{

		} else
		{
			var tx = (parseInt(ps[0]))-8;
			var ty = (parseInt(ps[1]))-8;			
			txt += '<img id="pop'+n+'s'+m+'m'+mapid+'" src="http://www.mmodb.com/DB/images/'+ics[icsarr[n]]+'" style="position:absolute;left: '+tx+'px;top: '+ty+'px;cursor: pointer;" onmouseover="detectnew(event,'+mapid+','+mpid+');" onmouseout="fixstyle(this);" onclick="linkclicknew(event,'+mapid+');">';
			//addnode('http://www.mmodb.com/DB/'+ics[icsarr[n]],tx,ty);
		}
	}
}
document.write(txt);
}
function linkclicknew(e, mapid)
{
	if (!e) var e = window.event;
// gets the actual click point
x = e.clientX?(e.clientX):document.getElementById("map"+mapid).offsetLeft;
y = e.clientY?(e.clientY):document.getElementById("map"+mapid).offsetTop;
x = x - findPosX(document.getElementById("map"+mapid)) + document.documentElement.scrollLeft;
y = y - findPosY(document.getElementById("map"+mapid)) + document.documentElement.scrollTop;
var cl = document.getElementById("click"+mapid);
var click = cl.value;
var clicks = click.split(";");
var data = document.getElementById("data"+mapid).value;
var ids = document.getElementById("ids"+mapid).value;
var names2 = document.getElementById("names"+mapid).value.split("|");
var idsa = ids.split("|");
var dts = data.split("|");
for (var n = 0; n < clicks.length;n++)
{
	var names = clicks[n].split("{");
	var name = names[1];
	var pos = names[0].split("|");
	for(var m = 0; m < pos.length; m++)
	{
		var lvls = pos[m].split(":");
		var ps = lvls[0].split(",");
		if (names[1])
		{
			var tp = names[1].split("[");
		}		
		if ((ps[0] > (x - 8)) && (ps[0] < (x + 8)) && (ps[1] > (y - 8)) && (ps[1] < (y + 8)) &&(document.getElementById("pop"+n+"s0m"+mapid).style.display != "none"))
		{
			var link = "http://lotro.mmodb.com";
			if (tp[1] != "2")
				link += "/bestiary/";
			else
				link += "/objects/";		
			var ts = names2[n].replace(/\s/g,"-");
			link += ts.toLowerCase() + "-" + idsa[n] + ".php";			
			top.location.href = link;
			return;
		}
	}
}
}




function detect(e,img,mpid)
{
	if (!e) var e = window.event;
	showcoords(e,0,mpid);
// gets the actual click point
x = e.clientX?(e.clientX):document.getElementById("map").offsetLeft;
y = e.clientY?(e.clientY):document.getElementById("map").offsetTop;
x = x - findPosX(document.getElementById("map")) + document.documentElement.scrollLeft;
y = y - findPosY(document.getElementById("map")) + document.documentElement.scrollTop;
var cl = document.getElementById("click");
var click = cl.value;
var clicks = click.split(";");
var data = document.getElementById("data").value;
var names2 = document.getElementById("names").value.split("|");
var dts = data.split("|");
var txts = new Array();
txts[1] = "Mob";
txts[2] = "Object";
txts[3] = "NPC";
txts[4] = "Quest NPC";
var regex = new RegExp("pop(\\w+)s(\\w+)");
var matches = regex.exec(img.id);
var currentclick = clicks[matches[1]];
var names = currentclick.split("{");
var name = names[1];
var pos = names[0].split("|");
var lvls = pos[matches[2]].split(":");
var ps = lvls[0].split(",");
var tp = names[1].split("[");
var obj = document.getElementById("pop"+matches[1]+"s"+matches[2]);
if ((ps[0] > (x - 10)) && (ps[0] < (x + 10)) && (ps[1] > (y - 10)) && (ps[1] < (y + 10)))
{
	if(obj.style.display != "none")
	{
		if(obj)
			obj.style.backgroundColor = '#FF0000';
		 coolTip(dts[matches[1]], CAPTION,(names2[matches[1]] + '(' + txts[tp[1]] + ')'));
		return;
	}

} else
{
	if(obj)
		obj.style.backgroundColor = '';
	//nd();	
}
}

function addnode(script_filename,x,y)
 {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('img');
    js.setAttribute('style', 'position:absolute;left: '+x+'px;top: '+y+'px;');
    js.setAttribute('onmousemove', 'detect(event);');
    js.setAttribute('onmouseout', 'nd();');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

function fixstyle(obj)
{
	obj.style.backgroundColor = '';
	nd();
}

function moblistentry(id,name,text)
{
	this.id = id;
	this.name = name;
	this.text = text;
}

function sortByName(a, b) {
    var x = a.name.toLowerCase();
    var y = b.name.toLowerCase();
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

function buildmoblist(mpid)
{
var cl = document.getElementById("click");
var click = cl.value;
var clicks = click.split(";");
var data = document.getElementById("data").value;
var ids = document.getElementById("ids").value;
var names2 = document.getElementById("names").value.split("|");
var idsa = ids.split("|");
var dts = data.split("|");
var x = findPosX(document.getElementById("map")) - document.getElementById("map").offsetLeft;
var y = findPosY(document.getElementById("map")) - document.getElementById("map").offsetTop;
var icsarr = document.getElementById("icons").value.split("|");
var txt = '<option value=""></option>';
var moblist = new Array();
var types = new Array();
types[1] = "Object";
types[4] = "Mob";
types[5] = "Node";
types[9] = "NPC";
types[10] = "Quest NPC";
for (var n = 0; n < clicks.length;n++)
{
	var names = clicks[n].split("{");
	var name = names[1];
	var pos = names[0].split("|");
	for(var m = 0; m < pos.length; m++)
	{
		var lvls = pos[m].split(":");
		var ps = lvls[0].split(",");
		if (names[1])
		{
			var tp = names[1].split("[");
		}
		if((ps[0] == 'undefined') || (ps[1] == 'undefined') || (ps[0] == 0) || ( ps[1] == 0) || (ps[0] < 0) || (ps[1] < 0))
		{

		} else
		{
			var tx = (parseInt(ps[0]))-8;
			var ty = (parseInt(ps[1]))-8;
			moblist[moblist.length++] = new moblistentry("pop"+n+"s"+m,names2[n],names2[n]+"("+types[icsarr[n]]+")("+getcoords(tx,ty,mpid)+")");
			m = pos.length;			
		}
	}
}
moblist.sort(sortByName);
for(var i = 0;i < moblist.length;i++)
{
	txt += '<option value="'+moblist[i].id+'">'+moblist[i].text+'</option>';
}
document.write(txt);
}

function showtarget(event,id)
{
	//alert(document.getElementById('mlist').value);
	detect(event,document.getElementById(document.getElementById('mlist').value),id);
}

function highlightdot()
{
	//var elid = document.getElementById("mlist").value;
	//var target = document.getElementById(elid);
	//var highlight = document.getElementById("highlight");
	//highlight.style.left = target.style.left;
	//highlight.style.top = target.style.top;
	//highlight.style.display = "block";
}

function buildnodes(mpid)
{
var cl = document.getElementById("click");
var click = cl.value;
var clicks = click.split(";");
var data = document.getElementById("data").value;
var ids = document.getElementById("ids").value;
var names2 = document.getElementById("names").value.split("|");
var idsa = ids.split("|");
var dts = data.split("|");
var x = findPosX(document.getElementById("map")) - document.getElementById("map").offsetLeft;
var y = findPosY(document.getElementById("map")) - document.getElementById("map").offsetTop;
var icsarr = document.getElementById("icons").value.split("|");
var ics = new Array();
ics[1] = 'barrel.gif';
ics[2] = 'chest.gif'
ics[3] = 'dragon.gif';
ics[4] = 'monster.gif';
ics[5] = 'node.gif';
ics[6] = 'quest.gif';
ics[7] = 'shrine.gif';
ics[8] = 'trap.gif';
ics[9] = 'human.gif';
ics[10] = 'ring.gif';
ics[11] = 'eye.gif';

var scale = '16x16';
if (clicks.length > 10) { scale = '12x12'; }
if (clicks.length > 20) { scale = '12x12'; }
if (clicks.length > 30) { scale = '10x10'; }

//new icons
ics[1] = 'icon-new/'+scale+'/ico-o.gif';
ics[2] = 'icon-new/'+scale+'/ico-c.gif';
ics[3] = 'icon-new/'+scale+'/ico-b.gif';
ics[4] = 'icon-new/'+scale+'/ico-m.gif';
ics[5] = 'icon-new/'+scale+'/ico-o.gif';
ics[6] = 'icon-new/'+scale+'/ico-q.gif';
ics[9] = 'icon-new/'+scale+'/ico-n.gif';
ics[10] = 'icon-new/'+scale+'/ico-q.gif';

var txt = '';
for (var n = 0; n < clicks.length;n++)
{
	var names = clicks[n].split("{");
	var name = names[1];
	var pos = names[0].split("|");
	for(var m = 0; m < pos.length; m++)
	{
		var lvls = pos[m].split(":");
		var ps = lvls[0].split(",");
		if (names[1])
		{
			var tp = names[1].split("[");
		}
		if((ps[0] == 'undefined') || (ps[1] == 'undefined') || (ps[0] == 0) || ( ps[1] == 0) || (ps[0] < 0) || (ps[1] < 0))
		{

		} else
		{
			var tx = (parseInt(ps[0]))-8;
			var ty = (parseInt(ps[1]))-8;			
			txt += '<img id="pop'+n+'s'+m+'" src="http://www.mmodb.com/DB/images/'+ics[icsarr[n]]+'" name="pop'+n+'" style="position:absolute;left: '+tx+'px;top: '+ty+'px;cursor: pointer;_cursor: hand;" onmouseover="detect(event,this,\''+mpid+'\');" onmouseout="fixstyle(this);" onclick="linkclick(event,this);">';
			//addnode('http://www.mmodb.com/DB/'+ics[icsarr[n]],tx,ty);
		}
	}
}
document.write(txt);
}
function linkclick(e,img)
{
	if (!e) var e = window.event;
// gets the actual click point
x = e.clientX?(e.clientX):document.getElementById("map").offsetLeft;
y = e.clientY?(e.clientY):document.getElementById("map").offsetTop;
x = x - findPosX(document.getElementById("map")) + document.documentElement.scrollLeft;
y = y - findPosY(document.getElementById("map")) + document.documentElement.scrollTop;
var cl = document.getElementById("click");
var click = cl.value;
var clicks = click.split(";");
var data = document.getElementById("data").value;
var ids = document.getElementById("ids").value;
var names2 = document.getElementById("names").value.split("|");
var idsa = ids.split("|");
var dts = data.split("|");
var regex = new RegExp("pop(\\w+)s(\\w+)");
var matches = regex.exec(img.id);
var currentclick = clicks[matches[1]];
var names = currentclick.split("{");
var name = names[1];
var pos = names[0].split("|");
var lvls = pos[matches[2]].split(":");
var ps = lvls[0].split(",");
var tp = names[1].split("[");
var obj = document.getElementById("pop"+matches[1]+"s"+matches[2]);
if ((ps[0] > (x - 8)) && (ps[0] < (x + 8)) && (ps[1] > (y - 8)) && (ps[1] < (y + 8)))
{
	if(obj.style.display != "none")
	{
		var link = "http://lotro.mmodb.com";
		if (tp[1] != "2")
			link += "/bestiary/";
		else
			link += "/objects/";			
		var ts = names2[matches[1]].replace(/\s/g,"-");
		ts = ts.replace(/'/,"");
		link += ts.toLowerCase() + "-" + idsa[matches[1]] + ".php";			
		top.location.href = link;
		return;
	}
}
}
function setmouse(e)
{
	document.getElementById("map").onmousemove = detect(e);
	return;
}
function clearmap(map)
{
//clear the hidden click input for that map
var cl = document.getElementById("click"+map);
cl.value = "";
document.myform.submit();
}
function setpage(page)
{
	var pg = document.getElementById("page");
	pg.value = page;
	document.myform.submit();
	return;	 
}

function setcontent(table,id)
{
	document.myform.table_name.value = table;
	document.myform.id.value = id;
	document.myform.submit();
	return;	
}

function setlistpage(letter,page)
{
	document.myform.action = letter+page+".php";
	document.myform.submit();
	return;	
}
function setsearchpage(page)
{
	document.myform.page.value = page;
	document.myform.submit();
	return;	
}
function addsort(type,column)
{
	var up = document.getElementById("ASC");
	var down = document.getElementById("DESC");
	document.getElementById("first").value = column;
	var rep = new RegExp(column);
	if(type == "ASC")
	{
		up.value += column + "|";
		down.value = down.value.replace(rep,"");
	} else
	{
		down.value += column + "|";
		up.value = up.value.replace(rep,"");
	}
	document.myform.submit();
	return;	
}
function addsort2(type,column)
{
	var up = document.getElementById("ASC");
	var down = document.getElementById("DESC");
	if(type == "ASC")
	{
	    down.value = "";
        up.value = column;
	} else
	{
        down.value = column;
        up.value = "";
	}
	document.myform.submit();
	return;	
}