/*
	Author:				Kathy Gannon
	Date Created		5/11/07
	Project:			B2B Redesign
	Name:				general.js
*/

/****************************************************************
 This section sets the top nav
 The javascript variable, curItem, must be set on the cfm page
*****************************************************************/
	var highLightedItem = 0;
	var chgDisplay = true;
	var hoverOverSub = false;
	
	/*
	This function changes the color of the top menu and swaps out the sub menu
	when the user hovers over the top menu.
	*/
	function changeTopMenu(itemId) {
	 if(itemId == highLightedItem) {return;}
	 if(highLightedItem != 0) {
	   chgDisplay = false;
	   document.getElementById("top"+highLightedItem).className = "display";
	   document.getElementById("tophidden"+highLightedItem).className = "nodisplay";
	   document.getElementById("sec"+highLightedItem).className = "nodisplay";
	 }
	 currentRolloverId = itemId;
	 document.getElementById("top"+itemId).className = "nodisplay";
	 document.getElementById("tophidden"+itemId).className = "display";
	 document.getElementById("sec"+itemId).className = "display";
	 if(curItem != 0) {
	   document.getElementById("sec"+curItem).className = "nodisplay";
	 }
	 highLightedItem = itemId
	}
	function changeSubMenu(itemId1, itemId2) {
	 document.getElementById("sub_"+itemId1+"_"+itemId2).className = "nodisplay";
	 document.getElementById("subhidden_"+itemId1+"_"+itemId2).className = "display";
	}	
	function restoreSubMenu(itemId1, itemId2) {
	 document.getElementById("sub_"+itemId1+"_"+itemId2).className = "display";
	 document.getElementById("subhidden_"+itemId1+"_"+itemId2).className = "nodisplay";
	}	
	function setRolloverStatus(subStatus) {
	 hoverOverSub = subStatus;
	 chgDisplay = false;
	}
	function reSetRolloverStatusWait() {
	 setTimeout('reSetRolloverStatus()', 20);
	}
	function reSetRolloverStatus() {
	    if(chgDisplay && highLightedItem != 0) {
	      restoreTopMenu(highLightedItem);
	    }
	    else {
	    chgDisplay = true;
	    } 
	}
	function checkRolloverStatus(rolloverId) {
	 if(!hoverOverSub) {chgDisplay = true;}
	 setTimeout('restoreTopMenu('+rolloverId+')', 20);
	}
	function checkOrigState(){
	 if(highLightedItem != 0) {
	  restoreTopMenu(highLightedItem);
	 }
	}
	function restoreTopMenu(rolloverId) {
	 if(chgDisplay ) {
	   document.getElementById("tophidden"+rolloverId).className = "nodisplay";
	   document.getElementById("top"+rolloverId).className = "display";
	   document.getElementById("sec"+rolloverId).className = "nodisplay";
	   if(curItem != 0) {
	     document.getElementById("sec"+curItem).className = "display";
	   }
	   highLightedItem = 0;
	 }
	 chgDisplay = true;
	}
/* End of top nav */	

/* Begin open content window */
function popContentWindow(url,w,h) {
	window.open (url, 'Content', 'width=' + w + ',height=' + h + ',toolbar=0,scrollbars=1,statusbar=0,menubar=0,resizable=1');
	} 
function openDocument(modact, more) {
    url = "index.cfm?fuseaction=log&modtype=DMS&modact="+modact;
	if(more) {
	  url = url + "&" + more;
	}
	window.open (url, 'Content', 'scrollbars=1,resizable=1');
	} 
/* End open content window */

/* Begin open video window */
function popVideoWindow(url,w,h,c) {
	window.open (url, 'Video'+c, 'left=200,top=20,width=' + w + ',height=' + h + ',toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1');
	} 
/* End open video window */
function showWebinar (info) {
    url = "index.cfm?fuseaction=modNBG&modtype=hospitalSolutions&modact=viewWebinar&link=" + info;
	window.open(url);
}
/* Begin image swap */
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("##")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/* End image swap */

/* Begin block swap */
var changeItem = true;
var t;

function checkSwapBlock(itemId, imgSwap, divName) {
  clearTimeout(t);
  changeItem = true;
  if(imgSwap) {
    if(divName)
      {t = setTimeout('swapBlock('+itemId+', \''+imgSwap+'\', \''+divName+'\')', 500);}
	else
      {t = setTimeout('swapBlock('+itemId+', \''+imgSwap+'\')', 500);}
  }
  else {
   t = setTimeout('swapBlock('+itemId+')', 500);
  }
}

