

function goPatCondition () 
{
	var list = document.conditionPatientForm.conditionPatientSelect;
	if (list.options[list.selectedIndex].value=="nil") {
	alert ("Please select a condition");
	return;
	} else {
	location=list.options[list.selectedIndex].value;
	}
}
function goDocCondition () {
	var list = document.conditionDoctorForm.conditionDoctorSelect;
	if (list.options[list.selectedIndex].value=="nil") {
	alert ("Please select a condition");
	return;
	} else {
	location=list.options[list.selectedIndex].value;
	}
}
function goExperiences () {
	var list = document.experienceIndexForm.conditionSelect;
	if (list.options[list.selectedIndex].value=="nil" || 		list.options[list.selectedIndex].value=="") {
	alert ("Please select a condition");
	return;
	} else {
	location=list.options[list.selectedIndex].value;
	}
}
function goExperiencesD () {
	var list = document.experienceIndexFormD.conditionSelect;
		if (list.options[list.selectedIndex].value=="nil" || list.options[list.selectedIndex].value=="") {
	alert ("Please select a condition");
	return;
	} else {
	location=list.options[list.selectedIndex].value;
	}
}
function redirectToUrl(selectBox) {
	if (selectBox.selectedIndex != 0) {
		location = selectBox.options[selectBox.selectedIndex].value;
	} else {
		alert ("Please select a condition");
		return false;
	}
}
function openGlossary (uri) {
	var glossaryWindow=window.open (uri, "glossary_window", "height=275,width=470,scrollbars,resizable,menubar");
	glossaryWindow.focus();
}
function openBMICalc () 
{
	  bmiWin = window.open("", "bmicalc", "height=420,width=650,scrollbars=auto,resizable,menubar");
	  bmiWin.location.href= "../scripts/BmiCalculator.html";
	  bmiWin.focus();
}
function openMidasSurvey () 
{
	  bmiWin = window.open("", "bmicalc", "height=420,width=650,scrollbars=yes,resizable=yes,menubar=no,toolbar=no");
	  bmiWin.location.href= "../scripts/MidasSurvey.html";
	  bmiWin.focus();
}
function isEmpty (inputStr) {
	if (inputStr=="" || inputStr==null) {
		return true;
	}
	return false;
}
var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var maxVersion = 6;
var actualVersion = 0;
var hasRightVersion = false;
var jsVersion = 1.0;
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;
function detectFlash(requiredVersion, useRedirect, flashPage, noFlashPage, upgradePage)
{
	jsVersion = 1.1;
	
	if(isIE && isWin)
	{
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
		document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
		document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
		document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
		document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
		document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
	}
  if (navigator.plugins) 
  {
    if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) 
    {
      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
      var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
      flash2Installed = flashVersion == 2;
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion >= 6;
    }
  }
	for (var i = 2; i <= maxVersion; i++)
	{
		if (eval("flash" + i + "Installed") == true) actualVersion = i;
	}
  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 3;
  if (actualVersion >= requiredVersion)
  {
	if (useRedirect)
	{
		if(jsVersion > 1.0)
		{
			window.location.replace(flashPage);
		}
		else
		{
			window.location = flashPage;
		}
	}
	hasRightVersion = true;
  } 
  else 
  {
    if (useRedirect) 
    {
      if(jsVersion > 1.0) 
      {
        window.location.replace((actualVersion >= 2) ? upgradePage : noFlashPage);
      }
      else
      {
        window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
      }
    }
  }
}

function openPageRating() 
{

	var articleid = document.ratePage.article_id.value;
	var ratingid = null;
	var ratingPicked = false;
	
	for (i = 0; i < document.ratePage.rating_id.length; i++) 
	{
		if (document.ratePage.rating_id[i].checked) 
		{
			ratingid = document.ratePage.rating_id[i].value;
			ratingPicked = true;
			break;
		}
		
    }
	
	if(ratingPicked)
	{
		var w = 480, h = 400;

		if (document.all || document.layers) 
		{
		   w = screen.availWidth;
		   h = screen.availHeight;
		}

		var popW = 480, popH = 350;

		var leftPos = (w-popW)/2, topPos = (h-popH)/2;

		ratingWin = window.open("", "pageRating", "height=250,width=500,scrollbars=no,resizable=no,menubar=no,toolbar=no,top=" + topPos + ",left=" + leftPos);
		ratingWin.location.href= "../ratepagethankyou.jsp?articleId=" + articleid + "&rating=" + ratingid;
		ratingWin.focus();
	}
	else
	{
		alert("You must choose an article rating first");
	}
}

function openCERedirect(celink)
{
	var w = 480, h = 340;

	if (document.all || document.layers) 
	{
	   w = screen.availWidth;
	   h = screen.availHeight;
	}

	var popW = 300, popH = 200;

	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	var ceLinkWin = window.open("", "ceRedirect", "height=290,width=420,scrollbars=no,resizable=yes,menubar=no,toolbar=no,top=" + topPos + ",left=" + leftPos);
	ceLinkWin.location.href= "scripts/CERedirect.html?" + celink
	ceLinkWin.focus();
}

function openCERedirectFromDropDown(selectBox)
{
    if(selectBox.selectedIndex != 0)
    {
        var celink = 'scripts/CERedirect.jsp?ceLink=' + selectBox.options[selectBox.selectedIndex].value;
        return raw_popup(celink, '_blank');
    }
    else
    {
        alert ("Please select a condition");
        return false;
    }
}


function openCEWindow(celink)
{
    var day = new Date();
    var id = day.getTime();
	// We add this query string so apache mod_rewrite can see the user
	// is coming from btuk and act accordingly. Normally we'd use 
	// referer but that gets lost because of the new window
	celink = celink + '?btuk=1';
    var newWindow = window.open(celink, id ,'top=1,left=1,scrollbars=yes,toolbar=yes,resizable=yes,width=800,height=500,menubar=yes,location=yes');
}

function openCERedirectForArticles(celink)
{
	var w = 480, h = 340;

	if (document.all || document.layers) 
	{
	   w = screen.availWidth;
	   h = screen.availHeight;
	}

	var popW = 300, popH = 200;

	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	var ceLinkWin = window.open("", "ceRedirect", "height=290,width=420,scrollbars=no,resizable=yes,menubar=no,toolbar=no,top=" + topPos + ",left=" + leftPos);
	ceLinkWin.location.href= "../scripts/CERedirect.html?" + celink
	ceLinkWin.focus();
}


function openExternalSite(link)
{
	var w = 480, h = 340;

	if (document.all || document.layers) 
	{
	   w = screen.availWidth;
	   h = screen.availHeight;
	}

	var popW = 300, popH = 200;

	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	var ceLinkWin = window.open("", "ceRedirect", "height=290,width=420,scrollbars=no,resizable=yes,menubar=no,toolbar=no,top=" + topPos + ",left=" + leftPos);
	ceLinkWin.location.href= "../scripts/CERedirect.html?" + link
	ceLinkWin.focus();
}


function raw_popup(url, target)
{
	var w = 480, h = 340;

	if (document.all || document.layers)
	{
	   w = screen.availWidth;
	   h = screen.availHeight;
	}

	var popW = 300, popH = 200;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    var _POPUP_FEATURES = 'toolbar=0,scrollbars=0,resizable=1,menubar=0,width=420,height=290,top=' + topPos + ',left=' + leftPos;

    var theWindow = window.open(url + '&btuk=1', target, _POPUP_FEATURES);
    theWindow.focus();
    return theWindow;
}

function link_popup(src)
{
  return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank');
}
