﻿/* **********************************************************************************************************************
    FILE: tools.js
    DIRECTORY: scripts/map
    PROJECT: GeoEye
    DATE: June 7, 2008
    AUTHORS: Grant McKenzie
             Ryan Whitley
    DESCRIPTION: Handles the google map tool buttons (pan, point, line, polygon, extent) and their basic functionality.
********************************************************************************************************************** */

var _mapMarkerInstructions = "Place marker on map to search by point of interest";
var _mapPolyInstructions = "Draw polygon on map to search by area of interest";
var _mapPanInstructions = "Pan around the map";

var color = "#ff0000";
var mcolor = "#008C00";     //2009/08/28 Monoi 色変更 #555500->#008C00
var featureTable_;
var _listener = null;
var _areaGeoType = "";
var _mapClickListener = null;
var _polygonClosed = false; // Trigger for polygon closed or not
var _polyListener = null; //The listener for drawing a polygon
var _measureListener = null; //The listener for drawing a polygon
var _mouseMoveListener = null; //Listening for mouse move events
var _mapExtent = null; // Setting mapExtent as a global variable allows it to be enabled and disabled based on zoom level
var _envelope = null; // Envelope created by the DrawShape tool
var _polygonUpdateCount = 0;  //Hack, since resizing a polygon is adding one listener for each resize.  Cut off at 1
var _follow_marker = null; //pin that follows mouse when point tool is initially selected

var _activeTool1 = null;
var _activeTool2 = null;
var _activeToolName = "";

var latlng = null;

var warningAreaSize = 5000;

// Overlays
var _polygon = null; // Area Polygon or Area Envelove

var _measureGeo = null;
var _drawMeasureType = "0";

var _mesuereLine = new Array();
var _mesuerePath = new Array();
var _mesuereEnvelope = new Array();
var _mesuerePolygon = new Array();

var _editMeasureGeometry = null;
var _editMeasureType = null;
var _editMeasureRow = -1;
var _editMeasureListener = null;
var _editMeasureisHidden = false;

var _dynMapOv_gyosei = null; // AGS Gyosei
var _dynMapOv_kido = null; // AGS Kido
var _dynMapOv_browse = null; // AGS Browse
var _dynMapOv_image = null; // AGS Image
var _dynMapOv_grid = null; // AGS Grid line
var _dynMapOv_sdbw = null;
var _dynMapOv_sdbw2 = null;
var _polygonArea = 0; //指定された四角形・多角形の面積

var _dynMapOv_jsi = null; // JSI撮影シェープ


function clearOverlays(ovArray)
{
    for(var i = 0; i < ovArray.length; i++) {
        gmap.removeOverlay(ovArray[i]);
    }
    if (ovArray == _mesuereLine) {
        _mesuereLine = new Array();
    }
    else if (ovArray == _mesuerePath) {
        _mesuerePath = new Array();
    }
    else if (ovArray == _mesuereEnvelope) {
        _mesuereEnvelope = new Array();
    }
    else if (ovArray == _mesuerePolygon) {
        _mesuerePolygon = new Array();
    }
}

function onToolMouseOver()
{
    var tool = event.srcElement;
    if(tool != _activeTool1 && tool != _activeTool2) {
        event.srcElement.style.backgroundColor = "white";
    }
}

function onToolMouseOut()
{
    var tool = event.srcElement;
    if(tool != _activeTool1 && tool != _activeTool2) {
        event.srcElement.style.backgroundColor = "";
    }
}

function defaultMapTool()
{
    var toolMapPan = $get("tool_MapPan");
    ChangeMapTool("MapPan", toolMapPan, null);
}

function ChangeMapTool(toolName, toolCont1, toolCont2)
{
    if(_activeToolName == toolName) return false;
    
    if(_activeTool1 != null) {
        _activeTool1.style.backgroundColor = "";
    }
    if(_activeTool2 != null) {
        _activeTool2.style.backgroundColor = "";
    }
    
    _activeToolName = toolName;
    _activeTool1 = toolCont1;
    _activeTool2 = toolCont2;

    if(_activeTool1 != null) {
        _activeTool1.style.backgroundColor = "#6666aa";
    }
    if(_activeTool2 != null) {
        _activeTool2.style.backgroundColor = "#6666aa";
    }
    
    disableDrawGeometry();
    removeMeasureGeometry();
    
    switch(_activeToolName) {
        case "MapPan":
            MapPan();
            break;
        //Add_Inoue1222
        case "Area_Point":
            if (_polygon != null && _areaGeoType == "Envelope") {
                enableAreaPoint();
            } else {
                removeAreaPolygon();
                SelectClickPoint2();
            }
            changeTabIndex(1, 0);
            break;
        case "Area_Envelope":
            //onClickTab1('CLEARAREA');
            if(_polygon != null && _areaGeoType == "Envelope") {
                enableAreaEnvelope();
            } else {
                removeAreaPolygon();
                trackEnvelope();
            }
            changeTabIndex(1, 0);
            break;
        case "Area_Polygon":
            //onClickTab1('CLEARAREA');
            if(_polygon != null && _areaGeoType == "Polygon") {
                enableAreaPolygon();
            } else {
                removeAreaPolygon();
                trackPolygon();
            }
            changeTabIndex(1, 1);
            break;
        case "SelectClickPoint":
            SelectClickPoint();
            break;
        case "SelectFootPrint":
            selectFootPrint();
            break;
        case "MeasureLine":
            trackMeasureLine();
            break;
        case "MeasurePath":
            trackMeasurePath();
            break;
        case "MeasurePolygon":
            trackMeasurePolygon();
            break;
        case "MeasureEnvelope":
            trackMeasureEnvelope();
            break;
    }

}
//JSI撮影時間SHP
function onClickJSI_SHAPE(type) {
    //非表示
    if (type == '0') {
        _dynMapOv_kido.hide();
        argument = "ControlType=JSISHAPE";
        argument += "&ShpVisible=" + type;
        eval(onClickCallback_Default);
        return false;
    }

    var argument = "";

    var optDate = document.getElementById("fplJsiSatsueiJikan_radioDateFromTo");
    var Start_Date = document.getElementById("fplJsiSatsueiJikan_txtStartDate");
    var End_Date = document.getElementById("fplJsiSatsueiJikan_txtEndDate");

    var optKisetsu = document.getElementById("fplJsiSatsueiJikan_radioDateKIsetsu");
    var Start_Year = document.getElementById("fplJsiSatsueiJikan_startYear");
    var End_Year = document.getElementById("fplJsiSatsueiJikan_endYear");
    var Start_Month = document.getElementById("fplJsiSatsueiJikan_startMonth");
    var End_Month = document.getElementById("fplJsiSatsueiJikan_endMonth");

    var AngleBound = document.getElementById("fplJsiSatsueiJikan_txtAngleBound");
    var UnryoBound = document.getElementById("fplJsiSatsueiJikan_txtUnryoBound");


    //2011/03/29 Add エラーチェック
    var numSYear = '';
    var numEYear = '';
    var numSMonth = '';
    var numEMonth = '';
    if (optDate.checked == true) {
        var array;
        array = Start_Date.value.split('/');
        if ((array.length != 3) || !isDate(array[0], array[1], array[2])) {
            alert("開始日付が不正です。");
            return false;
        }
        array = End_Date.value.split('/');
        if ((array.length != 3) || !isDate(array[0], array[1], array[2])) {
            alert("終了日付が不正です。");
            return false;
        }
    }
    else if (optKisetsu.checked == true) {
        //開始月
        numSMonth = Math.floor(Number(Start_Month.value));
        if (!isNaN(numSMonth) && 1 <= numSMonth && numSMonth <= 12) {
            Start_Month.value = numSMonth;
        }
        else {
            alert("開始月が不正です。");
            return false;
        }
        //終了月
        numEMonth = Math.floor(Number(End_Month.value));
        if (!isNaN(numEMonth) && 1 <= numEMonth && numEMonth <= 12) {
            End_Month.value = numEMonth;
        }
        else {
            alert("終了月が不正です。");
            return false;
        }
        //開始年
        if (Start_Year.value == '') {
            numSYear = 1999;
        }
        else {
            numSYear = Math.floor(Number(Start_Year.value));
            if (isNaN(numSYear)) {
                alert("開始年が不正です。");
                return false;
            }
            else {
                Start_Year.value = numSYear;
            }
        }
        //終了年
        if (End_Year.value == '') {
            var now = new Date();
            numEYear = now.getYear();
        }
        else {
            numEYear = Math.floor(Number(End_Year.value));
            if (isNaN(numEYear)) {
                alert("終了年が不正です。");
                return false;
            }
            else if (numEYear < numSYear) {
                alert("開始年または終了年が不正です。");
                return false;
            }
            else {
                End_Year.value = numEYear;
            }
        }
    }        
    else {
        alert("日付指定方法が選択されていません。");
        return false;
    }
    //2011/03/29 Add End エラーチェック

    //衛星軌道を表示
    argument = "ControlType=JSISHAPE";
    argument += "&ShpVisible=" + type;
    if (optDate.checked == true) {
        argument += "&optDate=1";
    }
    else {
        argument += "&optDate=0";
    }
    argument += "&Start_Date=" + Start_Date.value;
    argument += "&End_Date=" + End_Date.value;
    if (optKisetsu.checked == true) {
        argument += "&optKisetsu=1";
    }
    else {
        argument += "&optKisetsu=0";
    }
    argument += "&Start_Year=" + numSYear;
    argument += "&End_Year=" + numEYear;
    argument += "&Start_Month=" + numSMonth;
    argument += "&End_Month=" + numEMonth;
    argument += "&AngleBound=" + AngleBound.value;
    argument += "&UnryoBound=" + UnryoBound.value;
    eval(onClickCallback_Default);

    return false;
}


