﻿// JScript File

// Language selection control
function LanguageSelectionControl() {
    this.container = null;
    this.oLanguageButton = null;
    this.arLanguages = new Array();
    this.nSelectedLanguage = -1;
    this.sSelectedLanguage = '';
    this.sLanguagesAvailable = '';
}

LanguageSelectionControl.prototype = new GControl(false, false);

// We add the control to
// to the map container and return the element for the map class to
// position properly.
LanguageSelectionControl.prototype.initialize = function(map) {
  this.container = document.createElement("div");
  this.container.id = 'LanguageSelectionControlConainer1';

  this.oLanguageButton1 = document.createElement("img");
  this.oLanguageButton1.parentObject = this;  
  this.oLanguageButton1.id='LanguageButton1';
  this.oLanguageButton1.timerId=-1;
  this.oLanguageButton1.title=this.sLanguagesAvailable;
  this.oLanguageButton1.style.cursor="pointer";
  this.oLanguageButton1.style.verticalAlign="middle";
  this.oLanguageButton1.style.border="1px solid #000000";
  this.oLanguageButton1.onclick=function(){
    this.parentObject.nSelectedLanguage = 1 - this.parentObject.nSelectedLanguage;
    var sSelLang = this.parentObject.arLanguages[this.parentObject.nSelectedLanguage][0];
    loadInterfaceText(sSelLang, function(){
        var oLanguageButton = document.getElementById('LanguageButton1');
        oLanguageButton.parentObject.setLanguage(sSelLang); 
        if (document.mapData)
        {
            document.mapData.setLanguage(sSelLang.toUpperCase());
            document.mapData.saveCookies();
        }
        var oDistanceText = document.getElementById('DistanceText1');
        if (oDistanceText)
           oDistanceText.setDistance();
        
    });
  };

  this.oLanguageButton1.onmouseover=function(){
    if (this.timerId == -1)
    {
        if (document.mapData)
            document.mapData.requestControlHelp();
        this.timerId = window.setTimeout("var oInfoBtn=document.getElementById('InfoButton1'); if (oInfoBtn) oInfoBtn.showControlHelp();", 6000);
    }
  };
  this.oLanguageButton1.onmouseout=function(){
    if (this.timerId > -1)
    {
        window.clearTimeout(this.timerId);
        this.timerId = -1;
        var oInfoBtn=document.getElementById('InfoButton1'); 
        if (oInfoBtn) 
            oInfoBtn.hideControlHelp();
     }
  };
  
  if (this.sSelectedLanguage != '')
    this.setLanguage( this.sSelectedLanguage); 
      
  this.container.appendChild(this.oLanguageButton1);
  
  map.getContainer().appendChild(this.container);

  return this.container;
}

LanguageSelectionControl.prototype.initializeData=function(oXml, sSel){
    var sSelUpper = sSel.toUpperCase();
    var oItems = oXml.documentElement.getElementsByTagName("Language");
    if (oItems.length > 0)
    {
        for (i=0; i < oItems.length; i++)
        {
            this.arLanguages.push(new Array(oItems[i].getAttribute("id").toUpperCase(), oItems[i].getAttribute("XMLName"), oItems[i].getAttribute("LocalName"), oItems[i].getAttribute("English"), oItems[i].getAttribute("IconPath")));
            if (sSelUpper == oItems[i].getAttribute("id"))
            {
                this.sSelectedLanguage = sSelUpper;
                this.nSelectedLanguage = i;
            }
            
            if (i > 0)
                this.sLanguagesAvailable += ', \n';    
            this.sLanguagesAvailable +=  oItems[i].getAttribute("LocalName") + ' (' + oItems[i].getAttribute("XMLName") + ')';
        }
        
        if (this.nSelectedLanguage < 0)
        {
            this.nSelectedLanguage = 0;
            this.sSelectedLanguage = this.arLanguages[0][0];
        }
    }
}

LanguageSelectionControl.prototype.setLanguage=function(sLang){
  var i;
  var sLangUpper = sLang.toUpperCase();
  if (this.arLanguages)
    if (this.arLanguages.length > 0)
        for (i=0; i < this.arLanguages.length; i++)
            if (this.arLanguages[i][0] == sLangUpper)
            {
                this.sSelectedLanguage = sLangUpper;
                this.nSelectedLanguage = i;
                this.oLanguageButton1.src=this.arLanguages[i][4];
                //this.redraw();
            }
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
LanguageSelectionControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 5)); //, new GSize(5, 27)
}


// Info control
function InfoControl() {
    this.container = null;
    this.oInfoButton = null;
}

InfoControl.prototype = new GControl(false, false);

