function OpenPage(LinkURL, WindowName, iWidth, iHeight, Scrollbars)
{
	var iLeft = (screen.width / 2) - (iWidth / 2);
	var iTop = (screen.height / 2) - (iHeight / 2);
	var strScrollbars="";
	if (Scrollbars=="1"){strScrollbars=",scrollbars=yes";}
	window.open(LinkURL,WindowName,"width=" + iWidth + ",height=" + iHeight + ",left=" + iLeft + ",top=" + iTop + strScrollbars);
}

function SendPage(strURL)
{
OpenPage("/Email/sendpage.asp?Title=" + encodeURIComponent(document.title) + "&Page=" + encodeURIComponent(strURL),"PDIEmailPage","500","580");
}

function ReloadSubmissionList(sPageNum)
{
	document.DrugSubmitFormList.action="drug_submissions.asp?ChangeSort=on&PageNum=" + sPageNum;
	document.DrugSubmitFormList.target="";
	document.DrugSubmitFormList.submit();
}

function ReloadForumList(sQueryString)
{
	document.DrugForumList.action="drug_forums.asp?" + sQueryString;
	document.DrugForumList.target="";
	document.DrugForumList.submit();
}

function ReloadDiscussionList(sPageNum)
{
	document.DrugForumList.action="prescription_drug_discussions.asp?ChangeSort=on&PageNum=" + sPageNum;
	document.DrugForumList.target="";
	document.DrugForumList.submit();
}

function ReloadHelpTopicList(sPageNum)
{
	document.UrgentTopicsForm.action="urgent_topics.asp?ChangeSort=on&PageNum=" + sPageNum;
	document.UrgentTopicsForm.target="";
	document.UrgentTopicsForm.submit();
}

function ReloadHotTopicList(sPageNum)
{
	document.HotTopicsForm.action="hot_topics.asp?ChangeSort=on&PageNum=" + sPageNum;
	document.HotTopicsForm.target="";
	document.HotTopicsForm.submit();
}

function ReloadMHealthTopicList(sPageNum)
{
	document.UrgentTopicsForm.action="mental_health_discussions.asp?ChangeSort=on&PageNum=" + sPageNum;
	document.UrgentTopicsForm.target="";
	document.UrgentTopicsForm.submit();
}

function ReloadRecentEmailTopicList(sPageNum)
{
	document.TopicsForm.action="recent_emails.asp?ChangeSort=on&PageNum=" + sPageNum;
	document.TopicsForm.target="";
	document.TopicsForm.submit();
}

function FindMatchingDrugs()
{
//document.all.dresults.src="drug_search_iframe.asp?q=" + document.DrugMatchForm.DrugName.value;
dresults.location.replace("drug_search_iframe.asp?q=" + document.DrugMatchForm.DrugName.value);
event.returnValue=false;
}

function SigLinePreview()
{
	var sDispName=document.form.DispName.value;
	if (sDispName != ""){sDispName="<b>" + sDispName + "</b><br>"}
	var sLocation=document.form.Location.value;
	if (sLocation != ""){sLocation="<i>" + sLocation + "</i><br>"}
	var sWebSite=document.form.WebSite.value;
	if (sWebSite != "" && sWebSite != "http://"){sWebSite="<a href=\"" + sWebSite + "\" target=winb>" + sWebSite + "</a>"}else{sWebSite=""}
	
	document.all.siglineprev.innerHTML=sDispName + sLocation + sWebSite;
}

function ismaxlength(obj,shownumspan)
{
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
	if (shownumspan != "")
	{
		eval("document.all." + shownumspan + ".innerHTML=obj.value.length + ' / ' + mlength + ' characters'");
	}
}

/* highlight functions originally from: * * http://www.nsftools.com/misc/SearchAndHighlight.htm * *
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font class='notice'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}
/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      //alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.all.searchres.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.all.searchres.innerHTML = bodyText;
  return true;
}

function google_ad_request_done(google_ads) {

/*
* This function is required and is used to display
* the ads that are returned from the JavaScript
* request. You should modify the document.write
* commands so that the HTML they write out fits
* with your desired ad layout.
*/
var s = '';
var i;

/*
* Verify that there are actually ads to display.
*/
if (google_ads.length == 0) {
return;
}

/*
* If an image or flash ad is returned, display that ad.
* Otherwise, build a string containing all of the ads and
* then use a document.write() command to print that string.
*/


