// Set of scripts to make everything work right on IE<7

// This script makes sure IE displays <hr> stylings properly
function styleHR(){
	var aDivs = document.getElementsByTagName('hr');
	for (var i=0; i<aDivs.length; i++) {
			var hrDiv = document.createElement("div");
			hrDiv.className = "hrDiv";
			hrDiv.innerHTML = "&nbsp;";
			//bottomDiv.appendChild(bottomSpan);
						
			aDivs[i].parentNode.insertBefore(hrDiv,aDivs[i]);
			aDivs[i].style.display = "none";
	}
}

// Universal transparent-PNG enabler for MSIE/Win 5.5+
// http://dsandler.org
// From original code: http://www.youngpup.net/?request=/snippets/sleight.xml
// and background-image code: http://www.allinthehead.com/retro/69
// Very slightly modified by Ryan Huber, VMC Communications Web Team
// also:
//  * use sizingMethod=crop to avoid scaling PNGs (who would do such a thing?)
//  * only do this once, to make it compatible with CSS rollovers
function enableAlphaImages(objid){
	if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
		var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
		var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7.0);
		if (itsAllGood) {
			/*
			for (var i=0; i<document.all.length; i++){
				)
				var obj = document.all[i];
				*/
			if(document.getElementById(objid)){;
				var obj = document.getElementById(objid);
				var bg = obj.currentStyle.backgroundImage;
				var img = document.images[i];
				if (bg && bg.match(/\.png/i) != null) {
					var img = bg.substring(5,bg.length-2);
					var offset = obj.style["background-position"];
					obj.style.filter =
					"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='crop')";
					obj.style.backgroundImage = "url(http://www.vanderbilthealth.com/images/spacer.gif)";
					obj.style["background-position"] = offset; // reapply
				} else if (img && img.src.match(/\.png$/i) != null) {
					var src = img.src;
					img.style.width = img.width + "px";
					img.style.height = img.height + "px";
					img.style.filter =
					"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='crop')"
					img.src = "http://www.vanderbilthealth.com/images/spacer.gif";
				}
			} 
		}
	}
}

/* 	Here we have some functions necessary to make IE behave properly with
	focus, active, and hover pseudoclasses.  Courtesy htmldog.com, "Suckerfish Shoals".
*/
function fixIEPseudoClasses() {
	
		if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
		var buttontags = document.getElementsByTagName("button");
		for (var k=0; k<buttontags.length; k++) {
			buttontags[k].onmouseover=function(){
				this.className += ' iehover';
				/*this.hideFocus=true;*/
			}
			buttontags[k].onmouseout=function(){
				/*this.blur();*/
				this.className = this.className.replace(/\biehover\b/,'');
			}
			buttontags[k].onmousedown=function(){
				this.className += "ieactive";
				/*this.hideFocus=true;*/
			}
			buttontags[k].onmouseup=function(){
				/*this.blur();*/
				this.className = this.className.replace(/\bieactive\b/,'');
			}


		}
		//used to change select menu styles when activated
		var selecttags = document.getElementsByTagName("select");
		for (var k=0; k<selecttags.length; k++) {
			selecttags[k].attachEvent('onkeydown', expandSelectMenu);
			selecttags[k].attachEvent('onactivate', expandSelectMenu);
			selecttags[k].attachEvent('ondeactivate', collapseSelectMenu);
			/*selecttags[k].attachEvent ('onfocus', selectFirstMenu);*/
			/*selecttags[k].attachEvent ('onactivate', selectFirstMenu);*/
			
			
			selecttags[k].style.position="absolute";
			
			//select wrapper
			/*
			selecttags[k].parentNode.style.position="relative";
			// form
			selecttags[k].parentNode.parentNode.style.position="relative";
			//innermodule
			selecttags[k].parentNode.parentNode.parentNode.style.position="relative";
			//module
			selecttags[k].parentNode.parentNode.parentNode.parentNode.style.position="inline";
			//column
			selecttags[k].parentNode.parentNode.parentNode.parentNode.parentNode.style.position="inline";
			//column
			selecttags[k].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.position="inline";
			// maincontent
			selecttags[k].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.position="inline";
			//layoutarea
			selecttags[k].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.position="inline";
			*/
			
		}
	}
}

