<!--

// ALL FUNCTIONS ARE COPYRIGHT CSW GMBH !!!
// Copyright auf allen Funktionen liegt bei CSW GmbH !!!
// Sie sind NICHT berechtigt, diese Funktionen auf Ihren Webseiten zu benutzen !!!

function SwapImage() {
    args_images_SI = SwapImage.arguments;

    document[args_images_SI[1]].src = args_images_SI[0];
}

function hideLayer(layer_name) {
    if(document.getElementById(layer_name)) {
        document.getElementById(layer_name).style.visibility = "hidden";
    }
}

function showLayer(layer_name) {
    if(document.getElementById(layer_name)) {
        document.getElementById(layer_name).style.visibility = "visible";
    }
}

function div_mv(div, x, y, z, img, w, h) {
    document.all[div].style.left = x+'px';
    document.all[div].style.top  = y+'px';
    document.all[div].style.zIndex = z;
    document.images[img].width   = w;
    document.images[img].height  = h;
}

function div_x(div) {
    xx = document.all[div].style.left;
    x = Number(xx.substring(0,xx.length-2));
    return x;
}

function div_y(div) {
    yy = document.all[div].style.top;
    y = Number(yy.substring(0,yy.length-2));
    return y;
}

function Point(x,y)
{
    this.x = x;
    this.y = y;
    return this;
}

function get_mouse_xy() {
    MouseX = event.clientX + document.body.scrollLeft;
    MouseY = event.clientY + document.body.scrollTop;
}

function philosophie_onLoad() {

    document.onmousemove = get_mouse_xy;
    MouseX = 0;
    MouseY = 0;

    kreis = Math.PI * 2;
    eingrad = kreis / 360;

    dwinkel = eingrad * 1; //winkelgeschwindigkeit

    ofs_x  = 430; //475; //Kreismittelpunkt
    ofs_y  = 410;
    radius = 260; //300;
    neigung = Math.cos(eingrad * 122); //0 = hochkant, 90 = platt in der Horizontalen

    //name des div, name des image, winkeloffset, aktwinkel (initial=0)
    team = [
            ["div_ms" ,"pic_ms" ,  0,0],
            ["div_pv" ,"pic_pv" , 28,0],
            ["div_ab" ,"pic_ab" , 55,0],
            ["div_kgw","pic_kgw", 83,0],
            ["div_bk" ,"pic_bk" ,111,0],
            ["div_dp" ,"pic_dp" ,138,0],
            ["div_pb" ,"pic_pb" ,166,0],
            ["div_df" ,"pic_df" ,194,0],
            ["div_adm","pic_adm",222,0],
            ["div_sw" ,"pic_sw" ,249,0],
            ["div_vm" ,"pic_vm" ,277,0],
            ["div_bg" ,"pic_bg" ,305,0],
            ["div_kr" ,"pic_kr" ,332,0]
           ];


    for (var i=0; i<team.length; i++) {
        team[i][3] = team[i][2] * eingrad;
    }

    setTimeout("philosophie_mv()", 1);
}

function philosophie_mv() {

    //alert ('team.length='+team.length);

    z_index = 30; //Initialisierung
    z_py    = 1000;

    //MouseX-Position => dwinkel
    maxdx = 380;
    m_dx = ofs_x - MouseX; // - 35;

    if (m_dx > maxdx)
        m_dx = maxdx;
    if (m_dx < (-maxdx))
        m_dx = -maxdx;
    m_dx /= maxdx;

    //MouseY-Position => neigung
    maxdy = 32;
    mindy = -15;
    m_dy = ((ofs_y) - (MouseY*0.9))*0.25;
    if (m_dy > maxdy)
        m_dy = maxdy;
    if (m_dy < mindy)
        m_dy = mindy;

    //Entweder: Neigung berechnen:
    //neigung = Math.cos(eingrad * (90+m_dy));
    //Oder: m_dy fest einstellen
    m_dy = 1;


    for (var i=0; i<team.length; i++) {
        winkel = team[i][3];

        winkel += dwinkel * m_dx;
        if (winkel >= kreis)
            winkel = 0;
        if (winkel < 0)
            winkel = kreis + winkel;

        team[i][3] = winkel;

        //--------------
        px = radius * Math.sin(winkel);
        py = radius * Math.cos(winkel) * neigung;

        faktor = (Math.cos(winkel) + 1) * 0.5; // max 1
        pw = Math.ceil(140 * faktor); //Original Breite/Höhe des Images
        ph = Math.ceil( 30 * faktor);

        if (m_dy < 0) {
            if (py < z_py)
                z_index -= 1;
            else
                z_index += 1;
        } else {
            if (py < z_py)
                z_index += 1;
            else
                z_index -= 1;
        }

        z_py = py;

        //alert ('faktor='+faktor+' pw='+pw+' ph='+ph);
        div_mv(team[i][0], px+ofs_x, py+ofs_y, z_index, team[i][1], pw, ph);
    }


    setTimeout("philosophie_mv()", 20);
}

