// JavaScript Document

var xmlHttp;

function PadDigits(n, totalDigits) 
{ 
    n = n.toString(); 
    var pd = ''; 
    if (totalDigits > n.length) 
    { 
        for (i=0; i < (totalDigits-n.length); i++) 
        { 
            pd += '0'; 
        } 
    } 
    return pd + n.toString(); 
} 

function overlay (szHtml, nPage, nParagraph)
{
	var overlay;
	var Content;
	var Text;
	var n;
	var szID;


	var anchors = document.getElementsByTagName('a');

	szID  = PadDigits (nPage     , 3);
	szID += PadDigits (nParagraph, 3);
	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		
		var relAttribute = String(anchor.getAttribute('rel'));
		
		// use the string.match() method to catch 'lightbox' references in the rel attribute
		if (relAttribute.toLowerCase().match('leftmenu'))
		{
			var idAttribute = String (anchor.id)
			if (idAttribute == szID)
				anchor.style.color = '#030303';
			else
				anchor.style.color = '#238dc4';
		}
	}
	
	Content = document.getElementById ('balk2');
	if (Content)
	{
		overlay = document.getElementById ('overlay');
		if (overlay)
			Content.removeChild (overlay);
		overlay = document.createElement('div');
		overlay.setAttribute ('id', 'overlay');
		Content.appendChild (overlay);
		Text = document.createElement ('div');
		Text.setAttribute ('id', 'text');
		overlay.appendChild (Text);
		
		if (window.XMLHttpRequest)				// code for Mozilla, Safari, ** And Now IE 7 **, etc 
		{
			xmlHttp = new XMLHttpRequest();
		}
		else if (window.ActiveXObject)			//IE
		{
			xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
		}
		if (typeof(xmlHttp)=='object')
		{
			xmlHttp.onreadystatechange=postFileReady;
//			xmlHttp.open('GET', 'tekst/' + szHtml + '.html', true);
			xmlHttp.open('GET', 'tekst/' + szHtml, true);
			xmlHttp.send(null);
		}
		else
			alert ('no xmlHttp object......');
	}
	else
		alert ('\'balk2\' not found');
}
// function to handle asynchronous call
function postFileReady ()
{
	
	if (xmlHttp.readyState==4)
	{
		if (xmlHttp.status==200)
		{
			var Text = document.getElementById ('text');
			if (Text)
				Text.innerHTML=xmlHttp.responseText;
			else
				alert ('We have no text element!!');
		}
	}
}

function checkOverlay ()
{
	var szOverlay = "";
	var query = location.href.substring((location.href.indexOf('?')+1), location.href.length);
	if(location.href.indexOf('?') < 0) query = '';
	querysplit = query.split('&');
	query = new Array();
	
	for(var i = 0; i < querysplit.length; i++)
	{
		var namevalue = querysplit[i].split('=');
		namevalue[0] = namevalue[0].replace(/\+/g, ' ');
		query[namevalue[0]] = unescape(namevalue[1]);
	}
	szOverlay = query['txt'];
	if (szOverlay && szOverlay != "")
	{
		var szIndex = query['idx'];
		var nMenu = 0;
		var nTotal = 0;
		if (szIndex)
			nMenu = parseInt (szIndex);
		szIndex = query['tot'];
		if (szIndex)
			nTotal = parseInt (szIndex);
		overlay (szOverlay, nMenu, nTotal);
	}
}

function showPage (szPage)
{
}