function selectFootPrint()
{
    _mapClickListener = GEvent.addListener(gmap, "click", function(overlay, latlng) {
        var argument = "";
        argument = "Control=MAPSELECT";
        if(latlng == undefined) {
            var latlng = gmap.fromContainerPixelToLatLng(new GPoint(event.x,event.y));
        }
        argument += "&X=" + latlng.x.toString();
        argument += "&Y=" + latlng.y.toString();
        eval(onClickCallback_tab2);
    });
}
function SelectClickPoint()
{
    _mapClickListener = GEvent.addListener(gmap, "click", function(overlay, latlng) {
        var argument = "";
        argument = "Control=ClickPoint";
        if (latlng == undefined) {
            var latlng = gmap.fromContainerPixelToLatLng(new GPoint(event.x, event.y));
        }
        argument += "&X=" + latlng.x.toString();
        argument += "&Y=" + latlng.y.toString();

        var txt1 = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data1");
        var txt2 = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data2");

        var txt51 = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data3_1");
        var txt52 = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data3_2");
        var txt53 = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data3_3");

        var txt61 = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data4_1");
        var txt62 = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data4_2");
        var txt63 = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data4_3");

        var lat1 = 0;
        var lat2 = 0;
        var lat3 = 0;

        waitOperation(true);

        //2010/11/22 Rev 丸め処理共通化
        //txt1.value = Math.floor(Number(latlng.x.toString()) * 10000);
        //txt1.value = (Number(txt1.value) / 10000);
        //txt2.value = Math.floor(Number(latlng.y.toString()) * 10000);
        //txt2.value = (Number(txt2.value) / 10000);
        txt1.value = roundPoint(Number(latlng.x.toString()));
        txt2.value = roundPoint(Number(latlng.y.toString()));
        //2010/11/22 Rev End 丸め処理共通化

        //2010/11/24 Rev 処理を共通化
        //lat1 = Math.floor(Number(txt1.value));
        //lat2 = Math.floor((Number(txt1.value) * 60) % 60);
        //lat3 = Math.round((Number(txt1.value) * 3600) % 60);
        //txt51.value = lat1.toString();
        //txt52.value = lat2.toString();
        //txt53.value = lat3.toString();
        if (!setDMS(txt1, txt51, txt52, txt53, false)) {
            txt51.value = "";
            txt52.value = "";
            txt53.value = "";
        }
        //2010/11/24 Rev End 処理を共通化


        //2010/11/24 Rev 処理を共通化
        //lat1 = Math.floor(Number(txt2.value));
        //lat2 = Math.floor((Number(txt2.value) * 60) % 60);
        //lat3 = Math.round((Number(txt2.value) * 3600) % 60);
        //txt61.value = lat1.toString();
        //txt62.value = lat2.toString();
        //txt63.value = lat3.toString();
        if (!setDMS(txt2, txt61, txt62, txt63, true)) {
            txt61.value = "";
            txt62.value = "";
            txt63.value = "";
        }
        //2010/11/24 Rev End 処理を共通化

        var opt1 = document.getElementById("tab1_optSize1");
        var opt2 = document.getElementById("tab1_optSize2");
        var cbo1 = document.getElementById("cboYosi");
        var cbo2 = document.getElementById("cboDirect");
        var txt5 = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtScale");

        var height = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtheight")
        var width = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtwidth")

        if (opt1.checked == true) {
            argument += "&TYPE=1";
            argument += "&WIDTH=" + width.value.toString();
            argument += "&HEIGHT=" + height.value.toString();
        }
        else {
            argument += "&TYPE=2";
            argument += "&PAPER=" + cbo1.selectedIndex;
            argument += "&DIRECT=" + cbo2.selectedIndex;
            argument += "&SCALE=" + txt5.value.toString();
        }

        eval(onClickCallback_tab1);

    });
}

var _pinMarker = null;

//Add_Inoue1222
function SelectClickPoint2() {
    _mapClickListener = GEvent.addListener(gmap, "click", function(overlay, latlng) {
        //        var argument = "";
        //        argument = "Control=ClickPoint";
        if (latlng == undefined) {
            var latlng = gmap.fromContainerPixelToLatLng(new GPoint(event.x, event.y));
        }

        ClearBrowsePoly();

        //2010/11/17 Add 選択枠の削除
        if (selectPoly != null) {
            for (var i = 0; i < selectPoly.length; i++) {
                gmap.removeOverlay(selectPoly[i]);
            }
        }
        //2010/11/17 Add End 選択枠の削除

        //2010.11.30 fuchi ピンポイントを表示
        if (_pinMarker != null) {
            gmap.removeOverlay(_pinMarker);
        }
        var pin_icon = new GIcon();
        pin_icon.image = "./images/icon_pin.png";
        pin_icon.iconSize = new GSize(20, 20);
        pin_icon.iconAnchor = new GPoint(20, 20);        
        var opt1 = { icon: pin_icon };
        var marker = new GMarker(latlng, opt1);
        gmap.addOverlay(marker);
        _pinMarker = marker;

        var txt1 = document.getElementById("ucTab21_TabContainer1_TabPanel1_txtStartDate");
        var txt2 = document.getElementById("ucTab21_TabContainer1_TabPanel1_txtEndDate");
        var txt3 = document.getElementById("ucTab21_TabContainer1_TabPanel1_txtAngleBound");
        var txt4 = document.getElementById("ucTab21_TabContainer1_TabPanel1_txtUnryoBound");
        var txt5 = document.getElementById("ucTab21_TabContainer1_TabPanel1_startYear");
        var txt6 = document.getElementById("ucTab21_TabContainer1_TabPanel1_endYear");
        var txt7 = document.getElementById("ucTab21_TabContainer1_TabPanel1_startMonth");
        var txt8 = document.getElementById("ucTab21_TabContainer1_TabPanel1_endMonth");
        var opt1 = document.getElementById("ucTab21_TabContainer1_TabPanel1_radioDateFromTo");
        var opt2 = document.getElementById("ucTab21_TabContainer1_TabPanel1_radioDateKIsetsu");
        //コールバック
        var argument = "Control=SEARCH2";
        argument += "&TARGET=ucTab21_TabContainer1_TabPanel2_tab2div1";
        argument += "&StartDate=" + txt1.value;
        argument += "&EndDate=" + txt2.value;
        argument += "&AngleBound=" + txt3.value;
        argument += "&UnryoBound=" + txt4.value;
        argument += "&startYear=" + txt5.value;
        argument += "&endYear=" + txt6.value;
        argument += "&startMonth=" + txt7.value;
        argument += "&endMonth=" + txt8.value;
        argument += "&DateFromTo=" + opt1.checked;
        argument += "&DateKisetsu=" + opt2.checked;

        argument += "&X=" + latlng.x.toString();
        argument += "&Y=" + latlng.y.toString();

        tab2tbldiv = null;
        waitOperation(true);
        eval(onClickCallback_tab2);
    });
}

//End

function ClearAreaSearch()
{
    ClearStripPoly();
    ClearBrowsePoly();
    //setTimeout("_dynMapOv_browse.refresh();",500);
}

function ClearAll()
{
    clsSession();
    disableDrawGeometry();
    removeAreaPolygon();
    ClearAreaSearch();
    if(selectPoly != null) {
        for(var i = 0; i < selectPoly.length; i++) {
            gmap.removeOverlay(selectPoly[i]);
        }
    }
    
    _polygonArea = 0;
    
    defaultMapTool();
    
    var div = null;
    var hdiv = null;
    var txt = null;
    var cbo = null;
    
    if(_tab0resultMarker != null){
        gmap.removeOverlay(_tab0resultMarker);
        _tab0resultMarker = null;
    }
    //2010.11.30 fuchi
    if (_pinMarker != null) {
        gmap.removeOverlay(_pinMarker);
        _pinMarker = null;
    }
    document.getElementById("warningAreaSize").style.display = "none";
    
    //tab1四角形TABクリア
    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel1_ucTableView1_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel1_ucTableView1_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel1_ucTableView1");
    cbo = document.getElementById("tab1_cboZahyo1");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area1('0');
    }

    //tab1多角形TABクリア
    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView2_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView2_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel2_ucTableView2");

    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView3_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView3_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel2_ucTableView3");

    cbo = document.getElementById("tab1_cboZahyo2");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area2('0');
    }

    //tab1サイズ指定TAB/座標値指定TABクリア 
    txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtheight");
    if(txt != null){
        txt.value = "";
    }
    txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtwidth");
    if(txt != null){
        txt.value = "";
    }

    var i = 0;
    for(i = 1; i <= 2; i++){
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel4_txtZahyo2_Data" + i);
        if(txt != null){
            txt.value = "";
        }
    }

    for(i = 1; i <= 3; i++){
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data3_" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data4_" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel4_txtZahyo2_Data3_" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel4_txtZahyo2_Data4_" + i);
        if(txt != null){
            txt.value = "";
        }
    }

    cbo = document.getElementById("tab1_cboZahyo3");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area3('0');
    }
    cbo = document.getElementById("tab1_cboZahyo4");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area4('0');
    }
    
    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView4_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView4_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel4_ucTableView4");

    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView5_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView5_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel4_ucTableView5");

    //tab1市区町村TABクリア
    var btn = document.getElementById("tab1chkBtn_1");
    if(btn != null){
        btn.src="images/GridIcon/Check_ON.gif";
    }
    btn = document.getElementById("tab1chkBtn_2");
    if(btn != null){
        btn.src="images/GridIcon/Check_ON.gif";
    }
    txt = document.getElementById("ucTab11_TabContainer1_TabPanel5_tab1txtSearch");
    if(txt != null){
        txt.value = "";
    }
    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel5_ucTableView6_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel5_ucTableView6_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    cbo = document.getElementById("SelectTodofuke");
    if(cbo != null){
        cbo.selectedIndex = 0;
    }

    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel5_ucTableView6");

    hdiv = document.getElementById("ucTab21_TabContainer1_TabPanel2_ucTableView1_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab21_TabContainer1_TabPanel2_ucTableView1_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab21_TabContainer1_TabPanel2_ucTableView1");

    hdiv = document.getElementById("ucTab21_TabContainer1_TabPanel2_ucTableView2_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab21_TabContainer1_TabPanel2_ucTableView2_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab21_TabContainer1_TabPanel2_ucTableView2");

    //tab2検索TAB
    //2011/01/27 Add
    cbo = document.getElementById("ucTab21_TabContainer1_TabPanel1_cboDateType");
    if (cbo != null) {
        cbo.selectedIndex = 0;
    }
    cbo = document.getElementById("ucTab21_TabContainer1_TabPanel1_cboYear");
    if (cbo != null) {
        cbo.style.display = "none";
    }
    //2011/01/27 Add End
    
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_txtStartDate");
    if (txt != null) {
        //2010/12/01 Rev
        //txt.value = "2000/01/01";
        var d = new Date();
        txt.value = d.getFullYear() + "/01/01";
        //2010/12/01 Rev End
    }
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_txtEndDate");
    if(txt != null){
        var now = new Date();
        var year = now.getYear(); // 年
        var month = now.getMonth() + 1; // 月
        var day = now.getDate(); // 日
        if(month < 10) { month = "0" + month; }
        if(day < 10) { day = "0" + day; }
        txt.value = year + "/" + month + "/" + day;
    }
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_startYear");
    if(txt != null){
        txt.value = "";
    }
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_startYear");
    if(txt != null){
        txt.value = "";
    }
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_endYear");
    if(txt != null){
        txt.value = "";
    }
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_startMonth");
    if(txt != null){
        txt.value = "";
    }
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_endMonth");
    if(txt != null){
        txt.value = "";
    }
    
    //_dynMapOv_gyosei.hide();

    //2010/12/06 Rev 撮影角度　雲量初期値
    //$find("ucTab21_TabContainer1_TabPanel1_SliderExtender1").set_Value("50");
    //$find("ucTab21_TabContainer1_TabPanel1_SliderExtender2").set_Value("30");
    $find("ucTab21_TabContainer1_TabPanel1_SliderExtender1").set_Value("0");
    $find("ucTab21_TabContainer1_TabPanel1_SliderExtender2").set_Value("100");
    //2010/12/06 Rev End
    
    HeaderMessage.innerHTML ="";
    _polygonArea = 0;
    setTimeout("_dynMapOv_browse.refresh();",200);
    
}

