// used to get param value from url
// name String - the name of the url parameter
function gup(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)",
	regex = new RegExp(regexS),
	results = regex.exec(window.location.href);

	return results == null ? "" : results[1];
}

// This function is used to display the tabbed module
function updateTabDisplay(target, elm){
    var obj = $(elm);
    obj.up('.tabModuleContainer').select('.tabDisplay').each(
        function(tab){
        if(tab.hasClassName(target) && !tab.hasClassName('currentTabDisplay')){
            tab.addClassName('currentTabDisplay');
        } else if(!tab.hasClassName(target)) {
            tab.removeClassName('currentTabDisplay');
        }
    });
    obj.up('.tabModuleContainer').select('.tab').each(
        function(e){
        if(obj.up('.tab') == e && !e.hasClassName('curTab'))
            e.addClassName('curTab');
        else if(obj.up('.tab') != e && e.hasClassName('curTab'))
            e.removeClassName('curTab');
    });
}

/*
* based on Facebox by Chris Wanstrath -- http://famspam.com/facebox
* 
* :: ported to the Prototype JS library by ::
* Phil Burrows
* http://blog.philburrows.com
* peburrows@gmail.com
* Date: 3 May 2008
*
* Usage:
*  
* This Prototype version is setup to automatically run when the window's load event is fired (see last three lines of this file),
* so usage is as easy as adding rel="facebox" to any link you want to use Facebox
*
* AGAIN, kudos to to Chris Wanstrath and the guys from ErrFree for really putting in the brunt of the effort exerted on this
* I just spent an evening taking all their work and molding it into something that would use Prototype
*/

var Facebox = Class.create({
	initialize	: function(extra_set){
		this.settings = {
			loading_image	: '/common/images/loading-white-bg.gif',
			close_image		: '/common/images/closelabel.gif',
			image_types		: new RegExp('\.' + ['png', 'jpg', 'jpeg', 'gif'].join('|') + '$', 'i'),
			inited				: true,	
			facebox_html	: '\
	  <div id="facebox" style="display:none;"> \
	    <div class="popup"> \
	      <table> \
	        <tbody> \
	          <tr> \
	            <td class="tl"/><td class="b"/><td class="tr"/> \
	          </tr> \
	          <tr> \
	            <td class="b"/> \
	            <td class="body"> \
	              <div class="content clearfix"> \
	              </div> \
	              <div class="footer"> \
	                <a href="#" class="close"> \
	                  <img src="/common/images/closelabel.gif" title="close" class="close_image" /> \
	                </a> \
	              </div> \
	            </td> \
	            <td class="b"/> \
	          </tr> \
	          <tr> \
	            <td class="bl"/><td class="b"/><td class="br"/> \
	          </tr> \
	        </tbody> \
	      </table> \
	    </div> \
	  </div>'
		};
		if (extra_set) Object.extend(this.settings, extra_set);
		$$('body').first().insert({bottom: this.settings.facebox_html});
		
		this.preload = [ new Image(), new Image() ];
		this.preload[0].src = this.settings.close_image;
		this.preload[1].src = this.settings.loading_image;
		
		f = this;
		$$('#facebox .b:first, #facebox .bl, #facebox .br, #facebox .tl, #facebox .tr').each(function(elem){
			f.preload.push(new Image());
			f.preload.slice(-1).src = elem.getStyle('background-image').replace(/url\((.+)\)/, '$1');
		});
		
		// this.keyPressListener = this.watchKeyPress().bindAsEventListener(this);
		
		this.watchClickEvents();
		fb = this;
		Event.observe($$('#facebox .close').first(), 'click', function(e){
			Event.stop(e);
			fb.close()
		});
		Event.observe($$('#facebox .close_image').first(), 'click', function(e){
			Event.stop(e);
			fb.close()
		});
	},
	
	// watchKeyPress	: function(e){
	// 	// not sure if the call to this will work here
	// 	if (e.keyCode == 27) this.close();
	// },
	watchClickEvents	: function(e){
		var f = this;
		$$('a[rel=popout]').each(function(elem,i){
			Event.observe(elem, 'click', function(e){
				Event.stop(e);
				f.click_handler(elem, e);
			});
		});
		
	},
	loading	: function() {
		if ($$('#facebox .loading').length == 1) return true;
		
		contentWrapper = $$('#facebox .content').first();
		contentWrapper.childElements().each(function(elem, i){
			elem.remove();
		});
		contentWrapper.insert({bottom: '<div class="loading"><img src="'+this.settings.loading_image+'"/></div>'});
		var pageScroll = document.viewport.getScrollOffsets();
		var dimensions = $('facebox').getDimensions();
		$('facebox').setStyle({
			'top': pageScroll.top + (document.viewport.getHeight() / 10) + 'px',
			'left': pageScroll.left + ((document.viewport.getWidth() / 2) - (dimensions.width / 2)) + 'px'
		});
		
		Event.observe(document, 'keypress', this.keyPressListener);
	},
	reveal : function(data, klass){
		this.loading();
		box = $('facebox');
		if(!box.visible()) box.show();
		
		contentWrapper = $$('#facebox .content').first();
		if (klass) contentWrapper.addClassName(klass);
		contentWrapper.insert({bottom: data});
		load = $$('#facebox .loading').first();
		if(load) load.remove();
		$$('#facebox .body').first().childElements().each(function(elem,i){
			elem.show();
		});
		
		Event.observe(document, 'keypress', this.keyPressListener);
	},
	close		: function(){
		$('facebox').hide();
	},
	click_handler	: function(elem, e){
		this.loading();
		Event.stop(e);
		
		// support for rel="facebox[.inline_popup]" syntax, to add a class
		var klass = elem.rel.match(/facebox\[\.(\w+)\]/);
		if (klass) klass = klass[1];
		
		// div
		$('facebox').show();
		
		if (elem.href.match(this.settings.image_types)) {
			var image = new Image();
			fb = this;
			image.onload = function() {
				fb.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
			}
			image.src = elem.href;
		} else {
			// Ajax
			var fb = this;
			var fullURL = elem.href;
			var hashLoc = fullURL.indexOf("#");
			var urlLength = fullURL.length;
			var newURL = fullURL.substr(0, hashLoc);

			
			
			new Ajax.Request(newURL, {
				method		: 'get',
				onFailure	: function(transport){
					fb.reveal(transport.responseText, klass);
				},
				onSuccess	: function(transport){
					fb.reveal(transport.responseText, klass);
					var dimensions2 = $('facebox').getDimensions();
					
				},
				onComplete  : function() {
					var dimensions3 = $('facebox').getDimensions();
					$('facebox').style.left=((document.viewport.getWidth() / 2) - (dimensions3.width / 2)) + 'px';
				}
			});
			
		}
	}
});
var facebox;
Event.observe(window, 'load', function(e){
	facebox = new Facebox();
});
//END OF FACEBOX 

