﻿/*
	Represents base methods for client scripting
	Requires Prototype JavaScript framework, version 1.6.0 (Prototype.js) and linked stylesheet geto.css
	
	Defines objects:
		- Geto.Version
				Vraci cislo verze Geto frameworku		
		- Geto.BrowserInfo
			- Geto.BrowserInfo.isIE()
			  vraci 'true', jestlize je aktualni prohlizec Microsoft Internet Explorer, jinak 'false'
			  
			- Geto.BrowserInfo.isOpera()
			  vraci 'true', jestlize je aktualni prohlizec Opera, jinak 'false'
			
			- Geto.BrowserInfo.isSafari()
			  vraci 'true', jestlize je aktualni prohlizec Safari, jinak 'false'

			- Geto.BrowserInfo.isGecko()
			  vraci 'true', jestlize je aktualni prohlizec s jadrem Gecko, jinak 'false'

		- Geto.Forms
			- Geto.Forms.getWindowWidth(w)
			  obsolete, vraci sirku okna 'w' v pixelech, neni-li w definovano, vraci sirku okna 'top'
			
			- Geto.Forms.getWindowHeight(w)
			  obsolete, vraci vysku okna 'w' v pixelech, neni-li w definovano, vraci vysku okna 'top'
			  
			- Geto.Forms.activateAutoResize()
			  aktivuje automaticky resize modalniho prekryti na window.onresize

			- Geto.Forms.getPageSize()
			  vraci v poli rozmery dokumentu a aktualniho okna (pageWidth, pageHeight, windowWidth, windowHeight)
			  
			- Geto.Forms.disableScreen()
			  prekryje aktualni dokument sedym divem s castecnou pruhlednosti a neumozni tak praci s elementy krome modalnich dialogu
			  
			- Geto.Forms.enableScreen()
			  aktivuje aktualni dokument po te, co byl deaktivovan funkci Forms.disableScreen()
			  
			- Geto.Forms.resizeModalOverlay()
			  funkce je volana na udalosti body.onresize a pri zmene velikosti okna klienta meni velikost prekryvaciho
			  divu pri deaktivovanem dokumentu
			 
			- Geto.Forms.showIcfDialog(dialogId)
			  funkce zapouzdruje Forms.showDialog pro dialog definovany za pouzity webcontrolu <geto:Dialog ..., kde predavane
			  id je id serveroveho kontrolu Ecommerce.Web.UI.WebControls.Dialog z nehoz se do vybere obsah, nadpis a nastavi
			  jeho sirka, je-li modalni, display interval a mod (napr. alert s OK, confirm s YES/NO apd.).
			  Tato metoda predpoklada existenci webkontrolem Dialog vyrenderovanych js promennych:
				  - dialogId_width
				  - dialogId_title
				  - dialogId_mode
				  - dialogId_displayInterval
				  - dialogId_isModal
			  
			- Geto.Forms.showDialog(dialogTitle, dialogText, width, mode, displayInterval, isModal)
			  zobrazi dialog, pred tim deaktivuje aktualni dokument, je-li definovan displayInterval > 0, dialog
			  se po uplynuti casu v sekundach sam skryje a dokument aktivuje
			  
			- Geto.Forms.initDialogContainer()
			  overi existenci kontaineru pro dialog a v pripade potreby ho vytvori v dokumentu

			- Geto.Forms.hideDialog()
			  skryje dialog, ktery byl zobrazen zavolanim Forms.showDialog(...)
			  
			- Geto.Forms.repositionDialog()
			  funkce je volana na udalosti body.onresize a pri zmene velikosti okna klienta meni pozici dialogu
			  na stred obrazovky

			- Geto.Forms.resizeScreen()
			  funkce je volana na udalosti body.onresize a pouze zapouzdruje volani Forms.resizeModalOverlay()
			  a Forms.repositionDialog()
			  
			- showBusy()
			  funkce zobrazi div s animaci indikujici probihajici operaci na pozadi, obvykla ajaxove volani
			
			- initHideBusy()
			  funkce nastartuje casovac, ktery po 1 sekunde zavola Geto.Forms.hideBusy()
			
			- hideBusy: function()
			  skryje div indikujici probihajici operaci

			- repositionBusy()
			  nastavi pozici divu indikujici probihajici operaci do prostred screenu

			- Geto.Forms.showHint(id, hintTitle, hintText, displayInterval)
			  zobrazi okno napovedy k elementu, ktery ma predavane id, je-li displayInterval > 0, okno se po uplynuti
			  zadaneho intervalu v sekundach samo skryje
			  
			- Geto.Forms.hideHint()
			  skryje okno napovedy zobrazene funkci Forms.showHint(...)
			  
			- Geto.Forms.cacheImages()
			  nakesuje obrazky pri nahrati dokumentu, slouzi prevazne k vizualnimu urychleni pri zobrazovani dialogu
			  a napovedy (hintu)
			  
			- Geto.Forms.activateTab(tabsId, tabId)
			  prepne zalozku, obvykle pracuje s html vygenerovanym controlem geto:Tabs
			  tabsId je id skupiny zalozek (Tabs) a tabId je konkretni zalozka (Tab), na kterou ma byt prepnuto,
			  ostatni zalozky v dane skupine zalozek se deaktivuji automaticky
			
		- Geto.DragAndDrop
			- Geto.DragAndDrop.getMouseOffset(target, ev)
			  pozice mysi vuci elementu
			  
			- Geto.DragAndDrop.getPosition(e)
			  vraci pozici
			  
			- Geto.DragAndDrop.mouseMove(ev)
			  navazano na pohyb mysi pro zajisteni pohybu elementu pri tazeni
			  
			- Geto.DragAndDrop.mouseCoords(ev)
			  vraci souradnice mysi
			  
			- Geto.DragAndDrop.mouseUp()
			  provede 'drop' elementu na dane pozici, pusteni tlacitka mysi
			  
			- Geto.DragAndDrop.makeDraggable(item)
			  definuje html element jako element posouvatelny kurzorem mysi
		
		- Geto.Suggest
			- Geto.Suggest.stop()
			  deaktivuje naseptavac
			
			- Geto.Suggest.start()
			  aktivuje naseptavac
			  
			- Geto.Suggest.clear()
			  skryje naseptavac
			  
			- Geto.Suggest.init(id, getDataMethod)
			  inicializuje naseptavac pri startu stranky, id predstavuje identifikator input elementu, kam uzivatel
			  pise (data naseptavace se pak zobrazuji do elementu s identifikatorem id + 'SuggestFill')
			  getDataMethod predstavuje javascript metodu, ktera plni naseptavac daty
			  
			- Geto.Suggest.showSuggestion(inputText)
			  naplni jednotlive radky naseptavace retezci z dat a zobrazi je
			  
			- Geto.Suggest.keyCatch(ev)
			  zachytava stisky klaves pri stisknuti v input elementu a jedna-li se o enter, escape nebo sipky, vola odpovidajici akce
			  
			- Geto.Suggest.keyUp(ev)
			  zachytava stisky klaves po stisknuti v input elementu a ovlada casovace, ktere se staraji o ziskavani dat
			  
			- Geto.Suggest.isAllowedInputKey(keyId)
			  vraci true, pokud je klavesa s danym keyId povolena pro pouziti v naseptavaci
	
			- Geto.Suggest.isNotControlKey(keyId)
			  vraci true, pokud neni klavesa s danym keyId povolena jako ovladaci klavesa naseptavace, napr. insert, printscreen apd.

			- Geto.Suggest.getData()
			  zajistuje ziskani aktualnich dat v zavislosti na hodnote vstupniho pole pomoci volani javascriptove metody
			  definovane v Suggest.getDataMethod
			  
			- Geto.Suggest.displayData(result)
			  volana po uspesnem ziskani novych dat, ktera nastavi a nasledne vola zobrazeni naseptavace
			  
			- Geto.Suggest.putSelected(key)
			  vlozi aktualne zvoleny radek z naseptavace do input elementu
			  
			- Geto.Suggest.selectItem(keyId)
			  zajistuje zvoleni polozky naseptavace v zavislosti na stisknute klavese (sipky kurzoru) a aktualni pozici
			  
			- Geto.Suggest.unselectItem()
			  zrusi aktualni volbu polozky naseptavace
			  
			- Geto.Suggest.lineMouseover()
			  navazano na udalost Mouseover jednotlive radky naseptavace, vypne casovac a vola Suggest.mouseover
			  
			- Geto.Suggest.lineMouseOut()
			  navazano na udalost Mouseout jednotlive radky naseptavace a aktivuje timer, ktery vola Suggest.mouseout
			  
			- Geto.Suggest.lineClick()
			  vola Suggest.mouseclick
			  
			- Geto.Suggest.mouseout()
			  zrusi aktualni volbu polozky naseptavace
			  
			- Geto.Suggest.mouseover(line)
			  nastavi aktualne zvolenou radku naseptavace v zavislosti na radce, kde mouseover probehl
			  
			- Geto.Suggest.mouseclick(line)
			  zvoli aktualni radku a jeji obsah vlozi do inputu, je-li aktivovan autosubmit, provede odeslani formulare
			  
			- Geto.Suggest.action()
			  odesle formular ve kterem se input nachazi
			  
		- Geto.Keys
			- Geto.Keys.getKey(ev)
			  zapouzdruje ziskani kodu stisknute klavesy

			- Geto.Keys.isAllowedInputKey(keyId)
			
		- Geto.Ajax
			- Geto.Ajax.isAjaxProccessingStarted
			  vlastnost typu bool indikuje, jestli je nastartovano ajaxove volani, nebo nikoliv
			  
			- Geto.Ajax.startAjaxProccessing()
			  funkce provede operace pri zacatku ajaxoveho volani jako napriklad disablovani screenu, zobrazeni busy ikony apd.
			  
			- Geto.Ajax.initStopAjaxProccessing()
			  funkce nastartuje casovac, ktery za 1 sec zavola Geto.Ajax.stopAjaxProccessing()
			  
			- Geto.Ajax.stopAjaxProccessing()
			  funkce provede operace pri dokonceni ajaxoveho volani jako napriklad enable screenu, skryti busy ikony apd.
*/

