var newWindow;

function openWindow(url, name) {
	newWindow = window.open(url, name, "width=" + screen.availWidth + ",height=" + (screen.availHeight - 30));
	newWindow.focus();
}

function openLoginWindow() {
	loginWindow = window.open(BASE + "/app/cmsFrameset.php","loginWindow", "width=" + screen.availWidth + ",height=" + (screen.availHeight - 30) + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,screenX=0,screenY=0,left=0,top=0");
	loginWindow.focus();
}

function openMailboxWindow() {
	var windowName = 'newMailboxWindow' + Math.floor(Math.random() * 100);
	loginWindow = window.open(BASE + "/app/cmsFrameset.php", windowName, "width=" + screen.availWidth + ",height=" + (screen.availHeight - 30) + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,screenX=0,screenY=0,left=0,top=0");
	loginWindow.focus();
}

function newWindow(url, width, height, windowName) {
	var left = (screen.availWidth / 2) - (width / 2);
	var top = (screen.availHeight / 2) - (height / 2);
	var newWindow;
	if(!windowName) {
		var windowName = 'newWindow' + Math.floor(Math.random() * 100);
	}
	newWindow = window.open(url, windowName, 'top=' + top + 'px,left=' + left + 'px,screenX=' + left + 'px,screenY=' + top + 'px,width=' + width + 'px,height=' + height + 'px,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no');
	newWindow.focus();
}

function newPrintWindow(url, windowName) {
	var width = 850;
	var height = 580;
	var left = (screen.availWidth / 2) - (width / 2);
	var top = (screen.availHeight / 2) - (height / 2);
	var newWindow;
	if(!windowName) {
		var windowName = 'newWindow' + Math.floor(Math.random() * 100);
	}
	newWindow = window.open(url, windowName, 'top=' + top + 'px,left=' + left + 'px,screenX=' + left + 'px,screenY=' + top + 'px,width=' + width + 'px,height=' + height + 'px,menubar=yes,resizable=yes,scrollbars=yes,status=no,toolbar=no');
	newWindow.focus();
}

function newUserPageWindow(url, windowName) {
	var width = 780;
	var height = 580;
	var left = (screen.availWidth / 2) - (width / 2);
	var top = (screen.availHeight / 2) - (height / 2);
	var newWindow;
	if(!windowName) {
		var windowName = 'newWindow' + Math.floor(Math.random() * 100);
	}
	newWindow = window.open(url, windowName, 'top=' + top + 'px,left=' + left + 'px,screenX=' + left + 'px,screenY=' + top + 'px,width=' + width + 'px,height=' + height + 'px,menubar=yes,resizable=yes,scrollbars=yes,status=no,toolbar=no');
	newWindow.focus();
}

function newMailWindow(url, width, height) {
	//url = BASE + url;
	newWindow(url, width, height);
}

function cmsInit()	{
	// BEGIN fix na nevalídnosť kódu pri target="_blank"
	if(window.document.getElementsByTagName) {
		var anchors = window.document.getElementsByTagName("a");
		for(var i = 0; i < anchors.length; i++) {
			var anchor = anchors[i];
			var anchorHref = anchor.getAttribute("href");
			
			if(anchorHref && anchor.getAttribute("rel") == "external") {
				anchor.target = "_blank";
			}
			
			if(anchorHref) {
				anchorHref = anchorHref.toLowerCase();
				if(anchorHref.indexOf("http://") == 0 || anchorHref.indexOf("https://") == 0) {
					if(anchorHref.indexOf("http://" + BASE_CLEAR) == -1 && anchorHref.indexOf("https://" + BASE_CLEAR) == -1) {
						anchor.target = "_blank";
					}
				}
			}
		}
	}
	// END fix na nevalídnosť kódu pri target="_blank"
}

DOM.aE(window, "load", cmsInit, false);

function mainActiveTabOnClick(tabsElementID, tabID, contentID, thisElement)	{
	/* BEGIN Tab elements */
	var tabElement = DOM.gI(tabID);
	thisElement.className = "activeTab";
	nextSiblingTabElement = null;
	previousSiblingTabElement = null;
	
	nextSiblingTabElement = tabElement.nextSibling;
	do {
		try {
			var nextSiblingElementLink = nextSiblingTabElement.getElementsByTagName("A");
			nextSiblingElementLink[0].className = "";
			nextSiblingTabElement = nextSiblingTabElement.nextSibling;
		} catch(e) {}
	} while(nextSiblingTabElement);
	
	previousSiblingTabElement = tabElement.previousSibling;
	do {
		try {
			var previousSiblingElementLink = previousSiblingTabElement.getElementsByTagName("A");
			previousSiblingElementLink[0].className = "";
			previousSiblingTabElement = previousSiblingTabElement.previousSibling;
		} catch(e) {}
	} while(previousSiblingTabElement);
	/* END Tab elements */
	
	/* BEGIN Content elements */
	var contentElement = DOM.gI(contentID);
	contentElement.style.display = "block";
	nextSiblingContentElement = null;
	previousSiblingContentElement = null;
	
	nextSiblingContentElement = contentElement.nextSibling;
	do {
		try {
			nextSiblingContentElement.style.display = "none";
			nextSiblingContentElement = nextSiblingContentElement.nextSibling;
		} catch(e) {}
	} while(nextSiblingContentElement);
	
	previousSiblingContentElement = contentElement.previousSibling;
	do {
		try {
			previousSiblingContentElement.style.display = "none";
			previousSiblingContentElement = previousSiblingContentElement.previousSibling;
		} catch(e) {}
	} while(previousSiblingContentElement);
	/* END Content elements */
	
	(new AJAX()).RPC(BASE + "/cms/mainRPC.php", "saveActiveTabs", [tabsElementID, tabID, contentID], function(jsonObject) {});
}
