/*
　マップ操作関連の共通処理
　taro matsumoto
　2006/12/27
*/

// サブディレクトリの判別
var subdir = window.location.pathname.substring(1, window.location.pathname.indexOf("/", 1));

// urlパラメータ値を入れる変数
var strUrlParameter = window.location.search.substring(1);

// fidの値を入れる変数
var fidParam = "";

// パラメータにcoords,x,yが含まれるかどうかを判別した結果を入れる変数
var isCoords = false;
var isX = false;
var isY = false;

// Ajax.Requestするスクリプトの指定
var mapscriptURL = "../common/php/mapscript.php?dir=" + subdir;

// ひとつ前の地図URLをいれる変数
var prevmapimageURL = "";

// xmlドキュメントオブジェクトをいれる変数
var xmlDocument;

// 地図上のアイコン部分のHTML文字列をいれる変数
var strHTMLPixCoordsIcons = "";

// リスト部分のHTML文字列をいれる変数
var strHTMLFeaturesList = "";

// 主題図属性リスト部分のHTML文字列をいれる変数
var strOtherHTMLFeaturesList = "";

// 凡例の表示状態
var legendstatus = false;

// 航空写真の表示状態
var aerophotostatus = false;

// 地図画像の表示状態（trueならば表示完了。falseならばloadingdata）
var mapimagestatus = false;

// 地図画像のクリック座標
var coordx;
var coordy;

// 現在のURLを表示するかどうか
var isShowMapUrl = false;


// 属性表示のための別名定義
var fieldAliasList  = new Array();
fieldAliasList["文化財"] =      "filingkey:ファイリングキー|name:名前|kana:かな|address:所在地|tel:TEL|fax:FAX|url:URL|bikou:備考|yoyaku:予約|category:カテゴリ|areacd:エリアコード|x:X|y:Y";
fieldAliasList["遺跡"] =      "filingkey:ファイリングキー|name:名前|kana:かな";
fieldAliasList["学校区"] =          "filingkey:ファイリングキー|name:名前|kana:かな|bikou:備考";
fieldAliasList["ゴミ収集範囲"] =    "filingkey:ファイリングキー|name:名前|kana:かな|areacd:エリアコード|sun:日|mon:月|tue:火|wed:水|thu:木|fri:金|sat:土|bikou:備考";
fieldAliasList["庁舎間巡回バス路線"] =  "filingkey:ファイリングキー|bikou:備考";
fieldAliasList["庁舎間巡回バス乗り場"] =  "filingkey:ファイリングキー|name:名前|address:所在地|url:URL";
fieldAliasList["標準地（平成18年度）"] =          "hkey:標準地番号|hkubf:標準地区分フラグ|dno:表示用標準地番号|dno2:表示用標準地価格|idod:異動日時";
fieldAliasList["土地改良区"] =      "filingkey:ファイリングキー|name:名前|kana:かな|bikou:備考";
fieldAliasList["太陽の家"] =        "filingkey:ファイリングキー|bikou:備考";
fieldAliasList["都市計画用途図"] =  "filingkey:ファイリングキー|memo:名称|type:用途|kenpei:建ぺい率|yoseki:容積|menseki:面積|dno:表示文字|bikou:備考";



// fidParamの値をセット
if (strUrlParameter.length > 0) {
    arr = strUrlParameter.split("&");
    if(arr[0].indexOf("fid",0)>-1)  {
        fidParam = arr[0].split("=")[1];
    }
}

// isCoords,isX,isYの値をセット
arr = strUrlParameter.split("&");
for (i = 0; i < arr.length-1; i++) {
    if(arr[i].indexOf("cmd=coords",0)>-1)  {
        isCoords = true;
    }
    if(arr[i].indexOf("x=",0)>-1)  {
        isX = true;
    }
    if(arr[i].indexOf("y=",0)>-1)  {
        isY = true;
    }
}

