/*
 * @(#) xtd.js  1.0 02/10/04
 *
 * Copyright 2002 Orgdot AS. All Rights Reserved.
 * http://www.orgdot.com/javaopensource
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */


/**
 * Javascript utilities that should work on both old and new browsers
 *
 * @author      Olaf Havnes
 * @version     1.0, 10/04/02
 * @since       SWFIT1.0
 */

/**
 * Preload an image
 */
function preloadImage(url)
{
    im = new Image();
    im.src = url;
    return im;
}

/**
 * Preload an array of images
 */
function preloadImages (urls)
{
    ims = new Array();
    if (document.images != null) for (i = 0; i < urls.length; i++)
    {
        ims [i] = new Array();
        for (j = 0; j < urls[i].length; j++) ims[i][j] = preloadImage (urls[i][j]);
    }
    return ims;
}

/**
 * Swap images using the preloaded array
 */
function flipIm(i, j)
{
    if
    (
        document.images &&
        ims.length >= i &&
        ims[i].length >= j &&
        eval ("document.images.im_" + i) != null
    )
    eval ("document.images.im_" + i + ".src=ims[" + i + "][" + j + "].src");
    return true;
}
/**
 * Pop a variety of windows
 */
function winPop ( url, width, height, xpos, ypos, toolbar, scrollbar, resizable, name )
{
    wspec = "width="  + width  + ",";
    hspec = "height=" + height + ",";
    xspec = "screenX=" + xpos + ",left=" + xpos + ",";
    yspec = "screenY=" + ypos + ",top="  + ypos + ",";

    toolspec   = (toolbar)   ? "toolbar=yes,"    : "toolbar=no,";
    scrollspec = (scrollbar) ? "scrollbars=yes," : "scrollbars=no,";
    resizspec  = (resizable) ? "resizable=yes,"  : "resizable=no,";

    specs  = wspec + hspec + xspec + yspec;
    specs += toolspec + scrollspec + resizspec;
    specs += "status=no,titlebar=no,directories=no";

    popper = window.open(url,name,specs);
    if (window.focus) popper.focus();
}


function winPopThin ( url, width, height )
{
    winPop ( url, width, height, 100, 100, false, false, false, "miniwin" );
}

function winPopFat ( url, width, height )
{
    winPop ( url, width, height, 100, 100, true, true, true, "workwin" );
}
/**
 * Flash 4 code
 */
function flash4Code (mov_src, mov_wdt, mov_hgt, mov_col)
{
        code_ = '<object \n';
        code_ += '  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" \n';
        code_ += '  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"\n';
        code_ += '  width="' + mov_wdt + '" height="' + mov_hgt + '">\n';
        code_ += '  <param name="movie" value="' + mov_src + '">\n';
        code_ += '  <param name="quality" value="best">\n';
        code_ += '  <param name="menu" value="false">\n';
        code_ += '  <param name="align" value="lt">\n';
        code_ += '  <param name="scale" value="exactfit" \n';
        code_ += '  <param name="bgcolor" value="' + mov_col + '">\n';
        code_ += '<embed \n';
        code_ += '  src="' + mov_src + '" \n';
        code_ += '  quality="best" scale="exactfit" salign="lt" menu="false" \n';
        code_ += '  bgcolor=' + mov_col + ' \n';
        code_ += '  width="' + mov_wdt + '" \n';
        code_ += '  height="' + mov_hgt + '" \n';
        code_ += '  type="application/x-shockwave-flash" \n';
        code_ += '  pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash">\n';
        code_ += '</embed></object>';
        return code_;
}
/**
 * URL-encode
 */
function urlEncVar (str)
{
        return str + "=" + escape (eval (str)) + "&";
}