function ClearAll2_Wait()
{
    window.setTimeout("ClearAll2();",100);
}

function ClearAll2()
{
 //   clsSession();
    disableDrawGeometry();
    removeAreaPolygon();
    ClearAreaSearch();
    if(selectPoly != null) {
        for(var i = 0; i < selectPoly.length; i++) {
            gmap.removeOverlay(selectPoly[i]);
        }
    }
    _polygonArea = 0;
    
    defaultMapTool();
    
    var div = null;
    var txt = null;
    var cbo = null;
    
    document.getElementById("warningAreaSize").style.display = "none";

    //tab1四角形TABクリア
    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel1_ucTableView1_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel1_ucTableView1_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel1_ucTableView1");
    cbo = document.getElementById("tab1_cboZahyo1");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area1('0');
    }

    //tab1多角形TABクリア
    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView2_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView2_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel2_ucTableView2");

    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView3_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView3_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel2_ucTableView3");

    cbo = document.getElementById("tab1_cboZahyo2");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area2('0');
    }

    //tab1サイズ指定TAB/座標値指定TABクリア 
    txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtheight");
    if(txt != null){
        txt.value = "";
    }
    txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtwidth");
    if(txt != null){
        txt.value = "";
    }

    var i = 0;
    for(i = 1; i <= 2; i++){
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel4_txtZahyo2_Data" + i);
        if(txt != null){
            txt.value = "";
        }
    }

    for(i = 1; i <= 3; i++){
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data3_" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data4_" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel4_txtZahyo2_Data3_" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel4_txtZahyo2_Data4_" + i);
        if(txt != null){
            txt.value = "";
        }
    }

    cbo = document.getElementById("tab1_cboZahyo3");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area3('0');
    }
    cbo = document.getElementById("tab1_cboZahyo4");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area4('0');
    }
    
    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView4_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView4_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel4_ucTableView4");

    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView5_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView5_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel4_ucTableView5");

    //tab1市区町村TABクリア
    var btn = document.getElementById("tab1chkBtn_1");
    if(btn != null){
        btn.src="images/GridIcon/Check_ON.gif";
    }
    btn = document.getElementById("tab1chkBtn_2");
    if(btn != null){
        btn.src="images/GridIcon/Check_ON.gif";
    }
    txt = document.getElementById("ucTab11_TabContainer1_TabPanel5_tab1txtSearch");
    if(txt != null){
        txt.value = "";
    }
    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel5_ucTableView6_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel5_ucTableView6_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    cbo = document.getElementById("SelectTodofuke");
    if(cbo != null){
        cbo.selectedIndex = 0;
    }

    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel5_ucTableView6");

    hdiv = document.getElementById("ucTab21_TabContainer1_TabPanel2_ucTableView1_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab21_TabContainer1_TabPanel2_ucTableView1_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab21_TabContainer1_TabPanel2_ucTableView1");

    hdiv = document.getElementById("ucTab21_TabContainer1_TabPanel2_ucTableView2_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標','経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標','緯度');
    div = document.getElementById("ucTab21_TabContainer1_TabPanel2_ucTableView2_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab21_TabContainer1_TabPanel2_ucTableView2");
    
    //tab2検索TAB
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_txtStartDate");
    if(txt != null){
        //2010/12/01 Rev
        //txt.value = "2000/01/01";
        var d = new Date();
        txt.value = d.getFullYear() + "/01/01";
        //2010/12/01 Rev End
    }
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_txtEndDate");
    if(txt != null){
        var now = new Date();
        var year = now.getYear(); // 年
        var month = now.getMonth() + 1; // 月
        var day = now.getDate(); // 日
        if(month < 10) { month = "0" + month; }
        if(day < 10) { day = "0" + day; }
        txt.value = year + "/" + month + "/" + day;
    }
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_startYear");
    if(txt != null){
        txt.value = "";
    }
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_startYear");
    if(txt != null){
        txt.value = "";
    }
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_endYear");
    if(txt != null){
        txt.value = "";
    }
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_startMonth");
    if(txt != null){
        txt.value = "";
    }
    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_endMonth");
    if(txt != null){
        txt.value = "";
    }
    
    //_dynMapOv_gyosei.hide();
    
    //2010/12/06 Rev 撮影角度　雲量初期値
    //$find("ucTab21_TabContainer1_TabPanel1_SliderExtender1").set_Value("50");
    //$find("ucTab21_TabContainer1_TabPanel1_SliderExtender2").set_Value("30");
    $find("ucTab21_TabContainer1_TabPanel1_SliderExtender1").set_Value("0");
    $find("ucTab21_TabContainer1_TabPanel1_SliderExtender2").set_Value("100");
    //2010/12/06 Rev End
        
    HeaderMessage.innerHTML ="";
    _polygonArea = 0;
    setTimeout("_dynMapOv_browse.refresh();",200);
    setTimeout("waitOperation(false);",1000);
}

function ClearAreaSelect_Tab1()
{
    disableDrawGeometry();
    removeAreaPolygon();
    
    defaultMapTool();
    
    var div = null;
    var txt = null;
    var cbo = null;

    document.getElementById("warningAreaSize").style.display = "none";

//    //tab1四角形TABクリア
//    div = document.getElementById("ucTab11_TabContainer1_TabPanel1_ucTableView1_tbldiv");
//    if(div != null){
//        div.innerHTML = "";
//    }

//    cbo = document.getElementById("tab1_cboZahyo1");
//    if(cbo != null){
//        cbo.selectedIndex = 0;
//        changeZahyo_Area1('0');
//    }

//    //tab1多角形TABクリア
//    div = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView2_tbldiv");
//    if(div != null){
//        div.innerHTML = "";
//    }

//    div = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView3_tbldiv");
//    if(div != null){
//        div.innerHTML = "";
//    }



    var div = null;
    var hdiv = null;
    var txt = null;
    var cbo = null;


    //tab1四角形TABクリア
    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel1_ucTableView1_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標', '経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標', '緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel1_ucTableView1_tbldiv");
    if (div != null) {
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel1_ucTableView1");
    cbo = document.getElementById("tab1_cboZahyo1");
    if (cbo != null) {
        cbo.selectedIndex = 0;
        changeZahyo_Area1('0');
    }

    //tab1多角形TABクリア
    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView2_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標', '経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標', '緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView2_tbldiv");
    if (div != null) {
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel2_ucTableView2");

    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView3_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標', '経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標', '緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView3_tbldiv");
    if (div != null) {
        div.innerHTML = "";
    }

    cbo = document.getElementById("tab1_cboZahyo3");
    if (cbo != null) {
        cbo.selectedIndex = 0;
        changeZahyo_Area3('0');
    }
    cbo = document.getElementById("tab1_cboZahyo4");
    if (cbo != null) {
        cbo.selectedIndex = 0;
        changeZahyo_Area4('0');
    }

    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView4_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標', '経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標', '緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView4_tbldiv");
    if (div != null) {
        div.innerHTML = "";
    }
    //セッションクリア
    //clsSession("ucTab11_TabContainer1_TabPanel4_ucTableView4");

    hdiv = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView5_headdiv");
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｘ座標', '経度');
    hdiv.innerHTML = hdiv.innerHTML.toString().replace('Ｙ座標', '緯度');
    div = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView5_tbldiv");
    if (div != null) {
        div.innerHTML = "";
    }




    cbo = document.getElementById("tab1_cboZahyo2");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area2('0');
    }

    //tab1サイズ指定TAB/座標値指定TABクリア 
    txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtheight");
    if(txt != null){
        txt.value = "";
    }
    txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtwidth");
    if(txt != null){
        txt.value = "";
    }

    var i = 0;
    for(i = 1; i <= 2; i++){
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel4_txtZahyo2_Data" + i);
        if(txt != null){
            txt.value = "";
        }
    }

    for(i = 1; i <= 3; i++){
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data3_" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data4_" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel4_txtZahyo2_Data3_" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel4_txtZahyo2_Data4_" + i);
        if(txt != null){
            txt.value = "";
        }
    }

    cbo = document.getElementById("tab1_cboZahyo3");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area3('0');
    }
    cbo = document.getElementById("tab1_cboZahyo4");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area4('0');
    }
    
    div = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView4_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }

    div = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView5_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }

    //tab1市区町村TABクリア
    var btn = document.getElementById("tab1chkBtn_1");
    if(btn != null){
        btn.src="images/GridIcon/Check_ON.gif";
    }
    btn = document.getElementById("tab1chkBtn_2");
    if(btn != null){
        btn.src="images/GridIcon/Check_ON.gif";
    }
    txt = document.getElementById("ucTab11_TabContainer1_TabPanel5_tab1txtSearch");
    if(txt != null){
        txt.value = "";
    }
    cbo = document.getElementById("SelectTodofuke");
    if(cbo != null){
        cbo.selectedIndex = 0;
    }
    div = document.getElementById("ucTab11_TabContainer1_TabPanel5_ucTableView6_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }

//    div = document.getElementById("ucTab21_TabContainer1_TabPanel2_ucTableView1_tbldiv");
//    if(div != null){
//        div.innerHTML = "";
//    }
//    //セッションクリア
//    clsSession("ucTab21_TabContainer1_TabPanel2_ucTableView1");

//    div = document.getElementById("ucTab21_TabContainer1_TabPanel2_ucTableView2_tbldiv");
//    if(div != null){
//        div.innerHTML = "";
//    }
//    //セッションクリア
//    clsSession("ucTab21_TabContainer1_TabPanel2_ucTableView2");
//    
//    //tab2検索TAB
//    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_txtStartDate");
//    if(txt != null){
//        txt.value = "2000/01/01";
//    }   
//    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_txtEndDate");
//    if(txt != null){
//        var now = new Date();
//        var year = now.getYear(); // 年
//        var month = now.getMonth() + 1; // 月
//        var day = now.getDate(); // 日
//        if(month < 10) { month = "0" + month; }
//        if(day < 10) { day = "0" + day; }
//        txt.value = year + "/" + month + "/" + day;
//    }
//    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_startYear");
//    if(txt != null){
//        txt.value = "";
//    }
//    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_startYear");
//    if(txt != null){
//        txt.value = "";
//    }
//    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_endYear");
//    if(txt != null){
//        txt.value = "";
//    }
//    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_startMonth");
//    if(txt != null){
//        txt.value = "";
//    }
//    txt = document.getElementById("ucTab21_TabContainer1_TabPanel1_endMonth");
//    if(txt != null){
//        txt.value = "";
//    }
//    
//    $find("ucTab21_TabContainer1_TabPanel1_SliderExtender1").set_Value("50");
//    $find("ucTab21_TabContainer1_TabPanel1_SliderExtender2").set_Value("30");
}
function ClearArea_Tab1()
{
    disableDrawGeometry();
    removeAreaPolygon();
    var div = null;
    var txt = null;
    var cbo = null;
    
    //tab1四角形TABクリア
    div = document.getElementById("ucTab11_TabContainer1_TabPanel1_ucTableView1_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }

    cbo = document.getElementById("tab1_cboZahyo1");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area1('0');
    }

    //tab1多角形TABクリア
    div = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView2_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }

    div = document.getElementById("ucTab11_TabContainer1_TabPanel2_ucTableView3_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }

    cbo = document.getElementById("tab1_cboZahyo2");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area2('0');
    }

    //tab1サイズ指定TAB/座標値指定TABクリア 
    txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtheight");
    if(txt != null){
        txt.value = "";
    }
    txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtwidth");
    if(txt != null){
        txt.value = "";
    }

    var i = 0;
    for(i = 1; i <= 2; i++){
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel4_txtZahyo2_Data" + i);
        if(txt != null){
            txt.value = "";
        }
    }

    for(i = 1; i <= 3; i++){
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data3_" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel3_txtZahyo1_Data4_" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel4_txtZahyo2_Data3_" + i);
        if(txt != null){
            txt.value = "";
        }
        txt = document.getElementById("ucTab11_TabContainer1_TabPanel4_txtZahyo2_Data4_" + i);
        if(txt != null){
            txt.value = "";
        }
    }

    cbo = document.getElementById("tab1_cboZahyo3");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area3('0');
    }
    cbo = document.getElementById("tab1_cboZahyo4");
    if(cbo != null){
        cbo.selectedIndex = 0;
        changeZahyo_Area4('0');
    }
    
    div = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView4_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }

    div = document.getElementById("ucTab11_TabContainer1_TabPanel4_ucTableView5_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }

    //tab1市区町村TABクリア
    var btn = document.getElementById("tab1chkBtn_1");
    if(btn != null){
        btn.src="images/GridIcon/Check_ON.gif";
    }
    btn = document.getElementById("tab1chkBtn_2");
    if(btn != null){
        btn.src="images/GridIcon/Check_ON.gif";
    }
    txt = document.getElementById("ucTab11_TabContainer1_TabPanel5_tab1txtSearch");
    if(txt != null){
        txt.value = "";
    }
    cbo = document.getElementById("SelectTodofuke");
    if(cbo != null){
        cbo.selectedIndex = 0;
    }
    div = document.getElementById("ucTab11_TabContainer1_TabPanel5_ucTableView6_tbldiv");
    if(div != null){
        div.innerHTML = "";
    }

}

