

    var g_map;
    var g_state = 0;
    var g_infoWindow = null;
    var g_infoBubble = null;
    var g_featureName;
    var g_featureID;
    var g_featureBounds;
    var g_menuVisible = false;
    var g_pageMode = "DISPLAY";
    var g_canvasLabels = {};

    function Label(opt_options, text) {
        // Initialization
        this.setValues(opt_options);

        this.div_ = document.createElement('div');

        var div1 = document.createElement("div");
        this.div_.appendChild(div1);

        var div = document.createElement('div');
        div1.appendChild(div);


        div1.style.cssText = "border: 0px solid blue; width: 0px; height: 0px; line-height: 0px; padding: 0px; margin: 0px;";

        this.labelText = text;

        this.div_.style.cssText = "position: absolute;  top: 0px; left:0 ; z-index: 50; border: 0px solid black; background-color: transparent; line-height: 0px; padding: 0px; margin: 0px;";
		div.innerHTML = text;
       if (BrowserDetect.browser != "Explorer")
	        div.style.cssText = "position: relative; left: -50%; top: 0; color: #eeeeee; font-weight: bold; font-size: 9pt; white-space: nowrap;text-shadow: -1px 0 #555555, 0 1px #555555, 1px 0 #555555, 0 -1px #555555;";
	    else {
	        div.style.whiteSpace = "nowrap";
	        div.style.position = "relative";
	        div.style.left = "-50%";
	        div.style.top = "50%";
	        div.style.marginTop = "-8px";
	        div.style.paddingTop = "8px";
	        div.style.color = "#000000";
	        div.style.fontSize = "12px";
	        div.style.height = "12px";
	        div.style.filter = "progid:DXImageTransform.Microsoft.Shadow(Color=#ffffff, Direction=0, Strength=3) progid:DXImageTransform.Microsoft.Shadow(Color=#ffffff, Direction=90, Strength=3) progid:DXImageTransform.Microsoft.Shadow(Color=#ffffff, Direction=270, Strength=3) progid:DXImageTransform.Microsoft.Shadow(Color=#ffffff, Direction=180, Strength=3)";
	    }
	};
    Label.prototype = new google.maps.OverlayView;

    // Implement onAdd
    Label.prototype.onAdd = function () {

        var pane = this.getPanes().overlayLayer;
        pane.appendChild(this.div_);


        var me = this;
        this.listeners_ = [
           google.maps.event.addListener(this, 'position_changed',
               function () { me.draw(); }),
           google.maps.event.addListener(this, 'text_changed',
               function () { me.draw(); })
        ];
    };

    // Implement onRemove
    Label.prototype.onRemove = function () {
        //alert("remove");
        this.div_.parentNode.removeChild(this.div_);


        // InfoBubble is removed from the map, stop updating its position/text.
        for (var i = 0, I = this.listeners_.length; i < I; ++i) {
            google.maps.event.removeListener(this.listeners_[i]);
        }
    };

    // Implement draw
    Label.prototype.draw = function () {
        var projection = this.getProjection();
        var position = projection.fromLatLngToDivPixel(this.get('position'));

        var div = this.div_;
        div.style.left = position.x + 'px';
        div.style.top = position.y + 'px';
        //div.style.display = 'block';



        if (g_displayLabel == true)
            this.Show();
        else
            this.Hide();
    };

    Label.prototype.Hide = function () {
        this.div_.style.display = "none";
        this.div_.firstChild.style.display = "none";
        this.div_.firstChild.firstChild.display = "none";
    };

    Label.prototype.Show = function () {
        this.div_.style.display = "inline";
        this.div_.firstChild.style.display = "inline";
        this.div_.firstChild.firstChild.display = "inline";
    };

    Label.prototype.Close = function () {
        this.displayWindow = false;
        this.draw();
    };

    Label.prototype.Open = function (options) {
        this.setValues(options);
        this.displayWindow = true;
        this.draw();
    };

    Label.displayWindow = false;

    var g_displayLabel = false;

   
    // Label Overlay Class
    function LabelOverlay() { };


    LabelOverlay.prototype.SetVisible = function (b) { g_displayLabel = b; };

    LabelOverlay.prototype.Hide = function () {
    
    	for (key in g_canvasLabels) {
	        g_canvasLabels[key].Hide();
	    }
    
        for (var i = 0; i < g_labels.length; i++) {
            g_labels[i].Hide();
        }

    };

    LabelOverlay.prototype.Show = function () {
    	for (key in g_canvasLabels) {
	        g_canvasLabels[key].Show();
	    }

        for (var i = 0; i < g_labels.length; i++) {
            g_labels[i].Show();
        }

    };


    function MarkerLabel(opt_options, text, lineID) {
        // Initialization
        this.setValues(opt_options);

        this.div_ = document.createElement('div');

        var div1 = document.createElement("div");
        this.div_.appendChild(div1);

        var div = document.createElement('div');
        div1.appendChild(div);


        div1.style.cssText = "border: 0px solid blue; width: 0px; height: 0px; line-height: 0px; padding: 0px; margin: 0px;";

        this.labelText = text;

        this.div_.style.cssText = "position: absolute;  top: 0px; left:0 ; z-index: 50; border: 0px solid black; background-color: transparent; line-height: 0px; padding: 0px; margin: 0px;";

        //div.innerHTML = text;
        div.style.cssText = "position: relative; left: -50%; top: 20px; border: 0px solid red; color: white; font-weight: bold; font-size: 9pt; white-space: nowrap;";




        var link = document.createElement("a");
        link.href = "/AppPages/Pages/Survey-Brochure.aspx?sid=" + lineID;
        link.target = "_blank";
        //link.style.cssText = "border: 0px solid green; background-color: transparent; font-weight: bold; font-size: 9pt; white-space: nowrap; padding: 2px;"
        if (BrowserDetect.browser != "Explorer")
            link.style.cssText = "color: #EDDA74; font-weight: bold; font-size: 9pt; white-space: nowrap;text-shadow: -1px 0 #555555, 0 1px #555555, 1px 0 #555555, 0 -1px #555555;";
        else {
            //div.style.cssText = "position: relative; left: -50%; top: 0; border: 0px solid red; color: blue; font-weight: bold; font-size: 9pt; white-space: nowrap;"
            link.style.whiteSpace = "nowrap";
            link.style.color = "#EDDA74";
            link.style.fontSize = "12px";
            link.style.fontWeight = "bold";
            //link.style.height = "16px";
            /*
            div.style.position = "relative";
            div.style.top = "50%";
            div.style.paddingTop = "14px";
            div.style.height = "16px";
            div.style.filter = "progid:DXImageTransform.Microsoft.Shadow(Color=#000000, Direction=0, Strength=1) progid:DXImageTransform.Microsoft.Shadow(Color=#000000, Direction=90, Strength=1) progid:DXImageTransform.Microsoft.Shadow(Color=#000000, Direction=270, Strength=1) progid:DXImageTransform.Microsoft.Shadow(Color=#000000, Direction=180, Strength=1)";
            */
        }

        link.innerHTML = text;
        /*
        if (text = "View Brochure") {
            
        }
        */

        div.appendChild(link);

        
        google.maps.event.addDomListener(this.div_, 'mousedown', CancelBubble);
        google.maps.event.addDomListener(this.div_, 'click', CancelBubble);              // cancels click 
        google.maps.event.addDomListener(this.div_, 'dblclick', CancelBubble);          // cancels double click 
        google.maps.event.addDomListener(this.div_, 'contextmenu', CancelBubble);  // cancels double right click 

    };
    MarkerLabel.prototype = new google.maps.OverlayView;

    // Implement onAdd
    MarkerLabel.prototype.onAdd = function () {

        var pane = this.getPanes().floatPane;
        pane.appendChild(this.div_);


        var me = this;
        this.listeners_ = [
           google.maps.event.addListener(this, 'position_changed',
               function () { me.draw(); }),
           google.maps.event.addListener(this, 'text_changed',
               function () { me.draw(); })
        ];
    };

    // Implement onRemove
    MarkerLabel.prototype.onRemove = function () {
        //alert("remove");

        google.maps.event.clearListeners(this.div_, 'mousedown', CancelBubble);
        google.maps.event.clearListeners(this.div_, 'click', CancelBubble);              // cancels click 
        google.maps.event.clearListeners(this.div_, 'dblclick', CancelBubble);          // cancels double click 
        google.maps.event.clearListeners(this.div_, 'contextmenu', CancelBubble);  // cancels double right click 

        this.div_.parentNode.removeChild(this.div_);


        // InfoBubble is removed from the map, stop updating its position/text.
        for (var i = 0, I = this.listeners_.length; i < I; ++i) {
            google.maps.event.removeListener(this.listeners_[i]);
        }
    };

    // Implement draw
    MarkerLabel.prototype.draw = function () {
        var projection = this.getProjection();
        var position = projection.fromLatLngToDivPixel(this.get('position'));

        var div = this.div_;
        div.style.left = position.x + 'px';
        div.style.top = position.y + 'px';
        //div.style.display = 'block';



        if (this.displayWindow == true) {

            this.div_.style.display = "inline";
            this.div_.firstChild.style.display = "inline";
            this.div_.firstChild.firstChild.display = "inline";

        }
        else {
            this.div_.style.display = "none";
            this.div_.firstChild.style.display = "none";
            this.div_.firstChild.firstChild.display = "none";

        }

    };

    MarkerLabel.prototype.Close = function () {
        this.displayWindow = false;
        this.draw();
    };

    MarkerLabel.prototype.Open = function (options) {
        this.setValues(options);
        this.displayWindow = true;
        this.draw();
    };

    MarkerLabel.prototype.Show = function () { this.displayWindow = true; };

    MarkerLabel.prototype.Hide = function () { this.displayWindow = false; };


    MarkerLabel.displayWindow = false;

    function BrochureLabelOverlay() { this.label_ = new MarkerLabel(null, "", ""); };

    BrochureLabelOverlay.prototype.SetVisible = function (b) { this.label_.displayWindow = b; };
    BrochureLabelOverlay.prototype.Hide = function () {
        this.label_.setMap(null);
    };

    BrochureLabelOverlay.prototype.Show = function () {
        this.label_.setMap(g_map);
    };



   

    

  
   


   
   

    function ShowCustomInfoBubble(e, name, id) 
    {
        if (g_infoWindow != undefined)
            g_infoWindow.close();

        
        
        g_featureName = e.row["seis_line_name"].value;
        g_featureID = id;
        g_featureBounds = e.latLng.lng() + "," + e.latLng.lat() + ",450000";
        
        ClearInfoWindow();

        g_treeRefresh = false;
        g_infoBubble.Open({ position: e.latLng });

        SubmitInfo();
        //g_treeRefresh = true;
    }

            
    //////////////////////////////////////////////////////////////////////////////////
    // Map Layer Management


    function setupNewLayer(layer) {
        var url = layer.url;

        // Handle getting the bounds onto the URL for bound layers
        if (layer.needsBounds) {
            var bounds = g_map.getBounds();

            if (bounds == undefined)
                return;

            url = url.replace("$west", bounds.getSouthWest().lng());
            url = url.replace("$south", bounds.getSouthWest().lat());

            url = url.replace("$east", bounds.getNorthEast().lng());
            url = url.replace("$north", bounds.getNorthEast().lat());
        }

        // construct the kml and fme layers.
        if (layer.layerType == "kml" || layer.layerType == "fme") {
            var layerObj = new google.maps.KmlLayer(url, layer.layerOptions);
            google.maps.event.addListener(layerObj, "click", OnKMLLayerClick);
            layer.layerObject = layerObj;
        }
        // construct the fusion layer
        else if (layer.layerType == "fusion") {

            var layerObj = new google.maps.FusionTablesLayer(url, layer.layerOptions);
            google.maps.event.addListener(layerObj, "click", function(event){OnFusionLayerClick(layer, event)});

            layer.layerObject = layerObj;

        }
        else if (layer.layerType == "overlay") {

        }

    }

    function setupLayerBounds(layer) {
        var url = layer.url;
        var bounds = g_map.getBounds();

        url = url.replace("$west", bounds.getSouthWest().lng());
        url = url.replace("$south", bounds.getSouthWest().lat());

        url = url.replace("$east", bounds.getNorthEast().lng());
        url = url.replace("$north", bounds.getNorthEast().lat());

        try {
            if (layer.tempLayerObject != undefined)
                layer.tempLayerObject.setMap(null);
        }
        catch (err)
        { log(err.toString()); }


        //layer.tempLayerObject = layer.layerObject;
        try {
            layer.layerObject.setMap(null);
        }
        catch (err) {
            log(err.toString());
        }


        var layerObj = new google.maps.KmlLayer(url, layer.layerOptions);
        google.maps.event.addListener(layerObj, "click", OnKMLLayerClick);
        layer.layerObject = layerObj;
    }


    function setOverlayForZoomLevel() {
        var zoom = g_map.getZoom();

        for (var i in g_mapData.layers) {
            var layer = g_mapData.layers[i];

            if (layer.layerType != "overlay")
                continue;

            if (layer.enabled != true)
                return;

            if (zoom >= layer.minScale && zoom <= layer.maxScale)
                layer.layerObject.SetVisible(true);
            else
                layer.layerObject.SetVisible(false);

        }


    }


    // Toggle layers on and off as defined by there scale.
    function setLayersForZoomLevel() {

        var zoom = g_map.getZoom();



//		alert("starting len is: " + g_mapData.layers.length);
        for (i = 0; i < g_mapData.layers.length; i ++) {
            var layer = g_mapData.layers[i];

            // we are not going to handle overlays in this routine
            // we will handle them in ZoomChanged()
            if (layer.layerType == "overlay")
                continue;

            if (!layer.enabled)
                continue;

            // Should the layer be on?
            if (zoom >= layer.minScale && zoom <= layer.maxScale) {
                // Check to see if it isn't already on
                if (!layer.visible) {

                    // Check to see if we already have a layer object
                    if (layer.layerObject == null) {

                        setupNewLayer(layer);

                    }

                    // turn the layer on.
                    layer.visible = true;
                    layer.layerObject.setMap(g_map);

                }
                else  // The layers is already visible and should remain on.
                {
                    // Check to see if this layer requires bounds
                    if (layer.needsBounds) {
                        setupLayerBounds(layer);


                        layer.visible = true;
                        layer.layerObject.setMap(g_map);

                    }

                }

            }
            // The layer is on but is not within zoom range so we turn it off.
            else if (layer.visible) {

                try {
                    layer.layerObject.setMap(null);
                    layer.visible = false;

                    if (layer.tempLayerObject != undefined)
                        layer.tempLayerObject.setMap(null);
                }
                catch (err) {
                    //log(err.toString());
                }


            }
          //  alert("starting len is: " + g_mapData.layers.length + " -- i is: " + i);
        }
    }



    //////////////////////////////////////////////////////////////////////////////////
    // Map Options & Layer Control

    function setMapOptionChecked() {
        var mapType = g_map.getMapTypeId();
        switch (mapType) {
            case google.maps.MapTypeId.TERRAIN:
                document.getElementById("optTerrain").checked = true;
                break;
            case google.maps.MapTypeId.SATELLITE:
                document.getElementById("optSatellite").checked = true;
                break;
            case google.maps.MapTypeId.ROADMAP:
                document.getElementById("optStreets").checked = true;
                break;
        }
    }

    function findLayer(id) {
        for (i=0; i < g_mapData.layers.length; i++) {
            if (g_mapData.layers[i].id == id)
                return g_mapData.layers[i];
        }
    }

    function toggleLayer(chk, layerID) {
        var layer = findLayer(layerID);

        if (layer == undefined || layer == null)
            log("Error: Could not find layer " + layerID);


        switch (layer.layerType) {
            case "overlay":
                toggleOverlayLayer(chk, layer);
                break;

            default:
                toggleMapLayer(chk, layer);
                break;



        }


    }

    function toggleOverlayLayer(chk, layer) {
        if (chk.checked == true) {
            layer.enabled = true;
            layer.visible = false;
            setOverlayForZoomLevel();
            layer.layerObject.Show();
        }
        else {
            layer.enabled = false;
            layer.layerObject.SetVisible(false);
            layer.layerObject.Hide();
        }
    }

    function toggleMapLayer(chk, layer) {

        var name = layer.name;

        if (layer.id == "id3D")
        {
			var lblChk = document.getElementById("chkid3DLabel")
			if (lblChk)
				lblChk.checked = chk.checked;
				
            toggleOverlayLayer(chk, findLayer("id3DLabel"));
        }

        for (var i in g_mapData.layers) {
            var tmpLayer = g_mapData.layers[i];
            if (tmpLayer.name == name) {
                if (chk.checked == true) {
                    tmpLayer.enabled = true;
                    tmpLayer.visible = false;
                    

                }
                else {
                    tmpLayer.enabled = false;
                    if (tmpLayer.layerObject != null)
                        tmpLayer.layerObject.setMap(null);
                }
                var tmpChk = document.getElementById("chk" + tmpLayer.id);
				tmpChk.checked = chk.checked;
            }
        }

        if (chk.checked == true)
            setLayersForZoomLevel();
        else
            layer.layerObject.setMap(null);
    }

	function setupMenuControls()
	{
		var menu = document.getElementById("idLayerCheckbox");

        //menu.innerHTML = "";
        //var tmpArrLyrs = new Array();
		for (i = 0; i < g_mapData.layers.length; i++) {
		    var layer = g_mapData.layers[i];
		    var rowDiv;
		    //if(tmpArrLyrs.indexOf(layer.id) < 0)
		    //{
		    	rowDiv = document.createElement("div");
			    rowDiv.id = "div" + layer.id;
				var n = document.createElement("input");
	            n.type = "checkbox";
	            n.id = "chk" + layer.id;
	            
	            if (layer.enabled)
	            	n.checked = true;
	            /*
				alert(n.id + " - " + layer.id);
				if(n.addEventListener){
		           	n.addEventListener("click", function(){toggleLayer(n,layer.id)}, false);
	           	}else if(n.attachEvent){
	           		n.attachEvent("onclick", function(){toggleLayer(n,layer.id)});
	           	}
	           		n.style.display = "none";           	
	           	*/
	           	var att = document.createAttribute("onclick");
	            att.nodeValue = "toggleLayer(this,'" + layer.id + "');";
	            n.setAttributeNode(att);
	            //n.style.display = "none";           	
	           	//var att = document.createAttribute("onclick");
	            //att.nodeValue = "toggleLayer(this,'" + layer.id + "');";
	            //n.setAttributeNode(att);
	            rowDiv.appendChild(n);
	            
	
	            var l = document.createElement("label");
	            l.id = "lbl" + layer.id;
	            att = document.createAttribute("for");
	            att.nodeValue = n.id;
	            l.setAttributeNode(att);
	            l.innerHTML = layer.name;
				//l.style.display = "none";
				//menu.appendChild(l);
				rowDiv.appendChild(l);
	            //menu.appendChild(document.createElement("br"));
	            rowDiv.style.display = "none";
	            menu.appendChild(rowDiv);
			//}
		}
	}

    function openMenu() {

        g_menuVisible = true;

        var menu = document.getElementById("idLayerCheckbox");

       // menu.innerHTML = "";



        var zoom = g_map.getZoom();


        for (var i in g_mapData.layers) {


            var layer = g_mapData.layers[i];
			var rowDiv = document.getElementById("div" + layer.id);
			
            if (zoom >= layer.minScale && zoom <= layer.maxScale && layer.displayInLegend) 
            {
            	var n = document.getElementById("chk" + layer.id);
                //var l = document.getElementById("lbl" + layer.id);
                
//          	if (layer.enabled){
  //        	    n.checked = true;
            	    rowDiv.style.display = "block";
                    //n.style.display = "block";
					//l.style.display = "block";
    //          }else{
        //  	    n.checked = false;
      //    	    rowDiv.style.display = "none";
                    //n.style.display = "none";
                    //l.style.display = "none";
//               }
                /*
                var n = document.createElement("input");
                n.type = "checkbox";
                n.id = "chk" + layer.id;

                if (layer.enabled)
                    n.checked = true;
                else
                    n.checked = false;

                var att = document.createAttribute("onclick");
                att.nodeValue = "toggleLayer(this,'" + layer.id + "');";
                n.setAttributeNode(att);

                menu.appendChild(n);

                var l = document.createElement("label");
                att = document.createAttribute("for");
                att.nodeValue = n.id;
                l.setAttributeNode(att);
                l.innerHTML = layer.name;

                menu.appendChild(l);
                menu.appendChild(document.createElement("br"));
                */

            }
            else
            {
            	if(rowDiv)
	            	rowDiv.style.display = "none";
            }


        }

        var m = document.getElementById("idMenu");

        m.style.visibility = "visible";
    }

    function closeMenu() {
        var m = document.getElementById("idMenu");

        m.style.visibility = "hidden";
        g_menuVisible = false;
    }

    function setMapType(o) {
        switch (o.value) {
            case "Terrain":
                g_map.setMapTypeId(google.maps.MapTypeId.TERRAIN);
                break;

            case "Satellite":
                g_map.setMapTypeId(google.maps.MapTypeId.SATELLITE);
                break;

            case "Streets":
                g_map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
                break;


        }
    }

    var g_marker = null;
    function NodeClicked(id, type, max_lat, min_lng, min_lat, max_lng, name, lineID, forceRefresh) {


        var ne = new google.maps.LatLng(max_lat, max_lng);

        var sw = new google.maps.LatLng(min_lat, min_lng);

        var bounds = new google.maps.LatLngBounds(sw, ne);

        if (type == "SURVEY" && !forceRefresh)
            g_treeRefresh = false;
        else
            g_treeRefresh = true;

        g_map.fitBounds(bounds);



        var center = g_map.getCenter();
        if (g_marker != null)
            g_marker.setMap(null);

        g_marker = new google.maps.Marker({
            position: center,
            map: g_map,
            title: name
        });



        g_marker.setAnimation(google.maps.Animation.DROP);

        layer = findLayer("idBrochureLabel");

        layer.layerObject.Hide();


        if (type == "SURVEY") {



            layer.layerObject.label_ = new MarkerLabel({ map: g_map, position: center }, "View Flyer", lineID);
            layer.layerObject.label_.displayWindow = true;

            //g_markerLabel = new MarkerLabel({ map: g_map, position: center }, "View Brochure", lineID);
            //g_markerLabel.displayWindow = true;
            //g_markerLabel.bindTo("position", g_marker, "position");
            //g_markerLabel.bindTo("text", g_marker, "position");  
        }

    }
    var g_markerLabel = null;

    //////////////////////////////////////////////////////////////////////////////////
    // Google info bubble stuff


   
    function ShowGoogleInfoBubble(e, text)
    {

        CloseCustomInfoBubble();


        var ifc = { content: text,
        position: e.latLng, 
        maxWidth: 9200,
        disableAutoPan: true };

        if (g_infoWindow != undefined)
        {
            g_infoWindow.close();
            g_infoWindow.setOptions(ifc);
            //g_infoWindow.open(g_map);
        }
        else
        {
            g_infoWindow = new google.maps.InfoWindow(ifc);

            google.maps.event.addListener(g_infoWindow, "domready", SubmitInfo);
            google.maps.event.addListener(g_infoWindow, "closeclick", InfoWindowClosing)
            google.maps.event.addListener(g_infoWindow, "position_changed", InfoWindowPositionChanged);

            g_infoWindow.open(g_map);
        }


        g_infoWindow.open(g_map);
    }

    function InfoWindowPositionChanged()
    {
        
    }

    function InfoWindowClosing()
    {
       
    }
    


   

