function previewImage(url)
{
    var wnd = window.open("", "ImagePreview", "height=640,width=400,toolbar=no");
    wnd.document.write("<html>");
    wnd.document.write("<body>");
    wnd.document.write("<a href='javascript:window.close()' title='Kliknij aby zamknąć'><img src='"+url+"' border='0'></a>");
    wnd.document.write("</body>");
    wnd.document.write("</html>");
    wnd.document.images[0].onload = function () {
        wnd.resizeTo(wnd.document.images[0].width+30,wnd.document.images[0].height+100); // = document.images[0].width;
    };
    wnd.document.close();
}

function PopupWindow(url, width, height)
{
	var wnd = window.open(url, 'wnd','location=1,status=0,scrollbars=1,width='+width+',height='+height);
}

function ShowDiv(id)
{
	var div = document.getElementById(id);
	if (div)
	{
		if (div.style.display == "none")
		{
			div.style.display = "block";
		}
		else
		{
			div.style.display = "none";
		}
	}
}
function hightlightControl(id)
{
	var el = document.getElementById(id);
	if (el)
	{
		el.style.backgroundColor = "rgb(243,252,194)";
	}
}
function setFocusOnControl(id)
{
	var el = document.getElementById(id);
	if (el)
	{
		el.focus();
	}
}
function writeToDiv(id, html)
{
	var el = document.getElementById(id);
	if (el)
	{
		el.innerHTML = html;
	}
}
function showProgressBar(sender, id)
{
	var el = document.getElementById(id);
	if (el)
	{
		el.style.display = "block";
	}
	
	sender.disabled = true;
}
function disableControl(sender)
{
	sender.disabled = true;
}
function disableOtherControl(id)
{
	var el = document.getElementById(id);
	if (el)
	{
		el.disabled = true;
	}
}
function clearAndDisableTextBox(sender, id)
{
	var el = document.getElementById(id);
	if (el)
	{
		if (sender.checked)
		{
			el.value = "";
			el.disabled = true;
		}
		else
		{
			el.disabled = false;
		}
	}
}

function countCharsTextBox(sender, max, displayIn)
{
	var el = document.getElementById(displayIn);
	if (el)
	{
		if (sender.value == "")
		{
			el.innerHTML = "Zostało: <b>" + max + "</b> znaków";
			return;
		}
		var count = max - sender.value.length;
		if (count < 0)
		{
			el.innerHTML = "Zostało: <b>0</b> znaków";;
			sender.value = sender.value.substring(0, max);
		}
		else
		{
			el.innerHTML = count > max ? "Zostało: <b>" + max + "</b> znaków" : "Zostało: <b>" + count + "</b> znaków";
		}
	}
}

