﻿function setTab(name,cursel,n){
 for(i=1;i<=n;i++){
  var menu=document.getElementById(name+i);
  var con=document.getElementById("con_"+name+"_"+i);
  menu.className=i==cursel?"hoverfunction":"";
  con.style.display=i==cursel?"block":"none";
 }
}

function setText(textBox1,textBox2)
{
    var htmlTextbox1=document.getElementById(textBox1);
    var htmlTextbox2=document.getElementById(textBox2);
    htmlTextbox1.value=htmlTextbox2.value;
}

function hideDiv(divId)
{
    var divH=document.getElementById(divId);
    divH.style.display='none';
}

function ShowToolInfo(tip)
{
    ToolInfoTip.style.display='block';
    ToolInfoTip.style.top=100;
    ToolInfoTip.style.left=340;
    var tipBox=document.getElementById('TxtInfoTip');
    tipBox.value=tip
    
    setTimeout("CloseToolInfo()",3000);
}

function CloseToolInfo()
 {
    ToolInfoTip.style.display='none';
 }
function ToolPanelFunction()
{
//    var mapImage = document.getElementById("MapControl1_Image");
    var psel = FindElement("PntSel_Image");
    var activeTool = document.getElementById("PntSelActive");
    if(MainLeft.style.display=='none')
    {
        MainLeft.style.display='block'
        
        if(activeTool.value!="")
       {
           psel.fireEvent("onclick");
           psel.fireEvent("onclick");
           
           AppendScriptToForm('MapPanTool.Activate();');
       } 
       
        MainCenter.style.backgroundImage = 'url(images/MainCenterBG.jpg)';      
    }
    else if ( MainLeft.style.display=='block')
    {
        MainLeft.style.display='none'
       
         if(activeTool.value!="")
       {
           psel.fireEvent("onclick");
           psel.fireEvent("onclick");
       } 
       MainCenter.style.backgroundImage = 'url(images/MainCenterRBG.jpg)'; 
    }
    mapSize();
    GetMap("MapControl1");
}
function setMainHeight()
{
    var mapImage = document.getElementById("MapControl1_Image");
        var mainHeight=screen.availHeight;
        MainLeft.style.height=mainHeight-345;
        Panel1.style.height=mainHeight-381;
        MainCenter.style.height=mainHeight-345;
        mapdiv.style.height=mainHeight-345;
        TrackLayer.style.height=mainHeight-345;
        mapImage.style.height=mainHeight-345;
}

function mapSize()
{
    var mapImage = document.getElementById("MapControl1_Image");
    var mainWidth = window.innerWidth;
    if (mainWidth == null)
    {
	    if (document.documentElement && document.documentElement.clientWidth)
		    mainWidth = document.documentElement.clientWidth
	    else	
		    mainWidth = document.body.clientWidth;
    }
    var mainHeight = window.innerHeight;
    if (mainHeight == null)
    {
	    if (document.documentElement && document.documentElement.clientHeight)
		mainHeight = document.documentElement.clientHeight;
	    else
		mainHeight = document.body.clientHeight;
    }
    
    MainLeft.style.height=mainHeight-180;
    Panel1.style.height=mainHeight-216;
    MainCenter.style.height=mainHeight-180;
    mapdiv.style.height=mainHeight-180;
    TrackLayer.style.height=mainHeight-180;
    mapImage.style.height=mainHeight-180;
    
    
    if(MainLeft.style.display=="none")
    {
        mapdiv.style.width=mainWidth-10;
        mapmain.style.width=mainWidth-10;
        TrackLayer.style.width=mainWidth-10;
        mapImage.style.width=mainWidth-10;
    }
    else if(MainLeft.style.display=="block")
    {
        mapdiv.style.width=mainWidth-285;
        mapmain.style.width=mainWidth-285;
        TrackLayer.style.width=mainWidth;
        mapImage.style.width=mainWidth-285;
    }
    
    setTimeout("mapSize()",1000);
  }
  
  function GetMouseWheelEvent()
    {
        TabPName.style.display="none";
        var mapImage = document.getElementById("MapControl1_Image");
        var mc = FindElement("MapControl1");
        var url = "MapController.ashx?Command=WheelZoom&Width=" + mapImage.width +"&Height=" + mapImage.height
         + "&ExportFormat=" + mapImage.exportFormat + "&Ran=" + Math.random() + "&wheelvalue=" + event.wheelDelta;
        if (mapImage.mapAlias) 
            url += "&MapAlias=" + mapImage.mapAlias;  
            url +="&X=" + event.clientX ;
            url +="&Y=" + event.clientY;
            
        mapImage.style.left = 0;
        mapImage.style.top = 0;
        mapImage.style.clip = 'rect(' + 0 + ' ' +  mapImage.width + ' ' + mapImage.height + ' ' + 0 +')';      
        try 
        {
            mapImage.src = url;
        }
        catch(e)
        { 
            alert("Error!");
        }
    }
    
    function getZoomLevel()
	  {
         var mapImage = document.getElementById("MapControl1_Image"); 
         var ur=  "MapController.ashx?Command=ZoomLevel" +
                        "&MapAlias=" + mapImage.mapAlias + 
                        "&Ran=" + Math.random();
        var xmlHttp = CreateXMLHttp();
        xmlHttp.open("GET", ur, false);
        xmlHttp.send(null);
        var result = xmlHttp.responseText;
        var level = parseFloat(result);
       var select = FindElement("SelDiv"); 
       var rec = FindElement("RegSel_Image");
       var activeTool = document.getElementById("RegSelActive");
       if(level>250)
       {
            if(activeTool.value!="")
            {
                rec.fireEvent("onclick");
            }
            select.style.display = "none";
            
       } 
       else
       {
            select.style.display="block";
       }
          		
    }
    
    function mapResize()
       {
            var mapImage = document.getElementById("MapControl1_Image");
            if(MainLeft.style.display=='none')
            {
//                MainMaptd.style.width = '100%';
                mapImage.width = MainMaptd.style.width;
//               mapdiv.style.width = MainMaptd.style.width;
                mapImage.height = Main.style.height;  
              
            }
            else if ( MainLeft.style.display=='block')
            {
               mapImage.width = Main.style.width - MainLeft.style.width - MainCenter.style.width;
               mapImage.height = Main.style.height; 
            }   
            GetMap("MapControl1");
        } 
        



