var T = new Array();

function reset() { // reset screen widgets
    for (var t in T) {
        clearTimeout(t);
    }
}

addLoadEvent(function() {
        startMenu("mainMenu");
        startMenu("serviceMenu");
        startMenu("legalese");
        startMenu("index");
        }
    )
    
//--------------------------------------------------------------##

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


//--------------------------------------------------------------##


function displayBlockz(o, tag) {
    var p = o.parentNode;
    var navList = p.getElementsByTagName(tag);
    if (navList) {
        var L;
        var S = o.id.slice(0,-1);
        for (var i=0; i<navList.length; i++) {
            L=  navList[i].id.slice(0,-1);
            if (L != S) shideDisplay(L, 'none');
        }
        shideDisplay(S, 'block');
    }
}

function shideDisplay(elemID, state) { // create / destroy display blocks
    var LmNt = document.getElementById?document.getElementById(elemID):document.all?document.all(elemID):"";
    if ( LmNt ) {
        if ( state == 'toggle') {
             if (LmNt.style.display != 'block') {LmNt.style.display = 'block'}
             else LmNt.style.display = 'none';
        } else
            if (LmNt.style.display != state) LmNt.style.display = state ;
        }
}


//--------------------------------------------------------------##


function startMenu ( menuName ) {
    if (document.getElementById || document.all) {
        var navRoot = false;
        navRoot = document.getElementById?document.getElementById(menuName):document.all?document.all(menuName):"false";
        if (navRoot) {
            navRoot.onmouseover=ieHover;
            navRoot.onmouseout=ieOut;
    //      navRoot.onclick=function() { getLocation( this.getElementsByTagName('A')[0].getAttribute('href') ) };
            if (navRoot) {
                var navList = navRoot.getElementsByTagName("LI");
                var node = "";
                for (var i=0; i<navList.length; i++) {
                    node = navList[i];
                    node.onmouseover= ieHover;
                    node.onmouseout= ieOut
                    node.onclick = getLocation;
                }
            }
        }
    }
}

function startSubMenu (id) {
    var navRoot = document.getElementById?document.getElementById(id):document.all?document.all(id):"";
    if (navRoot) {
        var navList = navRoot.getElementsByTagName("LI");
        var node;
        for (var i=0; i< navList.length; i++) {
            node = navList[i];
            node.onmouseover=ieHover;
            node.onmouseout=ieOut;
            node.onclick = function() { displayBlockz( this, "LI"); return false }
            shideDisplay(node.id.slice(0,-1), "none");
        }
        shideDisplay(navList[0].id.slice(0,-1), "block");
    }
}

function startLang ( language ) {
    if (document.getElementById || document.all) {
        var navRoot = false;
        navRoot = document.getElementById?document.getElementById(language):document.all?document.all(language):"false";
        if (navRoot) {
            navRoot.onmouseover=ieHover;
            navRoot.onmouseout=ieOut;
    //      navRoot.onclick=function() { getLocation( this.getElementsByTagName('A')[0].getAttribute('href') ) };
            if (navRoot) {
                var navList = navRoot.getElementsByTagName("LI");
                var node = "";
                for (var i=0; i<navList.length; i++) {
                    node = navList[i];
                    node.onmouseover= ieHover;
                    node.onmouseout= ieOut
                    node.onclick = getLanguage;
                }
                var navList = navRoot.getElementsByTagName("A");
                var node = "";
                for (var i=0; i<navList.length; i++) {
                    node = navList[i];
                    node.onclick = getLanguage;
                }
            }
        }
    }
}


function startPNGs () {
    var png = /png$/i;
    var imageCache = document.images;
    for ( var i = 0;i < imageCache.length; i++ ) {
        if ( imageCache[i].src.match(png) ) {
            pngSrc = imageCache[i].src;
            width = imageCache[i].width;
            height = imageCache[i].height;
            imageCache[i].src = blankPix.src;
            imageCache[i].height = height;
            imageCache[i].parentNode.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+pngSrc+"', sizingMethod='scale')"
        }
    }
}

function getLanguage (e) {
    if (!e) var e = window.event;
    var re = RegExp("^(http://)?([^:/]+)?(/en|/mt|/)/*(.*)?$");
    var n = (window.event) ? e.srcElement : e.target;
    var l = n.href ? n.href : n.getElementsByTagName('A')[0].href;
    l = re.exec(l);
    var h = document.location.href;
    var x = re.exec(h);
    var y = x[1]+x[2]+l[3]+"/"+x[4];
    document.location.href = y;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    return false;
}
function getLocation (e) {
    if (!e) var e = window.event;
    var n = (window.event) ? e.srcElement : e.target;
    if ( n.getElementsByTagName('A') > 0 ) {
    	var loco = false; loco = n.getElementsByTagName('A')[0].href;
    	alert ('esta loco: '+loco);
    	if (loco) {
			document.location.href = loco;
			} else { alert ('no loco: '+loco);}
        }
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}

function ieHover (e) { // replace hover in ie
    if (!e) {
        var n = window.event.srcElement;
        n.className = "over";
    }
}
function ieOut (e) { // replace hover in ie
    if (!e) {
        var n = window.event.srcElement;
        n.className = "";
    }
}
