﻿// Still to think about it//
var tileoverlays = Array();
var cRight = new GCopyrightCollection('Asim Nazir');
	
var copyright = new GCopyright(1,
      new GLatLngBounds(new GLatLng(53.8136257,-3.0981445),new GLatLng(53.8654855,-2.9663944) ),
      14, "Ordnance Survey");

var copyrightCollection = new GCopyrightCollection('Map Data:');
copyrightCollection.addCopyright(copyright);

/////////////////////////////////////////////

function GPoint2(x, y)
{   
    return new GLatLng(y, x);
}

function CreateCustomControls()
{
    CreateMapControl();
    CreateSatelliteControl();
    CreateHybridControl();    
}

function MapControl_GM()
{
}

function SatelliteControl()
{
}

function HybridControl()
{
}
function TerrainControl()
{
}

function CreateTerrainControl()
{
    TerrainControl.prototype = new GControl();
    
    TerrainControl.prototype.initialize = function(map) {
    var container = document.createElement("div");

    var TerrainDiv = document.createElement("div");
    this.setButtonStyle_(TerrainDiv);
    container.appendChild(TerrainDiv);
    TerrainDiv.appendChild(document.createTextNode("Terrain"));
    GEvent.addDomListener(TerrainDiv, "click", function() {
    map.setMapType(G_PHYSICAL_MAP);
    });

    map.getContainer().appendChild(container);
    return container;
    }
    
    TerrainControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(X_TERRAIN_TYPE, Y_TYPE));
    }

    TerrainControl.prototype.setButtonStyle_ = function(button) {
    button.style.backgroundColor = "#000000";
    button.style.textAlign = "center";
    button.style.width = WIDTH_TERRAIN_TYPE;
    button.style.cursor = "pointer";
    button.style.color = "#FFFFFF";
    button.style.padding = "2px";
    button.style.marginBottom = "3px";
    button.style.fontFamily = "Arial";
	button.style.fontSize = "9pt";
    }

    map.addControl(new TerrainControl());
}

function CreateHybridControl()
{
    HybridControl.prototype = new GControl();
    
    HybridControl.prototype.initialize = function(map) {
    var container = document.createElement("div");

    var hybridDiv = document.createElement("div");
    this.setButtonStyle_(hybridDiv);
    container.appendChild(hybridDiv);
    hybridDiv.appendChild(document.createTextNode("Hybrid"));
    GEvent.addDomListener(hybridDiv, "click", function() {
    map.setMapType(G_HYBRID_MAP);
    });

    map.getContainer().appendChild(container);
    return container;
    }
    
    HybridControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(X_HYBRID_TYPE, Y_TYPE));
    }

    HybridControl.prototype.setButtonStyle_ = function(button) {
    button.style.backgroundColor = "#000000";
    button.style.textAlign = "center";
    button.style.width = WIDTH_HYBRID_TYPE;
    button.style.cursor = "pointer";
    button.style.color = "#FFFFFF";
    button.style.padding = "2px";
    button.style.marginBottom = "3px";
    button.style.fontFamily = "Arial";
	button.style.fontSize = "9pt";
    }

    map.addControl(new HybridControl());
}

function CreateSatelliteControl()
{
    SatelliteControl.prototype = new GControl();
    
    SatelliteControl.prototype.initialize = function(map) {
    var container = document.createElement("div");

    var satelliteDiv = document.createElement("div");
    this.setButtonStyle_(satelliteDiv);
    container.appendChild(satelliteDiv);
    satelliteDiv.appendChild(document.createTextNode("Satellite"));
    GEvent.addDomListener(satelliteDiv, "click", function() {
    map.setMapType(G_SATELLITE_MAP);
    });

    map.getContainer().appendChild(container);
    return container;
    }
    
    SatelliteControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(X_SATELLITE_TYPE, Y_TYPE));
    }

    SatelliteControl.prototype.setButtonStyle_ = function(button) {
    button.style.backgroundColor = "#000000";
    button.style.textAlign = "center";
    button.style.width = WIDTH_SATELLITE_TYPE;
    button.style.cursor = "pointer";
    button.style.color = "#FFFFFF";
    button.style.padding = "2px";
    button.style.marginBottom = "3px";
    button.style.fontFamily = "Arial";
	button.style.fontSize = "9pt";
    }

    map.addControl(new SatelliteControl());
}

