var isPreview = false;
var videoTeaserId;
var topBannerExpanded;

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function stateObj(id, obj) {
	this.id = id;
	this.obj = obj;
}

function getStateObj(id, objArr) {
	if (objArr == null) objArr = stateArr;
	for (j=0; j<objArr.length; j++) {
		if (objArr[j].id == id) return objArr[j];
	}
	return null;
}

function checkClassName(clsName, clsStr) {
	if (clsName == null) return false;
	clsArr = clsName.split(" ");
	if (clsArr.length == 0) {
		clsArr = new Array();
		clsArr[0] = clsName;
	}
	for (j=0; j<clsArr.length; j++) {
		if (clsArr[j].toString() == clsStr) return true;
	}
	return false;
}

function getSubIdWithClass(eId, eClass) {
    var el = document.getElementById(eId);
    if (el != null) {
        for (var i = 0; i < el.childNodes.length; i++) {
            if (checkClassName(el.childNodes[i].className, eClass)) {
                return el.childNodes[i].id;
            }
        }
    }
}

function getClassName(clsName, clsStr, clsReplace) {
	clsArr = clsName.split(' ');
	bFound = false;
	for (j=0; j<clsArr.length; j++) {
		if (clsReplace != null) {
			if ((clsArr[j].toString() == clsReplace) || (clsArr[j].toString() == clsStr)) {
				bFound = true;
				clsArr[j] = clsStr;
			}
		}
		else if (clsArr[j].toString() == clsStr) return clsName;
	}
	if (bFound) {
		clsName = '';
		for (i=0; i<clsArr.length; i++) {
			clsName += clsArr[i];
			if (i < clsArr.length-1) clsName += ' ';
		}
		return clsName;
	}
	else return clsName += ' ' + clsStr;
}

function toggle(obj) {
    var parent = obj;
    while ((parent = parent.parentNode) != null) {
        if (checkClassName(parent.className, "toggle")) {
            var toggleEl = parent;
            break;
        }
    }
	if (toggleEl != null) {
        var clsStr = "";
        clsArr = toggleEl.className.split(" ");
        for (var i = 0; i < clsArr.length; i++) {
            if (clsArr[i] == "on") {
                clsStr += "off"
            } else if (clsArr[i] == "off") {
                clsStr += "on"
            } else {
                clsStr += clsArr[i];
            }
            if (i < clsArr.length - 1) {
                clsStr += " ";
            }
        }
        toggleEl.className = clsStr;
    }
}

function flip(flipId, openId, slidesId) {
    var flipEl = document.getElementById(flipId);
    if (flipEl.className != "on") {
        if (openId == null) {
            var parent = flipEl.parentNode;
            for (var i = 0; i < parent.childNodes.length; i++) {
                if (parent.childNodes[i].className == "on") {
                    flipEl.className = "on";
                    parent.childNodes[i].className = "off";
                    return;
                }
            }
        }
        if (getStateObj(openId) == null) stateArr[stateArr.length] = new stateObj(openId, openId);
        lastEl = getStateObj(openId);
        if ((flipEl != null) && (flipId != lastEl.obj)) {
            flipEl.className = "on";
            if (slidesId != null) setOpacity(flipId, slidesId, openId)
            else {
                flipEl = document.getElementById(lastEl.obj);
                if (flipEl != null) flipEl.className = "off";
                lastEl.obj = flipId;
            }
        }
    }
}

function flipVideoList(flipId, openId, slidesId) {
    var flipEl = document.getElementById(flipId);
    if (flipEl.className != "on") {
        var tabNameA;
        var tabNameB;
        if (flipEl.className == "off tab_2") {
            tabNameA = "tab_2";
            tabNameB = "tab_1";
        }
        if (flipEl.className == "off tab_1") {
            tabNameA = "tab_1";
            tabNameB = "tab_2";
        }
        if (openId == null) {
            var parent = flipEl.parentNode;
            for (var i = 0; i < parent.childNodes.length; i++) {
                if (parent.childNodes[i].className == "on " + tabNameA) {
                    flipEl.className = "on " + tabNameA;
                    parent.childNodes[i].className = "off " + tabNameA;
                    return;
                }
            }
        }
        if (getStateObj(openId) == null) stateArr[stateArr.length] = new stateObj(openId, openId);
        lastEl = getStateObj(openId);
        if ((flipEl != null) && (flipId != lastEl.obj)) {
            flipEl.className = "on " + tabNameA;
            if (slidesId != null) setOpacity(flipId, slidesId, openId)
            else {
                flipEl = document.getElementById(lastEl.obj);
                if (flipEl != null) flipEl.className = "off " + tabNameB;
                lastEl.obj = flipId;
            }
        }
    }
}

