﻿// JScript File

    var map = null;
    var center = null;
    var geocoder = null;

    function gmpscRefreshCenter() {
    
        if (map) {
            GMPSCRCLoad(1, clientId);
        }
            
    }
    
    function GMPSCRCLoadCB(result) {
    
        if (result) {
            if (result.context) {
                var clientId = result.context;
                if (result.value) {
                    var e = dge(gs(clientId, 'RC'));
                    if (e) {
                        e.innerHTML = result.value;
                        
                        if (gs(clientId, 'rto' + clientId) != '') {
                            window.clearTimeout(gs(clientId,'rto' + clientId));
                        }
            
                        if (gs(clientId,'prto')!='') {
                            ss(clientId,'rto'+ clientId,setTimeout('GMPSCRCLoad(\'' + gs(clientId,'p') + '\',\'' + clientId + '\'); ', gs(clientId,'prto')));
                        }
                                    
                    }
                }
                TIHide(clientId);
            }
        }
    }
    
    function GMPSCRCLoad(pageNumber, clientId) {
    
        TIShow(clientId);
    
        ss(clientId, 'p', pageNumber);
    
        center = map.getCenter();
        
        if (center) {
    
            var lat = parseFloat(center.lat());
            var lng = parseFloat(center.lng());
            
            var bounds = map.getBounds();
            var hx = bounds.toSpan().x;
            var hy = bounds.toSpan().y;
            
            var ctcl = '-1';
            var e = dge(clientId + '_shwp');
            if (e && e.checked) ctcl+=',5';
            e = dge(clientId + '_shwv');
            if (e && e.checked) ctcl+=',12';
            e = dge(clientId + '_shwa');
            if (e && e.checked) ctcl+=',17';
            e = dge(clientId + '_shwb');
            if (e && e.checked) ctcl+=',16';
            e = dge(clientId + '_shwf');
            if (e && e.checked) ctcl+=',9';
            e = dge(clientId + '_shwc');
            if (e && e.checked) ctcl+=',21';

            // Added 11-05-2010 : pst        
            Webscene.UI.GMPSBC.GMPSCRCLoad(clientId, sessionId, nodeId, lng, lat, gs(clientId,'s'), gs(clientId,'p'), gs(clientId,'ps'), hx, hy, skin, ctcl, gs(clientId, 'noc'), gs(clientId + '_yf','y'), gs(clientId + '_yt','y'), gs(clientId,'pst'), gs(clientId,'tl'), GMPSCRCLoadCB, clientId);
            
        }
    
    }

    function GMPSBCLoad(clientId) {

        TIShow(clientId);
        // Added 27-12-2007
        if (typeof(GBrowserIsCompatible) != "undefined" ) {

            if (GBrowserIsCompatible()) {
          
                element = dge(gs(clientId,'IC'));
                
                if (element) { 
              
                    map = new GMap2(element);
                    GEvent.addListener(map, "moveend", gmpscRefreshCenter);         
                    if (window.attachEvent) {
                        window.attachEvent("unload",GUnload);
                    }
                    
                }

            }
                    
        }
        
        TIHide(clientId);
    
    }

    function GMarkerOptions() {} 
    GMarkerOptions.prototype = new Object(); 
    
    function GMPSCHide(clientId) {

        var tb = dge(gs(clientId,'tb'));        
        if (tb) {
            tb.style.display = 'block';
        }
//        var rc = dge(gs(clientId,'RC'));        
//        if (rc) {
//            rc.style.display = 'block';
//        }
            
        if (window.moShowPicture) { 
            moShowPicture(gs(clientId, "PV"),'', 0, 0); 
        }
        if (window.vvShowVideo) { 
            vvShowVideo(gs(clientId, "VV"),'', 0, 0); 
        }
        if (window.apPlayAudio) { 
            apPlayAudio(gs(clientId, "AP"),'', 0, 0); 
        }
        if (window.moShowDocument) { 
            moShowDocument(gs(clientId, "DV"),'', 0, 0); 
        }
        if (window.cvcShowCast) {
            cvcShowCast(gs(clientId, "CV"),'');
        }

        var lc = dge(gs(clientId, "LC"));
        if (lc) {
            lc.style.display = 'none';
        }
        var bb = dge(gs(clientId, "BB"));
        if (bb) {
            bb.style.display = 'none';
        }
        var e = dge(gs(clientId,'MC'));
        if (e) {
            e.style.display = 'none';
        }

        sh(clientId);
        
    }
    
    function GMPSCShow(clientId, cid, t) {

        TIShow(clientId);
//        var rc = dge(gs(clientId,'RC'));        
//        if (rc) {
//            rc.style.display = 'none';
//        }
        var tb = dge(gs(clientId,'tb'));        
        if (tb) {
            tb.style.display = 'none';
        }
        
        var mc = dge(gs(clientId,'MC'));
        if (mc) {
            mc.style.display = 'block';
        }
        
        if (t==5) {
        
            var e = dge(gs(clientId,'PV'));
    
            if (e) {
                e.style.display = 'block';
            }        
            
            if (window.moShowPicture) { 
                moShowPicture(gs(clientId, "PV"),cid, 0, 0); 
            }
        
        }
        
        if (t==29) {
        
            var e = dge(gs(clientId,'DV'));
    
            if (e) {
                e.style.display = 'block';
            }        
            
            if (window.moShowDocument) { 
                moShowDocument(gs(clientId, "DV"),cid, 0, 0); 
            }
        
        }
        
        if (t==12) {
        
            var e = dge(gs(clientId,'VV'));
    
            if (e) {
                e.style.display = 'block';
            }        
            
            if (window.vvShowVideo) { 
                vvShowVideo(gs(clientId, "VV"),cid, gs(gs(clientId,"VV"),'foc'), 0); 
            }
        }
        
        if (t==17) {
        
            var e = dge(gs(clientId,'AP'));
    
            if (e) {
                e.style.display = 'block';
            }        
            
            if (window.apPlayAudio) { 
                apPlayAudio(gs(clientId, "AP"),cid, 0, 0); 
            }
        }
        
        if (t==16) {
        
            var e = dge(gs(clientId,'LC'));
    
            if (e) {
                e.style.display = 'block';
                var op = 1;
                var result = Webscene.UI.GMPSBC.GMPSCShowBC(clientId, sessionId, nodeId, cid, skin, op);
                if (result) {
                    if (result.value) {
                        e.innerHTML = result.value;
                        RCRHGet(gs(clientId,'Rea'),cid, 1);
                    }
                }
            }        
            
        }
        
        if (t==9) {
        
            var e = dge(gs(clientId,'LC'));
    
            if (e) {
                e.style.display = 'block';
                var op = 1;
                var result = Webscene.UI.GMPSBC.GMPSCShowFIV(clientId, sessionId, nodeId, cid, skin, op, 1);
                if (result) {
                    if (result.value) {
                        e.innerHTML = result.value;
                        RCRHGet(gs(clientId,'Rea'),cid, 1);
                    }
                }
            }        
            
        }
        
        if (t==21) {
        
            var e = dge(gs(clientId,'CV'));
    
            if (e) {
                e.style.display = 'block';
            }        
            
            if (window.cvcShowCast) { 
                cvcShowCast(gs(clientId, "CV"),cid); 
            }
        }
        
        var bb = dge(gs(clientId, "BB"));
        if (bb) {
            bb.style.display = 'block';
        }
        
        TIHide(clientId);
        
        sh(clientId);

    }
    
    function GMPSCPlaceIcon(clientId, point, obj, url, cid, t, tt, d, iconUrl) {
    
        var wsIcon = new GIcon();

        wsIcon.image = iconUrl;
        wsIcon.shadow  = "http://www.google.com/mapfiles/shadow50.png";
        wsIcon.iconSize = new GSize(30, 30);
        wsIcon.shadowSize = new GSize(47, 30);
        wsIcon.iconAnchor = new GPoint(35, 30);
        wsIcon.infoWindowAnchor = new GPoint(9, 2);
        wsIcon.infoShadowAnchor = new GPoint(14, 2);
        
        TIShow(clientId);

        markerOptions = { icon: wsIcon };
    
        var marker = new GMarker(point, markerOptions);
        var image = '';
        if (url && url!='') {
            image = '<img style=\"padding:5px 5px 5px 5px;\" src=\"' + url + '\">';
        }

        if (map) {
            map.addOverlay(marker);
        }

        //GEvent.addListener(marker, "click", function() { map.removeOverlay(marker); GMPSCShow(clientId, cid, t); });
        marker.openInfoWindowHtml('<div class=\"LNK\" onclick="GMPSCShow(\'' + clientId + '\', \'' + cid + '\', ' + t + ');" style="align:left"><b>' + tt + '</b><br><br><div style="vertical-align:top;">' + image + '' + d + '</div></div>');
    
        TIHide(clientId);
    }
    
    // Creates a marker at the given point with the given number label
    function gmpscCreateMarker(point, alias, location, imageUrl, id, locType, locTypeLabel, dom) {
    
        var options = new GMarkerOptions();
        options.title = alias;
      
        var wsIcon = new GIcon();

        if (locType=='H') {
            wsIcon.image = 'Images/ContentType/ProfileIcon.gif';
        } else {
            wsIcon.image = 'Images/ContentType/ProfileIconCurrent.gif';
        }
        wsIcon.shadow  = "http://www.google.com/mapfiles/shadow50.png";
        wsIcon.iconSize = new GSize(30, 30);
        wsIcon.shadowSize = new GSize(47, 30);
        wsIcon.iconAnchor = new GPoint(35, 30);
        wsIcon.infoWindowAnchor = new GPoint(9, 2);
        wsIcon.infoShadowAnchor = new GPoint(14, 2);  
        
        options.icon = wsIcon;    
    
      var marker = new GMarker(point, options);
      GEvent.addListener(marker, "click", function() {
          var image = '';
          if (imageUrl!='') {
            image = '<img onClick=\"document.location=\'node.aspx?id=' + id + '\';\" src=\"' + imageUrl + '\">';
          }
          marker.openInfoWindowHtml('<div style="height:auto;"><b><a style="text-decoration:none; color:black;" target="_top" href=\"' + dom + '/node.aspx?id=' + id + '\">' + alias + '</a></b><br>' + image + '<br>' + location + ' (' + locTypeLabel + ')</div>');
      });
      return marker;
    }
    
    function GMPSCGetRelsCB(result) {
    
    if (result) {

        var clientId = result.context;
        if (result.value) {
        
            if ((gmpscLong>=-180) && (gmpscLat > -90)) {
        
                // Get a commalist with 0=lat,1=long,2=alias,3=location,4=image,5=nodeName
                var counter = 1;
                
                var pList = result.value.split("|");
                var decimalLong = -999;
                var decimalLat = -999;
                var alias = '';
                var place = '';
                var image = '';
                var id = '';
                var locType = '';
                var locTypeLabel = '';
                var dom = '';
                
                var numberOfProperties = 9;

                for (var i=0; i < pList.length; i++) {
                
                    if (i%numberOfProperties==0) {
                        decimalLat = pList[i];
                    }
                    
                    if (i%numberOfProperties==1) {
                        decimalLong = pList[i];
                    }
                    
                    if (i%numberOfProperties==2) {
                        alias = pList[i];
                    }

                    if (i%numberOfProperties==3) {
                    
                        place = pList[i];
                        
                    }

                    if (i%numberOfProperties==4) {
                    
                        image = pList[i];
                        
                    }
                    
                    if (i%numberOfProperties==5) {
                    
                        id = pList[i];
                        
                    }
                    
                    if (i%numberOfProperties==6) {
                    
                        locType = pList[i];
                        
                    }
                       
                    if (i%numberOfProperties==7) {
                    
                        locTypeLabel = pList[i];
                    
                    }
                       
                    if (i%numberOfProperties==8) {
                    
                        dom = pList[i];
                            
                        counter = counter + 1;
                        
                        map.addOverlay(gmpscCreateMarker(new GLatLng(decimalLat,decimalLong), alias, place, image, id, locType, locTypeLabel, dom));
                        
                        decimalLong = -999;
                        decimalLat = -999;
                        alias = '';
                        place = '';
                        id = '';
                        image = '';
                        locType = '';
                        locTypeLabel = '';
                        dom = '';
                        
                        
                    }
                
                }
                
            }
        
        }
        TIHide(clientId);
    }

}
          
    function GMPSCInit(clientId,initMap) {

        TIShow(clientId);
        
        if (map) {
            if (initMap) {
                map.addControl(new GLargeMapControl());
                map.addControl(new GMapTypeControl());
                if ((gmpscLong>=-180) && (gmpscLat > -90)) {
                    map.setCenter(new GLatLng(gmpscLat, gmpscLong), gs(clientId,'zl'));
                }
            }
            if (nodeId != '00000000-0000-0000-0000-000000000000') {
                Webscene.UI.GMPSBC.GMPSCBCGetRels(sessionId, nodeId, true, gs(clientId,'dom'), GMPSCGetRelsCB);
            }
        }
    }
    
    
    function GMPSBCGetTBCB(result) {
        if (result) {
            if (result.context) {
                var clientId = result.context;
                if (result.value) {
                    var e = dge(gs(clientId,'tb'));
                    if (e) {
                        e.innerHTML = result.value;
                    }
                }    
                TIHide(clientId);            
            }
        }
    }
    
    function GMPSBCGetTB(clientId) {
        
        TIShow(clientId);
        Webscene.UI.GMPSBC.GMPSBCGetTB(clientId, sessionId, nodeId, gs(clientId,'n'),gs(clientId,'sf'),gs(clientId + '_yf','y'), gs(clientId + '_yt','y'), gs(clientId,'sfi'), GMPSBCGetTBCB, clientId);

    }
    
    function GMPSBCSLCB(result) {
        if (result) {
            var clientId = result.context;
            ss(clientId, 'n','');
            GMPSBCGetTB(clientId);
            map.clearOverlays();
            GMPSCInit(false);
            TIHide(clientId);
        }
    }
    
    function GMPSCSL(clientId, locType) {
    
        TIShow(clientId);
        if (center) {
        
            if (gs(clientId, 'n') && gs(clientId, 'n')!='') {
                var lat = parseFloat(center.lat());
                var lng = parseFloat(center.lng());
                var zl = map.getZoom();

                Webscene.UI.GMPSBC.GMPSBCSL(clientId, sessionId, nodeId, lng, lat, gs(clientId, 'n'), locType, zl, GMPSBCSLCB, clientId);

            } else {
                ALByD('WS_GMPSBC_ERR_EmptyName',1);
            }
       
        }
        
    }
    
    function GMPSBCGotoCB(result) {
        if (result) {
            var clientId = result.context;
            if (result.value) {
    
                var l = result.value.split("|");
                var lat = -999;
                var lng = -999;
                var zl = 0;
                var mt = 0;
                var n = '';
            
                for (var i=0; i < l.length; i++) {
                                    
                    if (i%4==0) {
                        lat = l[i];
                    }
                                        
                    if (i%4==1) {
                        lng = l[i];
                    }

                    if (i%4==2) {
                        zl = l[i];
                    }
                    
                    if (i%4==3) {
                        n = l[i];
                    }
                    
                }
                
                ss(clientId, 'n', n);
                
                var e  = dge(clientId + '_n');
                if (e) {
                    e.value = gs(clientId, 'n');
                }
                
                if (map) {
                    map.setCenter(new GLatLng(lat, lng), parseInt(zl));
                    
                }
                
            }
            TIHide(clientId);
        }
    }
    
    function GMPSCGoto(clientId, lid) {
    
        TIShow(clientId);
        Webscene.UI.GMPSBC.GMPSBCGoto(clientId, sessionId, nodeId, lid, GMPSBCGotoCB, clientId);
        
    }
    
    function GMPSCDelL(clientId, lid) {
        var result = Webscene.UI.GMPSBC.GMPSBCDelL(clientId, sessionId, nodeId, lid);
        if (result) {
            var e  = dge(clientId + '_n');
            if (e) {
                ss(clientId, 'n', '');
                e.value = '';
            }
            GMPSBCGetTB(clientId);
        }
    }
    
    function GMPSBSrch(clientId) {
        TIShow(clientId);
        var t = dge(clientId + '_srch');
        if (t) {
            var a = t.value;
            if (!geocoder) {
                geocoder = new GClientGeocoder();
            }
            geocoder.getLatLng(a, 
            function(p) {      
                if (!p) {
                    ALByD('WS_GMPSBC_ERR_LocationNotFound',1);
                } else { 
                    map.setCenter(p, 13);       
                    var marker = new GMarker(p); 
                    map.addOverlay(marker);        
                    marker.openInfoWindowHtml(a);      
                }    
            });
        }
        TIHide(clientId);
    }

