
var dbgCount = 0;
var debugWindow;
var debugging = false;
var preloadFlag = true;
var themeText = "<table width=100%><tr>\n<td witdh=100% align=center><a href=\"#\" title=\"new\" onclick=\"theTheme.Set(this.title);return false;\">Change to New theme</a></td>\n<td witdh=100% align=center><a href=\"#\" title=\"ie\" onclick=\"theTheme.Set(this.title);return false;\">Change to IE theme</a></td><td witdh=100% align=center><a href=\"#\" title=\"ns\" onclick=\"theTheme.Set(this.title);return false;\">Change to NS theme</a><br />\n</td>\n</tr>\n</table>";
//Quick and Dirty Browsser Detection
var isSafari = document.layers ? 1 : 0;
var isIE = document.all != null ? true : false;
var isNS = document.getElementById && !document.all ? 1 : 0;
function setContentToc(someTopic) {
	switch (someTopic) {
	  case "benefit":
		LoadAJAXComponent("benefit", "htmlComponents/TOC/know.ra.benefit.htm");
		LoadAJAXComponent("natural", "htmlComponents/TOC/know.ra.naturalclosed.htm");
		LoadAJAXComponent("risk", "htmlComponents/TOC/know.ra.riskclosed.htm");
		break;
	  case "risk":
		LoadAJAXComponent("risk", "htmlComponents/TOC/know.ra.risk.htm");
		LoadAJAXComponent("benefit", "htmlComponents/TOC/know.ra.benefitclosed.htm");
		LoadAJAXComponent("natural", "htmlComponents/TOC/know.ra.naturalclosed.htm");
		break;
	  case "natural":
		LoadAJAXComponent("natural", "htmlComponents/TOC/know.ra.natural.htm");
		LoadAJAXComponent("benefit", "htmlComponents/TOC/know.ra.benefitclosed.htm");
		LoadAJAXComponent("risk", "htmlComponents/TOC/know.ra.riskclosed.htm");
		break;
	}
} 
function increaseTextSize(doIt) {
	if (doIt) {
		if (isIE) {
			theTheme.Set("ie");
		} else {
			theTheme.Set("ns");
		}
		document.getElementById('txtMinus').src = 'images/actions/textsize_minus_off.gif';
		document.getElementById('txtPlus').src = 'images/actions/textsize_plus_on.gif';
	} else {
		theTheme.Set("small");
		document.getElementById('txtMinus').src = 'images/actions/textsize_minus_on.gif';
		document.getElementById('txtPlus').src = 'images/actions/textsize_plus_off.gif';
	}
}
function getTarget(evt) {
	var targ;
	if (!evt) {
		var evt = window.event;
	}
	if (evt != null && evt.target) {
		targ = evt.target;
	} else {
		if (evt != null && evt.srcElement) {
			targ = evt.srcElement;
		}
	}
	if (targ) {
		if (targ.nodeType) {
			if (targ.nodeType == 3) { // defeat Safari bug
				targ = targ.parentNode;
			}
		}
	}
	return targ;
}
function getTargetObjPosition(obj) {
	var position = new Array(2);
	var x = obj.offsetLeft;
	var y = obj.offsetTop;
	position[0] = x;
	position[1] = y;
	while (obj.offsetParent) {
		if (obj == document.getElementsByTagName(bodyStr)[0]) {
			return position;
		} else {
            //debugMsg(obj.id);
			x += obj.offsetParent.offsetLeft;
			y += obj.offsetParent.offsetTop;
			obj = obj.offsetParent;
			position[0] = x;
			position[1] = y;
            //debugMsg("X: " + x + "  Y: " + y);
		}
	}
	return position;
}
function removeMe(evt, theDivName) {
	var theDiv = document.getElementById(theDivName);
	theDiv.innerHTML = "";
	theDiv.className = "deletedDiv";
}
function handleSearch() {
	if (document.getElementById("searchBox")) {
		var searchBy = document.getElementById("searchBox");
		var searchValue = searchBy.value;
		if (searchValue == "tb" || searchValue == "TB") {
			document.location = "searchResultsTb.htm";
		} else {
			document.location = "searchResults.htm";
		}
	}
}
// POP UP A PREFORMATTED EMAIL MESSAGE WINDOW
function popupEmail() {

  // SET MESSAGE VALUES
	var to = "email address";
	var cc = "email address";
	var bcc = "email address";
	var subject = "PDF";
	var body = "*To send the Information Packet, save the packet on your computer then click the Attachment button to select the file*";

  // BUILD MAIL MESSAGE COMPONENTS
	var doc = "mailto:" + to + "&subject=" + escape(subject) + "&body=" + escape(body) + "&attachment=" + "c:\x02p.gif";

  // POP UP EMAIL MESSAGE WINDOW
	window.location = doc;
}
// Show the debug window
function showDebug() {

		window.top.debugWindow = window.open("", "Debug", "left=0,top=0,width=300,height=700,scrollbars=yes," + "status=yes,resizable=yes");


		window.top.debugWindow.opener = self;
    // open the document for writing
		window.top.debugWindow.document.open();

		window.top.debugWindow.document.write("<HTML><HEAD><TITLE>Debug Window</TITLE></HEAD><BODY><PRE>\n");

}
// Show the new window
function showNewWin() {
	window.top.debugWindow = window.open("", "", "scrollbars=yes,toolbar=yes,status=no,menubar=yes," + "resizable=yes,height=600, width=800");
	window.top.debugWindow.opener = self;
  // open the document for writing
	window.top.debugWindow.document.open();
}
// If the debug window exists, then close it
function hideDebug() {
	if (window.top.debugWindow && !window.top.debugWindow.closed) {
		window.top.debugWindow.close();
		window.top.debugWindow = null;
	}
}
function debugMsg(msg) {
	if (debugging) {
		if (dbgCount == 0) {
			showDebug();
			dbgCount = 1;
		}
		if (window.top.closed) {
			window.top.debugWindow.document.open();
		}
		if (window.top.debugWindow && !window.top.debugWindow.closed) {
			window.top.debugWindow.document.write(msg + "\n");
		}
	}
}
function newWinMsg(msg) {
	showNewWin();
	if (window.top.debugWindow && !window.top.debugWindow.closed) {
		window.top.debugWindow.document.write(msg);
	}
}
function popWindow(targetUrl) {
	var newWindow = window.open(targetUrl, "", "scrollbars=yes,resizable=yes,toolbar=yes,status=no,menubar=yes");
}
function popWindow2(targetUrl, heightin, widthin) {
	window.open(targetUrl, "", "scrollbars=yes,resizable=yes,toolbar=yes,status=no,menubar=yes,height=" + heightin + ",width=" + widthin);
}
function checkSelection(evt) {
	var theSelect = getTarget(evt);
	var strVar = "";
}
String.prototype.tokenize = tokenize;
function tokenize() {
	var input = "";
	var separator = " ";
	var trim = "";
	var ignoreEmptyTokens = true;
	try {
		String(this.toLowerCase());
	}
	catch (e) {
		window.alert("Tokenizer Usage: string myTokens[] = myString.tokenize(string separator, string trim, boolean ignoreEmptyTokens);");
		return;
	}
	if (typeof (this) != "undefined") {
		input = String(this);
	}
	if (typeof (tokenize.arguments[0]) != "undefined") {
		separator = String(tokenize.arguments[0]);
	}
	if (typeof (tokenize.arguments[1]) != "undefined") {
		trim = String(tokenize.arguments[1]);
	}
	if (typeof (tokenize.arguments[2]) != "undefined") {
		if (!tokenize.arguments[2]) {
			ignoreEmptyTokens = false;
		}
	}
	var array = input.split(separator);
	if (trim) {
		for (var i = 0; i < array.length; i = i + 1) {
			while (array[i].slice(0, trim.length) == trim) {
				array[i] = array[i].slice(trim.length);
			}
			while (array[i].slice(array[i].length - trim.length) == trim) {
				array[i] = array[i].slice(0, array[i].length - trim.length);
			}
		}
	}
	var token = new Array();
	if (ignoreEmptyTokens) {
		for (var i = 0; i < array.length; i = i + 1) {
			if (array[i] != "") {
				token.push(array[i]);
			}
		}
	} else {
		token = array;
	}
	return token;
}

