// JavaScript Document
//2007 @ fantasyarea.com
function createRequest()
{
	if (window.XMLHttpRequest) { 
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('text/xml');
		}
	} 
	else if (window.ActiveXObject)
	{ 
		try  {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {}
		}
	}
	return httpRequest;
}

function getMonster(url)
{
	createRequest();
	httpRequest.onreadystatechange = getMonsterResult;
	httpRequest.open('GET', url, true);
	httpRequest.send(null);
}

function getMonsterResult()
{
	if (httpRequest.readyState == 4)
	{
		if (httpRequest.status == 200) 
		{
			xmlDoc = httpRequest.responseXML;
			var loc = 0; 
			var monster = xmlDoc.getElementsByTagName("Monster");
			var display = "";
			for(i=0; i<monster.length; i++)
			{
				m_loc = monster[i].childNodes[0].firstChild.nodeValue;
				if(m_loc != loc)
				{
					if(loc!=0) {
						display += '</ul>\n';
						display += '<div class="fclear"></div>\n';
						display += '</div>\n';
					}
					display += '<div class="map_mon_area">\n';
					display += '<h1>區域 '+m_loc+'</h1>\n';
					display += '<ul class="map_mon">\n';
					loc = m_loc;
				}
				m_name = monster[i].childNodes[1].firstChild.nodeValue;
				m_boss = monster[i].childNodes[2].firstChild.nodeValue;
			 	m_level = monster[i].childNodes[3].firstChild.nodeValue;
				m_HP = monster[i].childNodes[4].firstChild.nodeValue;
				m_A = monster[i].childNodes[5].firstChild.nodeValue;
				display+='<li onmouseover="Tip(\'Lv'+m_level+' '+'HP: '+m_HP+' '+m_A+'\')">'+m_name+'</li>';
				
				if(i==monster.length-1)
				{
					display += '<div class="fclear"></div>\n';
					display += '</ul>\n';
					display += '</div>\n';
				}
				
				 //alert(m_loc);
				 //document.getElementById('m_monster').innerHTML = m_loc;
			 }
			 //alert(display);
			 //document.write(display)
			 document.getElementById('m_monster').innerHTML = display;
		}
	}
}

var preimg;
var vshow;
var vupic;

function loadImage(show, upic)
{
	vshow = show;
	vupic = upic;
	document.getElementById(show).innerHTML = '<img src="image/pic_loading.gif" class="indicator">';
	preimg = new Image();
	preimg.src = upic;
	replace_img();
}

function replace_img()
{
	if (preimg.complete)
	{
		document.getElementById(vshow).innerHTML = '<img src="'+vupic+'">';
		return;
	}
	else
	{
		setTimeout('replace_img()', 300);
	}
}

function loadMap(show, upic, i, p, n)
{
	loadImage(show, upic);
	
	if(i==1) {
		document.getElementById('mt1').innerHTML = '<img src="image/map_tab1a.gif" name="Img_mt1" width="32" height="122" border="0" id="Img_mt1" />';
		document.getElementById('mt2').innerHTML = '<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Img_mt2\',\'\',\'image/map_tab2a.gif\',1)" onClick="loadMap(\'map_dis\',\''+p+'\',\'2\',\''+upic+'\',\''+n+'\')"><img src="image/map_tab2b.gif" name="Img_mt2" width="32" height="122" border="0" id="Img_mt2" /></a>';
		document.getElementById('m_monster').innerHTML='';
	}
	if(i==2) {
		document.getElementById('mt1').innerHTML = '<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Img_mt1\',\'\',\'image/map_tab1a.gif\',1)" onClick="loadMap(\'map_dis\',\''+p+'\',\'1\',\''+upic+'\',\''+n+'\')"><img src="image/map_tab1b.gif" name="Img_mt1" width="32" height="122" border="0" id="Img_mt1" /></a>';
		document.getElementById('mt2').innerHTML = '<img src="image/map_tab2a.gif" name="Img_mt2" width="32" height="122" border="0" id="Img_mt2" />';
		getMonster('map_monster.php?m='+n);
	}
}

//Macromedia
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
