var m_cachedImages = new Array();
var m_requiresPNGFilter = ((navigator.appName == "Microsoft Internet Explorer") && (parseFloat(navigator.appVersion) < 7));
var m_previousSrc;

function CacheImages() {
	var x, args = CacheImages.arguments;
	for (x = 0; x < args.length; x++) {
		m_cachedImages[m_cachedImages.length] = new Image;
		m_cachedImages[m_cachedImages.length-1].src = args[x];
	}
}

function SwapOver(source, index) {
    if (m_requiresPNGFilter) {
        source.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + m_cachedImages[index].src + "')";
    } else {
	    m_previousSrc = source.style.backgroundImage;
	    source.style.backgroundImage = "url(" + m_cachedImages[index].src + ")";
	}
}

function SwapReset(source, index) {
    if (m_requiresPNGFilter) {
        source.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + m_cachedImages[index].src + "')";
    } else {
	    source.style.backgroundImage = "url(" + m_cachedImages[index].src + ")";
	}
}

function InputFocusBlur(source, focusOrBlur, defaultText) {
	if (focusOrBlur == 1) {
		if (source.value == defaultText) {
			source.value = "";
		}
		source.className = "inputFieldActive";
	} else if (focusOrBlur == 2) {
		if (source.value.length == 0) {
			source.value = defaultText;
			source.className = "inputFieldInactive";
		}
	}
}

function TextSize(size) {
    var loc = "" + document.location;
    var tmp = "";
    
    // try a replace 
    tmp = loc.replace(/([?&]+)textsize=[123]/gi, "$1textsize=" + size);
    if ((tmp == loc) && (tmp.search(/[?&]+textsize=[123]/gi) < 0)) {
        tmp += (tmp.indexOf("?") > 0 ? "&" : "?") + "textsize=" + size;
    }
    document.location = tmp;
}

function PopUp(url, width, height) {
    var left = screen.width / 2 - width / 2;
    var top = screen.height / 2 - height / 2;
    return window.open(url,'','resizable=1,scrollbars=0,toolbar=0,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);
}

function PopUpForPrint(url, width, height) {
    var left = screen.width / 2 - width / 2;
    var top = screen.height / 2 - height / 2;
    window.open(url,'','resizable=1,scrollbars=1,toolbar=1,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);
}

function ImageZoom(imageId) {
    var width, height;
    if (screen.width > 1024) {
        width = 1024;
        height = 768;
    } else if (screen.width > 800) {
        width = 800;
        height = 600;
    } else {
        width = 640;
        height = 480;
    }

    var wnd = PopUp('', width, height);
    wnd.document.open();
    wnd.document.write('<html><head><title>Hälsospåret</title></head><body leftmargin=0 topmargin=0 style=\"text-align: center\" onmousedown="window.close()" onclick="window.close()"><table border="0" cellspacing="0" cellpadding="0" height="100%"><tr><td valign=middle><img src="/image.aspx?imageid=' + imageId + '&maxwidth=' + width + '&maxheight=' + height + '"></td></tr></table></body></html>');
    
    wnd.document.close();
}

function PrintHelp() {
    alert('För bästa utskriftsresultat, gör följande:\n\nGå till Förhandsgranska/Print Preview under Arkiv/Fil-menyn i din webbläsare (du kan behöva trycka på ALT-tangenten en gång för att göra menyn synlig).\n\nVälj en zoom-nivå för bästa utskrift, och klicka på utskriftsknappen i verktygsraden för att skriva ut.\n\nKlicka på OK i detta fönster för att fortsätta.');
}