/*
function traperror(msg,url,line) {
    alert(msg+"\n"+url+"\nLine:"+line); return true;
}
if (document.layers) {
    window.captureEvents(Event.ERROR); window.onError=traperror;
}
*/
function reloadPage() {
    if (innerWidth != origWidth || innerHeight != origHeight) location.reload();
}

if (document.layers) {
    origWidth = innerWidth; origHeight = innerHeight; onresize = reloadPage;
}

var ie4=0, nn4=0, nn6=0;
var themenu, rX, lX, tY, bY, zi = 0;
initmenu();

function initmenu(){
    if(document.all){
        zi=100; ie4=1; document.body.onmousemove=updateIt; }
    if(document.layers){
        zi=100; nn4=1; window.captureEvents(Event.MOUSEMOVE); window.onmousemove=updateIt; }
    if(document.getElementById && !ie4){
        zi=100; nn6=1; document.body.onmousemove=updateIt; }
}

function dropit(e,oIEorNN6s,sOneNN){    // For backward compatibility
    if (zi == 0) initmenu();
    if (ie4) dropmenu1(e,oIEorNN6s);
    if (nn4) dropmenu2(e,eval(sOneNN));
    if (nn6) dropmenu3(e,document.getElementById(oIEorNN6s));
}

function dropmenu(e,so){
    if (zi == 0) initmenu();
    if(ie4) dropmenu1(e,eval(so));
    if(nn4) dropmenu2(e,eval('document.'+so));
    if(nn6) dropmenu3(e,document.getElementById(so));
//  alert(lX+".."+rX+" "+tY+".."+bY);
}

function dropmenu1(e,menu){ // ie4
    if (window.themenu&&themenu.id!=menu.id)
        themenu.style.visibility="hidden";
    themenu=menu;
    themenu.style.left=document.body.scrollLeft+event.clientX-event.offsetX;
    themenu.style.top=document.body.scrollTop+event.clientY-event.offsetY+15;
    lX=themenu.style.posLeft-document.body.scrollLeft;
    rX=lX+themenu.offsetWidth;
    mX=rX-findLivePageWidth();
    if (mX > 0){
        themenu.style.left=themenu.style.posLeft-mX;
        lX-=mX;
        rX-=mX;
    }
    tY=themenu.style.posTop-document.body.scrollTop-20;
    bY=tY+themenu.offsetHeight+32;
    if (themenu.style.visibility!=="visible"){
        themenu.style.visibility="visible";
        themenu.style.zIndex=zi++;
    }
}

function dropmenu2(e,menu){ // nn4
    if (window.themenu&&themenu.id!=menu.id)
        themenu.visibility="hide";
    themenu=menu;
    themenu.left=e.pageX-e.layerX;
    themenu.top=e.pageY-e.layerY+17;
    lX=themenu.left;
    rX=lX+themenu.clip.width;
    mX=rX-findLivePageWidth();
    if (mX > 0){
        themenu.left-=mX;
        lX-=mX;
        rX-=mX;
    }
    tY=themenu.top-25;
    bY=themenu.top+themenu.clip.height+7;
    if (themenu.visibility!="show"){
        themenu.visibility="show";
        themenu.zIndex = zi++;
    }
}

function dropmenu3(e,menu){ // nn6
    if (window.themenu&&themenu.id!=menu.id)
        themenu.style.visibility="hidden";
    themenu=menu;
    themenu.style.left=e.pageX-e.layerX;
    themenu.style.top=e.pageY-e.layerY+17;
    lX=parseInt(themenu.style.left)-document.body.scrollLeft;
    rX=lX+themenu.offsetWidth;
    mX=rX-findLivePageWidth();
    if (mX > 0){
        themenu.style.left=parseInt(themenu.style.left)-mX;
        lX-=mX;
        rX-=mX;
    }
    tY=parseInt(themenu.style.top)-document.body.scrollTop+5;
    bY=tY+themenu.offsetHeight+7;
    if (themenu.style.visibility!="visible"){
        themenu.style.visibility="visible";
        themenu.style.zIndex=zi++;
    }
}

function hidemenu(){
    if(ie4) hidemenu1();
    if(nn4) hidemenu2();
    if(nn6) hidemenu3();
}

function hidemenu1(){
    if(window.themenu)
        themenu.style.visibility="hidden";
}

function hidemenu2(){
    if(typeof(themenu)!="undefined")
        themenu.visibility="hide";
}

function hidemenu3(){
    if (themenu.style.visibility!="hidden")
        themenu.style.visibility="hidden";
}

function updateIt(e){
    var x,y
    if(ie4){
        x=window.event.clientX;
        y=window.event.clientY;
        if(x>rX || x<lX || y>bY+1 || y<tY) hidemenu1();
    }
    if(nn4){
        x=e.pageX;
        y=e.pageY;
        if(x>rX || x<=lX-1 || y>bY || y<tY) hidemenu2();
    }
    if(nn6){
        x=e.clientX;
        y=e.clientY;
        if(x>rX || x<lX || y>bY+1 || y<tY-30) hidemenu3();
    }
}

function findLivePageHeight() {
    if (window.innerHeight) return window.innerHeight;
    if (document.body.clientHeight) return document.body.clientHeight;
    return (null);
}

function findLivePageWidth() {
    if (window.innerWidth) return window.innerWidth;
    if (document.body.clientWidth) return document.body.clientWidth;
    return (null);
}
