function getDocumentWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function getDocumentHeight() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function setLayout() {
  var nHeight = getDocumentHeight();

  if (window.document.getElementById('page')) {
    var nMainContentHeight = nHeight - 200;
    if (nMainContentHeight < 600) {
      nMainContentHeight = 550;
    }
    window.document.getElementById('page').style.height = (nMainContentHeight + 165) + 'px';
    window.document.getElementById('mainContentInside').style.height = nMainContentHeight + 'px';
  }
}


			    
   function validateDate(date)
   {	
		dateRegex = /^(((0?[1-9]|1\d|2[0-8])\.(0?[1-9]|1[012])|(29|30)\.(0?[13456789]|1[012])|31\.(0?[13578]|1[02]))\.(19|[2-9]\d)\d{2}|29\.0?2\.((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$/
		return date.match(dateRegex);
   }
   
   function validateTime(time)
   {
		timeRegex = /^(([0-9])|([0-1][0-9])|([2][0-3])):(([0-9])|([0-5][0-9]))(:[0-5]\d)?$/;
		return time.match(timeRegex);
   }
   
		    	
	/**
	 * Shows under construction alert
	 */
	function underConstruction()
	{
		alert('Tato funkce zatím není podporována.');
	}
	
	
	/**
	 * Shows element
	 */			
	function showElement(id)
	{
		var object = document.getElementById(id);
		object.style.display = 'block';
	}
	
	
	/**
	 * Hide element
	 */			
	function hideElement(id)
	{
		var object = document.getElementById(id);
		object.style.display = 'none';
	}
	
	
	/**
	 * Switch show/hide of element
	 */			
	function switchDisplayElement(id)
	{
		var object = document.getElementById(id);
		if (object.style.display == 'none') {
			object.style.display = 'block';
		} else {
			object.style.display = 'none';
		}
	}
	
	
	/**
	 * Switch show/hide of element
	 */			
	function isEmpty(id)
	{
		var object = document.getElementById(id);
		if (object.value == '') {
			return true;
		} else {
			return false;
		}
	}
	
	
	
	/**
	 * Shows curtain - for preventing double clicks
	 */			
	function showCurtain()
	{
		// move curtainText to center
		var object = document.getElementById('curtainText');
		var top = (document.body.clientHeight - 50) / 2;
		var left = (document.body.clientWidth - 300) / 2;
		object.style.top = top + 'px';
		object.style.left = left + 'px';
		
		showElement('curtain');
		showElement('curtainText');
	}
	
	/**
	 * Hides curtain
	 */			
	function hideCurtain()
	{
		hideElement('curtain');
		hideElement('curtainText');
	}
		
	
	
	/**
	 * Submit with confirmation and curtain
	 *
	 * @param string text confirmation text
	 */
	function safeSubmit(text)
	{
		if ((text=='') || confirm(text)) {
			showCurtain();
			return true;
		} else {
			hideCurtain();
			return false;
		}
	}
	
	
	/*
	 * PULLDOWN MENU 
	 */
	
	menuHover = function() {
		var oMenu = document.getElementById("mainMenuUL").getElementsByTagName("LI");
		
		for (var i=0; i<oMenu.length; i++) {
			oMenu[i].onmouseover=function() {
				this.className+=" menuHover";
			}
		
			oMenu[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" menuHover"), "");
			}
		}
	}
	
	if (window.attachEvent) {
		window.attachEvent("onload", menuHover);
	}
	
	
	
	
	/*
	 * (UN)ASSIGN OBJECT
	 */
	
	
	/**
	 *
	 */
	function assignObject(objectName, objectNameForAssign)
	{
		objectNameList = objectName + 'List';
		
		uSelect = document.getElementById('unassigned' + objectNameList);
		aSelect = document.getElementById('assigned' + objectNameList);
		aDiv = document.getElementById('currentAssigned' + objectNameList);
		
		for (i = uSelect.length - 1; i >= 0; i--) {
			if (uSelect.options[i].selected) {
				var newOpt = document.createElement('option');
				newOpt.text = uSelect.options[i].text;
				newOpt.value = uSelect.options[i].value;
			
				uSelect.remove(i);
				try {
					aSelect.add(newOpt, null); // standards compliant; doesn't work in IE
				} catch(ex) {
					aSelect.add(newOpt); // IE only
				}
				
				if(document.getElementById('currentAssigned' + objectName + '_' + newOpt.value)) {
					deleteInput = document.getElementById('deleteAssigned' + objectName + '_'+ newOpt.value);
					aDiv.removeChild(deleteInput);
				} else {
					var newInput = document.createElement('input');
					newInput.id = 'insertAssigned' + objectName + '_' + newOpt.value;
					newInput.type = 'hidden';
					newInput.name = objectNameForAssign + '[' + newOpt.value + ']';
					newInput.value = 'insert';
					
					aDiv.appendChild(newInput);
				}
			}
		}
		
		return false;
	}
	
	/**
	 *
	 */
	function unassignObject(objectName, objectNameForAssign)
	{
	
		objectNameList = objectName + 'List';
		
		uSelect = document.getElementById('unassigned' + objectNameList);
		aSelect = document.getElementById('assigned' + objectNameList);
		aDiv = document.getElementById('currentAssigned' + objectNameList);
		
		for (i = aSelect.length - 1; i >= 0; i--) {
			if (aSelect.options[i].selected) {
				var newOpt = document.createElement('option');
				newOpt.text = aSelect.options[i].text;
				newOpt.value = aSelect.options[i].value;
			
				aSelect.remove(i);
				try {
					uSelect.add(newOpt, null); // standards compliant; doesn't work in IE
				} catch(ex) {
					uSelect.add(newOpt); // IE only
				}
				
				if(document.getElementById('currentAssigned' + objectName + '_' + newOpt.value)) {
					var deleteInput = document.createElement('input');
					deleteInput.id = 'deleteAssigned' + objectName + '_' + newOpt.value;
					deleteInput.type = 'hidden';
					deleteInput.name = objectNameForAssign + '[' + newOpt.value + ']';
					deleteInput.value = 'delete';
					
					aDiv.appendChild(deleteInput);
				} else {
					oldInput = document.getElementById('insertAssigned' + objectName + '_' + newOpt.value);								
					aDiv.removeChild(oldInput);
				}
			}
		}
		
		return false;
	}



	/**
	 * This function searches for all checkboxes in specified form and check/uncheck them
	 *
	 * @param formId - id of form
	 * @param value - 1 to check, 0 to uncheck, NULL to invert selection
	 * @return void
	 */
	function checkAllCheckboxes(formId, value)
	{
		var form = document.getElementById(formId);
		if (!form) {
			return;
		}
		
		var inputs = form.getElementsByTagName("input");
		for (var i=0; i<inputs.length; ++i) {
			var input = inputs[i];
			if (input.type == 'checkbox') {
				
				if (value == 1) {
					input.checked = true;
				} else if (value == 0) {
					input.checked = false;
				} else if (!value) {
					input.checked = !input.checked;
				}
			}
		}
	}
	
	
	
	
	/**
	 * Invert check/uncheck of a checkbox
	 *
	 * @param checkboxId - id of checkbox
	 * @return void
	 */
	function invertCheck(checkboxId)
	{
		var checkbox = document.getElementById(checkboxId);
		if (!checkbox) {
			return;
		}

		checkbox.checked = !checkbox.checked;
	}
	
