function $$()
{
  /* Replacement for document.getElementById() */
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

/* Sets Image sizes for either 5 or 6 tabs */
function getWideImages(imageType)
{
    $$('usesImage').src = imageServer + "/images" + imagesBrand + "/usesWide_Off.gif";
    $$('usesImage').style.width = "66px";
    $$('usesImage').style.height = "27px";
    $$('sideeffectsImage').src = imageServer + "/images" + imagesBrand + "/sideeffectsWide_Off.gif"
    $$('sideeffectsImage').style.width = "108px";
    $$('sideeffectsImage').style.height = "27px";
    $$('precautionsImage').src = imageServer + "/images" + imagesBrand + "/precautionsWide_Off.gif"
    $$('precautionsImage').style.width = "112px";
    $$('precautionsImage').style.height = "27px";
    $$('interactionsImage').src = imageServer + "/images" + imagesBrand + "/interactionsWide_Off.gif"
    $$('interactionsImage').style.width = "115px";
    $$('interactionsImage').style.height = "27px";
    $$('overdoseImage').src = imageServer + "/images" + imagesBrand + "/overdoseWide_Off.gif"
    $$('overdoseImage').style.width = "93px";
    $$('overdoseImage').style.height = "27px";    
}

function getNarrowImages(imageType)
{
    $$('usesImage').src = imageServer + "/images_Narrow/usesWide_Off.gif";
    $$('usesImage').style.width = "55px";
    $$('usesImage').style.height = "26px";
    $$('sideeffectsImage').src = imageServer + "/images_Narrow/sideeffectsWide_Off.gif"
    $$('sideeffectsImage').style.width = "96px";
    $$('sideeffectsImage').style.height = "26px";
    $$('precautionsImage').src = imageServer + "/images_Narrow/precautionsWide_Off.gif"
    $$('precautionsImage').style.width = "98px";
    $$('precautionsImage').style.height = "26px";
    $$('interactionsImage').src = imageServer + "/images_Narrow/interactionsWide_Off.gif"
    $$('interactionsImage').style.width = "107px";
    $$('interactionsImage').style.height = "26px";
    $$('overdoseImage').src = imageServer + "/images_Narrow/overdoseWide_Off.gif"
    $$('overdoseImage').style.width = "79px";
    $$('overdoseImage').style.height = "26px";    
}

/* turns image to Off and hides active Tab */
function turnOff(activeTab)
{
    
    if ($$(activeTab + 'Image'))
    {   if (wideImages)
            { $$(activeTab + 'Image').src = imageServer + "/images" + imagesBrand + "/" + activeTab + "Wide_Off.gif"; }
        else { $$(activeTab + 'Image').src = imageServer + "/images" + imagesBrand + "/" + activeTab + "_Off.gif"; }
    }
    
    if ($$(activeTab + 'Content'))
    { $$(activeTab + 'Content').style.display = "none"; }
    
    if ($$(activeTab + 'Head'))
    { $$(activeTab + 'Head').style.display = "none"; }
    
    return false;
}

/* turns image to On and activates the current Tab */
function turnOn(activeTab)
{
    if ($$(activeTab + 'Image'))
    {
        if (wideImages)
        { $$(activeTab + 'Image').src = imageServer + "/images" + imagesBrand + "/" + activeTab + "Wide_On.gif"; }
        else { $$(activeTab + 'Image').src = imageServer + "/images" + imagesBrand + "/" + activeTab + "_On.gif"; }
    }
    
    if ($$(activeTab + 'Content'))
    { $$(activeTab + 'Content').style.display = "block"; }

	if ($$(activeTab + 'Head'))
	{ $$(activeTab + 'Head').style.display = "block"; }
    
    return false;
}

function getTab(currentTab) {
    refreshAds();
    turnOff(activeTab);
    activeTab = currentTab;
    turnOn(activeTab);
    return false;
}

function refreshAds() {

    var transTileId = Math.round(99999999*Math.random());

    // Grab the top divs for both ads on the page
    $("#bannerAd_fmt, #leftAd_fmt, #rightAd_fmt").each( function() {

        // Find the ad within the div
        var ad = $(this).children("iframe[id*=Ad_Iframe]");

	// Remove everything from the div except for the ad
	$(this).children().not(ad).remove();

        // Remove children within the ad iframe
        ad.children().remove();

	// Update the src for each ad
	var strSrc = ad.attr("src");
        if (!strSrc) { return; }

	strSrc = strSrc.replace(new RegExp("transactionID=[0-9]+"), "transactionID=" + transTileId);
	strSrc = strSrc.replace(new RegExp("tile=[0-9]*"), "tile=" + transTileId);

        // Update the src without adding to the page history
	ad[0].contentWindow.location.replace(strSrc);
    });

}



function setupPage()
{
    wideImages = 0;
    activeTab = "warnings";
    activeTab = GetActiveTab(activeTab,true);
    
    turnOff('warnings');
    turnOff('uses');
    turnOff('sideeffects');
    turnOff('precautions');
    turnOff('interactions');
    turnOff('overdose');
    
    /* checks to see if warnings has content and hides it if it doesn't */
    //if ($$('warningsContent').innerHTML == "") {
	if($$('handOutWarning') == null){
        $$('warningsTab').style.display = "none";
        wideImages = 1;
		if(imagesBrand == "_Narrow")
		{
			getNarrowImages();
		}
		else
		{
			getWideImages();
		}
        
        activeTab = "uses";
    }

    
    turnOn(activeTab);    
    
    //$$('monographContent').className = "";
     $$('hideFromJS').style.display = "block";
    
    return false;
}

function ShowDrugSlideShow()
{
	var frame = parent.document.getElementById("DrugImagesFrame")
	frame.style.display = "block";
}

function GotoMonoGraphUrl(url)
{
	if(url != null && url.length > 0)
	{
		window.location.href = url;
	}
	return false;
}

function setSize(iframe)
{
	iframe.frames.frameElement.style.height = iframe.document.body.scrollHeight + "px";
}

function ViewLinkInParent(url)
{
	if(window.parent)
	{
		window.parent.location.href = url;
	}
	return false;
}

function GetTransactionID()
{
	return Math.round(99999999*Math.random());
}

///////////////////////////////


function setupPageBoots()
{
    activeTab = "tab_warnings";
    
    turnOffBoots('tab_warnings');
    turnOffBoots('tab_uses');
    turnOffBoots('tab_sideeffects');
    turnOffBoots('tab_precautions');
    turnOffBoots('tab_interactions');
    turnOffBoots('tab_overdose');
    
    activeTab = "tab_warnings";
    
    turnOnBoots(activeTab);    
    
    // $$('hideFromJS').style.display = "block";
    
    return false;
}


function setupPageImageBoots()
{
    activeTab = "tab_tablet";
    activeTab = GetBootsImageActiveTab(activeTab);
    
    turnOffBoots('tab_tablet');
    turnOffBoots('tab_liquid');
    turnOffBoots('tab_capsule');
    turnOffBoots('tab_patch');
    turnOffBoots('tab_powder');
    
    turnOnBoots(activeTab);
    
    // $$('hideFromJS').style.display = "block";
    
    return false;
}


/* turns image to Off and hides active Tab */
function turnOffBoots(activeTab)
{
    if ($$(activeTab + 'Image'))
    {
        $$(activeTab + 'Image').src = imageServer + "/images/" + activeTab + "_off.gif";
    }
    
    if ($$(activeTab + '_fmt'))
    { $$(activeTab + '_fmt').style.display = "none"; }
    
    if ($$(activeTab + 'Head'))
    { $$(activeTab + 'Head').style.display = "none"; }
    
    return false;
}

/* turns image to On and activates the current Tab */
function turnOnBoots(activeTab)
{
    if ($$(activeTab+ 'Image'))
    {
        $$(activeTab + 'Image').src = imageServer + "/images/" + activeTab + "_on.gif";
    }
    
    if ($$(activeTab + '_fmt'))
    { $$(activeTab + '_fmt').style.display = "block"; }

	if ($$(activeTab + 'Head'))
	{ $$(activeTab + 'Head').style.display = "block"; }
    
    return false;
}

function getTabBoots(currentTab) {
    refreshAdsBoots();
    turnOffBoots(activeTab);
    activeTab = currentTab;
    turnOnBoots(activeTab);
    return false;
}

function refreshAdsBoots() {

    var transTileId = Math.round(99999999*Math.random());

    // Grab the top divs for both ads on the page
    $("#bannerAd_fmt, #leftAd_fmt, #rightAd_fmt").each( function() {

    // Find the ad within the div
    var ad = $(this).children("iframe[id*=Ad_fmt_IFrame]");

	// Remove everything from the div except for the ad
	$(this).children().not(ad).remove();

        // Remove children within the ad iframe
        ad.children().remove();

	// Update the src for each ad
	var strSrc = ad.attr("src");
        if (!strSrc) { return; }

	strSrc = strSrc.replace(new RegExp("transactionID=[0-9]+"), "transactionID=" + transTileId);
	strSrc = strSrc.replace(new RegExp("tile=[0-9]*"), "tile=" + transTileId);

        // Update the src without adding to the page history
	ad[0].contentWindow.location.replace(strSrc);
    });

}

function GetBootsImageActiveTab(currentTab)
{
   var qrStr = window.location.search;
   var spQrStr = qrStr.substring(1);
   // splits each of pair
   var arr = spQrStr.split('&');
   var val;
   var isTabNo;
   
   for (var i=0;i<arr.length;i++)
   {
        // splits each of field-value pair
        var index = arr[i].indexOf('=');
        var key = arr[i].substring(0,index);
        val = arr[i].substring(index+1);
        if(key == 'tab')
        {
            isTabNo = true;
            break;
        }
   }
   return GetActiveTabForBootsImage(val);
}

function GetActiveTabForBootsImage(val)
{
    var activeTab;
    
    switch (val)
    {
       case "1":
           activeTab = "tab_tablet";
           break;
        case "2":
           activeTab = "tab_liquid";
           break;
        case "3":
           activeTab = "tab_capsule";
           break;
        case "4":
           activeTab = "tab_patch";
           break;
        case "5":
           activeTab = "tab_powder";
           break;
        default:
            activeTab = "tab_tablet";
            break;                     
   }
   return activeTab;
}