// We add the control to
// to the map container and return the element for the map class to
// position properly.
InfoControl.prototype.initialize = function(map) {
  this.container = document.createElement("div");

  this.oInfoButton1 = document.createElement("img");
  this.oInfoButton1.parentObject = this;  
  this.oInfoButton1.id='InfoButton1';
  this.oInfoButton1.timerId=-1;
  this.oInfoButton1.LoadedInfoPage='';
  this.oInfoButton1.src='App_Themes/Images/InfoSignOval3.gif';
  this.oInfoButton1.title='Click here to open info window';
  this.oInfoButton1.style.cursor="pointer";
  this.oInfoButton1.style.verticalAlign="middle";

  this.oInfoButton1.helpDiv= document.createElement("DIV");
  this.oInfoButton1.helpDiv.style.visibility = "hidden";
    
  this.oInfoButton1.onclick=function(){
    var sLang = "RU";
    if (document.oLanguageSelectionControl)
       sLang = document.oLanguageSelectionControl.sSelectedLanguage;
    
    if (sLang != this.LoadedInfoPage)
        GDownloadUrl("GetMapData.aspx?v=1&dt=3&hl=" + sLang, function(oData, nResponseCode){
            WriteLog("Received info page data");
            if(nResponseCode == 200) {
                var oInfoPageDiv = document.getElementById("InfoPage");
                if (oInfoPageDiv){
                    //Add advertisement
                    oData += "<div> <script type='text/javascript'>";
                    oData += "google_ad_client = 'pub-4221506166354226';";
                    //234x60, created 11/18/07
                    oData += "google_ad_slot = '1303811202';";
                    oData += "google_ad_width = 234;";
                    oData += "google_ad_height = 60;";
                    oData += "</script>";
                    oData += "<script type='text/javascript' src='http://pagead2.googlesyndication.com/pagead/show_ads.js'> </script></div>";

                    oInfoPageDiv.innerHTML = oData;
                }
                    
                var oBtnInfo = document.getElementById("InfoButton1");
                if (oBtnInfo){
                    if (document.oLanguageSelectionControl)
                       oBtnInfo.LoadedInfoPage = document.oLanguageSelectionControl.sSelectedLanguage;
                       
                    oBtnInfo.displayInfoPage();
                }
            }
            else
                WriteLog("ResponseCode=" + nResponseCode);
            });
     else
        this.displayInfoPage();
  };

  this.oInfoButton1.displayInfoPage=function(){
    if (document.documentElement)
        if (document.documentElement.style)
            document.documentElement.style.overflow='';
            
    var oInfoPageDiv = document.getElementById("InfoPage");
    if (oInfoPageDiv)
    {
        showInfoPage('P1');
        oInfoPageDiv.style.visibility = 'visible';
        oInfoPageDiv.style.overflow = '';
        //oInfoPageDiv.style.height='1300px';
        //window.scrollTo(0, oInfoPageDiv.offsetTop);
    }
  };
    
  this.oInfoButton1.closeInfoPage=function(){
    var oInfoPageDiv = document.getElementById("InfoPage");
    if (oInfoPageDiv)
    {
        oInfoPageDiv.style.visibility = 'hidden';
        oInfoPageDiv.style.overflow = 'hidden';
        oInfoPageDiv.style.height='0px';
        window.scrollTo(0, 0);
    }
    
    if (document.documentElement)
        if (document.documentElement.style)
        {
            if (!document.getElementById("MetroSchema"))
                document.documentElement.style.overflow='hidden';
            else if (document.getElementById("MetroSchema").style.visibility=='hidden')
                document.documentElement.style.overflow='hidden';
        }
            
  };
    
  this.oInfoButton1.onmouseover=function(){
    if (this.timerId == -1)
    {
        if (document.mapData)
            document.mapData.requestControlHelp();
        this.timerId = window.setTimeout("var oInfoBtn=document.getElementById('InfoButton1'); if (oInfoBtn) oInfoBtn.showAllControlHelp();", 6000);
    }
  };
  this.oInfoButton1.onmouseout=function(){
    if (this.timerId > -1)
    {
        window.clearTimeout(this.timerId);
        this.timerId = -1;
        this.hideAllControlHelp();
    }
  };
  
  this.oInfoButton1.showControlHelp=function(){
      this.helpDiv.style.visibility = 'visible';
  }

  this.oInfoButton1.hideControlHelp=function(){
      this.helpDiv.style.visibility = 'hidden';
  }

  this.oInfoButton1.showAllControlHelp=function(){
      var oCtrlButtonTraces = document.getElementById('ButtonTraces1');
      var oCtrlButtonPushpin = document.getElementById('ButtonPushpin1');
      var oCtrlButtonStationSelection = document.getElementById('ButtonSchema1');
      var oCtrlButtonDistance = document.getElementById('DistanceContainer1');
      this.showControlHelp();
      if (oCtrlButtonTraces)
        oCtrlButtonTraces.showControlHelp();
      if (oCtrlButtonPushpin)
        oCtrlButtonPushpin.showControlHelp();
      if (oCtrlButtonStationSelection)
        oCtrlButtonStationSelection.showControlHelp();
      if (oCtrlButtonDistance)
        oCtrlButtonDistance.showControlHelp();
  }

  this.oInfoButton1.hideAllControlHelp=function(){
      var oCtrlButtonTraces = document.getElementById('ButtonTraces1');
      var oCtrlButtonPushpin = document.getElementById('ButtonPushpin1');
      var oCtrlButtonStationSelection = document.getElementById('ButtonSchema1');
      var oCtrlButtonDistance = document.getElementById('DistanceContainer1');
      this.hideControlHelp();
      if (oCtrlButtonTraces)
        oCtrlButtonTraces.hideControlHelp();
      if (oCtrlButtonPushpin)
        oCtrlButtonPushpin.hideControlHelp();
      if (oCtrlButtonStationSelection)
        oCtrlButtonStationSelection.hideControlHelp();
      if (oCtrlButtonDistance)
        oCtrlButtonDistance.hideControlHelp();
  }
  
  this.container.appendChild(this.oInfoButton1);
  this.container.appendChild(this.oInfoButton1.helpDiv);
  
  map.getContainer().appendChild(this.container);

  return this.container;
}

InfoControl.prototype.setTitle = function(sNewTitle) {
  this.oInfoButton1.title=sNewTitle;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
InfoControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(37, 5)); //, new GSize(5, 27)
}




// Drawing control
function DistanceControl() {
}
DistanceControl.prototype = new GControl(true, false);

