//
// Copyright 2004-2005 by Pixta, Inc.,
// 926A Diablo Ave., No. 542, Novato, CA 94947 U.S.A.
// All rights reserved.
//
// This software is the confidential and proprietary information
// of Pixta, Inc.
//
// util.js 
//
// General-purpose, useful Javascript routines
//
// Notes:
//

// Return the first index of 'val' in 'array', or -1 if it is not there
function arr_index(array, val)
{
    len = array.length;
    for (i = 0; i < len; i++)
    {
        if (array[i] == val)
            return i;
    }
    
    // nada
    return -1;
}    

// Return true if 'val' is in 'array', false otherwise
function arr_contains(array, val)
{
    index = arr_index(array, val);
        
    return (index >= 0) ? true : false;
}

// Select or deselect the given value in the given list of options
function setOption(options, val, state)
{
    len = options.length;
    for (i = 0; i < len; i++)
    {
        if (options[i].value == val)
        {
            options[i].selected = state;
            break;
        }
    }
}    

// escape() and unescape() are deprecated as of Javascript v1.5, but 
// encodeURI()/encodeURIComponent() and decodeURI()/decodeURIComponent()
// don't arrive on the scene until v1.5, either.
// In particular, IE < 5.5 does not support JS v1.5.
// Gotta love web development.
//
// _JSVersion is set in the <script> tag immediately before this 
// file is included.
//
function encodeString(str)
{
    if (_JSVersion < 1.5)
        return escape(str);
    else
        return encodeURIComponent(str);    
}

function decodeString(str)
{
    if (_JSVersion < 1.5)
        return unescape(str);
    else
        return decodeURIComponent(str);    
}
