

/*
jQuery.extend({
   getScript: function(url, callback) {
      var head = document.getElementsByTagName("head")[0];
      var script = document.createElement("script");
      script.src = url;

      // Handle Script loading
      {
         var done = false;

         // Attach handlers for all browsers
         script.onload = script.onreadystatechange = function(){
            if ( !done && (!this.readyState ||
                  this.readyState == "loaded" || this.readyState == "complete") ) {
               done = true;
               if (callback)
                  callback();

               // Handle memory leak in IE
               script.onload = script.onreadystatechange = null;
            }
         };
      }

      head.appendChild(script);

      // We handle everything using the script element injection
      return undefined;
   }//, DS: IE doesn't like a trailing comma here
});
*/


$.urlParam = function(name){
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
	if (!results) { return 0; }
	return results[1] || 0;
	}


function gnLoadScript (url, callback) {
      var head = document.getElementsByTagName("head")[0];
      var script = document.createElement("script");
      script.src = url;

      // Handle Script loading
      {
         var done = false;

         // Attach handlers for all browsers
         script.onload = script.onreadystatechange = 
		 function() {
		    if ( !done && (!this.readyState ||  this.readyState == "loaded" || this.readyState == "complete") ) {
		       done = true;
		       if (callback)
			  callback();

		       // Handle memory leak in IE
		       script.onload = script.onreadystatechange = null;
		    }
		 };
      }

      head.appendChild(script);

      // We handle everything using the script element injection
      return undefined;
   }

function gnRequireScripts(scriptArray, callback) {

	if (scriptArray.length>0) {
	
		gnLoadScript(scriptArray[0],function () {gnRequireScripts(scriptArray.slice(1),callback);});
	}
	else if (callback) {
		callback();
	}
}


function nsTop (item) {
	
	var scrollArea = $("#scrollArea")?$("#scrollArea"):$("#scrollAreaShort");
	
	if (scrollArea) {
		if (scrollArea.scrollTop()==0) {
			
			scrollArea.scrollTo(item.attr("hash"),100)
			$("#navigation a").removeClass("active");
			$(item).addClass("active");

		}
		else {
			scrollArea.scrollTo("#ns-monograph-top",100)
			$("#navigation a").removeClass("active");
						

		}
	}
		
}

function nsSizeScroll() {
	if ($("#scrollArea").length>0) {
	
		var pos =$("#scrollArea").offset();
		var top = 227; //pos.top;

		

		var properheight= Math.min (530,$(window).height()-top) -10;
		
	
		if (properheight>370) {
			$("#scrollArea").height(properheight);
		if ($("#leftNavInner")) {
			$("#leftNavInner").height(properheight);
			}
		}
	}

}



var abstractLoginDiv="<div id='ns-abstract-login'>";
abstractLoginDiv+="<p>If you have a Natural Standard subscription, login to view the full monograph below:</p>";
abstractLoginDiv+="<p><a href='/login.asp'>Login</a><a href='/subscribe.asp'>Subscribe</a></p><div class='clear'></div></div>";

nsClearDiv ="<div class='ns-clear'><!-- --></div>";


