function setSizes() {
	var fullS = document["fullscreen"]; 
	var maximized = (null!=fullS && fullS.fullscreen);
//	alert("setSizes "+maximized);
	if (maximized) return;
	var theMiddleDiv;
	var theLeftDiv = document.getElementById("css_left");
	
	if(document.getElementById("css_middle")){
		theMiddleDiv = document.getElementById("css_middle");
	}
	else{
		theMiddleDiv = document.getElementById("css_middle_window");
	}
	
	var height;
	if(null!=theMiddleDiv && null!=theLeftDiv ) {  
		if(theMiddleDiv.offsetHeight > theLeftDiv.offsetHeight){
			height = theMiddleDiv.offsetHeight;
//			alert("1theMiddleDiv.offsetHeight="+theMiddleDiv.offsetHeight+" - "+theLeftDiv.clientHeight);
		}
		else{
			height = theLeftDiv.offsetHeight;
//			alert("2theLeftDiv.offsetHeight="+theLeftDiv.offsetHeight+" - "+theMiddleDiv.clientHeight);
		}
	}
	else if (theMiddleDiv){
		height = theMiddleDiv.offsetHeight;
//		alert("3theMiddleDiv.offsetHeight="+theMiddleDiv.offsetHeight+" - "+theMiddleDiv.clientHeight);
	}
	else if(theLeftDiv){
		height = theLeftDiv.offsetHeight;
//		alert("4theLeftDiv.offsetHeight="+theLeftDiv.offsetHeight+" - "+theLeftDiv.clientHeight);
	}
			 	
	if(height) {	
		var theDiv;
		theDiv = document.getElementById("css_center");
		if( theDiv ) { 
			theDiv.style.height = (height+192) + 'px';//window.screen.height
		}
		theDiv = document.getElementById("css_bottom");
		if( theDiv ) { 
			theDiv.style.top = (height+192) + 'px';//window.screen.height
		}			
		theDiv = document.getElementById("left-border");
		if( theDiv ) { 
			theDiv.style.height = (height+40) + 'px';//window.screen.height
		}			
		theDiv = document.getElementById("right-border");
		if( theDiv ) { 
			theDiv.style.height = (height+40) + 'px';//window.screen.height
		}	
/*		theDiv = document.getElementById("css_left");
		if( theDiv ) { 
			theDiv.style.height = (height+40) + 'px';//window.screen.height
		}*/
	}			
}

function resize(){
	var fullS = document["fullscreen"]; 
	var maximized = (null!=fullS && fullS.fullscreen);
//	alert("resize "+maximized);
	if (!maximized) {
		var theDiv = document.getElementById("css_center");
		if( theDiv ) { 
			theDiv.style.height = 0 + 'px';//window.screen.height
		}
		theDiv = document.getElementById("css_bottom");
		if( theDiv ) { 
			theDiv.style.top = 0 + 'px';//window.screen.height
		}			
		theDiv = document.getElementById("left-border");
		if( theDiv ) { 
			theDiv.style.height = 0 + 'px';//window.screen.height
		}			
		theDiv = document.getElementById("right-border");
		if( theDiv ) { 
			theDiv.style.height = 0 + 'px';//window.screen.height
		}	
/*		theDiv = document.getElementById("css_left");
		if( theDiv ) { 
			theDiv.style.height = 0 + 'px';//window.screen.height
		}*/
	}			
	setSizes();
		
}

function setScrollBarOnTop(divId){
     var inputobj = document.getElementById(divId);  
	 if( inputobj ) {  
		 inputobj.scrollLeft = 5*inputobj.offsetWidth;  
	 } 
}
    
function submitOnSelect() { 
   // document.forms.showTherapeuticsMap.submit();
   var inputobj = document.getElementById( 'submit' );
    if( inputobj ) {  
		 	inputobj.onclick();  
	}  
} 

	
function selectGotoLink(path, selectedParam) {//function link(path, params[][]) {
	var selectedValue=null;
	var inputobj;
	if ((inputobj=document.getElementById(selectedParam))){
	    if(inputobj.length > 0)
		  selectedValue=inputobj.options[inputobj.selectedIndex].value;
/*	 		for(i=0; i<inputobj.length; i++){			
	 			if(inputobj.options[i].selected){				
	 				selectedValue = inputobj.options[i].value;	
	 			}		
	 		}*/		
 	}
	window.location.href=path+selectedParam+"="+selectedValue;
};	

function gotoLink(path, param, value) {//function link(path, params[][]) {
	window.location.href=path+"?"+param+"="+value;
};		

function removeOptions(inputobj){
	  if(inputobj.length > 0){
		  for (var i = inputobj.length - 1; i>=0; i--) {
			  inputobj.remove(i);
		  }
	  }
	}

function removeOptionSelected(selectedId){
  var inputobj = document.getElementById(selectedId);
  removeOptions(inputobj);		
}
	
