/*******  *******/
/******* Variablen initialisieren *******/
var mouse_x, mouse_y, last_mouse_x, last_mouse_y;
var versatz_x, versatz_y;
var drag = false;
var themap, thex, they, thet, thearea;
var maplink;
var page;

var oldhref = "";

isie = false;

var pagerequests, locrequests, areanametimeout, shopsrequest, shoptimeout, shoptimeout2, gatectimeout, gatectimeout2, treasuretimeout, treasuretimeout2, trapstimeout, trapstimeout2;

var totalwidth, totalheight;

var menutimeout;
var menusubtimeout;
var mtimeoutnr = 0;

var mapimage = new Image();
var mapwidth = 0, mapheight = 0;


var display = "treasures";

/******* initialisieren *******/
function init()
{
	mouse_init(); // moaus koordinaten abfrage
	window_init();
	url_init();
	window.setInterval("scan()",1000);
	browser_init();
	checkgooglesense();
}

function browser_init()
{
	if(navigator.userAgent.indexOf("compatible") != -1 && navigator.userAgent.indexOf("MSIE 6") != -1)
	{
		isie = true;
	}
}

/******* SCANS FOR BACK BUTTON *******/
function scan()
{
	/*var hash = document.location.hash.replace(";","/");;
	if(hash != "#" && hash != "" && oldhref != hash)
	{
		oldhref = hash;
		if(hash.search(/map/) != -1)
		{
			partss = hash.substr(5).split("/");
			loadmap(partss[0],partss[1],partss[2],partss[3],partss[4]);
		}else{
			var parts = hash.substr(1).split("/");
			if(parts.length > 1)
			{
				loadsubcontent(parts[0],parts[1]);
			}else{
				//loadcontent(hash.substr(1));
			}
		}
	}*/
}

/******* window init *******/
function window_init()
{
	totalwidth = (document.layers || (document.getElementById && !document.all)) ? window.innerWidth : document.body.clientWidth;
	totalheight = (document.layers || (document.getElementById && !document.all)) ? window.innerHeight : document.body.clientHeight;
}

/******* Maus Koordinaten *******/
function mouse_init()
{
	if(document.layers) // IE
	{
		window.captureEvents(Event.MOUSEMOVE);
		window.onmousemove = coors;
	} else { // alle anderen
		document.onmousemove = coors;
	}
}