function changeAreaEnvelope(pnts)
{
    removeAreaPolygon();
    _polygon = new GPolygon(pnts, "#ff0000", 2, 0.7, null, 0);
    gmap.addOverlay(_polygon);
    _areaGeoType = "Envelope";
//    displayAreaInfo(_polygon);
    if(_activeToolName == "Area_Envelope") {
        enableAreaEnvelope();
    }
}

function changeAreaEnvelope2(pnts, calcArea)
{
    removeAreaPolygon();
    _polygon = new GPolygon(pnts, "#ff0000", 2, 0.7, null, 0);
    gmap.addOverlay(_polygon);
    _areaGeoType = "Envelope";
    if(calcArea == true) {
        displayAreaInfo(_polygon);
    }
    if(_activeToolName == "Area_Envelope") {
        enableAreaEnvelope();
    }
}

function changeAreaPolygon(pnts)
{
    removeAreaPolygon();
    _polygon = new GPolygon(pnts, "#ff0000", 2, 0.7, null, 0);
    gmap.addOverlay(_polygon);
    _areaGeoType = "Polygon";
    
    //2010.11.26 fuchi 面積計算はサーバ側で行う
    //displayAreaInfo(_polygon);
    if(_activeToolName == "Area_Polygon") {
        enableAreaPolygon();
    }
}
function changeAreaPolygon_Rect(pnts) {
    removeAreaPolygon();
    _polygon = new GPolygon(pnts, "#ff0000", 2, 0.7, null, 0);
    gmap.addOverlay(_polygon);
    //ADD 2011.02.10 EXDKAZU START
    _areaGeoType = "Envelope";
    //ADD 2011.02.10 EXDKAZU END

    //2010.11.26 fuchi 面積計算はサーバ側で行う
    //displayAreaInfo(_polygon);
    if (_activeToolName == "Area_Polygon") {
        enableAreaPolygon();
    }
}
function changeAreaPolygon2(pnts, calcArea) {
    removeAreaPolygon();
    _polygon = new GPolygon(pnts, "#ff0000", 2, 0.7, null, 0);
    gmap.addOverlay(_polygon);
    _areaGeoType = "Polygon";
    if (calcArea == true) {
        displayAreaInfo(_polygon);
    }
    if (_activeToolName == "Area_Polygon") {
        enableAreaPolygon();
    }
}
function removeAreaPolygon()
{
    if(_mapClickListener != null) {
         GEvent.removeListener(_mapClickListener);
        _mapClickListener = null;
    }
    if(_polyListener != null) {
        GEvent.removeListener(_polyListener);
        _polyListener = null;
    }
    if (_polygon != null) {
        disableDrawGeometry();
        gmap.removeOverlay(_polygon);
        if(_mapClickListener != null) {
            GEvent.removeListener(_mapClickListener);
            _mapClickListener = null;
        }
        _polygon = null;
        _polygonBefore = null;
    }
    //2011/03/29 Add
    if (_pinMarker != null) {
        gmap.removeOverlay(_pinMarker);
        _pinMarker = null;
    }
    //2011/03/29 Add End
}

function removeMeasureGeometry()
{
    if(_mapClickListener != null) {
         GEvent.removeListener(_mapClickListener);
        _mapClickListener = null;
    }
    if(_measureListener != null) {
        GEvent.removeListener(_measureListener);
        _measureListener = null;
    }
    if (_measureGeo != null) {
        disableDrawGeometry();
        gmap.removeOverlay(_measureGeo);
        if(_mapClickListener != null) {
            GEvent.removeListener(_mapClickListener);
            _mapClickListener = null;
        }
        _measureGeo = null;
    }
}

function disableDrawGeometry()
{
    if(_mapClickListener != null) {
         GEvent.removeListener(_mapClickListener);
        _mapClickListener = null;
    }
    if(_polyListener != null) {
        GEvent.removeListener(_polyListener);
        _polyListener = null;
    }
    if(_measureListener != null) {
        GEvent.removeListener(_measureListener);
        _measureListener = null;
    }
    if (_polygon != null) {
        _polygon.disableEditing({onEvent: "mouseover"});
        _polygon.disableEditing();
        GEvent.clearInstanceListeners(_polygon);
    }
    if (_measureGeo != null) {
        _measureGeo.disableEditing({onEvent: "mouseover"});
        _measureGeo.disableEditing();
        GEvent.clearInstanceListeners(_measureGeo);
    }
}

//Add_Inoue1222
function enableAreaPoint() {
    if (_polygon != null) {
        _polyListener = GEvent.bind(_polygon, "lineupdated", null, onUpdateAreaPolygon);
        _polygon.enableEditing({ onEvent: "mouseover" });
    }
}
//end

function enableAreaPolygon()
{
    if(_polygon != null) {
        _polyListener = GEvent.bind(_polygon, "lineupdated", null, onUpdateAreaPolygon);
        _polygon.enableEditing({onEvent: "mouseover"});
    }
}

function enableAreaEnvelope()
{
    if(_polygon != null) {
        _polyListener = GEvent.bind(_polygon, "lineupdated", null, onUpdateAreaEnvelope);
        _polygon.enableEditing({onEvent: "mouseover",maxVertices : 4});
    }
}

function setEditMeasureGeometry(pnts,type,row)
{
    _editMeasureType = type;
    _editMeasureRow = row;
    
    clearEditMeasureGeometry();

    defaultMapTool();

    switch(_editMeasureType) {
    case "Line":
        _editMeasureisHidden = _mesuereLine[_editMeasureRow].isHidden();
        _editMeasureGeometry = new GPolyline(pnts, "#EE8228", 2, 0.7);
        gmap.addOverlay(_editMeasureGeometry);
        _editMeasureListener = GEvent.bind(_editMeasureGeometry, "lineupdated", null, onUpdateMeasure);
        _editMeasureGeometry.enableEditing({onEvent: "mouseover",maxVertices : 2});
        _mesuereLine[_editMeasureRow].hide();
        break;
    case "Path":
        _editMeasureisHidden = _mesuerePath[_editMeasureRow].isHidden();
        _editMeasureGeometry = new GPolyline(pnts, "#EE8228", 2, 0.7);
        gmap.addOverlay(_editMeasureGeometry);
        _editMeasureListener = GEvent.bind(_editMeasureGeometry, "lineupdated", null, onUpdateMeasure);
        _editMeasureGeometry.enableEditing({onEvent: "mouseover"});
        _mesuerePath[_editMeasureRow].hide();
        break;
    case "Polygon":
        _editMeasureisHidden = _mesuerePolygon[_editMeasureRow].isHidden();
        _editMeasureGeometry = new GPolygon(pnts, "#EE8228", 2, 0.7, null, 0);
        gmap.addOverlay(_editMeasureGeometry);
        _editMeasureListener = GEvent.bind(_editMeasureGeometry, "lineupdated", null, onUpdateMeasure);
        _editMeasureGeometry.enableEditing({onEvent: "mouseover"});
        _mesuerePolygon[_editMeasureRow].hide();
        break;
    case "Envelope":
        _editMeasureisHidden = _mesuereEnvelope[_editMeasureRow].isHidden();
        _editMeasureGeometry = new GPolygon(pnts, "#EE8228", 2, 0.7, null, 0);
        gmap.addOverlay(_editMeasureGeometry);
        _editMeasureListener = GEvent.bind(_editMeasureGeometry, "lineupdated", null, onUpdateMeasure);
        _editMeasureGeometry.enableEditing({onEvent: "mouseover",maxVertices : 4});
        _mesuereEnvelope[_editMeasureRow].hide();
        break;
    }
}