function coBrandHeader() {

	// GAS - November, 2010: Added logic to swap out header for co-branding logo... 
	// CTW - December 2010: Misc updates
	// CTW - July 2011: Modified to use CSS order precendence to make this less verbose
	

	// CTW 7/2011  All get the default (should actually be in the main css file)
	
	$('head').append('<link href="/library/partners/css/defaultLogo.css" rel="stylesheet" type="text/css" />');



	// CTW 7/2011 *Some* get overrides of the image
	
	if (location.hostname!="naturalstandard.com") {
	
		switch (location.hostname) {
		
	// 7/21/2011 -- Most cases now handled by the dynamic CSS in default case at end of switch

	// 7/18/2011

			case ("auburn.naturalstandard.com"): $('head').append('<link href="/library/partners/css/auburn.css" rel="stylesheet" type="text/css" />'); break;
			case ("echn.naturalstandard.com"): $('head').append('<link href="/library/partners/css/echn.css" rel="stylesheet" type="text/css" />'); break;
			case ("husson.naturalstandard.com"): $('head').append('<link href="/library/partners/css/husson.css" rel="stylesheet" type="text/css" />'); break;
			case ("jwu.naturalstandard.com"): $('head').append('<link href="/library/partners/css/jwu.css" rel="stylesheet" type="text/css" />'); break;
			//case ("mercy.naturalstandard.com"): $('head').append('<link href="/library/partners/css/mercy.css" rel="stylesheet" type="text/css" />'); break;
			case ("munson.naturalstandard.com"): $('head').append('<link href="/library/partners/css/munson.css" rel="stylesheet" type="text/css" />'); break;
			case ("publix.naturalstandard.com"): $('head').append('<link href="/library/partners/css/publix.css" rel="stylesheet" type="text/css" />'); break;



	// Earlier
			case ("lvhn.naturalstandard.com"): $('head').append('<link href="/library/partners/css/lvhn.css" rel="stylesheet" type="text/css" />'); break;
			case ("stjohns.naturalstandard.com"): $('head').append('<link href="/library/partners/css/stjohns.css" rel="stylesheet" type="text/css" />'); break;
			case ("scnm.naturalstandard.com"): $('head').append('<link href="/library/partners/css/scnm.css" rel="stylesheet" type="text/css" />'); break;
			case ("ihc.naturalstandard.com"): $('head').append('<link href="/library/partners/css/ihc.css" rel="stylesheet" type="text/css" />'); break;
			case ("seattlechildrens.naturalstandard.com"): $('head').append('<link href="/library/partners/css/seattlechildrens.css" rel="stylesheet" type="text/css" />'); break;
			case ("tmhs.naturalstandard.com"): $('head').append('<link href="/library/partners/css/tmhs.css" rel="stylesheet" type="text/css" />'); break;
			case ("nyu.naturalstandard.com"): $('head').append('<link href="/library/partners/css/nyu.css" rel="stylesheet" type="text/css" />'); break;
			case ("uws.naturalstandard.com"): $('head').append('<link href="/library/partners/css/uws.css" rel="stylesheet" type="text/css" />'); break;
			case ("utoronto.naturalstandard.com"): $('head').append('<link href="/library/partners/css/utoronto.css" rel="stylesheet" type="text/css" />'); break;
			case ("sw.naturalstandard.com"): $('head').append('<link href="/library/partners/css/sw.css" rel="stylesheet" type="text/css" />'); break;
			case ("rexhealth.naturalstandard.com"): $('head').append('<link href="/library/partners/css/rexhealth.css" rel="stylesheet" type="text/css" />'); break;
			case ("depaul.naturalstandard.com"): $('head').append('<link href="/library/partners/css/dePaul.css" rel="stylesheet" type="text/css" />'); break;
			case ("uvic.naturalstandard.com"): $('head').append('<link href="/library/partners/css/uvic.css" rel="stylesheet" type="text/css" />'); break;
			case ("mainemedical.naturalstandard.com"): $('head').append('<link href="/library/partners/css/mainemedical.css" rel="stylesheet" type="text/css" />'); break;
			case ("tampava.naturalstandard.com"): $('head').append('<link href="/library/partners/css/tampava.css" rel="stylesheet" type="text/css" />'); break;
			case ("vanthcs.naturalstandard.com"): $('head').append('<link href="/library/partners/css/vanthcs.css" rel="stylesheet" type="text/css" />'); break;

			case ("ecu.naturalstandard.com.jproxy.lib.ecu.edu"): $('head').append('<link href="/library/partners/css/ecu.css" rel="stylesheet" type="text/css" />'); break;
			case ("ecu.naturalstandard.com"): $('head').append('<link href="/library/partners/css/ecu.css" rel="stylesheet" type="text/css" />'); break;
			case ("naturalstandard.com.jproxy.lib.ecu.edu"): $('head').append('<link href="/library/partners/css/ecu.css" rel="stylesheet" type="text/css" />'); break;


			case ("sjfc.naturalstandard.com"): $('head').append('<link href="/library/partners/css/sjfc.css" rel="stylesheet" type="text/css" />'); break;
			case ("uvm.naturalstandard.com"): $('head').append('<link href="/library/partners/css/uvm.css" rel="stylesheet" type="text/css" />'); break;
			case ("ministryhealth.naturalstandard.com"): $('head').append('<link href="/library/partners/css/ministryhealth.css" rel="stylesheet" type="text/css" />'); break;
			case ("uclibraries.naturalstandard.com"): $('head').append('<link href="/library/partners/css/ucsf.css" rel="stylesheet" type="text/css" />'); break;
			case ("southuniversity.naturalstandard.com"): $('head').append('<link href="/library/partners/css/southuniversity.css" rel="stylesheet" type="text/css" />'); break;
			case ("lhs.naturalstandard.com"): $('head').append('<link href="/library/partners/css/lhs.css" rel="stylesheet" type="text/css" />'); break;
			case ("hawaii.naturalstandard.com"): $('head').append('<link href="/library/partners/css/hawaii.css" rel="stylesheet" type="text/css" />'); break;
			case ("drake.naturalstandard.com"): $('head').append('<link href="/library/partners/css/drake.css" rel="stylesheet" type="text/css" />'); break;
			case ("smh.naturalstandard.com"): $('head').append('<link href="/library/partners/css/smh.css" rel="stylesheet" type="text/css" />'); break;
			case ("newcastle.naturalstandard.com"): $('head').append('<link href="/library/partners/css/newcastle.css" rel="stylesheet" type="text/css" />'); break;
			case ("olemiss.naturalstandard.com"): $('head').append('<link href="/library/partners/css/olemiss.css" rel="stylesheet" type="text/css" />'); break;
			case ("presby.naturalstandard.com"): $('head').append('<link href="/library/partners/css/presby.css" rel="stylesheet" type="text/css" />'); break;
			case ("roswellpark.naturalstandard.com"): $('head').append('<link href="/library/partners/css/roswellpark.css" rel="stylesheet" type="text/css" />'); break;
			case ("stlcop.naturalstandard.com"): $('head').append('<link href="/library/partners/css/stlcop.css" rel="stylesheet" type="text/css" />'); break;
			case ("lomalinda.naturalstandard.com"): $('head').append('<link href="/library/partners/css/lomalinda.css" rel="stylesheet" type="text/css" />'); break;
			case ("0-lomalinda.naturalstandard.com.catalog.llu.edu"): $('head').append('<link href="/library/partners/css/lomalinda.css" rel="stylesheet" type="text/css" />'); break;
			case ("uc.naturalstandard.com"): $('head').append('<link href="/library/partners/css/uc.css" rel="stylesheet" type="text/css" />'); break;
			case ("nydh.naturalstandard.com"): $('head').append('<link href="/library/partners/css/nydh.css" rel="stylesheet" type="text/css" />'); break;
			case ("ocom.naturalstandard.com"): $('head').append('<link href="/library/partners/css/ocom.css" rel="stylesheet" type="text/css" />'); break;
			case ("humber.naturalstandard.com"): $('head').append('<link href="/library/partners/css/humber.css" rel="stylesheet" type="text/css" />'); break;
			case ("webster.naturalstandard.com"): $('head').append('<link href="/library/partners/css/webster.css" rel="stylesheet" type="text/css" />'); break;
			case ("ezproxy.mnl.umkc.edu/login?url=http://umkc.naturalstandard.com/"): $('head').append('<link href="/library/partners/css/umkc.css" rel="stylesheet" type="text/css" />'); break;
			case ("ezproxy.mnl.umkc.edu/login?url=http://umkc.naturalstandard.com"): $('head').append('<link href="/library/partners/css/umkc.css" rel="stylesheet" type="text/css" />'); break;
			case ("umkc.naturalstandard.com"): $('head').append('<link href="/library/partners/css/umkc.css" rel="stylesheet" type="text/css" />'); break;
			case ("ah.naturalstandard.com"): $('head').append('<link href="/library/partners/css/ah.css" rel="stylesheet" type="text/css" />'); break;
			case ("acphs.naturalstandard.com"): $('head').append('<link href="/library/partners/css/acphs.css" rel="stylesheet" type="text/css" />'); break;
			case ("ihdm.naturalstandard.com"): $('head').append('<link href="/library/partners/css/ihdm.css" rel="stylesheet" type="text/css" />'); break;
			case ("lewis.naturalstandard.com"): $('head').append('<link href="/library/partners/css/lewis.css" rel="stylesheet" type="text/css" />'); break;
			case ("lsuhsc.naturalstandard.com"): $('head').append('<link href="/library/partners/css/lsuhsc.css" rel="stylesheet" type="text/css" />'); break;
			case ("macneal.naturalstandard.com"): $('head').append('<link href="/library/partners/css/macneal.css" rel="stylesheet" type="text/css" />'); break;
			case ("vmacmemphis.naturalstandard.com"): $('head').append('<link href="/library/partners/css/vmacmemphis.css" rel="stylesheet" type="text/css" />'); break;
			case ("aamc.naturalstandard.com"): $('head').append('<link href="/library/partners/css/aamc.css" rel="stylesheet" type="text/css" />'); break;
			case ("logan.naturalstandard.com"): $('head').append('<link href="/library/partners/css/logan.css" rel="stylesheet" type="text/css" />'); break;
			case ("huntington.naturalstandard.com"): $('head').append('<link href="/library/partners/css/huntington.css" rel="stylesheet" type="text/css" />'); break;
			case ("uab.naturalstandard.com"): $('head').append('<link href="/library/partners/css/uab.css" rel="stylesheet" type="text/css" />'); break;
			case ("wellstar.naturalstandard.com"): $('head').append('<link href="/library/partners/css/wellstar.css" rel="stylesheet" type="text/css" />'); break;
			case ("broadlawns.naturalstandard.com"): $('head').append('<link href="/library/partners/css/broadlawns.css" rel="stylesheet" type="text/css" />'); break;
			case ("avahcs.naturalstandard.com"): $('head').append('<link href="/library/partners/css/avahcs.css" rel="stylesheet" type="text/css" />'); break;
			case ("mwu.naturalstandard.com"): $('head').append('<link href="/library/partners/css/mwu.css" rel="stylesheet" type="text/css" />'); break;
			case ("chc.naturalstandard.com"): $('head').append('<link href="/library/partners/css/chc.css" rel="stylesheet" type="text/css" />'); break;
			case ("dpl.naturalstandard.com"): $('head').append('<link href="/library/partners/css/dpl.css" rel="stylesheet" type="text/css" />'); break;
			case ("progressive.naturalstandard.com"): $('head').append('<link href="/library/partners/css/progressive.css" rel="stylesheet" type="text/css" />'); break;
			case ("mccormick.naturalstandard.com"): $('head').append('<link href="/library/partners/css/mccormick.css" rel="stylesheet" type="text/css" />'); break;
			case ("herbalife.naturalstandard.com"): $('head').append('<link href="/library/partners/css/herballife2.css" rel="stylesheet" type="text/css" />'); break;
			case ("bridgepointhealth.naturalstandard.com"): $('head').append('<link href="/library/partners/css/bridgepoint.css" rel="stylesheet" type="text/css" />'); break;
			case ("herballife.naturalstandard.com"): $('head').append('<link href="/library/partners/css/herballife2.css" rel="stylesheet" type="text/css" />'); break;
			case ("hormel.naturalstandard.com"): $('head').append('<link href="/library/partners/css/hormel2.css" rel="stylesheet" type="text/css" />'); break;
			case ("yale.naturalstandard.com"): $('head').append('<link href="/library/partners/css/yale.css" rel="stylesheet" type="text/css" />'); break;
			case ("kcls.naturalstandard.com"): $('head').append('<link href="/library/partners/css/KCL.css" rel="stylesheet" type="text/css" />'); break;
			case ("kcl.naturalstandard.com"): $('head').append('<link href="/library/partners/css/KCL.css" rel="stylesheet" type="text/css" />'); break;
			case ("horizon.naturalstandard.com"): $('head').append('<link href="/library/partners/css/horizon.css" rel="stylesheet" type="text/css" />'); break;
			//default: $('head').append('<link href="/library/partners/css/defaultLogo.css" rel="stylesheet" type="text/css" />');
			
			// 7/21/2011 CTW
			default: 
			partner = location.hostname.substring(0,location.hostname.indexOf("."));
			$('head').append('<link href="/library/partners/css/_default_partner_css.asp?partner=' + partner+'" rel="stylesheet" type="text/css" />');
		}
	}
	

}