function url_init()
{
	var url = document.location.href;
	url = url.replace(";","/");
	var tmp = url.search(/\#./);
	if(tmp != -1)
	{
		oldhref = document.location.hash;
		tmp = url.substr(tmp+1);
		tmp = tmp.replace("=",":");
		if(tmp.indexOf("map:") == 0)
		{
			tmp = tmp.substr(4);
			parts = tmp.split("/");
			loadmap(parts[0],parts[1],parts[2],parts[3],parts[4]);
		}else{
			if(tmp.indexOf("/") != -1)
			{
				var parts = tmp.split("/");
				loadcontent(parts[0]);
				loadnext(parts[0],parts[1]);
			}else{
				loadcontent(tmp);
			}
			loadmap('worldmap','','','','');
		}
	}else{
		loadmap('worldmap','','','','');
	}
}

function selection_update(map)
{
	var mc = document.getElementById('mapchanger_1');
	if(mc)
	{
		for(i = 0;i<mc.options.length;i++)
		{
			if(mc.options[i].value == map)
			{
				mc.selectedIndex = i;
			}
		}
	}
	
	mc = document.getElementById('mapchanger_2');
	if(mc)
	{
		for(i = 0;i<mc.options.length;i++)
		{
			if(mc.options[i].value == map)
			{
				mc.selectedIndex = i;
			}
		}
	}
}

function loadnext(site, parameter)
{
	if(document.getElementById("subcontent"))
	{
		loadsubcontent(site, parameter);
	}else{
		window.setTimeout("loadnext('" + site + "','" + parameter + "')", 10);
	}
}

/******* Koordinaten benutzung: Map verschieben, etc *******/
function coors(e) 
{
	mouse_x = (document.layers || (document.getElementById && !document.all)) ? e.pageX : document.body.scrollLeft + event.clientX;
	mouse_y = (document.layers || (document.getElementById && !document.all)) ? e.pageY : document.body.scrollTop + event.clientY;
	
	//document.getElementById('debug').innerHTML = mouse_x + ":" + mouse_y;
	
	if(drag == true)
	{
		versatz_x = mouse_x - last_mouse_x;
		versatz_y = mouse_y - last_mouse_y;
		
		document.getElementById('mapdiv').scrollLeft -= versatz_x;
		document.getElementById('mapdiv').scrollTop -= versatz_y;
	}
	if(document.getElementById('ownmarker').style.display == 'block')
	{
		document.getElementById('ownmarker').style.left = (mouse_x-14) + "px";
		document.getElementById('ownmarker').style.top = (mouse_y-14) + "px";
	}
	
	last_mouse_x = mouse_x;
	last_mouse_y = mouse_y;
}


/******* Map laden *******/
var img;
function loadmap(map,x,y,t,area)
{
	document.getElementById('mapdiv').style.visibility = "hidden";
	
	selection_update(map);
	
	themap = map; thex = x, they = y, thet = t, thearea = area;
	maplink = "#map:" + map + "/" + x + "/" + y + "/" + t + "/" + area;
	
	document.getElementById('mapdiv').style.cursor = "wait";
	
	getlocs(map);
	document.getElementById('mapimg').src = null;

	img = null;
	img = new Image();
	img.src = 'http://www.ff12maps.com/maps/mapcreate.php?map=' + map + '&x=' + x + '&y=' + y + "&t=" + t + "&area=" + area + "&display=" + display;
	checkloaded(x,y);
}

function checkloaded(x,y)
{
	if(img.complete)
	{
		document.getElementById('mapimg').src = img.src;
		window.setTimeout("centermap('" + x + "','" + y + "');",300);
	}else{
		window.setTimeout("checkloaded('" + x + "','" + y + "');",10);
	}
}

function centermap(x,y)
{	
	totalwidth = (document.layers || (document.getElementById && !document.all)) ? window.innerWidth : document.body.clientWidth;
	totalheight = (document.layers || (document.getElementById && !document.all)) ? window.innerHeight : document.body.clientHeight;
	
	var anzeigewidth = totalwidth - parseInt(document.getElementById('tab').style.width);
	var anzeigeheight = totalheight - 40;
	if(x == "undefined" || x == "")
	{
		document.getElementById('mapdiv').scrollLeft = (((img.width+400)-anzeigewidth)/2);
		document.getElementById('mapdiv').scrollTop = (((img.height+400)-anzeigeheight)/2);
	}else{
		document.getElementById('mapdiv').scrollLeft = (x-(anzeigewidth/2)) + 200;
		document.getElementById('mapdiv').scrollTop = (y-(anzeigeheight/2)) + 200;
	}
	
	document.getElementById('mapdiv').style.cursor = "auto";
	document.getElementById('mapdiv').style.visibility = "visible";
	
	if(themap != "worldmap")
	{
		window.setTimeout("document.location.href = maplink",10);
		oldhref = maplink;
		if(isie)
		{
			page = maplink.substr(1);
			backgroundframe.location.href = "switch.php?page=" + page;
		}
	}
}


/******* Map draggen *******/
function startdrag()
{
	drag=true;
	document.getElementById('mapimg').style.cursor = "move";
}

function stopdrag()
{
	drag=false;
	document.getElementById('mapimg').style.cursor = "auto";
}


/******* Tab ein/ausblenden *******/
function toggletabs()
{
	
	if(document.getElementById('tab').style.width != "0px") // Tabs einfahren, map auf 100% verbreitern
	{
		document.getElementById('tab').style.width = "0px";
		document.getElementById('showhide').style.display = "block";
		document.getElementById('mapdiv').style.right = "0px";
		document.getElementById('mapdiv').style.width = "100%";
		
		document.getElementById('mapdiv').scrollLeft = document.getElementById('mapdiv').scrollLeft-1; // FF hack damit die map aktualisiert wird
	}else{
		totalwidth = (document.layers || (document.getElementById && !document.all)) ? window.innerWidth : document.body.clientWidth;
		
		document.getElementById('tab').style.width = "400px";
		document.getElementById('showhide').style.display = "none";
		document.getElementById('mapdiv').style.right = "400px";
		document.getElementById('mapdiv').style.width = (totalwidth - 400 + 'px');
	}
}


/******* Tabcontent anzeigen *******/
function showtabcontent(tab)
{	
	document.getElementById('tabreiter_legende').style.backgroundColor = "#E6EDF4";
	document.getElementById('tabreiter_legende').style.borderBottomColor = "#5c6f8a";
	document.getElementById('tabreiter_content').style.backgroundColor = "#E6EDF4";
	document.getElementById('tabreiter_content').style.borderBottomColor = "#5c6f8a";
	document.getElementById('tab_legende').style.display = "none";
	document.getElementById('tab_content').style.display = "none";
	
	document.getElementById('tabreiter_' + tab).style.backgroundColor = "#F8FAFC";
	document.getElementById('tabreiter_' + tab).style.borderBottomColor = "#F8FAFC";	
	document.getElementById('tab_' + tab).style.display = "block";
}


/******* Content Laden *******/
function loadcontent(site)
{
	oldhref = "/#" + site;
	document.location.href = "/#" + site;
	if(isie)
	{
		page = site;
		backgroundframe.location.href = "switch.php?page=" + page;
	}
	
	if(document.getElementById('tab_content').style.display == "none")
	{
		showtabcontent('content');
	}	
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		pagerequests = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		pagerequests = new ActiveXObject("Microsoft.XMLHTTP");
	}
	pagerequests.onreadystatechange = rq_rfrs;
	var url = "cont/" + site + ".cont.php";
	pagerequests.open('GET', url, true); 
	pagerequests.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	pagerequests.send(null);
}

