/**
    @author Matthias Oberthür
    Email: matthias.oberthuer@gmx.de
    Online: www.oberthuer-online.de
    first created: 03.05.2001
    last changed: 30.10.2002
    Unless otherwise stated, any code contained on my homepage is
    freely usable so long as a disclaimer such as the one below appears in
    the code:
    
    **************************************************
    This code uses techniques found at
    oberthuer-online - http://www.oberthuer-online.de
    **************************************************
    
    Aim: utilities
    Content:    set the timeout for objects with an animation
                set the steps for an object with an animation
                produce a random number
                netscape resize fix
*/

// set a new timeout for objects which have a timeout
function increaseTimeout(obj,timeout)
{
    if(typeof(obj)== "string") eval(obj + ".timeout += timeout");
    else obj.timeout += timeout;
}

function decreaseTimeout(obj,timeout)
{
    if(typeof(obj)== "string") {
        if(eval(obj + ".timeout - timeout >= 0")) eval(obj + ".timeout -= timeout");
    }
    else {
        if(obj.timeout - timeout >= 0) obj.timeout -= timeout;
    }
}

// set new steps for objects which have an animation
function increaseSteps(obj,xsteps,ysteps)
{
    if(typeof(obj)== "string") {
        eval(obj + ".xSteps += (" + obj + ".xSteps > 0)? xsteps : -xsteps");
        eval(obj + ".ySteps += (" + obj + ".ySteps > 0)? ysteps : -ysteps");
    }
    else {
        obj.xSteps += (obj.xSteps > 0)? xsteps : -xsteps;
        obj.ySteps += (obj.ySteps > 0)? ysteps : -ysteps;
    }
}

function decreaseSteps(obj,xsteps,ysteps)
{
    if(typeof(obj)== "string") {
        eval(obj + ".xSteps -= (" + obj + ".xSteps > 0)? xsteps : -xsteps");
        eval(obj + ".ySteps -= (" + obj + ".ySteps > 0)? ysteps : -ysteps");
    }
    else {
        obj.xSteps -= (obj.xSteps > 0)? xsteps : -xsteps;
        obj.ySteps -= (obj.ySteps > 0)? ysteps : -ysteps;
    }
}

// Randomizer
var randomNumber;
var m = 233280;
var a = 9301;
var c = 49297;
var seed = 1;

function randomizer(maxValue,minValue)
{
    var minVal = (minValue)? minValue : 0;
    seed = new Date();
    seed = seed.getTime();
    randomNumber = (seed * a + c) % m;
    randomNumber = randomNumber/m;
    randomNumber = Math.round(maxValue * randomNumber) + minVal;
    return randomNumber;
}

// Netscape 4.x doesn't reload the page properly if you resize the window
// Here is the fix
if (document.layers) {
	window.onResize = resizeFix;
}

function resizeFix()
{
    if(parent.content.winWidth != window.innerWidth || parent.content.winHeight != window.innerHeight){
		document.location.href = document.location.href;
	}
}

function jumpMenu(form, menu, target)
{
    if(target == "_blank") window.open(document.forms[form].menu[document.forms[form].menu.selectedIndex].value,'');
    else self.location.href = document.forms[form].menu[document.forms[form].menu.selectedIndex].value;
}

function popup(name,url,width,height,scrollbar,resizable) {
    var w = (width)? width : 550;
    var h = (height)? height : 500;
    var scrolling = (scrollbar)? scrollbar : "no";
    var res = (resizable)? resizable : "yes";
    var flags = "fullscreen=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + scrolling + ",resizable="+ res +",copyhistory=no,width="+w+",height="+h+",left=0,top=0,screenX=0,screenY=0";
    var myWin = open(url,name,flags);
}

function changeDropDown(formName,target,values,arName) {
    var tmp_array = (arName)? eval(arName) : eval(values);
    document.forms[formName].elements[target].options.length = (arName)? tmp_array[values].length / 2 : tmp_array.length;
    with(document.forms[formName].elements[target]) {
        if(arName) {
            for(var i=0,j=0; i<tmp_array[values].length; j++,i+=2) {
                options[j] = new Option(tmp_array[values][i]);
                options[j].value = tmp_array[values][i+1];
            }
        }
        else {
            for(var i=0; i<tmp_array.length; i++) {
                options[i] = new Option(tmp_array[i]);
                options[i].value = tmp_array[i];
            }
        }
    }
}



function changeImage(name,suffix)
{
    if(document.images) {
        var pathToImage = document.images[name].src;
        pathToImage = pathToImage.substr(0,pathToImage.indexOf(name));
        document.images[name].src = pathToImage + name + suffix;
    }
}

var ns, ns4, ns6, mozilla, ie, ie4, ie5, op, mac, bill, linux;
function browserCheck() {
	var browser = navigator.appVersion
    var name = navigator.appName
    var userAgent = navigator.userAgent

	ns4 = (browser.substr(0,1) == 4 && name == "Netscape")? true : false
	ns6 = (browser.substr(0,1) == 5 && !ie)? true : false
    ns = (ns4 || ns6)? true : false
    mozilla = (ns6 && userAgent.indexOf("Netscape6") == -1)? true : false

    ie = (document.all)? true : false
	ie4 = (browser.indexOf("MSIE 4") > 0)? true : false
	ie5 = (browser.indexOf("MSIE 5") > 0)? true : false

    op = (userAgent.indexOf("Opera") > -1)? true : false
    if(ns && op) {
        op = true
        ns4 = false
        ns6 = true
    }
    // platform check
    bill = (browser.indexOf("Windows") >= 0)? true : false
    mac = (browser.indexOf("Mac") >= 0)? true : false
    linux = (browser.indexOf("Linux") >= 0 || browser.indexOf("X11") >= 0)? true : false
    return
}

function findWidthHeight() {
    winWidth = (ie && !op)? (ie4)? document.body.clientWidth : document.body.scrollWidth-20 : window.innerWidth;
    winHeight = (ie && !op)? (ie4)? document.body.clientHeight : document.body.scrollHeight-20 : null;
    return;
}