function findPos(obj) 
    {
	    var curleft = curtop = 0;
        if (obj.offsetParent) 
        {
            do 
            {
			    curleft += obj.offsetLeft;
			    curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);

        }

        return [curleft, curtop];
    }
    function log(msg)
    {
        setTimeout(function ()
        {
            throw new Error(msg);
        }, 0);
    }

     function CloseCustomInfoBubble()
    {
        
        CancelBubble();
        
        g_infoBubble.Close();
    }
        
    function CancelBubble(e)
    {

        try {

            e = (e) ? e : window.event;

            if (e.bubbles == undefined)
                e.cancelBubble = true;
            else 
            {
                if (e.bubbles)
                    e.stopPropagation();
                
            }
        }
        catch(e)
        {}
    }


     var g_labelHash = {};
    var g_labels = new Array();
    function DrawLabels(labelData)
    {
        
        var zoom = g_map.getZoom();

        if (zoom >=9 )
        {
            var val =  labelData; 

            if (val == "")
                return;

            var labels = val.split(",");

            for (var i = 0; i < labels.length; i++)
            {
                var lbl = labels[i].split("|");

                if (g_labelHash[lbl[3]] == undefined)
                {
                    var ll = new google.maps.LatLng(lbl[2],lbl[1]);

                    var lab = new Label({map: g_map, position: ll}, lbl[0]);
                
                    lab.displayWindow = true;

                    g_labelHash[lbl[3]] = lbl[3];
                    g_labels[g_labels.length] = lab;
                }
                
                
            }
        }
    }


	function DrawLabels1(labelData) {
    var val = labelData;

    if (val == "")
        return;

    var labels = val.split(",");

    for (var i = 0; i < labels.length; i++) {
        var lbl = labels[i].split("|");
        if (g_canvasLabels[lbl[3]] == undefined) {
            var mapLabel = new MapLabel({
                text: lbl[0],
                position: new google.maps.LatLng(lbl[2], lbl[1]),
                map: g_map,
                fontSize: 12,
                minZoom: 9,
                maxZoom: 20
            });
            g_canvasLabels[lbl[3]] = mapLabel;
        }

    }
}

    function ShowInqWindow(link, email, surveyName, button, remarkControl)
    {
        
        //var text = document.getElementById("ctl00_bc_txtRemark");
        //text.value = "Please send me information regarding surveys in this area: " + g_featureName;

/*
        var f = "";

        if (BrowserDetect.browser != "Explorer")
        {
            f = "dialogHeight: 650px; dialogWidth: 520px; scroll: no;";
        }
        else
            f= "dialogHeight: 600px;";

        window.showModalDialog("/Pages/RequestInfo.aspx", "Please send me information regarding surveys in this area: " + g_featureName, f);

        CancelBubble();
        
*/        
        
        if(surveyName == "")
        	surveyName = g_featureName;
        	
        var url = "http://www.olysei.com/AppPages/Pages/Survey-Brochure.aspx?sid=" + g_featureID;


		//var text = document.getElementById("ctl00_bc_txtRemark");
        remarkControl.value = "Please send information regarding surveys in this area: " + surveyName + "\n\n";
		remarkControl.value += url;
     

        button.click();

//        window.location.href = "mailto:" + email + "?subject=" + "Information request for survey " + surveyName;
        
      
        
    }

    
    function OpenBrochure(lineID, originator)
    {
        var url = "/AppPages/Pages/Survey-Brochure.aspx?sid=" + lineID + "&o=" + originator;

        window.open(url);

        CancelBubble();
    }



	if (!Array.prototype.indexOf) {
	  Array.prototype.indexOf = function (obj, startIndex) {
	    if (startIndex == null) {
	        startIndex = 0;
	    } else if (startIndex < 0) {
	        startIndex = Math.max(0, this.length + startIndex);
	    }
	    for (var i = startIndex, j = this.length; i < j; i++) {
	        if (this[i] === obj)
	            return i;
	    }
	    return -1;
	  };
	}