function doReset(obj) {
  for (var i=0, j=obj.elements.length; i<j; i++) {
        myType = obj.elements[i].type;
        if (myType == 'checkbox' || myType == 'radio')
            obj.elements[i].checked = false;
        if (myType == 'hidden' || myType == 'password' || myType == 'text' || myType == 'textarea')
            obj.elements[i].value = "";
        if (myType == 'select-one' || myType == 'select-multiple')
             obj.elements[i].options[0].selected = true;
    } 
}

//Toggle visibility of div or other block element.
//Currently used to show/hide article copyright detail.

function toggleDisclaimer(element, showlink) {
	if (document.getElementById(element).style.display == "none") {
		document.getElementById(element).style.display = "";
		document.getElementById(showlink).innerHTML = "Hide Disclaimer";
	} else {
		document.getElementById(element).style.display = "none";
		document.getElementById(showlink).innerHTML = "Show Disclaimer";
	}
}

function toggle(element, showlink, show, topic) {
	if ((document.getElementById(element).style.display == "none") || (show == "true")) {
		document.getElementById(element).style.display = "";
		document.getElementById(showlink).innerHTML = "Hide";
		document.getElementById(showlink).style.backgroundPosition = "0px -3px";
	} else {
		document.getElementById(element).style.display = "none";
		document.getElementById(showlink).innerHTML = "Show";
		document.getElementById(showlink).style.backgroundPosition = "0px -28px";
	}
		
	if(document.getElementById('footer-wrap-l')!=null && document.getElementById('toolbar-wrap-bottom')!=null) {
		if(topic == 'Benefits' || topic == 'Safety'){
			bottom = $('footer-wrap-l').getPosition().y - toolbarbottom;
		}else{
			bottom = $('footer-wrap-l').getPosition().y - toolbarbottom;
		}
	}
	else if(document.getElementById('ratings')!=null ) {
		bottom = $('ratings').getPosition().y - 550;
	}
	if(topic == 'video'){
	  var num=document.getElementById("content").clientHeight;
      document.getElementById("main").style.height=(num-304)+'px';    
     }
	
}

