/***********************************************************\
|                                                           |
|          - ARENA v1 Content Management System -           |
|             Copyright (c) 2004-2008 Blest AS              |
|                  E-mail: blest@blest.no                   |
|                 Tel: (+0047) 99 37 77 88                  |
|                 Web: http://www.blest.no                  |
|                                                           |
\***********************************************************/

var isOpera = ( navigator.userAgent.indexOf ( 'Opera' ) != -1 );
var isIE = ( !isOpera && navigator.userAgent.indexOf ( 'MSIE' ) != -1 );
var isIE6 = ( !isOpera && navigator.userAgent.indexOf ( 'MSIE 6' ) != -1 );
var isMozilla = ( !isIE && !isOpera && navigator.userAgent.indexOf ( 'Mozilla' ) != -1 );
var isSafari = ( navigator.userAgent.indexOf ( 'Safari' ) > 0 );
var isKonqueror = ( navigator.userAgent.indexOf ( 'Konqueror' ) > 0 );
if ( !document.toolTip )
	document.toolTip = new Object ( );

// Expose HTMLElement for prototyping in Safari and Konqueror
if ( isSafari || isKonqueror ) 
{
	function HTMLElement ( ) { };
	function HTMLDocument ( ) { };
	function HTMLCollection ( ) { };
	function HTMLOptionsCollection ( ) { };
	function Text ( ){ }; function Node ( ){ };
	
	HTMLElement = new Object ( );
	HTMLDocument = new Object ( );
	HTMLCollection = new Object ( );
	HTMLOptionsCollection = new Object ( );
	Text = document.createTextNode ( '' ).constructor;
	Node = Text;
	
	HTMLElement.prototype = document.createElement ( 'p' ).__proto__.__proto__;
	HTMLDocument = document.constructor;
	HTMLOptionsCollection = document.createElement ( 'select' ).options.constructor;
}

// IE fixes
if( typeof Array.prototype.push == 'undefined' )
{
	Array.prototype.push = function( element ) { this[this.length] = element; }
}
if( typeof Array.prototype.pop == 'undefined' )
{
	Array.prototype.pop = function () { var last = this[ this.length - 1 ]; this.length--; return last; }
}
if( typeof Array.prototype.forEach == 'undefined' )
{
	Array.prototype.forEach = function( f ) { for( var a = 0; a < this.length; a++ ) if ( this[a] ) f ( this[a] ); }
}

if( typeof window.addEventListener == "undefined" )
{
	window.addEventListener = function( type, listener, useCapture )
	{
		window.attachEvent ( "on"+type, listener );
	}
}

/* ************************************************************************ *\
*  MISC FUNCTIONS
\* ************************************************************************ */

function escapeFlash( string )
{
	// Only escape &s, =s, and whitespace characters
	string = string.replace( /([?=&\s])/g, function( match ) { return escape( match ) } );
	// Also escape the + char
	string = string.replace( /\+/g,  "%2B" );
	return string;
}

function getValueByElementId ( elementId )
{
	if ( document.getElementById( elementId ) )
	{
		elmnt = document.getElementById( elementId );
		if ( elmnt.type == "checkbox" )
		{
			return elmnt.checked;
		}
		return elmnt.value;
	}
	else
	{
		return "";
	}
}

function getDocumentWidth ( )
{
	var theWidth;
	if ( window.innerWidth )
	{
		theWidth = window.innerWidth;
	}
	else if ( document.documentElement && document.documentElement.clientWidth )
	{
		theWidth = document.documentElement.clientWidth;
	}
	else if ( document.body )
	{
		theWidth = document.body.clientWidth;
	}
	return theWidth;
}

function hideFormFields ( varAr )
{
	if ( !isIE ) return;
		
	if ( typeof ( varAr ) != "array" )
	{
		varAr = Array ( varAr );
	}
	for ( var a = 0; a < varAr.length; a++ )
	{
		var tagname = varAr[ a ] + "";
		var eles = document.body.getElementsByTagName ( tagname.toUpperCase ( ) );
		for ( var b = 0; b < eles.length; b++ )
		{
			if ( !eles[ b ].hidden )
			{
				eles[ b ].hidden = true;
				eles[ b ].style.visibility = "hidden";
			}
		}
	}
}

function showFormFields ( varAr )
{
	if ( !isIE ) return;
		
	if ( typeof ( varAr ) != "array" )
	{
		varAr = Array ( varAr );
	}
	for ( var a = 0; a < varAr.length; a++ )
	{
		var tagname = varAr[ a ] + "";
		var eles = document.body.getElementsByTagName ( tagname.toUpperCase ( ) );
		for ( var b = 0; b < eles.length; b++ )
		{
			if ( eles[ b ].hidden )
			{
				eles[ b ].hidden = false;
				eles[ b ].style.visibility = "visible";
			}
		}
	}
}

function getScrollTop ( )
{
	if ( document.all )
		return document.documentElement.scrollTop;		
	else if ( document.body.scrollTop )
		return document.body.scrollTop;
	else		
		return window.pageYOffset;
}

function getScrollLeft ( )
{
	if ( document.all )
		return document.documentElement.scrollLeft;
	else if ( document.body.scrollLeft )
		return document.body.scrollLeft;
	else
		return window.pageXOffset;
}

function getDocumentHeight ( )
{
	var theHeight;
	if ( window.innerHeight )
	{
		theHeight = window.innerHeight
	}
	else if ( document.documentElement && document.documentElement.clientHeight )
	{
		theHeight = document.documentElement.clientHeight
	}
	else if ( document.body )
	{
		theHeight = document.body.clientHeight
	}
	return theHeight;
}

function getElementWidth ( element )
{
	var width;
	if ( element.offsetWidth )
		width = element.offsetWidth;
	else if ( element.outerWidth )
		width = element.outerWidth;
	else if ( element.innerWidth )
		width = element.innerWidth;
	else if ( element.clientWidth )
		width = element.clientWidth;
	else if ( element.document )
		width = element.document.documentElement.clientWidth;
	return width;
}

function getElementHeight ( element )
{
	var height;
	if ( element.offsetHeight )
		height = element.offsetHeight;
	else if ( element.outerHeight )
		height = element.outerHeight;
	else if ( element.innerHeight )
		height = element.innerHeight;
	else if ( element.clientHeight )
		height = element.clientHeight;
	else if ( element.document )
		height = element.document.documentElement.clientHeight;
	return height;
}

// Gets a div by id inside an element
function getDivById ( id, element )
{
	if ( !element ) element = document.body;
	var divs = element.getElementsByTagName ( "DIV" );
	for ( var a = 0; a < divs.length; a++ )
		if ( divs[ a ].id == id ) return divs[ a ];
	return false;
}
document.getDivById = function ( id, element ){ return getDivById ( id, element ); }
HTMLElement.prototype.getDivById = function ( id ){ return getDivById ( id, this ); }