function OpenSendPopup(hdnSndLink, txtSndLink, currentUrl) {
    
    var bounds = g_map.getBounds();
    var neBounds = bounds.getNorthEast().lat() + "," + bounds.getNorthEast().lng();
    var swBounds = bounds.getSouthWest().lat() + "," + bounds.getSouthWest().lng();
    var zoom = g_map.getZoom();
    var enabledLayers = "";
    var mapType;
    var tmpMapType = g_map.getMapTypeId();

    switch (tmpMapType) {
        case google.maps.MapTypeId.TERRAIN:
            mapType = "t";
            break;
        case google.maps.MapTypeId.SATELLITE:
            mapType = "s";
            break;
        case google.maps.MapTypeId.ROADMAP:
            mapType = "r";
            break;
    }


    for (var i in g_mapData.layers) {
        var layer = g_mapData.layers[i];
        if (layer.enabled) {
            if (enabledLayers == "")
                enabledLayers = layer.id;
            else
                enabledLayers += "," + layer.id;
        }
    }
    var url = currentUrl + "&b=" + g_map.getBounds().toUrlValue() + "&t=" + mapType + "&z=" + zoom + "&ref=em&el=" + enabledLayers;
    txtSndLink.value = url;
    hdnSndLink.value = url;

    //link.href = "mailto:?subject=Map link from <%=_companyName%>&body=Map link: " + url;
    
    var mpeSnd = $find("bmpeSnd");
    mpeSnd.show();

}

