﻿// 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, "");
        /* 
            20071009 SAN: name-attribute put back into play as conformance mode is XHTML 1.0 Transitional.
            Action necessary to solve task "Link til anchors virker ikke", 01-10-2007 13:54 by Ulrik Herløv  
        */
        
        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();
}

//Looks for anchor tags with links to rss-feeds and places them into <link>-tags in header section
//Must be called after the anchor tags
function FindRssFeeds()
{   
    var anchors = document.documentElement.getElementsByTagName("a");
    var rss_link;
    var href;
    for(i = 0; i < anchors.length; i++)
    {
        
        href = anchors[i].getAttribute("HREF")
        //Checks for .rss extension on the link
        if( (href.match(/.*\.[Rr][Ss][Ss]/)) !== null )
        {
            var title = anchors[i].getAttribute("TITLE")
            //create and insert link-element
            rss_link = document.createElement("link");
            rss_link.setAttribute('rel','alternate');
            rss_link.setAttribute('type','application/rss+xml');
            rss_link.setAttribute('title',title);
            rss_link.setAttribute('href',href);
            var header = document.getElementsByTagName("head");
            if(header[0] != null)
                header[0].appendChild(rss_link);
        }
    }   
} 

// Pop up launcher used by user controls on SearchPostingType.aspx
function __open_document_window__(url)
{
    window.open(url, "", "menubar=no,location=yes,resizable=yes,scrollbars=yes,titlebar=yes,toolbar=yes");
}