function onUpdateMeasure()
{
    var pnts = new Array();
    for(var i = 0; i < _editMeasureGeometry.getVertexCount(); i++) {
        pnts.push(_editMeasureGeometry.getVertex(i));
    }

    var rrr = 0;
    var geo;
    var tyoe;
    
    switch(_editMeasureType) {
    case "Line":
        geo = new GPolyline(pnts, mcolor, 2, 0.7);
        geo.hide();
        gmap.addOverlay(geo);
        gmap.removeOverlay(_mesuereLine[_editMeasureRow]);
        _mesuereLine[_editMeasureRow] = geo;
        rrr = geo.getLength();
        type = 1;
        break;
    case "Path":
        geo = new GPolyline(pnts, mcolor, 2, 0.7);
        geo.hide();
        gmap.addOverlay(geo);
        gmap.removeOverlay(_mesuerePath[_editMeasureRow]);
        _mesuerePath[_editMeasureRow] = geo;
        rrr = geo.getLength();
        type = 2;
        break;
    case "Polygon":
        geo = new GPolygon(pnts, mcolor, 2, 0.7, null, 0);
        geo.hide();
        gmap.addOverlay(geo);
        gmap.removeOverlay(_mesuerePolygon[_editMeasureRow]);
        _mesuerePolygon[_editMeasureRow] = geo;
        rrr = geo.getArea();
        type = 3;
        break;
    case "Envelope":
        geo = new GPolygon(pnts, mcolor, 2, 0.7, null, 0);
        geo.hide();
        gmap.addOverlay(geo);
        gmap.removeOverlay(_mesuereEnvelope[_editMeasureRow]);
        _mesuereEnvelope[_editMeasureRow] = geo;
        rrr = geo.getArea();
        type = 4;
        break;
    }
    
    var s = new Sys.StringBuilder();
    var verCount = geo.getVertexCount();
    s.append("" + geo.getVertex(0).x + "," + geo.getVertex(0).y);
    for(var i = 1; i < verCount; i++) {
        s.append("," + geo.getVertex(i).x + "," + geo.getVertex(i).y);
    }
    argument = "Control=Measure";
    argument += "&TYPE=" + type; 
    argument += "&DATA=" + rrr;
    argument += "&XY=" + s;
    argument += "&ROW=" + _editMeasureRow;
    eval(onClickCallback_tab4_Measure);
}

function clearEditMeasureGeometry()
{
    if(_editMeasureGeometry != null){
        if(_editMeasureListener != null) {
            GEvent.removeListener(_editMeasureListener);
            _editMeasureListener = null;
        }
        _editMeasureGeometry.disableEditing({onEvent: "mouseover"});
        _editMeasureGeometry.disableEditing();
        GEvent.clearInstanceListeners(_editMeasureGeometry);
        gmap.removeOverlay(_editMeasureGeometry);
        _editMeasureGeometry = null;

        switch(_editMeasureType) {
        case "Line":
            if(_mesuereLine.length > _editMeasureRow && !_editMeasureisHidden) {
                _mesuereLine[_editMeasureRow].show();
            }
            break;
        case "Path":
            if(_mesuerePath.length > _editMeasureRow && !_editMeasureisHidden) {
                _mesuerePath[_editMeasureRow].show();
            }
            break;
        case "Polygon":
            if(_mesuerePolygon.length > _editMeasureRow && !_editMeasureisHidden) {
                _mesuerePolygon[_editMeasureRow].show();
            }
            break;
        case "Envelope":
            if(_mesuereEnvelope.length > _editMeasureRow && !_editMeasureisHidden) {
                _mesuereEnvelope[_editMeasureRow].show();
            }
            break;
        }
    }
}

function MapPan()
{
}

/// <summary>
/// Changes the base image of each button based on which tools has been selected
/// </summary>
/// <returns>null</returns>
function select(buttonId) {
}

/// <summary>
/// Sets the google maps icon properties
/// </summary>
/// <returns>icon</returns>
function getIcon(color) {
  var icon = new GIcon();
  icon.image = "images/map-push-pin.png";
  icon.shadow = "images/map-push-pin-shadow.png";
  icon.iconSize = new GSize(16, 30);
  icon.iconAnchor = new GPoint(5, 32);
  return icon;
}

/// <summary>
/// Gets a Custom Icon for the specified Image Url
/// </summary>
///<params name="url">The url of the icon to be loaded.</params>
/// <returns>icon</returns>
function getCustomIcon(url) {
  var icon = new GIcon();
  icon.image = "images/map-push-pin.png";
  icon.shadow = "images/map-push-pin-shadow.png";
  icon.iconSize = new GSize(16, 30);
  icon.iconAnchor = new GPoint(5, 32);
  return icon;
}

/// <summary>
/// Executes when Polygon tool is selected.
/// Clear overlays and ovelay info div (featuretable)
/// Start drawing the polygon when user clicks on map
/// </summary>
/// <returns>null</returns>
function trackPolygon() {
    try {
        _polygon = new GPolygon([], color, 2, 0.7, null, 0);
        _areaGeoType = "";
        HeaderMessage.innerHTML = "";
        _polygonArea = 0;
        startDrawingPolygon("AOI", onUpdateAreaPolygon, color, "polygon");
    }
    catch(e)
    {
        ErrorAlert(CatalogSearchError);
    }
}


//Add_Inoue_1222
function trackPoint() {
    try {
        _polygon = new GPolygon([], color, 2, 0.7, null, 0);
        _areaGeoType = "";
        HeaderMessage.innerHTML = "";
        _polygonArea = 0;
        startDrawingEnvelope("AOI", onUpdateAreaEnvelope, color, "polygon");
    }
    catch (e) {
        ErrorAlert(CatalogSearchError);
    }
}

//End
function trackEnvelope() {
    try {
        _polygon = new GPolygon([], color, 2, 0.7, null, 0);
        _areaGeoType = "";
        HeaderMessage.innerHTML = "";
        _polygonArea = 0;
        startDrawingEnvelope("AOI", onUpdateAreaEnvelope, color, "polygon");
    }
    catch(e)
    {
        ErrorAlert(CatalogSearchError);
    }
}
//2010.11.26 fuchi 面積計算はここではなく、サーバ側で算出する事！
function displayAreaInfo(areaPoly)
{
    var sqkm = GetSquareKm(areaPoly);
    var verCount = _polygon.getVertexCount();
    
    var maxX = -9999999999;
    var minX = 9999999999;
    var maxY = -9999999999;
    var minY = 9999999999;

    for(var i = 0; i < verCount; i++) {
        if(areaPoly.getVertex(i).x<minX)
        {
            minX = areaPoly.getVertex(i).x;
        }
        if(areaPoly.getVertex(i).x>maxX)
        {
            maxX = areaPoly.getVertex(i).x;
        }
        if(areaPoly.getVertex(i).y<minY)
        {
            minY = areaPoly.getVertex(i).y;
        }
        if(areaPoly.getVertex(i).y>maxY)
        {
            maxY = areaPoly.getVertex(i).y;
        }
    }
    var point1 = new GLatLng((minY + maxY) / 2 , minX);  //Y,X
    var point2 = new GLatLng((minY + maxY) / 2 , maxX);  //Y,X
    var points=[];
    points.push(point1);
    points.push(point2);
    
    var point3 = new GLatLng(minY , (minX + maxX) / 2);  //Y,X
    var point4 = new GLatLng(maxY , (minX + maxX) / 2);  //Y,X
    var points2=[];
    points2.push(point3);
    points2.push(point4);
    
    var _PolyLineGeo = new GPolyline(points);
    var _PolyLineGeo2 = new GPolyline(points2);

    var Xm = _PolyLineGeo.getLength();
    Xm = Xm / 1000;
    
    var Ym = _PolyLineGeo2.getLength();
    Ym = Ym / 1000;
    //  ここまで
//    var Xm2 = Math.floor(Number(Xm.toString())*10000);
//    Xm2 = (Number(Xm2)/10000);
//    var Ym2 = Math.floor(Number(Ym.toString())*10000);
//    Ym2 = (Number(Ym2)/10000);
    var Xm2 = Math.floor(Number(Xm.toString())*10+0.5);
    Xm2 = (Number(Xm2)/10);
    var Ym2 = Math.floor(Number(Ym.toString())*10+0.5);
    Ym2 = (Number(Ym2)/10);
    _polygonArea = sqkm;
    HeaderMessage.innerHTML = "面積:" + addCommas(sqkm) + " km<sup>2 </sup> 　縦:" + addCommas(Ym2) 
     + "km　横:" + addCommas(Xm2) + "km";
              
    if(_minArea2>sqkm) {
        if(_minArea1>sqkm) {
            HeaderMessage.style.color = "Red";
        } else {
            HeaderMessage.style.color = "Orange";
        }
    } else {
        HeaderMessage.style.color = "Black";
    }
    if(sqkm >= warningAreaSize) {
        document.getElementById("warningAreaSize").style.display = "";
    } else {
        document.getElementById("warningAreaSize").style.display = "none";
    }
}

function onUpdateAreaPolygon()
{
    //if(this == _polygon) {
        displayAreaInfo(_polygon);
        
        var s = new Sys.StringBuilder();
        var verCount = _polygon.getVertexCount();
        s.append("" + _polygon.getVertex(0).x + "," + _polygon.getVertex(0).y);
        for(var i = 1; i < verCount; i++) {
            s.append("," + _polygon.getVertex(i).x + "," + _polygon.getVertex(i).y);
        }
        
        _areaGeoType = "Polygon";
        argument = "Control=Map&Type=Polygon&Vertex=" + s.toString();
        eval(onClickCallback_tab1);
        changeTabIndex(2, 0);
    //}
}

