var win = window
var doc= document
if (doc.getElementsByTagName ){addEv(win, 'load', init)}
function init(){
	var cl = null;var showbnr = false;var showpr = false;var showstudy = false;var p = '<p></p>';var showbord = false;
	var cms = doc.getElementById("edit");
	if (cms){showbnr = true;showpr = true;showstudy = true;showbnr=true};
	//apply box class to style side paneldivs only if they have content
	 if( !doc.divs )
	{doc.divs = doc.getElementsByTagName("div");}
	for (var ti=0;ti<doc.divs.length;ti++) {
		var div = doc.divs[ti];
			if (div.getAttribute("class") != null ) {cl = div.getAttribute("class")}
			if (div.getAttribute("className") != null ) {cl = div.getAttribute("className")}
			if (cl != null ) {
				if (cl == 'study'){
					
					if (div.firstChild.firstChild){
						
					if (div.firstChild.firstChild.innerHTML){
					var pnl = div.firstChild.firstChild.innerHTML.toLowerCase();
					pnl = replace(pnl ,'\n','');
					pnl = replace(pnl ,'\r','');
					pnl = replace(pnl ,'\t','');
					
					if (pnl != p && pnl.length != 0){showstudy = true;}
					 }}
				if (showstudy){ div.className = 'panel';}
				}
				showstudy = false;
			
			if (cl == 'pr'){
				//apply promo class to promo box only if it has content;
				if (div.firstChild.firstChild.innerHTML){
					var pr = div.innerHTML.toLowerCase();
				pr = stripBreaks(pr);
				if (pr != p && pr.length!= 0){showpr = true;}
				}
				if (showpr){ div.className= 'promo';}
			}
			}
		cl = 'null'}
	
	//apply banner class to page banner div only if it has content
	var bnr = doc.getElementById("banner");
	if (bnr) {
		if (bnr.firstChild.firstChild.firstChild.innerHTML){
		var bnrc = bnr.firstChild.firstChild.firstChild.innerHTML.toLowerCase();
		bnrc = stripBreaks(bnrc);
		if (bnrc != p && bnrc.length != 0){showbnr = true;}
		}
	if (showbnr){ bnr.className = "banner prbanner" ;}}
	
	
	//apply top border to  sectionlist items in main-section pages only if they have content
	doc.h = doc.getElementsByTagName("h3");
	for (var i=0;i<doc.h.length;i++) {
	if (doc.h[i].getAttribute("class")!= null ) {cl = doc.h[i].getAttribute("class")}
	if (doc.h[i].getAttribute("className")!= null ) {cl = doc.h[i].getAttribute("className")}
	if ( cl=="section"){
		if (doc.h[i].innerHTML){
		hc = doc.h[i].innerHTML;
		hc = stripBreaks(hc);
		if (hc.length !=0){
				if(!doc.h[i].parentNode.getAttribute("class")) {showbord = true;}
				if (document.all && !window.opera){showbord=false;
					if(doc.h[i].parentNode.getAttribute("className") != "first" ) {showbord = true;}
				}}
				if (showbord) doc.h[i].parentNode.className = "border";
			}
		}
	cl = null;showbord=false}

	//hide field labels in staff profiles if the field is not used, unless in CMS edit view
	
	doc.dt = doc.getElementsByTagName("dt");//alert (doc.dt.length);
	for (var i=0;i<doc.dt.length;i++) {
		if (doc.dt[i].getAttribute("class")!= null ) {cl = doc.dt[i].getAttribute("class")}
		if (doc.dt[i].getAttribute("className")!= null ) {cl = doc.dt[i].getAttribute("className")}
		
		if (cl == 'section'){
				if (!doc.dt[i].nextSibling.innerHTML && !cms){
					doc.dt[i].style.display = 'none';
				}else{
					//allow for browsers that conserve whitespace
					var ddStr = stripBreaks(doc.dt[i].nextSibling.innerHTML);
					if (ddStr.length == 0){doc.dt[i].style.display = 'none';}
				}
			}
	}
	
	
}
function addEv(obj, evType, fn){
if(win.addEventListener){obj.addEventListener(evType, fn, false)
}else{if (obj.attachEvent){obj.attachEvent("on"+evType, fn)}}}

function replace(string,text,by) {
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) return string;
var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;
var newstr = string.substring(0,i) + by;
if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength),text,by);
return newstr;
}

function stripBreaks(text){
	var str  =replace(text ,'\n','');
	str = replace(str ,'\r','');
	return str;
}