// ウィンドウがロードされたときの処理
window.onload = function() {
    if ($('mapimage')) {
        Event.observe('mapimage', 'load', unmask, false); 
        Event.observe('nw', 'mouseout', jayroMouseOut, true); 
        Event.observe('nw', 'mouseover', jayroMouseOver, true); 
        Event.observe('nn', 'mouseout', jayroMouseOut, true); 
        Event.observe('nn', 'mouseover', jayroMouseOver, true); 
        Event.observe('ne', 'mouseout', jayroMouseOut, true); 
        Event.observe('ne', 'mouseover', jayroMouseOver, true); 
        Event.observe('ww', 'mouseout', jayroMouseOut, true); 
        Event.observe('ww', 'mouseover', jayroMouseOver, true); 
        Event.observe('cc', 'mouseout', jayroMouseOut, true); 
        Event.observe('cc', 'mouseover', jayroMouseOver, true); 
        Event.observe('ee', 'mouseout', jayroMouseOut, true); 
        Event.observe('ee', 'mouseover', jayroMouseOver, true); 
        Event.observe('sw', 'mouseout', jayroMouseOut, true); 
        Event.observe('sw', 'mouseover', jayroMouseOver, true); 
        Event.observe('ss', 'mouseout', jayroMouseOut, true); 
        Event.observe('ss', 'mouseover', jayroMouseOver, true); 
        Event.observe('se', 'mouseout', jayroMouseOut, true); 
        Event.observe('se', 'mouseover', jayroMouseOver, true); 
        mapRefresh();
    }
    if ($('scalebar')) {
        new Draggable("scalebar");
    }
    if ($('zoompallete')) {
        var objDraggablezoompallete = new Draggable("zoompallete", {handle:"zoompalletehandler"});
        $("zoompalletehandler").style.width = Element.getDimensions($('zoompallete')).width;
    }
    if ($('scaleinfo')) {
        var objDraggablescaleinfo = new Draggable("scaleinfo", {handle:"scaleinfohandler"});
        $("scaleinfohandler").style.width = Element.getDimensions($('scaleinfo')).width;
    }

}

// ジャイロバーにマウスオーバー/アウトした場合の処理
function jayroMouseOver(e) {
    var it = Event.element(e);
    if (it.id.length > 0 ) {
        $(it).style.backgroundColor = "#999966";
    }
}
function jayroMouseOut(e) {
    var it = Event.element(e);
    if (it.id.length > 0 ) {
        $(it).style.backgroundColor = "#CCCC99";
    }
}

// 凡例の表示非表示切り替え
function showLegend(e) {

    var objDraggable = new Draggable("legend", {handle:"legendtitle"});
    $("legend").style.left = Position.cumulativeOffset($('zoompallete'))[0] + Element.getDimensions($('zoompallete')).width + 10;
    $("legend").style.top = Position.cumulativeOffset($('zoompallete'))[1];
    $("legend").style.height = Element.getDimensions($('mapimage')).height * 0.8;
    $("legendinner").style.height = Element.getDimensions($('mapimage')).height * 0.76;
    $("legend").style.width = Element.getDimensions($('legendbarimage')).width+2;
    $("legendinner").style.width = Element.getDimensions($('legendbarimage')).width;
    $("closelegend").style.left = Element.getDimensions($('legendtitle')).width - Element.getDimensions($('closelegend')).width - 18;
    if (legendstatus) {
        objDraggable.destroy();
        $("legend").style.visibility = "hidden";
        legendstatus = false;
    } else {
        $("legend").style.visibility = "visible";
        legendstatus = true;
    }
}

// クリック操作
function command(obj) {
    var command = true;
    if (obj.id == "nw") {
        // 北西方向への移動の前処理
    } else if (obj.id == "nn") {
        // 北方向への移動の前処理
    } else if (obj.id == "ne") {
        // 北東方向への移動の前処理
    } else if (obj.id == "ww") {
        // 西方向への移動の前処理
    } else if (obj.id == "cc") {
        // 中心方向への移動の前処理
    } else if (obj.id == "ee") {
        // 東方向への移動の前処理
    } else if (obj.id == "sw") {
        // 南西方向への移動の前処理
    } else if (obj.id == "ss") {
        // 南方向への移動の前処理
    } else if (obj.id == "se") {
        // 南東方向への移動の前処理
    } else if (obj.id == "zoomin") {
        // 拡大の前処理
        if (limitMaxMinScale("max")) {
            command = true;
        } else {
            command = false;
        }
    } else if (obj.id == "zoomout") {
        // 縮小の前処理
        if (limitMaxMinScale("min")) {
            command = true;
        } else {
            command = false;
        }
    } else if (obj.id == "mapimage") {
        // パンの前処理
    } else if (obj.id == "scalechange") {
        // 縮尺変更の前処理
        if (document.f.scalechange.selectedIndex == 0) {
            if (limitMaxMinScale()) {
                command = true;
            } else {
                command = false;
            }
        } 
    } else if (obj.id == "aerophoto") {
        // 航空写真表示の前処理
        if ($("aerophoto").checked == true) {
            document.f.aerophotostatus.value = "1";
        } else {
            document.f.aerophotostatus.value = "0";
        }
    } else if (obj.id == "selMap") {
        // 主題図マップ切り替えの前処理
        if (obj.value != "") {
            document.f.mapname.value = obj.value;
            document.f.cmd.value = obj.value;
        } else {
            command = false;
        }
    } else {
        command = false;
    }
    
    
    if (command) {
        document.f.cmd.value = obj.id;
        mapRefresh();
        document.f.scalechange.blur();
        document.f.t.focus();
    }
}