function SendPageLink(btnSndOk, btnSndCancel) {
    
    //btnSndOk.disabled = true;
    //btnSndCancel.disabled = true;
    //var bmpeSnd = $find("bmpeSnd");
    //bmpeSnd.show();
}

function OpenRequestInfoPopup(link) {

    var mpeReq = $find("bmpeReq");
    mpeReq.show();

}


function BuildReportLinks(lineID, originator, dcsViewerRootWebAddress) {
    var divBubbleRpt = document.getElementById("divBubbleRpt");
    var i;
    var htmlContent = "";
    var url;

    for (i = 0; i < g_rptData.downloadLinks.length; i++) {
        var downloadLink = g_rptData.downloadLinks[i];

        if (downloadLink.enabled) {
        	if(downloadLink.originator == originator)
        	{
	            url = downloadLink.fmeAppLink + lineID;
	            htmlContent += "<div class=\"wp_arrow_bullet_item\">&nbsp;&#187;&nbsp;&nbsp;<a href=\"" + url + "\" target=\"blank\">" + downloadLink.title + "</a></div>";
	        }
        }
    }
    divBubbleRpt.innerHTML = htmlContent;

    var surveyLink = document.getElementById("idSurveyName");
    surveyLink.innerHTML = g_featureName;
    var dcs = document.getElementById("idDCSLink");
    if (BrowserDetect.browser != "Explorer") {
        var alertMsg = "javascript:alert('The DCSViewer Application only supports Microsoft Internet Explorer Browsers. \\n\\nWe apologize for the inconvenience.');";
        dcs.href = alertMsg;
        surveyLink.href = alertMsg;
    }
    else {
        var link = dcsViewerRootWebAddress + "/MapViewer.aspx?co=" + g_featureBounds + "&gl=t&ns=t";
        surveyLink.href = link;
        dcs.href = link;
    }

}