function rq_rfrs()
{
	// checken ob der request fertig ist
	if (pagerequests.readyState == 4) {
		// alles in Ordnung, Antwort wurde empfangen
			if (pagerequests.status == 200) {
				// perfekt!
				document.getElementById("tab_content").innerHTML = pagerequests.responseText;
				
				document.getElementById("tab_comments").innerHTML = "&nbsp;";
			} else {
				// die Anfrage enthielt Fehler;
				document.getElementById("tab_content").innerHTML = "<div style='position:absolute; top:45%; left:0%; width:100%; text-align:center;'><img src='gfx/error.gif' alt=''><br>Loading Error.<br>Automatic retry in 5 seconds.</div>";
				window.setTimeout("loadcontent(oldhref.substr(1));", 5000);
			}
	} else {
		// noch net bereit
		document.getElementById("tab_content").innerHTML = "<div style='position:absolute; top:45%; left:0%; width:100%; text-align:center;'><img src='gfx/loader.gif' alt='Now Loading'></div>"; 
	}
}

/******* Sub Content Laden *******/
function loadsubcontent(site,parameter)
{
	if(site.indexOf("comments") == -1)
	{
		oldhref = "/#" + site + "/" + parameter;
		document.location.href = "/#" + site + "/" + parameter;
		if(isie)
		{
			page = site + "/" + parameter;
			backgroundframe.location.href = "switch.php?page=" + page;
		}
	}
	
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		pagerequests = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		pagerequests = new ActiveXObject("Microsoft.XMLHTTP");
	}
	pagerequests.onreadystatechange = new Function("fx", "subrq_rfrs('" + site + "','" + parameter + "')");
	var url = "cont/" + site + "content.cont.php?parameter=" + parameter;
	pagerequests.open('GET', url, true); 
	pagerequests.setRequestHeader("Content-Type", "text/html; charset=utf-8");
	pagerequests.send(null);
}

