
//
// Common javascript functions
//

// Used when packing listboxes
var LISTBOX_VALUE_SEP = "|";

function openCenterWin (url, refName, width, height)
{
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 800, yMax=600;
    var xOffset = (xMax - width)/2, yOffset = (yMax - height)/2;

    string='\'toolbar=no,status=no,menubar=no,scrollbars=no,width=' + width +' ,height=' + height +',resizable=1,screenX='+xOffset+',screenY='+yOffset+', top='+yOffset+',left='+xOffset+'\'';

    window.open (url, refName, string);
}
function getCookie( name ) {
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
        return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ';', len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires ) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name+'='+escape( value ) +
        ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
        ( ( path ) ? ';path=' + path : '' ) +
        ( ( domain ) ? ';domain=' + domain : '' ) +
        ( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
    if ( getCookie( name ) ) document.cookie = name + '=' +
            ( ( path ) ? ';path=' + path : '') +
            ( ( domain ) ? ';domain=' + domain : '' ) +
            ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}


function getForm(formName)
{
    return ( eval("document."+formName) );
}

// Packs all checkboxes on a form to a form-field
// for later processing.
// @param formName, name of form containing the form-field
// @param field, name of form-field that should be filled with checkbox info.
function packCheckBoxes(formName, field)
{
    var f = getForm(formName);
    var field = eval("document."+formName+"."+field);
    var theCheckbox = "";

    for (var i=0; i<f.elements.length; i++)
    {
        if ((f.elements[i].type == 'checkbox'))
        {
            var cb = f.elements[i];
            var name = cb.name;
            if ( cb.checked )
              theCheckbox = name + "=true";
            else
              theCheckbox = name + "=false";

            if ( field.value == "" )
                field.value = theCheckbox;
            else
                field.value += LISTBOX_VALUE_SEP + theCheckbox;

        }
    }
}

