﻿/*

This file contains the custom location object which houses all metadata coming back
from the SQL database. It also contains some helper methods for displaying location
information on a VE map.

*/

function Location(
    inSiteId,
    inSiteNumber,    
    inSiteName,
    inTowerNumber,
    inTowerName,
    inTowerType,
    inTowerStatus,
    inGroundElevation,
    inLatitude,
    inLongitude,
    inAddress1,
    inCity,
    inZip,
    inCounty,
    inState,
    inRegion,
    inArea,
    inMTA,
    inBTA,
    inMSARSA,
    inFAA,
    inFCC,
    inTowerLocation,
    inHeightAGL,
    inDistance
){
    // Constants

    // this line of code has been moved to /Utilities/SiteLocator_location.js
    //var brochurePrefix = "http://www.americantower.com/OASISPublic/SitePublicPage/SiteBrochure.asp?lngSiteID=";
    var SQLTowerLocationWireless = "Wireless";
    var SQLTowerLocationBroadcast = "Broadcast - Region";
    var SQLTowerLocationInBuilding = "In Building";
    var SQLTowerLocationManaged = "Managed";
    var SQLTowerLocationRooftop = "Rooftop";
    var SQLTowerLocationUnknown = "-- Unknown --";    

    // Members
    var _SiteId = inSiteId;
    var _SiteNumber = inSiteNumber;
    var _SiteName = inSiteName;
    var _TowerNumber = inTowerNumber;
    var _TowerName = inTowerName;
    var _TowerType = inTowerType;
    var _TowerStatus = inTowerStatus;
    var _GroundElevation = inGroundElevation;
    var _Latitude = trimFloat(inLatitude, 6);
    var _Longitude = trimFloat(inLongitude, 6);
    var _Address1 = inAddress1;
    var _City = inCity;
    var _Zip = inZip;
    var _County = inCounty;
    var _State = inState;
    var _Region = inRegion;
    var _Area = inArea;
    var _MTA = inMTA;
    var _BTA = inBTA;
    var _MSARSA = inMSARSA;
    var _FAA = inFAA;
    var _FCC = inFCC;
    var _TowerLocation = inTowerLocation;
    var _StructureHeightAGL = trimFloat(inHeightAGL, 2);
    var _Distance = trimFloat(inDistance);
    
    if (_TowerType.indexOf("--") >= 0){
        _TowerType = "Unknown";
    }
    
    var pin = null;
    
    // Getter for location's pushpin title.
    function _getPushpinTitle(){
       //Modified: return _SiteName;
       return _TowerName;
    }
    
    // Getter for location's pushpin content.
    function _getPushpinContent(pinId){
    
        // Pushpin content includes driving directions input form.
        var content =
		    "<div class='bubbleContainer'>" + 
			    "<table class='bubbleTable'>" +
				    "<tr>" +
					    "<td class='bubbleImageCell'>" +
						    "<img src='" + loadingImage + "' class='bubbleImage' id='bubbleImage_" + pinId + "'/>" +
					    "</td>" +
					    "<td class='bubbleDataCell'>" +
					        "<div class='bubbleDriveData' id='bubbleDriveData_" + pinId + "' style='display:none;'>" +
						        "<form id='DDInput_" + pinId + "' action = 'javascript:map.GetRoute(" + pinId + ")' method='GET'>" +
        					        "<div style='text-align:left;height:25px;'>Starting Address:</div>" +
              				        "<table class='bubbleInputTable' style='width:175px;'>" + 
               					        "<tr><td class='inputDDStreet'>Street</td><td><input type='text' id='txtDDStreet_" + pinId + "' size='14'/></td></tr>" +
			                            "<tr><td class='inputDDCity'>City</td><td><input type='text' id='txtDDCity_" + pinId + "' size='14' /></td></tr>" +
            					        "<tr><td class='inputDDState'>State</td><td><input type='text' id='txtDDState_" + pinId + "' size='14'/></td></tr>" +
            					        "<tr><td class='inputDDZip'>Zip</td><td><input type='text' id='txtDDZip_" + pinId + "' size='14'/></td></tr>" +
               					        "<tr><td colspan='2'>" +
            					            "<div class='inputDDSearch' style='text-align:right'><input type='submit' value='Go'/></div>" +
            					        "</td></tr>" +
							        "</table>" +
						        "</form>" +
						    "</div>" +
						    "<div class='bubbleData' id='bubbleData_" + pinId + "' style='display:block;'>" + _getContentDetails() + "</div>" +
					    "</td>" +
				    "</tr>" +
				    "<tr style='height: 25px;'>" +
					    "<td colspan='2' class='bubbleLinksCell'>" +
					        "<a href='" + _getURL() + "' target='_blank'>Brochure</a>" +
					        " | <a href='javascript:panel_results.ShowLocation2(" + pinId + ");'>Zoom to Street Level</a>" +
					        " | <a id='bubbleDDLink_" + pinId + "' href='javascript:map.ShowBubbleDDInput(" + pinId + ");'>Driving Directions</a>" +
					    "</td>" +
				    "</tr>" +
			    "</table>" +
		    "</div>";
		return content;
    }
    
    // Getter for location's brochure URL.
    function _getURL()
    {        
        return brochurePrefix + _SiteId;

    }
    
    // Getter for location's pushpin object for VP map.
    function _getPushpin(index){
    
        // Create a pushpin if the location does not have one.
        if (pin == null){
        
            // Assign pre-defined location image.
            if (_TowerLocation.indexOf(SQLTowerLocationBroadcast) != -1){
                image = pinBroadcast;
            }
            else if (_TowerLocation.indexOf(SQLTowerLocationInBuilding) != -1){
                image = pinInBuilding;
            }
            else if (_TowerLocation.indexOf(SQLTowerLocationRooftop) != -1){
                image = pinRooftop;
            }
            // All other towers get Wireless icon.
            else{// if (_TowerLocation.indexOf(SQLTowerLocationWireless) != -1){
                image = pinWireless;
            }
            /*
            else{
                image = null;
            }
            */
        
            // Instatiate the actual VE pushpin
            // deprived VEPushpin
            //pin = new VEPushpin(index + "_" + _SiteId, new VELatLong(_Latitude, _Longitude), image, _getPushpinTitle(), _getPushpinContent(_SiteId) );
            
            // v 6.1 as new VEShape(VEShapeType.Pushpin, latlong);
            pin = new VEShape(VEShapeType.Pushpin, new VELatLong(_Latitude, _Longitude));
            //Shape has no Custom ID use prototype ShapeCustomeID
            pin.CustomShapeID = index + "_"+ _SiteId;
            pin.SetCustomIcon(image);
            pin.SetTitle(_getPushpinTitle());
            pin.SetDescription(_getPushpinContent(_SiteId));
            
            
            
        }
        
        // Return the current or newly created pushpin.
        return pin;
    }
    
    // Getter for location's address - in a friendly format.    
    function _getFormattedAddress(){
        var formattedAddress = _Address1 + ", " + _City + ", " + _State + ", " + _Zip + ", USA";
        
        return formattedAddress;
    }
    
    // Getter for location's detailed information that will appear in the bubble.
    function _getContentDetails(){
    
        // Set displayable field names.
        var bubbleDisplayName = new Array("Tower No.", "Name", "Address", "Latitiude", "Longitude", "Height (AGL)", "Class");
        
        // Set displayable fields
        //modified:_SiteNumber-_TowerNumber, _SiteName-_TowerName
        var bubbleDisplayField = new Array(_TowerNumber, _TowerName, _getFormattedAddress(), _Latitude, _Longitude, _StructureHeightAGL + " ft", _TowerLocation);
        
        // Create details table.
        var contentDetails = "<table class='bubbleDetailsTable'>"
        
        for (var i = 0; i < bubbleDisplayName.length;i++){
            contentDetails += "<tr><td>" + bubbleDisplayName[i] + "</td><td>" + bubbleDisplayField[i] + "</td></tr>\n";
        }
        contentDetails += "</table>";
        
        return contentDetails;        
    }
    
    
    // Getter for location's coordinates.
    function _getCoordinates(){
        return new VELatLong(_Latitude, _Longitude);
    }
     
    /* Public accessors for the mentioned functions. */ 
     
    this.SiteId = _SiteId;
    this.SiteNumber = _SiteNumber;
    this.SiteName = _SiteName;
    this.TowerNumber = _TowerNumber;
    this.TowerName = _TowerName;
    this.TowerType = _TowerType;
    this.TowerStatus = _TowerStatus;
    this.GroundElevation = _GroundElevation;
    this.Latitude = _Latitude;
    this.Longitude = _Longitude;
    this.Address1 = _Address1;
    this.City = _City;
    this.Zip = _Zip;
    this.County = _County;
    this.State = _State;
    this.Region = _Region;
    this.Area = _Area;
    this.MTA = _MTA;
    this.BTA = _BTA;
    this.MSARSA = _MSARSA;
    this.FAA = _FAA;
    this.FCC = _FCC;
    this.TowerLocation = _TowerLocation;
    this.StructureHeightAGL = _StructureHeightAGL;
    this.Distance = _Distance;
        
    this.GetPushpin = _getPushpin;
    this.GetURL = _getURL;
    this.GetFormattedAddress = _getFormattedAddress;
    this.GetCoordinates = _getCoordinates;
}