function onUpdateAreaEnvelope()
{
    //if(this == _polygon) {
        setTimeout(onUpdateAreaEnvelope2,100);
    //}
}
var _polygonBefore;
function onUpdateAreaEnvelope2()
{
    disableDrawGeometry();
    
    var pnts_Before = [];
    var pnts_New = [];
    var pnts_Before2 = [];
    var pnts_New2 = [];
    var pnts = [];

    var min_xy = _polygon.getBounds().getSouthWest();
    var max_xy = _polygon.getBounds().getNorthEast();

    //2011/04/11 Add 180度ラインをまたいだ場合メッセージを表示
    if ((min_xy.x - max_xy.x) > 200 || (max_xy.x - min_xy.x) > 200) {
        alert("180度ラインをまたぐ指定はできません。");
        ClearAll()
        return;
    }
    //2011/04/11 Add End
    
//    if(_polygonBefore!=null)
//    {
//        for(var i = 0; i < _polygon.getVertexCount(); i++) {
//            pnts_New.push(_polygon.getVertex(i));
//        }
//        for(var i = 0; i < _polygonBefore.getVertexCount(); i++) {
//            pnts_Before.push(_polygonBefore.getVertex(i));
//        }
//        for(var i = 0; i < _polygon.getVertexCount(); i++) {
//            if(pnts_Before[i].x!=pnts_New[i].x||pnts_Before[i].y!=pnts_New[i].y)
//            {
//                pnts_New2.push(_polygon.getVertex(i));
//                pnts_Before2.push(_polygonBefore.getVertex(i));
//            }
//        }
//        if(pnts_New2!=null)
//        {
//            if(pnts_New2.length>0)
//            {
//                for(var i = 0; i < pnts_New2.length; i++) {
//                    for(var y = 0; y < pnts_Before.length; y++) {
//                        if(pnts_Before2[i].x==pnts_Before[y].x)
//                        {
//                            pnts_New[y].x =pnts_New2[i].x;
//                        }
//                        if(pnts_Before2[i].y==pnts_Before[y].y)
//                        {
//                            pnts_New[y].y =pnts_New2[i].y;
//                        }
//                    }
//                }
//            }
//        }
//    }
//    else
//    {
//        pnts_New = new Array();
//        pnts_New.push(new GLatLng(min_xy.y,min_xy.x));
//        pnts_New.push(new GLatLng(max_xy.y,min_xy.x));
//        pnts_New.push(new GLatLng(max_xy.y,max_xy.x));
//        pnts_New.push(new GLatLng(min_xy.y,max_xy.x));
//        pnts_New.push(new GLatLng(min_xy.y,min_xy.x));
//    }
//  
    pnts_New = new Array();
    pnts_New.push(new GLatLng(min_xy.y,min_xy.x));
    pnts_New.push(new GLatLng(max_xy.y,min_xy.x));
    pnts_New.push(new GLatLng(max_xy.y,max_xy.x));
    pnts_New.push(new GLatLng(min_xy.y,max_xy.x));
    pnts_New.push(new GLatLng(min_xy.y,min_xy.x));
    
    removeAreaPolygon();
//    _polygon = new GPolygon(pnts, color, 2, 0.7, null, 0);
    _polygon = new GPolygon(pnts_New, color, 2, 0.7, null, 0);
    _polygonBefore = new GPolygon(pnts_New, color, 2, 0.7, null, 0);
    gmap.addOverlay(_polygon);
    enableAreaEnvelope();

    //displayAreaInfo(_polygon);

    var s = new Sys.StringBuilder();
    var verCount = _polygon.getVertexCount();
    s.append("" + _polygon.getVertex(0).x + "," + _polygon.getVertex(0).y);
    for(var i = 1; i < verCount; i++) {
        s.append("," + _polygon.getVertex(i).x + "," + _polygon.getVertex(i).y);
    }

    waitOperation(true);
    _areaGeoType = "Envelope";                        
    argument = "Control=Map&Type=Envelope&Vertex=" + s.toString();
    eval(onClickCallback_tab1);
    changeTabIndex(2, 0);
    
    //2009/07/29 Add Monoi
    document.getElementById("ucTab21_TabContainer1_TabPanel1_txtStartDate").focus()
    //2009/07/29 Add End
}

/// <summary>
/// Called from 'StartLine()' and 'StartShape()'
/// Accepts geometry object, descriptive name, onUpdate function, color and geometry type
/// Allows user to edit geometry
/// </summary>
/// <returns>null</returns>
function startDrawingPolygon(name, onUpdate, color) {
    try {
          gmap.addOverlay(_polygon);
          _polygonClosed = false;
          _polygon.enableDrawing();
          _polygon.enableEditing({onEvent: "mouseover"});
          _polygon.disableEditing({onEvent: "mouseout"});
          _mapClickListener = GEvent.addListener(gmap, "click", function() {
            if (_polygon != null) {
//              if (_polygon.getVertexCount() == 23) {
//                MapAlert("Your polygon contains 24 vertices, please close polygon before the 30 vertex limit.");
//              }
//              else if (_polygon.getVertexCount() == 29) {
//                MapAlert("Your polygon contains 30 vertices, it will automatically close");
//                // alert("count=" + _polygon.getVertexCount());
//                _polygon.insertVertex(_polygon.getVertexCount(), _polygon.getVertex(0));
//                _polygon.disableEditing();
//                GEvent.trigger(_polygon, "endline", function() { // When the polygon is complete...    
//                    select("mapPan");
//                    _polygonClosed = true;
//                    var cells = addFeatureEntry(name, color);
//                    _polyListener = GEvent.bind(_polygon, "lineupdated", cells.desc, onUpdate);
//                });
//              }
            }
          });
           GEvent.addListener(_polygon, "cancelline", function() {  // When there is an error with drawing the polygon (like only 2 it only contains two points
                removeAreaPolygon();
                _polygonClosed = false;
           });
           GEvent.addListener(_polygon, "endline", function() { // When the polygon is complete...
                _polygonClosed = true;
                GEvent.removeListener(_mapClickListener);
                _mapClickListener = null;
                GEvent.clearInstanceListeners(_polygon);
                _polyListener = GEvent.bind(_polygon, "lineupdated", null, onUpdate);
           });
      }
      catch(e)
      {
            ErrorAlert(CatalogSearchError);
      }
}

/// <summary>
/// Called from 'StartLine()' and 'StartShape()'
/// Accepts geometry object, descriptive name, onUpdate function, color and geometry type
/// Allows user to edit geometry
/// </summary>
/// <returns>null</returns>
function startDrawingEnvelope(name, onUpdate, color) {
    try {
        gmap.addOverlay(_polygon);
        _polygonClosed = false;
        _polygon.enableDrawing({maxVertices : 4});
        _polygon.enableEditing({onEvent: "mouseover"});
        _polygon.disableEditing({onEvent: "mouseout"});
        _mapClickListener = GEvent.addListener(gmap, "click", function(overlay, latlng) {
            if (_polygon != null) {
                if (_polygon.getVertexCount() >= 1) {
                    envelope_latlon1 = _polygon.getVertex(0);
                    envelope_latlon2 = latlng;
                    
                    if(envelope_latlon1.x != envelope_latlon2.x || envelope_latlon1.y != envelope_latlon2.y) {
                        GEvent.trigger(_polygon, "endline");
                    }
                }
            }
        });
        GEvent.addListener(_polygon, "cancelline", function() {  // When there is an error with drawing the polygon (like only 2 it only contains two points
            removeAreaPolygon();
            _polygonClosed = false;
        });
        GEvent.addListener(_polygon, "endline", function() { // When the polygon is complete...
            _polygonClosed = true;
            GEvent.clearInstanceListeners(_polygon);
            GEvent.removeListener(_mapClickListener);
            _mapClickListener = null;
            _polyListener = GEvent.bind(_polygon, "lineupdated", null, onUpdate);
        });
    }
    catch(e)
    {
        ErrorAlert(CatalogSearchError);
    }
}

function trackMeasureLine() {
    try {
          _measureGeo = new GPolyline([], mcolor, 2, 0.7, mcolor, 0, {clickable:false});
          gmap.addOverlay(_measureGeo);
          _measureGeo.enableDrawing();
          //_measureGeo.enableEditing({onEvent: "mouseover"});
          //_measureGeo.disableEditing({onEvent: "mouseout"});
          _mapClickListener = GEvent.addListener(gmap, "click", function(overlay, latlng) {
            if (_measureGeo != null) {
                if (_measureGeo.getVertexCount() >= 1) {
                    envelope_latlon1 = _measureGeo.getVertex(0);
                    envelope_latlon2 = latlng;
                    
                    if(envelope_latlon1.x != envelope_latlon2.x || envelope_latlon1.y != envelope_latlon2.y) {
                        GEvent.trigger(_measureGeo, "endline");
                    }
                }
            }
           });
           GEvent.addListener(_measureGeo, "cancelline", function() {  // When there is an error with drawing the polygon (like only 2 it only contains two points
                removeMeasureGeometry();
           });
           GEvent.addListener(_measureGeo, "endline", function() { // When the polyline is complete...
                GEvent.clearInstanceListeners(_measureGeo);
                GEvent.removeListener(_mapClickListener);
                _mapClickListener = null;
                
                setTimeout("onCreateMesureGeometry(1,trackMeasureLine,_mesuereLine);",100);
           });
      }
      catch(e)
      {
            //ErrorAlert(CatalogSearchError);
      }
}

function trackMeasurePath() {
    try {
          _measureGeo = new GPolyline([], mcolor, 2, 0.7, mcolor, 0, {clickable:false});
          gmap.addOverlay(_measureGeo);
          _measureGeo.enableDrawing();
          //_measureGeo.enableEditing({onEvent: "mouseover"});
          //_measureGeo.disableEditing({onEvent: "mouseout"});
           GEvent.addListener(_measureGeo, "cancelline", function() {  // When there is an error with drawing the polygon (like only 2 it only contains two points
                removeMeasureGeometry();
           });
           GEvent.addListener(_measureGeo, "endline", function() { // When the polyline is complete...
                GEvent.clearInstanceListeners(_measureGeo);
                
                setTimeout("onCreateMesureGeometry(2,trackMeasurePath,_mesuerePath);",100);
           });
      }
      catch(e)
      {
            //ErrorAlert(CatalogSearchError);
      }
}

function trackMeasurePolygon() {
    try {
          _measureGeo = new GPolygon([], mcolor, 2, 0.7, null, 0, {clickable:false});
          gmap.addOverlay(_measureGeo);
          _measureGeo.enableDrawing();
          //_measureGeo.enableEditing({onEvent: "mouseover"});
          //_measureGeo.disableEditing({onEvent: "mouseout"});
           GEvent.addListener(_measureGeo, "cancelline", function() {  // When there is an error with drawing the polygon (like only 2 it only contains two points
                removeMeasureGeometry();
           });
           GEvent.addListener(_measureGeo, "endline", function() { // When the polyline is complete...
                GEvent.clearInstanceListeners(_measureGeo);
                
                setTimeout("onCreateMesureGeometry(3,trackMeasurePolygon,_mesuerePolygon);",100);
           });
      }
      catch(e)
      {
            //ErrorAlert(CatalogSearchError);
      }
}