function positionElement ( element, halign, valign )
{
	var marginx = 8;
	var marginy = 8;
	
	var maxwidth;
	var maxheight;
	var windowx;
	var windowy;
	
	var scrolloffsetx;
	var scrolloffsety;
		
	var posx = 0;
	var posy = 0;
	
	var elementWidth = getElementWidth ( element );
	var elementHeight = getElementHeight ( element );
	
	element.style.top = "0px";
	element.style.left = "0px";
	
	if (self.innerHeight) // all except Explorer
	{
		windowx = self.innerWidth;
		windowy = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		windowx = document.documentElement.clientWidth;
		windowy = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		windowx = document.body.clientWidth;
		windowy = document.body.clientHeight;
	}
	
	if ( document.body.clientWidth )
	{
		maxwidth  = document.body.clientWidth;
		maxheight = document.body.clientHeight;
	}
	else if ( document.documentElement.clientWidth )
	{
		maxwidth  = document.documentElement.clientWidth;
		maxheight = document.documentElement.clientHeight;
	}
		
	scrolloffsety = getScrollTop ( );		
	scrolloffsetx = getScrollLeft ( );	
		
	// Vertical alignment
	
	if ( valign == "mouseTop" )
	{
		posy = scrolloffsety + mousey - 8;
		element.style.top = posy + "px";
	}
	if ( valign == "middle" )
	{
		posy = windowy / 2 ;
		posy = posy - ( elementHeight / 2 );
		if ( scrolloffsety )
		{
			posy = posy + scrolloffsety;
			if ( posy < ( scrolloffsety + marginy ) )
				posy = scrolloffsety + marginy;
		}
		if ( posy < marginy )
			posy = marginy;
		posy = Math.ceil ( posy );
		element.style.top = posy + "px";
	}
		
	if ( halign == "mouseRight" )
	{
		posx = scrolloffsetx + mousex - 8;
		element.style.left = posx + "px";
	}
	if ( halign == "mouseCenter" )
	{
		posx = scrolloffsetx + mousex;
		posx = posx - ( elementWidth / 2 );
		element.style.left = posx + "px";
	}
	if ( halign == "center" )
	{
		posx = windowx / 2 ;
		if ( scrolloffsetx )
			posx = posx + scrolloffsetx;
		posx = posx - ( elementWidth / 2 );
		if ( posx < marginx )
			posx = marginx;
		posx = Math.ceil ( posx );
		element.style.left = posx + "px";
	}
}

/* ************************************************************************ *\
*  DOM EXTENSIONS
*  Rewritten 2006-06-06 - inge
\* ************************************************************************ */

// The getElementsByClassName and getElementsByTagAndClassName functions
document.getElementsByTagAndClassName = function ( tagName, className, parentElement )
{
	var elements = new Array ();
	var parent = ( parentElement ) ? parentElement : document.body;
	var children = parent.getElementsByTagName( tagName );
	for ( var a = 0; a < children.length; a++ )
	{
		if ( children[a].hasClass ( className ) ) elements.push ( children[a] );
	}
	return elements;
}

// ..and the wrappers
document.getElementsByClassName                    = function ( className, parentElement ) { return document.getElementsByTagAndClassName ( "*", className, parentElement ); }
HTMLElement.prototype.getElementsByTagAndClassName = function ( tagName, className )       { return document.getElementsByTagAndClassName ( tagName, className, this ); }
HTMLElement.prototype.getElementsByClassName       = function ( className )                { return document.getElementsByClassName ( className, this ); }

// Get the computed css property
function getStyle( element, cssRule )
{
	if ( element.currentStyle ) var value = element.currentStyle[ cssRule ];
	else                             var value = false;
	return value;
}

// Get a style class that we can modify
function getStyleClass ( className ) 
{
	className = '.' + className;
	for ( var a = 0; a < document.styleSheets.length; a++ )
	{
		if ( document.styleSheets[ a ].rules )
		{
			for ( var b = 0; b < document.styleSheets[ a ].rules.length; b++ )
			{
				if ( document.styleSheets[ a ].rules[ b ].selectorText == className)
				{
					return document.styleSheets[ a ].rules[ b ];
				}
			}
		}
		else if ( document.styleSheets[ a ].cssRules )
		{
			for ( var b = 0; b < document.styleSheets[ a ].cssRules.length; b++ )
			{
				if ( document.styleSheets[ a ].cssRules[ b ].selectorText == className )
				{
					return document.styleSheets[ a ].cssRules[ b ];
				}
			}
		}
	}
	return false;
}

// Set a style property
function setStyle( element, cssRule, value )
{
	var original = getStyle( element, cssRule );
	if ( !element.styleHistory )            element.styleHistory = new Array();
	if ( !element.styleHistory[ cssRule ] ) element.styleHistory[ cssRule ] = new Array();
	element.styleHistory[ cssRule ].push( original );
	element.style[ cssRule ] = value;
	return value;
}

// Undo a style property change
function undoSetStyle( element, cssRule )
{
	if( this.styleHistory && this.styleHistory[ cssRule ] && this.styleHistory[ cssRule ].length )
	{
		var oldValue = this.styleHistory[ cssRule ].pop();
		this.style[ cssRule ] = oldValue;
	}
}

// Revert one or more style properties
function revertStyle( element, cssRules )
{
	var stylesChanged = 0;
	if( element.styleHistory )
	{
		if ( cssRules == '*' ) 
		{ 
			cssRules = new Array(); for( var a in element.styleHistory ) cssRules.push( a ); 
		}
		else if ( typeof cssRules != "Array" ) cssRules = Array( cssRules );

		for( var a = 0; a < cssRules.length; a++ )
		{
			var cssRule = cssRules[a];
			if ( element.styleHistory[ cssRules[a] ] && element.styleHistory[ cssRules[a] ][0] )
			{
				element.style[ cssRules[a] ] = element.styleHistory[ cssRules[a] ][0];
				element.styleHistory[ cssRules[a] ] = new Array();
				stylesChanged++;
			}
		}
	}
	return stylesChanged;
}

// Toggle display: none on an element
// TODO: Remove commented out things: INGE!! =)
function toggleHidden( element )
{	
	if ( element )
	{
		if ( element.isHidden || element.style.display == "none" || element.style.visibility == "hidden" ) 
		{
			element.style.display = "";
			element.style.visibility = "visible";
			element.isHidden = false;
		}
		else
		{
			element.style.display = "none";
			element.style.visibility = "hidden";
			
			element.isHidden = true;
		}
	}
}

// Check if an element has a specific class name
function hasClass( element, className )
{
	return ( 
		element.className && element.className.match( new RegExp("\\b"+className+"\\b") ) 
	) ? true : false;
}

// Add a classname to an element
function addClass( element, className )
{
	if ( !hasClass( element, className ) )
	{
		if ( element.className && element.className.length > 0 )
			className = element.className+" "+className;
		element.className = className;
	}
}

// Remove a classname from an element
function removeClass( element, className )
{
	if ( hasClass( element, className ) )
	{
		element.className = element.className.replace( new RegExp("\\b"+className+"\\b"), "" );
	}
}

function elementHasClass( element, className ) { return hasClass( element, className ); }

// Set select options from html onto a select element
function setSelectOptions ( select, options )
{
	var val = 0;
	if ( select.value ) val = select.value;
	
	options = options.split ( '</option>' );
	var level = 0;

	// Go through list of options
	for ( var a = 0; a < options.length; a++ )
	{
		// Extract value and text from the option html fragments
		if ( !options[ a ].length ) continue;
		var opt = options[ a ];
		opt = opt.split ( "<option value=\"" );
		opt = opt[ 1 ];
		opt = opt.split ( "\">" );
	
		// Create a new option and count identation level (&nbsp;)
		var option = document.createElement ( 'option' );
		option.value = opt[ 0 ];
		var count = opt[ 1 ].split ( '&nbsp;' ).length - 1;
		count = count / 2;
		option.text = opt[ 1 ];
		
		if ( option.value == val )
			option.selected = 'selected';
	
		// add option to the current pnode
		select.options.add ( option );
	}

	// Find the current select and replace it with the new one
	var pnode = document.getElementById ( 'categorylist' ).parentNode;
	pnode.replaceChild ( select, document.getElementById ( 'categorylist' ) );

	if ( isIE )
	{
		for ( var c = 0; c < select.options.length; c++ )
			select.options[ c ].setAttribute ( 'text', str_replace ( '&nbsp;', ' ', str_replace ( '&amp;', '&', select.options[ c ].text ) ) );
	}
	else select.innerHTML = select.innerHTML.split ( '&amp;' ).join ( '&' );
}


/* ************************************************************************ *\
*  GET MOUSE POSITION
\* ************************************************************************ */

