
if (document.layers) N4 = 1;
else if (document.all) IE = 1;
else if (document.getElementById) GK = 1;


/*
if(window.XMLHttpRequest) {
	ajax = new XMLHttpRequest();
} else if(window.ActiveXObject) {
	try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
}
*/

//XMLHttpRequestオブジェクト生成
//Win ie用
if(window.ActiveXObject){
	try {
		//MSXML2以降用
		ajax = new ActiveXObject("Msxml2.XMLHTTP"); //[1]'
	} catch (e) {
		try {
			//旧MSXML用
			ajax = new ActiveXObject("Microsoft.XMLHTTP"); //[1]'
		} catch (e2) {
			ajax = null;
		}
	}
} else if(window.XMLHttpRequest){
	//Win ie以外のXMLHttpRequestオブジェクト実装ブラウザ用
	ajax = new XMLHttpRequest(); //[1]'
} else {
	ajax = null;
}




function $(id){
	return document.getElementById(id);
	}

function firstfunc() {
		if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
		window.onmousewheel = document.onmousewheel = wheel;

		if (IE){
			//document.all["maintable"].onmousemove = dragmove;
			document.all["clear"].onmousedown = down;
			document.all["tempiconlay"].onmousedown = down;
			document.all["target"].onmousedown = down;
			}
		else{
			$("clear").onmousedown = down;
			$("tempiconlay").onmousedown = down;
			$("target").onmousedown = down;
			}
		document.onmouseup = up;
		document.onmousemove = move;
		window.document.onkeydown = keydown;
		window.document.onkeyup = keyup;
		document.ondblclick = dbl;
	
		if (loadCookie('server')=="") document.select.server.value='Euros';
		else document.select.server.value=loadCookie("server");
		if (loadCookie('belong')=="") document.select.belong.value='1';
		else document.select.belong.value=loadCookie("belong");
		if (loadCookie('ami')=="") $('ami').style.visibility='hidden';
		else $('ami').style.visibility=loadCookie("ami");
		if ($('ami').style.visibility=='visible') $('amiicon').innerHTML='<img src="./img/amiicon1.gif">';
		serverold=document.select.server.value;
		belongold=document.select.belong.value;
		
		getData(city,'koueki','');
		
		newx=-600;
		newy=-100;
		document.searchbox.searchword.focus();
		document.searchbox.searchword.style.imeMode='active';
		focusflg=1;
	}



