﻿// JScript 檔
var map = null;
function NewLatLng(x,y)
{
  LatLng=new ILatLng(y,x);
  return LatLng;
}
function initMap(initPnt, zoomLevel)
{
    //var pt = isDefined(initPnt) ? initPnt : new ILatLng(25.059637,121.532835);
    var pt = isDefined(initPnt) ? initPnt : new ILatLng(25.049613,121.515027);
    var lv = isDefined(zoomLevel) ? zoomLevel : 9;
    map = new IMap(document.getElementById("map"));
    map.setCenter(pt, lv);
    map.addControl(new IZoomControl());
    SetPoint();
}

function SetPoint()//取得滑鼠點選的座標
{
    IEvent.addListener(map, 'click', function(e) {
    var mousePos=mousePosition(e);
    var CLatLng=map.fromContainerPixelToLatLng(new IPoint(mousePos.x,mousePos.y));
    SetFormLngLat(CLatLng.lng(),CLatLng.lat());
    createPoint(CLatLng.lng(),CLatLng.lat());

    });
}
function SDKQueryResult(x,y)//SDK查詢結果
{
    SetFormLngLat(x,y);
    createPoint(x,y,"Query");
}
function FeedbackMaintain(x,y)
{
 createPoint(x,y,"feedback");
}

function SetFormLngLat(x,y)//將經緯度填入From
{
    var txtLng=document.getElementById("DetailsViewFBAddress_txtLng");
    var txtLat=document.getElementById("DetailsViewFBAddress_txtLat");
    var txtLng2=document.getElementById("DetailsViewFBAddress_txtLng2");
    var txtLat2=document.getElementById("DetailsViewFBAddress_txtLat2");
    
    var RadioAddrLatLng=document.form1.RadioAddrLatLng;
   
    var RadioAddrCheckValue;
    for (a=0;a<RadioAddrLatLng.length;a++)
    {
      if (RadioAddrLatLng[a].checked)
      {
        RadioAddrCheckValue=RadioAddrLatLng[a].value;
      }
    }
   /* var txtPoiLng=document.getElementById("DetailsViewFBPoi_txtPoiLng");
    var txtPoiLat=document.getElementById("DetailsViewFBPoi_txtPoiLat");
    var txtPoiLng2=document.getElementById("DetailsViewFBPoi_txtPoiLng2");
    var txtPoiLat2=document.getElementById("DetailsViewFBPoi_txtPoiLat2");
    
    var RadioPoiLatLng=document.form1.RadioPoiLatLng;
    var RadioPoiCheckValue;
     for (p=0;p<RadioPoiLatLng.length;p++)
    {
      if (RadioPoiLatLng[p].checked)
      {
        RadioPoiCheckValue=RadioPoiLatLng[p].value;
      }
    }
    */
    
    
    
    var txtRoadLng=document.getElementById("DetailsViewFBRoad_txtRoadLng");
    var txtRoadLat=document.getElementById("DetailsViewFBRoad_txtRoadLat");
    var txtRoadLng2=document.getElementById("DetailsViewFBRoad_txtRoadLng2");
    var txtRoadLat2=document.getElementById("DetailsViewFBRoad_txtRoadLat2");
    
    var RadioRoadLatLng=document.form1.RadioRoadLatLng;
    var RadioRoadCheckValue;
      for (r=0;r<RadioRoadLatLng.length;r++)
    {
      if (RadioRoadLatLng[r].checked)
      {
        RadioRoadCheckValue=RadioRoadLatLng[r].value;
      }
    }
    
    
    var txtTrafficLng=document.getElementById("DetailsViewFBTraffic_txtTrafficLng");
    var txtTrafficLat=document.getElementById("DetailsViewFBTraffic_txtTrafficLat");
    var txtTrafficLng2=document.getElementById("DetailsViewFBTraffic_txtTrafficLng2");
    var txtTrafficLat2=document.getElementById("DetailsViewFBTraffic_txtTrafficLat2");
    
    var RadioTrafficLatLng=document.form1.RadioTrafficLatLng;
    var RadioTrafficCheckValue;
      for (t=0;t<RadioTrafficLatLng.length;t++)
    {
      if (RadioTrafficLatLng[t].checked)
      {
        RadioTrafficCheckValue=RadioTrafficLatLng[t].value;
      }
    }
    
    
    
    
   /* var txtFoodLng=document.getElementById("DetailsViewFBFood_txtFoodLng");
    var txtFoodLat=document.getElementById("DetailsViewFBFood_txtFoodLat");
    var txtFoodLng2=document.getElementById("DetailsViewFBFood_txtFoodLng2");
    var txtFoodLat2=document.getElementById("DetailsViewFBFood_txtFoodLat2");
    
     var RadioFoodLatLng=document.form1.RadioFoodLatLng;
    var RadioFoodCheckValue;
      for (f=0;f<RadioFoodLatLng.length;f++)
    {
      if (RadioFoodLatLng[f].checked)
      {
        RadioFoodCheckValue=RadioFoodLatLng[f].value;
      }
    }
    
    
    var txtTravelLng=document.getElementById("DetailsViewTravel_txtTravelLng");
    var txtTravelLat=document.getElementById("DetailsViewTravel_txtTravelLat");
    var txtTravelLng2=document.getElementById("DetailsViewTravel_txtTravelLng2");
    var txtTravelLat2=document.getElementById("DetailsViewTravel_txtTravelLat2");
    var RadioTravelLatLng=document.form1.RadioTravelLatLng;
    var RadioTravelCheckValue;
      for (t=0;t<RadioTravelLatLng.length;t++)
    {
      if (RadioTravelLatLng[t].checked)
      {
        RadioTravelCheckValue=RadioTravelLatLng[t].value;
      }
    }
    
    
    
    var txtLifeLng=document.getElementById("DetailsViewLife_txtLifeLng");
    var txtLifeLat=document.getElementById("DetailsViewLife_txtLifeLat");
    var txtLifeLng2=document.getElementById("DetailsViewLife_txtLifeLng2");
    var txtLifeLat2=document.getElementById("DetailsViewLife_txtLifeLat2");
     var RadioLifeLatLng=document.form1.RadioLifeLatLng;
    var RadioLifeCheckValue;
      for (l=0;l<RadioLifeLatLng.length;l++)
    {
      if (RadioLifeLatLng[l].checked)
      {
        RadioLifeCheckValue=RadioLifeLatLng[l].value;
      }
    }
    */
    
    var lng=roundNumber(x,6);
    var lat=roundNumber(y,6);
    if (RadioAddrCheckValue=="1")
    {
     txtLng.value=lng;
     txtLat.value=lat;
    }
    else
    {
     txtLng2.value=lng;
     txtLat2.value=lat;
    }
    
   /*  if (RadioPoiCheckValue=="1")
    {
     txtPoiLng.value=lng;
     txtPoiLat.value=lat;
    }
    else
    {
     txtPoiLng2.value=lng;
     txtPoiLat2.value=lat;
    } */
    
    
    if (RadioRoadCheckValue=="1")
    {
      txtRoadLng.value=lng;
      txtRoadLat.value=lat;
    }
    else
    {
      txtRoadLng2.value=lng;
      txtRoadLat2.value=lat;
    }
    
     if (RadioTrafficCheckValue=="1")
    {
     txtTrafficLng.value=lng;
     txtTrafficLat.value=lat;
    }
    else
    {
     txtTrafficLng2.value=lng;
     txtTrafficLat2.value=lat;
    }
   
    
   /*  if (RadioFoodCheckValue=="1")
    {
     txtFoodLng.value=lng;
     txtFoodLat.value=lat;
    }
    else
    {
     txtFoodLng2.value=lng;
     txtFoodLat2.value=lat;
    }

    if (RadioTravelCheckValue=="1")
    {
     txtTravelLng.value=lng;
     txtTravelLat.value=lat;
    }
    else
    {
     txtTravelLng2.value=lng;
     txtTravelLat2.value=lat;
    }
    
    if (RadioLifeCheckValue=="1")
    {
     txtLifeLng.value=lng;
     txtLifeLat.value=lat;
    }
    else
    {
     txtLifeLng2.value=lng;
     txtLifeLat2.value=lat;
    }
    */
    
 
    
}