var Geto =
{
	Version: '1.0.0',
	
	BrowserInfo: {
		isIE: function()
		{
			if (Prototype.Browser.IE)
			{
					return true;
			}
			else
			{
					return false;
			}
		},
		
		isOpera: function()
		{
			if (Prototype.Browser.Opera)
			{
				return true;
			}
			else
			{
				return false;
			}
		},
		
		isSafari: function()
		{
			if (Prototype.Browser.WebKit)
			{
				return true;
			}
			else
			{
				return false;
			}
		},
		
		isGecko: function()
		{
			if (Prototype.Browser.Gecko)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	},

	Forms: {
		screenResizeActivated: false,
		dragObject: null,
		mouseOffset: null,
		busyContainer: null,
		hintContainer: null,
		hintTimer: null,
		dialogContainer: null,
		dialogTimer: null,
		dialogCallBack: null,
		modalOverlay: null,
		dialogConfirmYes: 'Yes',
		dialogConfirmNo: 'No',
		dialogConfirmCancel: 'Cancel',
		dialogAlertOk: 'OK',

		// Obsolete - use getPageSize instead
		getWindowWidth: function(w)
		{
			if (!w)
			{
				w = top;
			}
			if (w.innerWidth)
			{
				return w.innerWidth;
			}
			else if (w.document.documentElement && w.document.documentElement.clientWidth)
			{
				return document.documentElement.clientWidth;
			}
			else if (w.document.body && w.document.body.clientWidth)
			{
				return w.document.body.clientWidth;
			}
			else
			{
				return null;
			}
		},
		
		// Obsolete - use getPageSize instead
		getWindowHeight: function(w)
		{
			if (!w)
			{
				w = top;
			}
			if (w.innerHeight)
			{
				return w.innerHeight;
			}
			else if (w.document.documentElement && w.document.documentElement.clientHeight)
			{
				return w.document.documentElement.clientHeight;
			}
			else if (w.document.body && w.document.body.clientHeight)
			{
				return w.document.body.clientHeight;
			}
			else
			{
				return null;
			}
		},
		
		activateAutoResize: function()
		{
			if (!Geto.Forms.screenResizeActivated)
			{
				Geto.Forms.screenResizeActivated = true;
				window.onresize = function()
				{
					Geto.Forms.resizeScreen();
				}
			}
		},
                
		getPageSize: function()
		{
  			var xScroll, yScroll;

  			if (window.innerHeight && window.scrollMaxY)
  			{	
  				xScroll = document.body.scrollWidth;
  				yScroll = window.innerHeight + window.scrollMaxY;
  			}
  			else if (document.body.scrollHeight > document.body.offsetHeight)
  			// all but Explorer Mac
  			{
  				xScroll = document.body.scrollWidth;
  				yScroll = document.body.scrollHeight;
  			}
  			// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
  			else
  			{
  				xScroll = document.body.offsetWidth;
  				yScroll = document.body.offsetHeight;
  			}

  			var windowWidth, windowHeight;
			
			// all except Explorer
  			if (self.innerHeight)
  			{
  				windowWidth = self.innerWidth;
  				windowHeight = self.innerHeight;
  			} 
  			// Explorer 6 Strict Mode
  			else if (document.documentElement && document.documentElement.clientHeight)
  			{ 
  				windowWidth = document.documentElement.clientWidth;
  				windowHeight = document.documentElement.clientHeight;
  			}
  			// other Explorers
  			else if (document.body)
  			{
  				windowWidth = document.body.clientWidth;
  				windowHeight = document.body.clientHeight;
  			}	
	  		
  			var pageHeight, pageWidth;

  			// for small pages with total height less then height of the viewport
  			if(yScroll < windowHeight)
  			{
  				pageHeight = windowHeight;
  			}
  			else
  			{ 
  				pageHeight = yScroll;
  			}

  			// for small pages with total width less then width of the viewport
  			if(xScroll < windowWidth)
  			{	
  				pageWidth = windowWidth;
  			}
  			else
  			{
  				pageWidth = xScroll;
  			}
            // SSU 2010 - get scroll position
  			var scrOfX = 0, scrOfY = 0;
  			if (typeof (window.pageYOffset) == 'number') {
  			    //Netscape compliant
  			    scrOfY = window.pageYOffset;
  			    scrOfX = window.pageXOffset;
  			} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
  			    //DOM compliant
  			    scrOfY = document.body.scrollTop;
  			    scrOfX = document.body.scrollLeft;
  			} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
  			    //IE6 standards compliant mode
  			    scrOfY = document.documentElement.scrollTop;
  			    scrOfX = document.documentElement.scrollLeft;
  			}
  			
  			return { pageWidth: pageWidth,
  			         pageHeight: pageHeight,
  			         windowWidth: windowWidth,
  			         windowHeight: windowHeight,
  			         xScroll: scrOfX,  // SSU
  			         yScroll: scrOfY   //SSU 
  			     };
		},
		
		disableScreen: function()
		{
			if (Geto.Forms.modalOverlay == null)
			{
				Geto.Forms.modalOverlay = document.createElement('div');
				Geto.Forms.modalOverlay.id = 'ScreenOverlay';
				Geto.Forms.modalOverlay.className = 'screenoverlay';
				Geto.Forms.modalOverlay.style.backgroundColor = '#cccccc';
				if (Geto.Forms.modalOverlay.style.opacity != null)
				{
					Geto.Forms.modalOverlay.style.opacity = '0.5';
				}
				if (Geto.Forms.modalOverlay.style.filter != null)
				{
					Geto.Forms.modalOverlay.style.filter = 'alpha(opacity=50)';
				}
				if (Geto.Forms.modalOverlay.style.MozOpacity != null)
				{
					Geto.Forms.modalOverlay.style.MozOpacity = '0.5';
				}
				if (Prototype.Browser.IE)
				{
					Geto.Forms.modalOverlay.style.position = 'absolute';
				}
				else
				{
					Geto.Forms.modalOverlay.style.position = 'fixed';
				}
				Geto.Forms.modalOverlay.style.zIndex = 10;
				document.body.style.zIndex = 5;
				document.body.insertBefore(Geto.Forms.modalOverlay, document.body.firstChild);
			}
			Geto.Forms.modalOverlay.style.left = '0';
			Geto.Forms.modalOverlay.style.top = '0';
			Geto.Forms.resizeModalOverlay()
			Geto.Forms.modalOverlay.style.display = 'block';
		},
		
		enableScreen: function()
		{
			if (Geto.Forms.modalOverlay != null)
			{
				Geto.Forms.activateAutoResize();
				Geto.Forms.modalOverlay.style.backgroundColor = '#555555';
				if (Geto.Forms.modalOverlay.style.opacity != null)
				{
					Geto.Forms.modalOverlay.style.opacity = '0';
				}
				if (Geto.Forms.modalOverlay.style.filter != null)
				{
					Geto.Forms.modalOverlay.style.filter = 'alpha(opacity=0)';
				}
				if (Geto.Forms.modalOverlay.style.MozOpacity != null)
				{
					Geto.Forms.modalOverlay.style.MozOpacity = '0';
				}
				Geto.Forms.modalOverlay.style.display = 'none';
				// Geto.Forms.modalOverlay.parentNode.removeChild(Geto.Forms.modalOverlay);
				Geto.Forms.modalOverlay = null;
			}
		},
		
		resizeModalOverlay: function()
		{
			if (Geto.Forms.modalOverlay != null)
			{
				var pageSize = Geto.Forms.getPageSize();
				Geto.Forms.modalOverlay.style.width = (pageSize.windowWidth + 'px');
				Geto.Forms.modalOverlay.style.height = (pageSize.pageHeight + 'px');
			}
		},
		
		showIcfDialog: function(dialogId, callBack)
		{
			if (Geto.Forms.showDialog)
			{
				var contentText = '';
				if ($(dialogId))
				{
					if (callBack && callBack != null)
					{
						Geto.Forms.dialogCallBack = callBack;
					}
					
					var dialogSource = eval(dialogId + '_source');
					if (dialogSource != '')
					{				
						Geto.Forms.hideDialog();
						new Ajax.Request(dialogSource,
						{
							method: 'get',
							asynchronous: false,
							onSuccess: function(transport){
								contentText = transport.responseText || "soubor dialogu je prazdny";
							},
							onFailure: function(){
								contentText = 'Doslo k chybe nahrani dialogu ze souboru: ' + dialogSource;
							}
						});
					}
					else
					{
						contentText = $(dialogId).innerHTML;
					}
					Geto.Forms.showDialog($(dialogId), eval(dialogId + '_title'), contentText, eval(dialogId + '_width'), eval(dialogId + '_mode'), eval(dialogId + '_displayInterval'), eval(dialogId + '_isModal'), dialogSource);
				}
			}
			return false;
		},
					
		showDialog: function(dialogContentElement, dialogTitle, dialogText, width, mode, displayInterval, isModal)
		{
			Geto.Forms.hideDialog();
			Geto.Forms.activateAutoResize();
			var contentWidth = width - 6;
			if (isModal)
			{
				Geto.Forms.disableScreen();
				window.onkeydown = function(ev) {
					var keyId = Geto.Keys.getKey(ev);
					if ((keyId == Geto.Keys.keyEnter) || (keyId == Geto.Keys.keySpace) || (keyId == Geto.Keys.keyEscape))
					{
						ev.cancelBubble = true;;
						window.onkeydown = null;
						Geto.Forms.hideDialog();
					}
				}
			}
			Geto.Forms.initDialogContainer();

			if (dialogTitle == '')
			{
				dialogTitle = '&nbsp;';
			}
			
			var dialogHTML = '<div class=\"xdialog\"><div class=\"xdialog-hd\"><div class=\"xdialog-title\">' + dialogTitle + '<\/div><div class=\"xdialog-close\" onclick=\"Geto.Forms.hideDialog();\"><\/div><div id=\"DialogContent\" class=\"xdialog-content\">' + dialogText + '<\/div>';
			if (mode == 'info' || mode == 'alert')
			{
				dialogHTML += '<div class=\"xdialog-buttons\"><table><tr><td><div class=\"button\" id=\"OkButton\" onclick=\"Geto.Forms.hideDialog();Geto.Forms.proccessClick(\'ok\');\" /><span>' + Geto.Forms.dialogAlertOk + '</span><\/td><\/tr><\/table><\/div>';
			}
			else if (mode == 'confirm')
			{
				dialogHTML += '<div class=\"xdialog-buttons\"><table><tr><td><div class=\"button\" onclick=\"Geto.Forms.hideDialog();Geto.Forms.proccessClick(\'yes\');\"/><span>' + Geto.Forms.dialogConfirmYes + '<\/span><\/div><\/td><td><div class=\"button\" onclick=\"Geto.Forms.hideDialog();Geto.Forms.proccessClick(\'no\');\"/><span>' + Geto.Forms.dialogConfirmNo + '<\/span><\/div><\/td><\/tr><\/table><\/div>';
			}
			dialogHTML += '<\/div><div class=\"xdialog-ft\">123<\/div><\/div>';

//			var dialogHTML = '<div class=\"dialog\"><div class=\"dialog-ct1\" style=\"width:' + width + 'px;\"><div class=\"dialog-ct2\" style=\"width:' + contentWidth + 'px;\"><div class=\"dialog-title\">' + dialogTitle + '<\/div><div class=\"dialog-close\" onclick=\"Geto.Forms.hideDialog();\"><\/div><div id=\"DialogContent\" class=\"dialog-content\"><form>' + dialogText + '<\/form><\/div>';
//			if (mode == 'info' || mode == 'alert')
//			{
//				dialogHTML += '<div class=\"dialog-buttons\"><div class=\"button\" id=\"OkButton\" onclick=\"Geto.Forms.hideDialog();Geto.Forms.proccessClick(\'ok\');\" /><span>' + Geto.Forms.dialogAlertOk + '</span><\/div>';
//			}
//			else if (mode == 'confirm')
//			{
//				dialogHTML += '<div class=\"dialog-buttons\"><table><tr><td><div class=\"button\" onclick=\"Geto.Forms.hideDialog();Geto.Forms.proccessClick(\'yes\');\"/><span>' + Geto.Forms.dialogConfirmYes + '<\/span><\/div><\/td><td><div class=\"button\" onclick=\"Geto.Forms.hideDialog();Geto.Forms.proccessClick(\'no\');\"/><span>' + Geto.Forms.dialogConfirmNo + '<\/span><\/div><\/td><\/tr><\/table><\/div>';
//			}
//			dialogHTML += '<\/div><\/div><div class=\"dialog-footer-box\" style=\"width:' + width + 'px;\"><div class=\"dialog-footer\" style=\"width:' + contentWidth + 'px;\"><\/div><\/div><\/div>';
//			
			Geto.Forms.dialogContainer.innerHTML = dialogHTML;
			
			Geto.Forms.repositionDialog();
			$('DialogContainer').show();

			Geto.DragAndDrop.makeDraggable(Geto.Forms.dialogContainer);
			if (!isNaN(displayInterval) && displayInterval > 0)
			{
				displayInterval = displayInterval * 1000;
				Geto.Forms.dialogTimer = setTimeout('Geto.Forms.hideDialog()', displayInterval);
			}
		},
		
		initDialogContainer: function()
		{
			if (!Geto.Forms.dialogContainer)
			{
				Geto.Forms.dialogContainer = document.createElement('div');
				Geto.Forms.dialogContainer.id = 'DialogContainer';
				Geto.Forms.dialogContainer.style.position = 'absolute';
				Geto.Forms.dialogContainer.style.zIndex = 20;
				document.body.insertBefore(Geto.Forms.dialogContainer, document.body.firstChild);
			}
		},
		
		hideDialog: function()
		{
			if (Geto.Forms.dialogTimer != null)
			{
				clearTimeout(Geto.Forms.dialogTimer);
			}
			if (Geto.Forms.dialogContainer != null)
			{
				$('DialogContainer').hide();
				Element.remove('DialogContainer');
				Geto.Forms.dialogContainer = null;
				Geto.Forms.enableScreen();
			}
		},
		
		repositionDialog: function()
		{
			if (Geto.Forms.dialogContainer != null)
			{
				var pageSize = Geto.Forms.getPageSize();
				//Geto.Forms.dialogContainer.style.left = Math.floor((pageSize.windowWidth / 2) - Math.floor(Geto.Forms.dialogContainer.offsetWidth / 2)) + 'px';
				//Geto.Forms.dialogContainer.style.top = Math.floor((pageSize.windowHeight / 2) - Math.floor(Geto.Forms.dialogContainer.offsetHeight / 2)) + 'px';
				// SSU correction
				Geto.Forms.dialogContainer.style.left = Math.floor((pageSize.windowWidth / 2) - 300) + pageSize.xScroll + 'px';
				Geto.Forms.dialogContainer.style.top = Math.floor((pageSize.windowHeight / 2) - (Geto.Forms.dialogContainer.offsetHeight) - 50) + pageSize.yScroll +'px';

				
			}
		},
		
		proccessClick: function(result)
		{
			if (Geto.Forms.dialogCallBack && Geto.Forms.dialogCallBack != null)
			{
				Geto.Forms.dialogCallBack(result);
				Geto.Forms.dialogCallBack = null;
			}
		},
		
		resizeScreen: function()
		{
			Geto.Forms.repositionDialog();
			// Geto.Forms.repositionHint();
			Geto.Forms.repositionBusy();
			Geto.Forms.resizeModalOverlay();
		},
		
		showBusy: function()
		{
			Geto.Forms.activateAutoResize();
			if (!Geto.Forms.busyContainer)
			{
				Geto.Forms.busyContainer = document.createElement('div');
				Geto.Forms.busyContainer.id = 'BusyContainer';
				Geto.Forms.busyContainer.className = 'busycontainer';
				Geto.Forms.busyContainer.style.position = 'absolute';
				Geto.Forms.busyContainer.style.zIndex = 20;
				document.body.insertBefore(Geto.Forms.busyContainer, document.body.firstChild);
			}
			Geto.Forms.busyContainer.style.display = 'block';
		},
		
		initHideBusy: function()
		{
			if (Geto.Forms.busyContainer != null)
			{
				setTimeout('Geto.Forms.hideBusy()', 1000);
			}
		},

		hideBusy: function()
		{
			if (Geto.Forms.busyContainer != null)
			{
				Geto.Forms.busyContainer.style.display = 'none';
				Geto.Forms.busyContainer = null;
			}
		},

		repositionBusy: function()
		{
			if (Geto.Forms.busyContainer != null)
			{
				var pageSize = Geto.Forms.getPageSize();
				Geto.Forms.busyContainer.style.left = Math.floor((pageSize.windowWidth / 2) - Math.floor(Geto.Forms.busyContainer.offsetWidth / 2) + 200) + 'px';
				Geto.Forms.busyContainer.style.top = Math.floor((pageSize.windowHeight / 2) - Math.floor(Geto.Forms.busyContainer.offsetHeight / 2) - 200) + 'px';
			}
		},

		hintInputElementId: '',
		hintInputElementWidth: 0,
		hintRootElement: null,
		hintPositionLeft: 950,
		showAbsoluteHint: function(id)
		{
			var element = $(id);
			if (element != null)
			{
				element.style.display = 'block';
			}
		},
		hideAbsoluteHint: function(id)
		{
			var element = $(id);
			if (element != null)
			{
				element.style.display = 'none';
			}
		},
		showHint: function(id, hintTitle, hintText, displayInterval)
		{
			return;
			/*
			
			// Geto.Forms.hintRootElement = document.forms[0];
			Geto.Forms.hintRootElement = $('page');
			Geto.Forms.activateAutoResize();
			if (Geto.Forms.hintContainer == null)
			{
				Geto.Forms.hintContainer = document.createElement('div');
				Geto.Forms.hintContainer.id = 'HintContainer';
				Geto.Forms.hintContainer.style.position = 'absolute';
				Geto.Forms.hintRootElement.appendChild(Geto.Forms.hintContainer);
			}
			var inputElement = $(id);
			Geto.Forms.hintInputElementId = id;
			Geto.Forms.hintInputElementWidth = inputElement.offsetWidth;
			Geto.Forms.repositionHint();
			if (hintTitle == '')
			{
				hintTitle = '&nbsp;';
			}
			var hintHTML = '<div class=\"hint\"><div class=\"nib\"><\/div><div class=\"hint-ct1\"><div class=\"hint-ct2\"><div class=\"hint-title\">' + hintTitle + '<\/div><div class=\"hint-content\">' + hintText + '<\/div><\/div><\/div><div class=\"hint-footer-box\"><div class=\"hint-footer\"><\/div><\/div><\/div>';
			
			Geto.Forms.hintContainer.innerHTML = hintHTML;
			Geto.Forms.hintContainer.style.display = 'block';
			if (!isNaN(displayInterval) && displayInterval > 0)
			{
				displayInterval = displayInterval * 1000;
				Geto.Forms.hintTimer = setTimeout('Geto.Forms.hideHint()', displayInterval);
			}
			*/
		},

		hideHint: function()
		{
			if (Geto.Forms.hintTimer != null)
			{
				clearTimeout(Geto.Forms.hintTimer);
			}
			if (Geto.Forms.hintContainer != null)
			{
				Geto.Forms.hintContainer.style.display = 'none';
			}
		},
		
		repositionHint: function()
		{
			var inputElement = $(Geto.Forms.hintInputElementId);
			if (Geto.Forms.hintContainer != null && inputElement != null && document.forms[0] != null)
			{
				// var positionLeft = inputElement.offsetLeft;
				var positionTop = inputElement.offsetTop;
				while((inputElement = inputElement.offsetParent) && (inputElement != document.forms[0]))
				{
					// positionLeft += inputElement.offsetLeft;
					positionTop += inputElement.offsetTop;
				}
				Geto.Forms.hintContainer.style.left = (Geto.Forms.hintPositionLeft) + 'px';
				Geto.Forms.hintContainer.style.top = (positionTop - 24) + 'px';
			}
		},

		cacheImages: function(imagePaths)
		{
			if (document.images)
			{
				var len = imagePaths.length;
				for (var i = 0; i < len; i++)
				{
					var cachedImage = new Image();
					cachedImage.src = imagePaths[i];
				}
			}
		},
		
		activateTab: function(tabsId, tabId)
		{
			var tabs = $(tabsId + 'H').getElementsBySelector('div', '[class = "tabs-header"]');
			for (var i = 0; i < tabs.length; i++)
			{
				if (tabs[i] != null)
				{
					if (tabs[i].id != tabsId + 'H-' + tabId)
					{
						tabs[i].removeClassName('activetab');
						tabs[i].down().removeClassName('activetab-l');
					}
				}
			}
			var tempEl = $(tabsId + 'H-' + tabId);
			if (tempEl != null)
			{
				tempEl.addClassName('activetab');
				tempEl.down().addClassName('activetab-l');
			}

			
			var tabsContents = $(tabsId + 'C').getElementsBySelector('div');
			for (var i = 0; i < tabsContents.length; i++)
			{
				if (tabsContents[i] != null && tabsContents[i].id.indexOf(tabsId + 'C-') > -1)
				{
					if (tabsContents[i].id != tabsId + 'C-' + tabId)
					{
						tabsContents[i].hide();
					}
					else if (tabsContents[i].id == tabsId + 'C-' + tabId)
					{
						var tabSource = eval('tab' + tabId + '_source');
						var contentText = '';
						if (tabSource != '')
						{
							var contentContainer = ($(tabsContents[i].id)).down();
							contentContainer.cleanWhitespace();
							if (contentContainer.empty())
							{
								new Ajax.Request(tabSource,
								{
									method: 'get',
									asynchronous: false,
									onSuccess: function(transport) {
										contentText = transport.responseText || "soubor " + tabSource + " je prazdny";
									},
									onFailure: function() {
										contentText = 'Doslo k chybe nahrani dialogu ze souboru: ' + dialogSource;
									}
								});
								contentContainer.innerHTML = contentText;
							}
						}
						tabsContents[i].show();
					}
				}
			}
		}
	},

	DragAndDrop: {
		getMouseOffset: function(target, ev)
		{
			ev = ev || window.event;
			var docPos = Geto.DragAndDrop.getPosition(target);
			var mousePos = Geto.DragAndDrop.mouseCoords(ev);
			return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
		},

		getPosition: function(e)
		{
			var left = 0;
			var top = 0;

			while (e.offsetParent)
			{
				left += e.offsetLeft;
				top += e.offsetTop;
				e = e.offsetParent;
			}
			left += e.offsetLeft;
			top += e.offsetTop;
			return {x:left, y:top};
		},

		mouseMove: function(ev)
		{
			ev = ev || window.event;
			var mousePos = Geto.DragAndDrop.mouseCoords(ev);

			if(Geto.Forms.dragObject && mousePos != null)
			{
				if (Geto.Forms.dialogTimer != null)
				{
					clearTimeout(Geto.Forms.dialogTimer);
				}
				Geto.Forms.dragObject.style.position = 'absolute';
				Geto.Forms.dragObject.style.top = (mousePos.y - Geto.Forms.mouseOffset.y) + 'px';
				Geto.Forms.dragObject.style.left = (mousePos.x - Geto.Forms.mouseOffset.x) + 'px';
				return false;
			}
		},

		mouseCoords: function(ev)
		{
			if (ev.pageX || ev.pageY)
			{
				return {x:ev.pageX, y:ev.pageY};
			}
			if (ev != null && document.body != null)
			{
				return {
					x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
					y:ev.clientY + document.body.scrollTop - document.body.clientTop
				};
			}
			return null;
		},

		mouseUp: function()
		{
			Geto.Forms.dragObject = null;
		},

		makeDraggable: function(item)
		{
			if (item == null)
			{
				return;
			}
			
			document.onmousemove = Geto.DragAndDrop.mouseMove;
			document.onmouseup = Geto.DragAndDrop.mouseUp;

			var dragElement = item.getElementsByClassName('xdialog-title')[0];
			if (!dragElement || dragElement == null)
			{
				dragElement = item;
			}
			dragElement.onmousedown = function(ev) 
			{
				Geto.Forms.dragObject = item;
				Geto.Forms.mouseOffset = Geto.DragAndDrop.getMouseOffset(item, ev);
				return false;
			}
		}
	},

	Suggest: {
		enabled: true,
		underliningEnabled: false,
		maxLength: 10,
		inputElement: null,
		suggestElement: null,
		dtTimer: null,
		sTimer: null,
		activeLine: null,
		activeLineCss: 'suggest-active',
		repNum: 4,
		data: new Array(),
		lineBox: new Array(),
		autoSubmit: false,
		getDataMethod: null,
		
		stop: function()
		{
			Geto.Suggest.enabled = false;
		},
		
		start: function()
		{
			Geto.Suggest.enabled = true;
		},
		
		clear: function()
		{
			if (Geto.Suggest.suggestElement)
			{
				Geto.Suggest.suggestElement.hide();
			}
		},
		
		init: function(id, getDataMethod)
		{
			if (id)
			{
				Geto.Suggest.inputElement = $(id);
				Geto.Suggest.suggestElement = $(id + 'SuggestFill');
			}
			if (!Geto.Suggest.inputElement || !Geto.Suggest.suggestElement)
			{
				return;
			}

			if (getDataMethod)
			{
				Geto.Suggest.getDataMethod = getDataMethod;
			}
			else
			{
				return;
			}
			
			Geto.Suggest.start();
			Geto.Suggest.inputElement = $(id);
			Geto.Suggest.suggestElement = $(id + 'SuggestFill');
			Geto.Suggest.suggestElement.style.width = (Geto.Suggest.inputElement.getWidth()-2) + 'px';

			Geto.Suggest.inputElement.onkeyup = Geto.Suggest.keyUp;
			if (document.all || Geto.BrowserInfo.isSafari())
			{
				Geto.Suggest.inputElement.onkeydown = Geto.Suggest.keyCatch;
			}
			else
			{
				Geto.Suggest.inputElement.onkeypress = Geto.Suggest.keyCatch;
			}
			
			Geto.Suggest.suggestElement.innerHTML = '';
			var offset = Geto.BrowserInfo.isIE ? 6 : 20;
			for(i=0; i <= this.maxLength; i++)
			{
				var line = document.createElement('p');
				line.style.display = 'none';
				this.lineBox[i] = line;
				Geto.Suggest.suggestElement.appendChild(line);
				line.onmouseover = Geto.Suggest.lineMouseover;
				line.onmouseout = Geto.Suggest.lineMouseout;
				line.onclick = Geto.Suggest.lineClick;
				line.style.width = (Geto.Suggest.inputElement.getWidth()-offset) + 'px';
			}
			
			Geto.Suggest.inputElement.onclick = Geto.Suggest.unselectItem;
			Geto.Suggest.inputElement.onblur = function() {
				Geto.Suggest.sTimer = setTimeout("Geto.Suggest.clear()", 500);
				if ($(Geto.Suggest.inputElement.id + 'Hint') && Geto.Forms.hideAbsoluteHint)
				{
					Geto.Forms.hideAbsoluteHint(Geto.Suggest.inputElement.id + 'Hint');
				}
				
			};
		},
		
		showSuggestion: function(inputText)
		{
			var view = false;
			Geto.Suggest.repNum = 0;
			for(i=0; i <= this.maxLength; i++)
			{
				if (Geto.Suggest.data[i])
				{
					var elementText = Geto.Suggest.data[i];
					Geto.Suggest.lineBox[i].innerHTML = elementText;
					Geto.Suggest.lineBox[i].position = i;
					Geto.Suggest.lineBox[i].style.display = 'block';
					view = true;
					Geto.Suggest.repNum++;
				}
				else
				{
					Geto.Suggest.lineBox[i].innerHTML = '-';
					Geto.Suggest.lineBox[i].position = i;
					Geto.Suggest.lineBox[i].style.display = 'none';
				}
			}
			if (view)
			{
				Geto.Suggest.unselectItem();
				Geto.Suggest.suggestElement.show();
			}
			else
			{
				Geto.Suggest.suggestElement.hide();
			}
		},
		
		keyCatch: function(ev)
		{
			keyId = Geto.Keys.getKey(ev);
			if (Geto.Suggest.underliningEnabled && Geto.Keys.isAllowedInputKey(keyId) && keyId != Geto.Keys.keyTab)
			{
				Geto.Suggest.inputElement.removeClassName('underline');
			}
			if ((keyId == Geto.Keys.keyEnter) || (keyId == Geto.Keys.keyArrowRight))
			{
				return Geto.Suggest.putSelected(keyId);
			}
			if ((keyId == Geto.Keys.keyArrowUp) || (keyId == Geto.Keys.keyArrowDown))
			{
				Geto.Suggest.selectItem(keyId);
				return false;
			}
			if (keyId == Geto.Keys.keyEscape)
			{
				Geto.Suggest.clear();
			}
		},
		
		keyUp: function(ev)
		{
			keyId = Geto.Keys.getKey(ev);
			if ((keyId == Geto.Keys.keyBackspace) || (keyId == Geto.Keys.keyDelete))
			{ 
				clearTimeout(Geto.Suggest.dtTimer);
				Geto.Suggest.dtTimer = null;
				// Geto.Suggest.unselectItem();			
				Geto.Suggest.dtTimer = setTimeout('Geto.Suggest.getData()', 100);
			}
			else if (Geto.Suggest.isAllowedInputKey(keyId))
			{	
				clearTimeout(Geto.Suggest.dtTimer);
				Geto.Suggest.dtTimer = null;
				Geto.Suggest.dtTimer = setTimeout('Geto.Suggest.getData()', 250);
			}
		},
		
		isAllowedInputKey: function(keyId)
		{
			if (((keyId < Geto.Keys.keyPageUp) || (keyId > Geto.Keys.keyArrowRight)) && Geto.Suggest.isNotControlKey(keyId))
			{
				return true;
			}
			return false;
		},
		
		isNotControlKey: function(keyId)
		{
			if ((keyId != Geto.Keys.keyEnter) && (keyId != Geto.Keys.keyEscape) && (keyId != Geto.Keys.keyArrowDown) && (keyId != Geto.Keys.keyPrintScreen) && (keyId != Geto.Keys.keyInsert) && (keyId != Geto.Keys.keyCtrl) && (keyId != Geto.Keys.keyAlt))
			{
				return true;
			}
			return false;
		},

		getData: function()
		{
			if (Geto.Suggest.inputElement.value)
			{
				Geto.Suggest.getDataMethod(Geto.Suggest.inputElement.value);
			}
			else
			{
				Geto.Suggest.clear();
			}
		},
		
		displayData: function(result)
		{
			if (Geto.Suggest.suggestElement)
			{
				Geto.Suggest.data = result;
				Geto.Suggest.showSuggestion(Geto.Suggest.inputElement.value);
			}
		},
		
		putSelected: function(key)
		{
			if (Geto.Suggest.activeLine)
			{
				if (Geto.Suggest.underliningEnabled)
				{
					Geto.Suggest.inputElement.className = 'textbox underline';
				}
				Geto.Suggest.inputElement.value = Geto.Suggest.activeLine.innerHTML;
				if (key != Geto.Keys.keyEnter)
				{
					Geto.Suggest.getData(); 
				}
				if (Geto.Suggest.autoSubmit)
				{
					return true;
				}
				else
				{
					Geto.Suggest.clear();
					return false;
				}
			}
			else
			{
				return true;
			}
		},
		
		selectItem: function(keyId)
		{
			if (Geto.Suggest.data && (Geto.Suggest.data.length > 0))
			{
				if (Geto.Suggest.activeLine)
				{
					if (keyId == 40)
					{
						Geto.Suggest.activeLine.className = '';
						newActiveLine = Geto.Suggest.activeLine == Geto.Suggest.suggestElement.getElementsByTagName('p')[Geto.Suggest.repNum - 1] ? Geto.Suggest.activeLine : Geto.Suggest.activeLine.nextSibling;
						newActiveLine.className = Geto.Suggest.activeLineCss;
						Geto.Suggest.activeLine = newActiveLine;
					}
					else
					{ 
						Geto.Suggest.activeLine.className = '';
						newActiveLine = Geto.Suggest.suggestElement.getElementsByTagName('p')[0] == Geto.Suggest.activeLine ? Geto.Suggest.activeLine : Geto.Suggest.activeLine.previousSibling;
						newActiveLine.className = Geto.Suggest.activeLineCss;
						Geto.Suggest.activeLine = newActiveLine;
					}
				}
				else
				{
					firstLine = Geto.Suggest.suggestElement.getElementsByTagName('p')[0];
					firstLine.className = Geto.Suggest.activeLineCss;
					Geto.Suggest.activeLine = firstLine;
				}
			}
		},
		
		unselectItem: function()
		{
			if (Geto.Suggest.activeLine)
			{
				Geto.Suggest.activeLine.className = '';
				Geto.Suggest.activeLine = null;
			}
		},

		lineMouseover: function()
		{
			clearTimeout(Geto.Suggest.mTimer);
			Geto.Suggest.mouseover(this);		
		},
		
		lineMouseout: function()
		{
			Geto.Suggest.mTimer = setTimeout("Geto.Suggest.mouseout(this)", 100);
		},
		
		lineClick: function()
		{
			return Geto.Suggest.mouseclick(this);
		},
		
		mouseout: function()
		{
			Geto.Suggest.unselectItem();
		},
		
		mouseover: function(line)
		{
			if (Geto.Suggest.activeLine != null)
			{
				Geto.Suggest.activeLine.className = '';
			}
			Geto.Suggest.activeLine = line;
			Geto.Suggest.activeLine.className = Geto.Suggest.activeLineCss;
		},
		
		mouseclick: function(line)
		{
			Geto.Suggest.inputElement.value = line.innerHTML;
			setTimeout("Geto.Suggest.inputElement.focus()", 10);
			if (Geto.Suggest.autoSubmit)
			{
				Geto.Suggest.action();
			}
		},
		
		action: function()
		{
			Geto.Suggest.inputElement.form.submit();
			return false;
		}
	},

	Keys: {
		getKey: function(ev)
		{
			if (!ev)
			{
				ev =  window.event;
			}
			return ev.keyCode;
		},
		
		isAllowedInputKey: function(keyId)
		{
			if ((keyId <= Geto.Keys.keyTab) || (keyId == Geto.Keys.keyShift) || (keyId >= Geto.Keys.keyDelete) || (keyId == Geto.Keys.keySpace))
			{
				return true;
			}
			return false;
		},
		
		keyBackspace: 8,
		keyTab: 9,
		keyEnter: 13,
		keyShift: 16,
		keyCtrl: 17,
		keyAlt: 18,
		keyEscape: 27,
		keySpace: 32,
		keyPageUp: 33,
		keyPageDown: 34,
		keyEnd: 35,
		keyHome: 36,
		keyArrowLeft: 37,
		keyArrowUp: 38,
		keyArrowRight: 39,
		keyArrowDown: 40,
		keyPrintScreen: 44,
		keyInsert: 45,
		keyDelete: 46
	},
	
	Ajax: {
		isAjaxProccessingStarted: false,
		
		startAjaxProccessing: function(disableScreen)
		{
			if (!Geto.Ajax.isAjaxProccessingStarted)
			{
				Geto.Forms.showBusy();
				Geto.Forms.repositionBusy();

				Geto.Ajax.isAjaxProccessingStarted = true;
				if (disableScreen != false)
				{
					Geto.Forms.disableScreen();
				}
			}
		},
		
		startSilentAjaxProccessing: function()
		{
			if (!Geto.Ajax.isAjaxProccessingStarted)
			{
				Geto.Ajax.isAjaxProccessingStarted = true;
			}
		},

		initStopAjaxProccessing: function()
		{
			setTimeout('Geto.Ajax.stopAjaxProccessing()', 1000);
		},

		stopAjaxProccessing: function()
		{
			Geto.Ajax.isAjaxProccessingStarted = false;
			Geto.Forms.hideBusy();
			Geto.Forms.enableScreen();
		}
	}
}