function setFocus() {
    var ok = false;
    //alert('document.forms.length = ' + document.forms.length  );
    
    if (document.forms.length > 0) {
        var form1 = document.forms[0];
        var num = form1.elements.length;
        for (var i = 0; i < num; i++) {
            if ( (form1.elements[i].type == "text" || 
                  form1.elements[i].type == "textarea" || 
                  form1.elements[i].type == "password") &&
                 !form1.elements[i].disabled) {
                
                //alert('form1.elements[i].name: ' + form1.elements[i].name);
                try { 
                    form1.elements[i].focus(); ok = true; 
                } 
                catch(e) { }
                break;
            }
        }
    }
    if (!ok) {
        try {
            var elem = document.getElementById('enterSubmit');
            if (elem == null ) {
                var elem = document.getElementsByTagName('div')[0];
            }
            elem.focus();
            ok = true;
            // alert('Element with id=[' + elem.id + '] has the focus.');
        }
        catch(e) { 
          /* ignore */
        }
    }
}

function strtrim(inputString) {
    // Removes leading and trailing spaces from the passed string. Also removes
    // consecutive spaces and replaces it with one space. If something besides
    // a string is passed in (null, custom object, etc.) then return the input.
    if (typeof inputString != "string") { return inputString; }
    var retValue = inputString;
    var ch = retValue.substring(0, 1);
    while (ch == " ") { // Check for spaces at the beginning of the string
       retValue = retValue.substring(1, retValue.length);
       ch = retValue.substring(0, 1);
    }
    ch = retValue.substring(retValue.length-1, retValue.length);
    while (ch == " ") { // Check for spaces at the end of the string
       retValue = retValue.substring(0, retValue.length-1);
       ch = retValue.substring(retValue.length-1, retValue.length);
    }
    while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
       retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
    }
    return retValue; // Return the trimmed string back to the user
} // Ends the "strtrim" function
 

// Funktion strToInt kann noch keine negativen Zahlen!!!
function strToInt(str) {
    var a = 0;
    var code;
    
    str = strtrim(str);
    
    for (var i = 0; i < str.length; i++) {
        code = str.charCodeAt(i);
        if ((code >= 48) && (code <= 57)) {
            a = (a * 10) + (code - 48);
        } else {
            break;
        }
    }
    
    return a;
}


Number.max = function (a,b) {
    return a<b?b:a;
}

Number.min = function (a,b) {
    return a>b?b:a;
}

Math.mod = function(val,mod) {
    if (val < 0) {
        while(val<0) val += mod;
        return val;
    } else {
        return val%mod;
    }
}

window.getInnerWidth = function() {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (document.body.clientWidth) {
        return document.body.clientWidth;
    } else if (document.documentElement.clientWidth) {
        return document.documentElement.clientWidth;
    }
} 

window.getInnerHeight = function() {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (document.body.clientHeight) {
        return document.body.clientHeight;
    } else if (document.documentElement.clientHeight) {
        return document.documentElement.clientHeight;
    }
} 

String.prototype.endsWith = function(str) {
    return (this.length-str.length)==this.lastIndexOf(str);
}

String.prototype.reverse = function() {
    var s = "";
    var i = this.length;
    while (i>0) {
        s += this.substring(i-1,i);
        i--;
    }
    return s;
}

// this trim was suggested by Tobias Hinnerup
String.prototype.trim = function() {
    return(this.replace(/^\s+/,'').replace(/\s+$/,''));
}

String.prototype.toInt = function() {
    var a = new Array();
    for (var i = 0; i < this.length; i++) {
        a[i] = this.charCodeAt(i);
    }
    return a;
}

Array.prototype.intArrayToString = function() {
    var a = new String();
    for (var i = 0; i < this.length; i++) {
        if(typeof this[i] != "number") {
            throw new Error("Array must be all numbers");
        } else if (this[i] < 0) {
            throw new Error("Numbers must be 0 and up");
        }
        a += String.fromCharCode(this[i]);
    }
    return a;    
}

Array.prototype.compareArrays = function(arr) {
    if (this.length != arr.length) return false;
    for (var i = 0; i < arr.length; i++) {
        if (this[i].compareArrays) { //likely nested array
            if (!this[i].compareArrays(arr[i])) return false;
            else continue;
        }
        if (this[i] != arr[i]) return false;
    }
    return true;
}

Array.prototype.map = function(fnc) {
    var a = new Array(this.length);
    for (var i = 0; i < this.length; i++) {
        a[i] = fnc(this[i]);
    }
    return a;
}

Array.prototype.foldr = function(fnc,start) {
    var a = start;
    for (var i = this.length-1; i > -1; i--) {
        a = fnc(this[i],a);
    }
    return a;
}

Array.prototype.foldl = function(fnc,start) {
    var a = start;
    for (var i = 0; i < this.length; i++) {
        a = fnc(this[i],a);
    }
    return a;
}

Array.prototype.exists = function (x) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == x) return true;
    }
    return false;
}

Array.prototype.filter = function(fnc) {
    var a = new Array();
    for (var i = 0; i < this.length; i++) {
        if (fnc(this[i])) {
            a.push(this[i]);
        }
    }
    return a;
}

Array.prototype.random = function() {
    return this[Math.floor((Math.random()*this.length))];
}
//-->