var mousex, mousey;
var actionList = new Array ();
var arenaInputEvents = new Array ();
arenaInputEvents[ "onmouseup" ] = new Array ( );
arenaInputEvents[ "onmousedown" ] = new Array ( );
arenaInputEvents[ "onmouseout" ] = new Array ( );
arenaInputEvents[ "onresize" ] = new Array ( );

function addAction ( func )
{
	actionList[ actionList.length ] = func;
}

document.onmousemove = function ( e ) 
{
	var posx = 0;
	var posy = 0;
	if (!e) 
		var e = window.event;
	if (e.pageX || e.pageY)
	{
		mousex = e.pageX;
		mousey = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		mousex = e.clientX;
		mousey = e.clientY;
		if (isIE)
		{
			mousex += getScrollLeft ( );
			mousey += getScrollTop ( );
		}
	}
	
	// Execute actionlist
	for ( var a = 0; a < actionList.length; a++ )
	{
		actionList[ a ] ( );
	}   
}

function addEvent ( varEvent, varfunc )
{
	switch ( varEvent )
	{
		case "onmouseup":
			var events = arenaInputEvents[ "onmouseup" ];
			events[ events.length ] = varfunc;
			return true;
		case "onmousedown":
			var events = arenaInputEvents[ "onmousedown" ];
			events[ events.length ] = varfunc;
			return true;
		case "onmouseout":
			var events = arenaInputEvents[ "onmouseout" ];
			events[ events.length ] = varfunc;
			return true;
		case "onmousemove":
			var events = arenaInputEvents[ "onmousemove" ];
			addAction ( varfunc );
			return true;
		case "onresize":
			var events = arenaInputEvents[ "onresize" ];
			events[ events.length ] = varfunc;
			return true;
		default: 
			return false;
	}
}

window.onmousedown = function ( )
{
	if ( typeof ( arenaInputEvents[ "onmousedown" ] ) != "undefined" )
	{
		for ( var a = 0; a < arenaInputEvents[ "onmousedown" ].length; a++ )
		{
			arenaInputEvents[ "onmousedown" ][ a ] ( );
		}
	}
}

window.onmouseup = function ( )
{
	if ( typeof ( arenaInputEvents[ "onmouseup" ] ) != "undefined" )
	{
		for ( var a = 0; a < arenaInputEvents[ "onmouseup" ].length; a++ )
		{
			arenaInputEvents[ "onmouseup" ][ a ] ( );
		}
	}
}

window.onmouseout = function ( )
{
	if ( typeof ( arenaInputEvents[ "onmouseout" ] ) != "undefined" )
	{
		for ( var a = 0; a < arenaInputEvents[ "onmouseout" ].length; a++ )
		{
			arenaInputEvents[ "onmouseout" ][ a ] ( );
		}
	}
}

window.onresize = function ( )
{
	if ( typeof ( arenaInputEvents[ "onresize" ] ) != "undefined" )
	{
		for ( var a = 0; a < arenaInputEvents[ "onresize" ].length; a++ )
		{
			arenaInputEvents[ "onresize" ][ a ] ( );
		}
	}
}

/* ************************************************************************ *\
*  ONLOAD
\* ************************************************************************ */

var onloadFunctions = Array ();

function addOnload ( func )
{
	var temparray = onloadFunctions;
	temparray [ temparray.length ] = func;
	onloadFunctions = temparray;
}

window.onload = function ( )
{
	var func;
	for ( var i = 0; i < onloadFunctions.length; ++i ) 
	{
		if ( onloadFunctions[i] )
			onloadFunctions[i] ();
	}
} 

var collapsedLists = false;
function collapseLists ( )
{
	if ( !collapsedLists )
	{
		// Apply collapsable behaviour on lists
		var lists = document.getElementsByTagName ( "ul" );
		for ( i = 0; i < lists.length; i++ )
		{
			if ( elementHasClass ( lists[ i ], "collapsable" ) )
			{
				makeCollapsable ( lists[ i ] );	
			}
		}
		collapsedLists = true;
	}
}

/* ************************************************************************ *\
*  GLOBAL ARRAY
\* ************************************************************************ */

var globalArray = new Array ( );
function globalAdd ( func )
{
	var len = globalArray.length;
	globalArray[ len ] = func;
	return len;
}
function globalRemove ( pos )
{
	var Arr = new Array ( );
	for ( var a = 0; a < globalArray.length; a++ )
	{
		if ( a != pos )
			Arr[ Arr.length ] = globalArray[ a ];
	}
	globalArray = Arr;
}

/* ************************************************************************ *\
*  COLLAPSABLE LISTS
\* ************************************************************************ */

function makeCollapsable ( item ) 
{
	var listitems = item.getElementsByTagName ( 'li' );
	var uls = item.getElementsByTagName ( 'ul' );
	
	var expandElements = new Array ();
	
	for ( var i = 0; i < listitems.length; ++i ) 
	{
		var span = document.createElement( "SPAN" );
		span.className = "collapse";
			listitems[i].insertBefore ( span, listitems[i].firstChild );
		listitems[ i ].ullist = uls;
		
		if ( elementHasClass ( listitems[ i ], "current" ) )
			expandElements[ expandElements.length ] = listitems[ i ];
		
		/* *****************************************************
		*  COLLAPSE ITEM
		\* ***************************************************** */
		listitems[ i ].collapse = function ( ) 
		{
			this.collapsed = true;
			for ( var x = 0; x < this.subLists.length; x++ )
			{
				if ( this.subLists[ x ].parentNode == this )
				{
					this.subLists[ x ].style.display = 'none';
				}                                      
			}
			this.icons ();
		}
		
			/* *****************************************************
			*  EXPAND ITEM
			\* ***************************************************** */
		listitems[i].expand = function () 
		{
			this.collapsed = false;
		
			for ( var x = 0; x < this.subLists.length; x++ ) 
			{
				if ( this.subLists[ x ].parentNode == this )
				{
					this.subLists[ x ].style.display = '';
				}
			}
			this.icons ();
		}
		
		/* *****************************************************
		*  EXPAND TREE
		\* ***************************************************** */
		listitems[i].expandTree = function ()
		{
			this.expand ();
			if ( 
				this.parentNode.parentNode && 
				typeof ( this.parentNode.parentNode.expandTree ) != "undefined" 
			)
			{
				this.parentNode.parentNode.expandTree ();
			}
		}
		
		/* *****************************************************
		*  OPEN/COLLAPSE ITEM
		\* ***************************************************** */
		listitems[i].toggle = function () {
			if ( this.collapsed == false )
				this.collapse ();
			else
				this.expand ();
		}

		/* *****************************************************
		*  RECALCULATE ICONS
		\* ***************************************************** */
		listitems[i].icons = function ()
		{
			var img;
			var icon;
			if ( !( img = this.firstChild.firstChild ) )
			{
				img = document.createElement ( "IMG" );
				this.firstChild.appendChild( img );
			}
			
			if ( this.subLists.length > 0 )
			{
				icon = ( this.collapsed ) ? "admin/gfx/folder_closed.gif" : "admin/gfx/folder_open.gif";
			}
			else
			{
				icon = "admin/gfx/folder_blank.gif";
			}
			
			if ( img.src != icon ) img.src = icon;
		}

		clickables = listitems[i].getElementsByTagName ( 'span' );
		for (var x = 0; x < clickables.length; ++x) {
			if ( clickables[x].className == 'collapse') {        
				clickables[x].onclick = function () 
				{
					this.parentNode.toggle ();
				}
				
				//clickables[x].style.cursor = "hand";
				clickables[x].style.cursor = "pointer";
			}
		}

		listitems[i].subLists = listitems[i].getElementsByTagName ( 'ul' );
		listitems[i].collapsed = true;
		listitems[i].collapse ();
		listitems[i].icons ();
		
	}
	
	for (var i = 0; i < expandElements.length; ++i) 
	{
		expandElements[ i ].expandTree ();
	}
}

