var timer;
var visible_rightclick = '';

function toggle_class(sobj,state) {
    var obj = document.getElementById(sobj);
    var className = obj.className;
    if (className.indexOf('_') != -1) {
        var aclassName = className.split('_');
        className = aclassName[0] + '_' + state;
    } else {
        className = className + '_' + state;
    }
    obj.className = className;
}

function schedule_hide_popup_menu() {
    timer = setTimeout('hide_popup_menu();',500);
}

function clear_schedule_hide_popup_menu() {
    clearTimeout(timer);
}

function hide_popup_menu() {
    clearTimeout(timer);
    var obj = document.getElementById(visible_rightclick);
    obj.style.visibility = 'hidden';
    visible_rightclick = '';
}

function popup_rightclick(sobj) {
    if (visible_rightclick.length > 0) {
        hide_popup_menu();
    }
    var obj = document.getElementById(sobj);
    obj.filters[0].Apply();
    if (window.frames) {
        if (window.frames.name == 'frmTreeMenu') {
            mouseX = 4;
        }
    }
    var Y = document.body.scrollTop + mouseY;
    obj.style.left = mouseX;
    obj.style.top = Y;
    obj.style.visibility = 'visible';
    visible_rightclick = sobj;
    obj.filters[0].Play();
}

function popupDefaultWindow(URL,Settings) {
    var myPopup = window.open(URL,'_blank',Settings);
    myPopup.opener = self;
    myPopup.focus();
}
function popupCenterWindow(URL,Settings,popW,popH) {

    w = screen.availWidth;
    h = screen.availHeight;

    var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    var myPopup = window.open(URL,'_blank',Settings + ',top=' + topPos + ',left=' + leftPos);
    myPopup.opener = self;
    myPopup.focus();
}
function popupCenterWindowWithName(URL,Settings,popW,popH,Name) {

    w = screen.availWidth;
    h = screen.availHeight;

    var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    var myPopup = window.open(URL,Name,Settings + ',top=' + topPos + ',left=' + leftPos);
    myPopup.opener = self;
    myPopup.focus();
}

function popupCenterWindowOnScreen(URL,Settings,popW,popH) {

    w = screen.width;
    h = screen.height;

    var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    var myPopup = window.open(URL,'_blank',Settings + ',top=' + topPos + ',left=' + leftPos);
    myPopup.opener = self;
    myPopup.focus();
}

function di20(sobj,img) {
    var obj = document.getElementById(sobj);
    obj.src = img;
    return false;
}

function replace(string,text,by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
    var newstr = string.substring(0,i) + by;
    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);
    return newstr;
}


function toggle_tree(sobj,slocation,siconsize) {
    var obj = document.getElementById('Tree' + sobj);
    var objicon = document.getElementById('TreeIcon' + sobj);
    if (obj.style.display == 'block' || obj.style.display == '') {
        obj.style.display = 'none';
        objicon.src = slocation + 'plus_' + siconsize + '.gif';
        if (document.frMain) {
            if (document.frMain.OpenArms) {
                document.frMain.OpenArms.value = replace(document.frMain.OpenArms.value,',' + sobj + ',','');
            }
        }
    } else {
        obj.style.display = 'block';
        objicon.src = slocation + 'minus_' + siconsize + '.gif';
        if (document.frMain) {
            if (document.frMain.OpenArms) {
                document.frMain.OpenArms.value += ',' + sobj + ',';
            }
        }
    }
}

