﻿function $(id) { return document.getElementById(id); }

function showError(message) {
    showMessage(message, "CSM Autobase Error");
}
function showMessage(message, title) {
    if (top.radalert) {
        top.radalert(message, null, null, title);
    }
    else {
        top.alert(message);
    }
}
function showConfirmation(message) {
    showMessage(message, "CSM Autobase Confirmation");
}
function isVisible(element) {
    return (element.style.visibility == "visible");
}

function toggleElement(element) {
    if (isVisible(element))
        displayElement(element, false);
    else
        displayElement(element, true);
}

function hideElement(element) {
    displayElement(element, false)
}

function displayElement(element, show)
{
    if (show) {
        element.style.visibility = "visible";
        element.style.display = "";
    }
    else {
        element.style.visibility = "hidden";
        element.style.display = "none";
    }
}
function displayElementById(id, show) {
    var element = $(id);
    displayElement(element, show);
}
function toggleElementById(id) {
    var element = $(id);
    toggleElement(element);
}
//this is called to open up a link in separate tab. it should be used within a <a> tab:
//Sample:
// <a href="www.xyz.com" onclick="return onClickA(this);">xyz</a>
//
//two functions are created to avoid the typos
function onClickA(obj) { return onclickA(obj); }
function onclickA(obj) {
    try {
        if (obj.href)
            top.openUrlInNewTab(obj.innerHTML, obj.href);
    }
    catch (err) {
        //ignore
    }
    return false;
}
function onClickAWithTitle(obj, title) { onclickAWithTitle(obj, title); }
function onclickAWithTitle(obj, title) {
    try {
        if (obj.href)
            top.openUrlInNewTab(title + obj.innerHTML, obj.href);
    }
    catch (err) {
        //ignore
    }
    return false;
}
function getPageById(pageId) {
    var wnd;
    if (top.window) wnd = top.window;
    else wnd = window;
    
    var i;
    for (i = 0; i < wnd.frames.length; i++) {
        var frm = wnd.frames[i];
        if (frm.pageId && frm.pageId == pageId) {
            return frm;
        }
    }
}

function getRadWindow() {
    try {
        var oWnd = null;
        if (window.radWindow) oWnd = window.radWindow; //Will work in Mozilla in all cases, including classic dialog
        else if (window.frameElement && window.frameElement.radWindow) oWnd = window.frameElement.radWindow; //IE (and Mozilla)
        return oWnd;
    }
    catch (error) {
    }
}

function openRadWindow(url, windowid, width, height) {
    var oWnd = getRadWindow();
    var rWnd = null;
    if (oWnd == null) {
        rWnd = radopen(url, windowid);
        if (rWnd == null)
            rWnd = top.radopen(url, windowid);
    }
    else {
        rWnd = oWnd.BrowserWnd.radopen(url, windowid);
    }
    if (rWnd != null) {
        rWnd.setSize(width, height);
        rWnd.set_status('');
    }
    return rWnd;
}

function getBrowserWidth() {
    if (window.innerWidth) {
        return window.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientWidth != 0) {
        return document.documentElement.clientWidth;
    }
    else if (document.body) {
        return document.body.clientWidth;
    }
    return 0;
}

function getBrowserHeight() {
    if (window.innerHeight) {
        return window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight != 0) {
        return document.documentElement.clientHeight;
    }
    else if (document.body) {
        return document.body.clientHeight;
    }
    return 0;
}

