/*----- this is JavaScript but Emacs treats it like -*- C -*- ----------:äöü:--+
|                                                                              |
|   www.hugwi.ch - Javascript Functions                                        |
|                                                                              |
|    $Archive: /www.hugwi.ch/hugwi.js $
|   $Revision: 49 $
|       $Date: 19.12.01 15:56 $
|     $Author: Etter_k $
|   Copyright: Pesche                                                          |
|                                                                              |
+-----------------------------------------------------------------------------*/

// Notieren, dass der Browser .js-Files lesen kann
isScriptFileRead = true;

// Dieses Flag wird normalerweise vom onLoad-Event gesetzt
var isLoaded = false;

/*----------------------------------------------------------------------------*/
// Browser-Erkennung

// es geht einfacher, wenn wir nur Kleinbuchstaben haben
var agt = navigator.userAgent.toLowerCase();

// Browser Version
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Browser Marke
var is_opera = (agt.indexOf("opera") != -1);
var is_opera4 = ((agt.indexOf("opera 4.0") != -1)
              || (agt.indexOf("opera/4.0") != -1));
var is_nav  = (!is_opera)
           && (agt.indexOf('mozilla') != -1)
           && (agt.indexOf('spoofer') == -1)
           && (agt.indexOf('compatible') == -1);
var is_nav5 = (is_nav && (is_major == 5));
var is_ie   = (agt.indexOf("msie") != -1);
var is_ie5  = (agt.indexOf("msie 5.") != -1);

// Korrekturen der Version
if (is_opera4)
{
    is_minor = parseFloat(agt.substring(agt.indexOf("opera")+6));
    is_major = 4;
}
if (is_ie5)
    is_major = 5;

// JavaScript Version
is_js12 = (is_major >= 4);

// JScript Engine Version
if (is_ie)
{
    if (typeof(ScriptEngineMajorVersion) + "" == "undefined")
        is_engine = 1.0;
    else
    {
        is_engine = ScriptEngineMajorVersion() + 0.0;
        if (typeof(ScriptEngineMinorVersion) + "" != "undefined")
            is_engine += ScriptEngineMinorVersion() / 100;
    }
}
else
    is_engine = 4.04;

// Frames gibt's nur, wenn Style Sheets unterstützt werden (ab 4er-Versionen)
// und das Fenster breit genug ist (wie frage ich das mit IE4 ab?)
var useFrames = (is_major >= 4) && (!is_opera) && (is_ie || (top.innerWidth > 650));
//var useFrames = (is.major >= 4) && (is.ie || (top.innerWidth > 650));
// if ((is.major >= 4) && (is.ie))
// {
//     // Funktioniert erst, wenn das Body-Tag schon existiert (beim
//     // ersten Mal noch nicht...)
//     alert(top.document.body.clientWidth);
// }

// Festlegen, welches Stylesheet wir verwenden wollen
//var useCSS = (is.major >= 4);
// vorläufig Stylesheets nur mit Navigator 4
//var useCSS = (is.major >= 4) && is.nav;
// vorläufig keine Stylesheets; bei den Mitarbeitern muss zuerst der Content-Type
// raus...
var useCSS = false;
var cssLink = (is_ie
               ? '<link rel=StyleSheet href="../../hugwi-ie.css" type="text/css">\n'
               : '<link rel=StyleSheet href="../../hugwi.css" type="text/css">\n' );