function toggleNav(element, arrowstate , maxheight) {

if (document.getElementById(element).style.display == "none") {  				/* if hidden... */
	document.getElementById(element).style.display = "";  						/* ...show it */

	var divs = document.getElementsByTagName('div'); /* This is use dynamic height tabular navigation bar */
	for (var i = 0; i < divs.length; i++) {
		if (divs[i].className.search(/\bhcp-menu\b/) != -1){
			divs[i].style.height= 78 + (22 * maxheight)+"px";
		}
	}
	
	if (element.valueOf() == "hcp-menu-disease") {								/* if showing disease menu... */
		document.getElementById('hcp-menu-benefits').style.display = "none";	/* ...hide the other 3 */
		document.getElementById('hcp-menu-risks').style.display = "none";
		document.getElementById('hcp-menu-branalysis').style.display = "none";
		if ((document.body.className == "home") || (document.body.className == "home product")) {												/* if home page... */
			document.getElementById('arrow-benefits').style.backgroundPosition = "0px -92px";   /* ...show dark, down arrows for all except selected */
			document.getElementById('arrow-risks').style.backgroundPosition = "0px -92px";
			document.getElementById('arrow-branalysis').style.backgroundPosition = "0px -92px";
		}
		else {																					/* if not home page... */
			document.getElementById('arrow-benefits').style.backgroundPosition = "0px -46px";   /* show light, down arrows for others */
			document.getElementById('arrow-risks').style.backgroundPosition = "0px -46px";		
			document.getElementById('arrow-branalysis').style.backgroundPosition = "0px -46px";
			if (document.body.className.match('m-disease')) { document.getElementById('arrow-disease').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-benefits')) { document.getElementById('arrow-benefits').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-risks')) { document.getElementById('arrow-risks').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-branalysis')) { document.getElementById('arrow-branalysis').style.backgroundPosition = "0px -92px"; }
		}	
	}
	else if (element.valueOf() == "hcp-menu-benefits") {
		document.getElementById('hcp-menu-disease').style.display = "none";
		document.getElementById('hcp-menu-risks').style.display = "none";
		document.getElementById('hcp-menu-branalysis').style.display = "none";
		if ((document.body.className == "home") || (document.body.className == "home product")) {
			document.getElementById('arrow-disease').style.backgroundPosition = "0px -92px";
			document.getElementById('arrow-risks').style.backgroundPosition = "0px -92px";
			document.getElementById('arrow-branalysis').style.backgroundPosition = "0px -92px";
		}
		else {
			document.getElementById('arrow-disease').style.backgroundPosition = "0px -46px";
			document.getElementById('arrow-risks').style.backgroundPosition = "0px -46px";
			document.getElementById('arrow-branalysis').style.backgroundPosition = "0px -46px";
			if (document.body.className.match('m-disease')) { document.getElementById('arrow-disease').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-benefits')) { document.getElementById('arrow-benefits').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-risks')) { document.getElementById('arrow-risks').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-branalysis')) { document.getElementById('arrow-branalysis').style.backgroundPosition = "0px -92px"; }
		}	
	}
	else if (element.valueOf() == "hcp-menu-risks") {
		document.getElementById('hcp-menu-benefits').style.display = "none";
		document.getElementById('hcp-menu-disease').style.display = "none";
		document.getElementById('hcp-menu-branalysis').style.display = "none";
		if ((document.body.className == "home") || (document.body.className == "home product")) {
			document.getElementById('arrow-benefits').style.backgroundPosition = "0px -92px";
			document.getElementById('arrow-disease').style.backgroundPosition = "0px -92px";
			document.getElementById('arrow-branalysis').style.backgroundPosition = "0px -92px";
		}
		else {
			document.getElementById('arrow-benefits').style.backgroundPosition = "0px -46px";
			document.getElementById('arrow-disease').style.backgroundPosition = "0px -46px";
			document.getElementById('arrow-branalysis').style.backgroundPosition = "0px -46px";
			if (document.body.className.match('m-disease')) { document.getElementById('arrow-disease').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-benefits')) { document.getElementById('arrow-benefits').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-risks')) { document.getElementById('arrow-risks').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-branalysis')) { document.getElementById('arrow-branalysis').style.backgroundPosition = "0px -92px"; }
		}	
	}
	else if (element.valueOf() == "hcp-menu-branalysis") {
		document.getElementById('hcp-menu-benefits').style.display = "none";
		document.getElementById('hcp-menu-risks').style.display = "none";
		document.getElementById('hcp-menu-disease').style.display = "none";
		if ((document.body.className == "home") || (document.body.className == "home product")) {
			document.getElementById('arrow-benefits').style.backgroundPosition = "0px -92px";
			document.getElementById('arrow-risks').style.backgroundPosition = "0px -92px";
			document.getElementById('arrow-disease').style.backgroundPosition = "0px -92px";
		}
		else {
			document.getElementById('arrow-benefits').style.backgroundPosition = "0px -46px";
			document.getElementById('arrow-risks').style.backgroundPosition = "0px -46px";
			document.getElementById('arrow-disease').style.backgroundPosition = "0px -46px";
			if (document.body.className.match('m-disease')) { document.getElementById('arrow-disease').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-benefits')) { document.getElementById('arrow-benefits').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-risks')) { document.getElementById('arrow-risks').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-branalysis')) { document.getElementById('arrow-branalysis').style.backgroundPosition = "0px -92px"; }
		}	
	}
	document.getElementById(arrowstate).style.backgroundPosition = "0px 0px"; /* show dark, up arrow for clicked arrow */
	
} else {

	document.getElementById(element).style.display = "none";
	
	if ((document.body.className == "home") || (document.body.className == "home product")) {
		document.getElementById(arrowstate).style.backgroundPosition = "0px -92px";
	}
	else {
		document.getElementById(arrowstate).style.backgroundPosition = "0px -46px";
		if (document.body.className.match('m-disease')) { document.getElementById('arrow-disease').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-benefits')) { document.getElementById('arrow-benefits').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-risks')) { document.getElementById('arrow-risks').style.backgroundPosition = "0px -92px"; }
		else if (document.body.className.match('m-branalysis')) { document.getElementById('arrow-branalysis').style.backgroundPosition = "0px -92px"; }
	}	
	
}
	if(document.getElementById('toolbar-wrap')!=null) {
		if(document.getElementById('isi-buttons') != null){
			topVal = $('toolbar-wrap').getPosition().y - 80;
		}else{
			topVal = $('toolbar-wrap').getPosition().y - 30;
		}		
	}
	if(document.getElementById('footer-wrap-l')!=null && document.getElementById('toolbar-wrap-bottom')!=null) {
		if(topic == 'Benefits' || topic == 'Safety'){
			bottom = $('footer-wrap-l').getPosition().y - $('toolbar-wrap-bottom').getPosition().y;
		}else{
			bottom = $('footer-wrap-l').getPosition().y - $('toolbar-wrap-bottom').getPosition().y;
		}
	}
}