function setOpacity(id, slidesId, openId) {
	slideObj = getStateObj(slidesId);
	lastEl = getStateObj(openId);
	if ((BrowserDetect.browser != "Explorer") && (BrowserDetect.browser != "Firefox")) {
		slideObj.obj.ieop = 101;
		sDelay = slideDelay + 1000;
	}
	if (slideObj.obj.ieop <= 100) {
		slideObj.obj.ieop += 10;
		ieop = slideObj.obj.ieop;
		el = document.getElementById(id);
		if (BrowserDetect.browser == "Explorer") el.style.filter = "alpha(opacity=" + ieop + ")"
		else el.style.MozOpacity = ieop/100;
		ieop = 100 - ieop;
		el = document.getElementById(lastEl.obj);
		if (BrowserDetect.browser == "Explorer") el.style.filter = "alpha(opacity=" + ieop + ")"
		else el.style.MozOpacity = ieop/100;
		slideObj.obj.op_id = window.setTimeout('setOpacity("' + id + '", "' + slidesId + '", "' + openId + '")', 30);
		sDelay = slideDelay;
	}
	else {
		if (lastEl != null) {
			flipEl = document.getElementById(lastEl.obj);
			if (flipEl != null) flipEl.className = "off";
			lastEl.obj = id;
		}
		if (slideObj.obj.iIntervalID != -2) slideObj.obj.iIntervalID = window.setTimeout("slide('" + slidesId + "')", sDelay);
	}
}

function slide(slidesId, clickId, bInit) {
	slidesEl = document.getElementById(slidesId);
	if (slidesEl == null) return;
	linkStateId = slidesId + "_link";
	slideStateId = slidesId + "_li";
	slideObj = initSlide(slidesId, false);
	slideObj.obj.ieop = 0;
	linkNodes = slidesEl.getElementsByTagName("div")[0].getElementsByTagName("div")[0].getElementsByTagName("div");
	oInterval = getStateObj(slidesId);
	if (clickId != null) {
		linkEl = document.getElementById(clickId);
		if (oInterval != null) {
			if (oInterval.obj.iIntervalID != null) window.clearTimeout(oInterval.obj.iIntervalID)
			oInterval.obj.iIntervalID = -2;
		}
	}
	else {
		if (oInterval.obj.iIntervalID == -2) return;
		bFound = false;
		for (j=0; j<linkNodes.length; j++) {
			linkEl = linkNodes[j];
			if (linkEl.className == "on") {
				if (j == linkNodes.length-1) linkEl = linkNodes[0]
				else linkEl = linkNodes[j+1];
				bFound = true;
				break;
			}
		}
		if (!bFound) linkEl = linkNodes[0];
	}
	if (linkEl != null) {
		linkId = linkNodes[0].id;
		liId = slidesId + linkId.substring(linkId.lastIndexOf('_'), linkId.length);
		if (getStateObj(linkStateId) == null) stateArr[stateArr.length] = new stateObj(linkStateId, linkId);
		if (getStateObj(slideStateId) == null) stateArr[stateArr.length] = new stateObj(slideStateId, liId);
		linkId = linkEl.id;
		flip(linkId, linkStateId);
		liId = slidesId + linkId.substring(linkId.lastIndexOf('_'), linkId.length);
		liEl = document.getElementById(liId);
		if (liEl != null) {
			flip(liId, slideStateId, slidesId);
		}
	}
}

function initSlide(slidesId, bInterval) {
	if (getStateObj(slidesId) == null) {
		tmpObj = new Object();
		tmpObj.ieop = 0;
		tmpObj.op_id = 0;
		tmpObj.iIntervalID = -1;
		stateArr[stateArr.length] = new stateObj(slidesId, tmpObj);
		tmpObj = null;
	}
	return getStateObj(slidesId);
}