if (google_ads[0].type == "flash") {

s += '<a href=\"' + 
google_info.feedback_url + '\" class="gadtitle">Ads by Google</a><br>' + 
'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="' + 
google_ad.image_width + '" HEIGHT="' + 
google_ad.image_height + '"> <PARAM NAME="movie" VALUE="' + 
google_ad.image_url + '">' + 
'<PARAM NAME="quality" VALUE="high">' + 
'<PARAM NAME="AllowScriptAccess" VALUE="never">' + 
'<EMBED src="' + 
google_ad.image_url + '" WIDTH="' + 
google_ad.image_width + '" HEIGHT="' + 
google_ad.image_height + 
'" TYPE="application/x-shockwave-flash"' + 
' AllowScriptAccess="never" ' + 
' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';


} else if (google_ads[0].type == "image") {


   s += '<a href=\"' + 
google_info.feedback_url + '\" class="gadtitle">Ads by Google</a><br> <a href="' + 
google_ads[0].url + '" target="_top" title="go to ' + 
google_ads[0].visible_url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
google_ads[0].visible_url + '\';return true"><img border="0" src="' + 
google_ads[0].image_url + '"width="' + 
google_ads[0].image_width + '"height="' + 
google_ads[0].image_height + '"></a>';


} else if (google_ads[0].type == "html") {


s += google_ads[0].snippet;


} else {


if (google_ads.length == 1) {
/*
* Partners should adjust text sizes
* so ads occupy the majority of ad space.
*/
   s += '<a href=\"' + 
google_info.feedback_url + '\" class="gadtitle">Ads by Google</a><br><br><a style="align:center;text-decoration:none" href="' + 
google_ads[0].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
google_ads[0].visible_url + '\';return true"><span style="text-decoration:underline;font-size:20pt"> <b>' + 
google_ads[0].line1 + '</b><br></span></a> <span style="color:#000000;font-size:16pt">' +
google_ads[0].line2 + '<br>' +
google_ads[0].line3 + '<br></span> <a style="text-decoration:none" href="' + 
google_ads[0].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
google_ads[0].visible_url + '\';return true"><span>' + 
google_ads[0].visible_url + '</span></a><br>';

} else if (google_ads.length > 1) {

   s += '<a href=\"' + google_info.feedback_url + '\" class="gadtitle">Ads by Google</a><br><img src="http://psdruginfo.com/images/blank.gif" border=0 width=1 height=10>' 

  /*
  * For text ads, append each ad to the string.
  */

for(i = 0; i < google_ads.length; ++i) {

s += '<br><a href="' + 
google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
google_ads[i].visible_url + '\';return true">' + 
google_ads[i].line1 + '</b></a><br>' +
google_ads[i].line2 + ' ' +
google_ads[i].line3 + '<br><a class="smallsoft" style="text-decoration:none;font-weight:normal" href="' + 
google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
google_ads[i].visible_url + '\';return true"><span>' + 
google_ads[i].visible_url + '</span></a><br>';
}

if (google_ads[0].bidtype == "CPC") { /* insert this snippet for each ad call */ 
google_adnum = google_adnum + google_ads.length;
}

}
    }

    document.write(s);
    return;
}

function dspads()
{
	//document.getElementById('topad').parentNode.replaceChild(document.getElementById('topadB'),document.getElementById('topad'));
	parent.frames["topad"].location.href="/includes/728x90.htm";
	parent.frames["navbottomad"].location.href="/includes/160x600.htm";
}

/*AJAX related functions below * * * * * * * * * * * * */
function GetXmlHttpObjectCookie()
{
var xmlHttpCookie=null;
try
  {
  /* Firefox, Opera 8.0+, Safari*/
  xmlHttpCookie=new XMLHttpRequest();
  }
catch (e)
  {
  /* Internet Explorer*/
  try
    {
    xmlHttpCookie=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttpCookie=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttpCookie;
}

var xmlHttpCookie;

function GetCookie(sCookie,sField,sCode)
{ 
	xmlHttpCookie=GetXmlHttpObjectCookie();
	if (xmlHttpCookie==null)
	  {
	  return;
	  }
	var url="/includes/getcookie.asp?sid=" + Math.random() + "&c=" + escape(sCookie);
	xmlHttpCookie.onreadystatechange=function (){ 
		if (xmlHttpCookie.readyState==4)
		{
			eval(sField + "=xmlHttpCookie.responseText");
			if (sCode != "")
			{
				eval(sCode);
			}
		}
	}
	xmlHttpCookie.open("GET",url,true);
	xmlHttpCookie.send(null);
}