//HEALTHWISE

// This code may only be used in the development of displaying Healthwise
// content.  No warranty is given or implied.

// this points to the content
var baseUrl		= "../../xml";

function RenderDocument( pathToXml, pathToXsl, sectionHwid )
{
    var browser=navigator.appName;
    if (browser=="Netscape")
    {
        RenderDocumentFirefox( pathToXml, pathToXsl, sectionHwid );
    }
    else if (browser=="Microsoft Internet Explorer")
    {
        RenderDocumentIE( pathToXml, pathToXsl, sectionHwid );
    }
    else
    {
        alert("Unsupported browser: " + browser);
    }
}

function RenderDocumentFirefox( pathToXml, pathToXsl, sectionHwid )
{
    var processor = new XSLTProcessor();

    var myXMLHTTPRequest = new XMLHttpRequest();
    myXMLHTTPRequest.open("GET", pathToXsl, false);
    myXMLHTTPRequest.send(null);
    // *** get the XSL document
    var xslStylesheet = myXMLHTTPRequest.responseXML;
    processor.importStylesheet(xslStylesheet);

    // *** load the xml file
    myXMLHTTPRequest = new XMLHttpRequest();
    myXMLHTTPRequest.open("GET", pathToXml, false);
    myXMLHTTPRequest.send(null);
    var xmlSource = myXMLHTTPRequest.responseXML;
    
    // parameters
    if( args.sort )
    {
        processor.setParameter(null, "sort", args.sort);
    }
    
    processor.setParameter(null, "xmlFilePath", pathToXml);
    
    if( sectionHwid != "")
    {
		processor.setParameter(null, "gpSectionHWID", sectionHwid);
    }
    
    // *** transform
    var resultDocument = processor.transformToDocument(xmlSource);
    document.removeChild(document.firstChild);
    document.appendChild(resultDocument.firstChild);
	// force resize call for firefox since onload doesn't get called
	resizeWindowForInteractiveTool();
}

function RenderDocumentIE( pathToXml, pathToXsl, sectionHwid )
{
	var xslt = new ActiveXObject("Msxml2.XSLTemplate");
	var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
	var xslProc;
	
	// load xsl
	xslDoc.async = false;
	xslDoc.resolveExternals = true;
	xslDoc.load( pathToXsl );
	
	xslt.stylesheet = xslDoc;
	
	// load xml
	var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
	xmlDoc.async = false;
	xmlDoc.resolveExternals = true;
	xmlDoc.preserveWhiteSpace = true;
	xmlDoc.load( pathToXml );
	
	if(xmlDoc.documentElement == null)
	{
		alert ("Could not load XML file " + pathToXml);
	}

	// processor
	xslProc = xslt.createProcessor();
	xslProc.input = xmlDoc;
	
	// add params
	if(args.sort)
	{
		xslProc.addParameter("sort", args.sort);
	}
	
	xslProc.addParameter("xmlFilePath", pathToXml);
	
	if( sectionHwid != "")
    {
		xslProc.addParameter("gpSectionHWID", sectionHwid);
    }
	
	// transform
	xslProc.transform();
	
	document.write( xslProc.output );
}