function flipWeather(showId, hideId) {
	document.getElementById(hideId).style.display = 'none';
	document.getElementById(showId).style.display = 'block';
}

function playerFlip(linkId) {
	if (linkId == 'link_tv') {
        flip('tab_1');
		flip('link_tv');
		flip('navigation');
	}
	else {
		flip('tab_2');
		flip('link_search');
		flip('search');
	}
}

function clickInputUrl(el) {
	el.focus();
	el.select();
}

function toggleDiscussion(linkId, openId) {
	flip('disc_link_' + linkId, 'disc_link_' + openId);
	flip('disc_cont_' + linkId, 'disc_cont_' + openId);
}

function showTicker() {
	tickerEl = document.getElementById('ticker');
	if (tickerEl != null) {
		leftEl = document.getElementById('left');
		marginTop = tickerEl.offsetHeight + 5;
//		leftEl.style.marginTop = "-" + marginTop + "px";
		init_ticker();
	}
}

function showTopBar() {
	topBarEl = document.getElementById('top_bar');
    loacalBarEl = document.getElementById('local');
    if (loacalBarEl != null) {
       topBarEl.style.display = 'block';
       leftEl = document.getElementById('left');
       marginTop = topBarEl.offsetHeight + topBarEl.offsetTop;
       leftEl.style.marginTop = "-34" + "px";
    }
    if (topBarEl != null) {
       topBarEl.style.display = 'block';
    }
   // if (topBarEl != null) {
	//	topBarEl.style.display = 'block';
	//	leftEl = document.getElementById('left');
      //  marginTop = topBarEl.offsetHeight + topBarEl.offsetTop;
        //leftEl.style.marginTop = "-34" + "px";
	//}
}

function clickSearchDate(srcEl, intervalId) {
	var el = document.getElementById(intervalId);
	if (srcEl.value == "CUSTOM") {
        el.className = "on";
	} else {
		el.className = "";
	}
}

function openWindow(url) {
    if (url.href) {
        url = url.href;
    }
    window.open(url);
}

function openLegal(url) {
    openPopup(url);
}

function openTip(url) {
    openPopup(url);
}

function openStatistics(url) {
    openPopup(url);
}

function openRating(url) {
    openPopup(url);
}

function openViewer(url) {
    openPopup(url);
}

function openPlayer(url) {
    openPopup(url);
}

function openPopup(url) {
    if (url.href) {
        url = url.href;
    }
    var win = window.open(url, 'popup', 'left=0,top=0,width=1010,height=595,menubar=no,location=no,resizable=no,scrollbars=yes,status=yes');
    if (win) {
        win.focus();
    }
}

function overViewer(el) {
	contEl = el.parentNode.parentNode;
	if (checkClassName(contEl.className, "teaser_viewer")) contEl.className = getClassName(contEl.className, "on", "off");
}

function outViewer(el) {
	contEl = el.parentNode.parentNode;
	if (checkClassName(contEl.className, "teaser_viewer")) contEl.className = getClassName(contEl.className, "off", "on");
}

function mouseClick(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : "");
	var srcEl = (evt.target) ? evt.target : evt.srcElement;
    while ((srcEl.className == null || srcEl.className.length == 0) && srcEl.parentNode != null) {
        srcEl = srcEl.parentNode;
    }
    if (checkClassName(srcEl.className, "open-in-new")) {
        openWindow(srcEl);
        if (evt.preventDefault) {
            evt.preventDefault();
        } else {
            evt.returnValue = false;
        }
    }
    if (srcEl.className == "nav_drop") {
        var dropEl = srcEl.parentNode;
    }
    if (dropEl != null && dropEl.tagName == "LI") {
        if (videoTeaserId != null) {
            var playerEl = document.getElementById(videoTeaserId);
        }
    }
    var flipOn = dropEl != null && (activeMenu != dropEl);
    if (activeMenu != null || (dropEl != null && checkClassName(dropEl.className, "active"))) {
        activeMenu.className = activeMenu.className.replace("active", "");
		if (playerEl != null) {
            playerEl.style.visibility = "visible";
	    }
        activeMenu = null;
    }
    if (flipOn) {
        if (playerEl != null) {
			playerEl.style.visibility = "hidden";
	    }
        dropEl.className += " active";
        activeMenu = dropEl;
	}
    if (dropEl != null) {
        if (evt.stopPropagation) {
		    evt.stopPropagation();
		    evt.preventDefault();
	    }
    	return false;
    }
}