// We add the control to
// to the map container and return the element for the map class to
// position properly.
DistanceControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  container.map = map;
  container.style.cursor = "pointer";
  container.backgroundOn = false;
  container.id = "DistanceContainer1";
  container.timerId=-1;

  container.helpDiv= document.createElement("DIV");
  container.helpDiv.style.visibility = "hidden";
    
  this.oDistanceSign = document.createElement("img");
  this.oDistanceSign.title='';
  this.oDistanceSign.src='App_Themes/Images/DistanceSign.gif';
  this.oDistanceSign.style.cursor = "pointer";
  container.appendChild(this.oDistanceSign);

  var oMapType=map.getCurrentMapType();

  this.oDistanceText = document.createElement("small");
  this.oDistanceText.Text="";
  this.oDistanceText.id = "DistanceText1";
  this.oDistanceText.style.cursor = "pointer";
  this.oDistanceText.style.position = "absolute";
  this.oDistanceText.style.top = "0px";
  this.oDistanceText.style.left = "15px";
  //this.oDistanceText.style.height = "100%";

  if (oMapType)
    this.oDistanceText.style.color=oMapType.getTextColor();
  else
    this.oDistanceText.style.color = "#FFFFFF";
  this.oDistanceText.innerHTML = "";
  this.oDistanceText.setDistance=function(nDistance){
    var sDUM = "м";
    var sDUKM = "км";
    var sDUMin = "мин";
    var sDUH = "ч";
    var sDUD = "д";
    if (document.oInterfaceText){
        sDUM = oInterfaceText.getItemValue('ScaleControlMetersUnit',1);
        sDUKM = oInterfaceText.getItemValue('ScaleControlKilometersUnit',1);
        sDUMin = oInterfaceText.getItemValue('DistanceControlMinutesUnit',1);
        sDUH = oInterfaceText.getItemValue('DistanceControlHoursUnit',1);
        sDUD = oInterfaceText.getItemValue('DistanceControlDaysUnit',1);
    }
    if (nDistance)
        if (nDistance > -1)
            this.nDistance = nDistance;
        else
            nDistance = this.nDistance;
    else
        nDistance = this.nDistance;

    if (nDistance > -1){
        var nDistanceValue=nDistance;
        var sDistanceUnit=" " + sDUM + " ";
        var nWalkTime=(((nDistance / 1000) / 5) * 60).toFixed(0);
        var nWalkTimeMinutes=nWalkTime;
        var nWalkTimeHours=0;
        var nWalkTimeDays=0;
        var sWalkTime=nWalkTime.toString() + " " + sDUMin + " ";
        var re = / /g;
        if (nDistance > 1000)
        { nDistanceValue = nDistance / 1000; sDistanceUnit=" " + sDUKM + " "; }
        if (nWalkTime > 59)
        {
            nWalkHours = Math.floor((nWalkTime / 60));
            if (nWalkHours < 24)
                sWalkTime=nWalkHours.toString() + sDUH + " " + (nWalkTime-(nWalkHours*60)).toString() + sDUMin + " ";
            else
                sWalkTime=Math.floor((nWalkHours / 24)).toString() + sDUD + " " + (nWalkHours-(Math.floor((nWalkHours/24))*24)).toString() + sDUH + " " + (nWalkTime-(nWalkHours*60)).toString() + sDUMin;
        }
        var sHTMLDistanceUnit=sDistanceUnit.replace(re, "&nbsp;");
        var sHTMLWalkTime=sWalkTime.replace(re, "&nbsp;");
        this.innerHTML=nDistanceValue.toFixed(2).toString() + sHTMLDistanceUnit + "<br>" + sHTMLWalkTime;
        this.Text=nDistanceValue.toFixed(2).toString() + sDistanceUnit + "\n" + sWalkTime;
        this.parentNode.style.width = (this.offsetWidth + this.offsetLeft).toString() + "px";
    }
  }

  container.onmouseover=function(){
     if (!this.backgroundOn)
        this.setBackground(true);

    if (this.timerId == -1)
    {
        if (document.mapData)
            document.mapData.requestControlHelp();
        this.timerId = window.setTimeout("var oBtn=document.getElementById('DistanceContainer1'); if (oBtn) oBtn.showControlHelp();", 6000);
    }
  }
  
  container.onmouseout=function(){
     if (!this.backgroundOn)
        this.setBackground(false);

    if (this.timerId > -1)
    {
        window.clearTimeout(this.timerId);
        this.timerId = -1;
        this.hideControlHelp();
    }
  }
  
  container.showControlHelp=function(){
      this.helpDiv.style.visibility = 'visible';
  }

  container.hideControlHelp=function(){
      this.helpDiv.style.visibility = 'hidden';
  }
  
  container.onclick=function(){
     this.backgroundOn=!this.backgroundOn;
     if (this.backgroundOn)
        this.setBackground(true);
  }
  
  container.setBackground=function(bOn){
      if (bOn)
      {
         this.style.backgroundColor="#FFFFFF";
         var oText = document.getElementById("DistanceText1");
         if (oText)
            oText.style.color="#000000";

         this.style.border="1px solid #0000FF";
      }
      else
      {
         this.style.backgroundColor="transparent";
         this.style.border="none";
         var oText = document.getElementById("DistanceText1");
         if (oText){
            //oText.style.backgroundColor="transparent";
            var oMapType=map.getCurrentMapType();
            if (oMapType)
              oText.style.color=oMapType.getTextColor();
            else
              oText.style.color = "#FFFFFF";
         }
      }
  }
  
  container.appendChild(this.oDistanceText);
  container.appendChild(container.helpDiv);


  map.getContainer().appendChild(container);
  
  GEvent.addListener(map, "maptypechanged", function() {
      var oButton = document.getElementById("DistanceText1");
      if (!oButton.parentNode.backgroundOn){
          var oMapType=map.getCurrentMapType();
          if (oMapType)
            oButton.style.color=oMapType.getTextColor();
      }
  });
  
  
  return container;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
DistanceControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(200, 0)); //, new GSize(5, 27)
}


// Print, Email, Link control
function PrintEmailLinkControl() {
}
PrintEmailLinkControl.prototype = new GControl(false, true);

