/* 2010-03-26: Override of InfoPath javascripts after upgrade to MOSS SP2 - START */
//JQuery used to hide 'Powered by Infopath'.
$('.BrandingText').hide();

//Overridden function in /_layouts/inc/Core.js
if (objViewDataNode) {
    var objControl = ViewDataNode_GetHtmlControlFromViewDataNodeAllowNull(objViewDataNode);
    objControl.onresize = function() {
        ErrorVisualization.UpdateAllAsterisks();
        var iFrameCollection = document.getElementsByTagName("IFRAME");
        var iFrames = iFrameCollection.length;
        for (var iFrameIndex = 0; iFrameIndex < iFrames; iFrameIndex++) {
            /* Firefox and Chrome does not support paranthesis to index 
            arrays, which is used in the original javascript. */
            var objFrame = iFrameCollection[iFrameIndex];
            if (objFrame.id.indexOf("_RT1_plainText_iframe") != -1) {
                objFrame.height = objFrame.offsetHeight - 1;
                objFrame.height = objFrame.height + 1;
            }
        }
    };
}

//Overridden function in /_layouts/inc/Core.js
function RichTextBox_DetatchAllEvents() {
    var iFrameCollection = document.getElementsByTagName("IFRAME");
    if (iFrameCollection != null) {
        var iFrames = iFrameCollection.length;
        for (var iFrameIndex = 0; iFrameIndex < iFrames; iFrameIndex++) {
            /* Firefox and Chrome does not support paranthesis to index 
            arrays, which is used in the original javascript. */
            var objFrame = iFrameCollection[iFrameIndex];
            if (objFrame.id != null && objFrame.id.indexOf("_RT1_plainText_iframe") != -1)
            { RichTextBox_CleanupIFrame(objFrame); }
        }
    }
}

//Overridden function in /_layouts/inc/Core.js
function BaseList_Render(
objViewDataNode,
objSnippetElement,
strParentHtmlId,
arrHtmlToInsertBuilder,
arrListTemplate,
templateType) {
    var templateType = View.GetTemplateType();
    var strHtmlId = LeafControl_InitializeViewDataNode(strParentHtmlId, objViewDataNode, objSnippetElement);
    var boolRenderedWrappingSpan = LeafControl_RenderBeginWrappingSpan(strHtmlId, objViewDataNode, objSnippetElement, arrHtmlToInsertBuilder);
    arrHtmlToInsertBuilder.push(arrListTemplate[0]);
    LeafControl_RenderLeafAttributes(
strHtmlId,
objViewDataNode,
objSnippetElement,
true,
true,
arrHtmlToInsertBuilder);
    var styleAttribute = "direction:" + BaseControl_GetDirectionString(objSnippetElement);
    LeafControl_OutputAttribute(" style", styleAttribute, arrHtmlToInsertBuilder);
    if (templateType == 1) {
        var displayValue = "";
        var objServerFormattedValue;
        if ((ViewDataNode.GetDatum(objViewDataNode)._changedOnClient == true))
        { objServerFormattedValue = BaseControl_GetHtmlValue(objViewDataNode, BaseControl.GetFormatting); }
        else
        { objServerFormattedValue = (ViewDataNode.GetContent(objViewDataNode)[0]); }
        var objList = BaseList.GetList(objViewDataNode);
        var nItems = (objList.length) / 2;
        if (nItems > 0)
        { displayValue = objList[1]; }
        for (var nCurrentIndex = 0; nCurrentIndex < nItems; nCurrentIndex++) {
            var strValue = objList[nCurrentIndex * 2];
            var strDisplay = objList[nCurrentIndex * 2 + 1];
            if (objServerFormattedValue == strValue)
            { displayValue = strDisplay; }
        }
        LeafControl_OutputAttribute("value", displayValue, arrHtmlToInsertBuilder);
    }
    arrHtmlToInsertBuilder.push(arrListTemplate[1]);
    if (templateType != 1) {
        ;
        var objServerFormattedValue;
        if ((ViewDataNode.GetDatum(objViewDataNode)._changedOnClient == true))
        { objServerFormattedValue = BaseControl_GetHtmlValue(objViewDataNode, BaseControl.GetFormatting); }
        else
        { objServerFormattedValue = (ViewDataNode.GetContent(objViewDataNode)[0]); }
        var objList = BaseList.GetList(objViewDataNode);
        var nItems = (objList.length) / 2;
        for (var nCurrentIndex = 0; nCurrentIndex < nItems; nCurrentIndex++) {
            var strValue = objList[nCurrentIndex * 2];
            var strDisplay = objList[nCurrentIndex * 2 + 1];
            /* Added 2007-12-05 by b920pw:
            Need to remove empty option added by default in select control. 
            Added code: 
            if (strDisplay != "") { ... } */
            if (strDisplay != "") {
                arrHtmlToInsertBuilder.push("<option value=");
                arrHtmlToInsertBuilder.push(StAttrQuote(strValue));
                if (objServerFormattedValue == strValue)
                { arrHtmlToInsertBuilder.push(" selected>"); }
                else
                { arrHtmlToInsertBuilder.push("\>"); }
                arrHtmlToInsertBuilder.push(STSHtmlEncode(strDisplay));
                arrHtmlToInsertBuilder.push("</option>");
            }
        }
    }
    arrHtmlToInsertBuilder.push(arrListTemplate[3]);
    if (boolRenderedWrappingSpan)
    { LeafControl_RenderEndWrappingSpan(arrHtmlToInsertBuilder); }
}
/* 2010-03-26: Override of InfoPath javascripts after upgrade to MOSS SP2 - END */