function CreateMapControl()
{
    MapControl_GM.prototype = new GControl();
    
    MapControl_GM.prototype.initialize = function(map) {
    var container = document.createElement("div");

    var mapDiv = document.createElement("div");
    this.setButtonStyle_(mapDiv);
    container.appendChild(mapDiv);
    mapDiv.appendChild(document.createTextNode("Map"));
    GEvent.addDomListener(mapDiv, "click", function() {
    map.setMapType(G_NORMAL_MAP);
    });

    map.getContainer().appendChild(container);
    return container;
    }
    
    MapControl_GM.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(X_MAP_TYPE, Y_TYPE));
    }

    MapControl_GM.prototype.setButtonStyle_ = function(button) {
    button.style.backgroundColor = "#000000";
    button.style.textAlign = "center";
    button.style.width = WIDTH_MAP_TYPE;
    button.style.cursor = "pointer";
    button.style.color = "#FFFFFF";
    button.style.padding = "2px";
    button.style.marginBottom = "3px";
    button.style.fontFamily = "Arial";
	button.style.fontSize = "9pt";
    }

    map.addControl(new MapControl_GM());
}

function ShowToolTip(marker)
{    
    toolTip.innerHTML = marker.tooltip;
	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());
	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var height=toolTip.clientHeight;
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
	pos.apply(toolTip);
	toolTip.style.visibility="visible";
}

function ErrorHandler(res)
{   
   var msg = res.get_exceptionType() + "\r\n";
   msg += res.get_message() + "\r\n";
   msg += res.get_stackTrace();
   alert(msg);
}

function TimeOutHandler(res)
{
   alert("Timeout :" + res);
}

