function getCookie(n) {
	c = document.cookie;
	if ((p = c.indexOf(n += '=')) < 0 || (p > 0 && c.charAt(p-1) != ' ')) return;
	p += n.length;
	if ((k = c.indexOf(';', p)) < 0) k = c.length;
	return unescape(c.slice(p, k));
}

function setCookie(n, v, d, e) {
	document.cookie = n + '="' + v + '";' + (d && d.length > 2 ? 'domain='+d.substr(1, d.length - 2)+';' : '') + (e ? 'expires=' + e + ';' : '') + 'Path=/;';
}
	
function getWindowSize() {
	if (typeof(window.innerWidth) == 'number') {
	   	return Array(window.innerWidth, window.innerHeight);
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		return Array(document.documentElement.clientWidth, document.documentElement.clientHeight);
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		return Array(document.body.clientWidth, document.body.clientHeight);
	} else {
		return Array(0, 0);
	}	
}

function getWindowScroll() {
	if (typeof(window.pageYOffset) == 'number') {
		return Array(window.pageXOffset, window.pageYOffset);
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		return Array(document.body.scrollLeft, document.body.scrollTop);
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		return Array(document.documentElement.scrollLeft, document.documentElement.scrollTop);
	} else {
		return Array(0, 0);	
	}
}

function setTab(sender, id) {
	var e = document.getElementById('tabs');
	if (e) {
		var tab = e.getElementsByTagName('div');
		for (var i = 0, j = tab.length; i < j; i++) {
			if (tab[i].className == 'tabs') {
				var lnk = tab[i].getElementsByTagName('a');
				for (var x = 0, y = lnk.length; x < y; x++) {
					lnk[x].className = '';
				}
			} else if (tab[i].className == 'content') {
				var con = tab[i].getElementsByTagName('div');
				for (var x = 0, y = con.length; x < y; x++) {
					if (con[x].id.substr(0, 3) == 'tab') {
						if (con[x].id == 'tab_' + id) {
							con[x].style.display = 'block';
						} else {
							con[x].style.display = 'none';
						}
					}					
				}
			}
		}		
		sender.className = 'active';
	}
}

function showFoto(id) {
	var e = document.getElementById('fotoPopup');
	if (e) {
		var imgLoad = document.createElement('img');
			imgLoad.onload = function () {
				while (e.firstChild) e.removeChild(e.firstChild);
				e.appendChild(imgLoad);
				showPopup();
				sizePopup();				
			}
			imgLoad.src = dirPath + '_loading.gif';	

		var imgFoto = new Image();
			imgFoto.onload = function () {
				while (e.firstChild) e.removeChild(e.firstChild);
				e.appendChild(imgFoto);
				sizePopup();
			}
			imgFoto.src = dirPath + 'foto/' + id + '.jpg';
	}
	
}

function sizePopup() {
	var e = document.getElementById('fotoPopup');
	if (e) {
		var siz = getWindowSize();
		var scr = getWindowScroll();
		e.style.left = ( (siz[0] / 2) - (e.clientWidth  / 2) + scr[0] ) + 'px';
		e.style.top  = ( (siz[1] / 2) - (e.clientHeight / 2) + scr[1] ) + 'px';
	}
}

function showPopup() {
	var e = document.getElementById('hideWindow');
	if (e) {
		var size = getWindowSize();
		var main = document.getElementById('mainContainer');			
		var sizeX = (main.offsetWidth  > size[0] ? main.offsetWidth  : size[0]);
		var sizeY = (main.offsetHeight > size[1] ? main.offsetHeight : size[1]);		
		e.style.width   = '100%';
		e.style.height  = sizeY + 'px';		
		e.style.display = 'block';
	}	
	var e = document.getElementById('fotoPopup');
	if (e) {
		e.style.display = 'block';
	}
}

function hidePopup() {
	var e = document.getElementById('hideWindow');
	if (e) {
		e.style.display = 'none';
	}	
	var e = document.getElementById('fotoPopup');
	if (e) {
		e.style.display = 'none';
	}
}