/*----------------------------------------------------------------------------*/
function writeFrameset(main,navi,tips,logo)
{
    var withAutoScroll = "news-main,news-main98,news-main99,news-main-quiz,news-main-quiz98,index-any,"
        + "info-main-plan,info-main-acti,info-main-links,people,"
        + "prod-main-ctrl,prod-main-elec,prod-main-meas,prod-main-pc,prod-main-plan,prod-main-eng,"
        + "supp-main-ctrl,supp-main-elec,supp-main-meas,supp-main-pc,supp-main-plan,supp-main-eng,";
    var scroll = "no";
    if ( withAutoScroll.indexOf(main+",") >= 0 )
        scroll = "auto";

    document.writeln('<frameset framespacing="0" border="false" frameborder="0" cols="600,*" onLoad="isFrameLoaded=true;">');
    document.writeln('  <frame name="main" src="'+main+'.html" scrolling='+scroll+' marginwidth="0" marginheight="0">');
    document.writeln('  <frameset framespacing="0" border="false" frameborder="0" rows="171,213,*">');
    document.writeln('    <frame name="navi" target="main" src="'+navi+'.html" scrolling="no" marginwidth="21"');
    document.writeln('    marginheight="16">');
    document.writeln('    <frame name="tips" src="'+tips+'.html" scrolling="no" marginwidth="25" marginheight="4">');
    document.writeln('    <frame name="logo" src="'+logo+'.html" scrolling="no" marginwidth="22" marginheight="3">');
    document.writeln('  </frameset>');
    document.writeln('</frameset>');
}


/*----------------------------------------------------------------------------*/
// aus einem relativen URL einen absoluten URL basteln
function reLocate(newLocRel)
{
    var lastSlash;
    var newLoc;
    var oldLoc;

    // lastIndexOf hat bei Opera 3.21 einen Fehler: das letzte Zeichen wird
    // ignoriert. Deshalb müssen wir ein Dummy-zeichen anhängen...
    oldLoc = location.href + " ";

    // Herausfinden, ob der URL ein Dokument angibt (".htm" irgendwo im URL
    // vorhanden) oder das Default-Dokument bezeichnet
    if (oldLoc.lastIndexOf('.htm') == -1)
    {
        if (oldLoc.charAt(oldLoc.length - 2) == "/")
            lastSlash  = oldLoc.length - 2; // oldLoc hört mit "/ " auf...
        else
            lastSlash  = oldLoc.length - 1; // oldLoc hört ohne "/" auf...
    }
    else
        lastSlash  = oldLoc.lastIndexOf('/');
    newLoc = oldLoc.substring(0,lastSlash) + "/" + newLocRel;

    return newLoc;
}


/*----------------------------------------------------------------------------*/
function writeExplanation(link)
{
    document.write('<body>');
    document.write('Bitte <a href="'+ link  +'">folgen Sie dieser Verknüpfung</a>; ');
    document.write('ihr Browser tut es leider nicht von selbst...<br>');
    document.write('Please <a href="'+ link  +'">follow this link</a>; ');
    document.write('as your browser doesn\'t do it itself.<br>');
    document.write('</body>');
}

/*----------------------------------------------------------------------------*/
function textNavi(bgColor)
{
    var isGerman = (location.href.indexOf("/german/") > 0);
    var langNow = "german";
    var langOther = "english";
    var langOtherName = "English";
    var resizeText = ">>> >>> Bitte vergrössern Sie das Fenster bis etwa hier >>> >>><br>und klicken dann hier";
    if ( ! isGerman )
    {
        langNow = "english";
        langOther = "german";
        langOtherName = "Deutsch";
        resizeText = ">>> >>> please enlarge your window up to here >>> >>><br>and click here";
    }

    // Bei einem 4er-Browser sind wir nur hier, wenn das Fenster zu klein ist
    // Falls ein grösseres Fenster auf dem Bildschirm Platz hätte, melden wir das
    // (vorläufig nur mit Netscape; IE4 macht dann leider kein richtiges reload...
    if ((is_major >= 4) && is_nav && (screen.width >= 800))
    {
        document.write('<table border="0" cellpadding="0" cellspacing="0" bgcolor="#FF0000">\n');
        document.write('  <tr><td><img src="../images/spacer.gif" width="770" height="2"></td></tr>\n');
        document.write('  <tr><td align="right"><a href="index.html">\n');
        document.write('    <font color="#FFFFFF">'+resizeText+'</font>\n');
        document.write('  </a><td><tr>\n');
        document.write('</table>\n');
    }

    document.write('<table border="0" cellpadding="0" cellspacing="0" bgcolor="'+bgColor+'">\n');
    document.write('  <tr>\n');
    document.write('    <td><img src="../images/spacer.gif" width="25" height="11"></td>\n');
    document.write('    <td align="center" width="60" nowrap><font size="2">\n');
    document.write('      <a href="../'+langOther+'/">[ '+langOtherName+' ]</a>\n');
    document.write('    </font></td>\n');
    document.write('    <td align="center" width="60" nowrap><font size="2">\n');
    document.write('      <a href="index-any.html">[ Index ]</a>\n');
    document.write('    </font></td>\n');
    document.write('    <td><img src="../images/spacer.gif" width="25" height="11"></td>\n');
    document.write('    <td align="center" width="260" nowrap><font size="2">\n');
    document.write('      <a href="news-main.html">[ News ]</a>\n');
    document.write('      <a href="prod-main.html">[ Products ]</a>\n');
    document.write('      <a href="supp-main.html">[ Support ]</a>\n');
    document.write('      <a href="info-main.html">[ Info ]</a>\n');
    document.write('    </font></td>\n');
    document.write('    <td><img src="../images/spacer.gif" width="25" height="11"></td>\n');
    document.write('    <td align="center" width="120" nowrap><font size="2">\n');
    document.write('      <a href="../'+langNow+'/">[ Hug-Witschi AG ]</a>\n');
    document.write('    </font></td>\n');
    document.write('  </tr>\n');
    document.write('</table>\n');
}