function GetIconPath(idLkp, jsPage)
{
    return CreateIcon(GetMapMarkerPath(idLkp, jsPage));
}
function GetMarker_VEM(idLkp, jsPage)
{
     return GetMapMarkerPath(idLkp, jsPage);
}
function GetMapMarkerPath(idLkp, jsPage)
{
  // Commercial Properties
    if (jsPage == COMMERCIAL_FUNCTIONS)
    {
        if (idLkp == PROPERTY_STATUS_LISTING || idLkp == PROPERTY_STATUS_LISTING_ADVERTISE)
            return GetPath()+ "Pages/Markers/commercial_green.png";
        
        else if (idLkp == PROPERTY_STATUS_PENDING)
            return (GetPath()+ "Pages/Markers/commercial_orange.png");
            
        else if (idLkp == PROPERTY_STATUS_SOLD)
            return (GetPath()+ "Pages/Markers/commercial_red.png");
    }
    
    // Residential Properties
    else if (jsPage == RESIDENTIAL_FUNCTIONS)
    {
        if (idLkp == PROPERTY_STATUS_LISTING || idLkp == PROPERTY_STATUS_LISTING_ADVERTISE)
            return (GetPath()+ "Pages/Markers/residential_green.png");

        else if (idLkp == PROPERTY_STATUS_PENDING)
            return (GetPath()+ "Pages/Markers/residential_orange.png");
            
        else if (idLkp == PROPERTY_STATUS_SOLD)
            return (GetPath()+ "Pages/Markers/residential_red.png");
    }
    
    // WET
    else if (jsPage == WET)
    {   
        if (idLkp == "48 Hr. Circulation")
            return (GetPath()+ "Pages/Markers/purple.png");
            
        else if (idLkp == "Pre-Steam")
            return (GetPath()+ "Pages/Markers/yellow.png");
        
        else if (idLkp == "Wash Job")
            return (GetPath()+ "Pages/Markers/blue.png");
            
        else //if (idLkp == "24 Hr. Circulation")
            return (GetPath()+ "Pages/Markers/green.png");
    }
    
    // Oil Well
    else if (jsPage == OIL_WELL)
    {   
        return (GetPath()+ "Pages/Markers/Oil_marker.png");
    }
    
    // Deeds
    else if (jsPage == DEED_FUNCTIONS)
    { 
        if (idLkp == DEEDS_ICON)
            return (GetPath()+ "Pages/Markers/deeds1.png");
    }
        
    // Verified Sales
    else if (jsPage == VS_FUNCTIONS)
    {
        if(type == PROPERTY_STATUS_LISTING)
            return (GetPath()+ "Pages/Markers/comm_green_ver.png");
            
        else if(type == PROPERTY_STATUS_PENDING)
            return (GetPath()+ "Pages/Markers/comm_orange_ver.png");
            
        else if(type == PROPERTY_STATUS_SOLD)
            return (GetPath()+ "Pages/Markers/comm_red_ver.png");
            
        else if(type == USER)
            return (GetPath()+ "Pages/Markers/User_Marker_1.png");
    }        
    // AA , MBA
    else if (jsPage == AA_FUNCTIONS || jsPage == MBA_FUNCTIONS )

    {
        if (idLkp == "COMMERCIAL")
            return (GetPath()+ "Pages/Markers/commercial_green.png");
        
        else if (idLkp == "FrauTran")
            return (GetPath()+ "Pages/Markers/residential_red.png");
        else        
            return (GetPath()+ "Pages/Markers/residential_green.png");
    }    
    // Fuels
    else if (jsPage == FUELS_FUNCTIONS)
    {   
        if (idLkp)
            return (GetPath()+ "Pages/Markers/commercial_green.png");        
        else 
            return (GetPath()+ "Pages/Markers/commercial_orange.png");
    }    
    // MSDC
    else if (jsPage == MSDC_FUNCTIONS)
    {   
        return (GetPath()+ "Pages/Markers/blue.png");
    }
    
    // RETS
    else if (jsPage == RETS_FUNCTIONS)
    {   
        return (GetPath()+ "Pages/Markers/commercial_green.png");
    }
    
    // Map Marker
    else if (jsPage == MAP_MARKER)
    {   
        return (GetPath()+ "Pages/Markers/GetMarker.png");
    }
    
    // Locator
    else if (jsPage == LOCATOR)
    {
        if (idLkp == 2 || idLkp == 3 || idLkp == 4)
            return (GetPath()+ "Pages/Markers/residential_green.png");
        else if(idLkp == 1)
            return (GetPath()+ "Pages/Markers/commercial_red.png");
    }
    
    // Mckinzie
    else if (jsPage == MCKINZIE)
    {           
        if (idLkp == 'active')
            return (GetPath()+ "Pages/Markers/commercial_green.png");
        else if (idLkp == 'pending')
            return (GetPath()+ "Pages/Markers/commercial_orange.png");
        else if(idLkp == 'sold')
            return (GetPath()+ "Pages/Markers/commercial_red.png");
        else if(idLkp == 'expired')
            return (GetPath()+ "Pages/Markers/commercial_red.png");
    }
    
    // ASU
    else if (jsPage == ASU)
    {           
        if (idLkp == 'active')
            return (GetPath()+ "Pages/Markers/commercial_green.png");
        else if (idLkp == 'pending')
            return (GetPath()+ "Pages/Markers/commercial_orange.png");
        else if(idLkp == 'sold')
            return (GetPath()+ "Pages/Markers/commercial_red.png");
    }
    
    // Carbon Day
    else if (jsPage == CARBON_DAY)
    {           
        if (idLkp == 2 || idLkp == 3 || idLkp == 4)
            return (GetPath()+ "Pages/Markers/residential_green.png");
        else if(idLkp == 1)
            return (GetPath()+ "Pages/Markers/commercial_red.png")
    }
    // Overlays
    else
    {
        if(idLkp == OVERLAY_TYPE_SCHOOL)
            return (GetPath()+ "Pages/Markers/school.png");
            
        else if(idLkp == OVERLAY_TYPE_PARK)
            return (GetPath()+ "Pages/Markers/park.png");
            
        else if(idLkp == OVERLAY_TYPE_HOSPITAL)
            return (GetPath()+ "Pages/Markers/hospital.png");
            
        else if(idLkp == OVERLAY_TYPE_SHOPPING_MALL)
            return (GetPath()+ "Pages/Markers/shoppingmall.png");
    }
}