// pop up a window for a target when a doctype is passed in
function PopOffWindow(URL, type)
{
    var features;
    if ( type == "eform" )
    {
     features = "top=60,left=100,toolbar=no,location=no,menubar=no,statusbar=no,"
	       +"scrollbars=yes,resizable=yes";
    } 
    else if ( type == "Calculator" )
    {
     features = "height=600,width=640,top=60,left=100,"
	       +"toolbar=no,location=no,menubar=no,statusbar=no,"
	       +"scrollbars=yes,resizable=yes";	
    }
    else
    {
     features = "height=400,width=640,top=60,left=100,"
	       +"toolbar=no,location=no,menubar=no,statusbar=no,"
	       +"scrollbars=yes,resizable=yes";
    }
   var windowToOpen;
    if (windowToOpen && !windowToOpen.closed) {
		windowToOpen.close();
	}
    windowToOpen = window.open(URL, "Poppy", features);
    try {
		if (windowToOpen && window.focus) {
			windowToOpen.focus();
		}			
	}
	catch (ex) {
	}
} // end popoffwindow


// Given an hwid return the path to the content
// uses baseUrl defined at the top
function GetXmlFilePath( docHWID )
{
	var url;
	var strDocHWID;
	var i;

	url			= new String();
	strDocHWID	= new String(docHWID);

	for( i=0; i<strDocHWID.length; i+=4 )
	{
		url += "/" + strDocHWID.substr(i, 4);
	}
	url += "/" + docHWID + ".xml";
	url = baseUrl + url;

	return url;
}

function getArgs()
{
	var args = new Object();
	// Get Query String
	var query = location.search.substring(1);
	// Split query at the comma
	var pairs = query.split("&");

	// Begin loop through the querystring
	for(var i = 0; i < pairs.length; i++) {

		// Look for "name=value"
		var pos = pairs[i].indexOf('=');
		// if not found, skip to next
		if (pos == -1) continue;
		// Extract the name
		var argname = pairs[i].substring(0,pos);

		// Extract the value
		var value = pairs[i].substring(pos+1);
		// Store as a property
		args[argname] = unescape(value);
	}
	return args; // Return the Object
}

function showLayer(id, className) 
{
    var layers = document.getElementsByTagName("div");
    for (var i = 0; i < layers.length; i++) {
         if (layers[i].className == className) {
	       if (layers[i].id == id) {
	   	    if (layers[i].style.display == 'block') {
		      layers[i].style.display = 'none';
	   	    }
	   	    else {
		      layers[i].style.display = 'block';
	   	    }
	       }
         }
    }
}

function showRow(id, className) {
    var layers = document.getElementsByTagName("tr");
    for (var i = 0; i < layers.length; i++) {
         if (layers[i].className == className) {
	       if (layers[i].id == id) {
	   	    if (layers[i].style.display == 'block') {
		      layers[i].style.display = 'none';
	   	    }
	   	    else {
		      layers[i].style.display = 'block';
	   	    }
	       } else {
		      layers[i].style.display = 'none';
	       }
         }
    }
}

// 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);
      }
}