/* ************************************************************************ *\
*  FIX PNGS IN IE
\* ************************************************************************ */

var fixPNGsExceptions = new Array ( );
function isFixPNGsException ( varClass )
{
	for ( var a = 0; a < fixPNGsExceptions.length; a++ )
	{
		if ( fixPNGsExceptions[ a ] == varClass )
			return true;
	}
	return false;
}
function addFixPNGsException ( varClass )
{
	fixPNGsExceptions[ fixPNGsExceptions.length ] = varClass;
}
function fixPNGs ( arg, mode )
{	
	if ( !mode || mode == 1 )
	{
		if ( !arg )
			arg = false;
	
		var img = true;
		var div = true
		var td = true;
	
		if ( arg == "img" )
		{
			div = false;
			td = false;
		}
	
		if ( isIE )
		{							
			if ( div )
			{
				// div
				var elementlist = document.body.getElementsByTagName ( "div" );						
				for ( var a = 0; a < elementlist.length; a++ )
				{
					if ( 
						!isFixPNGsException ( elementlist[ a ].className ) &&
						elementlist[ a ].style.background.indexOf ( ".png" ) > 0 
					)
					{
						var sourceString = elementlist[ a ].style.background.split ( "'" );
						sourceString = sourceString.join ( "" );
						
						var image = sourceString.split ( "url(" );					
						
						if ( typeof ( image[ 1 ] ) != "undefined" )
						{
							var img = image[ 1 ].split ( ")" );						
							elementlist[ a ].style.background = "none";
							elementlist[ a ].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img[0]+"', sizingMethod='normal')";			
							if ( !elementlist[ a ].style.zIndex > 10 )
								elementlist[ a ].style.zIndex = '10';
						}					
					}
				}
			}
											
			// td
			if ( td )
			{
				var elementlist2 = document.body.getElementsByTagName ( "td" );		
				for ( var a = 0; a < elementlist2.length; a++ )
				{
					if ( 
						!isFixPNGsException ( elementlist2[ a ].className ) &&
						elementlist2[ a ].style.background.indexOf ( ".png" ) > 0 
					)
					{
						var sourceString = elementlist2[ a ].style.background.split ( "'" );
						sourceString = sourceString.join ( "" );
						
						var image = sourceString.split ( "url(" );					
						
						if ( typeof ( image[ 1 ] ) != "undefined" )
						{						
							var img = image[ 1 ].split ( ")" );						
							elementlist2[ a ].style.background = "none";
							elementlist2[ a ].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img[0]+"', sizingMethod='normal')";
							if ( !elementlist[ a ].style.zIndex > 10 )
								elementlist[ a ].style.zIndex = '10';
						}					
					}
				}
			}
						
			//img
			if ( img )
			{
				var elementlist3 = document.body.getElementsByTagName ( "img" );		
				for ( var a = 0; a < elementlist3.length; a++ )
				{				
					if ( 
						!isFixPNGsException ( elementlist3[ a ].className ) &&
						elementlist3[ a ].src.indexOf ( ".png" ) > 0 
					)
					{					
						var image = elementlist3[ a ].src;					
						if ( image.indexOf ( ".png" ) > 0 )
						{		
							if ( typeof ( image ) != "undefined" )
							{							
								var tmpImg = new Image ( );							
								tmpImg.src = elementlist3[ a ].src;
								elementlist3[ a ].src = "admin/gfx/nil.gif";
								elementlist3[ a ].style.width = tmpImg.width;
								elementlist3[ a ].style.height = tmpImg.height;
								elementlist3[ a ].style.background = "none";
								elementlist3[ a ].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+tmpImg.src+"', sizingMethod='normal')";							
								if ( !elementlist[ a ].style.zIndex > 10 )
									elementlist[ a ].style.zIndex = '10';
							}					
						}
					}
				}
			}
		}
	}
}

// Get an array from document.location
function getUrlVar ( varU )
{
	varStr = document.location + "";
	varStr = varStr.split ( varU + "=" );		
	
	if ( typeof ( varStr[ 1 ] ) == "string" )
	{		
		varStr = varStr[ 1 ].split ( "&" );		
		return varStr[ 0 ];
	}	
	return false;
}

cProgressLoader = function ( siteDiv, progressbarCanvas, progressbarDiv, fixMode )
{
	if ( fixMode )
		this.fixPNGImages = fixMode;
	else
		this.fixPNGImages = false;	
	
	this.progressbarDiv = progressbarDiv;
	this.progressbarCanvas = progressbarCanvas;
	
	this.progressBarDom = document.createElement ( "DIV" );
	this.progressBarDom.className = "ProgressBar";
	this.progressTextDom = document.createElement ( "DIV" );
	this.progressTextDom.className = "ProgressText";
	
	this.siteDiv = siteDiv;
	
	this.imagesLoaded = 0;
	this.totalImages = 0;
	this.imagesArray = new Array ( );	
	
	this.showSite = function ( )
	{						
		this.progressbarCanvas.innerHTML = "";
		this.progressbarCanvas.style.display = "none";
		this.siteDiv.style.visibility = "visible";		
		if ( this.fixPNGImages )
			fixPNGs ( this.fixPNGImages );
	}			
	
	this.init = function ( )
	{	
		// Add nodes		
		this.progressBarNode = this.progressbarDiv.appendChild ( this.progressBarDom );				
		this.progressTextNode = this.progressbarDiv.appendChild ( this.progressTextDom );
		
		var imagesEle = document.getElementsByTagName ( "img" );		
		if ( imagesEle.length > 0 && navigator.userAgent.indexOf ( "Safari" ) <= 0 )
		{			
			for ( var a = 0; a < imagesEle.length; a++ )
			{
				this.imagesLoaded++;
				this.totalImages++;
				var len = this.imagesArray.length;
				this.imagesArray[ len ] = new Image ( );
				this.imagesArray[ len ].master = this;
				this.imagesArray[ len ].onload = function ( )
				{
					var progress = Math.round ( 100 - ( this.master.imagesLoaded / this.master.totalImages * 100 ) );
					this.master.imagesLoaded--;
					this.master.progressTextNode.innerHTML = "Laster inn - " + progress + "% ferdig";
					this.master.progressBarNode.style.width = progress + "%";										
					
					if ( this.master.imagesLoaded == 0 )
						this.master.showSite ( );						
				}
				this.imagesArray[ len ].src = imagesEle[ a ].src;
			}		 	
		}
		else
			this.showSite ( );
	}
			
	this.init ( );	
}

// SAFE VAR - REMEMBER TO SYNC WITH PHP EQUIVALENT!

// Read a string that has been made safe for transport
function readVarSafe ( va )
{
	// Tab
	va = str_replace ( "_[taB]_", 	"\t", 							va );
	va = str_replace ( "_[taB2]_", 	"_[taB]_", 					va ); // <- unlikely but needed
	
	// Line ending		
	va = str_replace ( "_[newlinE]_", 	"\n", 					va );
	va = str_replace ( "_[newlinE2]_", 	"_[newlinE]_", 	va ); // <- unlikely but needed
	
	return va;
}

// Write a string in a way that it's safe to transport
function writeVarSafe ( va )
{
	// Tab
	va = str_replace ( "_[taB]_", 			"_[taB2]_", 				va ); // <- unlikely but needed (precaution)
	va = str_replace ( "\t", 						"_[taB]_", 					va );
	
	// Line ending
	va = str_replace ( "_[newlinE]_", 	"_[newlinE2]_",			va ); // <- unlikely but needed (precaution)
	va = str_replace ( "\n", 						"_[newlinE]_", 			va );
	
	return va;
}

