
/* MUUTTUJIA
-------------------------------------------*/
var legendAlias = "Legend1";
var indexmapAlias = "Map3";

var css1024 = "CSS/kala1024.css"
var css1680 = "CSS/kala.css";

//----------------------------------------

function piilotaLegenda()
{
	var legendControl = document.getElementById("LegendControl1");	
	legendControl.style.visibility = "hidden";
    if (legendControl.parentNode.tagName == "DIV")
    {
        legendControl.parentNode.style.visibility = "hidden";
    }
}

function luoLegenda(legendControlId)
{
    var legendControl = FindElement(legendControlId);
    var legendImageId = legendControlId + "_Image";
    var ekalataus = true;
    
    var exportFormat = "Gif";
    
    var url = "MapController.ashx?Command=GetLegend" + 
		    "&MapAlias=[object]" +
			"&LegendExportFormat=" + exportFormat + 
			"&Ran=" + Math.random();
			
	url += "&LegendAlias=Legend1";
    
    legendControl.innerHTML = "<img id='" + legendImageId +  "' src='" + url + "' alt='Legend 1' GALLERYIMG=\"no\"'/>";
    piilotaLegenda();
    showTab1(ekalataus);

}

function paivitaKartta(mapControlId, indexMapId) {
	try {
		var mapImageId = mapControlId + "_Image";
		var indexMapImageId = indexMapId + "_Image";
		
		var mapImage = FindElement(mapImageId);
		var indexMapImage = FindElement(indexMapImageId);
		
		if(indexMapImage) {
		    paivitaIndex(indexMapImage);
		}
		
		if(mapImage) {
			//For situations where percentages (%) are used in the height and width
			// properties of the MapControl (and rendered in the html span and img tags), 
			// for Firefox and Netscape, the pixel dimension of the image object
			// should have been calculated and the heigth and width properties
			// set in the DOM's image object.  For IE, this does not seem to be the case,
			// so the height and width may be 0. See "if" block below.
			var w = mapImage.width;
			var h = mapImage.height;
			var exportFormat = "Gif";
			var url = null;
						
			if (BrowserType() == IE) {
				//If the browser is IE, check if the sizes obtained above are 
				// less than 1 (0, null, nothing),
				// then get height and width in pixels of parent/containing
				// element, namely the SPAN tag, this should have been calculated
				// by IE and the properties set in the style object of SPAN
				if (w < 1) {
					//get width from the SPAN tags "style" property
					w = mapImage.parentElement.style.pixelWidth;
				}
				//get height from the SPAN tags "style" property
				if (h < 1) {
					h = mapImage.parentElement.style.pixelHeight;
				}
				if (mapImage.mapAlias == "") {
					mapImage.mapAlias = mapImage.attributes["mapAlias"].value;
				}
				if (mapImage.exportFormat == "") {
					mapImage.exportFormat = mapImage.attributes["exportFormat"].value;
					exportFormat = mapImage.exportFormat;
				}
			}
			
			//...set the size of the image object to proper pixel dimensions...
			mapImage.width = w;
			mapImage.height = h;

			//...set the image source to a new URL to get a new map image
			// of the proper pixel dimensions
			url = "MapController.ashx?Command=GetMap" + 
				"&Width=" + w +
				"&Height=" + h +
				"&ExportFormat=" + exportFormat + 
				"&Ran=" + Math.random();
				
			//If the map has an alias defined, append it to the url
			if (mapImage.mapAlias != "") {
				url += "&MapAlias=" + mapImage.mapAlias;
			}
			mapImage.style.left = 0;
			mapImage.style.top = 0;
			mapImage.style.clip = 'rect(' + 0 + ' ' + w + ' ' + h + ' ' + 0 +')';
			
			//Set the image object src attribute to the url to get a new map image
			mapImage.src = url;
			
		} else {
			alert("Image '" + mapImageId + "' could not be found on page");	
		}
	} catch (e) {
		//alert("Execption in 'GetMap' function (Command.js)");
	}
}

