//==============================================================
// POIactive ------------------------------------------------
POIactive = function() { }
var TI_activeInfo = new Object(); 
//============> POIactive
//------------> POIactive.create(MapID)
//------------> POIactive.getInnerHTML(MapID)
//------------> POIactive.remove(MapID)
//------------> POIactive.Initial(MapID)

//------------> POIactive.refresh (MapID)
//------------> POIactive.Show (MapID)
//------------> POIactive.Hide (MapID)
//--------------------------------------------------------------
//POIactive.create --------------------------------------------
POIactive.create = function(MapID) {
    var Mcode = Map.getMcodeFromMapID(MapID);
    var Ocode = "Map";
    POIactive.remove(MapID)
    document.getElementById(Mcode + "^" + Ocode + "^" + "MapContainer").innerHTML += POIactive.getInnerHTML(MapID);
    return true;
}
//--------------------------------------------------------------
//POIactive.create --------------------------------------------
POIactive.getInnerHTML = function(MapID) {
    var Mcode = Map.getMcodeFromMapID(MapID);
    var Ocode = "Map";
    var innerHTML = "";
    innerHTML += "<div id='" + Mcode + "^" + Ocode + "^" + "POIactive' class='POIactive'"
  //  innerHTML += "onmouseover='TOIItem_Info_Event(event,'over')'";
    // onmouseout="TOIItem_Info_Event(event,'out')" 
    innerHTML += "></div>";
    return innerHTML;
}
//--------------------------------------------------------------
//POIactive.remove --------------------------------------------
POIactive.remove = function(MapID) {
    var Mcode = Map.getMcodeFromMapID(MapID);
    var Ocode = "Map";
    var Celem = document.getElementById(Mcode + "^" + Ocode + "^" + "MapContainer")
    var elem = document.getElementById(Mcode + "^" + Ocode + "^" + "POIactive")
    if (elem) {
        Celem.removeChild(Elem);
        return true;
    } else {
        return false;
    }
}


//--------------------------------------------------------------
//POIactive.refresh --------------------------------------------
POIactive.refresh = function(MapID) {
    var Mcode = Map.getMcodeFromMapID(MapID);
    var Ocode = "Map";
    var Moptions = Map.MapObj[MapID]
    //----------------------------------
    var elem = document.getElementById(Mcode + "^" + Ocode + "^" + "POIactive")
//    if (TI_activeInfo.Gis_ID <= 100 || TI_activeInfo.Type == "TRI") {
//        elem.style.visibility = "hidden";
//        return;
//    }
    //----------------------------------
    var tmpPoint = new MapPoint(TI_activeInfo.X, TI_activeInfo.Y).transform(Moptions.MapRect, Moptions.ImageRect);
    TI_activeInfo.Xp = tmpPoint.x;
    TI_activeInfo.Yp = tmpPoint.y;
    elem.style.left = TI_activeInfo.Xp - 30 + "px";
    elem.style.top = TI_activeInfo.Yp - 30 + "px";
    // elem.style.backgroundImage = "url(Images_MapSymbol/TOIactive.png)";
    elem.style.visibility = "visible";
}
//--------------------------------------------------------------
//POIactive.Show -----------------------------------------------
POIactive.Show = function(MapID) {
    var Mcode = Map.getMcodeFromMapID(MapID);
    var Ocode = "Map";
    //----------------------------------
    var elem = document.getElementById(Mcode + "^" + Ocode + "^" + "POIactive")
    if (TI_activeInfo.Gis_ID <= 100 || TI_activeInfo.Type == "TRI") {
        elem.style.visibility = "hidden";
    }else{
        elem.style.visibility = "visible";
    }
}
//--------------------------------------------------------------
//POIactive.Hide -----------------------------------------------
POIactive.Hide = function(MapID) {
    var Mcode = Map.getMcodeFromMapID(MapID);
    var Ocode = "Map";
    document.getElementById(Mcode + "^" + Ocode + "^" + "POIactive").style.visibility = "hidden";
}
//--------------------------------------------------------------



