﻿// 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='../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)
                    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(10, 0)); //, 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='../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 = "m";
    var sDUKM = "km";
    var sDUMin = "Minuty";
    var sDUH = "Godziny";
    var sDUD = "Dni";
    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(10, 400)); //, 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.title='Drukuj mapę';
  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='../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="Zgloś błąd/wyślij wiadomość";
  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('http://www.maps.com.pl/?q=contact', 'Kontakt','menubar=no, toolbar=no, location=no, scrollbars=no, resizable=yes, status=no, width=800, left=30, top=30');//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='../images/email_icon_3.gif';
  
  oEMailInternal.appendChild(oEMailImg);
  this.oEMail.appendChild(oEMailInternal);
  container.appendChild(this.oEMail);


   
 


  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, 80)); //, new GSize(5, 27)
}