function CreateIcon(imagePath)
{   
    var icon = new GIcon();
    icon.image = imagePath;
    icon.iconSize = new GSize(xIconSize, yIconSize);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);
    
    return icon;
}

function AdjustMap()
{
    map.checkResize();
}

function tilesSelection(overlaytype, theme)
{       
    if(overlaytype.checked==true && tileoverlays[theme] == null)
    {     
        createCustomLayer(2,18,'bakersfield',theme);
	    map.addOverlay(tileoverlays[theme]);
	}
	else if(overlaytype.checked==true && tileoverlays[theme] != null)
	{
        map.addOverlay(tileoverlays[theme]);	    
	}
	else
	{	    
	    map.removeOverlay(tileoverlays[theme]);
	}
}

function createCustomLayer(minRes, maxRes, area, theme)
{
	var newLayer = new GTileLayer(copyrightCollection,minRes,maxRes);
			
	newLayer.getTileUrl = function (a,b) {return 'http://'+window.location.host+'/'+PATH_TILES+'/'+ area +'/'+theme+'/'+b+'/'+a.x+'_'+a.y+'_'+b+'.png';};
	newLayer.getOpacity = function () {return 0.4;};

	tileoverlays[theme] = new GTileLayerOverlay(newLayer);
	
	return newLayer;
}

function SetMapLegend()
{
    var mapLegend = document.getElementById("mapLegend");
    var img = document.getElementById("LengedImg");
    mapLegend.style.display='';
    
    if(legendStatus=='visible')
    { 
         mapLegend.style.visibility='hidden';
         SetMapLegendImage(img,2);
         legendStatus='hidden';
         if(document.getElementById("mapLegend"))
            document.getElementById("mapLegend").style.display='none';
    }
    else 
    { 
        mapLegend.style.visibility='visible';
        SetMapLegendImage(img,2);        
        legendStatus='visible';
        if(document.getElementById("mapLegend"))
            document.getElementById("mapLegend").style.display='';
    }
    return false;
}

function SetMapLegendImage(img,cmd)
{
    var path= GetPath() + "Pages/";
    
    if(cmd==0) //mouse out
    {
        if(legendStatus=='visible')
        {
            path=path+"hidemaplegend_off.gif";
        }
        else
        {
            path=path+"showmaplegend_off.gif";            
        }
    }
    else if(cmd==1)  //mouse over
    {
        if(legendStatus=='visible')
        {
            path=path+"hidemaplegend_on.gif";            
        }
        else
        {
            path=path+"showmaplegend_on.gif";
        }        
    }
    else if(cmd==2) //mouse click
    {  
        if(legendStatus=='visible')
        {
            path=path+"showmaplegend_on.gif";           
        }
        else
        {
            path=path+"hidemaplegend_on.gif";            
        }          
    }    
    
    img.src=path;
}

function CreateMapLegend()
{   
    MapControl_GM.prototype = new GControl();
    
    MapControl_GM.prototype.initialize = function(map) {
    var mapLegend = document.getElementById("mapLegend");
    this.setButtonStyle_(mapLegend);

    map.getContainer().appendChild(mapLegend);
    return mapLegend;
    }
    
    MapControl_GM.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(132,0));
    }

    MapControl_GM.prototype.setButtonStyle_ = function(button) {    
    button.style.textAlign = "center";
    button.style.width = widthMapLegend;   
    button.style.color = "#FFFFFF";   
    button.style.marginBottom = "3px";
    button.style.fontFamily = "Arial";
	button.style.fontSize = "7pt";
    }

    map.addControl(new MapControl_GM());
    
    document.getElementById("mapLegend").style.visibility='visible';
    
    if(legendStatus=='visible')
        document.getElementById("mapLegend").style.display='';
    else
        document.getElementById("mapLegend").style.display='none';
}

