var blnDOM = false;
var blnIE = false;
var blnNN4 = false;

if (document.getElementById)
{
  blnDOM = true;
}
else if (document.layers)
{
  blnNN4 = true;
}
else if (document.all)
{
  blnIE = true;
}

if (blnNN4)
{
  m_size = 13;
}
else
{
  m_size = 20;
}

// Get or create report suite ID
function hwSetAccount(param)
{
  var tempAccount;
  if (typeof (param) == "object" && typeof (param.account) != "undefined")  {
    tempAccount = param.account;
  }
  else  {
    if (typeof (hwTrackObject) == "object" && typeof (hwTrackObject.account) != "undefined")    {
      tempAccount = hwTrackObject.account;
    }
    else    {
      tempAccount = "hw-warning-account";
    }
  }
  return tempAccount.replace(/_/g, "-");
}

function displayWarning()
{
  // Verify what document we are displaying
  if (hwSectionHWID == "hw62789" || hwSectionHWID == "aa26921" ||
      hwSectionHWID == "aa26996" || hwSectionHWID == "hw58717" ||
      hwSectionHWID == "hw58941" || hwSectionHWID == "hw59143" ||
      hwSectionHWID == "hw59273" || hwSectionHWID == "hw59624" ||
      hwSectionHWID == "hw65153" || hwSectionHWID == "hw62787") 
  {		
	  document.writeln('<td align="left">');
	  document.writeln('<blockquote><font color="#FF0000"><b>');
	  document.writeln('Study recommends diuretics as first-line treatment for high blood pressure.');
	  document.writeln('&nbsp<a href="http://bulletin.healthwise.net/allhat/default.htm" target="_Blank">More Information from Healthwise</a>');
	  document.writeln('</b></font><blockquote>');
	  document.writeln('</td>');
  }
} // end displayWarning

function hwBuildNavigationSelectMenu()
{
	var search = "HWNavList=" 
	var navListArray;
	var cnt = 1;
	//if(document.forms["frmNavList"] != null) {
	navListArray = hwGetNavListArray();
	if (navListArray == null)
	{
		navListArray = new Array();
	}

	for (i = navListArray.length - 1; i > -1; i--)
	{
	  if (navListArray[i].length > 0)
		{
			var item = unescape(navListArray[i]);
			var fields = item.split("$");
			var title = m_topicTitle;
			if (fields[0] != title)
			{ // do not include the current document
				var docTitle = fields[0];
				if(docTitle.length > 60)
				docTitle = docTitle.substr(0, 60);
				document.writeln('<option  value="' + fields[1] + '">' + docTitle + '</option>');
			}
		}
	}
	if (hwUpdateNavList(navListArray)) { hwSaveSelNavList(navListArray); }
}//end hwBuildNavigationSelectMenu()function hwGetNavListArray() 
{
	var arg = "HWNavList=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) 
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		{
		  return (hwGetNavListVal(j).split("!!"));
		}
		i = document.cookie.indexOf(" ", i) + 1
		if (i == 0)
		{
		  break;
		}
	}
	return(null);
}function hwGetNavListVal(offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }

	return(unescape(document.cookie.substring(offset, endstr)));
}// if needed, add the current document to the list
function hwUpdateNavList(list)
{
	// The maximum Cookie size is 4KB. Once the cookie exceeds this
	// size, the cookie is reset, losing URL history.
	var index;
	if (m_rank > 2)
	{
	  return false;
	}			// This is needed for the DocTitle/SecTitle 30/30 split.	var m_topicTitleNew;
	if (hwSectionTitle.length < 1)
	{
		//m_topicTitleNew  = m_topicTitle;
		m_topicTitleNew = m_topicTitle.substring(0,30); // 30/30
	}
	else 
	{
		//m_topicTitleNew  = m_topicTitle + " (" + hwSectionTitle + ")";
		m_topicTitleNew  = m_topicTitle.substring(0,30) + " (" + hwSectionTitle.substring(0,30) + ")"; // 30/30
	}	
	index = hwIsInArray(m_topicTitleNew, list); // This is the new index, using the 30/30 split.

	if (index > -1) { list = list.slice(0, index - 1).concat(list.slice(index + 1)); }

	if (hwSectionTitle.length < 1)
	{
		//list[list.length] = m_topicTitle + "$" + document.URL;
		list[list.length] = m_topicTitle.substring(0,30) + "$" + document.URL; // 30/30
	}
	else 
	{
		//list[list.length] = m_topicTitle + " (" + hwSectionTitle + ")$" + document.URL;
		list[list.length] = m_topicTitle.substring(0,30) + " (" + hwSectionTitle.substring(0,30) + ")$" + document.URL; // 30/30
	}
	return true;
}function hwIsInArray(val, arr)
{
  for (i = 0; i < arr.length - 1; i++)
  {
    if (arr[i].indexOf(val) > -1)
    {
      return i;
    } 
  }
	return -1;
}
function hwSaveSelNavList(list) { 
	var value = "";
	for (i = 0; i < list.length; i++)
	{
		value += list[i] + "!!";
	}
	document.cookie = "HWNavList=" + escape(value) + ";" + "path=/";
}