function nsIE6 ($) {
	$("span.wbr").text(" ")
}


function nsInit() {


	// CTW - do this in a function call
	
	coBrandHeader()


	// GAS- Dec, 2010: Placed the function call below here and commented it out at the bottom of the mldmenu.js file to resolve loading issue.
	
	mlddminit();
	
	// - End co-branding logo logic.	
	
	nsSizeScroll();
	
	$(window).resize (function() {nsSizeScroll();});

	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		nsIE6($);
	}
	
	if (($('#navigation').length>0) || ($('#navigation-short').length>0)) {
	
		gnRequireScripts([	"/library/scripts/clientside/jquery.scrollTo-1.4.2-min.js",
					"/library/scripts/clientside/jquery.localscroll-1.2.7-min.js"], 
				function () {	
					$('#navigation').localScroll({ target:'#scrollArea', queue:true, duration:100 });
					$('#navigation a').click (function() {
						$("#navigation a").removeClass("active");
						$(this).addClass("active");
						
						}
					);
					
					$('#navigation-short').localScroll({ target:'#scrollAreaShort', queue:true, duration:100 });
					$('#navigation-short a').click (function() {
						$("#navigation-short a").removeClass("active");
						$(this).addClass("active");

						}
					);

					
					$('#navigation li:first-child a').click (function() {nsTop($(this))});
					
					
					
				});
	}


	$("#ns-news   #navigation-short li:first-child a").addClass ("active");
	$("#ns-events #navigation-short li:first-child a").addClass ("active");
	
	$('table#ns-table-professional-evidence-review th').wrapInner('<a  href="/explanation.asp"/>');
	/*
	if ($('div.ns-monograph').length>0)  {
	
		gnRequireScripts([	"/library/scripts/clientside/jquery.titlecase.js"], 
					function () {	
						$("div.ns-flashcard h3").toTitleCase();
						//$("div.pageHdr").toTitleCase();
						
						
				});
		
	}
	*/
	
	$("#generated-abstract #monograph-content").before(abstractLoginDiv);
	$("#generated-abstract span.brand-intro").after(abstractLoginDiv);
	
	$("#footer").before(nsClearDiv);
	
	$("table#ns-table-bottomline-evidence:not(.foreignlanguage) td.ns-condition p strong").wrapInner('<a onclick="nsLinkCondition(this)" href="#"/>');

	$("table#ns-table-professional-evidence td.ns-condition p strong").wrapInner('<a onclick="nsLinkCondition(this)" href="#"/>');
	
	
	$('a#ns-grading-system img').attr("src","/library/images/grading_system.gif");
	
	$('a#ns-grading-system img').hover(
		function() {
		$(this).attr("src","/library/images/grading_system2.gif");
			}, 
		function() {
		$(this).attr("src","/library/images/grading_system.gif");
		});

	$("table:not(.foreignlanguage) td.ns-grade p ").wrapInner('<a  href="/grading.asp"/>');
	
	$("table:not(.foreignlanguage) th.ns-class-grade p ").wrapInner('<a  href="/grading.asp"/>');

	if ($.urlParam("text")) {
		$("input.searchForm").val(decodeURIComponent($.urlParam("text").replace(/\+/gi," ")));
	}
		
	    $("input.searchForm").focus(function() {
	        if ($(this).val() == "Search") {
	            $(this).val("");
	        }
	    });
	    $("input.searchForm").blur(function() {
	        if ($(this).val() == "") {
	            $(this).val("Search");
	        }
	    });
	    
	    
	    //Dictionary init
	
	    $("#defineArea_left input").focus(function() {
		if ($(this).val() == "Define") {
			 $(this).val("");
			}
	     });

	    $("#defineArea_left input").blur(function() {
		if ($(this).val() == "") {
			 $(this).val("Define");
			}
	     });
		    
		   var dictionaryResult = $("#showResults");
		   
		   if (dictionaryResult.length>0 && dictionaryResult.text() =="") {
			dictionaryResult.text("Result");
	    }


	$("#ns-template-simple div.ns-brand ul:gt(0) li").wrapInner('<a  onclick="brandSearch($(this));" href="#"/>');

	$("#ns-template-simple div.ns-brand ul:gt(0) li strong").unwrap();
	
	
	$("#tabs li:last-child").addClass('last-child');
	$("th:last-child").addClass('last-child');
	
	if(window.CE_OFFERINGS) {
		var offering = CE_OFFERINGS[getCurrentTopic()];
		if(offering) {
			$("div.tools ul").prepend('<li class="takeCE"><a href="'+offering+'" onclick="doHostedAssessment(this.href); return false">Take CE/CME</a></li>');
		}
	}
	
	$("li.print").click (function () {
		
		if(isMonograph()) {
			newWindow("/mono-print.asp?file="+(window._pdfURL || location.pathname));
			if(window.event) event.returnValue = false;
			return false;
			
		}
		else {
			window.print();
		}
		
		
	});	
	
	if(isMonograph()) {
		$("div.tools li.print").after('<li class="eMail"><a href="#">eMail</a></li>');
		$("div.tools li.eMail").click (function () {
			newWindow("/mono-email.asp?file="+(window._pdfURL || location.pathname));
			if(window.event) event.returnValue = false;
			return false;
		});
	}

}