function trackMeasureEnvelope() {
    try {
          _measureGeo = new GPolyline([], mcolor, 2, 0.7, mcolor, 0, {clickable:false});
          gmap.addOverlay(_measureGeo);
          _measureGeo.enableDrawing();
          //_measureGeo.enableEditing({onEvent: "mouseover"});
          //_measureGeo.disableEditing({onEvent: "mouseout"});
          _mapClickListener = GEvent.addListener(gmap, "click", function(overlay, latlng) {
          if (_measureGeo != null) {
              if (_measureGeo.getVertexCount() >= 1) {
                    envelope_latlon1 = _measureGeo.getVertex(0);
                    envelope_latlon2 = latlng;
                    
                    if(envelope_latlon1.x != envelope_latlon2.x || envelope_latlon1.y != envelope_latlon2.y) {
                        GEvent.trigger(_measureGeo, "endline");
                    }
               }
           }
           });
           GEvent.addListener(_measureGeo, "cancelline", function() {  // When there is an error with drawing the polygon (like only 2 it only contains two points
                removeMeasureGeometry();
           });
           GEvent.addListener(_measureGeo, "endline", function() { // When the polyline is complete...
                GEvent.clearInstanceListeners(_measureGeo);
                GEvent.removeListener(_mapClickListener);
                _mapClickListener = null;
                
                setTimeout("onCreateMesureEnvelope();",100);
           });
      }
      catch(e)
      {
            //ErrorAlert(CatalogSearchError);
      }
}

function onCreateMesureEnvelope()
{
    disableDrawGeometry();
    
    var min_xy = _measureGeo.getBounds().getSouthWest();
    var max_xy = _measureGeo.getBounds().getNorthEast();
    
    var pnts = [];
    pnts.push(new GLatLng(min_xy.y,min_xy.x));
    pnts.push(new GLatLng(max_xy.y,min_xy.x));
    pnts.push(new GLatLng(max_xy.y,max_xy.x));
    pnts.push(new GLatLng(min_xy.y,max_xy.x));
    pnts.push(new GLatLng(min_xy.y,min_xy.x));
    
    removeMeasureGeometry();
    _measureGeo = new GPolygon(pnts, mcolor, 2, 0.7, null, 0, {clickable:false});
    gmap.addOverlay(_measureGeo);

    onCreateMesureGeometry(4,trackMeasureEnvelope,_mesuereEnvelope);
}

function onCreateMesureGeometry(type,trackFunc,measureArray)
{
    disableDrawGeometry();
    
    var rrr = 0;
    if(type <= 2) {
        rrr = _measureGeo.getLength();
    } else {
        rrr = _measureGeo.getArea();
    }
    var s = new Sys.StringBuilder();
    var verCount = _measureGeo.getVertexCount();
    s.append("" + _measureGeo.getVertex(0).x + "," + _measureGeo.getVertex(0).y);
    for(var i = 1; i < verCount; i++) {
        s.append("," + _measureGeo.getVertex(i).x + "," + _measureGeo.getVertex(i).y);
    }
    argument = "Control=Measure";
    argument += "&TYPE=" + type; 
    argument += "&DATA=" + rrr;
    argument += "&XY=" + s;
    eval(onClickCallback_tab4_Measure);
    
    measureArray.push(_measureGeo);
    trackFunc();
}

/// <summary>
/// Add overlay information to the info div
/// </summary>
/// <returns>array containing cell and color</returns>
function addFeatureEntry(name, color) {
  currentRow_ = document.createElement("tr");
  var colorCell = document.createElement("td");
  currentRow_.appendChild(colorCell);
  colorCell.style.backgroundColor = color;
  colorCell.style.width = "1em";
  var nameCell = document.createElement("td");
  currentRow_.appendChild(nameCell);
  nameCell.innerHTML = name;
  var descriptionCell = document.createElement("td");
  currentRow_.appendChild(descriptionCell);
  // featureTable_.appendChild(currentRow_);
  return {desc: descriptionCell, color: colorCell};
}

/// <summary>
/// Executes when Point (marker) tool is selected.
/// Clear overlays and ovelay info div (featuretable)
/// Start drawing the point when user clicks on map
/// </summary>
/// <returns>null</returns>
function placeMarker() {
  try
  {
      _foot.ClearFeatureTable();
      _listener = GEvent.addListener(gmap, "click", function(overlay, latlng) {
        if (latlng) {
          select("mapPan");
          GEvent.removeListener(_listener);
          //gmap.clearOverlays();
          var marker = new GMarker(latlng, {icon: getIcon(color), draggable: true});
          gmap.addOverlay(marker);
          _foot.SetVLayerDesc("POI: " + Math.round(marker.getLatLng().lat() * 10000) / 10000 + ", " + Math.round(marker.getLatLng().lng() * 10000) / 10000);
          _searchGeometryObject.SetGeometry(marker, "marker") //Set the global search marker to this newly created marker
          ExecuteCatalogSearch(marker.getLatLng());  // Search for footprints when marker is placed
          GEvent.addListener(marker, "dragend", function() {
            //gmap.clearOverlays();
            updateMarker(marker);
            //RW - Execute Point Catalog Search if point is dragged
            _searchGeometryObject.SetGeometry(marker, "marker"); //Set the global search marker to this newly created marker
            ExecuteCatalogSearch(marker.getLatLng()); // Search for footprints when marker is moved
          });
        }
      });
   }
   catch(e)
   {
        ErrorAlert(CatalogSearchError);   
   }
}

/// <summary>
/// Executes when Extent tool is selected.
/// Clear overlays and overlay info div (featuretable)
/// Gets the current map extent, creates polygon, adds polygon to the map
/// Passes extent for footprint search
/// </summary>
/// <returns>null</returns>
function buildExtent() {
	
	try 
	{
	    if(_mouseMoveListener != null){
            GEvent.removeListener(_mouseMoveListener); //remove mouse move listener if active
            gmap.removeOverlay(_follow_marker); //Remove the marker
          }
        //gmap.clearOverlays();
        _polygon = null;
        _polygonBefore = null;
        _foot.ClearFeatureTable();
        // Draw Polygon
        var nw = getLatLonFromPixel(2,2);
        var se = getLatLonFromPixel(gmap.getSize().width-4,gmap.getSize().height-4);
        var ne = getLatLonFromPixel(2, gmap.getSize().height-4);
        var sw = getLatLonFromPixel(gmap.getSize().width-4, 2);
//        var polygon = new GPolygon([nw,ne,se,sw,nw], color, 5, 1, color, 0.1);
        var polygon = new GPolygon([nw,ne,se,sw,nw], color, 5, 1, null, 0);
        gmap.addOverlay(polygon);
        
        // Compute/Display SqKM
        var sqkm = GetSquareKm(polygon);
        _foot.SetVLayerDesc("AOI (Approx): " + addCommas(sqkm) + " sq.km. ");
        
        _searchGeometryObject.SetGeometry(polygon, "envelope");  //Save for later to add on top of search results.
        SearchByGeometry(_searchGeometryObject); // Search for footprints based on extent
    }
    catch (e)
    {
        //throw CatalogSearchError;
        ErrorAlert(CatalogSearchError);
    }
}

/// <summary>
/// Accepts browser pixel values
/// </summary>
/// <returns>latlong point</returns>
function getLatLonFromPixel(x,y) {
    var swpixel = gmap.getCurrentMapType().getProjection().fromLatLngToPixel(gmap.getBounds().getSouthWest(),gmap.getZoom());
    var nepixel = gmap.getCurrentMapType().getProjection().fromLatLngToPixel(gmap.getBounds().getNorthEast(),gmap.getZoom());
    var latlong = gmap.getCurrentMapType().getProjection().fromPixelToLatLng(new GPoint(swpixel.x + x,nepixel.y + y),gmap.getZoom());
    var point = new GLatLng(latlong.y, latlong.x);
    return point;
} 

/// <summary>
/// When marker is selected and moved, update position info and optionally change color
/// </summary>
/// <returns>null</returns>
function updateMarker(marker) {
  var latlng = marker.getPoint();
  //TODO 共通化
  _foot.SetVLayerDesc("POI: " + Math.round(latlng.y * 10000) / 10000 + ", " + Math.round(latlng.x * 10000) / 10000);
}

/// <summary>
/// Create the basic control for the map tools
/// prototype: add it as a new control to google maps
/// prototype.initialize = construct the elements that are inside the control
/// </summary>
/// <returns>null</returns>
function MapToolControl() 
{
}

MapToolControl.prototype = new GControl();

MapToolControl.prototype.initialize = function(map) {
    var container = document.createElement("div");

    var toolMapPan = $get("tool_MapPan");
    GEvent.addDomListener(toolMapPan, "click", function() {
        ChangeMapTool("MapPan", toolMapPan, null);
    });

    var toolFootPrint = $get("tool_FootPrint");
    GEvent.addDomListener(toolFootPrint, "click", function() {
        ChangeMapTool("SelectFootPrint", toolFootPrint, null);
    });

    var ClickPoint = $get("tool_ClickPoint");
    GEvent.addDomListener(ClickPoint, "click", function() {
        ChangeMapTool("SelectClickPoint", ClickPoint, null);
    });

    //Add_Inoue1222
    var tool_Point1 = $get("tool_Point");
    var tool_Point2 = $get(tool_point_id);
    GEvent.addDomListener(tool_Point1, "click", function() {
    ChangeMapTool("Area_Point", tool_Point1, tool_Point2);
    });
    GEvent.addDomListener(tool_Point1, "click", function() {
    ChangeMapTool("Area_Point", tool_Point1, tool_Point2);
    });
    //end

    var toolAreaEnvelope1 = $get("tool_Area_Envelope");
    var toolAreaEnvelope2 = $get(tool_envelope_id);
    GEvent.addDomListener(toolAreaEnvelope1, "click", function() {
        ChangeMapTool("Area_Envelope", toolAreaEnvelope1, toolAreaEnvelope2);
    });
    GEvent.addDomListener(toolAreaEnvelope2, "click", function() {
        ChangeMapTool("Area_Envelope", toolAreaEnvelope1, toolAreaEnvelope2);
    });

    var toolAreaPolygon1 = $get("tool_Area_Polygon");
    var toolAreaPolygon2 = $get(tool_polygon_id);
    GEvent.addDomListener(toolAreaPolygon1, "click", function() {
        ChangeMapTool("Area_Polygon", toolAreaPolygon1, toolAreaPolygon2);
    });
    GEvent.addDomListener(toolAreaPolygon2, "click", function() {
        ChangeMapTool("Area_Polygon", toolAreaPolygon1, toolAreaPolygon2);
    });

    var toolMeasureLine = $get("tool_measure_Line");
    GEvent.addDomListener(toolMeasureLine, "click", function() {
        ChangeMapTool("MeasureLine", toolMeasureLine, null);
    });

    var toolMeasurePath = $get("tool_measure_Path");
    GEvent.addDomListener(toolMeasurePath, "click", function() {
        ChangeMapTool("MeasurePath", toolMeasurePath, null);
    });

    var toolMeasurePolygon = $get("tool_measure_Polygon");
    GEvent.addDomListener(toolMeasurePolygon, "click", function() {
        ChangeMapTool("MeasurePolygon", toolMeasurePolygon, null);
    });

    var toolMeasureEnvelope = $get("tool_measure_Envelope");
    GEvent.addDomListener(toolMeasureEnvelope, "click", function() {
        ChangeMapTool("MeasureEnvelope", toolMeasureEnvelope, null);
    });

    defaultMapTool();

    return container;
}

