/**
 * (main.js) Part of Portal Builder distribution files
 * Copyright 2010 Notorious Solutions Ltd. All Rights Reserved.
 * Unauthorized distribution, copying, modification, etc... in parts or in whole
 * is strictly forbidden without written permission from Notorious Solutions Ltd.
 * More information on www.notorious-solutions.com
 *
 * This file may only be used with the website/s designed with Portal Builder by Notorious Solutions Ltd.
 *
 * Last Modification Date: 2010-06-05
 * Last Modified By: AnGeL
**/

var newWindow = '';

/**
 * returns window size as array
 * arr[0] - width
 * arr[1] - height
 */
function getWindowSize()
{
    var width, height;
    if( self.innerHeight )
    {
        width = self.innerWidth;
        height = self.innerHeight;
    } else if( document.documentElement && document.documentElement.clientHeight )
    {
        width = document.documentElement.clientWidth;
        height = document.documentElement.clientHeight;
    } else if( document.body )
    {
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }
    return new Array(width, height);
}

function followLink(url, parameters, target, forceNewWin)
{
    if(parameters == null) parameters = 'scrollbars=1,resizable=1,height=480,width=640';
    if(target != "_blank")
    {
        document.location.href=url;
        return false;
    }
    if (!newWindow.closed && newWindow.location && forceNewWin != 1)
    {
        newWindow.location.href = url;
    }
    else
    {
        newWindow = window.open(url,'name',parameters);
        if(!newWindow.opener) newWindow.opener = self;
    }
    if (newWindow.focus) {
        newWindow.focus()
    }
    return false;
}

function confirmDelete(url, parameters, target, forceNewWin)
{
    if(confirm("Are you sure, you want to delete this item?"))
        return followLink(url, parameters, target, forceNewWin);
    else
        return false;
}

function displayIframe(url, id)
{
    var tmpEl = document.createElement('iframe');
    tmpEl.id = id;
    tmpEl.setAttribute("allowTransparency","true");
    tmpEl.src = url;
    tmpEl.style.display = "block";
    tmpEl.style.position = "fixed";
    var sz = getWindowSize();
    tmpEl.style.left = ((sz[0] - 560)/2)+"px";
    tmpEl.style.top = ((sz[1] - 400)/2)+"px";
    tmpEl.style.width = "560px";
    tmpEl.style.height = "400px";
    document.body.appendChild(tmpEl);

    return false;
}