// We add the control to
// to the map container and return the element for the map class to
// position properly.
PrintEmailLinkControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  container.id="PrintEmailLinkControl1";
  container.map=map;
  
  container.style.position="absolute";
  container.style.width="25px";
  container.style.fontSize="small";
  container.style.fontFamily="Arial,sans-serif";
    
  this.oPrint = document.createElement("div");
  this.oPrint.timerId=-1;
  this.oPrint.style.border="1px solid #000000";
  this.oPrint.title="";
  this.oPrint.style.backgroundColor="#FFFFFF";
  this.oPrint.style.cursor="pointer";
  this.oPrint.style.height="20px";
  this.oPrint.style.width="25px";
  this.oPrint.style.position="absolute";
  this.oPrint.style.textAlign="center";
  this.oPrint.style.top="0px";  
  this.oPrint.style.overflow="hidden";
  this.oPrint.onclick=function(){
  
    window.print();
    //window.open("mapprint.aspx", "_blank", "height=1000,width=650,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no");
  }
  
  this.oPrint.onmouseover=function(){
    if (this.timerId == -1)
    {
        if (document.mapData)
            document.mapData.requestControlHelp();
        this.timerId = window.setTimeout("var oInfoBtn=document.getElementById('InfoButton1'); if (oInfoBtn) oInfoBtn.showControlHelp();", 6000);
    }
  };
  this.oPrint.onmouseout=function(){
    if (this.timerId > -1)
    {
        window.clearTimeout(this.timerId);
        this.timerId = -1;
        var oInfoBtn=document.getElementById('InfoButton1'); 
        if (oInfoBtn) 
            oInfoBtn.hideControlHelp();
     }
  };
  
  var oPrintInternal = document.createElement("div");
  oPrintInternal.style.border="1px solid";
  oPrintInternal.style.borderColor="#FFFFFF #B0B0B0 #B0B0B0 #FFFFFF";
  oPrintInternal.style.backgroundColor="#FFFFFF";
  oPrintInternal.style.width="100%";
  oPrintInternal.style.height="18px";
  oPrintInternal.style.position="absolute";
  oPrintInternal.style.left="0px";
  oPrintInternal.style.align="center";
  oPrintInternal.style.overflow="hidden";

  var oPrintImg = document.createElement("img");
  oPrintImg.src='App_Themes/Images/print_icon_3.gif';
  oPrintImg.style.height="16px";

  oPrintInternal.appendChild(oPrintImg);
  this.oPrint.appendChild(oPrintInternal);
  container.appendChild(this.oPrint);


  this.oEMail = document.createElement("div");
  this.oEMail.timerId=-1;
  this.oEMail.style.border="1px solid #000000";
  this.oEMail.title="";
  this.oEMail.style.backgroundColor="#FFFFFF";
  this.oEMail.style.cursor="pointer";
  this.oEMail.style.height="20px";
  this.oEMail.style.width="25px"; 
  this.oEMail.style.position="absolute";
  this.oEMail.style.textAlign="center";
  this.oEMail.style.top="30px";  
  this.oEMail.style.overflow="hidden";
  this.oEMail.onclick=function(){
    var oPrintEmailLink = document.getElementById("PrintEmailLinkControl1");
    if (oPrintEmailLink)
    {
        //window.alert(oPrintEmailLink.makeLink());
        window.open("mailto:?subject=location on map&body="+escape(oPrintEmailLink.makeLink()) + " " , "_self"); //Click the following link to see location on map '
    }
  }
  
  this.oEMail.onmouseover=function(){
    if (this.timerId == -1)
    {
        if (document.mapData)
            document.mapData.requestControlHelp();
        this.timerId = window.setTimeout("var oInfoBtn=document.getElementById('InfoButton1'); if (oInfoBtn) oInfoBtn.showControlHelp();", 6000);
    }
  };
  this.oEMail.onmouseout=function(){
    if (this.timerId > -1)
    {
        window.clearTimeout(this.timerId);
        this.timerId = -1;
        var oInfoBtn=document.getElementById('InfoButton1'); 
        if (oInfoBtn) 
            oInfoBtn.hideControlHelp();
     }
  };
  
  var oEMailInternal = document.createElement("div");
  oEMailInternal.style.border="1px solid";
  oEMailInternal.style.borderColor="#FFFFFF #B0B0B0 #B0B0B0 #FFFFFF";
  oEMailInternal.style.backgroundColor="#FFFFFF";
  oEMailInternal.style.width="100%";
  oEMailInternal.style.height="18px";
  oEMailInternal.style.position="absolute";
  oEMailInternal.style.left="0px";
  oEMailInternal.style.overflow="hidden";

  var oEMailImg = document.createElement("img");
  oEMailImg.src='App_Themes/Images/email_icon_3.gif';
  
  oEMailInternal.appendChild(oEMailImg);
  this.oEMail.appendChild(oEMailInternal);
  container.appendChild(this.oEMail);


  this.oLink = document.createElement("div");
  this.oLink.timerId=-1;
  this.oLink.style.border="1px solid #000000";
  this.oLink.style.backgroundColor="#FFFFFF";
  this.oLink.style.cursor="pointer";
  this.oLink.style.height="20px";
  this.oLink.style.width="25px"; 
  this.oLink.style.position="absolute";
  this.oLink.style.top="60px"; 
  this.oLink.style.textAlign="center";
  this.oLink.style.overflow="hidden";
  this.oLink.title="";

  var oLinkInternal = document.createElement("div");
  oLinkInternal.style.border="1px solid";
  oLinkInternal.style.borderColor="#FFFFFF #B0B0B0 #B0B0B0 #FFFFFF";
  oLinkInternal.style.backgroundColor="#FFFFFF";
  oLinkInternal.style.width="100%";
  oLinkInternal.style.height="18px";
  oLinkInternal.style.position="absolute";
  oLinkInternal.style.left="0px";
  oLinkInternal.style.overflow="hidden";

  var oLinkImg = document.createElement("img");
  oLinkImg.src='App_Themes/Images/link_icon_3.gif';
  oLinkImg.style.height="16px";
  
  oLinkInternal.appendChild(oLinkImg);
  this.oLink.appendChild(oLinkInternal);

  this.oLink.onclick=function(){
    var oPrintEmailLink = document.getElementById("PrintEmailLinkControl1");
    if (oPrintEmailLink)
        window.prompt("Please copy the link:", oPrintEmailLink.makeLink());
  }
  
  this.oLink.onmouseover=function(){
    if (this.timerId == -1)
    {
        if (document.mapData)
            document.mapData.requestControlHelp();
        this.timerId = window.setTimeout("var oInfoBtn=document.getElementById('InfoButton1'); if (oInfoBtn) oInfoBtn.showControlHelp();", 6000);
    }
  };
  this.oLink.onmouseout=function(){
    if (this.timerId > -1)
    {
        window.clearTimeout(this.timerId);
        this.timerId = -1;
        var oInfoBtn=document.getElementById('InfoButton1'); 
        if (oInfoBtn) 
            oInfoBtn.hideControlHelp();
     }
  };
  
  container.appendChild(this.oLink);
 
  container.makeLink=function(){
    var sHostname = "kartametro.info";
    if (window.location)
        if (window.location.hostname)
            sHostName = window.location.hostname;
    if (sHostName == "localhost")
        sHostName += "/Mettro1";
//    else
//        sHostName += "/metromap";
    var sResult="http://" + sHostName + "/?v=1&";
    var oCenter = this.map.getCenter();
    var sCenter='';
    if (oCenter)
        sCenter = oCenter.toUrlValue(); //.replace(/\./g,'');
    if (sCenter != '')
        sResult += 'll=' + sCenter;
    
    if (this.map.getZoom())
    {   
        if (sResult != "")
            sResult += "&";
        sResult+='z='+this.map.getZoom().toString();
    }

    var oMapType = this.map.getCurrentMapType();        
    if(oMapType)
    {   
        if (sResult != "")
            sResult += "&";
        sResult += 't=' + oMapType.getUrlArg();
    }
    
    var oPushpinButton=document.getElementById('ButtonPushpin1');
    if (oPushpinButton)
        if (oPushpinButton.oMarker)
        {
            if (sResult != "")
                sResult += "&";
            sResult += 'mk=' + oPushpinButton.oMarker.getPoint().toUrlValue();
            if (oPushpinButton.sText != '')
            {
                var sTextEncoded = escape(oPushpinButton.sText);
                sResult += "," + sTextEncoded;
            }
            
        }

    var oTracesButton=document.getElementById('ButtonTraces1');
    if (oTracesButton)
        if (oTracesButton.encoded)
            if (oTracesButton.encoded != '')
            {
                if (sResult != "")
                    sResult += "&";
                sResult += 'pl=' + escape(oTracesButton.encoded);
            }
    
    return sResult;
  }

  map.getContainer().appendChild(container);
  return container;
}

PrintEmailLinkControl.prototype.setTitle = function(sNewPrintTitle, sNewEMailTitle, sNewLinkTitle) {
  this.oPrint.title=sNewPrintTitle;
  this.oEMail.title=sNewEMailTitle;
  this.oLink.title=sNewLinkTitle;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
PrintEmailLinkControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(9, 30)); //, new GSize(5, 27)
}




// Metrostation selection control
function StationSelectionControl() {
}
StationSelectionControl.prototype = new GControl(false, false);

