    // 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 );
	}

	var offsetTop = 0;
	function setOffsetTop(o) {

		try {
			if (o.pageY) {
				if (o.pageY - o.clientY <= 0 ) {
					offsetTop = 20;
				} else {
					offsetTop = o.pageY - o.clientY + 20;
				}
			} else if (document.body.scrollTop) {
				if (document.body.scrollTop - o.clientY <= 0 ) {
					offsetTop = 20;
				} else {
					offsetTop = document.body.scrollTop - clientY + 20;
				}
			} else {
				if(o.srcElement.parentNode.parentNode.className == "SeverityAnswer") {
					//alert("ClientY: " + o.clientY + ", ScreenY " + o.screenY + ", scrollTop: " + document.documentElement && document.documentElement.scrollTop);
					offsetTop = o.clientY + 250 - o.screenY + (document.documentElement && document.documentElement.scrollTop);
					if (offsetTop <= 20) {
						offsetTop = 20;
					}
				} else {
					if (o.srcElement.offsetTop + 250 - o.y <= 0) {
						offsetTop = 20;
					} else {
						offsetTop = o.srcElement.offsetTop + 270 - o.y;
					}
				}
			}
		} catch (e) {
			// do nothing
			//alert(e);
		}
	}

    // pop up a window for a target when a doctype is passed in
    function PopOffWindow(URL, type, width, height, hasScrollbars) {
        var newWidth = 640;
        var newHeight = 600;
        var newHasScrollbars = "yes";

        if (width != null)
            newWidth = width;

        if (height != null)
            newHeight = height;
        
        if (hasScrollbars != null)
            newHasScrollbars = hasScrollbars;
        
        //var site_base_path = "http://dev.mypreventionjourney.com";
        
    	if (URL.indexOf(".pdf") > 0) {
    	    features = "height=" + newHeight + ",width=" + newWidth + ",top=60,left=100,"
		       +"toolbar=no,location=no,menubar=no,statusbar=no,"
		       + "scrollbars=" + newHasScrollbars + ",resizable=yes";
			var windowToOpen;
		    if (windowToOpen && !windowToOpen.closed) {
				windowToOpen.close();
			}
		    windowToOpen = window.open(URL, "_uspm", features);
		    return;
    	}

    	//window.location = "#__top";
    	title = "Library";

    	//if (URL.indexOf("?q=") !=  -1 ) {
    	//	URL = site_base_path + "healthwise/docs/viewer2/render.php?" + URL.substr(URL.indexOf("&") + 1);
    	//}

	    var features;
	    if ( type == "eform" )
	    {
	        features = "top=60,left=100,toolbar=no,location=no,menubar=no,statusbar=no,"
		       +"scrollbars=yes,resizable=yes";
	        GB_show(title, URL, 600, 640 );
//	        var options = {
//	        caption: title,
//	        height: 600,
//	        width: 640,
//            fullscreen: false,
//            show_loading: true
//            }
//            var win = new GB_Window(options);
//            win.show(URL);
	        
	    }
	    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";
    	     GB_show(title, URL, 600, 640);
//	         var options = {
//	             caption: title,
//	             height: 600,
//	             width: 640,
//	             fullscreen: false,
//	             show_loading: true
//	         }
//	         var win = new GB_Window(options);
//	         win.show(URL);
		}
	    else
	    {

	     features = "height=" + newHeight + ",width=" + newWidth + ",top=60,left=100,"
		       + "toolbar=no,location=no,menubar=no,statusbar=no,"
		       + "scrollbars=" + newHasScrollbars + ",resizable=yes";
    	     //GB_show(title, URL, 400, 640, site_base_path );
//	            var options = {
//	            caption: title,
//	            height: 400,
//	            width: 640,
//                fullscreen: false,
//                show_loading: true
//                }
//                var win = new GB_Window(options);
	     //                win.show(URL);
	     GB_show(title, URL, newHeight, newWidth);

	    }
	    /*
	   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';
		   	    }
		       } else {
			      layers[i].style.display = 'none';
		       }
	         }
	    }
    }

    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]
    }