// event handler for selecting an item from the NavList
function hwNavigateList()
{	var index = document.forms.frmNavList.selNavList.selectedIndex;
	
	if (index > 0) { document.location.href = document.forms.frmNavList.selNavList.options[index].value; }
}
function hwPopoffWindow(DaURL, type)
{
	var features;
	if (type == "calculator")
	{
		features = "height=600,width=600,top=60,left=100,"
			+ "toolbar=no,location=no,menubar=no,statusbar=no,"
			+ "scrollbars=yes,resizable=yes";
	}
	else if (type == "slideshow")
	{
		features = "height=454,width=500,top=60,left=100,"
			+ "toolbar=no,location=no,menubar=no,statusbar=no,"
			+ "scrollbars=yes,resizable=yes";
	}
	else
	{
		if (hwDocType == "mm-doc")
		{
			features = "height=400,width=500,top=60,left=100,"
				+ "toolbar=no,location=no,menubar=no,statusbar=no,"
				+ "scrollbars=yes,resizable=yes";
		}
		else
		{		
			features = "height=400,width=500,top=60,left=100,"
				+ "toolbar=no,location=no,menubar=no,statusbar=no,"
				+ "scrollbars=yes,resizable=yes";
		}
	}
	var ItsTheWindow;
	ItsTheWindow = window.open(DaURL, "Poppy", features);
	ItsTheWindow.focus();
}

function trim(s)
{
  while (s.substring(0, 1) == ' ')
	{
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length - 1, s.length) == ' ')
	{
		s = s.substring(0,s.length-1);
	}
	return s;
}

function getNewTerm()
{
	// Set the newly entered text to sTerm, so the form postback 
	// uses the updated value.
	var term = document.search.SEARCHTERM.value;
	sTerm = trim( term );
	document.search.SEARCHTERM.value = sTerm;
}

function changeslides(a,b)
{
  if (typeof (maxSlideViewed) != 'undefined')
	{
		c = Math.max(a, b);
		if (c > maxSlideViewed) { maxSlideViewed = c; }
	}
	
	document.getElementById(a).style.display = "none";
	document.getElementById(b).style.display = "";
}

// Function to resize popup window if necessary.  Mainly 
// used for Interactive Tools that might be larger than
// the pop up window they are contained in.
function resizeWindowForInteractiveTool()
{ 				
	var tool = window.document["HealthwiseInteractiveTool"];
	if (tool != null)
	{ 					
		var width = tool.width; 					
		var height = tool.height; 
		var widthPadding = 152;
		var heightPadding = 335;

		if (width >= 600) { widthPadding = 40; }
		if (height >= 600) { heightPadding = 140; }
		
		resizedHeight = parseInt(height) + heightPadding; 					
		resizedWidth = parseInt(width) + widthPadding; 					
		window.resizeTo(resizedWidth, resizedHeight);    				
	}
}// Function to generate the needed link construct for kbnet.// This link will be then used by the itool to deep link into content.function hwGenerateContentLink(linkInfo){  if (linkInfo.documentType == 'MultiMedia' ||
	    linkInfo.documentType == 'Definition' ||
	    linkInfo.documentType == 'Answer')
  {
    return "StdDocument.aspx?DOCHWID=" + linkInfo.documentHref + "&POP=true";
  }
  return "StdDocument.aspx?DOCHWID=" + linkInfo.documentHref + "&amp;SECHWID=" + linkInfo.sectionHref;
}

function GetSymptomCheckerURL(docHWID, secHWID)
{
  var url = "StdDocument.aspx?DOCHWID=" + docHWID + "&SECHWID=" + secHWID;
  return url;
}

function isEmpty(myVar, localization)
{
  if (myVar.length < 2)
  {
    // if the length is 0 or 1, we do not search
    return false;
  }
}

//Open and Set Focus to FDB DIC window			
function setFocusToDICWindow(url, windowname)
{
  var windowToOpen = window.open(url, windowname, 'height=570,width=650,toolbar=no,location=no,menubar=no,statusbar=no,scrollbars=yes,resizable=no');
  windowToOpen.focus();
  return false;
}