/***********************************************
* Fixed ToolTip script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
		
var tipwidth='300px' //default tooltip width
var tipbgcolor='lightyellow'  //tooltip bgcolor
var disappeardelay=250  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="0px" //horizontal offset of tooltip from anchor link
var horizontal_offset="-3px" //horizontal offset of tooltip from anchor link

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
    var parentEl=what.offsetParent;
    while (parentEl!=null){
	    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
	    parentEl=parentEl.offsetParent;
    }
    return totaloffset;
}

function showhide(obj, e, visible, hidden, tipwidth){
    if (ie4||ns6)
	    dropmenuobj.style.left=dropmenuobj.style.top=-500
    if (tipwidth!=""){
	    dropmenuobj.widthobj=dropmenuobj.style
	    dropmenuobj.widthobj.width=tipwidth
    }
    if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
	    obj.visibility=visible
    else if (e.type=="click")
	    obj.visibility=hidden
}

function iecompattest(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
    var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
    if (whichedge=="rightedge"){
	    var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
	    dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
	    if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
		    edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
    }
    else{
	    var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
	    dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
	    if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
	    edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
    }
    return edgeoffset
}

function fixedtooltip(menucontents, obj, e, tipwidth){
    if (window.event) 
	    event.cancelBubble=true
    else if (e.stopPropagation) e.stopPropagation()
	    clearhidetip()
    targetcit = getDivById(menucontents)
    if (targetcit != null) {
	    dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
	    dropmenuobj.innerHTML=targetcit.innerHTML

	    if (ie4||ns6){
		    showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
		    dropmenuobj.x=getposOffset(obj, "left")
		    dropmenuobj.y=getposOffset(obj, "top")
		    dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
		    dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
	    }
    }
}

function hidetip(e) {
    if (typeof dropmenuobj!="undefined"){
	    if (ie4||ns6)
		    dropmenuobj.style.visibility="hidden"
    }
}

function delayhidetip() {
    if (ie4||ns6)
	    delayhide=setTimeout("hidetip()",disappeardelay)
}

function clearhidetip() {
    if (typeof delayhide!="undefined")
	    clearTimeout(delayhide)
}

function changeSlide(a,b) {
    document.getElementById(a).style.display = "none";
    document.getElementById(b).style.display = "";
}

function getDivById(divId){
	var x = document.getElementsByTagName('div')
	return x[divId]
}

//Opens a window to display the XML content
function ShowXML(hwid) {
    var xmlDocPath2 = GetXmlFilePath(hwid);
    window.open(xmlDocPath2);
}

 var getIToolConfig = function() {
 return {
 "fetalDevelopment": {"months": {"month":[ {"name":"month1", "linkContent": [{"documentType":"MedicalTest","description":"Pregnancy test/hCG","rank":"1","documentHref":"hw42062","sectionHref":"hw42065"}, {"documentType":"MedicalTest","description":"Home pregnancy tests","rank":"1","documentHref":"hw227606","sectionHref":"hw227609"}, {"documentType":"Special","description":"Pregnancy","rank":"1","documentHref":"hw197814","sectionHref":"hw197816"}, {"documentType":"Frame","description":"Preparing for a healthy pregnancy","rank":"3","documentHref":"hw195050","sectionHref":"hw195050-sec"}, {"documentType":"Definition","description":"How to count the weeks","rank":"4","documentHref":"tn10321","sectionHref":"tn10321-sec"}]}, {"name":"month2","linkContent": [{"documentType":"MedicalTest","description":"Pregnancy test/hCG","rank":"1","documentHref":"hw42062","sectionHref":"hw42065"}, {"documentType":"MedicalTest","description":"Home pregnancy tests","rank":"1","documentHref":"hw227606","sectionHref":"hw227609"}, {"documentType":"Special","description":"Pregnancy","rank":"1","documentHref":"hw197814","sectionHref":"hw197816"}, {"documentType":"Frame","description":"Preparing for a healthy pregnancy","rank":"3","documentHref":"hw195050","sectionHref":"hw195050-sec"}, {"documentType":"Definition","description":"How to count the weeks","rank":"4","documentHref":"tn10321","sectionHref":"tn10321-sec"}]}, {"name":"month3","linkContent": [{"documentType":"Special","description":"Birth defects testing","rank":"1","documentHref":"uf6260","sectionHref":"uf6261"}, {"documentType":"MedicalTest","description":"Chorionic villus sampling (CVS)","rank":"1","documentHref":"hw4104","sectionHref":"hw4107"}, {"documentType":"DecisionPoint","description":"Should I have chorionic villus sampling (CVS)?","rank":"2","documentHref":"tb1905","sectionHref":"tb1905-Intro"}, {"documentType":"Definition","description":"How to count the weeks","rank":"4","documentHref":"tn10321","sectionHref":"tn10321-sec"}]}, {"name":"month4","linkContent": [{"documentType":"Special","description":"Birth defects testing","rank":"1","documentHref":"uf6260","sectionHref":"uf6261"}, {"documentType":"Frame","description":"Maternal serum triple or quadruple screen","rank":"3","documentHref":"ta7038","sectionHref":"ta7038-sec"}, {"documentType":"MedicalTest","description":"Amniocentesis","rank":"1","documentHref":"hw1810","sectionHref":"hw1813"}, {"documentType":"DecisionPoint","description":"Should I have the maternal serum triple or quadruple test (triple or quad screen)?","rank":"2","documentHref":"aa21828","sectionHref":"aa21828-Intro"}, {"documentType":"DecisionPoint","description":"Should I have an amniocentesis?","rank":"2","documentHref":"aa103080","sectionHref":"aa103080-Intro"}, {"documentType":"Definition","description":"How to count the weeks","rank":"4","documentHref":"tn10321","sectionHref":"tn10321-sec"}]}, {"name":"month5","linkContent": [{"documentType":"Special","description":"Birth defects testing","rank":"1","documentHref":"uf6260","sectionHref":"uf6261"}, {"documentType":"Frame","description":"Maternal serum triple or quadruple screen","rank":"3","documentHref":"ta7038","sectionHref":"ta7038-sec"}, {"documentType":"MedicalTest","description":"Amniocentesis","rank":"1","documentHref":"hw1810","sectionHref":"hw1813"}, {"documentType":"MedicalTest","description":"Fetal ultrasound","rank":"1","documentHref":"hw4693","sectionHref":"hw4696"}, {"documentType":"DecisionPoint","description":"Should I have an early fetal ultrasound?","rank":"2","documentHref":"aa22092","sectionHref":"aa22092-Intro"}, {"documentType":"DecisionPoint","description":"Should I have an amniocentesis?","rank":"2","documentHref":"aa103080","sectionHref":"aa103080-Intro"}, {"documentType":"DecisionPoint","description":"Should I have the maternal serum triple or quadruple test (triple or quad screen)?","rank":"2","documentHref":"aa21828","sectionHref":"aa21828-Intro"}, {"documentType":"Definition","description":"How to count the weeks","rank":"4","documentHref":"tn10321","sectionHref":"tn10321-sec"}]}, {"name":"month6","linkContent": [{"documentType":"Special","description":"Premature infant","rank":"1","documentHref":"tn5684","sectionHref":"tn5687"}, {"documentType":"DecisionPoint","description":"How can I make informed decisions about my extremely premature infant?","rank":"2","documentHref":"tn8416","sectionHref":"tn8416-Intro"}, {"documentType":"Definition","description":"How to count the weeks","rank":"4","documentHref":"tn10321","sectionHref":"tn10321-sec"}]}, {"name":"month7","linkContent": [{"documentType":"Special","description":"Premature infant","rank":"1","documentHref":"tn5684","sectionHref":"tn5687"}, {"documentType":"DecisionPoint","description":"How can I make informed decisions about my extremely premature infant?","rank":"2","documentHref":"tn8416","sectionHref":"tn8416-Intro"}, {"documentType":"Frame","description":"Kick counts","rank":"3","documentHref":"aa107042","sectionHref":"aa107042-sec"}, {"documentType":"Definition","description":"How to count the weeks","rank":"4","documentHref":"tn10321","sectionHref":"tn10321-sec"}]}, {"name":"month8","linkContent": [{"documentType":"Special","description":"Premature infant","rank":"1","documentHref":"tn5684","sectionHref":"tn5687"}, {"documentType":"Frame","description":"Kick counts","rank":"3","documentHref":"aa107042","sectionHref":"aa107042-sec"}, {"documentType":"Definition","description":"How to count the weeks","rank":"4","documentHref":"tn10321","sectionHref":"tn10321-sec"}]}, {"name":"month9","linkContent": [{"documentType":"Frame","description":"Kick counts","rank":"3","documentHref":"aa107042","sectionHref":"aa107042-sec"}, {"documentType":"Special","description":"Premature infant","rank":"1","documentHref":"tn5684","sectionHref":"tn5687"}, {"documentType":"Special","description":"Labor, delivery, and postpartum period","rank":"1","documentHref":"tn9759","sectionHref":"tn9760"}, {"documentType":"Definition","description":"How to count the weeks","rank":"4","documentHref":"tn10321","sectionHref":"tn10321-sec"}]}, {"name":"month10","linkContent": [{"documentType":"Frame","description":"Kick counts","rank":"3","documentHref":"aa107042","sectionHref":"aa107042-sec"}, {"documentType":"Special","description":"Labor, delivery, and postpartum period","rank":"1","documentHref":"tn9759","sectionHref":"tn9760"}, {"documentType":"Definition","description":"How to count the weeks","rank":"4","documentHref":"tn10321","sectionHref":"tn10321-sec"}]} ]}}}} 

function hwGenerateContentLink(linkInfo) {
 url = "symptom-checker-link.front?contentid=" + linkInfo.documentHref + "&sectionid="+ linkInfo.sectionHref;

 return url;
 }
//END OF HEALTHWISE

(function() {

	// Dan Krecichwost

	var window = this,
	doc = window.document,
	undefined,
	health,
	utils,
	tabs,
	tabsConfig;

	window.health = health = window.health || {};

	/* UTILS */

	health.utils = utils = {

		replaceHtml : function(el, html) {

			// Steven Levithan, http://blog.stevenlevithan.com/archives/faster-than-innerhtml

			var oldEl = typeof el === "string" ? doc.getElementById(el) : el;

			/*@cc_on // Pure innerHTML is slightly faster in IE
				oldEl.innerHTML = html;
				return oldEl;
			@*/

			var newEl = oldEl.cloneNode(false);
			newEl.innerHTML = html;
			oldEl.parentNode.replaceChild(newEl, oldEl);
			return newEl;
		},
		
		applyAttributes : function(parent, objects, attributes) {
			var x, i, l = objects.length;
			for (x in attributes) {
				for (i = 1; i <= l; i++) {
					objects[i-1][x] = attributes[x](parent, i);
				}
			}
		},
		
		isFunction : function(func) {
			return typeof func == 'function';
		}
	};


	/* TABS */

	health.tabs = tabs = function tabs(tabsetName, tabsetConfiguration) {
		
		var t = this,
		tabset = t.tabset = tabsetConfiguration || (tabset = tabs.config[tabsetName]) ? tabset() : null,
		defaultConfig = tabsConfig.__defaultConfig(),
		x;
		
		if (!(tabset && tabset.panel)) {
			return false;
		}
		
		for (x in tabset) {
			t[x] = tabset[x];
		}

		var panel = t.panel,
		tab = t.tab,
		startIndex = t.index = t.startIndex || defaultConfig.startIndex;

		t.tabsetName = tabsetName;
		t.collection[tabsetName] = t;
		
		function buildCollection(object) {
			if (object) {
				object.collection = object.collection || $$(object.selector);
				object.current = object.collection[startIndex-1];
				if (object.events) {
					utils.applyAttributes(t, object.collection, object.events);
				}
			}
		}
		
		buildCollection(panel);
		buildCollection(tab);

		for (x in defaultConfig) {
			if (!t[x]) {
				t[x] = utils.isFunction(defaultConfig[x]) ? defaultConfig[x](t) : defaultConfig[x];
			}
		}

		if (t.autoStart) {
			t.startRotation();
		}
	};
	
	tabs.collection = tabs.prototype.collection = {};

	tabs.prototype.rotate = function(t, index, instant) {
	
		if (!t) {
			t = this;
		}
		
		t.index = index || (t.index % t.indexTotal + 1);
		
		if (t.tab) {
			t.switchTab();
		}

		if (t.panel) {
			if (instant) {
				t.switchPanelInstant();
			} else {
				t.switchPanel();
			}
		}
	};

	tabs.prototype.startRotation = function() {

		var t = this,
		callback = t.rotate;

		/*@cc_on
			callback = function(t) {
				return function() {
					t.rotate();
				};
			}(t);
		@*/

		t.timeout = window.setInterval(callback, t.interval, t, null, null);

		t = callback = null;
	};

	tabs.prototype.stopRotation = function() {

		if (this.timeout) {
			window.clearInterval(this.timeout);
			this.timeout = null;
		}
	};
	var toReturnOrNotToReturn;
	tabs.prototype.switchTab = function(t) {
		
		t = t || this;
		var tab = t.tab,
		indexTab = tab.collection[t.index-1],
		currentTab = tab.current;
		
		if (indexTab && currentTab && currentTab != indexTab) {
			$(currentTab).removeClassName(tab.selectedClass);
			$(indexTab).addClassName(tab.selectedClass);
			tab.current = indexTab;
			toReturnOrNotToReturn = false;
		}
		else{
			toReturnOrNotToReturn = true;
		}
		t = indexTab = currentTab = null;
	};
	
	tabs.prototype.switchPanel = function(t) {
		
		t = t || this;
		var panel = t.panel,
		indexPanel = panel.collection[t.index-1],
		currentPanel = panel.current;

		if (indexPanel && currentPanel && currentPanel != indexPanel) {

			$(currentPanel).removeClassName(panel.selectedClass);
			$(indexPanel).addClassName(panel.selectedClass);

			window.Effect[t.effect](indexPanel, { duration: t.effectDuration / 1000 });
			currentPanel.style.display = 'block';

			if (panel.timeout) {
				window.clearTimeout(panel.timeout);
			}

			panel.timeout = window.setTimeout(function() { currentPanel.style.display = 'none'; panel.timeout = currentPanel = null; }, t.effectDuration + 100);

			panel.current = indexPanel;
		}
		t = indexPanel = null;
	};
	
	tabs.prototype.switchPanelInstant = function(t) {

		t = t || this;
		var panel = t.panel,
		indexPanel = panel.collection[t.index-1],
		currentPanel = panel.current;

		if (indexPanel && currentPanel && currentPanel != indexPanel) {

			$(currentPanel).removeClassName(panel.selectedClass);
			$(indexPanel).addClassName(panel.selectedClass);

			currentPanel.style.display = 'none';
			panel.collection[t.index-1].style.display = 'block';
			
			panel.current = indexPanel;
		}
		t = indexPanel = currentPanel = null;
	};
	
	// configurations prefixed with a double underscore are not meant to be used as arguments to the tabs constructor
	tabs.config = tabsConfig = {

		__defaultConfig : function() {

			return {
				startIndex : 1,
				indexTotal : function(t) { 
					return t.panel.collection.length;
				},
				interval : 5000,
				autoStart : false,
				effect : 'Appear',
				effectDuration : 1000
			};
		},

		scrollTabs : function() {

			return {
				panel : {
					selector : '#hlt-scrollTabs-area > ul',
					selectedClass : 'hlt-scrollTabs-panel-selected'
				},
				tab : {
					selector : '#hlt-scrollTabs-nav > li',
					selectedClass : 'hlt-scrollTabs-nav-selected',
					events : {
						onclick : function(t, i) {
							return function() { 
								t.rotate(t, i, false);
								return false;
							};
						}
					}
				},
				autoStart : false,
				effect : 'Appear',
				effectDuration : 300
			};
		},

		leadContent : function() {

			return {
				panel : {
					selector : '#hlt-leadContent-imgArea > li',
					selectedClass : 'hlt-leadContent-img-selected'
				},
				tab : {
					selector : '#hlt-leadContent-nav-ul > li',
					selectedClass : 'hlt-leadContent-nav-selected',
					events : {
						onclick : function(t, i) {
							return function() {
								t.stopRotation();
								t.rotate(t, i, true);
								if(toReturnOrNotToReturn == true){
								return true;
								}
								else{
								return false;
								}
							};
						}
					}
				},
				interval : 12000,
				autoStart : true,
				effect : 'Appear',
				effectDuration : 1000
			};
		},

		newsRotator : function() {

			return {
				panel : {
					selector : '#hlt-newsRotator-list > li',
					selectedClass : 'hlt-newsRotator-item-selected'
				},
				interval : 5000,
				autoStart : true,
				effect : 'Appear',
				effectDuration : 1000
			};
		},

		__azIndex : function(type) {

			function displayResults(panel, letter) {
				new window.Ajax.Request("/encyclo-results.front?index=" + letter + "&type=" + type, {
					method : 'get',
					onCreate : function(transport){
						panel.innerHTML = '<div class="loading-image"><img src="/common/images/loading.gif"></div>';
					},
					onSuccess : function(transport){
						panel.innerHTML = transport.responseText;
					}
				});
			};

			return {
				panel : {
					selector : '#hlt-enc-results'
				},
				tab : {
					selector : '#hlt-enc-letters > a',
					events : {
						onclick : function(t, i) {
							return function() {
								displayResults(t.panel.current, String.fromCharCode(96 + i));
								return false;
							};
						}
					}
				},
				interval : 5000,
				autoStart : true,
				effect : 'Appear',
				effectDuration : 1000,
				startRotation : function() {
	
					var indexParam = gup('index');
					if (indexParam) {
						displayResults(this.panel.current, indexParam);
					}
				}
			};
		},
		
		azIndex1 : function() {
			return tabsConfig.__azIndex(1);
		},
		
		azIndex2 : function() {
			return tabsConfig.__azIndex(2);
		}
	}
})();

