if (typeof (km_scripts) == 'undefined') var km_scripts = new Object();
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
km_myclass_import(gaJsHost + "google-analytics.com/ga.js");

try {
    var pageTracker = _gat._getTracker("UA-9522013-1");
    pageTracker._trackPageview();
} catch (err) { }

function km_myclass_import(jsFile) {
    if (km_scripts[jsFile] != null) return;
    var scriptElt = document.createElement('script');
    scriptElt.type = 'text/javascript';
    scriptElt.src = jsFile;
    document.getElementsByTagName('head')[0].appendChild(scriptElt);
    km_scripts[jsFile] = jsFile; // or whatever value your prefer
}



// JScript File
var CMap_arrMap = new Array();


function CMap_writeFlash(div_id, id, flash_name, width, height, color, transparent, FlashVars) {
    var element = document.getElementById(div_id)
    if (element) {
        element.innerHTML = CMap_toString(id, flash_name, width, height, color, transparent, FlashVars);
    }
}

function CMap_toString(id, flash_name, width, height, color, transparent, FlashVars) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return CMap_toStringForExplorer(id, flash_name, width, height, color, transparent, FlashVars);
    }
    else {
        return CMap_toStringForStandard(id, flash_name, width, height, color, transparent, FlashVars);
    }
}

function CMap_toStringForExplorer(id, flash_name, width, height, color, transparent, FlashVars) {
    var str = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"";
    str += " id=\"" + id + "\"";
    str += " codebase=\"" + location.protocol + "//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0\"";
    str += " width=\"" + width + "\" ";
    str += " height=\"" + height + "\"";
    str += ">";
    if (typeof FlashVars != "undefined") {
        str += "<param name=\"FlashVars\" value=\"" + FlashVars + "\" />";
    }
    str += "<param name=\"width\" value=\"" + width + "\" />";
    str += "<param name=\"height\" value=\"" + height + "\" />";
    str += "<param name=\"movie\" value=\"" + flash_name + "\" />";
    str += "<param name=\"allowFullScreen\" value=\"true\" />";
    str += "<param name=\"allowNetworking\" value=\"all\" />";
    str += "<param name=\"allowscriptaccess\" value=\"always\" />";
    str += "<param name=\"wmode\" value=\"" + transparent + "\" />";
    str += "<param name=\"bgcolor\" value=\"" + color + "\" />";
    str += "</object>";
    return str;
}

function CMap_toStringForStandard(id, flash_name, width, height, color, transparent, FlashVars) {
    var str = "<embed src=\"" + flash_name + "\" width=\"" + width + "\" height=\"" + height + "\" salign=\"tl\" scale=\"noScale\" quality=\"high\" ";
    if (typeof FlashVars != "undefined") {
        str += "FlashVars=\"" + FlashVars + "\" ";
    }
    str += "type=\"application/x-shockwave-flash\" ";
    str += "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" ";
    str += "id=\"" + id + "\"";
    str += "allowFullScreen=\"true\" ";
    str += "allowNetworking=\"all\" ";
    str += "allowscriptaccess=\"always\" ";
    str += "wmode=\"" + transparent + "\" ";
    str += "bgcolor=\"" + color + "\" ";
    str += "></embed>";
    return str;
}

function CMap_getMapByID(mapID) {
    for (var i = 0; i < CMap_arrMap.length; i++) {
        if (CMap_arrMap[i].mapID == mapID) {
            return CMap_arrMap[i];
        }
    }
    return null;
}

function CMap_initMap(mapID) {    
    var map = CMap_getMapByID(mapID);
    map.setMapMode();
    map.addMarker(map.strMarker);
    map.drawShape(map.strShape);
    this.strShape = "";
    if (map.markerID != "") {
        map.showMarker();
    }
    else {
        map.setMapCenter();
    }
    map.setMapCenterDefault();
    map.callFuncCalled();
    if (map.okShowNSearch) {
        map.showNSearch();
    }
    if (map.okShowLabelCenter) {
        map.showLabelCenter();
    }
    else {
        map.hideLabelCenter();
    }
    if (map.okShowQuyHoach) {
        map.show_btnQuyHoach(map.HienThiQuyHoach);
    }
    if (map.okShowVHXH) {
        map.show_btnVHXH(map.HienThiVHXH);
    }
}

function CMap_centerChange(mapID, Lat, Lng, Zoom) {
    var map = CMap_getMapByID(mapID);
    map.onMapCenterChange(mapID, Lat, Lng, Zoom);
}

