//****************************************************************************
// $Id: sitemgr.js 1583 2006-04-24 17:26:13Z nmapp $
//****************************************************************************
//****************************************************************************
// StartApp
//****************************************************************************
function StartApp(width,height,percent,url,win_name,bg_url)
{
    if (width == 0 && height == 0)
    {
        width=screen.width * (percent / 100);
        height=screen.height * (percent / 100);
    }
                                                                                                    
    window.open(url, win_name, "resizable=yes,toolbar=yes,width="+width+",height="+height, true);
   // window.location = bg_url;
}
//****************************************************************************
// CheckPassword(form,optional run mode)
//****************************************************************************
function CheckPassword(submitter,run_mode)
{
    // Check to see if the password was left blank.
    if (submitter.password.value == '')
    {
        alert("You left your new password field blank. Please try again.");
        return(false);
    }
    // Check to see if the validation password was left blank.
    if (submitter.vpassword.value == '')
    {
        alert("You did not enter the password a second time. Please try again.");
        return(false);
    }
    // Validate that both passwords match.
    if (submitter.password.value != submitter.vpassword.value)
    {
        alert("Your passwords do not match. Please try again.");
        return(false);
    }

    if (run_mode != '')
    {
        SubmitMode(submitter,run_mode); 
    }
    else
    {
        return true;
    }
}
//****************************************************************************
function Delete(url,object,delete_confirm_message,cannot_delete_message)
{
    if(cannot_delete_message != '')
    {
        alert(cannot_delete_message);
    }
    else
    {
        var msg = "";
        if ( delete_confirm_message != '' ) 
        {
            msg += delete_confirm_message;
        }
        else
        {
            msg += 'Are you sure you want to delete this '+ object + '?';
        }

        if (confirm(msg)) 
        {
            document.location=url;
        }
    }
}

//****************************************************************************
// TreeToggle(form, run mode)
//****************************************************************************
function TreeToggle(item)
{
    obj=document.getElementById(item);
    try{
        visible=(obj.style.display!="none")
    }catch(er)
    {
        UnSetCookieData(item);
        return false;
    }
    key=document.getElementById("x" + item);
    if(visible)
    {
        obj.style.display="none";
        key.innerHTML="<img src='/sitemgr/images/folder.gif'  width='16' height='16' hspace='0' vspace='0' border='0'>";
        UnSetCookieData(item);
    }
    else
    {
        obj.style.display="block";
        key.innerHTML="<img src='/sitemgr/images/textfolder.gif'  width='16' height='16' hspace='0' vspace='0' border='0'>";
        SetCookieData(item);
    }
}

function ReloadTree()
{
    var cookieName = parent.cookie_name;
    var cookieData = GetCookie(cookieName);
    if(cookieData == null)
    {
        return true;
    }
    else
    {
        var id_list = cookieData.split(",");
        while(array_element = id_list.pop())
        {
            if(array_element == null) continue;
            TreeToggle(array_element);
        }
    }
}

function UnSetCookieData(item)
{
    var cookieName = parent.cookie_name;
    var cookieData = GetCookie(cookieName);
    var id_list;
    if(cookieData == null)
    {
        id_list = new Array();
    }
    else
    {
        id_list = cookieData.split(",");
    }
    var array_element = '';
    var tmp_array = new Array();
    var i = 0;
    var alen = id_list.length;
    while(array_element = id_list.pop())
    {
        if(array_element == null) continue;
        if(array_element == item) continue;
        tmp_array.push(array_element);
    }

    var ids = tmp_array.join();
    DeleteCookie(cookieName);
    document.cookie = cookieName + "=" + ids + "; PATH = /";
}

function SetCookieData(item)
{
    UnSetCookieData(item);
    var cookieName = parent.cookie_name;
    var cookieData = GetCookie(cookieName);
    var id_list;
    if(cookieData == null)
    {
        id_list = new Array();
    }
    else
    {
        id_list = cookieData.split(",");
    }
    id_list.push(item);
    var ids = id_list.join();

    DeleteCookie(cookieName);
    document.cookie = cookieName + "=" + ids + "; PATH = /";
}

function GetCookie (name) 
{  
    var arg = name + "=";  
    var alen = arg.length;  
    var clen = document.cookie.length;  
    var i = 0;  
    while (i < clen) 
    {    
        var offset = i + alen;    
        if (document.cookie.substring(i, offset) == arg)
        {
            var endstr = document.cookie.indexOf (";", offset);  
            if (endstr == -1)
            {
                endstr = document.cookie.length;  
            }
            return unescape(document.cookie.substring(offset, endstr));
        }
        i = document.cookie.indexOf(" ", i) + 1;    
        if (i == 0) break;   
    }  
    return null;
}

function DeleteCookie (name) {  
    var exp = new Date();  
    exp.setTime (exp.getTime() - 1);  
    var cval = GetCookie (name);  
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
//****************************************************************************
function RefreshConfigMgrTree()
{
    if (parent.configmgr_tree && parent.frames[parent.configmgr_tree])
    {
        parent.frames[parent.configmgr_tree].location.reload(true);
    }
    return true;
}

function checkWord()
{
    var word = document.DictionaryForm.word;
    
    if(word.value.search(/[\^\s\`\~\!\@\#\%\^\&\*\(\)\_\=\+\\\|\]\[\}\{\"\;\:\?\/\>\<]/) >= 0)
    {
        alert("Words can not contain no spaces or special characters beside hyphen: (eg. \" \"_~!@#$%^&*()+=\\/<>{}[])");
        return false;
    }
    return true;
}
//****************************************************************************
function openWindow(options) {
    var parts = options.split('|');
    /*
    0 - url
    1 - window_prefix (e.g. run mode or some other alpha window name)
    2 - unique_id (e.g. story_id)
    3 - unique_flag (1 or 0 to specify if window name needs to include the unique id)
    4 - height
    5 - width
    */
    var url = parts[0];
    var window_name = '';
    var win_opts = _window_options(parts[5],parts[4]);
    if (parts[3] == 1) {
        window_name = parts[1] + "_" + parts[2];
    } else {
        window_name = parts[1];
    }
    popup_win = window.open(url, window_name, win_opts)
    if (popup_win.opener == null) {
        popup_win.opener = self;
    }
}
//****************************************************************************