//Health News Module
function displayNewsContent(index) {
	if (index == 1) {
		var otherElem = 2;
		var newClassName = "category selected";
		var toChange = "news-tab-"+index;
		var otherToChange = "news-tab-2";
	} else {
		var otherElem = 1;
		var newClassName = "category selected";
		var toChange = "news-tab-"+index;
		var otherToChange = "news-tab-1";
	}
	
	
	$('news-tabbed-content-'+otherElem).hide();
	$('news-tabbed-content-'+index).appear();
	
	
	if (otherToChange == "news-tab-2") {
		$(toChange).className = newClassName;
		$(otherToChange).className = "category";
	} else {
		$(toChange).className = newClassName;
		$(otherToChange).className = "category";
	}
	
}

//Search A-Z Module
function displayAZContent(index) {
	if (index == 1) {
		var otherElem = 2;
		var newClassName = "category first selected";
		var toChange = "az-conditions";
		var otherToChange = "az-drugs";
	} else {
		var otherElem = 1;
		var newClassName = "category last selected";
		var toChange = "az-drugs";
		var otherToChange = "az-conditions";
	}

	$('tabbed-content-'+otherElem).hide();
	$('tabbed-content-'+index).appear();
	
	
	if (otherToChange == "az-drugs") {
		$(toChange).className = newClassName;
		$(otherToChange).className = "category last";
	} else {
		$(toChange).className = newClassName;
		$(otherToChange).className = "category first";
	}
	
}
//First Visit Cookie
function GetCookie (name) {
  var arg = name + "=";
  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 getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  var curDate = new Date();
  var cyear = curDate.getFullYear() + 1;
  var cmonth = curDate.getMonth();
  var cday = curDate.getDate();
  var expiryDate = new Date(cyear, cmonth, cday);

  document.cookie = name + "=" + escape (value) + ("; expires=" + expiryDate.toGMTString()) + 
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}