function CMap_newMarkerChange(mapID, Lat, Lng) {
    var map = CMap_getMapByID(mapID);
    map.onNewMarkerChange(mapID, Lat, Lng);    
}

function CMap_mapClick(mapID, Lat, Lng) {
    var map = CMap_getMapByID(mapID);
    map.onMapClick(mapID, Lat, Lng);
}

function CMap_btnNSearch_onClick(mapID) {
    var map = CMap_getMapByID(mapID);
    map.btnNSearch_onClick(mapID);
}

function CMap_btnDrawSave_onClick(mapID, markerID, strCenter, strPoly, strArea) {
    var map = CMap_getMapByID(mapID);
    map.btnDrawSave_onClick(mapID, markerID, strCenter, strPoly, strArea);
}

function CMap(mapID, divID, width, height) {
    this.defineConstant();
    this.divID = divID;
    this.mapID = mapID;
    this.arrFuncCalled = new Array();
    this.arrArgFuncCalled = new Array();
    this.mapMode = this.SATELITE;
    this.LatDefault = 21.03067;
    this.LngDefault = 105.85241;
    this.Lat = 21.0406875;
    this.Lng = 105.7386017;
    this.Zoom = 18;
    this.strMarker = "";
    this.strShape = "";
    this.markerID = "";
    this.allowSetMarkerCenter = 1;
	this.allowShowInfo = 1;
    this.okShowNSearch = false;
    this.okShowLabelCenter = false;
    this.okShowQuyHoach = false;
    this.okShowVHXH = false;
    CMap_arrMap.push(this);
    this.load(divID, width, height);
    try {
        var pageTracker = _gat._getTracker("UA-9522013-1");
        pageTracker._trackPageview();
    } catch (err) { }
}

CMap.prototype.defineConstant = function() {
    this.SATELITE = 1;
    this.MAP = 2;
    this.BOTH = 4;
    this.PLANNING = 8;

    this.CENTER_CHANGE = "Center change";
    this.NEW_MARKER_CHANGE = "New marker change";
    this.MAP_CLICK = "Map click";
    this.NSEARCH_CLICK = "NSearch click";
    this.DRAWSAVE_CLICK = "Draw save";

    this.FUNC_setMarkerVisible = "setMarkerVisible";
    this.FUNC_setMarkerTitle = "setMarkerTitle";
    this.FUNC_changeNewMarkerMode = "changeNewMarkerMode"
}

CMap.prototype.load = function(divID, width, height) {
    CMap_writeFlash(divID, this.mapID, "http://nmap.oneres.net/bando/map.swf", width, height, "#EEEEFF", "transparent", "mapID=" + this.mapID);
    //CMap_writeFlash(divID, this.mapID, "http://localhost:1318/DinhVi/resources/BanDo_090903/map.swf", width, height, "#EEEEFF", "transparent", "mapID=" + this.mapID);
}

CMap.prototype.callFuncCalled = function() {
    for (var i = 0; i < this.arrFuncCalled.length; i++) {
        switch (this.arrFuncCalled[i]) {
            case this.FUNC_setMarkerVisible:
                this.setMarkerVisible(this.arrArgFuncCalled[i][0], this.arrArgFuncCalled[i][1]);
                break;

	    case this.FUNC_setMarkerTitle:
                this.setMarkerTitle(this.arrArgFuncCalled[i][0], this.arrArgFuncCalled[i][1]);
                break;

            case this.FUNC_changeNewMarkerMode:
                this.changeNewMarkerMode(this.arrArgFuncCalled[i][0]);
                break;
        }
    }
}

CMap.prototype.addListener = function(eventID, func) {
    switch (eventID) {
        case this.CENTER_CHANGE:
            this.onMapCenterChange = func;
            break;

        case this.NEW_MARKER_CHANGE:
            this.onNewMarkerChange = func;            
            break;

        case this.MAP_CLICK:
            this.onMapClick = func;
            break;

        case this.NSEARCH_CLICK:
            this.btnNSearch_onClick = func;
            break;
            
        case this.DRAWSAVE_CLICK:
            this.btnDrawSave_onClick = func;
            break;
    }
}

CMap.prototype.setMapMode = function(mapMode) {
    if (typeof mapMode != "undefined") {
        this.mapMode = mapMode;
    }
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.setMapMode != "undefined") {
        fmap.setMapMode(this.mapMode);
    }
}

