﻿// JScript File
//Id for label that show the current location tha the user zoomed to
var ZoomToLocationTextID = "LabelZoomToArea";
//Div ID:s for controls that hide/show the controls inside the Drawingbox floatingpanel
//Holds the time from last print map
var TimeLastPrint = 0;

function ChangeSearchForm(DraingBoxDivIDToShow)
{

    //ASP.NET? adds Serch_ to id of SelectSearchForm id!
    var chosenSerchForm = document.getElementById('Search_SelectSearchForm').value;
    var i=1;
    var currentHeight = 0;
    var currentWidth = 0;
    while(document.getElementById("SearchForm" + i) != null)
    {
        var currentForm = document.getElementById("SearchForm" + i);
        if(("SearchForm" + i) == chosenSerchForm)
        {
            currentHeight = document.getElementById("Search_QueryAttributesTask" + i).clientHeight;
            currentWidth = document.getElementById("Search_QueryAttributesTask" + i).clientWidth;
            currentForm.style.visibility = "visible";
            currentForm.style.top = "0px";
            currentForm.style.zIndex = "999999";
        }
        else
        {
            currentForm.style.visibility = "hidden";
            //Fix for Internet explorer where hidden div:s makes it impossible 
            // to click on the Text box bellow it.
            currentForm.style.top = "200px";
            
        }
        i++;
    }
    
    var height = document.getElementById("SearchTable").clientHeight + currentHeight;
    document.getElementById("Search_SideResizeCell").style.height = height + "px";
    document.getElementById("Search_BodyCell").style.height = height + "px";
    /*if (map != null && webMapAppLeftPanelWidth < currentWidth + 10)
    {
        webMapAppLeftPanelWidth = currentWidth + 10;
        if (map != null)
            AdjustMapSize();
    }*/
} 

var Groups = new Object;
function MarkTreeNodes(id, taskresultId)
{
    var ids = Groups[id];
    var idArray = ids.split(",");
    for(var i=0; i < idArray.length; i++)
    {
        SetCheckBoxChecked(idArray[i] + "_CheckBox");
        //ANHI 9.3 Migration
        //TreeViewPlusObjects[taskresultId].nodeChecked(idArray[i]);
        $find(taskresultId)._nodeChecked(idArray[i]);
    }
}

function Print(argument,context)
{
    
    date = new Date();
    if((date.getTime() - TimeLastPrint) > 3000)
    {
        var keyPairs = new Array();
        for(var i=0; i < argument.split("&").length; i++) 
        {
            var keyValue = argument.split("&")[i];
            keyPairs[i] = new Array();
            keyPairs[i][0] = keyValue.split("=")[0];
            keyPairs[i][1] = keyValue.split("=")[1];
        }
        TimeLastPrint = date.getTime();
        if(keyPairs[0][1] == "1")
        { 
           printWindow = window.open("PrintForm.aspx?width=" + keyPairs[1][1] + "&height=" + keyPairs[2][1],"printWindow","location=0,status=1,scrollbars=0,width=" + keyPairs[1][1] + ",height=" + keyPairs[2][1]);
        }
        else
        {
            printWindow = window.open("CopyMapForm.aspx","printWindow","location=0,status=1,scrollbars=0,width=" + keyPairs[1][1] + ",height=" + keyPairs[2][1]);
        }
        //printWindow.moveTo(0,0);
    }
    
}

function ShowDiv(divID)
{
    document.getElementById(divID).style.visibility = "visible";
}
        
function HideDiv(divID)
{
    document.getElementById(divID).style.visibility = "hidden";
}

function clearIdentifyLocation() 
{
    if (document.getElementById("IdentifyLocation") != null)
        document.getElementById("IdentifyLocation").style.visibility = "hidden";
}

function showCoords(e)
{
    var coordText = document.getElementById("Coordinates");
    
    //ANHI 9.3 Migration
    if (coordText == null || map == null || map._containerDiv.id == null)
        return;
    
    //retrieves current coord unit from hidden variable.  If Map Properties floating panel id is changed, this must be updated.
    webMapCoordUnits = "g"; //document.getElementById("MapProperties_SelectedCoordUnit").value;
    
    getXY(e);
    
    var box = calcElementPosition(map._containerDiv.id); //ANHI 9.3 Migration
    zleft = mouseX - box.left;
    ztop = mouseY - box.top;

    var ExtentStr = document.getElementById("MapExtent").value;
    var ExtentAr = ExtentStr.split(",");
	
    var x = Math.round((ExtentAr[0]*1 + (ExtentAr[1]*1 - ExtentAr[0]*1) * zleft / box.width)*100/100);  
    var y =  Math.round((ExtentAr[3]*1 + (ExtentAr[2]*1 - ExtentAr[3]*1) * ztop / box.height)*100/100);
    
    if(webMapCoordUnits == "latlong")
    {
        var latLonDdStr = convertSP(x,y);
        var ll = latLonDdStr.split(",");
        var LonDD = ll[0];
        var LatDD = ll[1];
        x = (Math.round(LatDD * 1000000)) / 1000000;
        y = (Math.round(LonDD * 1000000)) / 1000000;
        coordText.innerHTML = "Latitud: " + x + ", Longitud: " + y;
    }
    else
    {
        coordText.innerHTML = "Östlig: " + x + ", Nordlig: " + y;
    }
}

function ChangeLocationLabel(LocationLabelText)
{
  document.getElementById(ZoomToLocationTextID).innerHTML = LocationLabelText;
}

function SetCheckBoxChecked(checkboxID)
{
    document.getElementById(checkboxID).checked = "true";
}

function OpenHelp(helpUrl)
{
     printWindow = window.open(helpUrl,"printWindow","location=0,status=1,scrollbars=1,width=730,height=900");
}