// We add the control to
// to the map container and return the element for the map class to
// position properly.
StationSelectionControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  container.style.position="absolute";

  this.oButtonSchema = document.createElement("div");
  this.oButtonSchema.id='ButtonSchema1';
  this.oButtonSchema.timerId=-1;
  this.oButtonSchema.LoadedSchema='none';
  this.oButtonSchema.style.border="1px solid #000000";
  this.oButtonSchema.style.backgroundColor="#FFFFFF";
  this.oButtonSchema.style.height="20px";
  this.oButtonSchema.style.width="20px"; 
  this.oButtonSchema.style.position="absolute";
  //this.oButtonSchema.style.right="0px";
  this.oButtonSchema.style.left="0px";
  this.oButtonSchema.style.cursor="pointer";
  
  this.oButtonSchema.helpDiv= document.createElement("DIV");
  this.oButtonSchema.helpDiv.style.visibility = "hidden";

  this.oButtonSchema.onclick=function(){
    var sLang = "RU";
    if (document.oLanguageSelectionControl)
       sLang = document.oLanguageSelectionControl.sSelectedLanguage;
    //document.open('MetroSchema.aspx?nl='+sLang,'SchemaMetroMoscow','menubar=no,status=no,titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,left=0,top=0,width=1024,height=' + window.screen.availHeight);
    
    if (sLang != this.LoadedSchema)
        GDownloadUrl("GetMapData.aspx?v=1&dt=2&hl=" + sLang, function(oData, nResponseCode){
            WriteLog("Received schema data");
            if(nResponseCode == 200) {
            
                var oMetroSchemaDiv = document.getElementById("MetroSchema");
                if (oMetroSchemaDiv)
                    oMetroSchemaDiv.innerHTML = oData.replace(/__1_/g, "<div id='DMOMOS").replace(/__2_/g,"' class='StationName' style='").replace(/__3_/g,"px;' onclick='onStationClick(this.id.substring(1))' onmouseover='selectStation(this.id.substring(1));' onmouseout='unselectStation(this.id.substring(1));'>").replace(/__4_/g,"px' src='App_Themes/Images/Metro/StationSelectionMarker.gif' onclick='onStationClick(this.id.substring(1))'/></div>").replace(/__5_/g,"' onmouseover='selectStation(this.id.substring(1));' onmouseout='unselectStation(this.id.substring(1));' style='background-color:Black' />");
                    
                var oBtnSchema = document.getElementById("ButtonSchema1");
                if (oBtnSchema){
                    if (document.oLanguageSelectionControl)
                       oBtnSchema.LoadedSchema = document.oLanguageSelectionControl.sSelectedLanguage;
                       
                    oBtnSchema.displayMetroSchema();
                }
                    
            }
            else
                WriteLog("ResponseCode=" + nResponseCode);
            });
     else
        this.displayMetroSchema();
  };

  this.oButtonSchema.displayMetroSchema=function(){
    var oMetroSchemaDiv = document.getElementById("MetroSchema");
    if (oMetroSchemaDiv)
    {
        oMetroSchemaDiv.style.visibility = 'visible';
        oMetroSchemaDiv.style.overflow = 'visible';
        oMetroSchemaDiv.style.height='1310px';
    }
    var oMapDiv = document.getElementById("map");
    if (oMapDiv)
    {
        var oStSelCtrl = document.getElementById("StationSelectionControl1");
        if (oStSelCtrl)
        {
            oStSelCtrl.style.visibility = 'hidden';
        }
        oMapDiv.style.visibility = 'hidden';
        oMapDiv.style.height='0px';
    }
    
    if (document.documentElement)
        if (document.documentElement.style)
            document.documentElement.style.overflow='';
  };
  
  var oButtonSchemaImg = document.createElement("img");
  oButtonSchemaImg.src='App_Themes/Images/Metro/ButtonSchema5.gif';
  oButtonSchemaImg.style.borderRight="1px solid #B0B0B0";
  oButtonSchemaImg.style.borderBottom="1px solid #B0B0B0";
  oButtonSchemaImg.style.backgroundColor="#FFFFFF";
  oButtonSchemaImg.style.position="absolute";
  oButtonSchemaImg.style.right="0px";
  oButtonSchemaImg.style.bottom="0px";
  
  this.oButtonSchema.appendChild(oButtonSchemaImg);
  this.oButtonSchema.appendChild(this.oButtonSchema.helpDiv);
  
  this.oButtonSchema.onmouseover=function(){
    if (this.timerId == -1)
    {
        if (document.mapData)
            document.mapData.requestControlHelp();
        this.timerId = window.setTimeout("var oBtn=document.getElementById('ButtonSchema1'); if (oBtn) oBtn.showControlHelp();", 6000);
    }
  };
  this.oButtonSchema.onmouseout=function(){
    if (this.timerId > -1)
    {
        window.clearTimeout(this.timerId);
        this.timerId = -1;
        this.hideControlHelp();
    }
  };
  
  this.oButtonSchema.showControlHelp=function(){
      this.helpDiv.style.visibility = 'visible';
  }

  this.oButtonSchema.hideControlHelp=function(){
      this.helpDiv.style.visibility = 'hidden';
  }
  
  
  this.oSelect = document.createElement("select");
  this.oSelect.id='StationSelectionControl1';
  this.oSelect.timerId=-1;
  this.oSelect.style.position="absolute";
  this.oSelect.style.cursor="default";
  this.oSelect.style.border="1px solid #000000";
  //this.oSelect.style.right="25px";
  this.oSelect.style.left="25px";
  
  this.oSelect.arStations=new Array();
  this.oSelect.map=map;
  this.oSelect.style.visibility="hidden";
  this.oSelect.onchange=function(){ 
   var valInitial=this.options[this.selectedIndex].value;
   if(valInitial)
   {
        var nPos=valInitial.indexOf('(');
        if(nPos>-1)
        {
            valInitial=valInitial.substring(nPos+1,valInitial.length-2);
            nPos=valInitial.indexOf(',');
            if(nPos>-1)
            {
                var sLat=valInitial.substring(0, nPos-1);
                var sLng=valInitial.substring(nPos+1, valInitial.length-1);
                if(this.map)
                {
                    this.parentNode.focus();
                    var nZoom=this.map.getZoom();
                    if(nZoom<14)
                        window.setTimeout("var oMySel=document.getElementById('StationSelectionControl1'); if(oMySel) {oMySel.map.setCenter(new GLatLng(" + sLat + ", " + sLng + "), 15); } else window.alert('Not found');", 10);
                    else
                        window.setTimeout("var oMySel=document.getElementById('StationSelectionControl1'); if(oMySel) oMySel.map.panTo(new GLatLng(" + sLat + ", " + sLng + ")); else window.alert('Not found');", 10);
//                    if(nZoom<14) {
//                        var oMySel=document.getElementById('StationSelectionControl1'); if(oMySel) {oMySel.map.setCenter(new GLatLng(parseFloat(sLat), parseFloat(sLng)), 15); } else window.alert('Not found');
//                    }
//                    else {
//                        var oMySel=document.getElementById('StationSelectionControl1'); if(oMySel) oMySel.map.panTo(new GLatLng(parseFloat(sLat), parseFloat(sLng))); else window.alert('Not found');
//                    }
                }
            }
        }
   }
  } 

  this.oSelect.onmouseover=function(){
    if (this.timerId == -1)
    {
        if (document.mapData)
            document.mapData.requestControlHelp();
        this.timerId = window.setTimeout("var oBtn=document.getElementById('ButtonSchema1'); if (oBtn) oBtn.showControlHelp();", 6000);
    }
  };
  
  this.oSelect.onmouseout=function(){
    if (this.timerId > -1)
    {
        window.clearTimeout(this.timerId);
        this.timerId = -1;
        var oBtn=document.getElementById('ButtonSchema1'); 
        if (oBtn) 
            oBtn.hideControlHelp();    
    }
  };

  container.appendChild(this.oSelect);
  container.appendChild(this.oButtonSchema);

  map.getContainer().appendChild(container);

  return container;
}