CMap.prototype.setMarkerVisible = function(markerID, visible) {
    var fmap = document.getElementById(this.mapID);

    if (fmap && typeof fmap.setMarkerVisible != "undefined") {
        fmap.setMarkerVisible(markerID, visible);
    }
    else {
        this.arrFuncCalled.push(this.FUNC_setMarkerVisible);
        var cs = this.arrFuncCalled.length - 1;
        this.arrArgFuncCalled[cs] = new Array(markerID, visible);
    }
}

CMap.prototype.setMarkerTitle = function(markerID, strTitle) {
    var fmap = document.getElementById(this.mapID);

    if (fmap && typeof fmap.setMarkerTitle != "undefined") {
        fmap.setMarkerTitle(markerID, strTitle);
    }
    else {
        this.arrFuncCalled.push(this.FUNC_setMarkerTitle);
        var cs = this.arrFuncCalled.length - 1;
        this.arrArgFuncCalled[cs] = new Array(markerID, strTitle);
    }
}

CMap.prototype.setMarkerAttribute = function(markerID, name, value) {
    var fmap = document.getElementById(this.mapID);

    if (fmap && typeof fmap.setMarkerAttribute != "undefined") {
        fmap.setMarkerAttribute(markerID, name, value);
    }
}

CMap.prototype.showMarker = function(markerID, allowSetMarkerCenter, allowShowInfo) {
    if (typeof markerID != "undefined") {
        this.markerID = markerID;
    }
    if (typeof allowSetMarkerCenter != "undefined") {
        this.allowSetMarkerCenter = allowSetMarkerCenter;
    }
	if (typeof allowShowInfo != "undefined") {
        this.allowShowInfo = allowShowInfo;
    }
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.showMarker != "undefined" && this.markerID != "") {
        fmap.showMarker(this.markerID, this.allowSetMarkerCenter, this.allowShowInfo);
    }
}

CMap.prototype.getMapCenter = function() {
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.getMapCenter != "undefined") {
        return fmap.getMapCenter();
    }
    return null;
}

CMap.prototype.getMapZoom = function() {
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.getMapZoom != "undefined") {
        return fmap.getMapZoom();
    }
    return null;
}

CMap.prototype.setMapZoom = function(Zoom) {
    var fmap = document.getElementById(this.mapID);
	if (typeof Zoom != "undefined") this.Zoom = Zoom;
    if (fmap && typeof fmap.setMapZoom != "undefined") {
        return fmap.setMapZoom(this.Zoom);
    }
    return null;
}

CMap.prototype.setMapCenter = function(Lat, Lng, Zoom) {
    if (typeof Lat != "undefined") this.Lat = Lat;
    if (typeof Lng != "undefined") this.Lng = Lng;
    if (typeof Zoom != "undefined") this.Zoom = Zoom;
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.setMapCenter != "undefined") {
        fmap.setMapCenter(this.Lat, this.Lng, this.Zoom);
    }
}

CMap.prototype.setMapCenterDefault = function(Lat, Lng) {
    if (typeof Lat != "undefined") this.LatDefault = Lat;
    if (typeof Lng != "undefined") this.LngDefault = Lng;
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.setMapCenterDefault != "undefined") {
        fmap.setMapCenterDefault(this.LatDefault, this.LngDefault);
    }
}

CMap.prototype.getBottomLeftLatLng = function() {
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.getBottomLeftLatLng != "undefined") {
        return fmap.getBottomLeftLatLng();
    }
    return null;
}

CMap.prototype.getTopRightLatLng = function() {
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.getTopRightLatLng != "undefined") {
        return fmap.getTopRightLatLng();
    }
    return null;
}

CMap.prototype.getMapMode = function() {
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.getMapMode != "undefined") {
        return fmap.getMapMode();
    }
    return 0;
}

CMap.prototype.clearGraphic = function() {
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.clearGraphic != "undefined") {
        fmap.clearGraphic();
    }
}

CMap.prototype.drawRect = function(Lat1, Lng1, Lat2, Lng2, width, color) {
    if (typeof width == "undefined") {
        width = 1;
    }
    if (typeof color == "undefined") {
        color = 0xFF0000;
    }
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.drawRect != "undefined") {
        fmap.drawRect(Lat1, Lng1, Lat2, Lng2, width, color);
        return true;
    }
    return false;
}