function OpenSignIn(link) {
    var mpeReq = $find("bmpeReq");
    mpeReq.hide();

    var mpeReqSignIn = $find("bmpeReqSignIn");
    mpeReqSignIn.show();

}

function UpdateBrochureLink(layer, e) {
    var divBrochure = document.getElementById("divBrochure");
    if (layer.enableBrochure) {
        divBrochure.innerHTML = "<a href=\"javascript:void(0)\" onclick='OpenBrochure(\"" + e.row["seis_line_id"].value + "\",\"" + e.row["originator"].value + "\");' class=\"bubble_banner_link\"><img alt=\"\" src=\"/Style Library/Seitel/Images/viewbrochure.png\" width=\"150\" height=\"72\" /></a>";
    } else {
        divBrochure.innerHTML = "<img alt=\"\" src=\"/Style Library/Seitel/Images/viewbrochuredisabled.png\" width=\"150\" height=\"72\" />";
    }
}




function refreshMap2() {

	for (i = 0; i < g_mapData.layers.length; i++ ) {
            var tmpLayer = g_mapData.layers[i];
            if (tmpLayer.layerType == "kml")
            {
            	var ind = tmpLayer.url.indexOf("&refdt=")
            	var tmpUrl = tmpLayer.url;
		        if (tmpLayer.layerType == "kml") {
		        	if(ind >= 0)
		            	tmpUrl = tmpLayer.url.substring(0, ind);
		            
		            tmpLayer.url = tmpUrl + "&refdt=" + + (new Date()).getTime();
		        }

	            if (tmpLayer.enabled && tmpLayer.visible) {
	                tmpLayer.enabled = false;
	                if (tmpLayer.layerObject != null)
	                    tmpLayer.layerObject.setMap(null);
	
	                if (tmpLayer.layerObject == null) {
	                    setupNewLayer1(tmpLayer);
	                }
	                tmpLayer.layerObject.setMap(g_map);
	                tmpLayer.enabled = true;
	            }
            }
        }
	
	
	
    setTimeout(function () {
        var re = new RegExp("googleapis");
        var currentImg = "";
        for (i = 0; i < document.images.length; i++) {
            currentImg = document.images[i];
            if (re.test(currentImg.src)) {
                currentImg.src = currentImg.src + "&" + (new Date()).getTime();
            }
        }

    }, 500);

}


function OpenMapViewer() {
    var retVal;
    retVal = window.showModalDialog("/SitePages/MapViewer.html", "", "dialogWidth:1030px;dialogHeight:740px;");
    alert(retVal);

}



function appendKMLDummyParams(currentDate)
{
	for (i = 0; i < g_mapData.layers.length; i++) {
	    var layer = g_mapData.layers[i];
	    var dtToday = new Date();
	    if(layer.layerType == "kml")
	    	layer.url = layer.url + "?dtt=" + currentDate;
	}
}



function adjustSize(trvLib, txtTreeHeightID, hdnWhatsNewStateID) {
    $('#s4-leftpanel-content').height(document.documentElement.clientHeight - $('#s4-leftpanel-content').offset().top - 6);
    var txtTreeHeight = document.getElementById(txtTreeHeightID);
    var hdnWhatsNewState = document.getElementById(hdnWhatsNewStateID);
    var subtrahend;
    if (hdnWhatsNewState.value == "1")
        subtrahend = 162;
    else {
        subtrahend = 61;
    }
    $(trvLib).height(document.documentElement.clientHeight - $('#s4-leftpanel-content').offset().top - subtrahend);
    txtTreeHeight.value = document.documentElement.clientHeight - $('#s4-leftpanel-content').offset().top - subtrahend;
}


function SetMapBounds(referrer, tmpBounds, center, zoom, mapType, tmpEnabledLayers) {
    var ne;
    var sw;
    var skipZoom = false;

    if (tmpBounds != "") {
        var bounds;
        var tmpBounds;
        if (referrer == "em" || referrer == "if") {
            if (tmpBounds != "") {
                var arrBounds = tmpBounds.split(",");
                sw = new google.maps.LatLng(arrBounds[0], arrBounds[1]);
                ne = new google.maps.LatLng(arrBounds[2], arrBounds[3]);
                bounds = new google.maps.LatLngBounds(sw, ne);
            }
            else
                skipZoom = true;
        }


        switch (mapType) {
            case "t":
                g_map.setMapTypeId(google.maps.MapTypeId.TERRAIN);
                document.getElementById("optTerrain").checked = true;
                break;
            case "s":
                g_map.setMapTypeId(google.maps.MapTypeId.SATELLITE);
                document.getElementById("optSatellite").checked = true;
                break;
            case "r":
                g_map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
                document.getElementById("optStreets").checked = true;
                break;
        }
        //bounds.extend(sw);
        //bounds.extend(ne);
        /*
        var arrTmpCenter = center.split(",");
        var llCenter = new google.maps.LatLng(arrTmpCenter[0], arrTmpCenter[1]);
        g_map.setCenter(llCenter);
        */
        g_map.fitBounds(bounds);
        if (referrer == "em" || (referrer == "if" && !skipZoom)) {
            var listener = google.maps.event.addListenerOnce(g_map, "zoom_changed", function () {
                var oldZoom = g_map.getZoom();
                g_map.setZoom(parseFloat(zoom));
            });


            setLayersForZoomLevel();

            var arrEnabledLayers = tmpEnabledLayers.split(",");

            for (i = 0; i < g_mapData.layers.length; i++) {
                var layer = g_mapData.layers[i];
                var lyrChkBox = document.getElementById("chk" + layer.id);

                if (arrEnabledLayers.indexOf(layer.id) >= 0) {
                    layer.enabled = true;
                    lyrChkBox.checked = true;
                } else {
                    layer.enabled = false;
                    lyrChkBox.checked = false;
                }
            }

            setLayersForZoomLevel();

        }
    }
}