/*----------------------------------------------------------------------------*/
function header(bgColor)
{
    if ( ! useFrames )
    {
        textNavi(bgColor);
    }
}


/*----------------------------------------------------------------------------*/
function footer(bgColor)
{
    if ( ! useFrames )
    {
        document.write("<br>\n");

        textNavi(bgColor);

        document.write("<hr>\n");
        document.write("<font size=\"1\">\n");
        document.write("<address>&copy; Hug-Witschi AG<br>\n");
        document.write("<a href=\"mailto:info@hugwi.ch\">info@hugwi.ch</a><br>\n");
        document.write("<a href=\"mailto:webmaster@hugwi.ch\">webmaster@hugwi.ch</a>\n");
        document.write("</address>\n");
        document.write("URL dieser Seite: " + document.location + "\n");
        document.write("</font><p>\n");
    }
}

/*----------------------------------------------------------------------------*/
function footerFrame(bgColor)
{
    if ( useFrames )
    {
        // die Breite sollte übereinstimmen mit der in generate.pl
        document.write("<table border='0' cellpadding='0' cellspacing='0'>\n");
        document.write("  <tr>\n");
        document.write("    <td><img src='../images/spacer.gif' width='32' height='68'></td>\n");
        document.write("    <td valign='bottom'><font size='1'>\n");
        document.write("      &copy; Hug-Witschi AG<br>\n");
        document.write("      <a href=\"mailto:info@hugwi.ch\">info@hugwi.ch</a><br>\n");
        document.write("      <a href=\"mailto:webmaster@hugwi.ch\">webmaster@hugwi.ch</a><br>\n");
        document.write("    <br></font></td>\n");
        document.write("  </tr>\n");
        document.write("</table>\n");
    }
}


/*----------------------------------------------------------------------------*/
var srcTopLeft;
var srcTop;
var srcTopRight;
var srcLeft;
var srcRight;
var srcBotLeft;
var srcBot;
var srcBotRight;