function isMonograph () {
	return window._isMonograph ? true : false;
}

function getCurrentTopic () {
	var loc = location.href;
	var str = loc.substring(loc.lastIndexOf("/")+1, loc.indexOf(".asp"));
	
	return str.replace(/^(patient|flashcard|refs|topicnews)[-_]/i, "");
}

function nsLinkCondition (item) {
	document.location ="/databases/effectiveness/ex/nslinkcondition.asp?title=" +item.innerHTML
	
}


function doLink (item) {
	doPubMedLink(item);
	//document.location ="/databases/effectiveness/ex/nslinkcondition.asp?title=" +item.innerHTML
	
}

function getSearchTerm(name){
 name += "";
 name = name.replace(/ seed|herb| leaf| leaves| extract| powder| fruit| flower| complex| oil| syrup| root| blend/gi, "");
 name = name.replace(/^\d+%/, "");
 name = name.replace(/\s+/g, " ");
 return trim(name);
}

function trim (str){
 str += "";
 str = str.replace(/^\s+/, ""); 
 str = str.replace(/\s+$/, "");
 return str;
}

function brandSearch(link) {

		
	var item=link.text();
	
	item= item.replace(/~/gi,"'");

	item= item.replace(/&/gi,"");
	
	item=item.replace(/ and /gi," ");
	
	if (item.indexOf(" - ")>0) {
		item = item.substring(0,item.indexOf(" - "));
	}

	if (item.indexOf("(")>0) {
		item = item.substring(0,item.indexOf("("));
	}

	item=getSearchTerm(item);


	
	document.location = "/search.asp?text=" +item;
	return(false);

}