function getElementsByClassName ( classname, node )
{
	if ( !node )
		node = document.body;
	
	var Elements = node.getElementsByTagName ( "*" );
	
	if ( typeof ( Elements ) != "undefined" )
	{
		var array = new Array ( );
		
		for ( var a = 0; a < Elements.length; a++ )
		{
			if ( Elements[ a ].className && Elements[ a ].className.match ( 
				new RegExp( "(^|\\s)" + classname + "(\\s|$)" ) )
			)
			{
				array.push ( Elements[ a ] );
			}
		}
	}
	return array;
}

function getElementLeft ( varElement )
{
	var element = varElement;
	if ( !element ) return;
	var val = 0;
	
	if ( element.offsetParent )
	{
		while ( element && element != document.body )
		{
			if ( element.offsetLeft )
				val += element.offsetLeft;
			if ( element.id == "workbench" && !isIE )
				val += getScrollLeft ( );
			element = element.offsetParent;
		}
	}
	else if ( element.offsetLeft )
	{
		val = element.offsetLeft;
	}
	return val;
}

function getElementTop ( varElement )
{
	var element = varElement;
	if ( !element ) return;
	var val = 0;
	
	if ( element.offsetParent )
	{
		while ( element && element != document.body )
		{
			val += element.offsetTop;
			if ( element.id == "workbench" && !isIE )
				val += getScrollTop ( );
			element = element.offsetParent;
		}
	}
	else if ( element.offsetTop )
	{
		val = element.offsetTop;
	}
	return val;
}

function getElementPosition ( element )
{
	var obj = new Object ( );
	obj.left = 0; obj.top = 0;
	obj.width = element.offsetWidth; 
	obj.height = element.offsetHeight;
	var e;
	
	if ( isIE )
	{
		/**
		 * workaround for ie when not calculating border widths.
		 * You can supply dragoffsetleft="value"
		**/
		
		if ( ( e = element.getAttribute ( 'dragoffsetleft' ) ) )
			obj.left += parseInt ( e );
		if ( ( e = element.getAttribute ( 'dragoffsettop' ) ) )
			obj.top += parseInt ( e );
	}
	
	while ( element && typeof ( element ) != 'undefined' && element.tagName && element.tagName.toLowerCase ( ) != 'body' && element.tagName.toLowerCase ( ) != 'html' )
	{
		obj.left += element.offsetLeft;
		obj.top += element.offsetTop;
		if ( typeof ( element.offsetParent ) != 'unknown' )
		{
			element = element.offsetParent;
		}
		else break;
	}
	return obj;
}

function getBaseUrl ( )
{
	if ( !document.base_url )
	{
		return '/';
	}
	return document.base_url;
}

function getCookie ( cookieName )
{
	var cookies = document.cookie + "";
	cookies = str_replace ( ",", ";", cookies );
	cookies = str_replace ( "\n", ";", cookies );
	cookies = str_replace ( "; ", ";", cookies );
	cookies = cookies.split ( ";" );
	for ( var a = 0; a < cookies.length; a++ )
	{
		if ( 
			cookies[ a ].substr ( 0, cookieName.length ) == cookieName ||
			cookies[ a ].substr ( 1, cookieName.length ) == cookieName
		)
		{
			if ( cookies[ a ].substr ( 0, 1 ) == " " )
				cookies[ a ] = cookies[ a ].substr ( 1, cookies[ a ].length - 1 );
			var candidate = cookies[ a ];
			candidate = candidate.split ( "=" );
			return unescape(candidate[ 1 ]);
		}
	}
	return false;
}

function setCookie ( cookieName, cookieVar, expiration, path )
{
	// Assign
	if ( !expiration ) expiration = "";
	else expiration = ";\nexpires=" + expiration.toGMTString ( );
	if ( !path ) 
		path = ";\npath=" + getBaseUrl ( ) + ";\ndomain=" + CookieDomain;
	else
	{
		path = path.split ( "." );
		if ( path.length == 3 )
			path = path[ 1 ] + "." + path[ 2 ];
		else path = path.join ( "." ); 
		path = ";\npath=" + path;
	}
	
	document.cookie = cookieName + "=" + escape(cookieVar) + expiration + path;
}

// Copy an object
function copyObject ( obj )
{
	if ( obj )
	{
		var copy;
		if ( obj.tagName )
			copy = document.createElement ( obj.tagName );
		else copy = new Object ( );
		for ( var p in obj )
		{
			try
			{
				copy[ p ] = obj[ p ];
			}
			catch ( e ){ }
		}
		return copy;
	}
	return false;
}

function preventBrowserDrag ( element )
{
	element.ondrag = function () { return false; }
	if ( typeof element.addEventListener != "undefined" )
	{
		element.addEventListener( "mousedown", function ( e ) 
		{ 
			if ( e.preventDefault )
				e.preventDefault();
		}, true );
	}
}

function makeNumeric ( varNUM )
{
	varNUM = varNUM + "";
	varNUM = varNUM.split ( "px" );
	varNUM = varNUM.join ( "" );
	varNUM = varNUM.split ( "," );
	varNUM = varNUM.join ( "." );
	varNUM += 0.1;
	varNUM -= 0.1;
	return varNUM;
}

// Generic tab page support
function changeTab ( varTab, arr, cookiename )
{
	// make sure we have the tab!
	var found = 0;
	for ( var a = 0; a < arr.length; a++ )
	{
		if ( arr[ a ] == varTab )
		{
			found = 1;
			break;
		}
	}
	if ( found != 1 )
		varTab = arr[ 0 ];
	
	// ga
	if ( !cookiename )
		cookiename = 'tabmode=';
	else cookiename = cookiename + '=';
	
	for ( var a = 0; a < arr.length; a++ )
	{
		if ( arr[ a ] == varTab )
		{
			document.getElementById ( "tab" + varTab ).tabIsActive = true;
			document.getElementById ( "tab" + varTab ).className = "tab tabCurrent";
			document.getElementById ( "page" + varTab ).style.display = "";
			document.getElementById ( "page" + varTab ).pageIsActive = true;
			document.cookie = cookiename + varTab;
		}
		else
		{
			document.getElementById ( "tab" + arr[ a ] ).tabIsActive = false;
			document.getElementById ( "tab" + arr[ a ] ).className = "tab";
			document.getElementById ( "page" + arr[ a ] ).style.display = "none";
			document.getElementById ( "page" + arr[ a ] ).pageIsActive = false;
		}
		if ( navigator.userAgent.indexOf ( "MSIE" ) > 0 )
		{
			document.getElementById ( "tab" + arr[ a ] ).style.cursor = "hand";
		}
		else document.getElementById ( "tab" + arr[ a ] ).style.cursor = "pointer";
	}
}