function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = "hkCount = "+cval+"expires="+ exp.toGMTString();

}

var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
  var count = GetCookie('hkCount');
  if(count == null) {
    SetCookie('hkCount','1');
    return 1;
    }
    else {
    var newcount = parseInt(count) + 1;
    DeleteCookie('hkCount');
    SetCookie('hkCount',newcount,exp);
    return count;
  }
}

function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function checkFirstVisit() {
	if (GetCookie('hkCount') == null) {
		document.getElementById("firstVisitMSG").style.display = "block";
		var doIt = amt();
	}
}
function closePopup() {
	document.getElementById("firstVisitMSG").style.display = "none";
}

Event.observe(window, 'load', function() {
  if ( $('hw-nav') != null){
	var newVarArr = $$('div.story');
	newVarArr[0].addClassName('hwstory');
  }
  


  
});

var popIndex = 0;
var numerator;
var totalItemsinPop;

function previousPop(){
	if(popIndex>0){
		jQuery('a.nextLink').fadeTo('fast',1.0);
		popIndex = popIndex-numerator;
		newToShow = popIndex-numerator;
		jQuery("#morePopUp .headlineItem").hide();
		for(var i=popIndex; i>newToShow; i--){
			jQuery("#morePopUp .headlineItem").eq(i).show();
		}
	}
	if(popIndex<=0){
		jQuery('a.prevLink').fadeTo('fast',.50);
	}
	
}
function nextPop(){
	if(popIndex<= (totalItemsinPop - numerator)){
		jQuery('a.prevLink').fadeTo('fast',1.0);
		popIndex = popIndex+numerator;
		newToShow = popIndex+numerator;
		jQuery("#morePopUp .headlineItem").hide();
		for(var i=popIndex; i<newToShow; i++){
			jQuery("#morePopUp .headlineItem").eq(i).show();
		}
	}
	if(popIndex>=(totalItemsinPop - numerator)){
		jQuery('a.nextLink').fadeTo('fast',.50);
	}
	
}