function resetToolbar() {
	//var slideEffect = new Fx.Style('toolbar-wrap', 'margin-top', {wait:false, duration:600, transition:Fx.Transitions.circOut});
	//var top = $('toolbar-wrap').getPosition().y - 30;
	  window.addEvent('scroll', function(){
	    slideEffect.start.delay(100, slideEffect, Math.max(0, window.getScrollTop() - topVal));
	  });
}

//function called in offline version of Medversation
function ShowMsg(){
	alert('This link is not available for offline version');
}

//This functionality is called in offline version of Medversation for view larger image
function submitFigurePopupOffline(document_number, figure_number){
	var ext_path ="";
	var url = location.href;
	url = url.toLowerCase();	
	
	if(url.indexOf("medversation/showbibliography/pageno")>-1){
		ext_path = "../../../../"; 
	}
	else if(url.indexOf("medversation/showbibliography/sort")>-1){
		ext_path = "../../"; 
	}
	else if(url.indexOf("medversation/hcp")>-1 ||url.indexOf("medversation/consumer/")>-1){
		ext_path = "../../"; 
	}
	else if(url.indexOf("medversation/home")>-1 ||url.indexOf("medversation/mainlibrary")>-1){
		ext_path = "../";
	}

	popImage(ext_path + figure_number,'Image');
}