﻿// Variables for text size
var currentSize = 100;
var currentLine = 100;

function OpenWindow(href) {
    window.open(href, '_blank');
    return false;
}

function fontUp() {
    if (currentSize < 150) { currentSize = currentSize + 10; currentLine = currentLine + 10; doSetFontSize(); }
}

function fontDown() {
    if (currentSize > 80) { currentSize = currentSize - 10; currentLine = currentLine - 10; doSetFontSize(); }
}

function doSetFontSize() {
    document.getElementById('container').style.fontSize = currentSize + '%';
}

// Telerik r.a.d.editor filter. Strips unwanted tag attributes in order to make output XHTML1.1 compliant
function RadEditorAnchorFilter()
{
    this.GetDesignContent = null;
    this.GetHtmlContent = function(content)
    {
        var newContent = content.replace(/target=(.?)_same(.?)/g,"rel=$1_same$2");
        newContent = newContent.replace(/target=(.?)_blank(.?)/g,"rel=$1_blank$2");  
        newContent = newContent.replace(/name=(.?)(\w*)(.?)/g, "");
        
        return newContent;
    };
    this.GetPreviewContent = null;
}

// Telerik r.a.d.editor function. Applies filter.
function onClientLoad(editor)
{
    var customFilter = new RadEditorAnchorFilter();
    editor.FiltersManager.Add(customFilter);
}

// updateTargetAnchors() is to be called when page is loaded (e.g. window.onload = updateTargetAnchors;)
// Purpose is to update all anchors that are to be opened in a new window as Telerik r.a.d.editor filter strips the "target" attribute to make output XHTML1.1 compliant
function updateTargetAnchors() {
    if (!document.getElementsByTagName) return;
    
    var anchors = document.getElementsByTagName("a");
    
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "_blank")
            anchor.target = "_blank";
    }
}

// Triggered by bodys onload-event
function bodyOnLoad() {
    updateTargetAnchors();
}

// Prints praksisnotat in new window
function printPraksis(printElementId) {
    var printWin = window.open("/StaticPages/PrintPraksis.aspx?printElementId=" + printElementId, "", "height=480,width=640,scrollbars=1,resizable=1,menubar=1,toolbar=0,status=1,location=0,directories=0");
    
    if(printWin != null)
        printWin.focus();
}