function createPoint(x, y,mode)//Show Icon and SetCenter
{
   var infoHtml = "";
   if (mode=="feedback")
   {
    infoHtml+="<table>";
    infoHtml+="<tr><td><span style='font-size:12px'>使用者回報的參考座標!!。</span></td></tr>";
    infoHtml+="</table>";

   }
   else
   {
    infoHtml+="<table>";
    infoHtml+="<tr><td><span style='font-size:12px'>如回報或分享的位置無誤<br>請完成右邊表單填寫!!<br>感謝您對研勤科技的支持。</span></td></tr>";
    infoHtml+="</table>";
   }
    
    var ppgicon = new IIcon();

    strimg='../img/thumbtack.gif';
    ppgicon.image = strimg;
    ppgicon.iconSize = new ISize(24, 24);
    ppgicon.iconAnchor = new IPoint(12, 12);
    ppgicon.infoWindowAnchor = new IPoint(0, 25);
    ppgicon.transparent = null;
    ppgicon.imageMap = null;
    
    var latlng=new ILatLng(y,x,9);
    var _PointMarker = new IMarker(latlng, ppgicon);
    _PointMarker.bindInfoWindowHtml(infoHtml, {size:new ISize(150,70)});
   
    map.clearOverlays();
    map.addOverlay(_PointMarker);
    //_PointMarker.enableDragging();
    _PointMarker.openInfoWindow();
   if (mode=="feedback" || mode=="Query")
   {
    map.setCenter(latlng);
   }


}

function mousePoint(x,y)
{
  this.x=x;
  this.y=y;
}
function mousePosition(e)//滑鼠點選的螢幕座標
{
  var x=parseInt(e.clientX);
  var y=parseInt(e.clientY);
  return new mousePoint(x,y);
}

function roundNumber(base,length)//小數點N位
{ 
 var M=Math.pow(10,length);
 var NewNo=Math.round(base*M)/M;
 return NewNo;
  
}
function InsertSuccess()
{
  alert("圖資回報完成!!感謝您對本公司產品的支持!!");
  location.href="Default.aspx";
}