/*----------------------------------------------------------------------------*/
function raiseButton(row,col,img)
{
    if (document.images)
    {
        // zuerst mal die Werte Backupen
        srcTopLeft  = eval('self.document.m'+(row-1)+(col-1)+'c.src');
        srcTop      = eval('self.document.m'+(row-1)+(col  )+'d.src');
        srcTopRight = eval('self.document.m'+(row-1)+(col+1)+'e.src');
        srcLeft     = eval('self.document.m'+(row  )+(col-1)+'b.src');
        srcRight    = eval('self.document.m'+(row  )+(col+1)+'f.src');
        srcBotLeft  = eval('self.document.m'+(row+1)+(col-1)+'a.src');
        srcBot      = eval('self.document.m'+(row+1)+(col  )+'h.src');
        srcBotRight = eval('self.document.m'+(row+1)+(col+1)+'g.src');

        // jetzt kommt unsere Farbe
        eval('self.document.m'+(row-1)+(col-1)+'c.src = "../images/'+img+'.gif"');

        eval('self.document.m'+(row-1)+(col  )+'e.src = "../images/'+img+'.gif"');
        eval('self.document.m'+(row-1)+(col  )+'d.src = "../images/'+img+'.gif"');
        eval('self.document.m'+(row-1)+(col  )+'c.src = "../images/'+img+'.gif"');

        eval('self.document.m'+(row-1)+(col+1)+'e.src = "../images/'+img+'.gif"');

        eval('self.document.m'+(row  )+(col-1)+'a.src = "../images/'+img+'.gif"');
        eval('self.document.m'+(row  )+(col-1)+'b.src = "../images/'+img+'.gif"');
        eval('self.document.m'+(row  )+(col-1)+'c.src = "../images/'+img+'.gif"');

        eval('self.document.m'+(row  )+(col+1)+'g.src = "../images/'+img+'.gif"');
        eval('self.document.m'+(row  )+(col+1)+'f.src = "../images/'+img+'.gif"');
        eval('self.document.m'+(row  )+(col+1)+'e.src = "../images/'+img+'.gif"');

        eval('self.document.m'+(row+1)+(col-1)+'a.src = "../images/'+img+'.gif"');

        eval('self.document.m'+(row+1)+(col  )+'g.src = "../images/'+img+'.gif"');
        eval('self.document.m'+(row+1)+(col  )+'h.src = "../images/'+img+'.gif"');
        eval('self.document.m'+(row+1)+(col  )+'a.src = "../images/'+img+'.gif"');

        eval('self.document.m'+(row+1)+(col+1)+'g.src = "../images/'+img+'.gif"');
    }
}

/*----------------------------------------------------------------------------*/
function leaveButton(row,col)
{
    if (document.images)
    {
        // die gebackupten Werte restoren
        eval('self.document.m'+(row-1)+(col-1)+'c.src = srcTopLeft ');

        eval('self.document.m'+(row-1)+(col  )+'e.src = srcTop     ');
        eval('self.document.m'+(row-1)+(col  )+'d.src = srcTop     ');
        eval('self.document.m'+(row-1)+(col  )+'c.src = srcTop     ');

        eval('self.document.m'+(row-1)+(col+1)+'e.src = srcTopRight');

        eval('self.document.m'+(row  )+(col-1)+'a.src = srcLeft    ');
        eval('self.document.m'+(row  )+(col-1)+'b.src = srcLeft    ');
        eval('self.document.m'+(row  )+(col-1)+'c.src = srcLeft    ');

        eval('self.document.m'+(row  )+(col+1)+'g.src = srcRight   ');
        eval('self.document.m'+(row  )+(col+1)+'f.src = srcRight   ');
        eval('self.document.m'+(row  )+(col+1)+'e.src = srcRight   ');

        eval('self.document.m'+(row+1)+(col-1)+'a.src = srcBotLeft ');

        eval('self.document.m'+(row+1)+(col  )+'g.src = srcBot     ');
        eval('self.document.m'+(row+1)+(col  )+'h.src = srcBot     ');
        eval('self.document.m'+(row+1)+(col  )+'a.src = srcBot     ');

        eval('self.document.m'+(row+1)+(col+1)+'g.src = srcBotRight');
    }
}

/*----------------------------------------------------------------------------*/
// Beim Laden einer Seite muss der erste angezeigte Tip "over" heissen
var lastTip = "over";

function showTip(tip)
{
    if (useFrames && top.isFrameLoaded)
    {
        if (is_nav5)
        {
            top.tips.document.getElementById(tip).style.display = 'block';
            top.tips.document.getElementById(lastTip).style.display = 'none';
            lastTip = tip;
        }
        else if (is_nav)
        {
            top.tips.document.layers[lastTip].moveTo(-300, 4);
            top.tips.document.layers[tip].moveTo(25, 4);
            lastTip = tip;
        }
        else if (is_ie)
        {
            // default ist wegen nav5 'none' ist, auf 'sichtbar' (=block) setzen
            top.tips.document.all[tip].style.display = 'block';
            top.tips.document.all[lastTip].style.pixelLeft = -300;
            top.tips.document.all[tip].style.pixelLeft = 25;
            lastTip = tip;
        }
    }
}