//--------------------------------------------------------------
//POIactive.Hide -----------------------------------------------
POIactive.GetPOIactive = function(MapID,ID) {
    var Mcode = Map.getMcodeFromMapID(MapID);
    var Moptions = Map.MapObj[MapID];

    var request = "";
    request += "&Reguest=TI_active";
    request += "&Reg_MapCode=" + Mcode;
    request += "&Reg_MapLang=" + Moptions.MapLang;
    request += "&Reg_POI_ID=" + ID;
//----------------------------------
    Req.makeRequest(MapID, Moptions.serverUrl, Moptions.busyReq, "Request", POIactive.successCallback, POIactive.errorCallback, request);
};
//--------------------------------------------------------------
//POIactive.successCallback -----------------------------------
POIactive.successCallback = function(xmlhttp, MapID) {
    Progress.hide(MapID)

    var Moptions = Map.MapObj[MapID]
    //var Mcode = Map.getMcodeFromMapID(MapID);
    var response = xmlhttp.responseText;
    if (response == null || response == "") { return };
    var jsonR = JSON.parse(response);
    //----------------------------------
    clearInterval(Slide_Interval);
    //TOIItem_Info_Event(null,'close');

    if (jsonR.Response == "TI_active") {
        //TI_active_Info_Read(MapID,jsonR.Resp_POI_ID, jsonR.Resp_POIactive)
        //TI_active_Info_Draw();
        POIactive.ReadPOIactive(MapID, jsonR.Resp_POI_ID, jsonR.Resp_POIactive)
        POIactive.refresh(MapID);
    }
    //CTO_MapLoadWait_Hide();
    Progress.hide(MapID)
}
//--------------------------------------------------------------
//POIactive.errorCallback ----------------------------------
POIactive.errorCallback = function(Nc, Oc) {
    // TOC.display(Req.getErrorHtml(Nc));
};

//--------------------------------------------------------------
//POIactive.ReadPOIactive ------------------------------------
POIactive.ReadPOIactive = function(MapID, inputPOI_ID, inputData) {
var Moptions = Map.MapObj[MapID];
    //TImap_ActiveID = inputPOI_ID;
    Moptions.MapActivePOI = inputPOI_ID;
    var InputValue = inputData.split(";");
    TI_activeInfo = new TI_activeInfo_Rec(InputValue);
    if (TI_activeInfo.Type == "TRI") {
        TRI_activeInfo = TI_activeInfo;
    }
}
//--------------------------------------------------------------




////==========================  TI_active_Info_Read   ========================|
//function TI_active_Info_Read(inputID, inputData) {
//    TImap_ActiveID = inputID;
//    var InputValue = inputData.split(";");
//    //var TOI_Point = new MapPoint(InputValue[3], InputValue[4]).transform(ctoMap.MapRect, new MapRect(0,0,ctoMap.ImageSize.w ,ctoMap.ImageSize.h));
//    //var TOI_Point = new MapPoint(InputValue[3], InputValue[4]).transform(ctoMap.MapRect,ctoMap.ImageRect);
//    TI_activeInfo = new TI_activeInfo_Rec(InputValue);
//    if (TI_activeInfo.Type == "TRI") {
//        TRI_activeInfo = TI_activeInfo;
//    }
//}

function TI_activeInfo_Rec(InputValue) {
    // this.Type =InputValue[1].substr(0,3);
    this.Gis_ID = InputValue[0];
    this.Type = InputValue[1];

    this.Code = InputValue[2];
    this.Name = InputValue[3];
    this.Xp = 0;
    this.Yp = 0;
    this.X = InputValue[4];
    this.Y = InputValue[5];
    this.aX1 = InputValue[6];
    this.aY1 = InputValue[7];
    this.aX2 = InputValue[8];
    this.aY2 = InputValue[9];
    //this.ZoomOver_S =InputValue[7];
    this.bX1 = InputValue[10];
    this.bY1 = InputValue[11];
    this.bX2 = InputValue[12];
    this.bY2 = InputValue[13];
    //this.ZoomNormal_S =InputValue[10];
    this.cX1 = InputValue[14];
    this.cY1 = InputValue[15];
    this.cX2 = InputValue[16];
    this.cY2 = InputValue[17];
    //this.ZoomClose_S =InputValue[13];
    this.QviewScale = InputValue[18];
    //  this.ObjectTopology = InputValue[19];
}


////-------------------------------------------------------------------------------------
//function ServerReguest_TI_active(ID) {
//    var ret = "";
//    ret += "&Reguest=TI_active";
//    ret += "&RegMapLang=" + Map_Lang;
//    ret += "&RegTI_ID=" + ID;
//    sendAJAXRequest(srvURL, ret, ServerResponse_TI_active);
//    CTO_MapLoadWait_Show();
//}
////-------------------------------------------------------------------------------------
//function ServerResponse_TI_active(response) {
//    if (response == null || response == "") { return };
//    var jsonR = JSON.parse(response);
//    //--------------------------------------------------------------
//    var MapID = 0;
//    var Mcode = Map.getMcodeFromMapID(MapID);
//    var Mdata = Map.MapObj[MapID];

//    clearInterval(Slide_Interval);
//    //TOIItem_Info_Event(null,'close');

//    if (jsonR.Response == "TI_active") {
//        TI_active_Info_Read(jsonR.RespTI_ID, jsonR.RespTI_active)
//        //TI_active_Info_Draw();
//        POIactive.refresh(MapID);
//    }
//    //CTO_MapLoadWait_Hide();
//    Progress.hide(MapID)
//}