function changeSize(div, width, height, transparent)
{
    div.style.height = height;
    div.style.width = width;
    if (transparent)
    {
        div.style.filter = "alpha(opacity=92)";
	div.style.opacity = "0.92";
    }
    else
    {
	div.style.filter = "alpha(opacity=100)";
	div.style.opacity = "1.00";
    }
}

function changeTransparency(val, transparencyInput, map)
{
    transparencyInput.value = val;
    if (transparencyInput.value < 0.0)
		transparencyInput.value = 0;
    if (transparencyInput.value > 1.0)
		transparencyInput.value = 1.0;
    for (var i = 0; i < map.overlayMapTypes.length; i++) {
	var overlay = map.overlayMapTypes.getAt(i);
	if (overlay == null) continue;
	var opt = overlay.getOptions();
	if (opt.noChange == true) continue;
	opt.opacity = transparencyInput.value / 1;
	var imgMap = new google.maps.ImageMapType(opt);
	imgMap.setOptions(opt);
	map.overlayMapTypes.setAt(i, imgMap);
    }
}

function loadTrackbar(tableID, transparencyInput, map)
{
	var trackbar = new Trackbar(0, 1, 200, function (val) {
	    changeTransparency(val, transparencyInput, map);
	});
	//trackbar.GetContainer().style.display = 'inline';
	trackbar.GetContainer().style.position = 'relative';
	trackbar.GetContainer().style.top = '0px';
	trackbar.GetContainer().style.left = '0px';
	trackbar.GetContainer().style.width = '200px';
	trackbar.SetCurrentValue(transparencyInput.value);
	var tblBody = document.getElementById(tableID).tBodies[0];
	var newRow = tblBody.insertRow(-1);
	var newCell0 = newRow.insertCell(0);
	newCell0.colSpan = "2";
	newCell0.innerHTML = "<h4 class='vis'>Widoczność warstw</h4>";
	tblBody = document.getElementById('tableVis').tBodies[0];
	newRow = tblBody.insertRow(-1);
	newCell0 = newRow.insertCell(0);
	newCell0.colSpan = "2";
	newCell0.appendChild(trackbar.GetContainer());
	newRow = tblBody.insertRow(-1);
	newCell0 = newRow.insertCell(0);
	newCell0.innerHTML = "<span class=\"skala\">0%</span>";
	newCell0.style.textAlign = "left";
	newCell0 = newRow.insertCell(-1);
	newCell0.innerHTML = "<span class=\"skala\">100%</span>";
	newCell0.style.textAlign = "right";
	trackbar.StartListening();
}

function detect()
{
	if(navigator.userAgent.indexOf("MSIE") != -1)
	{
		if(/MSIE 6/i.test(navigator.userAgent))
		{
		
			document.body.style.width = "800px";
			document.body.style.height = "500px";
			document.body.style.overflow = "auto";
		
			var ramka = document.getElementById("ramka");
			var mapa = document.getElementById("mapka");
			var ladowanie = document.getElementById("big_window");
		
			ramka.style.height = (screen.height - 150) + "px";
			ramka.style.borderBottom = "1px solid #D1E785";
		
			mapa.style.height = (screen.height - 150) + "px";
			mapa.style.width = (screen.width - 22 - 250) + "px";
		
			ladowanie.style.height = (screen.height - 150) + "px";
			ladowanie.style.width = (screen.width - 22 - 250) + "px";
		}
		else
		{
			loadTrackbar();
			
			window.onresize = refresh;
		}
	}
	else
	{
		loadTrackbar();
		
		window.onresize = refresh;
	}
}

function refresh()
{
	// TODO: funkcja odświeżająca wymiary warstwy z ramką
	//alert("cc");
}

function showHide()
{
	
	if(document.getElementById("legenda").style.display == "none")
	{
		document.getElementById("legenda").style.display = "block";
		document.getElementById("tresc").style.left = "250px";
		document.getElementById("ramka").style.width = "250px";
	}
	else
	{
		document.getElementById("legenda").style.display = "none";
		document.getElementById("tresc").style.left = "0px";
		document.getElementById("ramka").style.width = "0px";
	}
}

function showHideIE6()
{
	
	if(document.getElementById("legenda").style.display == "none")
	{
		document.getElementById("legenda").style.display = "block";
		document.getElementById("tresc").style.left = "250px";
		document.getElementById("ramka").style.width = "250px";
		document.getElementById("mapka").style.width = (screen.width - 22 - 250) + "px";
	}
	else
	{
		document.getElementById("legenda").style.display = "none";
		document.getElementById("tresc").style.left = "0px";
		document.getElementById("ramka").style.width = "0px";
		document.getElementById("mapka").style.width = (screen.width - 22) + "px";
	}
}


var timer = new Array();

// funkcja wyświetla pełny formularz
function showHideForm(divN, divName, width, height, transparent)
{
	if(transparent)
	{
		var w = document.getElementById(divN).style.width;
		var h = document.getElementById(divN).style.height;
		
		if(w != width && h != height)
		{
			timer[divN] = setTimeout('hideForm(\'' + divN + '\',\''+ divName +'\', \'' + width + '\',\'' + height + '\')', 300);
		}
	}
	else
	{
		clearTimeout(timer[divN]);
	
		document.getElementById(divN).style.height = height;
		document.getElementById(divN).style.width = width;
		document.getElementById(divN).style.filter = "alpha(opacity=100)";
		document.getElementById(divN).style.opacity = "1.00";

		document.getElementById(divName).style.display = "block";
	}
}

function hideForm(divN, divName, width, height)
{
		document.getElementById(divN) .style.filter = "alpha(opacity=92)";
		document.getElementById(divN).style.opacity = "0.92";
		document.getElementById(divN).style.height = height;
		document.getElementById(divN).style.width = width;
		document.getElementById(divName).style.display = "none";
}

function showDisclaimer()
{
	document.getElementById('big_window').style.display = 'inline';
}

function hideDisclaimer()
{
	document.getElementById('big_window').style.display = 'none';
}

function wait(map) {
    document.body.style.cursor = "wait";
    map.setOptions({draggableCursor: "wait"});
}

function endWaiting(map) {
    document.body.style.cursor = "default";
    map.setOptions({draggableCursor: "pointer"});
}