function subrq_rfrs(site,parameter)
{
	// checken ob der request fertig ist
	if (pagerequests.readyState == 4) {
		// alles in Ordnung, Antwort wurde empfangen
			if (pagerequests.status == 200) {
				// perfekt!				
				var tmp = pagerequests.responseText.split("~|~");
				
				document.getElementById("subcontent").innerHTML = tmp[0];
				if(tmp[1] != "")
					document.getElementById("tab_comments").innerHTML = "<div><img src='gfx/comments.gif' alt=''> <a href='#' OnClick=\"loadsubcontent('comments','" + site + "," + parameter + "'); return false;\">" + tmp[1] + " " + hintstips + "</a> | <img src='gfx/comments_add.gif' alt=''> <a href='#' OnClick=\"loadsubcontent('commentsadd','" + site + "," + parameter + "'); return false;\">" + writehintstips + ".</a></div>";
					
				if(document.getElementById("inner_sense"))
					document.getElementById("inner_sense").src = "http://www.ff12maps.com/cont/inner_sense.html";
			} else {
				// die Anfrage enthielt Fehler;
				document.getElementById("tab_content").innerHTML = "<div style='position:absolute; top:45%; left:0%; width:100%; text-align:center;'><img src='gfx/error.gif' alt=''><br>Loading Error.<br>Automatic retry in 5 seconds.</div>";
				var site = oldhref.substr(1,oldhref.indexOf("/"));
				var parameter = oldhref.substr(oldhref.indexOf("/") + 1);
				window.setTimeout("loadsubcontent(site, parameter);", 5000);
			}
	} else {
		// noch nicht bereit
		document.getElementById("subcontent").innerHTML = "<div style='position:absolute; top:45%; left:0%; width:100%; text-align:center;'><img src='gfx/loader.gif' alt='Now Loading'></div>";
	}
}


/******* Toggle Content *******/
function togglecontainer(containername)
{
	if(document.getElementById(containername).style.display == "none")
	{
		document.getElementById(containername).style.display = "inline";
		document.getElementById(containername + "_img").src = "gfx/toggle_minus.gif";
	}else{
		document.getElementById(containername).style.display = "none";
		document.getElementById(containername + "_img").src = "gfx/toggle_plus.gif";
	}
}


/******* Menu *******/
function clearmenu()
{
	document.getElementById('menusubcontent_1').style.display = "none";
	document.getElementById('menusubcontent_2').style.display = "none";
	document.getElementById('menusubcontent_3').style.display = "none";
}

function togglemenu(ebene,num,display)
{
	if(display == "block")
	{	
		if(ebene == "sub")
			clearmenu();
	
		window.clearTimeout(menutimeout);
		if(ebene == "subsub")
			window.clearTimeout(menusubtimeout);
			
		document.getElementById('menu' + ebene + 'content_' + num).style.display = "block";
	}else{
		if(ebene == "sub")
			menutimeout = window.setTimeout("document.getElementById('menu" + ebene + "content_" + num + "').style.display = 'none';",200);
		else
			menusubtimeout = window.setTimeout("document.getElementById('menu" + ebene + "content_" + num + "').style.display = 'none';",200);
	}
}


/******* LOCS *******/
function getlocs(map)
{
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		locrequests = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		locrequests = new ActiveXObject("Microsoft.XMLHTTP");
	}
	locrequests.onreadystatechange = locrq_rfrs;
	var url = "cont/getlocs.inc.php?map=" + map + "&display=" + display;
	locrequests.open('GET', url, true); 
	locrequests.setRequestHeader("Content-Type", "text/html; charset=utf-8");
	locrequests.send(null);
}

function locrq_rfrs()
{
	// checken ob der request fertig ist
	if (locrequests.readyState == 4) {
		// alles in Ordnung, Antwort wurde empfangen
			if (locrequests.status == 200) {
				// perfekt!
				var text = locrequests.responseText;
				
				document.getElementById("mainmap").innerHTML = text;
			} else {
				// die Anfrage enthielt Fehler;
				window.setTimeout("getlocs(themap);", 1000);
			}
	} else {
		// noch nicht bereit
		
	}
}


/**** areas ****/
function showareaname(text)
{
	if(document.getElementById('mapimg').style.cursor != "pointer")
		document.getElementById('mapimg').style.cursor = "crosshair";
	areanametimeout = window.setTimeout("showareaname2(\"" + text + "\");",250);
}

function showareaname2(text)
{
	var namediv = document.getElementById('areaname');
	document.getElementById('areaname_inner').innerHTML = text;
	namediv.style.display = "block";
	namediv.style.top = (mouse_y-12) + "px";
	namediv.style.left = (mouse_x+12) + "px";
}