function panToSelected(oSelect)
{
   var valInitial=oSelect.options[oSelect.selectedIndex].value;
   if(valInitial)
   {
        var nPos=valInitial.indexOf('(');
        if(nPos>-1)
        {
            valInitial=valInitial.substring(nPos+1,valInitial.length-2);
            nPos=valInitial.indexOf(',');
            if(nPos>-1)
            {
                var sLat=valInitial.substring(0, nPos-1);
                var sLng=valInitial.substring(nPos+1, valInitial.length-1);
                //GLog.write(nLat + ';' + nLng);
                if(this.map)
                {
                    var nZoom=oSelect.map.getZoom();
                    //GLog.write(nZoom);
                    if(nZoom<14)
                        window.setTimeout("var oMySel=document.getElementById('StationSelectionControl1'); if(oMySel) oMySel.map.panTo(new GLatLng(" + sLat + ", " + sLng + ")); else window.alert('Not found');", 10);
                    else
                        window.setTimeout("var oMySel=document.getElementById('StationSelectionControl1'); if(oMySel) oMySel.map.setCenter(new GLatLng(" + sLat + ", " + sLng + ", 14));  else window.alert('Not found');", 10);
                    
                }
            }
        }
   }
}

// Add new option to the Select control
StationSelectionControl.prototype.addItem = function(sName, sValue, sColor) {
    if (this.oSelect)
    {
        var nPos=-1;
        var sUCName = sName.toUpperCase();
        for (i=0; i < this.oSelect.arStations.length; i++)
        {
            var sUCOptionName=this.oSelect.arStations[i][0].toUpperCase();
            if (sUCName < sUCOptionName)
            {
                nPos=i;
                break;
            }
        }

        //Do not add duplicate
        if (nPos > 0)
            if (this.oSelect.arStations[nPos-1][0].toUpperCase() == sUCName)
                nPos=-2;
        
        if (nPos > -2)
        {
            if (nPos > -1)
            {
               this.oSelect.arStations.splice(nPos, 0, new Array(sName, sValue, sColor));
            }
            else{
                this.oSelect.arStations.push(new Array(sName, sValue, sColor));
            }
        }
     }
}

StationSelectionControl.prototype.publishItems = function() {
    if (this.oSelect)
    {
        WriteLog("publishItems started");
        for (var i=0; i < this.oSelect.arStations.length; i++){
            var oOption = document.createElement("OPTION");
            this.oSelect.options[this.oSelect.options.length] = oOption;
            //this.oSelect.options.add(oOption);

            oOption.innerText = this.oSelect.arStations[i][0];
            oOption.text = this.oSelect.arStations[i][0];
            oOption.value = this.oSelect.arStations[i][1];
        }
        
        this.oSelect.arStations.length = 0;
        WriteLog("publishItems ended");
    }
}

StationSelectionControl.prototype.setVisibility = function(bIsVisible) {
    if (bIsVisible)
        this.oSelect.style.visibility="visible";
    else
        this.oSelect.style.visibility="hidden";
}

StationSelectionControl.prototype.setTitle = function(sNewTitle) {
  this.oButtonSchema.title=sNewTitle;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
StationSelectionControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(80, 5)); //, new GSize(5, 27)
}



// Drawing control
function DrawingControl() {
}
DrawingControl.prototype = new GControl(false, false);