//MapToolControl.prototype.initialize = function() {

//    // #### Pan tool
//	var mapPan = document.createElement("div");
//	mapPan.setAttribute("id", "mapPan");
//	mapPan.setAttribute("title", _mapPanInstructions);
//	this.setButtonStyle_(mapPan);
//	container.appendChild(mapPan);
//	GEvent.addDomListener(mapPan, "click", function() {
//	  select("mapPan");
//	  if (_listener != null) {
//	    GEvent.removeListener(_listener); // Remove marker functionality when pan is selected
//	  }
//	  if (_polygon != null) {
//        _polygon.disableEditing();  // Remove polygon functionality when pan is selected
//        if (_polygonClosed == false) {
//            gmap.clearOverlays();  // If the polygon hasn't been closed, remove it from the map.
//        }
//      }
//      if (_mouseMoveListener != null){
//        GEvent.removeListener(_mouseMoveListener); //remove mouse move listener if active
//        gmap.removeOverlay(_follow_marker); //Remove the marker
//      }
//    });
//	
//	// #### Point/Marker tool
//	var mapMarkerTool = document.createElement("div");
//	mapMarkerTool.setAttribute("id", "mapMarker");
//	mapMarkerTool.setAttribute("title", _mapMarkerInstructions);
//	this.setButtonStyle_(mapMarkerTool);
//	container.appendChild(mapMarkerTool);
//	var markerEventListener = GEvent.addDomListener(mapMarkerTool, "click", function() {
//      if (_polygon != null) {
//        _polygon.disableEditing(); // Remove polygon functionality when marker is selected
//        if (_polygonClosed == false) {
//            gmap.clearOverlays();  // If the polygon hasn't been closed, remove it from the map.
//        }
//      }
//	  CreateDraggableMarker();
//	  select("mapMarker");
//      placeMarker();
//      _polygon = null;
//    });
//	
//	// #### Polygon tool
//	var mapPoly = document.createElement("div");
//	mapPoly.setAttribute("id", "mapPoly");
//	mapPoly.setAttribute("title", _mapPolyInstructions);
//	this.setButtonStyle_(mapPoly);
//	container.appendChild(mapPoly);
//	var polyEventListener = GEvent.addDomListener(mapPoly, "click", function() {
//	  select("mapPoly");
//      if (_polygon != null) {
//        _polygon.disableEditing(); // Remove old polygon functionality when polygon is selected
//        if (_polygonClosed == false) {
//            gmap.clearOverlays();  // If the old polygon wasn't closed, remove it from the map.
//        }
//      }
//	  if (_listener != null) {
//	    GEvent.removeListener(_listener); // Remove marker functionality when polygon tool is selected
//	  }
//	  if(_mouseMoveListener != null){
//        GEvent.removeListener(_mouseMoveListener); //remove mouse move listener if active
//        gmap.removeOverlay(_follow_marker); //Remove the marker
//      }
//      startShape();
//    });
//   
//    // #### Extent tool
//	_mapExtent = document.createElement("div");
//	_mapExtent.setAttribute("id", "mapExtent");
//	this.setButtonStyle_(_mapExtent);
//	container.appendChild(_mapExtent);
//    // Extent functionality is being set in Utilities.js (ExecuteZoomCheck).	

//	gmap.getContainer().appendChild(container);
//	return container;
//}

// Sets the proper CSS for the given button element.
MapToolControl.prototype.setButtonStyle_ = function(button) 
{
//	if (button.id == "mapPan")
//		{ button.style.backgroundImage = "url(images/button-map-drag-active.gif)"; 
//		  button.style.left = "80px"; }
//	else if (button.id == "mapMarker")
//		{ button.style.backgroundImage = "url(images/button-map-pin.gif)";
//		  button.style.left = "120px"; }
//	else if (button.id == "mapPoly")
//		{ button.style.backgroundImage = "url(images/button-map-polygon.gif)"; 
//		  button.style.left = "160px"; }
//	else if (button.id == "mapExtent")
//		{ button.style.backgroundImage = "url(images/button-map-map-extent-disabled.gif)"; 
//		  button.style.left = "200px"; }
//	
//	button.style.position = "absolute";
//	button.style.top = "7px";
//	button.style.width = "32px";
//	button.style.height = "32px";
//	button.style.cursor = "pointer";
//	button.style.zindex = "3";
}
 
/// <summary>
/// When extent sqkm is greater than threshold status = false
/// When the status is false, disable the mapExtent map tool by removing the listener on it.
/// Otherwise, add the listener to back on the mapExtent tool.
/// </summary>
/// <returns>null</returns>
function ExtentToolStatus(status) 
{
    try
    {
        if(status == false) 
        {
            GEvent.clearInstanceListeners(_mapExtent);
            _mapExtent.style.cursor = "not-allowed";
            _mapExtent.style.backgroundImage = "url(images/button-map-map-extent-disabled.gif)";
            $("mapExtent").style.cursor = "not-allowed";
            $("mapExtent").title = "Zoom in to search by current extent";
            $("mapExtent").style.backgroundImage = "url(images/button-map-map-extent-disabled.gif)";
            _extentToolOn = false;  // For the pop-up bubble extent tool
        }
        else if(status == true && _extentToolOn == false) //RW - added check to see if tool was already on.
        {
            GEvent.addDomListener(_mapExtent, "click", function() {
                select("mapExtent");
               if (_polygon != null) 
               {
                 _polygon.disableEditing(); // Remove polygon functionality
               }
               try 
               {
                buildExtent();
               }
               catch(e)
               {
                //this is the end of the line for this error. The Method was called as an
                // event handler by Google API so this is as far as we call bubble the error.
                new ErrorAlert(e.message);
               }
            });
            _mapExtent.style.cursor = "pointer";
            _mapExtent.style.backgroundImage = "url(images/button-map-map-extent.gif)";
            $("mapExtent").style.cursor = "pointer";
            $("mapExtent").title = "Search by current extent";
            $("mapExtent").style.backgroundImage = "url(images/button-map-map-extent.gif)";
            _extentToolOn = true; // For the pop-up bubble extent tool
        }
        else if(status == true && _extentToolOn == true)
        {
            _mapExtent.style.cursor = "pointer";
            _mapExtent.style.backgroundImage = "url(images/button-map-map-extent.gif)";
            $("mapExtent").style.cursor = "pointer";
            $("mapExtent").title = "Search by current extent";
            $("mapExtent").style.backgroundImage = "url(images/button-map-map-extent.gif)";
        }
    }
    catch(e)
    {
        ErrorAlert(e.message);
    }
}

/// <summary>
/// Generates HTML string with map tools, based on mapExtent tool being enabled or disabled in pop-up bubble.
/// </summary>
/// <params name="placeName">The placeName to be displayed</params>
/// <params name="extentToolOn">bool.  Whether or not the extent search tool should be enabled or disabled.</params>
/// <returns>map tools as html content for pop-up bubble</returns>
function BubbleContent(placeName) {
    var extentTool = null; 
    if(_extentToolOn)
    {
        extentTool = "<td><div id='mapExtent' style='cursor:pointer;background-image:url(images/button-map-map-extent.gif)' title='Search by current extent' onclick='if(_extentToolOn){buildExtent();}'/></td>";
    }
    else
    {
        extentTool = "<td><div id='mapExtent' style='cursor:pointer;background-image:url(images/button-map-map-extent-disabled.gif)' title='Search by current extent' onclick='if(_extentToolOn){buildExtent();}'/></td>";    
    }
    
    var htmlcontent = "<span class='GreenBold'>" + placeName + "</span><br/>" +
                    "Refine your Area of Interest by dragging, searching again,<br/> or clicking another Find Place search result.<br/>" +
                    "<br /><span class='GreenBold'>Search the Image Catalog</span><br />" +
                    "To see available images in our Catalog, use one of these<br />" +
                    " tools.(Map Extent available only at certain zoom levels.)<br/>" +
                    "<table style='font-size:small;'>\n<tr>\n" +
                    "<td 'width:100px'><div id='mapMarker' style='cursor:pointer;background-image:url(images/button-map-pin.gif)' title='Place marker on map to search by point of interest' onclick='CreateDraggableMarker(),placeMarker()'/></td>\n" +
                    "<td 'width:100px'><div id='mapPoly' style='cursor:pointer;background-image:url(images/button-map-polygon.gif)' title='Draw polygon on map to search by area of interest' onclick='startShape();'/></td>\n" +
                    extentTool +
                    "</tr><tr>" +
                    "<td style='width:100px'><b>Point</b><br />" +
                    "Specific point</td>" +
                    "<td style='width:100px'><b>Polygon</b><br />" +
                    "Define an area</td>" +
                    "<td><b>Map Extent</b><br />" +
                    "Entire map window</td>" +
                    "</tr></table>";
    return htmlcontent;
}

/// <summary>
/// Places a marker on the map that follows the mouse around until the map is clicked.
/// </summary>
/// <returns>null</returns>
function CreateDraggableMarker()
{
	    //RW - Add a listener on map mouse move to show the icon moving with the mouse
       ClearEverything();
//	   var color = getColor(true);
	   //next, make map div cursor grab
	   // $("wrapper-map").style.cursor = "url(images/pointer.cur)"; //TODO: this doesn't work
	   	//next, add a marker.
      //var follow_marker = new GMarker(getLatLonFromPixel(320,105), {icon: getCustomIcon('images/red_marker_drag.gif'), clickable: false}); //Position of the Marker button
      _follow_marker = new GMarker(getLatLonFromPixel(320,105), {icon: getIcon(color), draggable: true});
      gmap.addOverlay(_follow_marker);
	  _mouseMoveListener = GEvent.addDomListener(gmap, "mousemove", function(latlng){
	  //Make a marker follow the mouse around the map.
	  var lat = latlng.lat();
	  var lng = latlng.lng();
	  _follow_marker.setLatLng(new GLatLng(lat, lng)); //any offset will have to be dependent on map zoom.
	  });
}



