userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
//base = 'http://wdg.orcmacro.com/bodyandsoul/new/';
//base = 'http://app1-ws1-test-2.nci.nih.gov/~bodyandsoul/';
base = 'http://bodyandsoul.nih.gov/';
//base = '';

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function findElement(n,ly) {
	if (browserVers < 4)		return document[n];
	var curDoc = ly ? ly.document : document;
	var elem = curDoc[n];
	if (!elem) {
		for (var i=0;i<curDoc.layers.length;i++) {
			elem = findElement(n,curDoc.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		var img;
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			img = null;
			if (document.layers) {
				img = findElement(changeImages.arguments[i],0);
			}
			else {
				img = document.images[changeImages.arguments[i]];
			}
			if (img) {
				img.src = changeImages.arguments[i+1];
			}
		}
	}
}

function preloadImages() {
	var imgdir = '';
	if (document.images) {
		menu_top_01_over = newImage(base + "images/menu_top_01-over.gif");
		menu_top_02_over = newImage(base + "images/menu_top_02-over.gif");
		menu_top_03_over = newImage(base + "images/menu_top_03-over.gif");
		menu_top_04_over = newImage(base + "images/menu_top_04-over.gif");
		menu_top_05_over = newImage(base + "images/menu_top_05-over.gif");
		preloadFlag = true;
	}
}


function getValue(varname) {

	var url = window.location.href;
	var qparts = url.split("?");
	if (qparts.length == 0) { return ""; }
	var query = qparts[1];
	var value = "";
	if (query != null) {
		var vars = query.split("&");

		for (i=0;i<vars.length;i++) {
			var parts = vars[i].split("=");
			if (parts[0] == varname) {
				value = parts[1];
				break;
			}
		}
  
		value = unescape(value);
		value.replace(/\+/g," ");
	}
	return value;

}

function getObj(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	} else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	} else if (document.layers) {
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}

function JumpToUrl(selObj) { 
	eval("this.location='"+selObj.options[selObj.selectedIndex].value+"'");
}