// We add the control to
// to the map container and return the element for the map class to
// position properly.
DrawingControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
    
  container.style.width="24px";
  container.id="DrawingControl1";

  this.oButtonPushpin = document.createElement("div");
  this.oButtonPushpin.map = map;
  this.oButtonPushpin.mode=1;
  this.oButtonPushpin.timerId=-1;
  this.oButtonPushpin.sText = '';
  this.oButtonPushpin.oMarker = null;
  this.oButtonPushpin.oLabel = null;
  this.oButtonPushpin.id='ButtonPushpin1';
  this.oButtonPushpin.style.border="1px solid #000000";
  this.oButtonPushpin.style.width="21px";
  this.oButtonPushpin.style.height="21px";
  this.oButtonPushpin.style.cursor="pointer";

  this.oButtonPushpin.helpDiv= document.createElement("DIV");
  this.oButtonPushpin.helpDiv.style.visibility = "hidden";

  this.oButtonPushpin.oButtonPushpinDivInternal = document.createElement("div");
  this.oButtonPushpin.oButtonPushpinDivInternal.style.width="19px";
  this.oButtonPushpin.oButtonPushpinDivInternal.style.height="19px";
  this.oButtonPushpin.oButtonPushpinDivInternal.style.border="1px solid";
  this.oButtonPushpin.oButtonPushpinDivInternal.style.borderColor="#FFFFFF #B0B0B0 #B0B0B0 #FFFFFF";
  this.oButtonPushpin.oButtonPushpinDivInternal.style.backgroundColor="#FFFFFF";
  this.oButtonPushpin.oButtonPushpinDivInternal.style.align="middle";
  
  this.oButtonPushpin.oButtonPushpinImg = document.createElement("img");
  this.oButtonPushpin.oButtonPushpinImg.src='App_Themes/Images/flag-1-blue-none.gif'; //'App_Themes/Images/traces2.gif';
  this.oButtonPushpin.oButtonPushpinImg.style.position="relative";
  this.oButtonPushpin.oButtonPushpinImg.style.top="0px";
  this.oButtonPushpin.oButtonPushpinImg.style.left="0px";
  
  this.oButtonPushpin.oButtonPushpinDivInternal.appendChild(this.oButtonPushpin.oButtonPushpinImg);
  this.oButtonPushpin.appendChild(this.oButtonPushpin.oButtonPushpinDivInternal);
  this.oButtonPushpin.appendChild(this.oButtonPushpin.helpDiv);
  
  this.oButtonPushpin.onclick=function(){
     this.mode=1 - this.mode;
     if (this.mode==0){
        this.buttonDown();
        if (!this.oMarker)
        {
            var oPnt;
            if (end_marker)
                oPnt = end_marker.getPoint();
            else
                oPnt = this.map.getCenter();
                
            this.createMarker(oPnt, this.sText);
        }
        else
        {
            this.map.savePosition();
            this.map.panTo(this.oMarker.getPoint());
        }
     }
     else 
        this.buttonUp();
  };
  
  this.oButtonPushpin.buttonUp=function(){
    this.mode=1;
    this.oButtonPushpinImg.style.top="0px";
    this.oButtonPushpinImg.style.left="0px";
    this.oButtonPushpinDivInternal.style.borderColor="#FFFFFF #B0B0B0 #B0B0B0 #FFFFFF";
    this.oButtonPushpinDivInternal.style.backgroundColor="#FFFFFF";
    this.applyTitle();
  };
  
  this.oButtonPushpin.buttonDown=function(){
    this.mode=0;
    this.oButtonPushpinImg.style.top="1px";
    this.oButtonPushpinImg.style.left="1px";
    this.oButtonPushpinDivInternal.style.borderColor="#909090 #C0C0C0 #C0C0C0 #909090";
    this.oButtonPushpinDivInternal.style.backgroundColor="#C0C0C0";
    this.applyTitle();
    
    var oBtnPushpin = document.getElementById("ButtonTraces1");
    if (oBtnPushpin)
        oBtnPushpin.buttonUp();
  };
  
  this.oButtonPushpin.createMarker=function(oPoint, sText){
   if (!this.oMarker)
   {
        this.oMarker = createMainMarker(this.map, oPoint, sText);
        this.oButtonPushpinImg.src='App_Themes/Images/flag-1-blue-red.gif';
        this.oLabel = this.createLabel(oPoint, sText);
   }
   else
   {
        this.oMarker.setPoint(oPoint);
        this.setText(sText);
   }
  };
  
  this.oButtonPushpin.onLabelClick=function(oPoint)
  {
        var bResult = false;
        if (this.oLabel)
        {
            bResult = this.oLabel.hitTest(oPoint);
            if (bResult)
                onClickMainMarker(this.oMarker);
        }    

        return bResult;
  }
  
  this.oButtonPushpin.setText=function(sText){
    this.sText = sText;
    var sCorrectText = sText.replace(/ /g, "&nbsp;");

    if (this.oLabel)
        if (sCorrectText != '')
            this.oLabel.setContents(sCorrectText);
        else
        {
            this.map.removeOverlay(this.oLabel);
            this.oLabel = null;
        }
    else
        if (this.oMarker)
           if (sCorrectText != '')
            this.oLabel = this.createLabel(this.oMarker.getPoint(), sCorrectText);
  }
  
  this.oButtonPushpin.recreateMarker=function(sText){
    if (this.oMarker)
    {
        var oPoint = this.oMarker.getPoint();
        this.map.removeOverlay(this.oMarker);
        this.oMarker = createMainMarker(this.map, oPoint, this.sText);
    }
  }

  this.oButtonPushpin.deleteMainMarker=function(){
    this.map.removeOverlay(this.oMarker);
    this.oMarker = null;
    this.map.closeInfoWindow();
    this.sText = '';

    this.oButtonPushpinImg.src='App_Themes/Images/flag-1-blue-none.gif';
    this.buttonUp();    
    if (this.oLabel)
    {
        this.map.removeOverlay(this.oLabel);
        this.oLabel = null;
    }
  }
  
  this.oButtonPushpin.closeInfoWindow=function(){
    this.map.closeInfoWindow();
  }
  
  this.oButtonPushpin.createLabel=function(oPoint, sTitle){
    var MarkerLabelE = null;
    if (sTitle)
    {
          var sCorrectText = sTitle.replace(/ /g, "&nbsp;");
          MarkerLabelE = new ELabel(oPoint, sCorrectText, "style1", new GSize(-16,-36), 80);
          this.map.addOverlay(MarkerLabelE);
    }

    return MarkerLabelE;
  }

  this.oButtonPushpin.moveLabel=function(oPoint){
    if (this.oLabel)
       this.oLabel.setPoint(oPoint);
  }
  
  this.oButtonPushpin.applyTitle=function(){
    if (oInterfaceText)
        if (this.mode==0)
            this.title=oInterfaceText.getItemValue('PushpinButtonControlTitleDown',1);
        else
            if (this.oMarker)
                this.title=oInterfaceText.getItemValue('PushpinButtonControlTitleUpFindMarker',1);
            else
                if (points)
                    if (points.length > 0)
                        this.title=oInterfaceText.getItemValue('PushpinButtonControlTitleUpTraces',1);
                    else
                        this.title=oInterfaceText.getItemValue('PushpinButtonControlTitleUpNoTraces',1);
  }

  this.oButtonPushpin.onmouseover=function(){
    if (this.timerId == -1)
    {
        if (document.mapData)
            document.mapData.requestControlHelp();
        this.timerId = window.setTimeout("var oBtn=document.getElementById('ButtonPushpin1'); if (oBtn) oBtn.showControlHelp();", 6000);
    }
  };
  this.oButtonPushpin.onmouseout=function(){
    if (this.timerId > -1)
    {
        window.clearTimeout(this.timerId);
        this.timerId = -1;
        this.hideControlHelp();
    }
  };
  
  this.oButtonPushpin.showControlHelp=function(){
      this.helpDiv.style.visibility = 'visible';
  }

  this.oButtonPushpin.hideControlHelp=function(){
      this.helpDiv.style.visibility = 'hidden';
  }
  

  container.appendChild(this.oButtonPushpin);
  var oSpace = document.createElement("small");
  oSpace.innerHTML = "&nbsp;";
  oSpace.style.height = "3px";
  container.appendChild(oSpace);

  this.oButtonTraces = document.createElement("div");
  this.oButtonTraces.id='ButtonTraces1';
  this.oButtonTraces.mode=1;
  this.oButtonTraces.encoded='';
  this.oButtonTraces.title=null;
  this.oButtonTraces.timerId=-1;
  this.oButtonTraces.style.cursor="pointer";
  this.oButtonTraces.style.border="1px solid #000000";
  this.oButtonTraces.style.width="21px";
  this.oButtonTraces.style.height="21px";
  this.oButtonTraces.style.verticalAlign="middle";

  this.oButtonTraces.helpDiv= document.createElement("DIV");
  this.oButtonTraces.helpDiv.style.visibility = "hidden";
  
  this.oButtonTraces.oButtonTracesDivInternal = document.createElement("div");
  this.oButtonTraces.oButtonTracesDivInternal.style.width="19px";
  this.oButtonTraces.oButtonTracesDivInternal.style.height="19px";
  this.oButtonTraces.oButtonTracesDivInternal.style.border="1px solid";
  this.oButtonTraces.oButtonTracesDivInternal.style.borderColor="#FFFFFF #B0B0B0 #B0B0B0 #FFFFFF";
  this.oButtonTraces.oButtonTracesDivInternal.style.backgroundColor="#FFFFFF";
  this.oButtonTraces.oButtonTracesDivInternal.style.align="middle";
  
  this.oButtonTraces.oButtonTracesImg = document.createElement("img");
  this.oButtonTraces.oButtonTracesImg.src='App_Themes/Images/traces5-blue.gif'; //'App_Themes/Images/traces2.gif';
  this.oButtonTraces.oButtonTracesImg.style.position="relative";
  this.oButtonTraces.oButtonTracesImg.style.top="0px";
  this.oButtonTraces.oButtonTracesImg.style.left="0px";
  
  this.oButtonTraces.oButtonTracesDivInternal.appendChild(this.oButtonTraces.oButtonTracesImg);
  this.oButtonTraces.appendChild(this.oButtonTraces.oButtonTracesDivInternal);
  this.oButtonTraces.appendChild(this.oButtonTraces.helpDiv);
  
  this.oButtonTraces.setCursor=function(sCursor){
    if (!sCursor)
        sCursor = this.sInitialCursor;
        
    var divMap = document.getElementById('map');
    if (divMap)
        if (divMap.firstChild)
            if (divMap.firstChild.firstChild)
                if (divMap.firstChild.firstChild.style)
                    divMap.firstChild.firstChild.style.cursor = sCursor; 

  }

  this.oButtonTraces.setCrosshairCursor=function(){
      var oCtrlButtonTraces = document.getElementById('ButtonTraces1');
      var divMap = document.getElementById('map');
      if ((divMap) && (oCtrlButtonTraces))
         if (oCtrlButtonTraces.mode == 0)
            oCtrlButtonTraces.setCursor('crosshair');
  }
  
  this.oButtonTraces.getCursor=function(){
    var divMap = document.getElementById('map');
    if (divMap)
        if (divMap.firstChild)
            if (divMap.firstChild.firstChild)
                if (divMap.firstChild.firstChild.style)
                    this.sInitialCursor = divMap.firstChild.firstChild.style.cursor;
  }
  
  this.oButtonTraces.getCursor();
  
  this.oButtonTraces.onclick=function(){
      this.mode=1 - this.mode;
      if (this.mode==0)
        this.buttonDown();
      else
        this.buttonUp();
  };

  this.oButtonTraces.onmouseover=function(){
    if (this.timerId == -1)
    {
        if (document.mapData)
            document.mapData.requestControlHelp();
        this.timerId = window.setTimeout("var oBtn=document.getElementById('ButtonTraces1'); if (oBtn) oBtn.showControlHelp();", 6000);
    }
  };
  this.oButtonTraces.onmouseout=function(){
    if (this.timerId > -1)
    {
        window.clearTimeout(this.timerId);
        this.timerId = -1;
        this.hideControlHelp();
    }
  };
  
  this.oButtonTraces.showControlHelp=function(){
      this.helpDiv.style.visibility = 'visible';
  }

  this.oButtonTraces.hideControlHelp=function(){
      this.helpDiv.style.visibility = 'hidden';
  }
  
  
  this.oButtonTraces.buttonUp=function(){
    this.mode=1;
    this.oButtonTracesImg.src='App_Themes/Images/traces5-blue.gif';
    this.oButtonTracesImg.style.top="0px";
    this.oButtonTracesImg.style.left="0px";
    this.oButtonTracesDivInternal.style.borderColor="#FFFFFF #B0B0B0 #B0B0B0 #FFFFFF";
    this.oButtonTracesDivInternal.style.backgroundColor="#FFFFFF";
    hideMarkers();
    this.applyTitle();
    if (document.oDistanceControl)
        if (document.oDistanceControl.oDistanceText)
            if (document.oDistanceControl.oDistanceText.parentNode)
            {
                document.oDistanceControl.oDistanceText.parentNode.backgroundOn = false;
                document.oDistanceControl.oDistanceText.parentNode.setBackground(false);
            }
    this.setCursor();
  };
  
  this.oButtonTraces.buttonDown=function(){
    this.mode=0;
    this.oButtonTracesImg.src='App_Themes/Images/traces5-blue-blue.gif';
    this.oButtonTracesImg.style.top="1px";
    this.oButtonTracesImg.style.left="1px";
    this.oButtonTracesDivInternal.style.borderColor="#909090 #C0C0C0 #C0C0C0 #909090";
    this.oButtonTracesDivInternal.style.backgroundColor="#C0C0C0";
    showMarkers();
    this.applyTitle();

    var oBtnPushpin = document.getElementById("ButtonPushpin1");
    if (oBtnPushpin)
        oBtnPushpin.buttonUp();
    if (document.oDistanceControl)
        if (document.oDistanceControl.oDistanceText)
            if (document.oDistanceControl.oDistanceText.parentNode)
            {
                document.oDistanceControl.oDistanceText.parentNode.backgroundOn = true;
                document.oDistanceControl.oDistanceText.parentNode.setBackground(true);
            }

    this.setCursor('crosshair');
  };
  
  GEvent.addListener(map, "click", function(marker, point){
      var oCtrlButtonPushpin = document.getElementById('ButtonPushpin1');
      if (oCtrlButtonPushpin)
          if (!oCtrlButtonPushpin.onLabelClick(point))
             onClickPolylineDirections(point);
      
      var oCtrlButtonTraces = document.getElementById('ButtonTraces1');
      var divMap = document.getElementById('map');
      if ((divMap) && (oCtrlButtonTraces))
         if (oCtrlButtonTraces.mode == 0)
            oCtrlButtonTraces.setCursor('crosshair');

  });
  
  GEvent.addListener(map, "dragend", function(){
      var oCtrlButtonTraces = document.getElementById('ButtonTraces1');
      var divMap = document.getElementById('map');
      if ((divMap) && (oCtrlButtonTraces))
         if (oCtrlButtonTraces.mode == 0)
            window.setTimeout("var oCtrlButtonTraces = document.getElementById('ButtonTraces1'); if (oCtrlButtonTraces) oCtrlButtonTraces.setCrosshairCursor()", 20);

  });
  
  this.oButtonTraces.decode=function(sEncoded)
  {
      this.encoded=sEncoded;
      decode(sEncoded);
      hideMarkers();
  }

  this.oButtonTraces.applyTitle=function(){
    if (oInterfaceText)
        if (this.mode==0)
            this.title=oInterfaceText.getItemValue('TracesButtonControlTitleDown',1);
        else
            this.title=oInterfaceText.getItemValue('TracesButtonControlTitleUp',1);
  }
  
  container.appendChild(this.oButtonTraces);
  
  map.getContainer().appendChild(container);
  return container;
}