/**
* New tab support
* Usage: initTabSystem ( 'myTabs', 'normal', 'myTabsTabs' ); @last two args are optional
* Or   : initTabSystem ( 'myTabs', 'subtabs' );
* Or   : initTabSystem ( 'myTabs' );
*/
function initTabSystem ( element, vartype, key )
{
	var ele, varID;
	if ( !element ) element = false;
	if ( typeof ( element ) == "object" ) { ele = element; varID = ele.id; }
	else { ele = document.getElementById ( element ); varID = element; }
	if ( !ele ) return; else if ( ele.initialized ) return; else ele.initialized = true;
	if ( !vartype ) vartype = "normal";
	if ( !key ) key = varID;
	var Match = "tab";
	if ( vartype == "subtabs" ) Match = "subTab";
	
	var tabs = ele.getElementsByTagName ( "DIV" );
	var activeElement = false;

	for ( var n = 0; n < tabs.length; n++ )
	{	
		if ( tabs[ n ].parentNode != ele ) continue;
		if ( tabs[ n ].className == Match )
		{
			if ( ( tabs[ n ].id == getCookie ( key + "activeTab" ) || !getCookie ( key + "activeTab" ) ) && !activeElement )
			{
				tabs[ n ].className = Match + "Active";
				activatePage ( tabs[ n ].id.replace ( Match, "page" ), tabs[ n ].parentNode );
				setCookie ( key + "activeTab", tabs[ n ].id );
			}
			tabs[ n ].onclick = function ( )
			{
				var pid = this.id.replace ( Match, "page" );
				activateTab ( this, this.parentNode, vartype );
				setCookie ( key + "activeTab", this.id );
				activeElement = tabs[ n ];
			}
		}
	}
	if ( isOpera && activeElement )
	{
		activeElement.onclick ( );
	}
}
/**
* Activate a tab - will also activate the corresponding page
**/
function activateTab ( element, container, vartype )
{
	var ele;
	var Match = "tab";
	if ( vartype == "subtabs" )
		Match = "subTab";

	if ( typeof ( element ) == "object" ) ele = element;
	else ele = document.getElementById ( element );
		
	if ( typeof ( container ) != "object" )
	{
		if ( typeof ( element ) == "object" )
			container = element.parentNode;
		else
			container = document.getElementById ( container );
	}
		
	if ( !ele ) return;
	
	var tabs = container.getElementsByTagName ( "DIV" );
	ele.className = Match + "Active";
	for ( var n = 0; n < tabs.length; n++ )
	{
		if ( tabs[ n ].parentNode != container ) continue;
		if ( tabs[ n ].id != ele.id && tabs[ n ].className.substr ( 0, Match.length ) == Match )
			tabs[ n ].className = Match;
	}
	activatePage ( getDivById ( ele.id.replace ( Match, 'page' ), container ), container );
}
/** 
 * This activates a page, used bu activateTab()
**/
function activatePage ( element, container )
{
	var ele; 
	
	if ( typeof ( container ) != "object" )
	{
		if ( typeof ( element ) == "object" )
			container = element.parentNode;
		else
			container = document.getElementById ( container );
	}
	
	if ( !container ) return;
	
	if ( typeof ( element ) == "object" ) ele = element;
	else ele = getDivById ( element, container );
	
	if ( !ele ) return false;
	
	ele.className = "pageActive";
	ele.style.visibility = 'visible';
	
	if ( isIE ) ele.style.position = 'static';
	else 
	{
		ele.style.position = 'relative';
		ele.style.display = '';
	}
	
	var pages = container.getElementsByTagName ( "DIV" )
	
	for ( var n = 0; n < pages.length; n++ )
	{
		if ( pages[ n ].parentNode != container ) continue;
		if ( pages[ n ].id != ele.id && pages[ n ].className.substr ( 0, 4 ) == "page" )
		{
			pages[ n ].className = "page";
			if ( isIE )
			{
				pages[ n ].style.visibility = 'hidden';
				pages[ n ].style.position = 'absolute';
			}
			else pages[ n ].style.display = 'none';
		}
	}
}
// Done new tab support

/* Lists of unique values */
var arenaUniqueList = function ( varname )
{
	this.Name = varname;
	this.Entries = new Array ( );
	this.addEntry = function ( val )
	{
		for ( var a = 0; a < this.Entries.length; a++ )
			if ( this.Entries[ a ] == val ) return false;
		this.Entries[ this.Entries.length ] = val;
		return true;
	}
	this.remEntry = function ( val )
	{
		var outAr = new Array ( );
		for ( var a = 0; a < this.Entries.length; a++ )
			if ( this.Entries[ a ] != val )
				outAr[ outAr.length ] = this.Entries[ a ];
		this.Entries = outAr;
		return true;
	}
}
function addToUniqueList ( vname, val )
{
	if ( !document.arenalists )
		document.arenalists = new Array ( );
	var lst = false;
	for ( var a = 0; a < document.arenalists.length; a++ )
		if ( document.arenalists[ a ].Name == vname )
			lst = document.arenalists[ a ];
	if ( !lst )
	{
		document.arenalists[ document.arenalists.length ] = new arenaUniqueList ( vname );
		lst = document.arenalists[ document.arenalists.length - 1 ];
	}	
	return lst.addEntry ( val );
}
function remFromUniqueList ( vname, val )
{
	if ( !document.arenalists )
		document.arenalists = new Array ( );
	var lst = false;
	for ( var a = 0; a < document.arenalists.length; a++ )
		if ( document.arenalists[ a ].Name == vname )
			lst = document.arenalists[ a ];
	if ( !lst )
		return false;
	return lst.remEntry ( val );
}
function getUniqueListEntries ( vname )
{
	if ( !document.arenalists )
		document.arenalists = new Array ( );
	var lst = false;
	for ( var a = 0; a < document.arenalists.length; a++ )
		if ( document.arenalists[ a ].Name == vname )
			lst = document.arenalists[ a ];
	if ( !lst )
		return false;
	if ( lst.Entries.length )
		return lst.Entries;
	return false;
}

/* MouseOver lib  */

toolTip = function ( )
{
	this.Visible = false;
	this.Node = document.createElement ( 'DIV' );
	this.Node.id = "ToolTipRect";
	if ( isIE )
		this.Node.style.position = 'absolute';
	else
		this.Node.style.position = 'fixed';
	this.Node.style.visibility = 'hidden';
	this.Node.style.top = '0px';
	this.Node.style.left = '0px';
	this.Node.style.height = '4px';
	this.Node.style.zIndex = '10000';
	if ( isIE )
		this.Node.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=90)';
	else
		this.Node.style.opacity = 0.9;
	document.getElementById ( 'TopLevelContainer' ).appendChild ( this.Node );
	
	this.show = function ( )
	{
		this.Node.style.width = '180px'; this.Node.style.height = 'auto';
		this.Node.innerHTML = '<div><p><strong>' + this.Header + '</strong></p>' + ( this.Desc ? ( '<p>' + this.Desc + '</p></div>' ) : '' );
		this.Visible = true; this.move ( );
		this.Node.style.visibility = 'visible';
		this.Node.style.height = 'auto';
	}
	this.hide = function ( )
	{
		this.Node.style.visibility = 'hidden';
		this.Node.style.width = '1px'; this.Node.style.height = '4px';
		this.Visible = false;
	}
	this.move = function ( )
	{
		if ( this.Visible )
		{
			/* Make rect stick to bounds */
			var Width = this.Node.style.width + "";
			Width = Width.replace ( "px", "" ); 
			Width++; Width--;
			var MaxLeft = getElementWidth ( document.body );
			var Left = mousex - 90; 
			if ( Left < 2 ) Left = 2;
			if ( Left + Width >= MaxLeft )
				Left = MaxLeft - Width - 24;
			var Top = mousey + ( isIE ? 16 : ( 16 - getScrollTop ( ) ) );
			if ( isIE )
			{
				if ( ( Top + getElementHeight ( this.Node ) ) - getScrollTop ( ) > getElementHeight ( document.body ) )
					Top = mousey - getElementHeight ( this.Node ) - 10;
			}
			if ( !isIE )
			{
				if ( ( Top + getElementHeight ( this.Node ) ) > ( ( getScrollTop ( ) + window.innerHeight ) ) )
					Top = mousey - getElementHeight ( this.Node ) - 10 - getScrollTop ( );
			}
				
			/* Position */
			this.Node.style.top = Top + 'px';
			this.Node.style.left = Left + 'px';
		}
	}
}

addOnload ( function ( )
{
	if ( document.getElementById ( "TopLevelContainer" ) )
	{
		document.toolTip = new toolTip ( ); addAction ( function ( ) { document.toolTip.move ( ) } );
	}
} );

