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/login.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 openRegistrationWindow() {
	loginWindow = window.open(BASE + "/registration/studentRegistration.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 printSituation(e,div,image,text) {
	!e ? e = window.event : null;
	window.document.getElementById( div ).style.display = '';
	window.document.getElementById( div ).style.position = 'absolute';
     var thisScrollTop = Math.max(window.document.documentElement.scrollTop, window.document.body.scrollTop);
	window.document.getElementById( div ).style.top = e.clientY + thisScrollTop + 35 + 'px';
	window.document.getElementById( div ).style.left = e.clientX   + 20 + 'px';
	window.document.getElementById( div ).style.background = "rgb(64,98,131) center bottom no-repeat";
	//window.document.getElementById( div ).innerHTML = text;
	setOpacity(window.document.getElementById( div ),94);
}
function hiddenSituation(e,div) {
	!e ? e = window.event : null;
	window.document.getElementById(div).style.display = "none";
}

function setOpacity(thisElement, opacity) {
 thisElement.style.filter = "alpha(opacity:"+opacity+",style=0)";
 thisElement.style.KHTMLOpacity = opacity/100;
 thisElement.style.MozOpacity = opacity/100;
 thisElement.style.opacity = opacity/100;
}

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 && anchor.getAttribute("rel") == "lytebox[photogallery]") {
				anchor.href = anchor.getAttribute("rev");				
			}				
		}
	}
	// END fix na nevalídnosť kódu pri target="_blank"
}

$(document).ready(function()	{
	// 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(anchor.className.indexOf("FotoGaleria") >= 0) {
				if(anchor.getAttribute("rev")) {
					anchor.href = anchor.getAttribute("rev");
				}
				anchor.setAttribute("rel", "FotoGaleria");				
			}
			
			if(anchor.className.indexOf("Fotka") >= 0) {
				if(anchor.getAttribute("rev")) {
					anchor.href = anchor.getAttribute("rev");
				}
				anchor.setAttribute("rel", "Fotka");				
			}			
					
		}
	}
	// END fix na nevalídnosť kódu pri target="_blank"
});

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