function IncMenu(sub) {
	var imgdir = '';
//	document.write('<p>[[Menu]]</p>');
//	document.write('<a href="index.html">Home</a><br />');
//	document.write('<a href="why.html">Why</a><br />');
//	document.write('<a href="programpillars.html">Pillars</a><br />');
//	document.write('<a href="resources.html">Resources</a><br />');
//	document.write('<p>[[Menu]]</p>');

	document.write('<div style="background: url(\'' + base + 'images/home_menu.gif\') no-repeat; color: #ffffff; width: 640px; height: 51px; padding: 38px 50px 0px 118px;">');
if (sub == 0) {
	document.write('				<a href="' + base + 'what.html" onmouseover="showit(0);"><img name="menu_top_01" src="' + base + 'images/menu_top_01-over.gif" width="126" height="24" ');
	document.write('				hspace="0" vspace="0" border="0" alt=""></a><a href="programpillars.html"');
} else {
	document.write('				<a href="' + base + 'what.html" onmouseover="changeImages(\'menu_top_01\', \'' + base + 'images/menu_top_01-over.gif\'); showit(0); return true;"');
	document.write('				onmouseout="changeImages(\'menu_top_01\', \'' + base + 'images/menu_top_01.gif\'); return true;"');
	document.write('				onmousedown="changeImages(\'menu_top_01\', \'' + base + 'images/menu_top_01-over.gif\'); return true;"');
	document.write('				onmouseup="changeImages(\'menu_top_01\', \'' + base + 'images/menu_top_01-over.gif\'); ');
	document.write('				return true;"><img name="menu_top_01" src="' + base + 'images/menu_top_01.gif" width="126" height="24" ');
	document.write('				hspace="0" vspace="0" border="0" alt=""></a><a href="' + base + 'programpillars.html"');
}
if (sub == 1) {
	document.write('				onmouseover="showit(1);"><img name="menu_top_02" src="' + base + 'images/menu_top_02-over.gif" width="126" height="24" ');
	document.write('				hspace="0" vspace="0" border="0" alt=""></a><a href="' + base + 'resources.html"');
} else {
	document.write('				onmouseover="changeImages(\'menu_top_02\', \'' + base + 'images/menu_top_02-over.gif\'); showit(1); return true;"');
	document.write('				onmouseout="changeImages(\'menu_top_02\', \'' + base + 'images/menu_top_02.gif\'); return true;"');
	document.write('				onmousedown="changeImages(\'menu_top_02\', \'' + base + 'images/menu_top_02-over.gif\'); return true;"');
	document.write('				onmouseup="changeImages(\'menu_top_02\', \'' + base + 'images/menu_top_02-over.gif\'); ');
	document.write('				return true;"><img name="menu_top_02" src="' + base + 'images/menu_top_02.gif" width="126" height="24" ');
	document.write('				hspace="0" vspace="0" border="0" alt=""></a><a href="' + base + 'resources.html"');
}
if (sub == 2) {
	document.write('				onmouseover="showit(2);"><img name="menu_top_03" src="' + base + 'images/menu_top_03-over.gif" width="126" height="24" ');
	document.write('				hspace="0" vspace="0" border="0" alt=""></a><a href="' + base + 'contact.html"');
} else {
	document.write('				onmouseover="changeImages(\'menu_top_03\', \'' + base + 'images/menu_top_03-over.gif\'); showit(2); return true;"');
	document.write('				onmouseout="changeImages(\'menu_top_03\', \'' + base + 'images/menu_top_03.gif\'); return true;"');
	document.write('				onmousedown="changeImages(\'menu_top_03\', \'' + base + 'images/menu_top_03-over.gif\'); return true;"');
	document.write('				onmouseup="changeImages(\'menu_top_03\', \'' + base + 'images/menu_top_03-over.gif\'); ');
	document.write('				return true;"><img name="menu_top_03" src="' + base + 'images/menu_top_03.gif" width="126" height="24" ');
	document.write('				hspace="0" vspace="0" border="0" alt=""></a><a href="' + base + 'contact.html"');
}
if (sub == 3) {
	document.write('				onmouseover="showit(3);"><img name="menu_top_04" src="' + base + 'images/menu_top_04-over.gif" width="126" height="24" ');
	document.write('				hspace="0" vspace="0" border="0" alt=""></a><a href="' + base + 'index.html"');
} else {
	document.write('				onmouseover="changeImages(\'menu_top_04\', \'' + base + 'images/menu_top_04-over.gif\'); showit(3); return true;"');
	document.write('				onmouseout="changeImages(\'menu_top_04\', \'' + base + 'images/menu_top_04.gif\'); return true;"');
	document.write('				onmousedown="changeImages(\'menu_top_04\', \'' + base + 'images/menu_top_04-over.gif\'); return true;"');
	document.write('				onmouseup="changeImages(\'menu_top_04\', \'' + base + 'images/menu_top_04-over.gif\'); ');
	document.write('				return true;"><img name="menu_top_04" src="' + base + 'images/menu_top_04.gif" width="126" height="24" ');
	document.write('				hspace="0" vspace="0" border="0" alt=""></a><a href="'+ base + 'index.html"');
}
if (sub == 4) {
	document.write('				onmouseover="showit(4);"><img name="menu_top_05" src="' + base + 'images/menu_top_05-over.gif" width="126" height="24" ');
	document.write('				hspace="0" vspace="0" border="0" alt=""></a>');
} else {
	document.write('				onmouseover="changeImages(\'menu_top_05\', \'' + base + 'images/menu_top_05-over.gif\'); showit(4); return true;"');
	document.write('				onmouseout="changeImages(\'menu_top_05\', \'' + base + 'images/menu_top_05.gif\'); return true;"');
	document.write('				onmousedown="changeImages(\'menu_top_05\', \'' + base + 'images/menu_top_05-over.gif\'); return true;"');
	document.write('				onmouseup="changeImages(\'menu_top_05\', \'' + base + 'images/menu_top_05-over.gif\'); ');
	document.write('				return true;"><img name="menu_top_05" src="' + base + 'images/menu_top_05.gif" width="126" height="24" ');
	document.write('				hspace="0" vspace="0" border="0" alt=""></a><br />');
}

//	document.write('<!-- Edit the dimensions of the below, plus background color-->');
//	document.write('<ilayer width="600" height="27" name="dep1" bgColor="#ffffff">');
//	document.write('	<layer name="dep2" width="600" height="27">');
//	document.write('	</layer>');
//	document.write('</ilayer>');
	document.write('<div style="position: absolute; top: 0px; left: 0px; width: 115px; height: 90px;"><a href="' + base + 'index.html"<img src="' + base + 'images/spacer.gif" width="115" height="90" border="0"></a></div>');
	document.write('<div style="position: absolute; top: 0px; left: 115px; width: 450px; height: 35px;"><a href="' + base + 'index.html"<img src="' + base + 'images/spacer.gif" width="4540" height="35" border="0"></a></div>');
	document.write('</div>');
	document.write('<div id="describe" style="position: absolute; top: 62px; left: 118px; background-color: #ffffff; width: 600px; height: 16px; margin: 5px 0px 5px 15px;" onmouseover="clear_delayhide()" onmouseout="resetit(event,'+sub+')"></div>');

}