DrawingControl.prototype.setTitle = function(sNewPushpinButtonTitleUpNoTraces, sNewPushpinButtonTitleUpTraces, sNewPushpinButtonTitleDown, sNewTracesButtonTitleUp, sNewTracesButtonTitleDown) {
  this.applyTitles();
}

DrawingControl.prototype.applyTitles = function() {
    if (this.oButtonPushpin)
        this.oButtonPushpin.applyTitle();
            
    if (this.oButtonTraces)
        this.oButtonTraces.applyTitle();
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
DrawingControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(25, 295)); //, new GSize(5, 27)
}


// Ad control
function AdControl() {
    this.container = null;
//    this.oAd = null;
}

AdControl.prototype = new GControl(false, false);

// We add the control to
// to the map container and return the element for the map class to
// position properly.
AdControl.prototype.initialize = function(map) {
  this.container = document.createElement("div");

  if (window.screen.availWidth < 1100){
      this.container.innerHTML = "<iframe FRAMEBORDER=0 style='width:100%; height:100%' src='AdControlContentS.htm'></iframe>";
      this.container.style.width = "234px";
      this.container.style.height = "60px";
  }
  else{
    if (window.screen.availWidth < 1200){
      this.container.innerHTML = "<iframe FRAMEBORDER=0 style='width:100%; height:100%' src='AdControlContentM.htm'></iframe>";
      this.container.style.width = "468px";
      this.container.style.height = "60px";
    }
    else{
      this.container.innerHTML = "<iframe FRAMEBORDER=0 style='width:100%; height:100%' src='AdControlContentL.htm'></iframe>";
      this.container.style.width = "728px";
      this.container.style.height = "90px";
    }
  }
  this.container.style.overflow = "hidden";
  this.container.style.scroll = "none";
  
  map.getContainer().appendChild(this.container);

  return this.container;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
AdControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(300, 0)); //, new GSize(5, 27)
}