function paivitaIndex(indexMapImage)
{
    try {
    
        if (indexMapImage)
        {
			var w = indexMapImage.width;
			var h = indexMapImage.height;
			var exportFormat = "Gif";
			var url = null;
						
			if (BrowserType() == IE) {

				if (w < 1) {
					//get width from the SPAN tags "style" property
					w = indexMapImage.parentElement.style.pixelWidth;
				}
				//get height from the SPAN tags "style" property
				if (h < 1) {
					h = indexMapImage.parentElement.style.pixelHeight;
				}
				if (indexMapImage.mapAlias == "") {
					indexMapImage.mapAlias = indexmapAlias;
				}
				if (indexMapImage.exportFormat == "") {
					indexMapImage.exportFormat = indexMapImage.attributes["exportFormat"].value;
					exportFormat = indexMapImage.exportFormat;
				}
			}
			
			//...set the size of the image object to proper pixel dimensions...
			indexMapImage.width = w;
			indexMapImage.height = h;

			//...set the image source to a new URL to get a new map image
			// of the proper pixel dimensions
			url = "MapController.ashx?Command=GetMap" + 
				"&Width=" + w +
				"&Height=" + h +
				"&ExportFormat=" + exportFormat + 
				"&Ran=" + Math.random();
				
			//If the map has an alias defined, append it to the url
			if (indexMapImage.mapAlias != "") {
				url += "&MapAlias=" + indexMapImage.mapAlias;
			}
			indexMapImage.style.left = 0;
			indexMapImage.style.top = 0;
			indexMapImage.style.clip = 'rect(' + 0 + ' ' + w + ' ' + h + ' ' + 0 +')';
			
			//Set the image object src attribute to the url to get a new map image
			indexMapImage.src = url;
			
			} else {
			alert("Image could not be found on page");	
		}
	} catch (e) {
		//alert("Execption in 'GetMap' function (Command.js)");
	}
}

function showOhje()
{
    window.open('Ohjeet.aspx', '', "width=600, height=400", false);
}

function switchCSS(arg)
{
//  ELEMENTIT
    var link = document.getElementsByTagName("link")[0];
    var map1 = document.getElementById("mapMain");
    var map2 = document.getElementById("mapIndex");
    var img1 = map1.childNodes.item(0);
    var img2 = map2.childNodes.item(0);
    var srcImg1 = img1.src;
    var srcImg2 = img2.src;
    
    if (screen.width < 1680)    // RESO 1024 (1280) x 768 (1024)
    {
        link.href = css1024;
        
        map1.style.height = "580px"; // 360
        map1.style.width = "658px"; // 385 // 707
        srcImg1 = srcImg1.replace(/300/, "658"); // 385 // 707
        img1.src = srcImg1.replace(/300/, "580"); // 360
        img1.height = 580; // 360
        img1.width = 658; // 385 // 707
        
        map2.style.height = "200px";    //150
        map2.style.width = "200px";     //150
        srcImg2 = srcImg2.replace(/300/, "200");
        img2.src = srcImg2.replace(/300/, "200");
        img2.height = 200;
        img2.width = 200;
        
        if (arg == true)
        {
            __doPostBack('size', '200,200,580,658'); // 150, 150, 360, 385 / 707
        }
    }
    else                        // RESO 1680 x 1050
    {
        link.href = css1680;
        
        map1.style.height = "550px";
        map1.style.width = "800px";
        srcImg1 = srcImg1.replace(/300/, "800");
        img1.src = srcImg1.replace(/300/, "550");    
        img1.height = 550;
        img1.width = 800;
        
        map2.style.height = "220px";
        map2.style.width = "250px";
        srcImg2 = srcImg2.replace(/300/, "250");
        img2.src = srcImg2.replace(/300/, "220");
        img2.height = 220;
        img2.width = 250;
        
        if (arg == true)
        {
            __doPostBack('size', '220,250,550,800');
        }
    }
}

function showTab1(ekalataus)
{
    var tab1 = document.getElementById("divTasot");
    tab1.style.display = "";
    tab1 = document.getElementById("tab1");
    
    if (document.all) { // IE
        var attr = tab1.attributes.getNamedItem("class");
        attr.value = "selected";
    } else { // FF
        tab1.setAttribute("class", "selected");
    }
    
    var tab2 = document.getElementById("divLisatiedot");
    if (tab2 != null)
    {
        tab2.style.display = "none";
    }
    
    switchCSS(false);
    
    if (document.all) { // IE
        if (ekalataus == false) {
        
        paivitaKartta("mapMain", "mapIndex");
        }
    }
}

function showTab2()
{
    var tab2 = document.getElementById("divLisatiedot");
    tab2.style.display = "";
    tab2 = document.getElementById("tab2");
    
    if (document.all) { // IE
        var attr = tab2.attributes.getNamedItem("class");
        attr.value = "selected";
    } else { // FF
        tab2.setAttribute("class", "selected");
    }
    
    var tab1 = document.getElementById("divTasot");
    if (tab1 != null)
    {
        tab1.style.display = "none";
    }
}