/* Legacy Code */

var CMWindow = null;

function NewWinFull(url, scrollbars) {
	var width= screen.availWidth-6;
	var height=screen.availHeight-32;
	CMWindow=open(url,"_blank",'top=0,left=0,toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,resizable=yes,directories=no,width=' + width+',height='+height);

	CMWindow.resizeTo ( screen.availWidth, screen.availHeight);
	if (CMWindow.focus != null) {
		CMWindow.focus()
	}
}


function NewWinSmall(url, scrollbars) {
	var width= 500;
	var height=350;
 	CMWindow=open(url,"_blank",'top=0,left=0,toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,resizable=yes,directories=no,width=' + width+',height='+height);

	if (CMWindow.focus != null) {
    		CMWindow.focus()
  	}
}



function doAssessment(v1,v2,v3,v4) {
	alert("To be implemented...");
	return false;
	if (v1.indexOf("offsite-")>0) {

		NewWinSmall(v1);

	}
	else {

		NewWinFull("/ContinuingEducation/hosted/start_assessment.asp?assessment=" + v1.substring(v1.lastIndexOf("/")+1, v1.indexOf(".htm")));
	}
}


function doHostedAssessment(url) {
	NewWinFull(url);
}



 function newWindow(url, scrollbars, isPubMed) {

 	var CMWindow=open(url,"_blank",'top=0,left=0,toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,resizable=yes,directories=no,width=780,height=530');

	if (CMWindow.focus != null) {
	 	CMWindow.focus()
	 }
} 