// 最小縮尺分母のチェック
function limitMaxMinScale(strMode) {
    var boolMaxMinScale = true;
    if (strMode == "max") {
        if (parseInt($('scale').value)/2 < 100) {
            alert("これ以上大縮尺の地図表示はできません。");
            boolMaxMinScale = false;
        } else {
            boolMaxMinScale = true;
        }    
    }
    if (strMode == "min") {
        if (parseInt($('scale').value)*2 > 1000000) {
            alert("これ以上小縮尺の地図表示はできません。");
            boolMaxMinScale = false;
        } else {
            boolMaxMinScale = true;
        }
    }
    return boolMaxMinScale;
}

// 地図画像クリック時に要素上の座標を取得する
function mapClick(obj,e) {

	/*
    var x = Event.pointerX(e);
    var y = Event.pointerY(e);
	var ret = Position.cumulativeOffset($('mapimage'));
	x = x - ret[0];
	y = y - ret[1];
	*/
	
    var pixx;
    var pixy;
    if(document.all) {
        pixx = e.offsetX;
        pixy = e.offsetY;
    } else if(document.layers || document.getElementById ) {
        pixx = e.layerX;
        pixy = e.layerY;
    }
	
    document.f.mainmapx.value = pixx;
    document.f.mainmapy.value = pixy;

    command(obj);

}


// loadingdataの表示を開始する
function mask() {
    if ($('featureicon')) {
        $('featureicon').innerHTML = '';
        $('featureicon').style.display = 'none';
        $('featureicon').style.visibility = 'hidden';
    }
    if ($('showsaiPhoto')) {
        //$('showsaiPhoto').src = '../../common/img/white.gif';
    }
    if ($('attributeinfo')) {
        $('attributeinfo').style.visibility = 'hidden';
        $('attributeinfo').style.display = 'none';
    }
    if ($('otherattributeinfo')) {
		$('otherattributeinfo').style.visibility = 'hidden';
		$('otherattributeinfo').style.display = 'none';
		$('otherattributeinfotitle').style.visibility = 'hidden';
		$('otherattributeinfotitle').style.display = 'none';
		
    }

    if ($('featurelisthtml')) {
        $('featurelisthtml').innerHTML = '';
        $('featurelisthtml').display = 'none';
    }
    if ($('itemlist')) {
        $('itemlist').style.display = 'none';
        $('itemlist').style.visibility = 'hidden';
    }
    if ($('loadingdata')) {
        $('loadingdata').style.visibility = 'visible';
    }
    if ($('mask')) {
        $('mask').style.visibility = 'visible';
    }
    if ($('scalechange')) {
        $('scalechange').style.visibility = 'hidden'; 
    }
    if ($('showsaiName')) {
        var strMes = 'データ検索中...';
        $('showsaiPhoto').style.visibility = 'hidden';
        $('showsaiPhoto').style.display = 'none';
        $('showsaiName').innerHTML = strMes;
        $('showsaiKana').innerHTML = '　';
        $('showsaiAddress').innerHTML = strMes;
        $('showsaiTel').innerHTML = strMes;
        $('showsaiFax').innerHTML = strMes;
        $('showsaiUrl').innerHTML = strMes;
        $('showsaiInfo').innerHTML = strMes;
        $('showsaiName').style.color = '#CCCCCC';
        $('showsaiAddress').style.color = '#CCCCCC';
        $('showsaiTel').style.color = '#CCCCCC';
        $('showsaiFax').style.color = '#CCCCCC';
        $('showsaiUrl').style.color = '#CCCCCC';
        $('showsaiInfo').style.color = '#CCCCCC';
    }
}

