function setEditValue(edit, value)
{
    var editControl = window.opener.document.getElementById(edit);
    if  (editControl != null)
        editControl.value = value;
    window.close();
}

function checkAll(masterCheckClientId)
{
	if (typeof(checks) != "undefined" && checks != null)
	{
		var check = document.getElementById(masterCheckClientId);
		for(counter = 0; counter < checks.length; counter++)
		{
			var option = document.getElementById(checks[counter]);
			if (option != null && !option.disabled)
				option.checked = check.checked;
		}
	}
}

function tryUncheckMasterCheck(slaveCheckClientId, masterCheckClientId)
{
	masterCheck = document.getElementById(masterCheckClientId);
	slaveCheck = document.getElementById(slaveCheckClientId);
	
	if (!slaveCheck.checked && masterCheck.checked)
		masterCheck.checked = false;
}

function confirmation(text)
{
    if (!window.confirm(text))
	    event.returnValue = false;
}

function changeChecked(masterCheck)
{
  var masterControl = document.getElementById(masterCheck);
  if(masterControl != null)
  {
		var list = rights_Forward;
		if(!masterControl.checked)
			list = rights_Backward;
			
		for(counter = 0; counter < list.length; counter++)
		{
			var check = document.getElementById(list[counter]);
			if(check == masterControl)
				break;
				
			check.checked = masterControl.checked;
		}
  }
}

function showInPopUpWindow(url, windowName)
{
  var win = window.open(url, windowName, "width=1000,height=740,left=5,top=5,scrollbars=yes,resizable=yes");
  win.focus();
}

function showInPopUpWindowWithPosition(url, windowName, left, top)
{
  var win = window.open(url, windowName, "width=1000,height=740,left=" + left + ",top=" + top + ",scrollbars=yes,resizable=yes");
  if(win != null)
	win.focus();
  else
    alert('Nepodařilo se otevřít nové okno. Pravděpodobně máte zakázáno otevírání PopUp oken.');
}

function submitOnEnter(submitButtonClientId)
{
	if (window.event != null)
	{
		if(window.event.keyCode==13) 
		{
			var butt = document.getElementById(submitButtonClientId);
			butt.click();
			window.event.returnValue = false;
		}
	}
}

function getValueFromHidden(hidClientId)
{
	hidValue = 0;
	hidClient = document.getElementById(hidClientId);
	colorId = (hidClient != null) ? colorId = hidClient.value : hidClientId.value; 
	
	return parseInt(colorId);
}

function pageAutoRefresh(second)
{
	setTimeout("window.location.reload(true)", second * 1000);
}

function disableObjects()
{
	for(counter = 0; counter < disabledControls.length; counter++)
	{
		ctrl = document.getElementById(disabledControls[counter]);
		if(ctrl != null)
			ctrl.disabled = !ctrl.disabled;
	}
}

function GetE(elementId)
{
	return document.getElementById(elementId);
}

function selectRadios(list)
{
	for(counter = 0; counter < list.length; counter++)
	{
		radio = document.getElementById(list[counter]);
		if(!radio.checked)
			radio.checked = true;
	}
}

function ScriptFunction(url, itemId)
{
    var xmlhttp = false;

	try 
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e) 
	{
		try 
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E) 
		{
			xmlhttp = false;
		}
	}
	
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
	{
		xmlhttp = new XMLHttpRequest();
	}
	
	xmlhttp.open("GET", url, true);
	
	xmlhttp.onreadystatechange = function() {

		if (xmlhttp.readyState == 4)
		{
		    document.getElementById(itemId).innerHTML = xmlhttp.responseText;			
		}
	}
	
	xmlhttp.send(null)
}

function ChangeSessionTimeout(targetTextItem, time, errorUrl) 
{
	time = time - 1;
	var minutes = Math.floor(time / 60);
	var seconds = time % 60;
	var timeText = "";
	if (minutes < 10)
		timeText = "0" + minutes;
	else
		timeText = minutes;
	if (seconds < 10)
		timeText = timeText + ":0" + seconds;
	else
		timeText = timeText + ":" + seconds;
	var item = document.getElementById(targetTextItem)
	if (time > 0)
	{
		if (item != null)
		{
			item.innerHTML = timeText;
			if (time < 180)
				item.style.color = "red";
		}
		
		window.setTimeout ('ChangeSessionTimeout(\'' + targetTextItem + '\', ' + time + ', \'' + errorUrl + '\');', 1000);
	}
	else
	{
		//window.location.reload(true);	
		window.location.href = errorUrl;
	}
}

function LoadPngs(blankImagePath)
{
 if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) 
 {
  var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
  var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7.0);
       // debugger
       
        if (itsAllGood)
        {
         document.writeln('<style type="text/css">img { visibility:hidden; } </style>');
            for(var i=0; i<document.all.length; i++)
            {
              var img = document.all[i]
              if (img.src != null)
              {
                  var imgName = img.src.toUpperCase()
                  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
                  {
                //alert('ok');
                var src = img.src;
                img.style.width = img.width + "px";
                img.style.height = img.height + "px";
                img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader  (src='" + src + "')";
                img.src = blankImagePath;
           }
           img.style.visibility = "visible";
          }
       }
      }
 }
}

function nabidka(idex) 
{
    if (idex.style.display == 'none')
        idex.style.display = '';
    else
        idex.style.display = 'none'
}

function checkNumber(objEvent) 
{
    var unicode = objEvent.charCode ? objEvent.charCode : objEvent.keyCode;
    if (unicode != 8)
        if (unicode < 48 || unicode > 57)
        return false;
}

function checkNumberWithSpace(objEvent) 
{
    var unicode = objEvent.charCode ? objEvent.charCode : objEvent.keyCode;
    if (unicode != 8)
        if ((unicode < 48 || unicode > 57) && unicode != 32)
        return false;
}

function selectRadios(list) 
{
    for (counter = 0; counter < list.length; counter++) 
    {
        radio = document.getElementById(list[counter]);
        if (!radio.checked)
            radio.checked = true;
    }
}
