﻿function breakOutOfFrames() 
{
    if(parent.frames.length >= 1)
    {
        window.top.location.href = 'Login.aspx';
    }
}

// Workaround hack for FCKeditor together with ajax
function FCKUpdateLinkedField(id)
{
    try
    {
        if(typeof(FCKeditorAPI) == "object")
        {
            FCKeditorAPI.GetInstance(id).UpdateLinkedField();
        }
    }
    catch(err)
    {
    }
}

// Selects all content in a textbox and changes bg to light yellow
function HiLightTextBox(controlId, eventTrigger) 
{
    // Get reference
    var objTextBox = $get(controlId);
    
    // Set background color
    if (eventTrigger == 'focus') 
    {
        // Select all content
        objTextBox.select();
        
        objTextBox.style.backgroundColor = '#FBFFD4';
    } 
    else 
    {
        objTextBox.style.backgroundColor = '#FFFFFF';
    }
}

function DisplayPostingMessage(targetCtrl, strMsg) 
{
    var msgBox = document.getElementById('updateContainer');
    var strMsgContainer = document.getElementById('updateInnerText');
    var srcCtrl = document.getElementById(targetCtrl);

    strMsgContainer.innerHTML = strMsg;
    msgBox.style.display = 'block';
    msgBox.style.left = findPosX(srcCtrl);
    msgBox.style.top = findPosY(srcCtrl);
}

function DisplayTimeoutMessage(pnlCtrl, strCtrl, targetCtrl, strMsg, intTimeOut) 
{
    var msgBox = document.getElementById(pnlCtrl);
    var strMsgContainer = document.getElementById(strCtrl);
    var srcCtrl = document.getElementById(targetCtrl);

    strMsgContainer.innerHTML = strMsg;
    msgBox.style.display = 'block';
    msgBox.style.left = findPosX(srcCtrl);
    msgBox.style.top = findPosY(srcCtrl);

    window.setTimeout("HidePostingMessage('" + pnlCtrl + "')", intTimeOut);
}


function HidePostingMessage(ctrl) 
{
    var msgBox = document.getElementById(ctrl);
    msgBox.style.display = 'none';
}

// Get the x pos from an object
function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

// Get the y pos from an object
function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;

    return curtop;
}

function GenerateUserName(txtFirstName, txtLastName, txtUserName, txtPassword) 
{
    var firstName = document.getElementById(txtFirstName).value.toLowerCase();
    var lastName = document.getElementById(txtLastName).value.toLowerCase();
    var userName = "bro" + lastName.substr(0,2) + firstName.substr(0,2);

    document.getElementById(txtUserName).value = userName;
    document.getElementById(txtPassword).focus();
}

function ConfirmDeleteThread() 
{
    return confirm('Vill du verkligen ta bort tråden och ALLA inlägg som svarat på tråden?\nDetta går ej att ångra!');
}

function ConfirmDeletePost()
{
    return confirm('Vill du verkligen ta bort detta svar?\nDetta går ej att ångra!');
}

// Opens a new window in center of screen
function windowOpener(windowHeight, windowWidth, windowName, windowUri)
{
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;

    newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth + 
        ',height=' + windowHeight + 
        ',left=' + centerWidth + 
        ',top=' + centerHeight + 
        ',scrollbars=yes');

    newWindow.focus();
    return newWindow.name;
}


/*
    Start page banner functions
*/

function SetUrl(fileUrl, clientID, clientTxt) 
{
    // Get reference to image
    var objImg = $get(clientID);
    var objTxt = $get(clientTxt);

    // Set new image
    objImg.src = fileUrl;
    objTxt.value = fileUrl;
}