function btnNTSSearchClick(hdnNTSVal, hdnSearchVal) {
    var txtNTSSearch = $("#txtNTSSearch");
    var s = txtNTSSearch.val();
    txtNTSSearch.toggle(true);
    var data = s.replace(/\-|_/g, "");
    if (data.length == 0) {
        alert("Please enter a search value.");
        return false;
    }
    hdnNTSVal.value = data;
    hdnSearchVal.value = s;
    return true;
}

function txtSurveySearchKeyUp(txtSurveySearch, btnNTSSearch) {
    var divSearchTypeTitle = $("#divSearchTypeTitle");
    var divSearchTypeEx = $("#divSearchTypeEx");
    if (txtSurveySearch.val().length == 2) {
        if (txtSurveySearch.val().match(/[^\d]/) == null) {
            txtSurveySearch.toggle(false);
            var txtNTSSearch = $("#txtNTSSearch");
            txtNTSSearch.mask("999-*");
            txtNTSSearch.toggle(true);
            txtNTSSearch.val(txtSurveySearch.val());
            txtNTSSearch.focus();
            divSearchTypeTitle.html("DLS or NTS Search");
            divSearchTypeEx.html("(e.g. 066-22-5, 106-E-01-A)");
        } else {
            divSearchTypeTitle.html("Survey or Area Search");
            divSearchTypeEx.html("");
        }
        
    } else if (txtSurveySearch.val().length == 0) {
        txtSurveySearch.val("");
        txtSurveySearch.toggle(true);
        var txtNTSSearch = $("#txtNTSSearch");
        divSearchTypeTitle.html("");
        divSearchTypeEx.html("");
        txtNTSSearch.toggle(false);
        btnNTSSearch.toggle(false);
        txtNTSSearch.val("");
        txtSurveySearch.focus();
    }
}

var isDataValid = false;

function txtNTSSearchKeyDown(txtSurveySearch, btnNTSSearch, hdnSearchMask, event) {
    var divSearchTypeTitle = $("#divSearchTypeTitle");
    var divSearchTypeEx = $("#divSearchTypeEx");
    var unicode = event.keyCode ? event.keyCode : event.charCode;
    if (unicode == 13) {
        if (isDataValid) {
            btnNTSSearch.click();
        } else {
            alert("Please enter a valid " + divSearchTypeTitle.html() + " entry.");
            event.returnValue = false;
        }
        return false;
    }
    return true;
}

function txtNTSSearchKeyUp(txtSurveySearch, btnNTSSearch, hdnSearchMask, event) {
    var divSearchTypeTitle = $("#divSearchTypeTitle");
    var divSearchTypeEx = $("#divSearchTypeEx");
    var txtNTSSearch = $("#txtNTSSearch");
    var s = txtNTSSearch.val();
    var data = s.replace(/\-|_/g, "");
    //var unicode = event.keyCode ? event.keyCode : event.charCode;
    
    isDataValid = false;
    if (data == "") {
        txtSurveySearch.val("");
        txtSurveySearch.toggle(true);
        txtNTSSearch.toggle(false);
        btnNTSSearch.toggle(false);
        divSearchTypeTitle.html("");
        divSearchTypeEx.html("");
        txtNTSSearch.val("");
        hdnSearchMask.value = "";
        txtSurveySearch.focus();
    } else if (data.length >= 3) {
        if (data.length == 3) {
            txtNTSSearch.mask("999-*");
            btnNTSSearch.toggle(false);
            txtNTSSearch.focus();
            divSearchTypeTitle.html("DLS or NTS Search");
            hdnSearchMask.value = "999-*";
            divSearchTypeEx.html("(e.g. 066-22-5, 106-E-01-A)");
        } else if (data.length == 4) {        
            if (isNaN(data.substring(3, 4))) {
                btnNTSSearch.toggle(true);
                isDataValid = true;
                txtNTSSearch.mask("999-a-99");
                //txtNTSSearch.val(s + String.fromCharCode(event.which));
                txtNTSSearch.focus();
                divSearchTypeTitle.html("NTS Search");
                divSearchTypeEx.html("(e.g. <b>106-E</b>-01-A)");
                hdnSearchMask.value = "999-a-99";

            } else {
                txtNTSSearch.mask("999-99-9");
                //txtNTSSearch.val(s + String.fromCharCode(event.which));
                //txtNTSSearch.val(s);
                txtNTSSearch.focus();
                divSearchTypeTitle.html("DLS Search");
                divSearchTypeEx.html("(e.g. 066-22-5)");
                hdnSearchMask.value = "999-99-9";
            }
        } else if (data.length == 5) {
            if (isNaN(data.substring(3, 4))) {
                divSearchTypeEx.html("(e.g. <b>106-E-01</b>-A)");
            }else{
                divSearchTypeEx.html("(e.g. 066-22-5)");
            }
            btnNTSSearch.toggle(false);  
        } else if (data.length == 6) {
            if (isNaN(data.substring(3, 4))) {
                btnNTSSearch.toggle(true);
                isDataValid = true;
                if (data.match(/^\d\d\d[a-z]/i)) {
                    txtNTSSearch.mask("999-a-99-a");
                    divSearchTypeEx.html("(e.g. <b>106-E-01</b>-A)");
                    txtNTSSearch.focus();
                    hdnSearchMask.value = "999-a-99-a";
                }
            } else {
                btnNTSSearch.toggle(true);
                isDataValid = true;
                divSearchTypeEx.html("(e.g. <b>066-22-5</b>)");
            }
        } else if (data.length == 7) {
            btnNTSSearch.toggle(true);
            isDataValid = true;
            divSearchTypeEx.html("(e.g. <b>106-E-01-A</b>)");
        }
    }
}



/*
function SetupNTSSearch(txtSurveySearch) {
    //alert(txtSurveySearch.parent().html());
    var txtNTSSearch = $("#txtNTSSearch");
    txtNTSSearch.mask("999-*");
    txtSurveySearch.keyup(function (event) {
        alert("survey keyup");
        if (txtSurveySearch.val().length == 2) {
            if (txtSurveySearch.val().match(/[^\d]/) == null) {
                txtSurveySearch.toggle(false);
                txtNTSSearch.toggle(true);
                txtNTSSearch.val(txtSurveySearch.val());
                txtNTSSearch.focus();
            }
        } else if (txtSurveySearch.val().length == 0) {
            txtSurveySearch.val("");
            txtSurveySearch.toggle(true);
            txtNTSSearch.toggle(false);
            txtNTSSearch.val("");
            txtSurveySearch.focus();
        }
    });
    alert($("#txtNTSSearch").length);

    $("#txtNTSSearch").keyup(function () {
        alert("up here");
    });
    
    txtNTSSearch.keyup(function (event) {
        alert("search keyup");
        var s = txtNTSSearch.val();
        var data = s.replace(/\-|_/g, "");
        if (data == "") {
            txtSurveySearch.val("");
            txtSurveySearch.toggle(true);
            txtNTSSearch.toggle(false);
            txtNTSSearch.val("");
            txtSurveySearch.focus();
        } else if (data.length >= 3) {
            if (data.length == 3) {
                txtNTSSearch.mask("999-*");
                txtNTSSearch.focus();
            } else {
                if (data.length == 4) {
                    if (isNaN(data.substring(3, 4))) {
                        txtNTSSearch.mask("999-a-99");
                        //txtNTSSearch.val(s + String.fromCharCode(event.which));
                        txtNTSSearch.focus();

                    } else {
                        txtNTSSearch.mask("999-99-9");
                        //txtNTSSearch.val(s + String.fromCharCode(event.which));
                        //txtNTSSearch.val(s);
                        txtNTSSearch.focus();
                    }
                } else if (data.length == 6) {
                    if (data.match(/^\d\d\d[a-z]/i)) {
                        txtNTSSearch.mask("999-a-99-a");
                        txtNTSSearch.focus();
                    }
                }
            }
        }
    });
}
*/


