function lib_bwcheck(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.opera6=this.agent.indexOf("Opera 6")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()

function calculateSize(bytes){
	var strPrefix = " Kb";
	Kbytes = parseInt(bytes/1000);
	if(Kbytes>1000){
		Kbytes=Kbytes/1000;
		Kbytes = String(Kbytes);
		//pos = Kbytes.indexOf(".");
		KbytesNew = Kbytes.substring(Kbytes.indexOf("."),Kbytes.indexOf(".")+2);
		Kbytes = Kbytes.substring(0,Kbytes.indexOf(".")) + KbytesNew;
		strPrefix = " Mb";
	}
	document.write(Kbytes + strPrefix);
}

function extension(ext){
	ext = ext.toLowerCase()
	document.write('<img src="/system/images/icons/file_' + ext + '_16.gif" width="16" height="16"');
}


function confirmForm(f) {
	var isOk = true;
	var message = "Please fill in:\n\n";
	for(var i = 0; i < f.length; i++) {
		if(f[i].name.substring(0,4) == "obl_" & (f[i].value=="" || f[i].value==-1)) {
			isOk = false;
			message += " - " + f[i].name.substring(4,f[i].name.length) + "\n";
			f[i].style.background = "#FFF371";
		} else {
			var fieldName = f[i].name.substring(4,f[i].name.length)
			fieldName = fieldName.toLowerCase();
			if(fieldName == "obl_email" || fieldName == "email" || fieldName == "epost" || fieldName == "e-mail" || fieldName == "e-post") {
				if(!checkEmail(f[i].value)) {
					message += " - The E-mail address is not valid.\n";
					isOk = false;
					f[i].style.background = "#FFF371";
				} else {
					f[i].style.background = "#FFFFFF"
				}
			} else {
				f[i].style.background = "#FFFFFF"
			}
		}
	}
	if(!isOk) {
		alert(message);
	}
	return isOk;
}

function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
	return (true)
}
	
	return (false)
}

//Scroll functions ###################################################################################################################
var timer;
var speed;

function makeObj(obj,nest){
    nest=(!nest) ? "":'document.'+nest+'.'
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight
	this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight
	this.up=goUp;this.down=goDown;
	this.moveIt=moveIt; this.x=0; this.y=0;
    this.obj = obj + "Object"
    eval(this.obj + "=this")
    return this
}

// A unit of measure that will be added when setting the position of a layer.
var px = bw.ns4||window.opera?"":"px";

function moveIt(x,y){
	this.x = x
	this.y = y
	this.css.left = this.x+px
	this.css.top = this.y+px
}

//Makes the object go up
function goDown(move){
	if (this.y>-this.scrollHeight+oCont.clipHeight){
		this.moveIt(0,this.y-move)
			if (loop) setTimeout(this.obj+".down("+move+")",speed)
	}
}

//Makes the object go down
function goUp(move){
	if (this.y<0){
		this.moveIt(0,this.y-move)
		if (loop) setTimeout(this.obj+".up("+move+")",speed)
	}
}

//Calls the scrolling functions. Also checks whether the page is loaded or not.
function scroll(speed){
	if (scrolltextLoaded){
		loop = true;
		if (speed>0) oScroll.down(speed)
		else oScroll.up(speed)
	}
}

//Stops the scrolling (called on mouseout)
function noScroll(){
	loop = false
	if (timer) clearTimeout(timer)
}

//Makes the object
var scrolltextLoaded = false
function scrolltextInit(){
	oCont = new makeObj('scrolltextcontainer')
	oScroll = new makeObj('scrolltext','scrolltextcontainer')
	oScroll.moveIt(0,0)
	oCont.css.visibility = "visible"
	scrolltextLoaded = true
	
}

//Start scrolling after stopped (called on mouseout)
function newScroll(speed){
	loop = false
	if (timer) clearTimeout(timer)
}

// CHANGE CLASS FUNCTION
var classname = 'active';// this will test the class values, it holds the current value, and should correspond to the off state class 
var classname1 = 'activeie';// static value, change this to your class 1 name
var classname2 = 'active';// static value, change this to your class 2 name
var feature = 'single';// sets if only hover element or all changes :: options: 'single' or 'all'

// gets all the elements of that have class classname and returns them as an array
function getElementsByClassName(needle) 
{
	var my_array = document.getElementsByTagName("*");
	var retvalue = new Array();
	var i;
	var j;

	for (i=0,j=0;i<my_array.length;i++) 
	{
		var c = " " + my_array[i].className + " ";
		if (c.indexOf(" " + needle + " ") != -1) retvalue[j++] = my_array[i];
	}
	return retvalue;
}

function replaceactive()
{
	var div = getElementsByClassName(classname)
	if(bw.ie5 || bw.ie6)
	{
		toggle();
	}
}

// if feature is set to all, this will switch all of the class items
// loops through the classname array and switches them to their opposite values
function toggle()
{
	var divs = getElementsByClassName(classname)
	for(i=0; i <divs.length;i++)
	{
		if(divs[i].className == classname1)
		{
			divs[i].className = classname2;
			classname = classname2;
		}
		else
		{
			divs[i].className = classname1;
			classname = classname1;
		} 
	}
}

// Show and hide text in layer, use as: <a href="#" onmouseover="showtext('Id_of_div','this is your text')" onmouseout="hidetext()">obj</a>, add "filter:alpha(opacity=0);-moz-opacity:0;" the the style of that div

// Source: http://www.javascriptkit.com/javatutors/crossmenu2.shtml

var baseopacity=0

function showtext(textlayer,thetext){
if (!document.getElementById)
return
textcontainerobj=document.getElementById(textlayer)
browserdetect=textcontainerobj.filters? "ie" : typeof textcontainerobj.style.MozOpacity=="string"? "mozilla" : ""
instantset(baseopacity)
document.getElementById(textlayer).innerHTML=thetext
highlighting=setInterval("gradualfade(textcontainerobj)",50)
}

function hidetext(){
cleartimer()
instantset(baseopacity)
}

function instantset(degree){
if (browserdetect=="mozilla")
textcontainerobj.style.MozOpacity=degree/100
else if (browserdetect=="ie")
textcontainerobj.filters.alpha.opacity=degree
else if (document.getElementById && baseopacity==0)
document.getElementById("tabledescription").innerHTML=""
}

function cleartimer(){
if (window.highlighting) clearInterval(highlighting)
}

function gradualfade(cur2){
if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.2, 0.99)
else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=20
else if (window.highlighting)
clearInterval(highlighting)
}

