img = new Image;
function changeImg(imgName, target) {
	img.src = imgName;
	document[target].src = img.src;
}

function getLayer(id) {
	if (document.layers) {
		for (i=0;i<document.layers.length;i++) {
			if (document.layers[i].name == id) {
				return document.layers[i];
			}
		}
	} else if (document.getElementById) {
		return document.getElementById(id)
	} else if (document.all) {
		return document.all[id]
	}
}


function validateMessage() {
	document.newMessage.submit();
}

function submitPoll(obj) {
	o = -1;
	
	for (i=0; i < obj.option.length;i++) {
		if (obj.option[i].checked) {o=i};
	}
	
	if (o == -1) {
		alert('Der er ikke valgt et svar!');
	} else {
		obj.submit();
	}
}

function openScaleableWin(url,win_name,popUpWidth,popUpHeight,leftPos,topPos) {
	popWidthHeight = "width=" + popUpWidth + ",height=" + popUpHeight;
	poptop = "";
	popleft = "";
	features = popWidthHeight + poptop + popleft + ',scrollbars=no, status=yes, resize=yes';
	window.open(url,win_name,features);
}

function openWin(url,win_name) {
	window.open(url,win_name);
}

//Copyright (c) 2001 Peter Belesis.
HM_DOM 	= (document.getElementById) ? true : false;
HM_NS4 	= (document.layers) ? true : false;
HM_IE 	= (document.all) ? true : false;
HM_IE4	= HM_IE && !HM_DOM;
HM_Mac 	= (navigator.appVersion.indexOf("Mac") != -1);
HM_IE4M = HM_IE4 && HM_Mac;
//end

function getLeftPosition() {

	if (window.innerWidth) {
		var winSize = window.innerWidth;
	
	} else {
		var winSize = document.body.clientWidth;
	}

	return (winSize/2)-170;
}
				
function getLeftPos(item) {
	return getLeftPosition() + getLayer('mPosHM_Menu' + item).offsetParent.offsetLeft;
}

function getTopPos(item) {
	return 60 + getLayer('mPosHM_Menu' + item).offsetParent.offsetTop;
}

var alphaChars = "abcdefghijklmnopqrstuvwxyz";
var digitChars = "0123456789";
var asciiChars = alphaChars + digitChars + "!#$%&()*+-./:;<=>?@[\]^_~";

function isASCII(str)
{
    var v_len = str.length;
    var i;
    for (i = 0; i < v_len; i++)
        if (asciiChars.indexOf(str.charAt(i)) == -1)
            return false;

    return true;
}//isASCII

function isdigits(str)
{
    var v_len = str.length;
    var i;
    for (i = 0; i < v_len; i++)
        if (digitChars.indexOf(str.charAt(i)) == -1)
        return false;

    return true;
}//isdigits



function checkemail(str)
{
    var resultStr   = str.replace(/ /gi, "");
    var atIndex     = resultStr.indexOf("@");
    var dotIndex    = resultStr.lastIndexOf(".");

    if ( resultStr == "" || !isASCII(resultStr) || dotIndex == -1) return false;
    if ( resultStr.lastIndexOf("@") != atIndex || resultStr.charAt(atIndex+1) == ".") return false;
    if ( atIndex <= 0 || dotIndex < atIndex || dotIndex >= resultStr.length-1) return false;

    return true;
}
function afmeld(email)
{
    if(checkemail(email))
    {
        location.href = '?mopid=nyhedsbrevstd&unsubscribe=1&email='+ email;
    }//if
    else
    {
        alert("'" + email + "' er ikke en valid email.");
    }//else
}
function tilmeld(email)
{
    if(checkemail(email))
    {
        location.href = '?mopid=nyhedsbrevstd&subscribe=1&email=' + email;
    }//if
    else
    {
        alert("'" + email + "' er ikke en valid email.");
    }//else
}
function getCenterWindowStr(popW, popH)
{
    if (document.all || document.layers)
    {
        w = screen.availWidth;
        h = screen.availHeight;
    }//if
    else
    {
        w = window.screen.availWidth;
        h = window.screen.availHeight;
    }//else

    var leftPos = (w - popW) / 2
    var topPos  = (h - popH) / 2;

    return 'top=' + topPos + ',left=' + leftPos;
}//function getCenterWindowStr
function openNewsletter(lnk)
{
    var height = 600;
    var width  = 690;
    helpWindow = window.open(lnk, 'newsletterWindow'                                      ,
                             'width=' + width + ',height=' + height + ','                 +
                             getCenterWindowStr(width, height)                            + 
                             ',location=no,status=no,toolbar=no,resizable=no,status=no,scrollbars=yes');
}//function openHelp