function getCookieValue (name) {
	 var nameEQ = name + "=";
	 var ca = document.cookie.split(';');
	 var str = "";

	 for(var i=0;i < ca.length;i++) {
		 var c = ca[i];
		 while (c.charAt(0)==' ') c = c.substring(1,c.length);

		 if (c.indexOf(nameEQ) == 0) {
			try {
				str = decodeURIComponent(c.substring(nameEQ.length,c.length));
				}
			catch (e) {
				return "";
			 }
			return str;
		 }
	 }
	 return str;
}

function getSpecialArgs() {

 // DS: new implementation using cookie set with pub med parameters from database

 var specialArgs = getCookieValue("PubMedCookie");

 return specialArgs ? "&"+specialArgs : "";

 /*********************** DS: not used, but retained for reference ***********

 if (ck.indexOf("User=IPAccessAllowed%3AYale")>=0){
 specialArgs+="&otool=yalelib"
 }

 if (ck.indexOf("User=IPAccessAllowed%3ALehigh")>=0){
 specialArgs+="&holding=palvhlib_fft"
 }

 if (ck.indexOf("User=IPAccessAllowed%3ASarasota")>=0){
 specialArgs+="&holding=fluzesllib"
 }

 if (ck.indexOf("User=IPAccessAllowed%3AVanderbilt")>=0){
 specialArgs+="&holding=vandylib"
 }

 if (ck.indexOf("User=IPAccessAllowed%3AMassachusetts+College+of+Pharmacy")>=0){
 specialArgs+="&holding=mcplib"
 }
 if (ck.indexOf("User=IPAccessAllowed%3AWake+Forest+U")>=0){
 specialArgs+="&holding=wfusmlib"
 }
 if (ck.indexOf("User=IPAccessAllowed%3AUniversity+of+Virginia")>=0){
 specialArgs+="&holding=uvirlib"
 }
 if (ck.indexOf("User=IPAccessAllowed%3AUCONN")>=0){
 specialArgs+="&holding=uchclib"
 }
 if (ck.indexOf("User=IPAccessAllowed%3AMaine+Medical+Center")>=0){
 specialArgs+="&holding=memclib_fft"
 }
 if (ck.indexOf("User=IPAccessAllowed%3AKaiser+Permanente")>=0){
 specialArgs+="&holding=cakpkclib"
 }

 return(specialArgs);

 ***************************************************/
}