function addToolTip ( varTitle, varDesc, varEle )
{
	if ( !varEle ) return;
	if ( typeof ( varEle ) != "object" )
		varEle = document.getElementById ( varEle );
	if ( !varEle ) return;
	
	varEle.onmouseover = function ( )
	{
		document.toolTip.Header = varTitle;
		document.toolTip.Desc = varDesc;
		document.toolTip.show ( );
	}
	
	varEle.onmouseout = function ( )
	{
		document.toolTip.hide ( );
	}
}

/**
* Modal dialogues --------------------------------------------------
**/

ModalDialogue = function ( )
{
	// Internal variables
	this._speed = 1.1;
	this._fademode = '';
	this._backgroundOpacity = 70;
	this._bopacity = 0;
	
	// Setup background
	this.Background = document.createElement ( "DIV" );
	if ( !isIE )
	{
		this.Background.style.position = 'fixed';
		this.Background.style.top = '0px';
	}
	else
	{
		this.Background.style.position = 'absolute';
		this.Background.style.top = getScrollTop ( ) + 'px';
	}
	this.Background.style.left = '0px';
	this.Background.style.width = '100%';
	this.Background.style.height = '100%';
	if ( isIE || navigator.userAgent.indexOf ( 'Opera' ) > 0 )
	{
		this.Background.style.height = document.documentElement.clientHeight + "px";
	}
	this.Background.style.background = '#331';
	this.Background.style.zIndex = '20001';
	this.Background.onclick = function () { return false; };
	this.Background.onmousedown = function () { return false; };
	this.Background.style.cursor = 'busy';
	
	// Setup foreground
	this.Foreground = document.createElement ( "DIV" );
	if ( !isIE )
		this.Foreground.style.position = 'fixed';
	else
		this.Foreground.style.position = 'absolute';
	this.Foreground.style.zIndex = '20002';
	this.Foreground.style.overflowX = 'hidden';
	this.Foreground.className = 'Container';
	this.Foreground.style.padding = '2px';
	
	this.setWidth = function ( varwidth )
	{
		if ( varwidth )
		{
			this.Foreground.style.width = Math.round ( varwidth ) + "px";
			this.Foreground.style.left = Math.round ( ( getDocumentWidth ( ) / 2 ) - ( Math.round ( varwidth ) / 2 ) ) + "px";
			this.Width = Math.round ( varwidth );
		}
	}
	
	this.setHeight = function ( varheight )
	{
		if ( varheight )
		{
			this.Foreground.style.height = Math.round ( varheight ) + "px";
			this.Foreground.style.top = Math.round ( ( getDocumentHeight ( ) / 2 ) - ( Math.round ( varheight ) / 2 ) + ( isIE ? getScrollTop ( ) : 0 ) ) + "px";
			this.Height = Math.round ( varheight );
		}
	}

	this.init = function ( )
	{
		this._container = (
			document.getElementById ( 'TopLevelContainer' ) ? 
			document.getElementById ( 'TopLevelContainer' ) : 
			document.getElementById ( 'Empty__' )
		);
		if ( !this.contenturl ) removeModalDialogue ( this.Name );
		
		this._bopacity = 70;
		this._renderBackground ( );
		this._setOpacity ( );
		
		this.jax = new bajax ( );
		this.jax.modal = this;
		this.jax.openUrl ( this.contenturl, 'get', true );
		this.jax.onload = function ( )
		{
			this.modal._content = this.getResponseText ( );
			this.modal._renderForeground ( );
			if ( typeof ( this.modal.queuefunc ) == 'array' )
			{
				for ( var a = 0; a < this.modal.queuefunc.length; a++ )
				{
					this.modal.queuefunc[ a ]();
				}
			}
			else if ( this.modal.queuefunc ) 
			{
				this.modal.queuefunc ( );
			}
			/*
			if ( this.modal.queuefunc )
			{
				this.modal._fadein ( 
					new Array ( 
						this.modal.InstanceName + '._renderForeground ( )', 
						this.modal.InstanceName + '.queuefunc ( )' 
					) 
				);
			}
			else
			{
				this.modal._fadein ( this.modal.InstanceName + '._renderForeground ( )' );
			}*/
			this.modal.jax = 0;
		}
		this.jax.send ( );
	}
	
	// Private functions
	this._setOpacity = function ( )
	{
		if ( !isIE )
			this.Background.style.opacity = ( this._bopacity / 100 );
		else 
			this.Background.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + this._bopacity + ')';
	}
	
	this._removeBackground = function ( )
	{
		showFormFields ( 'select' );
		if ( typeof ( this.Background ) == 'object' )
		{
			if ( navigator.appName == 'Opera' )
			{
				this.Background.style.height = '0px';
				document._operaworkaround = this;
				setTimeout ( 'document._operaworkaround._container.removeChild ( document._operaworkaround.Background )', 1 );
			}
			else
				this._container.removeChild ( this.Background );
		}
	}
	
	this._removeForeground = function ( )
	{
		this._container.removeChild ( this.Foreground );
	}
	
	this._renderBackground = function ( )
	{
		hideFormFields ( 'select' );
		this._setOpacity ( );
		this._container.appendChild ( this.Background );
	}
	this._renderForeground = function ( )
	{
		this.Foreground.innerHTML = '<div class="SubContainer" style="display: block; overflow: auto; height: ' + ( this.Height - 4 - 14 ) + 'px">' + this._content + '</div>';
		this._container.appendChild ( this.Foreground );
	}
	
	/**
	 * Fade in the modal dialogue
	**/
	this._fadein = function ( varfunc )
	{
		if ( !varfunc ) varfunc = '';
		if ( this._fademode != '' && this._fademode != 'in' )
			return;
		this._fademode = 'in';
		this._bopacity -= ( this._bopacity - this._backgroundOpacity ) / this._speed;
		this._bopacity += 0.1; // safety margin
		if ( this._bopacity < this._backgroundOpacity )			
		{
			this.Background.style.cursor = 'busy';
			setTimeout ( this.InstanceName + "._fadein ( '" + varfunc + "' )", 25 );
		}
		else 
		{
			this.Background.style.cursor = 'default';
			this._bopacity = this._backgroundOpacity;
			this._fademode = '';
			if ( varfunc )
			{
				if ( typeof ( varfunc ) == "array" )
				{
					for ( var z = 0; z < varfunc.length; z++ )
						setTimeout ( varfunc[ z ], 1 );
				}
				else
				{
					setTimeout ( varfunc, 1 );
				}
			}
		}
		this._setOpacity ( );
	}
	
	/**
	 * Fade out the modal dialogue
	**/
	this._fadeout = function ( varfunc )
	{
		if ( !varfunc ) varfunc = '';
		if ( this._fademode != '' && this._fademode != 'out' )
			return;
		this._fademode = 'out';
		this._bopacity -= this._bopacity / this._speed;
		this._bopacity -= 0.1; // safety margin
		if ( this._bopacity > 0 )			
		{
			this.Background.style.cursor = 'busy';
			setTimeout ( this.InstanceName + "._fadeout ( \"" + varfunc + "\" )", 25 );
		}
		else 
		{
			this._bopacity = 0;
			this._fademode = '';
			if ( varfunc ) setTimeout ( varfunc, 1 );
		}
		this._setOpacity ( );
	}
}

function removeModalDialogue ( varname )
{
	if ( !document.modaldialogues ) return false;
	for ( var a = 0; a < document.modaldialogues.length; a++ )
	{
		if ( document.modaldialogues[ a ].Name == varname )
		{
			document.modaldialogues[ a ]._removeForeground ( );
			_removeModalDialogue ( varname );
			//document.modaldialogues[ a ]._fadeout ( "_removeModalDialogue ( '" + varname + "' )" );
			return true;
		}
	}
	return false;
}