/* Gör ett anrop med visst intervall för att sidan med snurran inte ska timea ut. */
function Reconnect(millisecs) {
    window.setInterval('DoReconnect()', millisecs); //Set to length required
}

function DoReconnect() {
    var img = new Image(1, 1);
    img.src = '_layouts\lf_reconnect.aspx';
}

function IsIE() {
    var agt = navigator.userAgent.toLowerCase();
    return (agt.indexOf('msie') != -1);
}

function IsFF() {
    var agt = navigator.userAgent.toLowerCase();
    return (agt.indexOf('firefox') != -1);
}

function IsOpera() {
    var agt = navigator.userAgent.toLowerCase();
    return (agt.indexOf('opera') != -1);
}
function IsSafari() {
    var agt = navigator.userAgent.toLowerCase();
    return (agt.indexOf('safari') != -1);
}

function ShowPopupLayer(id) {
    var tag = document.getElementById(id);
    if (tag != null && tag.style.display != 'block') {
        tag.style.display = 'block';
        if (IsIE() == true) {
            var ifrm = document.createElement('iframe');
            ifrm.id = id + 'Iframe';
            ifrm.src = 'about:blank';
            ifrm.style.position = 'absolute';
            ifrm.style.display = 'none';
            ifrm.scrolling = 'no';
            ifrm.frameBorder = '0';
            var iref = document.body.appendChild(ifrm);
            iref.style.width = tag.clientWidth;
            iref.style.height = tag.clientHeight;
            iref.style.top = getElementPosition(tag).top;
            iref.style.left = getElementPosition(tag).left;
            iref.style.zIndex = 199;
            iref.style.display = 'block';
        }
    }
    return false;
}

function HidePopupLayer(id) {
    var tag = document.getElementById(id);
    if (tag != null && tag.style.display != 'none') {
        tag.style.display = 'none';
    }
    if (IsIE()) {
        var ifrm = document.getElementById(id + 'Iframe');
        if (ifrm != null) document.body.removeChild(ifrm);
    }
    return false;
}

function ShowLocale(ctrl, name, id, mouseOverControlId) {
    var mouseOverControl = document.getElementById(mouseOverControlId)
    if (mouseOverControl != null && mouseOverControl != undefined) {
        var localeNameControl = mouseOverControl.getElementsByTagName('div')[0]
        if (localeNameControl != null && localeNameControl != undefined) {
            localeNameControl.innerHTML = name;
        }
    }
    var source = document.getElementById(ctrl)
    if (source != null && source != undefined) {
        source.src = "/Style%20Library/Images/svkarta_" + id + ".gif";
    }
}

function getElementPosition(ref) {
    var oRef = ref, oLeft = 0, oTop = 0;
    while (oRef) {
        oLeft += oRef.offsetLeft;
        oTop += oRef.offsetTop;
        oRef = oRef.offsetParent;
    }
    if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined') {
        oLeft += document.body.leftMargin;
        oTop += document.body.topMargin;
    }
    return { left: oLeft, top: oTop };
}