function swapBlock(itemId, imgSwap, divName) {
  if(changeItem) {
    document.getElementById("bottomOn"+itemId).className = document.getElementById("bottomOn"+itemId).className.replace(/nodisplay/, "display");
    document.getElementById("bottom"+itemId).className = document.getElementById("bottom"+itemId).className.replace(/display/, "nodisplay"); 
    document.getElementById("block"+itemId).className = document.getElementById("block"+itemId).className.replace(/nodisplay/, "display");

    document.getElementById("bottomOn"+curBandItem).className = document.getElementById("bottomOn"+curBandItem).className.replace(/display/, "nodisplay");
    document.getElementById("bottom"+curBandItem).className = document.getElementById("bottom"+curBandItem).className.replace(/nodisplay/, "display"); 
    document.getElementById("block"+curBandItem).className = document.getElementById("block"+curBandItem).className.replace(/display/, "nodisplay");
	
	if(imgSwap) {
      document.getElementById("title"+curBandItem).className = "nodisplay";
      document.getElementById("title"+itemId).className = "display";
	  if(imgSwap == "CPBlockNone") {
	    document.getElementById("blockBG").className = "nodisplay";
	  }
	  if(imgSwap == "IPACBlock2" || imgSwap == "CPBlock") {
	    document.getElementById("blockBG").className = "display";
	  }
	  if(divName)
	   {document.getElementById(divName).className = imgSwap;}
	  else
	   {document.getElementById('topLeftBlock').className = imgSwap;}
	}
    curBandItem = itemId;
    }
}

function resetBlock(itemId) {
  changeItem = false;
}
function clickSwapBlock(itemId, imgSwap, divName) {
  clearTimeout(t);
  changeItem = true;
  if(imgSwap) {
   if(divName) 
     {swapBlock(itemId, imgSwap, divName); }
   else
     {swapBlock(itemId, imgSwap); }
  }
  else {
   swapBlock(itemId);
  }
}
/* End block swap */
/* Miscellaneous */
function closeObject(objName,stname) {
	document.getElementById(objName).className = "nodisplay";
	if (stname != "") {
	document.getElementById(stname).className = document.getElementById(stname).className.replace(/nodisplay/, "display");
	}
}
function toggleBlocks() {
  YearSelect = document.getElementById("SelYear");
  selectYear = YearSelect[YearSelect.selectedIndex].value;
  document.getElementById(curYearSel).className = "nodisplay";
  document.getElementById(selectYear).className = "display";
  curYearSel = selectYear;
}
function toggleReportTypes() {
  typeSelect = document.getElementById("SelType");
  selectType = typeSelect[typeSelect.selectedIndex].value;
  document.getElementById(curTypeSel).className = "nodisplay";
  document.getElementById(selectType).className = "display";
  curTypeSel = selectType;
}
/*
	This function is used to adjust the position of the bottom section
	of the press release page depending on the height of the press release section.
*/
function adjHeight(item) {
 if(!eval("a"+item)) {
    if (document.getElementById(item).clientHeight < 461) {
	  document.getElementById('adj'+item).style.height = eval(461 - 5 - document.getElementById(item).clientHeight) + "px";
	}
	eval("a"+item+" = true");
 }
}
function openWin(modact){
	var loc =  modact;
	window.open(loc,"HealthGrades","scrollbars=yes,resizable=yes");
}

function expandbio(nameon, nameoff) {
	document.getElementById(nameon).className = "display";
	document.getElementById(nameoff).className = "nodisplay";
}

function showgraph(nameon) {
	document.getElementById(nameon).className = "display";
	if(nameon == "conferencecalls") {
	window.scrollBy(0,800);
	}
	else {
	window.scrollBy(0,300);
	}
}

// This is used on the Investor Relations page to toggle between the latest earnings
// releases and the lateste press releases.
var curRelease = "earningsRel";
function switchReleases() {
	if(curRelease == "earningsRel") {
	 document.getElementById("earnRelCurrent").className = "nodisplay";
	 document.getElementById("earningsRel").className = "nodisplay";
	 document.getElementById("pressRelCurrent").className = "display";
	 document.getElementById("pressRel").className = "display";
	 curRelease = "pressRel";
	}
	else {
	 document.getElementById("earnRelCurrent").className = "display";
	 document.getElementById("earningsRel").className = "display";
	 document.getElementById("pressRelCurrent").className = "nodisplay";
	 document.getElementById("pressRel").className = "nodisplay";
	 curRelease = "earningsRel";
	}
}
	
	String.prototype.trim=function(){
		return this.replace(/^\s*|\s*$/g,'');
	}
	String.prototype.ltrim=function(){
		return this.replace(/^\s*/g,'');
	}	
	String.prototype.rtrim=function(){
		return this.replace(/\s*$/g,'');
	}
/* End Miscellaneous */
function RotateWebinar() {
	if (document.getElementById(featureArray[0]).className == "display") {
	  document.getElementById(featureArray[0]).className = "nodisplay";
	  document.getElementById(featureArray[1]).className = "display";
	}
	else {
	  document.getElementById(featureArray[0]).className = "display";
	  document.getElementById(featureArray[1]).className = "nodisplay";
	}
	setTimeout("RotateWebinar()", 7000);
}
