// Main browser detection routine
function BrowserDetect() {
    var ua = navigator.userAgent.toLowerCase(); 
    this.ua = ua;
    this.isIE = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ); 
    this.versionMinor = parseFloat(navigator.appVersion); 
    if (this.isIE && this.versionMinor >= 4) this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
    this.versionMajor = parseInt(this.versionMinor); 
    this.isWin32 = ((ua.indexOf('win') != -1) && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1) );
    this.isIE55 = (this.isIE && this.versionMinor == 5.5);
    this.isIE6up = (this.isIE && this.versionMajor >= 6); 
}

// If running IE5.5+ on win32, then display 
// PNGs with AlphaImageLoader
var browser = new BrowserDetect();
var pngAlpha = false;
if ((browser.isIE55 || browser.isIE6up) && browser.isWin32)
    pngAlpha = true;

// Sets object's background
function setObjBackground (id, png_img) {    
    obj = document.getElementById(id).style;
    if (pngAlpha) {
        obj.backgroundImage = '';
        obj.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + png_img + "', sizingMethod='scale')";
    } else {
        obj.backgroundImage = 'url(' + png_img + ')';
    }
}

// Outputs the image as a DIV with the AlphaImageLoader, or with
// a standard IMG image tag
function displayImage(strId, strPath, intWidth, intHeight, strClass, strAlt) {   
    if (pngAlpha)
        document.write('<div style="cursor:pointer;display:block;height:'+intHeight+'px;width:'+intWidth+'px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+strPath+'\', sizingMethod=\'scale\')" id="'+strId+'" class="'+strClass+'" title="'+strAlt+'"><img src="/pict/1x1.gif" width="'+intWidth+'" height="'+intHeight+'" alt="'+strAlt+'" class=sp></div>');
    else
        document.write('<img src="'+strPath+'" width="'+intWidth+'" height="'+intHeight+'" id="'+strId+'" name="'+strId+'" border="0" class="'+strClass+'" alt="'+strAlt+'" />');
}

// Reverses given string
function strrev(st) {

    var s = "";
    var i = st.length;

    while (i > 0) {
        s += st.substring(i-1,i);
        i--;
    }

    return s;

}

// Creates new image object from the URL
function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

// Roll-over & roll-out functions with opacity support
function rollOver(image, alpha, closemenus) {
    if ((preloadFlag == true) && (document.images)) {
        var img_on = eval(image + "_on").src;

        if (pngAlpha && (alpha == "yes")) {
            document.getElementById(image).style.filter = '';
            document.getElementById(image).style.backgroundImage = 'url(' + img_on + ')';
        } else {
            document.getElementById(image).src = img_on;
        }
        
        // Now close menus if required
        if (closemenus == "yes")
            DropOutMenu.closeOthers('menu_inexistant');
    }
}

function rollOut(image, alpha, closemenus) {
    if ((preloadFlag == true) && (document.images)) {
        var img_off = eval(image + "_off").src;

        if (pngAlpha && (alpha == "yes")) {
            document.getElementById(image).style.filter = '';
            setObjBackground (image, img_off);
        } else {
            document.getElementById(image).src = img_off;
        }
        
        // Now close menus if required
        if (closemenus == "yes")
            DropOutMenu.closeOthers('menu_inexistant');
    }
}

DropOutMenu.Registry = []
DropOutMenu.hideDelay = 1000

