var mbW=250;
var mbO=[],mbP=[],mbA,mbT,mbTf;

function mbSet(m,c) {
if (document.getElementById&&document.createElement) {
	var m=document.getElementById(m);
	m.className=c;
	var e,f,i,j;

	var e=m.firstChild;
	while (e) {
		if (e.tagName=='LI') {
			var div=document.createElement('div');
			while (e.firstChild) {
				div.appendChild(e.firstChild);
			}
			e.appendChild(div);
		}
		e=e.nextSibling;
	}

	e=m.getElementsByTagName('a');
	if (!mbTf) mbTf=new Function('mbHAT();');
	for (i=0;i<e.length;i++) {
		e[i].onmouseout=e[i].onblur=mbTf;
	}

	m=m.getElementsByTagName('ul');
	for (i=0;i<m.length;i++) {
		if (j=m[i].id) {
			mbO[j]=m[i];
			e=m[i].parentNode;
			f=e.parentNode.getAttribute('id');
			if (mbO[f]) {
				mbP[j]=f;
			}
			f=new Function('mbS(\''+j+'\');');
			e=e.getElementsByTagName('a');
			for (c=0;c<e.length;c++) {
				e[c].onmouseover=e[c].onfocus=f;
			}
			mbH(j);
		}
	}
}}

function mbHA() {
	if (mbA) {
		while (mbA) mbH(mbA);
		mbHE('visible');
	}
}

function mbHAT() {
	if (!mbT) mbT=setTimeout('mbHA();', mbW);
}

function mbTC() {
	if (mbT) {
		clearTimeout(mbT);
		mbT=null;
	}
}

function mbS(m) {
	mbTC();
	if (mbA) while (mbA&&m!=mbA&&mbP[m]!=mbA) mbH(mbA);
	else mbHE('hidden');

	mbSH(m,'visible');
	mbA=m;
}

function mbH(m) {
	if (m==mbA) mbA=mbP[m];
	mbSH(m,'hidden');
	mbT=null;
}

function mbSH(m,v) {
	mbO[m].parentNode.firstChild.className=v;
	mbO[m].style.visibility=v;
}

function mbHE(v) {
	//mbHEV(v,document.getElementsByTagName('select'));
}

function mbHEV(v,e) {
	for (var i=0;i<e.length;i++) e[i].style.visibility=v;
}

var headerSearchDefaultText = 'Site Search ...';

function upfrontInit()
{
    upfront_installCascadingMenu('nav');
    upfront_installHeaderSearch('navmeta-search');
    upfront_installMetaAgentLocator('meta-agent-locator');
    upfront_installFooterRelocator('frm-footer-nav');
}

function upfront_installCascadingMenu(navId)
{
    if (document.getElementById(navId))
        mbSet(navId, 'mb');
}

function upfront_installHeaderSearch(frmId)
{
    frm = document.getElementById(frmId);
    if (!frm)
        return;

    inputs = frm.getElementsByTagName('input');
    elt = null;
    for (i = 0; i < inputs.length; i++) {
        if (inputs[i].type == 'text') {
            elt = inputs[i];
            break;
        }
    }
    if (!elt)
        return;

    frm.qElt = elt;
    elt.defaultText = headerSearchDefaultText;

    elt.onfocus = function()
    {
        if (this.value == this.defaultText)
            this.value = '';
    }

    elt.onblur = function()
    {
        if (this.value.length == 0)
            this.value = this.defaultText;
    }

    frm.onsubmit = function()
    {
        this.qElt.onfocus();
    }

    elt.onblur();
}

function upfront_installMetaAgentLocator(frmId)
{
    frm = document.getElementById(frmId);
    if (!frm)
        return;

    inputs = frm.getElementsByTagName('input');
    selects = frm.getElementsByTagName('select');

    newWidth = 0;
    for (i = 0; i < inputs.length; i++) {
        if (inputs[i].type == 'text') {
            newWidth = inputs[i].offsetWidth;
        }
    }

    if (newWidth > 0) {
        for (i = 0; i < selects.length; i++) {
            selects[i].style.width = newWidth + 'px';
        }
        for (i = 0; i < inputs.length; i++) {
            if (inputs[i].type == 'submit') {
                inputs[i].style.width = newWidth + 'px';
            }
        }
    }
}

function upfront_installFooterRelocator(frmId)
{
    frm = document.getElementById(frmId);
    if (!frm)
        return;

    frm.url.onchange = function(e)
    {
        if (this.value.length == 0)
            return;

        document.location = this.value;
    }
}