function IncFooter(subf) {
	var imgdir = '';
	document.write('<div style="background: url(\'' + base + 'images/home_footer_bg.gif\') no-repeat; color: #999999; width: 784px; height: 98px; padding: 10px 50px 0px 50px;">');
	document.write('<div style="width: 530px;">');
//	document.write('<a href="' + base + 'sitemap.html" class="grey">Site Map</a> &bull; ');
	document.write('<a href="' + base + 'sitemap.shtml" class="grey">Site Map</a> &bull; ');
	document.write('<a href="http://www3.cancer.gov/accessibility/nci508.htm" class="grey" target="_blank">Accessibility</a> &bull; ');
//	document.write('<a href="' + base + 'accessibility.html" class="grey">Accessibility</a> &bull; ');
//	document.write('<a href="#" class="grey">FAQ</a> &bull; ');
	document.write('<a href="' + base + 'contact.shtml" class="grey">Contact Us</a> &bull; ');
	document.write('<a href="' + base + 'index.shtml" class="grey">Home</a><br />');
	document.write('<a href="http://www.os.dhhs.gov/" class="grey">U.S. Department of Health and Human Services</a> &bull; ');
	document.write('<a href="http://www.nih.gov/" class="grey">National Institute of Health</a> &bull; ');
	document.write('<a href="http://www.cancer.gov/" class="grey">National Cancer Institute</a><br />');
	document.write('</div>');
	document.write('</div>');
}


function resetit(e,drop){
	if (document.all&&!menuobj.contains(e.toElement))
	delayhide=setTimeout("showit("+drop+")",delay_hide)
	else if (document.getElementById&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
	delayhide=setTimeout("showit("+drop+")",delay_hide)
}

function clear_delayhide(){
	if (window.delayhide)
	clearTimeout(delayhide)
}

function contains_ns6(a, b) {
	while (b.parentNode)
	if ((b = b.parentNode) == a)
	return true;
	return false;
}

function showit(which) {
	clear_delayhide()
	thecontent=(which==-1)? "" : submenu[which]
	if (document.getElementById||document.all)
		menuobj.innerHTML=thecontent
	else if (document.layers) {
		menuobj.document.write(thecontent)
		menuobj.document.close()
	}
}

function showSubmenu(obj) {
// submenu_X
	var el = document.getElementById('submenu_0');
	el.style.display = "none";
	var el = document.getElementById('submenu_1');
	el.style.display = "none";
	var el = document.getElementById('submenu_2');
	el.style.display = "none";
	var el = document.getElementById('submenu_3');
	el.style.display = "none";
//
	var temp = 'submenu_' + obj;
	var el = document.getElementById(temp);
	el.style.display = "block";
}
