﻿// JScript File
var flamingo = null;
var childPopups  = new Array();
var childPopupNr = 0;
var newWin;

//START TOGGLE functions
var isCollapsed = false;
var isVisible = true;

function slideSideBar() {
    
    if (isCollapsed) {
        //console.log('Uitschuiven en dan zichbaar maken call');
        $("#flashcontent").animate({left: "701px" }, "swing");
        $("#left").animate({ width: "700px" }, "swing", toggleVisibility);                
        $("#toggleButton").text("<<");
        
        // overflow aanzetten
    }
    else {
        //console.log('Inschuiven');
        $("#flashcontent").animate({left: "211px" }, "swing");
        $("#left").animate({ width: "210px" }, "swing");
        $("#toggleButton").text(">>");
        
        // overflow uitzetten
        
        //console.log($("#left").css("overflow"));
        //$("#left").css("overflow-y","hidden");
    }
    
    isCollapsed = !isCollapsed;
}

function toggleVisibility() {
    
    if (isVisible) {
        //console.log('Hiden en dan inschuiven');
        $("#pnlInhoud").fadeOut("fast", slideSideBar); //find("*").not("#toggleButton").
    }
    else {
        //console.log("Tonen");
        $("#pnlInhoud").fadeIn("fast");
    } 
    
    isVisible = !isVisible;           
}

function toggleOn() {
    // Uitklappen zodat de text zichtbaar is: enkel wanneer dit niet het geval is
    if (isCollapsed) {
        slideSideBar();
    }
}

$(document).ready(function() {
    $('#toggleButton').click(function() {
        if (isCollapsed) {
            //console.log("Eerst uitschuiven");
            slideSideBar();
        }
        else {
            //console.log("Open dus eerst onzichtbaar maken");
            toggleVisibility();
        }
    });
});

// other functions

function openNewWindow(URLtoOpen, windowName, windowFeatures) {
// open a child popup
    newWin = window.open("", windowName, windowFeatures);
    if (newWin != null) {
        newWin.location.href = URLtoOpen;
        newWin.focus();
        childPopups[childPopupNr++] = newWin;
    }
}
function closeDepWins() {
// Close any open child popup windows (called from body onUnload event)
    for (var i = 0; i < childPopups.length; i++) {
        if (childPopups[i] && !childPopups[i].closed) {
	        childPopups[i].close();
        }
    }
}

function getDocHeight() {
    var D = document;
    return Math.max(D.body.clientHeight, D.documentElement.clientHeight);
}

function pageLoaded(){
    //  Set correct height for the flash map
    mapDiv = document.getElementById("sidebar2");
    flashDiv = document.getElementById("flashcontent");
    
    docHeight = getDocHeight();
    flashDiv.style.height = docHeight + "px";
    mapDiv.style.height = docHeight + "px";
           
}

function Left(str, n){
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function OpenPanel()
{
    var paneel = $find('KlapMaarOpen');
    if (paneel.get_Collapsed()){
        paneel.expandPanel();
        this.document.getElementById("content").style.width=this.document.body.clientWidth-215;
        
    }
}
function ClosePanel()
{
    var paneel = $find('KlapMaarOpen');
    if (!paneel.get_Collapsed()){
        paneel.collapsePanel();
    }
}

function GetCheckedItems()
{

    var element;
    var stritems = "";
    for (var i = 0; i < document.form1.elements.length; i++) 
    {
        element = document.form1.elements[i];
        //if (element.tagName == "INPUT" && element.type == "image" && element.name == _varButtonId) {
        if (Left(element.id, 6) == "chkadd" && element.checked) {
            stritems += element.id + ",";
        }
    }

    document.getElementById("hfCheckedItems").value = stritems;
}

function CheckAll(val)
{

    var element;
    for (var i = 0; i < document.form1.elements.length; i++) 
    {
        element = document.form1.elements[i];
        if (Left(element.id, 6) == "chkadd") {
            element.checked = val;
        }
    }
    GetCheckedItems();
}

function GetExtent()
{
    var extent = flamingo.call("map", "getCurrentExtent");
     var strextent = "";
    if (extent != null & extent != undefined)
    {    
        strextent = (Math.round(extent.minx)).toString() + " " + (Math.round(extent.maxx)).toString() + " " + (Math.round(extent.miny)).toString() + " " + (Math.round(extent.maxy)).toString();
    }
    else
    {
        strextent = "unknown";
    }
    document.getElementById("hfCurrentExtent").value = strextent;
    //extents are string in the format "xmin xmax ymin ymax"
    //alert(strextent);
}

function ZoomToExtent(val)
{
    var coords = val.split(" ");
    var extent = new Object;
    extent.minx = Math.round(coords[0]*0.99995);
    extent.maxx = Math.round(coords[1]*1.00005);
    extent.miny = Math.round(coords[2]*0.99995);
    extent.maxy = Math.round(coords[3]*1.00005);
    flamingo.call("map", "moveToExtent", extent, 0, 0);
}

function IMG1_onclick() {}