function getMoreArticlesJS(urlToGet,numToLoad){
	numerator = numToLoad;
	var fullUrlToGet = urlToGet+' #section .module:first';
	var closeButton = '<a href="javascript:closePopUp();" title="close" class="closeFace"><img title="close" src="/hive/images/components/closeButton.png" border="0" width="40" height="40" /></a>';//construct the close button
	var prevNextAllButtons = '<div id="prevNextAll"><a href="javascript:previousPop()" class="prevLink">Previous</a> | <a href="javascript:nextPop()" class="nextLink">Next</a></div>';//construct the close button
	var roundedTop = '<b class="roundedCorners">'+
                        '<b class="roundedCorners1"><b></b></b>'+
                        '<b class="roundedCorners2"><b></b></b>'+
                        '<b class="roundedCorners3"></b>'+
                        '<b class="roundedCorners4"></b>'+
                        '<b class="roundedCorners5"></b></b>';//construct the top rounded corners http://www.spiffycorners.com/index.php
        var roundedBottom = prevNextAllButtons+'<b class="roundedCorners">'+
                                '<b class="roundedCorners5"></b>'+
                                '<b class="roundedCorners4"></b>'+
                                '<b class="roundedCorners3"></b>'+
                                '<b class="roundedCorners2"><b></b></b>'+
                                '<b class="roundedCorners1"><b></b></b></b>';//construct the bottom rounded corners http://www.spiffycorners.com/index.php
	
	var htmlToCon = '<div id="morePopUp" class="moreItemsHolder" style="display:none"><div class="topper">'+closeButton+'</div><div id="morePopUpH" class="loading"></div></div>';
	jQuery('body').append(htmlToCon);
	jQuery("#morePopUp").prepend(roundedTop);
		jQuery("#morePopUp").append(roundedBottom);
		jQuery('a.prevLink').fadeTo('fast',.50);
		var viewport = document.viewport.getDimensions(); //get the viewport dimensions (visible screen)
		var containerH = $('container').getDimensions(); //get the container div dimensions
		var viewportOffset = document.viewport.getScrollOffsets(); //see how far the user has scrolled
		var width = viewport.width;//set the width variable, initially to the width of the viewport
		
		if(viewport.width < containerH.width){ //check to see if the user's resolution is so low that there is a horiontal scroll bar
		    width = containerH.width; //if it is, use the width of the container div, so the overlay covers everything
		}
		    
		var height = containerH.height; //set the height variable
		
		var overLay = '<div id="fadedBGOverlay" class="opacityBG" style="width:'+width+'px;height:'+height+'px;display:none;"></div>'; //construct the ovrlay
		Element.insert( $('container'), {'after':overLay} );//write the overlay
		$('fadedBGOverlay').appear({ duration: 0.3, from: 0, to: 0.7 }); //fade in the background overlay
		
		
		var widthPos = parseInt( width / 2 ) - parseInt( ($('morePopUp').getWidth() / 2) )+'px';//figure out where to position the popup horizontally
		var realOffset = viewportOffset.top + parseInt((viewport.height/2)) - parseInt( ($('morePopUp').getHeight() / 2) )+'px' ;//figure out where to position the popup vertically
		$('morePopUp').setStyle({ left: widthPos, top: realOffset});//position the popup
		$('morePopUp').appear({ duration: 0.7, from: 0, to: 1.0 });   //fade in the pop-up
		
	jQuery("#morePopUpH").load(fullUrlToGet, function(){
		
		var numberOfElements = jQuery("#morePopUp .headlineItem").length;
		totalItemsinPop = numberOfElements;
		jQuery("#morePopUp .headlineItem").hide();
		jQuery('#morePopUpH').removeClass('loading');
		for(var i=0; i<numToLoad; i++){
			jQuery("#morePopUp .headlineItem").eq(i).show();
		}
	});
}//end get more articles js

 function closePopUp(){
    $('fadedBGOverlay').remove();
    $('morePopUp').remove();
    $('headerAdCode1').show();
    $('headerAdCode2').show();
    $('headerAdCode3').show();
    $('headerAdCode4').show();
 }