function getReal(el, type, value) {
	temp = el;
	while ((temp != null) && (temp.tagName != "BODY")) {
		str = eval("temp." + type);
		if (str != null) {
			if (checkClassName(str, value)) {
				el = temp;
				return el;
			}
		}
		temp = temp.parentNode;
	}
	return null;
}

function mouseOver(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : "");
	srcEl = (evt.target) ? evt.target : evt.srcElement;
	linkEl = getReal(srcEl, "className", "img_hover");
	if (linkEl != null) {
		imgEl = linkEl.childNodes.item(0);
		if (imgEl != null) {
			if (imgEl.src != null)
				if (imgEl.src.indexOf('_on.gif') == -1) imgEl.src = imgEl.src.replace('.gif', '_on.gif');
		}
		return;
	}
	linkEl = getReal(srcEl, "className", "player_control");
	if (linkEl != null) {
		playerMouseOver(linkEl);
		return;
	}
	linkEl = getReal(srcEl, "className", "play_hover");
	if (linkEl != null) {
		overViewer(linkEl);
		return;
	}
}

function mouseOut(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : "");
	srcEl = (evt.target) ? evt.target : evt.srcElement;
	linkEl = getReal(srcEl, "className", "img_hover");
	if (linkEl != null) {
		imgEl = linkEl.childNodes.item(0);
		if (imgEl != null) {
			if (imgEl.src != null)
				if (imgEl.src.indexOf('_on.gif') != -1) imgEl.src = imgEl.src.replace('_on.gif', '.gif');
		}
		return;
	}
	linkEl = getReal(srcEl, "className", "player_control");
	if (linkEl != null) {
		playerMouseOut(linkEl);
		return;
	}
	linkEl = getReal(srcEl, "className", "play_hover");
	if (linkEl != null) {
		outViewer(linkEl);
		return;
	}
}

function mouseDown(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : "");
	srcEl = (evt.target) ? evt.target : evt.srcElement;
	linkEl = getReal(srcEl, "tagName", "A");
	linkEl = getReal(srcEl, "className", "player_control");
	if (linkEl != null) playerMouseDown(linkEl);
}

function mouseUp(evt) {
	evt = (evt) ? evt : ((window.event) ? window.event : "");
	srcEl = (evt.target) ? evt.target : evt.srcElement;
	linkEl = getReal(srcEl, "tagName", "A");
	linkEl = getReal(srcEl, "className", "player_control");
	if (linkEl != null) playerMouseUp(linkEl);
}

function setCookie(name, value, daysBeforeExpire) {
	var data = name + "=" + escape(value);
    if (daysBeforeExpire) {
        var today = new Date();
        today.setTime(today.getTime());
        daysBeforeExpire *= 1000 * 60 * 60 * 24;
        data += ";expires=" + new Date(today.getTime() + (daysBeforeExpire));
    }
    data += ";path=/;";
    document.cookie = data;
}

function getCookie(cookieName) {
	var cookieList = document.cookie.split("; ");
	for (var i=0; i<cookieList.length; i++) {
		var name = cookieList[i].split("=");
		if (unescape(name[0]) == cookieName) return unescape(name[1]);
	}
	return null;
}

function toggleFont(articleId, bIncrease, bInit) {
	articleEl = document.getElementById(articleId);
	if (articleEl != null) {
		str = articleEl.className;
		if (bInit) {
			cookieStr = getCookie('fontsize');
			if (cookieStr != null) str += ' ' + cookieStr;
		}
		else {
			cookieStr = '';
			if (bIncrease) {
				cookieStr = 'larger';
				if (checkClassName(str, 'larger')) str = str
				else if (checkClassName(str, 'large')) str = str.replace('large', 'larger')
				else {
					str += ' large';
					cookieStr = 'large';
				}
			}
			else {
				if (checkClassName(str, 'larger')) {
					str = str.replace('larger', 'large');
					cookieStr = 'large';
				}
				else if (checkClassName(str, 'large')) str = str.replace('large', 'medium');
			}
			setCookie('fontsize', cookieStr);
		}
		articleEl.className = str;
	}
}