// push > then itemcitylist
function itemcitylist(itemname){
	flgck=0;
	$('progress').innerHTML='<img src="./img/progress.gif">';
	if(IE==1){
		ajax.open('GET', 'http://gvtrademap.daa.jp/ajax/itemsearch20.php?itemname='+itemname);
		}
	else{
		//tempcity=encodeURI(tempcity);
		ajax.open('GET', 'http://gvtrademap.daa.jp/ajax/itemsearch20gk.php?itemname='+itemname);
		}

	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4 && ajax.status == 200) {
			var xmldoc = ajax.responseXML;
			var prices = xmldoc.getElementsByTagName('price');
			var citys = xmldoc.getElementsByTagName('city');
			var learns = xmldoc.getElementsByTagName('learn');
			
			elementno=xmldoc.getElementsByTagName('city').length;	//Elementの数
			var cityuses = xmldoc.getElementsByTagName('cityuse');

			winsizeget();
			shadowswt('visible');
			$('title').innerHTML='　'+itemname;
			var Table='<table border="0" cellpadding="2" cellspacing="1" bgcolor="#000000">';
			var icons="";
			lineno=Math.floor((winy-200)/19);
			var endno=lineno;
			endno=elementno;
			if (elementno<endno){
				endno=elementno;
				}

			for (i=0;i<endno;i++){
				//Table+='<tr><td width="228" id="'+citys[i].firstChild.nodeValue+'" nowrap>';
				Table+='<tr><td width="170" id="'+citys[i].firstChild.nodeValue+'" nowrap>';
				if (getflgno(citys[i].firstChild.nodeValue)==document.select.belong.value){
					Table+='　<a href="#" onClick="cityjump(\''+citys[i].firstChild.nodeValue+'\');">'+citys[i].firstChild.nodeValue+'</a></td>';
					Table+='<td class="price" width="58" nowrap>'+addFigure(prices[i].firstChild.nodeValue)+'</td></tr>';
					}
				else{
					Table+='　<a href="#" onClick="cityjump(\''+citys[i].firstChild.nodeValue+'\');"><font color="gray">'+citys[i].firstChild.nodeValue+'</font></a></td>';
					if (type=='koueki'){
						if (prices[i].firstChild.nodeValue>=0){
							Table+='<td class="price" width="58" nowrap>'+addFigure(Math.floor(1.14*prices[i].firstChild.nodeValue))+'</td></tr>';
							}
						if (prices[i].firstChild.nodeValue==-1){
							Table+='<td class="kind" width="58" nowrap><font color="#008888">採集</font></td></tr>';
							}
						if (prices[i].firstChild.nodeValue==-2){
							Table+='<td class="kind" width="58" nowrap><font color="#888800">調達</font></td></tr>';
							}
						}
					else if (type!=='hito'){
						Table+='<td class="price" width="58" nowrap>'+addFigure(prices[i].firstChild.nodeValue)+'</td></tr>';
						}
					else{
						Table+='<td class="price" width="58" nowrap></td></tr>';
						}
					}
				}
			
			
			
			for (j=0;j<cityno;j++){
				cityspot[j]=0;
				}
			
			for (i=0;i<elementno;i++){
				for (j=0;j<cityno;j++){
					if (cityname[j]==citys[i].firstChild.nodeValue && cityspot[j]==0){
						icons+='<div id="city'+j+'" style="position:absolute;left:'+((cityx[j]-20)*zoom/100)+'px;';
						icons+='top:'+((cityy[j]-20)*zoom/100)+'px;z-index:4;visibility:visible;';
						//明るく！
						if (getflgno(citys[i].firstChild.nodeValue)==document.select.belong.value || type!=='koueki'){
							if (GK==1){
								//icons+='"><img id="cityimg'+j+'" src="trademap_gkimg.php?img='+cityname[j]+'" width="30" height="30">';
								icons+='"><img id="cityimg'+j+'" src="trademap_gkimg.php?img='+cityname[j]+'">';
								}
							else{
								//icons+='"><img id="cityimg'+j+'" src="./img/'+cityname[j]+'.gif" width="30" height="30">';
								icons+='"><img id="cityimg'+j+'" src="./img/'+cityname[j]+'.gif">';
								}
							if (xmldoc.getElementsByTagName('learn').length>0){
								icons+='<span style="position:absolute;left:-7;top:15;font-size:9px;width:200px;nowrap;"><b>'+learns[i].firstChild.nodeValue+'</b></span>';
								icons+='<span style="position:absolute;left:-6;top:14;font-size:9px;width:200px;nowrap;"><b>'+learns[i].firstChild.nodeValue+'</b></span>';
								icons+='<span style="position:absolute;left:-6;top:16;font-size:9px;width:200px;nowrap;"><b>'+learns[i].firstChild.nodeValue+'</b></span>';
								icons+='<span style="position:absolute;left:-5;top:15;font-size:9px;width:200px;nowrap;"><b>'+learns[i].firstChild.nodeValue+'</b></span>';
								icons+='<span style="position:absolute;left:-6;top:15;font-size:9px;color:#FFFFFF;width:200px;nowrap;"><b>'+learns[i].firstChild.nodeValue+'</b></span>';
								}
							
							icons+='</div>\n';
							}
						//暗く
						else{
							icons+='filter:alpha(style=0,opacity=50);-moz-opacity:0.5;opacity:0.5;">';
							if (GK==1){
								//icons+='<img id="cityimg'+j+'" src="trademap_gkimg.php?img='+cityname[j]+'" width="30" height="30">';
								icons+='<img id="cityimg'+j+'" src="trademap_gkimg.php?img='+cityname[j]+'">';
								}
							else{
								//icons+='<img id="cityimg'+j+'" src="./img/'+cityname[j]+'.gif" width="30" height="30">';
								icons+='<img id="cityimg'+j+'" src="./img/'+cityname[j]+'.gif">';
								}
							icons+='</div>\n';
							}
						cityspot[j]=1;
						}
					//else{
					//	cityspot[j]=0;
					//	}
					}
				}


			for (i=0;i<xmldoc.getElementsByTagName('cityuse').length;i++){
				//hitno++
				for (j=0;j<cityno;j++){
					if (cityname[j]==cityuses[i].firstChild.nodeValue){
						icons+='<div id="city'+j+'" style="position:absolute;left:'+((cityx[j]-20)*zoom/100)+'px;';
						icons+='top:'+((cityy[j]-20)*zoom/100)+'px;z-index:4;visibility:visible;';
						if (GK=1){
							//icons+='filter:alpha(style=0,opacity=50);-moz-opacity:0.5;opacity:0.5;"><img id="cityimg'+j+'" src="trademap_gkimg.php?img='+cityuses[i].firstChild.nodeValue+'" width="30" height="30"></div>\n';
							icons+='filter:alpha(style=0,opacity=50);-moz-opacity:0.5;opacity:0.5;"><img id="cityimg'+j+'" src="trademap_gkimg.php?img='+cityuses[i].firstChild.nodeValue+'"></div>\n';
							}
						else{
							//icons+='filter:alpha(style=0,opacity=50);-moz-opacity:0.5;opacity:0.5;"><img id="cityimg'+j+'" src="./img/'+cityuses[i].firstChild.nodeValue+'.gif" width="30" height="30"></div>\n';
							icons+='filter:alpha(style=0,opacity=50);-moz-opacity:0.5;opacity:0.5;"><img id="cityimg'+j+'" src="./img/'+cityuses[i].firstChild.nodeValue+'.gif"></div>\n';
							}

						cityspot[j]=1;
						break;
						}
					}
				}


			Table+='</table>';
			$('maintable').innerHTML=Table;
			
			
			$('cityicon').innerHTML =icons;
			
			/*
			for (j=0;j<cityno;j++){
				if (cityspot[j]==1){
					changeImage('cityimg'+j);
					}
				}
			
			for (i=0;i<elementno;i++){
				for (j=0;j<cityno;j++){
					if (cityname[j]==citys[i].firstChild.nodeValue){
						changeImage('cityimg'+j);
						}
					}
				}
			*/
			changeImagesize();
			$('progress').innerHTML=elementno+'件';
		}
	}
	ajax.send(null);
	}