function _removeModalDialogue ( varname )
{
	var outar = new Array ( );
	for ( var a = 0; a < document.modaldialogues.length; a++ )
	{
		if ( document.modaldialogues[ a ].Name != varname )
		{
			var dex = outar.length;
			outar[ dex ] = document.modaldialogues[ a ];
			outar[ dex ].InstanceName = 'document.modaldialogues[ ' + dex + ' ]';
			outar[ dex ].Index = dex;
		} 
		else 
		{
			document.modaldialogues[ a ]._removeBackground ( );
		}
	}
	document.modaldialogues = outar;
}

function initModalDialogue ( varname, width, height, contenturl, queuefunc )
{
	if ( !queuefunc ) queuefunc = false;
	
	removeModalDialogue ( varname );
	
	if ( !document.modaldialogues )
		document.modaldialogues = new Array ( );
	var dex = document.modaldialogues.length;
	document.modaldialogues[ dex ] = new ModalDialogue ( );
	document.modaldialogues[ dex ].setWidth ( width );
	document.modaldialogues[ dex ].setHeight ( height );
	document.modaldialogues[ dex ].contenturl = contenturl;
	document.modaldialogues[ dex ].Index = dex;
	document.modaldialogues[ dex ].Name = varname;
	document.modaldialogues[ dex ].InstanceName = "document.modaldialogues[ " + dex + " ]";
	document.modaldialogues[ dex ].queuefunc = queuefunc;
	document.modaldialogues[ dex ].init ();
	return document.modaldialogues[ dex ];
}

/**
* Flashmovie object, used to place
* IE and Opera friendly plugin code
* through javascript...
**/
FlashMovie = function ( )
{
	this.classid = 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';
	this.codebase = window.location.protocol + '//fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0';
	this.width = '100%';
	this.height = '100%';
	this.quality = 'high';
	this.background = '#fff';
	this.name = '';
	this.align = 'middle';
	this.allowscriptaccess = 'sameDomain';
	this.src = '';
	this.pluginspage = 'http://www.macromedia.com/go/getflashplayer';
	this.type = 'application/x-shockwave-flash';
	this.id = '';
	
	// Render HTML to a string and return
	this.render = function ( )
	{
		var ar = Array (
			"<object ", "classid=\"", this.classid, "\"",
			" codebase=\"", this.codebase, "\" width=\"", this.width, "\"",
			" height=\"", this.height, "\" ", ( this.id ? "id=\"" + this.id + "\"" : "" ),
			" align=\"", this.align, "\">","<param name=\"allowScriptAccess\" value=\"", this.allowscriptaccess, "\" />",
			"<param name=\"movie\" value=\"", this.movie, "\" />",
			"<param name=\"quality\" value=\"", this.quality, "\" />",
			"<param name=\"bgcolor\" value=\"", this.background, "\" />",
			"<embed src=\"", this.movie, "\" quality=\"", this.quality, "\" bgcolor=\"", this.background, 
			"\" width=\"", this.width, "\" height=\"", this.height, "\" name=\"", this.name, "\" align=\"", 
			this.align, "\" allowScriptAccess=\"", this.allowscriptaccess, "\"", 
			" type=\"", this.type, "\" pluginspage=\"", this.pluginspage, "\" />",
			"</object>"
		);
		return ar.join ( '' );
	}
	
	// Place html on an element
	this.place = function ( varid )
	{
		if ( typeof ( varid ) == 'string' )
			varid = document.getElementById ( varid );
		if ( varid )
			varid.innerHTML = this.render ( );
	}
}

/**
* Set opacity on an element (compatible with most, cross browser (except konqueror))
**/
function setOpacity ( ele, op )
{
	if ( !ele ) return;
	if ( ele.opacity && ele.opacity == op ) return;
	
	if ( op == false ) op = 0
	
	ele.opacity = op;
	
	if ( isIE )
	{
		ele.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + ( op * 100 ) + ')';
	}
	else
	{
		ele.style.opacity = op;
	}
}

/**
 * Return an array of the script code
**/
function extractScripts ( html )
{
	var scripts = html.split ( '</script>' );
	var resultArray = new Array ( );
	for ( var a = 0; a < scripts.length; a++ )
	{	
		var script = scripts[ a ].split ( '<script>' );
		script = script[ 1 ];
		if ( script )
		{
			resultArray[ resultArray.length ] = script;
		}
	}
	return resultArray;
}

/**
 * Remove scripts
**/
function removeScripts ( html )
{
	var tc = html.split ( '<script' );
	for ( var a = 0; a < tc.length; a++ )
		html = html.replace ( /<script\b[^>]*>(.*?)<\/script>/i, '' );
	return html;
}


/**
 * Makes sure that all elements have proper positions
 * that we can read offsets from
**/
function SetProperDomPositions ( ele )
{
	if ( !ele ) ele = document.body;	

	for ( var a = 0; a < ele.childNodes.length; a++ )
	{
		var element = ele.childNodes[ a ];
		switch ( element.style.position )
		{
			case 'static':
				element.style.position = 'relative';
				break;
			case 'relative':
			case 'fixed':
			case 'absolute':
				break;
			default:
				element.style.position = 'relative';
				break;
		}
		if ( element.childNodes.length )
			SetProperDomPositions ( element );
	}
}

/** 
 * Get current translation of this one
**/
function trans ( key )
{
	if ( typeof ( document.translations ) == 'object' )
	{
		if ( document.translations[ key ] )
			return document.translations[ key ];
	}
	return key;
}

/**
 * Notify with blinking text
**/
function Notify( vartext, varcolors )
{
	var tr, tg, tb;
	if ( !varcolors ) varcolors = '224,232,185';
	
	if ( vartext )
	{	
		varcolors = varcolors.split ( ',' );
		document._notify_or = parseInt ( varcolors[ 0 ] );
		document._notify_og = parseInt ( varcolors[ 1 ] );
		document._notify_ob = parseInt ( varcolors[ 2 ] );
		
		document._notifytext = vartext;
		document._notify_r = parseInt ( varcolors[ 0 ] );
		document._notify_g = parseInt ( varcolors[ 1 ] );
		document._notify_b = parseInt ( varcolors[ 2 ] );
		document._notify_mode = 1;
		document.getElementById ( 'Notify' ).innerHTML = document._notifytext;
		document.getElementById ( 'Notify' ).style.color = 'rgb(' + document._notify_r + ',' + document._notify_g + ',' + document._notify_b + ')';
	}
	if ( document._notify_mode == 1 )
	{
		tr = 100;
		tg = 0;
		tb = 0;
	}
	else if ( document._notify_mode == 2 )
	{
		tr = document._notify_or;
		tg = document._notify_og;
		tb = document._notify_ob;
	}
	else if ( document._notify_mode == 3 )
	{
		tr = 100;
		tg = 0;
		tb = 0;
	}
	else if ( document._notify_mode == 4 )
	{
		tr = document._notify_or;
		tg = document._notify_og;
		tb = document._notify_ob;
	}
	if ( document._notify_mode != 0 )
	{
		var diffr = ( document._notify_r - tr ) / 3;
		var diffg = ( document._notify_g - tg ) / 3;
		var diffb = ( document._notify_b - tb ) / 3;
		
		document._notify_r -= diffr;
		document._notify_g -= diffg;
		document._notify_b -= diffb;
		
		var roundr = Math.round ( document._notify_r );
		var roundg = Math.round ( document._notify_g );
		var roundb = Math.round ( document._notify_b );
		
		if ( roundr == tr && roundg == tg && roundb == tb )
		{ 
			if ( document._notify_mode++ > 4 ) 
				document._notify_mode = 0; 
		}
		
		document.getElementById ( 'Notify' ).style.color = 'rgb(' + roundr + ',' + roundg + ',' + roundb + ')';
		setTimeout ( 'Notify()', 50 );
	}
	else document.getElementById ( 'Notify' ).innerHTML = '';
}
