﻿function evElement(e) {
  try { return window.event.srcElement; } catch(e) { }
  try { return e.target; } catch(e) { }
  return null;
}
function evOf(e) {
	var ev = null;
	try { ev = window.event; } catch(ee) { }
	if (!ev) { ev = e; }
	return ev;
}

function docEl(s) {
  var el = null;
  s = s.replace(/\$/g,'_'); 
  try { el = document.getElementById(s); } catch(e) { }
  if (!el) { try { el = document.forms[0].item(s); } catch(e) { } }		
  return el;
}

function openerEl(s) {
  var el = null;
  s = s.replace(/\$/g,'_'); 
  try { el = window.opener.document.getElementById(s); } catch(e) { }
  if (!el) { try { el = window.opener.document.forms[0].item(s); } catch(e) { } }		
  return el;
}

function OpenWindow(url, width, height, target) {
	var left = (window.screen.width - width) / 2;
	var top = (window.screen.height - height) / 2;
	var options = 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',status=no,statusbar=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=no';
	window.open(url, target, options);
	return false;
}

function OpenScrollWindow(url, width, height, target) {
	var left = (window.screen.width - width) / 2;
	var top = (window.screen.height - height) / 2;
	var options = 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',status=no,statusbar=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes';
	window.open(url, target, options);
	return false;
}

function CloseWindow() {
	if (window.opener && !window.opener.closed) {window.opener.focus();} 
	window.close();
}

function CloseWindowWithUrlReload() {
	var parent = window.opener;
	if (parent && !parent.closed) {parent.location.replace(parent.location.href);} 
	CloseWindow();
}


try {
	HTMLElement.prototype.foxclick = function() { __doPostBack(this.id,'');	}
} catch(e) { // MSIE fails. Neimplementuje takto prototyp HTMLElement
}

function RefreshParentBy(buttonName) {
	var button = openerEl(buttonName);
	if (button) { 
		try { 
			button.click(); 
		} catch(e) { 
			try { 
				if (button.onclick) {
					button.onclick; 
				} else {
					try { button.foxclick(); } catch(e) { } 
				}
			} catch(e) { 
				try { button.foxclick(); } catch(e) { 
				} 
			} 
		}	
	} 
}

function RefreshBy(buttonName) {
    var button = docEl(buttonName);
    if (button) {
        try {
            button.click();
        } catch (e) {
            try {
                if (button.onclick) {
                    button.onclick;
                } else {
                    try { button.foxclick(); } catch (e) { }
                }
            } catch (e) {
                try { button.foxclick(); } catch (e) {
                }
            }
        }
    }
}

function ResizeDialog(ctlFormWidthName, ctlFormHeightName) {
	var ctlFormWidth = document.getElementById(ctlFormWidthName);
	var ctlFormHeight = document.getElementById(ctlFormHeightName);
	var w = ctlFormWidth.offsetWidth;
	var h = ctlFormHeight.offsetHeight;
	if (w > (window.screen.width - 60)) {w = window.screen.width - 60;}
	if (h > (window.screen.height - 200)) {h = window.screen.height - 200;}
	window.resizeTo(w + 60, h + 120);
	window.moveTo((window.screen.width - (w + 60)) / 2, (window.screen.height - (h + 120)) / 2);
	window.resizeTo(w + 60, h + 120);
	window.focus();
}

function ResizeDialogHeight(iWidth, ctlFormHeightName) {
	var ctlFormHeight = document.getElementById(ctlFormHeightName);
	var h = ctlFormHeight.offsetHeight;
	if (h > (window.screen.height - 200)) {h = window.screen.height - 200;}
	window.resizeTo(iWidth, h + 120);
	window.moveTo((window.screen.width - (iWidth + 60)) / 2, (window.screen.height - (h + 120)) / 2);
	window.resizeTo(iWidth, h + 120);
	window.focus();
}

/* vrati kod klavesy bez kontrol */
function GetKeyCodeBase(e){
	var keyCode = -1;
	if (window.event) {
		keyCode = window.event.keyCode;
	}
	if (e && keyCode <= 0) {
		keyCode = e.charCode;
		if (keyCode <= 0){
		    keyCode = e.keyCode;
		}
	}
	return keyCode;
}

function DialogOnKeyPress(e) {
   var keyCode = -1;
	  keyCode = GetKeyCodeBase(e);
   if (keyCode == 27) {
     CloseWindow();
     return false;
   }
  	return;
}

function ResetLogin() {
  try{ docEl('ctl00_Content_AppLogin_txtLogin').value=''; } catch(e) {}
  try{ docEl('ctl00_Content_AppLogin_txtPass').value=''; } catch(e) {}
  return false;
}