// loadingdataの表示を解除する
function unmask(e) {
    var elmfeaturelist = xmlDocument.getElementsByTagName("featurelist").item(0);
    var elmotherfeaturelist = xmlDocument.getElementsByTagName("otherfeaturelist").item(0);
    if ($('loadingdata')) {
        $('loadingdata').style.visibility = 'hidden';
    }
    if ($('mask')) {
        $('mask').style.visibility = 'hidden';
    }
    if ($('scalechange')) {
        $('scalechange').style.visibility = 'visible';
    }
    if ($('featurelistcount')) {
        $('featurelistcount').innerHTML = getTagValue(elmfeaturelist,"featurecount") + '件';
    }
    if ($('aerophoto')) {
        if ($('aerophotostatus').value == "1") {
            $('aerophoto').checked = true;
        } else if ($('aerophotostatus').value == "0") {
            $('aerophoto').checked = false;
        }
        if ((getTagValue(xmlDocument.documentElement,"scale") > 5001) || (getTagValue(xmlDocument.documentElement,"scale") < 1000)) {
            $('anotationaerophotoshow').innerHTML = "(1/1000～1/5000の範囲のみで表示可)";
            $('aerophoto').disabled = true;
        } else {
            $('anotationaerophotoshow').innerHTML = "";
            $('aerophoto').disabled = false;
       }
    }

    if ($('selMap')) {
        for (i = 0; i < document.dummyform.mapname.length; i++) {
            if (document.dummyform.mapname.options[i].value == getTagValue(xmlDocument.documentElement,"mapname")) {
                document.dummyform.mapname.selectedIndex = i;
            }
        }
    }
//alert(getTagValue(elmotherfeaturelist,"otherfeaturecount"));

    if ($('otherfeaturelisthtml')) {
        
        if (getTagValue(elmotherfeaturelist,"otherfeaturecount") > 0) {
	        $('otherfeaturelisthtml').innerHTML = strOtherHTMLFeaturesList;
	        $('otherfeaturelisthtml').display = 'block';
			if ($('otherattributeinfo')) {
	            $('otherattributeinfo').style.display = 'block';
	            $('otherattributeinfo').style.visibility = 'visible';
				$('otherattributeinfotitle').style.visibility = 'visible';
				$('otherattributeinfotitle').style.display = 'block';
			}

			if ((getTagValue(elmotherfeaturelist,"otherfeaturecount") == 1) && (getTagValue(elmitems[0],"name") == "公共施設" )) {
		        
				$('otherfeaturelisthtml').innerHTML = "";
		        $('otherfeaturelisthtml').display = 'none';
				if ($('otherattributeinfo')) {
		            $('otherattributeinfo').style.display = 'none';
		            $('otherattributeinfo').style.visibility = 'hidden';
					$('otherattributeinfotitle').style.visibility = 'hidden';
					$('otherattributeinfotitle').style.display = 'none';
				}
			}
        } else {
	        $('otherfeaturelisthtml').innerHTML = "";
	        $('otherfeaturelisthtml').display = 'none';
			if ($('otherattributeinfo')) {
	            $('otherattributeinfo').style.display = 'none';
	            $('otherattributeinfo').style.visibility = 'hidden';
				$('otherattributeinfotitle').style.visibility = 'hidden';
				$('otherattributeinfotitle').style.display = 'none';
			}
        }
    }



    if ($('featurelisthtml')) {
        $('featurelisthtml').innerHTML = strHTMLFeaturesList;
        $('featurelisthtml').display = 'block';
    }
    if ($('itemlist')) {
        $('itemlist').style.display = 'block';
        $('itemlist').style.visibility = 'visible';
    }
    if ($('featureicon')) {
        if (parseInt(getTagValue(elmfeaturelist,"featurecount")) < 1) {
            $('featureicon').style.visibility = 'hidden';
            $('featureicon').style.display = 'none';
        } else {
            $('featureicon').innerHTML = strHTMLPixCoordsIcons;
            $('featureicon').style.position = 'static';
            $('featureicon').style.display = 'inline';
        }
    }

    $("legend").style.height = Element.getDimensions($('mapimage')).height * 0.8;
    $("legendinner").style.height = Element.getDimensions($('mapimage')).height * 0.76;
    $("legend").style.width = Element.getDimensions($('legendbarimage')).width+2;
    $("legendinner").style.width = Element.getDimensions($('legendbarimage')).width;

    if ($('markerimage')) {
       if (isCoords && isX && isY && 
       ((parseInt(getTagValue(xmlDocument.documentElement,"markerpixx")) ) > -1)  && 
       ((parseInt(getTagValue(xmlDocument.documentElement,"markerpixy")) ) > -1)  && 
       ((parseInt(getTagValue(xmlDocument.documentElement,"markerpixx")) ) < 661)  && 
       ((parseInt(getTagValue(xmlDocument.documentElement,"markerpixy")) ) < 451) 
       ) {
           $('markerimage').style.visibility = 'visible';
           $('markerimage').style.left = getTagValue(xmlDocument.documentElement,"markerpixx") - 13;
           $('markerimage').style.top = getTagValue(xmlDocument.documentElement,"markerpixy") - 33;
           $('addressstring').style.left = parseInt(getTagValue(xmlDocument.documentElement,"markerpixx")) + 16;
           $('addressstring').style.top = getTagValue(xmlDocument.documentElement,"markerpixy") - 32;
           if (getTagValue(xmlDocument.documentElement,"markeraddress") != "") {
               $('addressstring').innerHTML = getTagValue(xmlDocument.documentElement,"markeraddress");
           }
       } else {
           $('markerimage').style.visibility = 'hidden';
           $('addressstring').style.visibility = 'hidden';
       }
    }
    if ((document.f.cmd.value != "coords") && (document.f.cmd.value != "area") && (document.f.cmd.value != "aerophotostatus") ) {
        document.f.cmd.value = "";
    }
    if (fidParam != "") {
        showInfo(fidParam);
    }
}

