var sUserAgent = navigator.userAgent;

var isOpera = sUserAgent.indexOf("Opera") > -1;
var isKHTML = sUserAgent.indexOf("KHTML") > -1 || sUserAgent.indexOf("Konqueror") > -1 || sUserAgent.indexOf("AppleWebKit") > -1;
var isMoz = sUserAgent.indexOf("Gecko") > -1 && !isKHTML;
	
var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh");
var isUnix = (navigator.platform == "X11") && !isWin && !isMac;

var isIE = sUserAgent.indexOf("compatible") > -1 && sUserAgent.indexOf("MSIE") > -1 && !isOpera;
var isMinIE4 = isMinIE5 = isMinIE5_5 = isMinIE6 = false;




function gE( sElement ){ return document.getElementById( sElement ) ? document.getElementById( sElement ) : false; }
function gEV( element ){ return fetchElement( element ).value; }
function sEV( e, v ){ gE( e ).value = v; }
function gEHTML( element ){ return fetchElement( element ).innerHTML; }
function sEHTML( element, text ){ fetchElement( element ).innerHTML = text; }
function gEC( element ){ return fetchElement( element ).checked; }
function gECAsBit( element ){ return (fetchElement( element ).checked) ? 1 : 0; }
function isString(a){ return typeof a == 'string'; }

function fetchElement( element )
{
	if( isString( element ) ) return gE( element );
	return element;
}

function setStyle( element, sStyle )
{	
	if( isIE ) fetchElement( element ).style.setAttribute( "cssText", sStyle );
	else fetchElement( element ).setAttribute( "style", sStyle );
}

function hideElement( element )
{
	setStyle( element, "display:none" );
}
function showElement( element )
{
	setStyle( element, "display:block" );
}

//--- hide-and-show functions, help functions and variables----

//helper function to hideAndShow() but can also be used alone, then switchStatus must be set to true in the call
function simpleHideAndShow( element, switchStatus )
{
	if( isIE )
	{
		if( fetchElement( element ).style.getAttribute( "cssText" ).indexOf("none") == -1 )
			hideElement(element);
		else
			showElement(element);
	}
	else
	{
		if( fetchElement(element).getAttribute("style" ) )
		{
			if( fetchElement(element).getAttribute("style").indexOf("none") == -1 )
				hideElement(element);
			else
				showElement(element);
		}
		else
		{
			hideElement( element );
		}
	}
}


function hideAndShow( element )
{
	
	
	if( fetchElement( element ) )
	{
		simpleHideAndShow( element ); //the element was callable by it's id
		return;
	}
	
	
	//now trying to fetch by name (only div-elements can be fetched by name in IE)
	
	if( isIE ) 
		var elementsToChange = getElementsByName_iefix( "div", element );
	else 
		var elementsToChange = document.getElementsByName( element );
	
	
	if( elementsToChange.length > 0 )
	{
		// Only one of each kind, please. Otherwise it will not affect even numbers of the same ID
		var singles = new Array();
		
		for( i = 0; i < elementsToChange.length; i++ )
		{
			var found = 0;
			
			for( j = 0; j < singles.length; j++ )
			{
				if(  singles[j].id == elementsToChange[i].id )
				{
					found = 1;
					break;
				}
			}
			
			if( found == 0 )
			{
				singles.push(elementsToChange[i]);
			}
		}
		
		
		for( var i=0; i < singles.length; i++ )
		{
			simpleHideAndShow( singles[i].id );
		}
	}
}

//--- END OF HIDE-AND-SHOW------


function setOnclick( element, nonie, ie )
{

	if( isIE )
	{
		gE( element ).onclick = ie;
	}
	else
	{
		gE( element ).setAttribute( "onclick", nonie );
	}

}

function openEAC() {
	if( isIE )
	{
		window.open("http://88.80.5.114/~bouncer/eac/index.php","EACbokning","width=300,height=485,scrollbars=no");
	}
	else
	{
		window.open("http://88.80.5.114/~bouncer/eac/index.php","EACbokning","width=300,height=472,scrollbars=no");
	}
}

function openImage( width1, height1, file, title ) {
	if( isIE )
	{
		window.open( "file", "title", "width=width1", "height=height1", "scrollbars=no");
	}
	else
	{
		window.open( file, title, "width=1024", "height=683", "scrollbars=no");
	}
}