function DownloadPackage(url) {
    window.location.href = url;
    //alert("downloading...");
    //downloadURL(url);
}


var downloadURL = function (url) {
    var iframe;
    iframe = document.getElementById("hiddenDownloader");
    if (iframe === null) {
        iframe = document.createElement('iframe');
        iframe.id = "hiddenDownloader";
        iframe.style.visibility = 'hidden';
        document.body.appendChild(iframe);
    }
    iframe.src = url;
}


function ResetData(hdnSearchVal, txtNTSSearch, hdnSearchMask, txtSurveySearch, btnNTSSearch) {
    txtSurveySearch.toggle(false);
    txtNTSSearch.toggle(true);
    txtNTSSearch.mask(hdnSearchMask.val());
    txtNTSSearch.val(hdnSearchVal.val());
    txtNTSSearch.focus();
    btnNTSSearch.toggle(true);

    txtNTSSearchKeyUp(txtSurveySearch, btnNTSSearch, hdnSearchMask);

}



//////////////////////////////////////////////////////////////////////////////////
// Map Layer Management

function InfoBubble(opt_options, htmlNode) {
    // Initialization
    this.setValues(opt_options);

    this.htmlNode = htmlNode;

    // InfoBubble specific
    var span = this.span_ = document.createElement('div');

    span.style.cssText = 'position: absolute;  top: 0px; left: 0px; z-index: 100;' +
                      ' border: 0px solid black;  ';

    var div = this.div_ = document.createElement('div');
    this.arrow = document.createElement("img");
    this.arrow.style.cssText = "position: relative; z-index: 105; top: -74px; display: none;";
    this.arrow.src = "/Style%20Library/Seitel/Images/Arrow.gif";

    div.appendChild(this.arrow);
    div.appendChild(span);


    this.shadow = document.createElement("img");
    this.shadow.style.cssText = "position: absolute;  top: -239px; left: -20px; z-index: 97; display: none;";
    this.shadow.src = "/Style%20Library/Seitel/Images/shadow2.png";

    this.arrowShadow = document.createElement("img");
    this.arrowShadow.style.cssText = "position: absolute;  top: -80px; z-index: 99; display: none;";
    this.arrowShadow.src = "/Style%20Library/Seitel/Images/shadow-arrow.png";

    this.corners = document.createElement("img");
    this.corners.src = "/Style%20Library/Seitel/Images/roundpng2.png"
    this.corners.style.cssText = "position: absolute;  top: -345px; left: -110px; z-index: 98; width: 640px; height: 273px; display: none;";

    div.appendChild(this.corners);
    div.appendChild(this.shadow);
    div.appendChild(this.arrowShadow);

    div.style.cssText = 'position: absolute; display: none';

    var node = htmlNode;

    //html = node.outerHTML;

    node = node.parentNode.removeChild(node);

    this.span_.appendChild(node);


    google.maps.event.addDomListener(this.span_, 'mousedown', CancelBubble);
    google.maps.event.addDomListener(this.span_, 'click', CancelBubble);              // cancels click 
    google.maps.event.addDomListener(this.span_, 'dblclick', CancelBubble);          // cancels double click 
    google.maps.event.addDomListener(this.span_, 'contextmenu', CancelBubble);  // cancels double right click 

    //this.html_ = html;

    //this.span_.innerHTML = this.html_;

};


InfoBubble.prototype = new google.maps.OverlayView;

// Implement onAdd
InfoBubble.prototype.onAdd = function () {
    //alert("add");
    var pane = this.getPanes().floatPane;
    pane.appendChild(this.div_);

    // Ensures the InfoBubble is redrawn if the text or position is changed.
    var me = this;
    this.listeners_ = [
           google.maps.event.addListener(this, 'position_changed',
               function () { me.draw(); }),
           google.maps.event.addListener(this, 'text_changed',
               function () { me.draw(); })
        ];
};

// Implement onRemove
InfoBubble.prototype.onRemove = function () {

    google.maps.event.clearListeners(this.span_, 'mousedown', CancelBubble);
    google.maps.event.clearListeners(this.span_, 'click', CancelBubble);              // cancels click 
    google.maps.event.clearListeners(this.span_, 'dblclick', CancelBubble);          // cancels double click 
    google.maps.event.clearListeners(this.span_, 'contextmenu', CancelBubble);  // cancels double right click 

    this.div_.parentNode.removeChild(this.div_);
    this.span_.parentNode.removeChild(this.span_);

    // InfoBubble is removed from the map, stop updating its position/text.
    for (var i = 0, I = this.listeners_.length; i < I; ++i) {
        google.maps.event.removeListener(this.listeners_[i]);
    }
};

// Implement draw
InfoBubble.prototype.draw = function () {
    var projection = this.getProjection();
    var position = projection.fromLatLngToDivPixel(this.get('position'));

    var div = this.div_;
    div.style.left = position.x + 'px';
    div.style.top = position.y + 'px';
    div.style.display = 'block';



    if (this.displayWindow == true) {
        this.htmlNode.style.display = "inline";
        this.arrow.style.display = "inline";
        this.arrowShadow.style.display = "inline";
        this.shadow.style.display = "inline";
        this.corners.style.display = "inline";

    }
    else {
        this.htmlNode.style.display = "none";
        this.arrow.style.display = "none";
        this.arrowShadow.style.display = "none";
        this.shadow.style.display = "none";
        this.corners.style.display = "none";
    }

};

InfoBubble.prototype.Close = function () {
    this.displayWindow = false;
    this.draw();
};

InfoBubble.prototype.Open = function (options) {
    this.setValues(options);
    this.displayWindow = true;
    this.draw();


    var projection = this.getProjection();
    var position = projection.fromLatLngToDivPixel(this.get('position'));
    position.y -= 125;
    position.x += 293;

    var center = projection.fromDivPixelToLatLng(position);



    if (BrowserDetect.browser == "Explorer" && BrowserDetect.version <= 8)
        g_map.setCenter(center);
    else
        g_map.panTo(center);




};

InfoBubble.displayWindow = false;