/*----------------------------------------------------------------------------*/
// globale Variable, um das Original-Bild zwischenzuspeichern
var srcSwapped;

// mouseOver-/Out-Funktionen
function buttonFocus(imgName,newImageBasename)
{
    // mit Style-Sheets ist images.length == 0, ich weiss (noch) nicht,
    // wohin die Bilder verschwunden sind
    if (document.images && document.images.length > 0)
    {
        var lastSlash;
        var lastDot;
        var newImageURL;

        // zuerst mal das alte Bild backupen
        srcSwapped  = eval('self.document.'+imgName+'.src');

        // den URL des neuen Bildes aus dem alten konstruieren
        lastSlash = srcSwapped.lastIndexOf('/');
        lastDot   = srcSwapped.lastIndexOf('.');
        newImageURL = srcSwapped.substring(0, lastSlash+1)
            + newImageBasename
            + srcSwapped.substring(lastDot);

        // jetzt das neue zeigen
        eval('self.document.'+imgName+'.src = "'+newImageURL+'"');
    }
    else if (document.images)
    {
        // zuerst mal das alte Bild backupen
        srcSwapped  = eval('self.document.layers.'+imgName+'Stripe'
                           +'.layers.'+imgName+'Icon'
                           +'.document.images.'+imgName+'.src');

        // jetzt das neue zeigen
        eval('self.document.layers.'+imgName+'Stripe'
             +'.layers.'+imgName+'Icon'
             +'.document.images.'+imgName+'.src'
             +' = "../images/'+newImageBasename+'.gif"');
    }
}

function buttonRestore(imgName)
{
    if (document.images && document.images.length > 0)
    {
        // wieder das alte Bild zeigen
        eval('self.document.'+imgName+'.src = srcSwapped');
    }
    else if (document.images)
    {
        // wieder das alte Bild zeigen
        eval('self.document.layers.'+imgName+'Stripe'
             +'.layers.'+imgName+'Icon'
             +'.document.images.'+imgName+'.src'
             +' = srcSwapped');
    }
}


/*----------------------------------------------------------------------------*/
function stripeBegin(name,alt,idle,focus)
{
    document.writeln('<table border="0" cellpadding="0" cellspacing="0">');
    document.writeln('  <tr>');
    document.writeln('    <td><img src="../images/spacer.gif" width="24" height="21"></td>');
    document.writeln('    <td><img src="../images/spacer.gif" width="68" height="21"></td>');
    document.writeln('    <td><img src="../images/spacer.gif" width="22" height="21"></td>');
    document.writeln('    <td><img src="../images/spacer.gif" width="440" height="21"></td>');
    document.writeln('    <td><img src="../images/spacer.gif" width="2" height="21"></td>');
    document.writeln('  </tr>');
    document.writeln('  <tr>');
    document.writeln('    <td><img src="../images/spacer.gif" width="24" height="150"></td>');
    document.writeln('    <td valign="top"><a href="#top"');
    document.writeln('        onMouseOver="buttonFocus(\''+name+'\',\''+focus+'\');"');
    document.writeln('        onMouseOut="buttonRestore(\''+name+'\');"');
    document.writeln('        ><img name="'+name+'" alt="'+alt+'"');
    document.writeln('        src="../images/'+idle+'.gif" width="68" height="68" border="0"');
    document.writeln('        ></a></td>');
    document.writeln('    <td><img src="../images/spacer.gif" width="22" height="150"></td>');
//    document.writeln('    <td valign="top"><img src="../images/spacer.gif" width="17" height="17"><br>');
    document.writeln('    <td valign="top" width="440">');
    document.writeln('');
}

function stripeEnd()
{
    document.writeln('      <br><img src="../images/spacer.gif" width="22" height="30">');
    document.writeln('    </td>');
    document.writeln('    <td><img src="../images/spacer.gif" width="2" height="150"></td>');
    document.writeln('  </tr>');
    document.writeln('</table>');
}

// eof