function MenuHover(ref, addr) {
    var dyn = document.getElementById(ref.id + 'dyn');
    if (dyn != null) {
        if (dyn.style.display != 'block') {
            var popLeft = getElementPosition(ref).left;
            if ((popLeft + dyn.clientWidth) > 950) popLeft = 950 - dyn.clientWidth;
            dyn.style.left = popLeft;
            dyn.style.top = getElementPosition(ref).top + ref.offsetHeight;
            dyn.style.display = 'block';
            dyn.style.zIndex = 101;
            if (IsIE() == true) {
                var ifrm = document.createElement('iframe');
                ifrm.id = 'lfmenu3idrop';
                ifrm.src = addr;
                ifrm.style.position = 'absolute';
                ifrm.style.display = 'none';
                ifrm.scrolling = 'no';
                ifrm.frameBorder = '0';
                var iref = document.body.appendChild(ifrm);
                iref.style.width = dyn.clientWidth;
                iref.style.height = dyn.clientHeight;
                iref.style.top = getElementPosition(ref).top + ref.offsetHeight;
                iref.style.left = popLeft;
                iref.style.zIndex = 99;
                iref.style.display = 'block';
            }
        }
    }
    return false;
}

function MenuUnhover(ref) {
    var dyn = document.getElementById(ref.id + 'dyn');
    if (dyn != null) {
        if (dyn.style.display != 'none') dyn.style.display = 'none';
    }
    if (IsIE()) {
        var ifrm = document.getElementById('lfmenu3idrop');
        if (ifrm != null) document.body.removeChild(ifrm);
    }
    return false;
}

function PopZip(url) {
    var u = document.getElementById('newUrl');
    if (u != null && url != '') u.value = url;
    return ShowPopupLayer('zipPopup');
}

function SetImageURL(id, pic) {
    var img = document.getElementById(id);
    if (img != null) {
        img.src = '/Style%20Library/Images/' + pic;

    }
    return false;
}

//****** Kod för LocalTargetConfiguration  ********//
function moveUp(listBoxId, hiddenText) {
    var listbox = document.getElementById(listBoxId);
    var hidden = document.getElementsByName(hiddenText)(0);
    var options = listbox.options;
    var index = listbox.options.selectedIndex;
    var selectedItem = options(index);
    if (!(index == 0 || options.length <= 1)) {
        var itemAbove = options(index - 1);
        var text = itemAbove.text
        var value = itemAbove.value
        itemAbove.value = selectedItem.value;
        itemAbove.text = selectedItem.text;
        options(index).value = value;
        options(index).text = text;
        listbox.options.selectedIndex = index - 1;

        hidden.value = "";
        for (var i = 0; i < options.length; i++) {
            hidden.value = hidden.value + options(i).value + ';';
        }
    }
}

function moveDown(listBoxId, hiddenText) {
    var listbox = document.getElementById(listBoxId);
    var hidden = document.getElementsByName(hiddenText)(0);
    var options = listbox.options;
    var index = listbox.options.selectedIndex;
    var selectedItem = options(index);
    if (!(index == options.length - 1 || options.length <= 1)) {
        var itemBelow = options(index + 1);
        var text = itemBelow.text
        var value = itemBelow.value
        itemBelow.value = selectedItem.value;
        itemBelow.text = selectedItem.text;
        options(index).value = value;
        options(index).text = text;
        listbox.options.selectedIndex = index + 1;

        hidden.value = "";
        for (var i = 0; i < options.length; i++) {
            hidden.value = hidden.value + options(i).value + ';';
        }
    }
}

//****** Kod för Inställningarsidan  ********//
function toggleSize(introId, subheadId, contentId, toLower) {

    var introPreview = document.getElementById(introId);
    var subheadPreview = document.getElementById(subheadId);
    var contentPreview = document.getElementById(contentId);
    if (introPreview != null && subheadPreview != null && contentPreview != null) {
        if (toLower) {
            introPreview.className = 'lf-Content-Introduction-Normal';
            introPreview.innerHTML = "S&#229; h&#228;r visas ingresstext med textstorleken &#34;Normal&#34;"
            subheadPreview.style.fontSize = "11px";
            contentPreview.className = 'lf-Content-Text-Normal';
            contentPreview.innerHTML = "S&#229; h&#228;r visas br&#246;dtext med textstorleken &#34;Normal&#34;"
        }
        if (!toLower) {
            introPreview.className = 'lf-Content-Introduction-Large';
            introPreview.innerHTML = "S&#229; h&#228;r visas ingresstext med textstorleken &#34;Stor&#34;"
            subheadPreview.style.fontSize = "15px";
            contentPreview.className = 'lf-Content-Text-Large';
            contentPreview.innerHTML = "S&#229; h&#228;r visas br&#246;dtext med textstorleken &#34;Stor&#34;"
        }

        return true;
    }
    return false;
}

function changeSelectLink(select, link) {
    document.getElementById(link).href = select.options[select.selectedIndex].value
}