CMap.prototype.drawShape = function(A) {
    if (typeof A == "undefined" || A == "") {
        return false;
    }
    
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.drawShape != "undefined") {
        var arr = A.split("#-#");
        var i;
        
        for (i = 0; i < arr.length; i++) {
            fmap.drawShape(arr[i]);
        }
        return true;
    }
    else {
        if (this.strShape != "") {
            this.strShape += "#-#" + A;
        }
        else {
            this.strShape = A;
        }
    }
    return false;
}



CMap.prototype.addMarker = function(A) {
    if (typeof A != "undefined" && A != "") {
        if (this.strMarker != "") {
            this.strMarker += "#-#" + A;
        }
        else {
            this.strMarker = A;
        }
        var fmap = document.getElementById(this.mapID);
        if (fmap && typeof fmap.addMarker != "undefined") {
            fmap.addMarker(A);
        }
    }    
}

CMap.prototype.changeNewMarkerMode = function(vtChinhXac) {
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.changeNewMarkerMode != "undefined") {        
        fmap.changeNewMarkerMode(vtChinhXac);
    }
    else {
        this.arrFuncCalled.push(this.FUNC_changeNewMarkerMode);
        var cs = this.arrFuncCalled.length - 1;
        this.arrArgFuncCalled[cs] = new Array(vtChinhXac);        
    }
}

CMap.prototype.hideInfoWindow = function() {
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.hideInfoWindow != "undefined") {
        fmap.hideInfoWindow();
    }
}

CMap.prototype.changeMapSize = function(width, height) {
    var fmap = document.getElementById(this.mapID);
    if (fmap) {
        this.unhideMap();
        if (width > 0 && height > 0) {
            if (parseInt(fmap.width) != width || parseInt(fmap.height) != height) {
                fmap.width = width;
                fmap.height = height;
            }
        }
        else {
            this.hideMap(BanDoID);
        }
    }
}

CMap.prototype.setDrawMode = function(LoaiHinh, width, color, bgr) {
    if (typeof LoaiHinh == "undefined") {
        LoaiHinh = 1;
    }
    if (typeof width == "undefined") {
        width = 2;
    }
    if (typeof color == "undefined") {
        color = 0xFF0000;
    }
    if (typeof bgr == "undefined") {
        bgr = 0x000000;
    }
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.setDrawMode != "undefined") {
        fmap.setDrawMode(LoaiHinh, width, color, bgr);
    }
}

CMap.prototype.show_btnQuyHoach_btnVHXH = function(HienThiQuyHoach, HienThiVHXH) {
    this.show_btnQuyHoach(HienThiQuyHoach);
    this.show_btnVHXH(HienThiVHXH);
}

CMap.prototype.show_btnQuyHoach = function(HienThiQuyHoach) {
    if (typeof HienThiQuyHoach == "undefined") {
        HienThiQuyHoach = 0;
    }
    this.okShowQuyHoach = true;
    this.HienThiQuyHoach = HienThiQuyHoach;
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.show_btnQuyHoach != "undefined") {
        return fmap.show_btnQuyHoach(HienThiQuyHoach);
    }
    return null;
}

CMap.prototype.show_btnVHXH = function(HienThiVHXH) {
    if (typeof HienThiVHXH == "undefined") {
        HienThiVHXH = 0;
    }
    this.okShowVHXH = true;
    this.HienThiVHXH = HienThiVHXH;
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.show_btnVHXH != "undefined") {
        return fmap.show_btnVHXH(HienThiVHXH);
    }
    return null;
}

CMap.prototype.showNSearch = function() {
    this.okShowNSearch = true;
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.showNSearch != "undefined") {
        return fmap.showNSearch();
    }
    return null;
}

CMap.prototype.showLabelCenter = function() {
    this.okShowLabelCenter = true;
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.showLabelCenter != "undefined") {
        return fmap.showLabelCenter();
    }
    return null;
}

CMap.prototype.hideLabelCenter = function() {
    this.okShowLabelCenter = false;
    var fmap = document.getElementById(this.mapID);
    if (fmap && typeof fmap.hideLabelCenter != "undefined") {
        return fmap.hideLabelCenter ();
    }
    return null;
}

CMap.prototype.hideMap = function() {
    var div = document.getElementById(this.divID);

    div.style.display = "none";
}

CMap.prototype.unhideMap = function() {
    var div = document.getElementById(this.divID);

    div.style.display = "";
}