function shadowswt(swt){
	if (swt){
		shadowset=0;
		if (swt=='visible') shadowset=1;
		if ( GK ){
			$('shadow').style.visibility=swt;
			}
		else if ( IE ){
			document.all('shadow').style.visibility=swt;
			}
		else if ( OP ){
			if (swt='hidden'){
				swt='hide';
				}
			document.layers['shadow'].visibility=swt;
			}
		}
	}


function findElement(n) {
	return document.all ? document.all(n)
	: $(n);
	}

function allflg(){
	flgck=1;
	var icons="";
	shadowswt('visible');
	for (i=0;i<cityonly;i++){
		icons=icons+'<div id="city'+i+'" style="position:absolute;left:'+((cityx[i]-12)*zoom/100)+'px;';
		icons=icons+'top:'+((cityy[i]-8)*zoom/100)+'px;z-index:4;visibility:visible;">';
		if (document.select.server.value=='Euros'){
			icons=icons+'<img id="cityimg'+i+'" src="./img/flg'+domain_euros[i]+'.gif">';
			}
		if (document.select.server.value=='Zephyros'){
			icons=icons+'<img id="cityimg'+i+'" src="./img/flg'+domain_zephyros[i]+'.gif">';
			}
		if (document.select.server.value=='Notos'){
			icons=icons+'<img id="cityimg'+i+'" src="./img/flg'+domain_notos[i]+'.gif">';
			}
		if (document.select.server.value=='Boreas'){
			icons=icons+'<img id="cityimg'+i+'" src="./img/flg'+domain_boreas[i]+'.gif">';
			}
		icons=icons+'</div>\n';
		cityspot[i]=1;
		}
	$('cityicon').innerHTML =icons;
	changeImagesize();
	}




function meisanspot(nowcity,itemname){
	z=(zoom/10)-4;
	var nowcityno=0;
	for (i=0;i<meisan.length;i++){
		if (itemname==meisan[i]){
			nowcityno=meisanarea[i];
			break;
			}
		}
	$('area').style.visibility='visible';
	$('base').innerHTML='<img src="./img/meisanwbg_'+zoom+'.gif">';
	

	for (i=1;i<meisanx.length;i++){
		if (i==20 || i==21 || i==22 || i==23 || i==25) continue;
		$('lay'+i).innerHTML='';

		tx=meisanx[i][z];
		ty=meisany[i][z];
		for (j=0;j<4;j++){
			if (meisannot[nowcityno][j]==i){
				$('lay'+i).style.left=tx+'px';
				$('lay'+i).style.top=ty+'px';
				$('lay'+i).innerHTML='<img src="./img/meisanw'+i+'_'+zoom+'.gif">';
				}
			}
		
		if (itemname=='コショウ'){
			if (i==15 || i==16 || i==17){
				$('lay'+i).style.left=tx+'px';
				$('lay'+i).style.top=ty+'px';
				$('lay'+i).innerHTML='<img src="./img/meisanw'+i+'_'+zoom+'.gif">';
				}
			if (i==6 || i==7 || i==8) $('lay'+i).innerHTML='';
			continue;
			}
		if (i==9 || i==10 || i==11 || i==14 || i==15 || i==16){
			if (itemname=='ウイスキー' || itemname=='シェリー' || itemname=='テキーラ' || itemname=='フルーツブランデー' || itemname=='アクアビット' || itemname=='ジン'){
				$('lay'+i).style.left=tx+'px';
				$('lay'+i).style.top=ty+'px';
				$('lay'+i).innerHTML='<img src="./img/meisanw'+i+'_'+zoom+'.gif">';
				continue;
				}
			}
		}
	
	//nowcityも消す
	$('lay'+nowcityno).style.left=meisanx[nowcityno][z]+'px';
	$('lay'+nowcityno).style.top=meisany[nowcityno][z]+'px';
	$('lay'+nowcityno).innerHTML='<img src="./img/meisanw'+nowcityno+'_'+zoom+'.gif">';

	}

function addFigure(str) {
var num = new String(str).replace(/,/g, "");
while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
return num;
}