function getCustomCitationLink (url, id, params) {
 var str = url +"?pmid="+id;
 if(params) {
 str += "&"+params;
 }
 return str;
}

function vcuCitation (url, arg, params) {
 // DS: Cusotm citation function for VCU

 params = getCookieValue("PubmedParams"); // DS: note "Pubmed" with a lower case m.

 var str = url +"?" + params + "&" + "id=pmid:"+encodeURIComponent(arg);


 return str;
}

// DS: The technique in VCU's custom function above works for the sfx link resolver system generally with "sid=NaturalStandard"

function sfxCitation (url, arg, params) {
	params = params || "";		
	params += (params ? "&" :"") + "sid=NaturalStandard";
	
	return url +"?" + params + "&" + "id=pmid:"+encodeURIComponent(arg);
}

function doPubMedLink (arg) {
 var url = getCookieValue("CitationURL");
 if (url && (url !="null")){
 var funcName = getCookieValue("CitationFunction");
 var params = getCookieValue("CitationParams");
 var func = getCustomCitationLink;
 if(funcName){
 func = window[funcName] || func;
 }

 newWindow(func(url, arg, params), "", true);
 }
 else {
 var specialArgs =getSpecialArgs();
 newWindow("http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&list_uids="+ arg +"&dopt=Abstract" + specialArgs, "", true);
 }
}

function doRefLink (arg) {

 var specialArgs =getSpecialArgs();

 while (arg.substring(0,1) == " ") {
 arg=arg.substring(1)

 }

 var loc = document.location.href
 var relref=""
 if ( loc.indexOf("/news/")>1 ) {
 relref="../../"
 }

 else if (loc.indexOf("glossary/")>1 )
 relref="../"
 else
 relref="../../"


 if (arg.length>2) {
 if (arg.substring(0,2)=="PM")
 //NewWin2("http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&list_uids="+ arg.substring(3) +"&dopt=Abstract" + specialArgs);
 doPubMedLink(arg.substring(3));
 else if (arg.substring(0,3)=="CN:")
 findAndLinkCondition(arg.substring(4) );

 else if (parseInt(arg).toString() == arg)
 NewWin2(relref+"glossary/glossary" + arg +".asp");
 else {
 ShowMonographInfo(arg, "herb", "");

 }
 }
 else if (parseInt(arg).toString() == arg)
 NewWin2("http://naturalstandard.com/monographs/glossary/glossary" + arg +".asp");
 else {
 if (window.event) {
 //alert (window.event.srcElement.innerText);

 ShowMonographInfo(arg, "herb",window.event.srcElement.innerText)
 }
 else {
 ShowMonographInfo(arg, "herb", "");
 }

 }
}



jQuery(document).ready(
	function ($){ 
		nsInit($);
	}
);