function showNote(parametr) {
	if(!document.getElementById ) return false;
	 var inputobj = document.getElementById( 'noteLabel' );  
	 if( inputobj ) {  
	 	inputobj.value = parametr;  
	 } 
	return false;
}

var xmlhttp;

function GetXmlHttpObject(){
	if (window.XMLHttpRequest){
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	  }
	if (window.ActiveXObject){
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
}

function sendRequest(url, viewId, loadingTextId, processRequestFn, clickFn, CompleteFn, loadingText){
     if (url != 0){
    	xmlhttp=GetXmlHttpObject();
    	 
    	if (null!=loadingTextId)
    	{
		    var loadingText = document.getElementById(loadingTextId);  
		    if (null!=loadingText)
		      loadingText.value = loadingText;
    	}
        xmlhttp.open("GET", url, true);
        xmlhttp.onreadystatechange= function () {processRequestFn(viewId, loadingTextId, clickFn, CompleteFn); } ;
        xmlhttp.send(null);
      }
      else{
        document.getElementById(viewId).innerHTML = "";
        
      }
}

function sendSelectOptionRequest(url, viewId, loadingTextId, clickFn, CompleteFn, loadingText){
	sendRequest(url, viewId, loadingTextId, processSelectOptionRequest, clickFn, CompleteFn, loadingText);
}

function sendBunkaRequest(url, viewId, loadingTextId, CompleteFn, loadingText){
//	alert(url);
	sendRequest(url, viewId, loadingTextId, processSelectOptionRequest, null, CompleteFn, loadingText);
}

function getElemValue(inputobj, idx)
{
	var val=null;
	if (null!=inputobj && idx>=0){		
			var val = inputobj.options[idx].value;
			if (null!=val)
			{
 			_idx = val.indexOf(';');
 			if (_idx>=0)
 				val = val.substring(0, _idx);
			}
	}
	return val;
}

function getElemCurrentValue(inputobj)
{
	if (null==inputobj) return null;
	return getElemValue(inputobj, inputobj.selectedIndex);
}

function getCurrentValue(inputId)
{
	var idx;
	var val=null;
	if (null!=inputId && ""!=inputId){
		var inputobj = document.getElementById(inputId);
		val=getElemCurrentValue(inputobj);
	}
	return val;
}

function AddParam(Name, Value)
{
	if (null==Value || 0==Value.length)
		return '';
	return Name+'='+Value+'&';
}

function sendUzemiRequest(ContextURL, SelId1, SelId2, SelId3, SelId4, SelId5, SelId6, druhUzemiId, viewId, loadingTextId, loadingText, jine, processFn, clickFn, CompleteFn){
	var url = ContextURL+'/uzemi.do?';
//	alert("sendUzemiRequest="+ContextURL);
	url+=AddParam('Id1', getCurrentValue(SelId1));
	url+=AddParam('Id2', getCurrentValue(SelId2));
	url+=AddParam('Id3', getCurrentValue(SelId3));
	url+=AddParam('Id4', getCurrentValue(SelId4));
	url+=AddParam('Id5', getCurrentValue(SelId5));
	url+=AddParam('Id6', getCurrentValue(SelId6));
	url+=AddParam('druhUzemiId', druhUzemiId);
	if (null!=jine)
		url+=AddParam('jine', jine);
	url=url.substring(0, url.length-1);
	/*debug(url);*/
	removeOptionSelected(viewId);
	sendRequest(url, viewId, loadingTextId, processFn, clickFn, CompleteFn, loadingText);
}

function sendUzemiRequestIsEmptyVal(ContextURL, SelId1, SelId2, SelId3, SelId4, SelId5, SelId6, druhUzemiId, viewId, loadingTextId, loadingText, jine, processFn, clickFn, CompleteFn, TestOneRow){
	var inputobj=document.getElementById(viewId);
	if (null!=inputobj){
//		alert("sendUzemiRequestIsEmpty2="+getElemValue(inputobj, 0));
		if((0==inputobj.length) || ((1==inputobj.length) && ((!TestOneRow) || (0>getElemValue(inputobj, 0)))))
			sendUzemiRequest(ContextURL, SelId1, SelId2, SelId3, SelId4, SelId5, SelId6, druhUzemiId, viewId, loadingTextId, loadingText, jine, processFn, clickFn, CompleteFn);
 	}		
}

function sendUzemiRequestIsEmpty(ContextURL, SelId1, SelId2, SelId3, SelId4, SelId5, SelId6, druhUzemiId, viewId, loadingTextId, loadingText, jine, processFn, CompleteFn, clickFn){
	var inputobj=document.getElementById(viewId);
	if (null!=inputobj){
		if((0==inputobj.length) || (1==inputobj.length))
			sendUzemiRequest(ContextURL, SelId1, SelId2, SelId3, SelId4, SelId5, SelId6, druhUzemiId, viewId, loadingTextId, loadingText, jine, processFn, clickFn, CompleteFn);
 	}		
}

function InternalProcessRequest(viewId, loadingTextId, clickFn, outerTag, innerTag, ResultFn, CompleteFn){
  if (xmlhttp.readyState == 4){	  
    if(xmlhttp.status == 200){
      var inputobj = document.getElementById(viewId);
      
      if("div" == inputobj.tagName.toLowerCase()){
    	  inputobj.innerHTML = xmlhttp.responseText;
      }
      else if(outerTag == inputobj.tagName.toLowerCase()){	    	  	    	  
//	    	 alert(xmlhttp.responseText);
//	    	 alert("!!!" + xmlhttp.responseXML);
    	  if (null!=xmlhttp.responseXML)
    	  {
	    	  var xmlDoc=xmlhttp.responseXML.documentElement;
//		    	  alert(xmlDoc);
	    	  var elements =  xmlDoc.getElementsByTagName(innerTag);
	    	  var index = 0;
//	    	  	  alert("!!!" + xmlhttp.responseText);

	    	  for(var i = 0; i < elements.length; i++){
	    		  ResultFn(elements[i], inputobj, clickFn)
	    	  }
    	  }
	    }   	  	     	  	
      }  
   	
    else
    {
        alert("Chyba pri nacitani stanky"+ xmlhttp.status +":"+ xmlhttp.statusText);
    }
  }
  if (null!=loadingTextId)
  {
    var loadingText = document.getElementById(loadingTextId);  
    if (null!=loadingText)
      loadingText.value = "";
  }
  if (null!=CompleteFn) 
    CompleteFn();
  resize();	
  }

function addOptionIfNotExists(inputobj, text, value){
	for(i=0; i<inputobj.length; i++){			
		if(inputobj.options[i].text==text){
			inputobj.options[i].selected=true;
			return;
		}
	}
	if (inputobj.length<=1)
		removeOptions(inputobj);
	var oOption = new Option(text, value, true, true);
	inputobj.options.add(oOption);  
}	

function addOption(element, inputobj, clickFn){
	  var oOption;
	  if(element.attributes.length > 1){
		  oOption = new Option(element.childNodes[0].nodeValue, element.attributes[0].nodeValue, true, true);
	  }
	  else{
		  oOption = new Option(element.childNodes[0].nodeValue, element.attributes[0].nodeValue);
	  }
//	  debug(element.childNodes[0].nodeValue+' - '+element.attributes[0].nodeValue);
	  if (null!=clickFn)
		  oOption.onclick=function(){ clickFn(); }
	  inputobj.options.add(oOption);  
}
 
function addOptionWithExtent(element, inputobj, clickFn){
	  //var oOption = document.createElement('option'); 
	  var oOption;
	  var elements =  element.getElementsByTagName('extent');
	  var Extent=element.attributes[0].nodeValue;
	  
	  if (elements.length>0)
		  Extent+=";"+elements[0].attributes.getNamedItem('left').nodeValue+";"+elements[0].attributes.getNamedItem('right').nodeValue+";"+elements[0].attributes.getNamedItem('bottom').nodeValue+";"+elements[0].attributes.getNamedItem('top').nodeValue;

	  if(element.attributes.length > 1){
		  oOption = new Option(element.childNodes[0].nodeValue, Extent, true, true);
	  }
	  else{
		  oOption = new Option(element.childNodes[0].nodeValue, Extent);
	  }
	  if (null!=clickFn)
	  {
    	  if (elements.length>0)
    	  {
    		  var left = elements[0].attributes.getNamedItem('left').nodeValue;
    		  var right = elements[0].attributes.getNamedItem('right').nodeValue;
    		  var bottom = elements[0].attributes.getNamedItem('bottom').nodeValue;
    		  var top = elements[0].attributes.getNamedItem('top').nodeValue;
			      oOption.onclick=function(){ clickFn(left, right, bottom, top); }
	    	  }
		  }
		  inputobj.options.add(oOption);  
  }
    
	function processSelectOptionRequest(viewId, loadingTextId, clickFn, CompleteFn){
		InternalProcessRequest(viewId, loadingTextId, clickFn, "select", "option", addOption, CompleteFn);
}

function processSelectOptionRequestExtent(viewId, loadingTextId, clickFn, CompleteFn){
	InternalProcessRequest(viewId, loadingTextId, clickFn, "select", "option", addOptionWithExtent, CompleteFn);
}
	
function checkAllBoxes(){
	var checkboxes = document.getElementsByTagName('input');
	
	for(i=0; i<checkboxes.length; i++){			
		if('checkbox' == checkboxes[i].type){
			checkboxes[i].checked = true;
		}				
	}	
	return null;
}

function uncheckAllBoxes(){
	var checkboxes = document.getElementsByTagName('input');
	
	for(i=0; i<checkboxes.length; i++){			
		if('checkbox' == checkboxes[i].type){
			checkboxes[i].checked = false;
		}				
	}	
	return null;
}	