function BuildReportLinks1(lineID, originator, dcsViewerRootWebAddress) {
    var divBubbleRpt = document.getElementById("divBubbleRpt");
    var i;
    var htmlContent = "";
    var url;

    if (g_rptData.downloadLinks) {
        for (i = 0; i < g_rptData.downloadLinks.length; i++) {
            var downloadLink = g_rptData.downloadLinks[i];

            if (downloadLink.enabled) {
                if (downloadLink.originator == originator) {
                    url = downloadLink.fmeAppLinkParams + lineID;
                    if (BrowserDetect.browser == "Explorer" && BrowserDetect.version < 9) {
                        htmlContent += "<a href=\"javascript:void(0)\" onclick=\"ShowDownloadNotification();openWindow('win_" + (new Date()).getTime() + "','/_layouts/Seitel.CMS.CustomApplicationPages/Redirector.aspx?rt=fd&p=" + escape(url) + "&o=" + originator + "\',300,300,true,true,true,true,true,true,true);\" target=\"_blank\">" + downloadLink.title + "</a>";
                    } else {
                        htmlContent += "<a href=\"javascript:DownloadPackage('" + url + "');\">" + downloadLink.title + "</a>";
                    }

                }
            }
        }
    }

    if (g_rptData.reportLinks) {
        for (i = 0; i < g_rptData.reportLinks.length; i++) {
            var reportLink = g_rptData.reportLinks[i];

            if (reportLink.enabled) {
                if (reportLink.originator == originator) {
                    url = dcsViewerRootWebAddress + "/PublicReportViewer.aspx?gl=t&ID=" + reportLink.reportID + "&MapLines='" + lineID + "'";
                    $("#divBubbleReport").html("<a href=\"" + url + "\" target=\"blank\">" + reportLink.text + "</a>");
                    $("#divBubbleReportImg").html("<a href=\"" + url + "\" target=\"blank\"><img src=\"/Style Library/Seitel/Images/reporticobig.png\"/></a>");
                }
            }
        }
    }


    divBubbleRpt.innerHTML = htmlContent;

    var surveyLink = document.getElementById("idSurveyName");
    surveyLink.innerHTML = g_featureName;
    var dcs = document.getElementById("idDCSLink");
    if (BrowserDetect.browser != "Explorer") {
        var alertMsg = "javascript:alert('The DCSViewer Application only supports Microsoft Internet Explorer Browsers. \\n\\nWe apologize for the inconvenience.');";
        dcs.href = alertMsg;
        //surveyLink.href = alertMsg;
    }
    else {
        var link = dcsViewerRootWebAddress + "/MapViewer.aspx?co=" + g_featureBounds + "&gl=t&ns=t";
        //surveyLink.href = link;
        dcs.href = link;
    }
}



function ClearInfoWindow() {

    document.getElementById("idWaitImage").style.visibility = "visible";
    document.getElementById("idPCR_GRID").innerHTML = "&nbsp;";
    document.getElementById("idCMPL_DATE").innerHTML = "&nbsp;";
    document.getElementById("idLINE_LGTH").innerHTML = "&nbsp;";
    document.getElementById("idBIN_SIZE").innerHTML = "&nbsp;";
    document.getElementById("idSRC_LINE_ORIENTATION").innerHTML = "&nbsp;";
    document.getElementById("idENVRNMNT").innerHTML = "&nbsp;";
    document.getElementById("idENERGY_SRC_DESCRIPTION").innerHTML = "&nbsp;";
    document.getElementById("idSHPT_INTRVL").innerHTML = "&nbsp;";
    document.getElementById("idRCVR_LINE_ORIENTATION").innerHTML = "&nbsp;";
    document.getElementById("idRECEIVER_ARRAY").innerHTML = "&nbsp;";
    document.getElementById("idGROUP_INTERVAL").innerHTML = "&nbsp;";
    document.getElementById("idNUM_TRACES").innerHTML = "&nbsp;";
    document.getElementById("idSPREAD").innerHTML = "&nbsp;";

    document.getElementById("idLeftProducts").innerHTML = "&nbsp;";
    document.getElementById("idRightProducts").innerHTML = "&nbsp;";

}



function FillInfoContent(surveyInfo) {


    document.getElementById("idWaitImage").style.visibility = "hidden";
    var info = surveyInfo

    //alert(info);

    var parts = info.split("|");

    var values = parts[0].split(",");


    document.getElementById("idPCR_GRID").innerHTML = (values[1] == undefined) ? "Unavailable" : values[0] + "&nbsp;";
    document.getElementById("idCMPL_DATE").innerHTML = (values[1] == undefined) ? "Unavailable" : values[2] + "&nbsp;";
    document.getElementById("idLINE_LGTH").innerHTML = (values[2] == undefined) ? "Unavailable" : values[1] + "&nbsp;";
    document.getElementById("idBIN_SIZE").innerHTML = (values[3] == undefined) ? "Unavailable" : values[3] + "&nbsp;";
    document.getElementById("idSRC_LINE_ORIENTATION").innerHTML = (values[4] == undefined) ? "Unavailable" : values[4] + "&nbsp;";
    document.getElementById("idENVRNMNT").innerHTML = (values[5] == undefined) ? "Unavailable" : values[5] + "&nbsp;";
    document.getElementById("idENERGY_SRC_DESCRIPTION").innerHTML = (values[6] == undefined) ? "Unavailable" : values[6] + "&nbsp;";
    document.getElementById("idSHPT_INTRVL").innerHTML = (values[7] == undefined) ? "Unavailable" : values[7] + "&nbsp;";
    document.getElementById("idRCVR_LINE_ORIENTATION").innerHTML = (values[8] == undefined) ? "Unavailable" : values[8] + "&nbsp;";
    document.getElementById("idRECEIVER_ARRAY").innerHTML = (values[9] == undefined) ? "Unavailable" : values[9] + "&nbsp;";
    document.getElementById("idGROUP_INTERVAL").innerHTML = (values[10] == undefined) ? "Unavailable" : values[10] + "&nbsp;";
    document.getElementById("idNUM_TRACES").innerHTML = (values[11] == undefined) ? "Unavailable" : values[11] + "&nbsp;";
    document.getElementById("idSPREAD").innerHTML = (values[12] == undefined) ? "Unavailable" : values[12] + "&nbsp;";

    document.getElementById("idLeftProducts").innerHTML = "";
    document.getElementById("idRightProducts").innerHTML = "";

    if (parts.length < 2) {
        document.getElementById("idLeftProducts").innerHTML = "&nbsp;";
        document.getElementById("idRightProducts").innerHTML = "&nbsp;";
        return;
    }
    values = parts[1].split(",");
    var hasProducts = false;

    for (var i = 0; i < values.length; i++) {
        hasProducts = true;
        var li = document.createElement("li");
        //li.innerHTML = values[i];
        //li.setAttribute("class", "products");
        li.innerHTML = "&bull;&nbsp;" + values[i];

        if (li.innerHTML.length > 0)
            switch (i % 2) {
            case 0:
                document.getElementById("idLeftProducts").appendChild(li);
                break;
            case 1:
                document.getElementById("idRightProducts").appendChild(li);
                break;
        }
    }

    if (!hasProducts) {
        document.getElementById("idLeftProducts").innerHTML = "&nbsp;";
        document.getElementById("idRightProducts").innerHTML = "&nbsp;";
    } else {
        if(values.length < 2)
            document.getElementById("idRightProducts").innerHTML = "&nbsp;";
    }

    g_treeRefresh = true;
}