function activate(obj) {
    if (!checkClassName(obj.className, "active")) {
        obj.className = "active";
    }
}
function deactivate(obj) {
    if (checkClassName(obj.className, "active")) {
        obj.className = "";
    }
}

function printPage() {
	if (window.print) {
		window.print();
        window.location ="?mode=print";
    } else alert("Din webbl�sare st�djer ej denna funktion");
}

function tickerObject(str, link, moreInfo, newWindow) {
	this.str = str;
	this.link = link;
	this.moreInfo = moreInfo;
    this.newWindow = newWindow;
}

function clearField(el) {
	if (el.value == el.defaultValue) el.value = '';
}

function resetField(el) {
	if (el.value == '') el.value = el.defaultValue;
}

function expandTopBannerNews(intHeight){
    var intMove = intHeight;
    var header = document.getElementById("header");
    var top = document.getElementById("top_right");
    var navigation = document.getElementById("navigation");
    var middle = document.getElementById("middle");

    if (!topBannerExpanded) {
        header.style.top = parseInt(header.offsetTop + intMove) + "px";
        top.style.top = parseInt(top.offsetTop + intMove) + "px";
        navigation.style.top = parseInt(navigation.offsetTop + intMove - 62) + "px";
        middle.style.marginTop = parseInt(middle.offsetTop + intMove - 62) + "px";
        topBannerExpanded = true;
    } else {
        header.style.top = parseInt(header.offsetTop - intMove) + "px";
        top.style.top = parseInt(top.offsetTop - intMove) + "px";
        navigation.style.top = 125 + "px";
        middle.style.marginTop = 148 + "px";
        topBannerExpanded = false;
    }
}

 function expandTopBannerWeather(intHeight){
    var intMove = intHeight;
    var header = document.getElementById("header");
    var top = document.getElementById("top_right");
    var navigation = document.getElementById("navigation");
    var center = document.getElementById("center");
    var right = document.getElementById("right");
    if (!topBannerExpanded) {
        header.style.top = parseInt(header.offsetTop + intMove) + "px";
        top.style.top = parseInt(top.offsetTop + intMove) + "px";
        navigation.style.top = parseInt(navigation.offsetTop + intMove - 62) + "px";
        center.className = "center-down";
        right.className = "right-down";
        topBannerExpanded = true;
    } else {
        header.style.top = parseInt(header.offsetTop - intMove) + "px";
        top.style.top = parseInt(top.offsetTop - intMove) + "px";
        navigation.style.top = 125 + "px";
        center.className = "";
        right.className = "";
        topBannerExpanded = false;
    }
}

var activeMenu = null;

var news = Array();

var cursor="_"; // set cursor
var delay=5; // seconds between each news item

var stateArr = new Array;

var slideDelay = 3000;
var bWriteFlash = true;

function dehype() {
    var hype = document.getElementById("hype");
    if (hype) {
        var cookieName = hype.getElementsByTagName("img")[0].id;
        if (getCookie(cookieName)) {
            var img = document.createElement("img");
            img.src = site + "images/icon_rate_off.gif";
            img.className = "icon";
            img.alt = "Du har redan hajpat den h�r artikeln";
            hype.parentNode.insertBefore(img, hype);
            hype.parentNode.removeChild(hype);
        }
    }
}

function init() {
	//showTopBar(); // Pushing up top bar
	//toggleFont('article_read', null, true); // Setting font size (using cookies)
    //dehype();
	//init_ticker(); // Showing ticker

    //	Starting top slides
	//window.setTimeout("slide('slides_1', null, true)", slideDelay);
	//window.setTimeout("slide('slides_2', null, true)", slideDelay+(slideDelay/1.7));
}

