
 /**
  * Default JavaScript file
  *
  * @version $Id: default.js,v 1.1 2004/11/08 17:43:41 stefan Exp $
  */

var MonthMap = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

// Open Window
function OpenWindow( url, name, width, height )
    {
    var params;
    if (screen.availHeight <= 600)
        params = "width=" + width + ",height=" + height + ",resizable=yes, scrollbars=yes, status=no";
        else
        params = "width=" + width + ",height=" + height + ",resizable=yes, scrollbars=no, status=no";

    win = window.open( url, name, params );
    }

// Open Scrollable Window
function OpenScrollableWindow( url, name, width, height )
    {
    var params = "width=" + width + ",height=" + height + ",resizable=1, scrollbars=1, status=0";

    win = window.open( url, name, params );
    }

//Swap image functions.
function preloadImages()
    {
    var d = document;
    if(d.images)
        {
        if(!d.MM_p) d.MM_p=new Array();

        var i, j = d.MM_p.length, a = preloadImages.arguments;

        for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0)
                {
                d.MM_p[j]=new Image;
                d.MM_p[j++].src=a[i];
                }
        }
    }

function swapImgRestore()
    {
    var i, x , a = document.MM_sr;

    for(i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
    }

function findObj(n, d)
    {
    var p,i,x;

    if(!d) d = document;
    if((p = n.indexOf("?")) > 0 && parent.frames.length)
        {
        d=parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
        }
    if(!(x = d[n]) && d.all) x = d.all[n];
    for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];

    for(i = 0; !x && d.layers && i < d.layers.length; i++) x = findObj(n, d.layers[i].document);

    return x;
    }

function swapImage()
    {
    var i, j = 0, x, a = swapImage.arguments;

    document.MM_sr = new Array;

    for(i = 0; i < (a.length-2); i += 3)
        if ((x = findObj(a[i])) != null)
            {
            document.MM_sr[j++] = x;
            if(!x.oSrc) x.oSrc = x.src;
            x.src = a[i+2];
            }
    }


function isUndefined(v)
    {
    return typeof(v) == 'undefined';
    }

function isDefined(v)
    {
	return typeof(v) != 'undefined';
    }

function fillTemplate(template)
    {
	var result = template;
	for (var i = 1; i< arguments.length; i+= 2)
	    {
		var name = arguments[i];
		var rexp = new RegExp('\\$\\{' + name + '\\}', 'g');
		var value = arguments[i + 1];
		result = result.replace(rexp, value);
	    }

	return result;
    }

function toggleOpen(modelSource)
    {
	var openFlagName = modelSource + '_open';
	var open = eval(openFlagName);
	if (open == undefined) open = false;
	eval(openFlagName + '=' + !open);
    }

function refreshElement(id)
    {
	var elm = document.getElementById(id);
	if (elm)
	    {
		var widget = ElementWidgetMap[id];
		if (widget)
		    {
			widget.updateModel();
			elm.innerHTML = widget.render();
		    }
	    }
    }

function isAllCharsEmpty(s)
    {
	for (var i = 0; i < s.length; i++)
	    {
		if (s.charCodeAt(i) > 32) return false;
	    }

	return true;
    }

function isEmpty(s)
    {
	return isUndefined(s) || s == null || s.length == 0 || isAllCharsEmpty(s);
    }

function processEmpty(s)
    {
	return isEmpty(s) ? '' : s;
    }

function nbsp(s)
    {
	return isEmpty(s) ? '&nbsp;' : s;
    }

function addStaticContentPrefix(rest)
    {
	if (isDefined(staticContentPrefix) && staticContentPrefix != null)
		return staticContentPrefix + rest;
	    else
		throw "global variable staticContentPrefix undefined or null";
    }

function renderWidgetWrapper(widget)
    {
	return fillTemplate(Template.widgetWrapperElement, 'elementId', widget.elementId, 'content', widget.render() );
    }

function getToday()
    {
	var today = new Date();

	return today.getDate() + '/' + MonthMap[today.getMonth()] + '/' + today.getFullYear();
    }

function changeCss(theClass, element, value)
    {
	var cssRules;
	if (document.all) cssRules = 'rules';
	    else if (document.getElementById) cssRules = 'cssRules';

    for (var S = 0; S < document.styleSheets.length; S++)
	    {
	    for (var R = 0; R < document.styleSheets[S][cssRules].length; R++)
	        {
	        if (document.styleSheets[S][cssRules][R].selectorText == theClass) document.styleSheets[S][cssRules][R].style[element] = value;
	        }
	    }
    }

//----------------------------------------------------------------------------------------------------------------------
/**
 * Create progress bar control.
 * ex: createProgressBar(300,15,'white',1,'black','blue',85,7);
 */
var progressbars = new Array();

function createProgressBar(w, h, bgc, brdW, brdC, blkC, speed, blocks)
    {
    var w3c=(document.getElementById) ? true : false;
    var ie=(document.all) ? true : false;
    var N=-1;


    if(ie||w3c)
        {
        var t='<div style="position:relative; overflow:hidden; width:'+w+'px; height:'+h+'px; background-color:'+bgc+'; border-color:'+brdC+'; border-width:'+brdW+'px; border-style:solid; font-size:1px;">';
        t+='<span id="blocks'+(++N)+'" style="left:-'+(h*2+1)+'px; position:absolute; font-size:1px">';

        for(i=0;i<blocks;i++)
            {
            t+='<span style="background-color:'+blkC+'; left:-'+((h*i)+i)+'px; font-size:1px; position:absolute; width:'+h+'px; height:'+h+'px; '
            t+=(ie)?'filter:alpha(opacity='+(100-i*(100/blocks))+')':'-Moz-opacity:'+((100-i*(100/blocks))/100);
            t+='"></span>';
            }

        t+='</span></div>';

        document.write(t);
        var bA=(ie)?document.all['blocks'+N]:document.getElementById('blocks'+N);

        bA.blocks=blocks;
        bA.w=w;
        bA.h=h;
        progressbars[progressbars.length]=bA;
        setInterval('startProgressBar(' + N + ')',speed);
        }
    }

function startProgressBar(bn, bars)
    {
    var t=progressbars[bn];
    t.style.left=((parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w)? -(t.h*2+1) : parseInt(t.style.left)+t.h+1)+'px';
    }
