var origInits = new Array();
var funcStack = new Array();

loadFunc( base );
window.onload = initApplication;

function initApplication()
{
	for (var i=0; i < funcStack.length; i++)
	{
		funcStack[i]();
	}
}

function base()
{
	var els = document.getElementsByTagName( 'a' );

	if (navigator.userAgent.indexOf( 'IE 6.0' ) != -1)
	{			
		window.onresize = function()
		{

			if (document.documentElement.clientWidth > 1130)
				document.getElementById( 'pageWr' ).style.width = '1100px';

			else if (document.documentElement.clientWidth < 1000)
				document.getElementById( 'pageWr' ).style.width = '970px';

			else
				document.getElementById( 'pageWr' ).style.width = (document.documentElement.clientWidth - 30) + 'px';
		}

		window.onresize();
	}

	for (var i=0; i<els.length; i++)
	{
		var item = els[i];

		if ( item.className.indexOf( 'extLinkPopup' ) != -1 || item.className.indexOf( 'intLinkPopup' ) != -1 )
			item.onclick = function() {window.open( this.href, '_blank', 'width=900,height=500,menubar=yes,location=yes,scrollbars=yes,resizable=yes' ); return false;}

		if ( item.className.indexOf( 'extLinkPopupMinimal' ) != -1)
			item.onclick = function() { window.open( this.href, '_blank', 'width=900,height=500,menubar=no,scrollbars=yes,resizable=yes' ); return false;}
	}
	
	var search = document.getElementById( 'txtSearch' );
	
	if (search)
	{
		search.onclick = changeColor;
		search.onblur = resetColor;
	}
	
	var cnr = document.getElementById( 'cnr' );
	if (cnr)
	{
		cnr.onclick = changeColor;
		cnr.onfocus = changeColor;
		cnr.onblur = resetColor;
	}
	
	var user = document.getElementById( 'user' );
	if (user)
	{
		user.onclick = changeColor;
		user.onfocus = changeColor;
		user.onblur = resetColor;
	}
	
	var passwd = document.getElementById( 'passwd' );
	if (passwd)
	{
		passwd.onclick = changeColor;
		passwd.onfocus = changeColor;
		passwd.onblur = resetColor;
	}
}

function loadFunc( new_function )
{
	funcStack.push( new_function );
}

function changeColor()
{
	if (this.style.color)
		return;

	this.style.color = '#3C3C3C';
	origInits[this.id] = this.value;
	this.value = "";
}

function resetColor()
{
	if (this.value)
		return;

	this.style.color = '';
	this.value = origInits[this.id];
}

// TYPO3 Functions
var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);
var version = "";
var msie4 = (browserName == "Microsoft Internet Explorer" && browserVer >= 4);

if ((browserName == "Netscape" && browserVer >= 3) || msie4 || browserName=="Konqueror" || browserName=="Opera") {version = "n3";} else {version = "n2";}

// Blurring links:
function blurLink(theObject)	{	//
	if (msie4)	{theObject.blur();}
}

// decrypt helper function
function decryptCharcode(n,start,end,offset)	{
	n = n + offset;

	if (offset > 0 && n > end)	{
		n = start + (n - end - 1);
	} else if (offset < 0 && n < start)	{
		n = end - (start - n - 1);
	}

	return String.fromCharCode(n);

}

// decrypt string
function decryptString(enc,offset)	{
	var dec = "";
	var len = enc.length;

	for(var i=0; i < len; i++)	{
		var n = enc.charCodeAt(i);

		if (n >= 0x2B && n <= 0x3A)	{
			dec += decryptCharcode(n,0x2B,0x3A,offset);	// 0-9 . , - + / :
		} else if (n >= 0x40 && n <= 0x5A)	{
			dec += decryptCharcode(n,0x40,0x5A,offset);	// A-Z @
		} else if (n >= 0x61 && n <= 0x7A)	{
			dec += decryptCharcode(n,0x61,0x7A,offset);	// a-z
		} else {
			dec += enc.charAt(i);
		}
	}
	return dec;
}

// decrypt spam-protected emails
function linkTo_UnCryptMailto(s)	{
	location.href = decryptString(s,-1);
}