var AJAXLoader = {
    _scriptRegExp: new RegExp("((<[\\s\\/]*script\\b[^>]*>)([^>]*)(<\\/script>))"),
    load: function(url, id) {
        if (url.indexOf("?") >= 0) {
            url += "&";
        } else {
            url += "?";
        }
        url += new Date().getTime();
        try {
            YAHOO.util.Connect.asyncRequest("GET", url, this._getCallBack(id));
        } catch(e) {}
    },
    post: function(form, id, url) {
        YAHOO.util.Connect.setForm(form, false);
        if (!url) {
            url = form.action;
        }
        try {
            YAHOO.util.Connect.asyncRequest("POST", url, this._getCallBack(id))
        } catch(e) {}
    },
    _successHandler: function(o) {
        if (o.responseText !== undefined) {
            if (o.argument.id != null) {
                var obj = document.getElementById(o.argument.id);
                if (obj != null) {
                    obj.innerHTML = o.responseText;
                }
            }
            var scriptMatch = o.responseText.match(AJAXLoader._scriptRegExp);
            if (scriptMatch) {
                try {
                    var script = RegExp.$3;
                    if (script.length > 0) {
                        if (window.execScript) {
                            window.execScript(script);
                        } else {
                            window.setTimeout(script, 0);
                        }
                    }
                } catch (e) {}
            }
        }
    },
    _getCallBack: function(id) {
        return {
            success: AJAXLoader._successHandler,
            timeout: 5000,
            argument: { id: id }
        };
    }
}

var Form = {
    validate: function(form) {
        var unfilled = new Array();
        var labelTags = form.getElementsByTagName("label");
        var labels = new Array();
        for (var i = 0; i < labelTags.length; i++) {
            var label = labelTags[i].innerHTML;
            if (label.endsWith("\\.") || label.endsWith(":")) {
                label = label.substr(0, label.length - 1);
            }
            label = label.replace(/<.*?>/g, "");
            labels[labelTags[i].htmlFor] = label;
        }
        for (var i = 1; i < arguments.length; i++) {
            var field = eval("form." + arguments[i]);
            var isFilled = false;
            if (field.type == "radio") {
                for (var j = 0; j < field.length; j++) {
                    if (field[j].checked) {
                        isFilled = true;
                        break;
                    }
                }
            } else if (field.type == "checkbox") {
                isFilled = field.checked;
            } else if (field.type == "file" ||
                       field.type == "text" ||
                       field.type == "textarea") {
                isFilled = field.value.length > 0;
            }
            if (!isFilled) {
                unfilled[unfilled.length] = labels[field.id];
            }
        }
        if (unfilled.length > 0) {
            var html = "Du har gl\u00F6mt fylla i f\u00F6ljande f\u00E4lt:<br/>";
            for (var i = 0; i < unfilled.length; i++) {
                html += unfilled[i];
                if (i == unfilled.length - 2) {
                    html += " och ";
                } else if (i < unfilled.length - 1) {
                    html += ", ";
                }
            }
            html += ".";
            var obj = document.getElementById(form.id + "_error");
            if (obj) {
                obj.innerHTML = html;
                return false;
            }
        }
        return true;
    },
    reset: function(id) {
        var form = document.getElementById(id);
        if (form) {
            form.reset();
            var previousName = null;
            for (var i = 0; i < form.elements.length; i++) {
                var field = form.elements[i];
                if (field.type == "radio") {
                    field.checked = field.name != previousName;
                } else if (field.type == "checkbox") {
                    field.checked = false;
                } else if (field.type == "select") {
                    field.selectedIndex = null;
                } else if (field.type == "text" || field.type == "textarea") {
                    field.value = "";
                }
                previousName = field.name;
            }
            var obj = document.getElementById(form.id + "_error");
            if (obj) {
                obj.innerHTML = "";
            }
        }
    }
}

String.prototype.endsWith = function(s){
    return new RegExp(s + "$").test(this);
}

if (BrowserDetect.browser == "Explorer") {
    document.onclick = mouseClick;
    document.onmouseover = mouseOver;
    document.onmouseout = mouseOut;
    document.onmousedown = mouseDown;
    document.onmouseup = mouseUp;
} else {
    document.addEventListener("click", mouseClick, true);
    document.addEventListener("mouseover", mouseOver, true);
    document.addEventListener("mouseout", mouseOut, true);
}