function expandSelectMenu(){
	
	selectMenu = event.srcElement;
	
	selectMenu.className="ieactive";
	selectMenu.size=10;
	if(selectMenu.options.length<10){
		selectMenu.size=event.srcElement.options.length;
	}
	
	var ieMat = document.createElement('iframe');
	ieMat.id = "ieMatId";
	ieMat.style.width=selectMenu.offsetWidth+"px";
	ieMat.style.height=selectMenu.offsetHeight+"px";	
	selectMenu.parentNode.insertBefore(ieMat,selectMenu);
	
	ieMat.style.zIndex="50";
	selectMenu.style.zIndex="51";
	selectMenu.parentNode.style.zIndex="49";
	selectMenu.parentNode.parentNode.style.zIndex="48";
	selectMenu.parentNode.parentNode.parentNode.style.zIndex="47";
	selectMenu.parentNode.parentNode.parentNode.parentNode.style.zIndex="46";
	selectMenu.parentNode.parentNode.parentNode.parentNode.parentNode.style.zIndex="45";
	selectMenu.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.zIndex="44";


	ieMat.style.position="absolute";
	selectMenu.parentNode.parentNode.parentNode.parentNode.style.marginLeft="9px";
	selectMenu.parentNode.parentNode.parentNode.parentNode.style.marginLeft="10px";
	
	/*
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var ie6 = (rslt != null && Number(rslt[1]) < 7.0);
	if(ie6){
		selectMenu.attachEvent('onpropertychange', collapseSelectMenu);
	} else {
		*/
		selectMenu.attachEvent('ondblclick', collapseSelectMenu);	
	//}
	/*selectMenu.attachEvent('onpropertychange', collapseSelectMenu);*/

	/*
	
	for(j=0;j<selectMenu.options.length;j++){
		selectMenu.options[j].onhover = function(){
			selectMenu.options[j].selected = true;
		}
		selectMenu.options[j].onclick = function(){
			selectMenu.options[j].selected = true;
			collapseSelectMenu();
		}
	}
	
	*/
	
}
function collapseSelectMenu(){
	
	
	//if(event.srcElement.selectedIndex>0){
	//	alert( "getting "  + event.srcElement.selectedIndex );
	//}	
	
	
	/*event.srcElement.detachEvent('onpropertychange', collapseSelectMenu);*/
	
	event.srcElement.className="";
	event.srcElement.size=1;
	event.srcElement.parentNode.style.zIndex="0";
	event.srcElement.parentNode.parentNode.style.zIndex="0";
	event.srcElement.parentNode.parentNode.parentNode.style.zIndex="0";
	event.srcElement.parentNode.parentNode.parentNode.parentNode.style.zIndex="0";
	event.srcElement.parentNode.parentNode.parentNode.parentNode.parentNode.style.zIndex="0";
	event.srcElement.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.zIndex="0";
	if(document.getElementById("ieMatID")){
		event.srcElement.parentNode.removeChild(document.getElementById("ieMatID"));
	}

	selectFirstMenu();
	selectMenu.parentNode.parentNode.parentNode.parentNode.style.marginLeft="9px";
	selectMenu.parentNode.parentNode.parentNode.parentNode.style.marginLeft="10px";
	
	
	
	
	/* need to reset these
	selecttags[k].attachEvent ('onbeforeactivate', expandSelectMenu);
	selecttags[k].attachEvent ('ondeactivate', collapseSelectMenu);
	selecttags[k].attachEvent ('onactivate', selectFirstMenu);
	*/
	
}
function selectFirstMenu(){
	
	if(event.srcElement.selectedIndex<0){
		event.srcElement.options[0].selected=true;
	}	
	
}