function DisplayMapLegend()
{   
    var button = document.getElementById("ctl00_ContentPlaceHolder1_lbtnMapLegend");
    var mapLegend = document.getElementById("mapLegend");
    var img = document.getElementById("LengedImg");
    mapLegend.style.display='';
    
    if(legendStatus=='visible')
    { 
         button.innerHTML="Show Map Legend ";
         mapLegend.style.visibility='hidden';
         img.src="Images/expand_blue.jpg";
         legendStatus='hidden';
    }
    else 
    {      
        button.innerHTML="Hide Map Legend ";
        mapLegend.style.visibility='visible';
        img.src="Images/collapse_blue.jpg";    
        legendStatus='visible';
    }
    return false;
}

function SetVariables()
{   
    if(Mckenzie_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // mckinzie subdomain    
    {   
        legendStatus = 'visible';
        xIconSize = 24;
        yIconSize = 30;
    }
    else if(MenloAtherton_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // MenloAtherton subdomain    
    {   
        legendStatus = 'visible';
        xIconSize = 24;
        yIconSize = 30;
    }
    else if(Vancouver_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // vancouver subdomain    
    {            
        legendStatus = 'visible';
        xIconSize = 24;
        yIconSize = 30;
    }
    else if(Foster_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // Foster subdomain    
    {            
        legendStatus = 'visible';
        xIconSize = 24;
        yIconSize = 30;
    }   
    else if(CheckDomain(ASU_Domain_1) == 1  || CheckDomain(ASU_Domain_2) == 1 ) // ASU subdomain    
    {               
        legendStatus = 'visible';
        xIconSize = 24;
        yIconSize = 30;
    }    
    else if(MBA_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // MBA subdomain    
    {            
        legendStatus = 'visible';
        xIconSize = 24;
        yIconSize = 30;
    }    
    else if(AA_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // AA subdomain    
    {              
        legendStatus = 'visible';
        xIconSize = 24;
        yIconSize = 30;
    }
    else if(FCF_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // FCF subdomain    
    {            
        legendStatus = 'visible';
        xIconSize = 24;
        yIconSize = 30;
    }    
    else if(WET_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // WET subdomain    
    {            
        legendStatus = 'hidden';
        xIconSize = 12;
        yIconSize = 20;
    } 
    else if(SLB_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // SLB subdomain    
    {   
        legendStatus = 'visible';
        xIconSize = 12;
        yIconSize = 20;
    } 
    else if(OilDemo_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // OilDemo subdomain    
    {   
        legendStatus = 'visible';
        xIconSize = 12;
        yIconSize = 20;
    }     
    else if(Drgca_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // Drgca subdomain    
    {  
        legendStatus = 'visible';
        xIconSize = 24;
        yIconSize = 30;
    }
    else if(MSDC_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // MSDC subdomain    
    {  
        legendStatus = 'visible';
        xIconSize = 12;
        yIconSize = 20;
    } 
    else if(BakersField_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // BakersField subdomain
    {  
        legendStatus = 'visible';
        xIconSize = 24;
        yIconSize = 30;
    }
    else if(Demo_Domain.toLowerCase() == window.location.hostname.toLowerCase()) // Demo subdomain    
    {  
        legendStatus = 'visible';
        xIconSize = 24;
        yIconSize = 30;
    }
    else if(CheckDomain(Locatorpm_Domain_1) == 1 || CheckDomain(Locatorpm_Domain_2) == 1 ) // Locator subdomain    
    {  
        legendStatus = 'hidden';
        xIconSize = 24;
        yIconSize = 30;
    }
    else if(CheckDomain(CarbonDay_Domain) == 1) // Carbon Day  subdomain    
    {  
        legendStatus = 'hidden';
        xIconSize = 12;
        yIconSize = 15;
    }
    else  // not subdomain 
    {   
        legendStatus = 'visible';
        xIconSize = 24;
        yIconSize = 30;
    }
}


function FormatDate(openHouse)
{
    var d = new Date();
    d = openHouse;
    
    try
    {
        var indicator = 'AM';
        var date = d.getUTCDate();
        var month = d.getUTCMonth() + 1;
        var year = d.getUTCFullYear();
        var hours = d.getUTCHours();
        
        if(hours > 12)
        {
            hours = hours - 12;
            indicator = 'PM';
        }
            
        if(hours < 10)
            hours = "0" + hours;
        
        var minutes = d.getUTCMinutes();
        
        if(minutes < 10)
            minutes = "0" + minutes;
            
        var seconds = d.getUTCSeconds();
        
        if(seconds < 10)
            seconds = "0" + seconds;
        
        var varDate = month + '/' + date + '/' + year ;//+ ' - ' + hours + ':' + minutes + ':' + seconds + ' ' + indicator;
    }
    catch(e)
    {
        varDate = 'N/A';
    }
    
    return varDate;
}

function CreateHybridControl_Id(id)
{
    HybridControl.prototype = new GControl();
    
    HybridControl.prototype.initialize = function(map) {
    var container = document.createElement("div");

    var hybridDiv = document.createElement("div");
    this.setButtonStyle_(hybridDiv);
    container.appendChild(hybridDiv);
    hybridDiv.appendChild(document.createTextNode("Hybrid"));
    GEvent.addDomListener(hybridDiv, "click", function() {
    map.setMapType(G_HYBRID_MAP);
    });

    map.getContainer().appendChild(container);
    return container;
    }
    
    HybridControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(X_HYBRID_TYPE, Y_TYPE));
    }

    HybridControl.prototype.setButtonStyle_ = function(button) {
    button.style.backgroundColor = "#000000";
    button.style.textAlign = "center";
    button.style.width = widthHybridType;
    button.style.cursor = "pointer";
    button.style.color = "#FFFFFF";
    button.style.padding = "2px";
    button.style.marginBottom = "3px";
    button.style.fontFamily = "Arial";
	button.style.fontSize = "9pt";
    }

    map[id].addControl(new HybridControl());
}

function CreateSatelliteControl_Id(id)
{
    SatelliteControl.prototype = new GControl();
    
    SatelliteControl.prototype.initialize = function(map) {
    var container = document.createElement("div");

    var satelliteDiv = document.createElement("div");
    this.setButtonStyle_(satelliteDiv);
    container.appendChild(satelliteDiv);
    satelliteDiv.appendChild(document.createTextNode("Satellite"));
    GEvent.addDomListener(satelliteDiv, "click", function() {
    map.setMapType(G_SATELLITE_MAP);
    });

    map.getContainer().appendChild(container);
    return container;
    }
    
    SatelliteControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(X_SATELLITE_TYPE, Y_TYPE));
    }

    SatelliteControl.prototype.setButtonStyle_ = function(button) {
    button.style.backgroundColor = "#000000";
    button.style.textAlign = "center";
    button.style.width = widthSatelliteType;
    button.style.cursor = "pointer";
    button.style.color = "#FFFFFF";
    button.style.padding = "2px";
    button.style.marginBottom = "3px";
    button.style.fontFamily = "Arial";
	button.style.fontSize = "9pt";
    }

    map[id].addControl(new SatelliteControl());
}

function CreateMapControl_Id(id)
{
    MapControl_GM.prototype = new GControl();
    
    MapControl_GM.prototype.initialize = function(map) {
    var container = document.createElement("div");

    var mapDiv = document.createElement("div");
    this.setButtonStyle_(mapDiv);
    container.appendChild(mapDiv);
    mapDiv.appendChild(document.createTextNode("Map"));
    GEvent.addDomListener(mapDiv, "click", function() {
    map[id].setMapType(G_NORMAL_MAP);
    });

    map.getContainer().appendChild(container);
    return container;
    }
    
    MapControl_GM.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(X_MAP_TYPE, Y_TYPE));
    }

    MapControl_GM.prototype.setButtonStyle_ = function(button) {
    button.style.backgroundColor = "#000000";
    button.style.textAlign = "center";
    button.style.width = widthMapType;
    button.style.cursor = "pointer";
    button.style.color = "#FFFFFF";
    button.style.padding = "2px";
    button.style.marginBottom = "3px";
    button.style.fontFamily = "Arial";
	button.style.fontSize = "9pt";
    }

    map[id].addControl(new MapControl_GM());
}

function CreateCustomControls_Id(id)
{
    CreateMapControl_Id(id);
    CreateSatelliteControl_Id(id);
    CreateHybridControl_Id(id);    
}

function CalculateCoordinates(streetId, cityId, stateId, zipCodeId, button, latitude, longitude, isStreetIdText)
{
    buttonId = button;
    latitudeId = latitude;
    longitudeId = longitude;
    
    var street;
        
    if(isStreetIdText == '1')
        street = document.getElementById(streetId).value;
    else
        street = document.getElementById(streetId).options[document.getElementById(streetId).selectedIndex].text;
            
    var city = document.getElementById(cityId).value;
    var state = document.getElementById(stateId).options[document.getElementById(stateId).selectedIndex].text;
    var zipCode = document.getElementById(zipCodeId).value;
    CalculateMapCoordinates(street, city , state, zipCode);    
}

function StreetLinesCalculateCoordinates(streetId1, cityId, stateId, zipCodeId, button, latitude, longitude , IsGeoCode)
{    

    if(document.getElementById(IsGeoCode).value != "1")
    {
       document.getElementById(button).click();
    }
    else
    {
        buttonId = button;
        latitudeId = latitude;
        longitudeId = longitude;        
        var street = document.getElementById(streetId1).value;
        var city = document.getElementById(cityId).value;
        var state = document.getElementById(stateId).options[document.getElementById(stateId).selectedIndex].text;
        var zipCode = document.getElementById(zipCodeId).value;
        CalculateMapCoordinates(street, city , state, zipCode);   
    }
}
function ClickButton(button)
{
    document.getElementById(button).click();
}
function CalculateMapCoordinates(street, city , state, zipCode)
{
    //<![CDATA[
    if (GBrowserIsCompatible())
    {
            
        address = street + ', ' + city + ', ' + state + ', ' + zipCode;        
        var geocoder = new GClientGeocoder();
        
        if (geocoder)
        {   
            geocoder.getLatLng(address, CalculateCoordinates_CB);
        }
    }
    //]]>
}

function CalculateCoordinates_CB(res)
{
    if (!res)
    {
        alert(address + ' not found');
        return false;
    }
    else
    {
        document.getElementById(latitudeId).value=res.lat();
        document.getElementById(longitudeId).value=res.lng();
    }    
    if(CheckDomain(CarbonDay_Domain) == 1) // CarbonDay subdomain    
        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$btnAddTree_GetLongLat", "", true, "", "", false, true))
    else if(CheckDomain(ASU_Domain_1) == 1 || CheckDomain(ASU_Domain_2) == 1) // ASU  subdomain    
        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$btnGetLongLat", "", true, "", "", false, true));
    else
        document.getElementById(buttonId).click();
}



function StreetLinesCalculateCoordinates_Ajax(streetId1, cityId, stateName, zipCodeId, button, latitude, longitude)
{ 
    buttonId = button;
    latitudeId = latitude;
    longitudeId = longitude;    
    var street = document.getElementById(streetId1).value;
    var city = document.getElementById(cityId).value;    
    var state = stateName;
    var zipCode = document.getElementById(zipCodeId).value;
    CalculateMapCoordinates(street, city , state, zipCode);       
}


