function OpenHelpWindow(theURL)
{
	var winName		= 'HelpWindow';
	var features	= 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes';
	var myWidth		= '400';
	var myHeight	= '600';
	var isCenter	= 'true';

	if(window.screen)if(isCenter)if(isCenter=="true")
	{
		var myLeft = (screen.width-myWidth)/2;
		var myTop = (screen.height-myHeight)/2;
		features+=(features!='')?',':'';
		features+=',left='+myLeft+',top='+myTop;
 	}

	HelpWindow = window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	HelpWindow.focus();
}

function divOpenClose(DivTag)
{
	if ( document.getElementById( DivTag ).className == 'hidden' )
	{
		document.getElementById( DivTag ).className='';
	}
	else
	{
		document.getElementById( DivTag ).className='hidden';
	}
}

function divShowHide(DivTag)
{
	if ( document.getElementById( DivTag ).style.display == 'none' )
	{
		document.getElementById( DivTag ).style.display = 'block';
	}
	else
	{
		document.getElementById( DivTag ).style.display = 'none';
	}
}

function returnPopupValue( Key, Title, KeyField, TitleField, AltRedirect )
{
	var oKeyField	= window.opener.document.getElementById( KeyField );
	var oTitleField	= window.opener.document.getElementById( TitleField );

	if ( (oKeyField==null) || (oTitleField==null) )
	{
		window.opener.location = unescape(AltRedirect);
		window.close();
		window.top.opener.focus();
	}
	else
	{
		oKeyField.value		= Key;
		oTitleField.value	= Title;
		window.close();
		window.top.opener.focus();
	}

}

/*
* fck 2.x
*/
function getImage( fileUrl )
{
	window.top.opener.SetUrl( fileUrl ) ;
	window.top.close() ;
	window.top.opener.focus() ;
}

function hideStyles(WindowName)
{
	if (WindowName == 'BrowseWindow')
	{
		if ( document.getElementById && document.getElementById('menu_wrapper') )
		{
			document.getElementById('menu_wrapper').className='hidden';
		}
	}
	else
	{
		if ( document.getElementById && document.getElementById('insertImageFCK') )
		{
			document.getElementById('insertImageFCK').className='hidden';
		}
	}
}

/* change style, and remember help */
function setStyleById(i, p, v, r)
{
	var n = document.getElementById(i);
	n.style[p] = v;

	// huske endringen?
	if ( r == 'True' )
	{
		var expires = new Date( 2010, 1, 1 );
		document.cookie = i + "=" + escape( p ) +":" + escape( v ) +"; expires=" + expires.toGMTString() + ";path=/;" ;
	}
}

function setStyleIdByCookie( Id )
{
	aCookie = document.cookie.split(";");

	for ( i=0; i < aCookie.length; i++ )
	{
		aName = aCookie[i].split("=");

		var a = aName[0];
		var b = Id;

		var c = aName[1];

		if ( a = b )
		{
			style = c.split(":");

//			alert( style[0] + ' : '+style[1] );
			setStyleById( Id, style[0], style[1], 'False' );
		}
    }
}

/* hover table rows */
function rowUpdateBg(row)
{
    row.style.backgroundColor = (row == rowWithMouse) ? '#F0F4F8' : '#FFFFFF';
}

function rowRollover(myId, isInRow)
{
  var row = document.getElementById('tr_' + myId);
  rowWithMouse = (isInRow) ? row : null;
  rowUpdateBg(row);
}

/* sjekk for hvilken browsertype som benyttes */
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function OpenPopup( URL, Width, Height )
{
	day = new Date();
	id = day.getTime();

	if (Width != null) { PopupWidth = Width; } else { PopupWidth = screen.width * 0.7; }
	if (Height != null) { PopupHeight = Height; } else { PopupHeight = screen.height * 0.7; }

/*	if (window.showModalDialog)
	{
		window.showModelessDialog(URL,"popup","dialogWidth:"+PopupWidth+"px;dialogHeight:"+PopupHeight+"px;resizable:yes;status:no;");
	}
	else
	{ */
		var p = window.open(URL, 'popup_'+id, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='+PopupWidth+',height='+PopupHeight+',left='+((screen.width - PopupWidth) / 2)+',top='+((screen.height - PopupHeight) / 2));

		if (p.constructor == window.constructor)
		{
			// Popup window was opened
			p.focus();
		}
//	}
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Set Cookie with ID value
 */
function setCookie(CookieName, IdName)
{
    var Value	= '';
    var expires = new Date( 2010, 1, 1 );

    if ( document.getElementById( IdName ) != null )
    {
    	Value = document.getElementById( IdName ).value;

    	document.cookie = CookieName + "=" + escape( Value ) +"; expires=" + expires.toGMTString() + ";path=/;" ;

    	//alert( CookieName + "=" + escape( Value ) +"; expires=" + expires.toGMTString() + ";path=/;" );
    }
}

/*
* PHP's in_array
*/
function in_array(item, jsarray)
{
    for (i=0; i<jsarray.length; i++)
    {
        if (jsarray[i] == item) return true;
    }
    return false;
}

/*
* tabContentChangers
*/
function ViewContent( cid )
{
	var iCount;
	var LiId;

	if ( cid == 'default' )
	{
		//alert(getCookie('gwTab'));
		if ( getCookie('gwTab') && in_array(getCookie('gwTab'), aTabs) )
		{
			cid = getCookie('gwTab');
		}
		else
		{
			// første i array
			cid = aTabs[0];
		}
	}

	// Sett denne tab i cookie
	document.cookie = 'gwTab' + "=" + escape( cid ) + ";path=/;" ;

	if (document.getElementById(cid))
	{
		document.getElementById(cid).style.display="block";

		LiId = cid.replace('tabContent','tab');
		document.getElementById(LiId).className = "current";

		for ( iCount = 0; iCount < aTabs.length; iCount++ )
		{
			if ( aTabs[iCount] != cid )
			{
				TempCid = aTabs[iCount];

				HideContent( TempCid );

				TempLiId = TempCid.replace('tabContent','tab');
				document.getElementById(TempLiId).className = null;
			}
		}
	}
}
function HideContent(cid)
{
	if ( document.getElementById(cid) )
	{
		document.getElementById(cid).style.display="none";
	}
}

/*
* Datofunksjoner
*/
function dateReset( FieldPrefix, DisplayText )
{
	var Field;
	var Display;

	Field	= document.getElementById( FieldPrefix );
	Display	= document.getElementById( FieldPrefix+'_display' );

	Field.value			= '0';
	Display.innerHTML	= DisplayText;
}

/**
 * Feltfunksjoner
 */
function fieldClear( FieldName )
{
	var Field;

	Field	= document.getElementById( FieldName );

	Field.value			= '';
}

/**
 * jsCalendar funksjoner
 */


/**
 * Invert checkbox
 */
function invertCheckbox( Field )
{
	var Checkbox = document.getElementById( Field );

	if ( Checkbox.checked == true )
	{
		Checkbox.checked = false;
	}
	else if ( Checkbox.checked == false )
	{
		Checkbox.checked = true;
	}
}