// 詳細情報表示欄の書き換え処理
function showInfo(fid) {


    var strFID = "";
    elms = document.getElementsByName('featureicon');
    for (i = 0; i < elms.length; i++) {
        elms[i].src = '../../common/img/spacer.gif';
        elms[i].style.visibility = 'visible';
    }
    var elmfeaturelist = xmlDocument.getElementsByTagName("featurelist").item(0);
    if (elmfeaturelist) {
         if (getTagValue(elmfeaturelist,"featurecount") > 0) {
            elmitems = elmfeaturelist.getElementsByTagName("item");
            for (i = 0; i < elmitems.length; i++) {
                strrowid = elmitems[i].getAttribute("rowid"); 
                elmattributeinfo = elmitems[i].getElementsByTagName("attributeinfo").item(0);
                elmmapscriptinfo = elmitems[i].getElementsByTagName("mapscriptinfo").item(0);
                if (getTagValue(elmattributeinfo,"filingkey") != "") {
                    strFID = getTagValue(elmattributeinfo,"filingkey");
                } else {
                    strFID = getTagValue(elmattributeinfo,"fid");
                }
                if (strFID == fid) {
                    var strOption = "";
                    if ($('selMap')) {
                        if (document.f.mapname.value != "default.map") {
                            strOption = strOption + '&mapname=' + document.f.mapname.value;
                        }
                    }
                    if (getTagValue(xmlDocument.documentElement,"aerophotostatus") == "1") {
                        strOption = strOption + '&aerophotostatus=1';
                    }
                    strFeatureIconId = 'featureicon' + strrowid;
                    if ($('showsaiPhoto')) {
                        if (getTagValue(elmmapscriptinfo,"photo") != "") {
                            $('showsaiPhoto').style.display = 'inline';
                            $('showsaiPhoto').style.visibility = 'visible';
                            $('showsaiPhoto').src = './photo/' + strFID + '.jpg';
                        } else {
                            $('showsaiPhoto').style.visibility = 'hidden';
                            $('showsaiPhoto').style.display = 'none';
                        }
                    }
                    if ($('showsaiName')) {
						strTooltip = 'クリックすると 「' + getTagValue(elmattributeinfo,"name") + '」 を中心にして地図を表示します。';
                        $('showsaiName').innerHTML = '<a href="map.php?fid=' + strFID + strOption + '" class="showsai" title="' + strTooltip + '" alt="' + strTooltip + '">' + getTagValue(elmattributeinfo,"name") + '</a>';
                        $('showsaiKana').innerHTML = getTagValue(elmattributeinfo,"kana");
                        $('showsaiAddress').innerHTML = getTagValue(elmattributeinfo,"address")+"　";
                        $('showsaiTel').innerHTML = getTagValue(elmattributeinfo,"tel")+"　";
                        $('showsaiFax').innerHTML = getTagValue(elmattributeinfo,"fax")+"　";
                        $('showsaiUrl').innerHTML = '<a href="' + getTagValue(elmattributeinfo,"url") + '" target="_blank">' + getTagValue(elmattributeinfo,"url") + '</a>'+"　";
                        
						if(getTagValue(elmattributeinfo,"bikou") != "" ){
							if(getTagValue(elmattributeinfo,"bikou").substring(0, 4) == "http" ){
								$('showsaiInfo').innerHTML = '<input type="button" onclick="window.open(\''+getTagValue(elmattributeinfo,"bikou") + '\',\'yoyaku\')" value="施設を予約する" />'+"　";
							}else{
								$('showsaiInfo').innerHTML = getTagValue(elmattributeinfo,"bikou")+"　";
							}
						}else{
							$('showsaiInfo').innerHTML = "　";
						}
                        /* $('showsaiInfo').innerHTML = getTagValue(elmattributeinfo,"bikou")+"　"; */
                        $('showsaiAddress').style.color = '#333333';
                        $('showsaiTel').style.color = '#333333';
                        $('showsaiFax').style.color = '#333333';
                        $('showsaiUrl').style.color = '#333333';
                        $('showsaiInfo').style.color = '#333333';
                    }
                    if ($('attributeinfo')) {
                        $('attributeinfo').style.visibility = 'visible';
                        $('attributeinfo').style.display = 'block';
                        new Effect.Highlight($('attributeinfo'), {startcolor:'#CCCC99', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
                    }
                    $(strFeatureIconId).style.visibility = 'visible';
                    $(strFeatureIconId).src = '../../common/img/featureicon_marked.gif';
                }
            }
        }
    }else{
        
    }
}

// 地図の読み込み
function mapRefresh() {
    if (!$('mapform')) {
        return false;
    }
    prevmapimageURL = $('mapimage').src;
    mask();
    var strParameters = "cmd=" + document.f.cmd.value +
                        "&scale=" + document.f.scale.value + 
                        "&scalechange=" + document.f.scalechange.value +
                        "&minx=" + document.f.minx.value + 
                        "&miny=" + document.f.miny.value + 
                        "&maxx=" + document.f.maxx.value + 
                        "&maxy=" + document.f.maxy.value + 
                        "&mainmapx=" + document.f.mainmapx.value + 
                        "&mainmapy=" + document.f.mainmapy.value + 
                        "&mapname=" + document.f.mapname.value + 
                        "&aerophotostatus=" + document.f.aerophotostatus.value +
                        "&x=" + document.f.x.value +
                        "&y=" + document.f.y.value +
                        "&fid=" + document.f.fid.value +
                        "&areacd=" + document.f.areacd.value;
      // prompt("",strParameters);
                        
    new Ajax.Request(mapscriptURL, {
        method: "get",
        parameters: strParameters ,
        requestHeaders: ['If-Modified-Since','Wed, 15 Nov 1995 00:00:00 GMT'],
        onSuccess: function(httpObj) {
            xmlDocument = httpObj.responseXML;
            $('mapimage').src = getTagValue(xmlDocument.documentElement,"mapimage");
            $('mapimage').style.visibility = 'visible';
            $('scalebarimage').src = getTagValue(xmlDocument.documentElement,"scalebarimage");
                $('legendbarimage').src = getTagValue(xmlDocument.documentElement,"legendimage");
            $('nowscalevalue').innerHTML = "1/" + getTagValue(xmlDocument.documentElement,"scale");
            $('nowscalevalue').selected = true;
            $('scale').value = getTagValue(xmlDocument.documentElement,"scale");
            $('minx').value = getTagValue(xmlDocument.documentElement,"minx");
            $('miny').value = getTagValue(xmlDocument.documentElement,"miny");
            $('maxx').value = getTagValue(xmlDocument.documentElement,"maxx");
            $('maxy').value = getTagValue(xmlDocument.documentElement,"maxy");
            $('mapname').value = getTagValue(xmlDocument.documentElement,"mapname");
            $('aerophotostatus').value = getTagValue(xmlDocument.documentElement,"aerophotostatus");
            str = 'cmd=ext' +
                  '&scale=' + getTagValue(xmlDocument.documentElement,"scale") + 
                  '&x=' + getTagValue(xmlDocument.documentElement,"centergeox") + 
                  '&y=' + getTagValue(xmlDocument.documentElement,"centergeoy") + 
                  '&mapname=' + $('mapname').value +
                  '&aerophotostatus=' + $('aerophotostatus').value +
                  '';
            if (location.search.length > 0) {
				$('mapurlstring').innerHTML = document.URL.substring(0,document.URL.indexOf(location.search)) + '?' + str;
			} else {
				$('mapurlstring').innerHTML = document.URL + '?' + str;
			}
            makeHTML();
            if (subdir == 'kankou') {
                callbackProcess(xmlDocument);
            }
        },
        onComplete: function(httpObj) {},
        onFailure: function() {unmask();},
        onException: function (httpObj) {unmask();$('showsaiName').src=prevmapimageURL;} 

    });

}

// 指定した要素エレメント中のタグの値を取得する
function getTagValue(objElements, strTagName) {
    var strValue = "";
    if (objElements.getElementsByTagName(strTagName).item(0)) {
        if (objElements.getElementsByTagName(strTagName).item(0).hasChildNodes()) {
            strValue = objElements.getElementsByTagName(strTagName).item(0).firstChild.nodeValue;
        }
    }
    return strValue;
}

// 地図上のマーカー画像の制御
function changeMarkerIcon(obj) {
    if (obj.src.indexOf("spacer.gif", 0) > -1) {
        obj.src = '../../common/img/featureicon_marked_temp.gif';
    } else if (obj.src.indexOf("featureicon_marked_temp.gif", 0) > -1) {
        obj.src = '../../common/img/spacer.gif';
    } else if (obj.src.indexOf("featureicon_marked.gif", 0) > -1) {
        obj.src = '../../common/img/featureicon_marked_mouseover.gif';
    } else if (obj.src.indexOf("featureicon_marked_mouseover.gif", 0) > -1) {
        obj.src = '../../common/img/featureicon_marked.gif';
    }
}

// HTMLを生成する
function makeHTML() {
    var elmfeaturelist = xmlDocument.getElementsByTagName("featurelist").item(0);
    strHTMLPixCoordsIcons = "";
    strHTMLFeaturesList = "";
    if (elmfeaturelist) {
         if (getTagValue(elmfeaturelist,"featurecount") > 0) {
            elmitems = elmfeaturelist.getElementsByTagName("item");
            for (i = 0; i < elmitems.length; i++) {
                strrowid = elmitems[i].getAttribute("rowid"); 
                elmattributeinfo = elmitems[i].getElementsByTagName("attributeinfo").item(0);
                elmmapscriptinfo = elmitems[i].getElementsByTagName("mapscriptinfo").item(0);
                var strOption = "";
                if ($('selMap')) {
                    if (document.f.mapname.value != "default.map") {
                        strOption = strOption + '&mapname=' + document.f.mapname.value;
                    }
                }
                if (getTagValue(xmlDocument.documentElement,"aerophotostatus") == "1") {
                    strOption = strOption + '&aerophotostatus=1';
                }
                //alert(strOption);
                if (subdir == 'kankou') {
                    strHTMLPixCoordsIcons = strHTMLPixCoordsIcons + 
                        '<a href="map.php?fid=' + getTagValue(elmattributeinfo,"fid") + strOption + '" ' + 
                        'title="' + getTagValue(elmattributeinfo,"name") + '">' +
                        '<img onmouseover="changeMarkerIcon(this);" onmouseout="changeMarkerIcon(this);" ' +
                        'name="featureicon" ' +
                        'class="featureiconimage" ' +
                        'id="featureicon' + strrowid + '" ' + 
                        'border="0" ' +
                        'src="../../common/img/spacer.gif" ' + 
                        'style="left:' + (getTagValue(elmmapscriptinfo,"pixx")-15) + ';top:' + (getTagValue(elmmapscriptinfo,"pixy")-16) + ';position:absolute;width:32px;height:32px;visibility:visible;display:block;" ' + 
                        'alt="' + getTagValue(elmattributeinfo,"name") + '">' + 
                        '</a>';
                } else {
                    strHTMLPixCoordsIcons = strHTMLPixCoordsIcons + 
                        '<a href="map.php?fid=' + getTagValue(elmattributeinfo,"filingkey") + strOption + '" ' + 
                        'title="' + getTagValue(elmattributeinfo,"name") + '">' +
                        '<img onmouseover="changeMarkerIcon(this);" onmouseout="changeMarkerIcon(this);" ' +
                        'name="featureicon" ' +
                        'class="featureiconimage" ' +
                        'id="featureicon' + strrowid + '" ' + 
                        'border="0" ' +
                        'src="../../common/img/spacer.gif" ' + 
                        'style="left:' + (getTagValue(elmmapscriptinfo,"pixx")-15) + ';top:' + (getTagValue(elmmapscriptinfo,"pixy")-16) + ';position:absolute;width:32px;height:32px;visibility:visible;display:block;" ' + 
                        'alt="' + getTagValue(elmattributeinfo,"name") + '">' + 
                        '</a>';
                    strHTMLFeaturesList = strHTMLFeaturesList + 
                        '<a href="#attributeinfo" ' + 
                        'fid="' + getTagValue(elmattributeinfo,"filingkey") + '" ' +  
                        'name="featurelistitem" class="featurelistitem" ' + 
                        'id="featurelistitem' + strrowid + '" ' + 
						'title="クリックすると 「' + getTagValue(elmattributeinfo,"name") + '」 の詳細情報を表示します。" alt="クリックすると 「' + getTagValue(elmattributeinfo,"name") + '」 の詳細情報を表示します。" ' + 
                        'onclick="showInfo(\'' + getTagValue(elmattributeinfo,"filingkey") + '\');">' + getTagValue(elmattributeinfo,"name") + '</a>';
                }
            }
        }
    }
    elmfeaturelist = xmlDocument.getElementsByTagName("otherfeaturelist").item(0);
    strOtherHTMLFeaturesList = "";
    if (elmfeaturelist) {
        if (getTagValue(elmfeaturelist,"otherfeaturecount") > 0) {
            elmitems = elmfeaturelist.getElementsByTagName("item");
            
            for (i = 0; i < elmitems.length; i++) {
                    var sss = "";
                    elmattributeinfo = elmitems[i].getElementsByTagName("attributeinfo").item(0);
                    n = elmattributeinfo.childNodes.length;
                    sss = sss + '<tr>';
                    for (j = 0 ; j < n; j++) {
                        sss = sss + '<th>' + getAliasFieldName(getTagValue(elmitems[i],"name"),elmattributeinfo.childNodes[j].tagName) + '</th>';
                    }
                    sss = sss + '</tr>';
                    sss = sss + '<tr>';
                    for (j = 0 ; j < n; j++) {
                        
                        if (getTagValue(elmattributeinfo,elmattributeinfo.childNodes[j].tagName) != "") {
                            sss = sss + '<td>' + getTagValue(elmattributeinfo,elmattributeinfo.childNodes[j].tagName) + '</td>';
                        } else {
                            sss = sss + '<td>　</td>';
                        }
                    }
                    sss = sss + '</tr>';

                if (getTagValue(elmitems[i],"name") != "公共施設" ) {
                    strOtherHTMLFeaturesList = strOtherHTMLFeaturesList + 
                        '<div class="attribute">' + 
                        '<div class="layername">' + getTagValue(elmitems[i],"name") + '</div>' + 
                        '<table border="0" cellspacing="0" cellpadding="3">' + 
                        sss + 
                        '</table>' + 
                        '</div>' + 
                        '';
                }
            }
            
            if ((getTagValue(elmfeaturelist,"otherfeaturecount") == 1) && (getTagValue(elmitems[0],"name") == "公共施設" )) {
                // strOtherHTMLFeaturesList = '<div class="attribute">みつかりませんでした</div>';
            }
        } else {
            // strOtherHTMLFeaturesList = '<div class="attribute">みつかりませんでした</div>';
        }
    }
	
}

// マップページのURLを表示
function showMapUrl() {
	if (isShowMapUrl) {
	
	    if ($('mapurlstring')) {
	        $('mapurlstring').style.visibility = 'visible';
	    }
		
		isShowMapUrl = false;
	} else {
	    if ($('mapurlstring')) {
	        $('mapurlstring').style.visibility = 'hidden';
	    }
	
		isShowMapUrl = true;
	}
}

// 属性表示のための別名を取得
function getAliasFieldName(strLayerName, strFieldName) {

    strAliasFieldName = strFieldName;

    var tempList = new Array();
    if (fieldAliasList[strLayerName]!=null) {
    
        if (fieldAliasList[strLayerName]!="") {
        
            if (fieldAliasList[strLayerName].indexOf("|")==-1) {
                var tempPair = fieldAliasList[strLayerName].split(":");
                if (tempPair[0].toUpperCase() == strFieldName.toUpperCase()) {
                    strAliasFieldName = tempPair[1];
                }
                tempPair=null;
            } else {
            
                tempList = fieldAliasList[strLayerName].split("|");
                
                for (var i=0;i<tempList.length;i++) {
                
                    var tempPair = tempList[i].split(":");
                    
                    
                    
                    if (tempPair[0].toUpperCase() == strFieldName.toUpperCase()) {
                        strAliasFieldName = tempPair[1];
                    }
                }
            }
        }
    } 

    return strAliasFieldName;
}