// constructor
function DropOutMenu(id, dir, left, top, width, height) {
    this.ie  = document.all ? 1 : 0
    this.ns4 = document.layers ? 1 : 0
    this.dom = document.getElementById ? 1 : 0

    if (this.ie || this.ns4 || this.dom) {
        this.id          = id
        this.dir         = dir
        this.orientation = dir == "left" || dir == "right" ? "h" : "v"
        this.dirType     = dir == "right" || dir == "down" ? "-" : "+"
        this.dim         = this.orientation == "h" ? width : height
        this.hideTimer   = false
        this.open        = false
        this.over        = false

        // global reference to this object
        this.gRef = "DropOutMenu_"+id
        eval(this.gRef+"=this")

        // add this menu object to an internal list of all menus
        DropOutMenu.Registry[id] = this

        var d = document

        var strCSS = '<style type="text/css">';
        strCSS += '#' + this.id + '_container { visibility:hidden; '
        strCSS += 'left:' + left + 'px; '
        strCSS += 'top:' + top + 'px; '
        strCSS += 'overflow:hidden; z-index:10000; }'
        strCSS += '#' + this.id + '_container, #' + this.id + '_content { position:absolute; '
        strCSS += 'width:' + width + 'px; '
        strCSS += 'height:' + height + 'px; '
        strCSS += 'clip:rect(0 ' + width + ' ' + height + ' 0); '
        strCSS += '}'
        strCSS += '</style>';

        d.write(strCSS)

        this.load()
    }
}
DropOutMenu.prototype.load = function() {
    var d = document
    var lyrId1 = this.id + "_container"
    var lyrId2 = this.id + "_content"
    var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
    if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
    var temp

    if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
    else {
        this.container  = obj1
        this.menu       = obj2
        this.style      = this.ns4 ? this.menu : this.menu.style
        this.homePos    = eval("0" + this.dirType + this.dim)
        this.outPos     = 0

        // set event handlers.
        if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
        this.menu.onmouseover = new Function("DropOutMenu.showMenu('" + this.id + "')")
        this.menu.onmouseout = new Function("DropOutMenu.hideMenu('" + this.id + "')")

        //set initial state
        this.endSlide()
    }
}
DropOutMenu.closeOthers = function (id) {
    for (menu in DropOutMenu.Registry) 
        if (id != menu) DropOutMenu.hide(menu);
}
DropOutMenu.showMenu = function(id) {
    var reg = DropOutMenu.Registry
    var obj = DropOutMenu.Registry[id]
    
    if (obj.container) {
        obj.over = true

        // close other menus
        DropOutMenu.closeOthers (id);

        // if this menu is scheduled to close, cancel it.
        if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }

        // if this menu is closed, open it.
        if (!obj.open) reg[id].startSlide(true)
    }
}
DropOutMenu.hideMenu = function(id) {
    // schedules the menu to close after <hideDelay> ms, which
    // gives the user time to cancel the action if they accidentally moused out
    var obj = DropOutMenu.Registry[id]
    if (obj.container) {
        if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
        obj.hideTimer = window.setTimeout("DropOutMenu.hide('" + id + "')", DropOutMenu.hideDelay);
    }
}
DropOutMenu.hide = function(id) {
    var obj = DropOutMenu.Registry[id]
    obj.over = false

    if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
    
    // flag that this scheduled event has occured.
    obj.hideTimer = 0

    // if this menu is open, close it.
    if (obj.open) obj.startSlide(false)
}
DropOutMenu.prototype.startSlide = function(open) {
    this[open ? "onactivate" : "ondeactivate"]()
    this.open = open
    if (open) this.setVisibility(true)
    this.endSlide()
}
DropOutMenu.prototype.endSlide = function() {
    this.moveTo(this.open ? this.outPos : this.homePos)
    if (!this.open) this.setVisibility(false)
    if ((this.open && !this.over) || (!this.open && this.over)) {
        this.startSlide(this.over)
    }
}
DropOutMenu.prototype.setVisibility = function(bShow) { 
    var s = this.ns4 ? this.container : this.container.style
    s.visibility = bShow ? "visible" : "hidden"
}
DropOutMenu.prototype.moveTo = function(p) { 
    this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"
}
DropOutMenu.prototype.getPos = function(c) {
    return parseInt(this.style[c])
}

// events
DropOutMenu.prototype.onactivate     = function() { }
DropOutMenu.prototype.ondeactivate   = function() { }

function chk_msg() {
    var sa  = msgform.action.split("?");
    var s   = sa[0];
    var hd  = cd77t2d(msgform.hshs.value);
    var h   = utf8d2t(hd);
    var ha  = h.split(" + ");
    var act = sa[0] + "?" + "sh" + "sd" + "=" + strrev(ha[1]);
    msgform.action = act;
}

function utf8d2t(d) {
        var r=new Array; var i=0;
        while(i<d.length) {
            if (d[i]<128) { r[r.length]= String.fromCharCode(d[i]); i++;}
            else if((d[i]>191) && (d[i]<224)) { r[r.length]= String.fromCharCode(((d[i]&31)<<6) | (d[i+1]&63)); i+=2;}
            else { r[r.length]= String.fromCharCode(((d[i]&15)<<12) | ((d[i+1]&63)<<6) | (d[i+2]&63)); i+=3;}
        }
        return r.join("");
}

function cd77arrays() {
    var cd77s='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; cd77 = new Array();bd77 =new Array();
    for (var i=0; i<cd77s.length ;i++) { cd77[i] = cd77s.charAt(i); bd77[cd77s.charAt(i)] = i; }
}
cd77arrays();

function cd77t2d(t) {
        var d=new Array; var i=0; t=t.replace(/\n|\r/g,""); t=t.replace(/=/g,"");
        while (i<t.length) {
            d[d.length] = (bd77[t.charAt(i)]<<2) | (bd77[t.charAt(i+1)]>>4);
            d[d.length] = (((bd77[t.charAt(i+1)]&15)<<4) | (bd77[t.charAt(i+2)]>>2));
            d[d.length] = (((bd77[t.charAt(i+2)]&3)<<6) | (bd77[t.charAt(i+3)]));
        i+=4; }
        if (t.length%4 == 2)d = d.slice(0, d.length-2); if (t.length%4 == 3)d = d.slice(0, d.length-1);
        return d;
}