function moveareaname()
{
	document.getElementById('areaname').style.left = (mouse_x + 12) + "px";
	document.getElementById('areaname').style.top = (mouse_y-12) + "px";
}

function hideareaname()
{
	window.clearTimeout(areanametimeout);
	document.getElementById('mapimg').style.cursor = "auto";
	document.getElementById('areaname').style.display = "none";
}


/**** GATE CRYSTAL ****/
function showgatec(actualmap)
{
	document.getElementById('mapimg').style.cursor = "help";
	gatectimeout = window.setTimeout("showgatec2(\"" + actualmap + "\");",250);
}

function showgatec2(actualmap)
{
	window.clearTimeout(gatectimeout2);
	var gatediv = document.getElementById('gatecrystal');
	gatediv.style.display = "block";
	gatediv.style.top = (mouse_y) + "px";
	gatediv.style.left = (mouse_x+12) + "px";
}

function hidegatec()
{
	window.clearTimeout(gatectimeout);
	document.getElementById('mapimg').style.cursor = "auto";
	gatectimeout2 = window.setTimeout("document.getElementById('gatecrystal').style.display = 'none';",300);
}

/**** SHOPS ****/
function showshop(name)
{		
	document.getElementById('mapimg').style.cursor = "help";
	shoptimeout = window.setTimeout("showshop2('" + name + "');",300);
}

function showshop2(name)
{
	window.clearTimeout(shoptimeout2);
	shopdiv = document.getElementById('shops');
	if(shopdiv.style.display != "block")
	{
		document.getElementById('shops_title').innerHTML = "<b>" + shop + ": " + name + "</b>";
		document.getElementById('shops_type').innerHTML = "";
		shopdiv.style.display = "block";
		if((totalwidth - mouse_x) > 550)
		{
			shopdiv.style.left = (mouse_x+12) + "px";
		}else{
			shopdiv.style.left = (mouse_x-562) + "px";
		}
		
		if((totalheight - mouse_y) > 300)
		{
			shopdiv.style.top = (mouse_y) + "px";
		}else{
			shopdiv.style.top = (mouse_y - 312) + "px";
		}
		getshops(name,'','');
	}
}

function hideshop()
{
	window.clearTimeout(shoptimeout);
	document.getElementById('mapimg').style.cursor = "auto";
	shoptimeout2 = window.setTimeout("document.getElementById('shops').style.display = 'none';",300);
}

function getshops(shopname,type,pressed)
{
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		shopsrequest = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		shopsrequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	shopsrequest.onreadystatechange = refreshshops;
	var url = "cont/getshops.inc.php?name=" + shopname + "&type=" + type + "&pressed=" + pressed;
	shopsrequest.open('GET', url, true); 
	shopsrequest.setRequestHeader("Content-Type", "text/html; charset=utf-8");
	shopsrequest.send(null);
}

function refreshshops()
{
	// checken ob der request fertig ist
	if (shopsrequest.readyState == 4) {
		// alles in Ordnung, Antwort wurde empfangen
			if (shopsrequest.status == 200) {
				// perfekt!
				var text = shopsrequest.responseText;
				var parts = text.split("<hr>");
				document.getElementById('shops_type').innerHTML	= parts[0];
				document.getElementById('shops_content').innerHTML = parts[1];
			} else {
				// die Anfrage enthielt Fehler;
				//window.setTimeout("shops(themap);", 1000);
			}
	} else {
		// noch nicht bereit
		document.getElementById('shops_content').innerHTML = "<table style='width:100%; height:100%;'><tr><td align='center' valign='middle'><img src='gfx/loader-small.gif' alt=''></td></tr></table>";
	}
}


/************** COMMENTS **************/
function checkcomments(feld)
{
	if(document.getElementById('commentsname').value == "" || document.getElementById('commentstext').value == "")
	{	
		document.getElementById('commentssubmit').disabled = true;
		document.getElementById('commentssubmit').value = insertnametext;
		document.getElementById('secnumloadim').src = 'gfx/cancel.gif';
	}else{
		if(document.getElementById('secnum').value.length == 5 && feld == 'secnum')
		{
		
			if (window.XMLHttpRequest) { // Mozilla, Safari, ...
				checkcommentsrequest = new XMLHttpRequest();
			} else if (window.ActiveXObject) { // IE
				checkcommentsrequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			checkcommentsrequest.onreadystatechange = refreshcheckcomments;
			var param = document.getElementById('t').value;
			var url = "cont/checkcomments.inc.php?param=" + param + "&eingabe=" + document.getElementById('secnum').value;
			checkcommentsrequest.open('GET', url, true);
			checkcommentsrequest.setRequestHeader("Content-Type", "text/html; charset=utf-8");
			checkcommentsrequest.send(null);
			
		}else{
			document.getElementById('commentssubmit').disabled = true;
			document.getElementById('commentssubmit').value = secnumincorrect;
			document.getElementById('secnumloadim').src = 'gfx/cancel.gif';
		}
	}
}

function refreshcheckcomments()
{
	// checken ob der request fertig ist
	if (checkcommentsrequest.readyState == 4) {
		// alles in Ordnung, Antwort wurde empfangen
			if (checkcommentsrequest.status == 200) {
				// perfekt!
				var text = checkcommentsrequest.responseText;
				if(text == "1")
				{
					document.getElementById('commentssubmit').disabled = false;
					document.getElementById('commentssubmit').value = sendtodb;
					document.getElementById('secnumloadim').src = 'gfx/accept.gif';
				}else{
					document.getElementById('commentssubmit').disabled = true;
					document.getElementById('commentssubmit').value = secnumincorrect;
					document.getElementById('secnumloadim').src = 'gfx/cancel.gif';
				}
			} else {
				// FEHLER
				document.getElementById('secnumloadim').src = 'gfx/cancel.gif';
			}
	} else {
		// noch nicht bereit
		document.getElementById('secnumloadim').src = 'gfx/loader-small.gif';
	}
}


function savecomments()
{
	var name = document.getElementById('commentsname').value;
	var text = document.getElementById('commentstext').value;
	text = text.replace(/\n/g,"<br>");
	var error = 0;
	
	if(name == "")
	{
		error++;
		document.getElementById('commentsname').style.border = "1px solid #930000";
	}else{
		document.getElementById('commentsname').style.border = "1px solid #009300";
	}
	if(text == "")
	{
		error++;
		document.getElementById('commentstext').style.border = "1px solid #930000";
	}else{
		document.getElementById('commentstext').style.border = "1px solid #009300";
	}
	
	if(error == 0)
	{
		comment_content = document.getElementById('content').value;
		comment_content_id = document.getElementById('content_id').value;
		
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			commentsrequest = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE
			commentsrequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		commentsrequest.onreadystatechange = refreshcomments;
		var url = "cont/commentsinsertcontent.inc.php?name=" + name + "&text=" + text + "&content=" + comment_content + "&content_id=" + comment_content_id;
		commentsrequest.open('GET', url, true); 
		commentsrequest.setRequestHeader("Content-Type", "text/html; charset=utf-8");
		commentsrequest.send(null);
	}
}

function refreshcomments()
{
	// checken ob der request fertig ist
	if (commentsrequest.readyState == 4) {
		// alles in Ordnung, Antwort wurde empfangen
			if (commentsrequest.status == 200) {
				// perfekt!
				var text = commentsrequest.responseText;
				document.getElementById('commentsform').innerHTML = text;
			} else {
				// die Anfrage enthielt Fehler;
				sendmail("SAVECOMMENTS - " + commentsrequest.responseText);
				document.getElementById('commentsform').innerHTML = "<b>Error occured!</b><br>" + commentsrequest.responseText;
			}
	} else {
		// noch nicht bereit
		document.getElementById('commentsform').innerHTML = "<table style='width:100%; height:100%;'><tr><td align='center' valign='middle'><img src='gfx/loader.gif' alt=''></td></tr></table>";
	}
}


/******* Own Marker *******/
function setmarkerstart()
{
	document.getElementById('ownmarker').style.display = 'block';
}

function setmarkerstop()
{
	if(isie)
		selectboxes("hide");

	if((mouse_x-200+document.getElementById('mapdiv').scrollLeft) < 0 || (mouse_x-200+document.getElementById('mapdiv').scrollLeft) > img.width || (mouse_y-215+document.getElementById('mapdiv').scrollTop) < 0 || (mouse_y-215+document.getElementById('mapdiv').scrollTop) > img.height)
	{
		document.getElementById('ownmarker_outer').style.display = "block";
		document.getElementById('ownmarker_content').innerHTML = markerinvalid + "<br><br><button OnClick=\"document.getElementById('ownmarker_outer').style.display = 'none'; document.getElementById('ownmarker').style.display = 'block';if(isie) selectboxes('show');\">" + tryagain + "</button> <button OnClick=\"document.getElementById('ownmarker_outer').style.display = 'none';if(isie) selectboxes('show');\">" + cancel + "</button>";
		document.getElementById('ownmarker').style.display = 'none';
	}else{
		document.getElementById('ownmarker_outer').style.display = "block";
		document.getElementById('ownmarker_content').innerHTML = displaymaplink + ":<br><b><a href='http://www.ff12maps.com#map:" + themap + "/" + (mouse_x-200+document.getElementById('mapdiv').scrollLeft) + "/" + (mouse_y-215+document.getElementById('mapdiv').scrollTop) + "'>http://www.ff12maps.com#map:" + themap + "/" + (mouse_x-200+document.getElementById('mapdiv').scrollLeft) + "/" + (mouse_y-215+document.getElementById('mapdiv').scrollTop) + "</a></b><br><br><button OnClick=\"document.getElementById('ownmarker_outer').style.display = 'none'; if(isie) selectboxes('show');\">" + close + "</button>";
		document.getElementById('ownmarker').style.display = 'none';
	}
}


/******* display overlays *******/
function toggledisplay(newdisplay)
{
	display = newdisplay;
	var im = "";
	switch(display)
	{
		case "treasures":
			im = "gfx/new_treasure.png"; break;
		case "traps":
			im = "gfx/new_trap.png"; break;
		case "urns":
			im = "gfx/new_urn.png"; break;
	}
	document.getElementById('displayselect').style.backgroundImage = "url(" + im + ")";
	loadmap(themap,thex,they,thet,thearea);
}


/******* treasures *******/
function displaytreasures(id)
{
	document.getElementById('mapimg').style.cursor = "help";
	treasuretimeout = window.setTimeout("displaytreasures2('" + id + "');",300);
}

function displaytreasures2(id)
{
	window.clearTimeout(treasuretimeout2);
	treasurediv = document.getElementById('treasure_fldst');
	if(treasurediv.style.display != "block")
	{
		treasurediv.style.display = "block";
		if((totalwidth - mouse_x) > 450)
		{
			treasurediv.style.left = (mouse_x+12) + "px";
		}else{
			treasurediv.style.left = (mouse_x-462) + "px";
		}
		
		if((totalheight - mouse_y) > 230)
		{
			treasurediv.style.top = (mouse_y) + "px";
		}else{
			treasurediv.style.top = (mouse_y - 242) + "px";
		}
		gettreasures(id);
	}
}

function hidetreasures()
{
	document.getElementById('mapimg').style.cursor = 'auto';
	window.clearTimeout(treasuretimeout);
	treasuretimeout2 = window.setTimeout("document.getElementById('treasure_fldst').style.display = 'none';",300);
}

function gettreasures(id)
{
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		treasurerequest = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		treasurerequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	treasurerequest.onreadystatechange = new Function("fx", "refreshtreasures('" + id + "')");
	var url = "cont/gettreasures.inc.php?id=" + id;
	treasurerequest.open('GET', url, true); 
	treasurerequest.setRequestHeader("Content-Type", "text/html; charset=utf-8");
	treasurerequest.send(null);
}

function refreshtreasures(id)
{
	// checken ob der request fertig ist
	if (treasurerequest.readyState == 4) {
		// alles in Ordnung, Antwort wurde empfangen
			if (treasurerequest.status == 200) {
				// perfekt!
				var text = treasurerequest.responseText;
				document.getElementById('treasure_fldst').style.width = "450px";
				document.getElementById('treasure_sub').style.display = "block";
				document.getElementById('treasure_div').innerHTML = text;
			} else {
				// die Anfrage enthielt Fehler;
				window.setTimeout("gettreasures(id);", 1000);
				//alert("ERROR:\n" + treasurerequest.responseText);
			}
	} else {
		// noch nicht bereit
		document.getElementById('treasure_fldst').style.width = "40px";
		document.getElementById('treasure_sub').style.display = "none";
		document.getElementById('treasure_div').innerHTML = "<div style='width:32px; height:32px;padding:4px; text-align:center;'><img src='gfx/loader-small.gif' alt=''></div>";
	}
}

/******* TRAPS *******/
function displaytraps(text)
{
	document.getElementById('mapimg').style.cursor = "help";
	trapstimeout = window.setTimeout("displaytraps2('" + text + "');",300);
}

function displaytraps2(text)
{
	window.clearTimeout(trapstimeout2);
	trapsdiv = document.getElementById('traps_fldst');
	if(trapsdiv.style.display != "block")
	{
		trapsdiv.style.display = "block";
		if((totalwidth - mouse_x) > 450)
		{
			trapsdiv.style.left = (mouse_x+12) + "px";
		}else{
			trapsdiv.style.left = (mouse_x-462) + "px";
		}
		
		if((totalheight - mouse_y) > 230)
		{
			trapsdiv.style.top = (mouse_y) + "px";
		}else{
			trapsdiv.style.top = (mouse_y - 242) + "px";
		}
		document.getElementById('traps_div').innerHTML = text;
	}
}

function hidetraps()
{
	document.getElementById('mapimg').style.cursor = 'auto';
	window.clearTimeout(trapstimeout);
	trapstimeout2 = window.setTimeout("document.getElementById('traps_fldst').style.display = 'none';",300);
}


/******* IE HACK *******/
function selectboxes(mode)
{
	var selectboxes = document.getElementsByTagName("select");
	if(mode == "show")
	{
		for(j=0;j<selectboxes.length;j++)
			selectboxes[j].style.visibility = 'visible';
	}else{
		for(j=0;j<selectboxes.length;j++)
			selectboxes[j].style.visibility = 'hidden';
	}
}

function checkgooglesense()
{
	var test = document.getElementById('googlesense').innerHTML;
	if(test.indexOf("iframe") == -1)
	{
		document.getElementById("adblock").style.display = "block";
	}
}


/******* LANG SELECT *******/
function togglelangselect(newlang)
{
	document.getElementById('interface_lang_select').style.backgroundImage = "url(gfx/flags/" + newlang + ".gif)";
}

function loadnewlang()
{
	var lang = document.getElementById('interface_lang_select').options[document.getElementById('interface_lang_select').selectedIndex].value;
	document.location.href = "http://" + lang + ".ff12maps.com/" + document.location.hash;
}


/******* Send Error Mail ******/
function sendmail(message)
{
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		mailrequest = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		mailrequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url = "cont/senderrormail.inc.php?message=" + message;
	mailrequest.open('GET', url, true); 
	mailrequest.setRequestHeader("Content-Type", "text/html; charset=utf-8");
	mailrequest.send(null);
}


/******* Open Licence Gid *******/
function openlicencegrid()
{
	licencewindow = window.open("licencegrid.php", "LicenceGrid", "width=709, height=635, left=10, top=10, dependent=yes, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no");
	licencewindow.focus();
}


/******* Inner Sense *******/
function loadinnersense()
{
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		pagerequests = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		pagerequests = new ActiveXObject("Microsoft.XMLHTTP");
	}
	pagerequests.onreadystatechange = innrsns_rfrs;
	var url = "cont/inner_sense.html";
	pagerequests.open('GET', url, true); 
	pagerequests.setRequestHeader("Content-Type", "text/html; charset=utf-8");
	pagerequests.send(null);
}

function innrsns_rfrs()
{
	// checken ob der request fertig ist
	if (pagerequests.readyState == 4) {
		// alles in Ordnung, Antwort wurde empfangen
			if (pagerequests.status == 200) {
				// perfekt!
				document.getElementById("inner_sense").innerHTML = pagerequests.responseText;
			} else {
				// die Anfrage enthielt Fehler;
			}
	} else {
		// noch nicht bereit
	}
}

