
var page_name = new Array();
page_name[0] = "Drug Description";
page_name[1] = "Indications &amp; Dosage";
page_name[2] = "Side Effects &amp; Drug Interactions";
page_name[3] = "Warnings &amp; Precautions";
page_name[4] = "Overdosage &amp; Contraindications";
page_name[5] = "Clinical Pharmacology";
page_name[6] = "Patient Information";
page_name[7] = "Consumer - Uses";
page_name[8] = "Consumer - Side Effects &amp; Precautions";
page_name[9] = "Consumer - Drug Interactions";

function RedirectToFDB()
{
    //Get the Page 8 Href in the anchor tag to redirect to it...this function called during movenext
    var anc = document.getElementById('pg8Anchor');
    var sUrl = anc.attributes["href"].value;
    window.location = sUrl;  
}

function moveNext() {
    //If there is no FDB content, then the NumberOfPages variable is replaced in the rxList.asp page to 7
    if (CurrentPage == 7 && NumberOfPages == 7)
        RedirectToFDB();
    else
    {    
	    if (CurrentPage >= NumberOfPages)
    //		{CurrentPage = 1;LastPage = NumberOfPages;}
		    {LastPage = CurrentPage;CurrentPage = 1;}
	    else
		    {LastPage = CurrentPage;CurrentPage++;}

	    changeTab()
	    changePage()
	    registerPageView()
	    smartLinkTables()
	}
}

function movePrev() {
    if (CurrentPage == 1 && NumberOfPages == 7)
        RedirectToFDB();
    else
    {
	    if (CurrentPage == 1)
		    {CurrentPage = NumberOfPages;LastPage = 1;}
	    else
		    {LastPage = CurrentPage;CurrentPage--;}

	    changeTab()
	    changePage()
	    registerPageView()
	    smartLinkTables()
	}
}

function jumpToPage(page_number) {
	LastPage = CurrentPage;
	CurrentPage = page_number;

	changeTab()
	changePage()
	registerPageView()
	smartLinkTables()
}

function changeTab() {
	if (CurrentPage >= 8 && LastPage < 8) {
		document.getElementById('consumerTab').style.background = "url(http://images.rxlist.com/images/rxlist/fdamonographtab1.gif)";
		document.getElementById('advConsTab').style.background = "url(http://images.rxlist.com/images/rxlist/fdamonographtab2.gif)";
		}
	if (LastPage >= 8 && CurrentPage < 8) {
		document.getElementById('consumerTab').style.background = "url(http://images.rxlist.com/images/rxlist/fdbmonographtab1.gif)";
		document.getElementById('advConsTab').style.background = "url(http://images.rxlist.com/images/rxlist/fdbmonographtab2.gif)";
		}
}

function changePage() {
	document.getElementById('PageType').innerHTML = page_name[CurrentPage-1];

	document.getElementById('page_' + LastPage).style.display = "none";
	document.getElementById('page_' + CurrentPage).style.display = "block";

	document.getElementById('pagination_top_' + LastPage).className = "none";
	document.getElementById('pagination_bottom_' + LastPage).className = "none";	
	if (LastPage >=8)
	    document.getElementById('pagination_left_8').className = "none";
	else
	    document.getElementById('pagination_left_' + LastPage).className = "none";

	document.getElementById('pagination_top_' + CurrentPage).className = "currentpage";
	document.getElementById('pagination_bottom_' + CurrentPage).className = "currentpage";
	//keep the selected left menu item as page 8 when paging to 9 and 10
	if (CurrentPage >= 8)
	    document.getElementById('pagination_left_8').className = "active_fmt";
	else
	    document.getElementById('pagination_left_' + CurrentPage).className = "active_fmt";
	    
	var oNP = document.getElementById('paginationNextPage');
	if (oNP != null)
	{
	    if (CurrentPage < NumberOfPages)
	        oNP.innerHTML = "<b>Next:</b>&nbsp;<a href='javascript:moveNext();'>"+page_name[CurrentPage]+"</a>";
	    else
	        oNP.innerHTML = "";
	}

	window.scrollTo(0,0);

	writeSessionCookie(sDrugName, CurrentPage)
}


function registerPageView() {
	var transTileId = Math.round(99999999*Math.random());
	refreshAd('bannerAd_fmt',transTileId);
	refreshAd('rightAd_fmt',transTileId);
	refreshAd('leftAd_fmt',transTileId);
	wmdPageview('rxlist.com/cgi/generic/' + sDrugName, CurrentPage);
}


function jumpToPageFromStart(page_number) {
	LastPage = CurrentPage;
	CurrentPage = page_number;

	changeTab()
	changePage()
	wmdPageview("rxlist.com/cgi/generic/" + sDrugName, CurrentPage + '#');
}

function refreshAd(strAd,transTileId) {
				
	var objAd = document.getElementById(strAd);
	var okToLoop = 0;

	if (objAd) {
	
		var theObjects = objAd.getElementsByTagName("*");

		/* Makes sure there is an approved iframe before running a possible infinte loop */
		for (i=0;i<=theObjects.length-1;i++)
			{
				if (theObjects[i].id.indexOf("Ad_Iframe") != -1) {
					okToLoop+=1;
				}
			}
		
		/* Runs two loops that remove all other objects other than the original webmd iframe */
		if (okToLoop == 1)
		{
			while(theObjects.length > 1) {
				for (i=0;i<=theObjects.length-1;i++)
				{
					if (theObjects[i].id.indexOf("Ad_Iframe") < 0) {
						objAd.removeChild(theObjects[i]);
					}
				}
			}
		}

		/* Grabs the src of either the iframe or script whichever one is in the div */
		iframe = objAd.getElementsByTagName('iframe')[0];
		adScript = objAd.getElementsByTagName('script')[0];

		if(!iframe) {
			var strHTML = adScript.src;
		}
		else {
			var strHTML = iframe.src;
		}
			
		/* Refreshes the other variables in the src */ 
		strHTML = strHTML.replace(new RegExp("transactionID=[0-9]+"), "transactionID=" + transTileId);
		strHTML = strHTML.replace(new RegExp("tile=[0-9]*"), "tile=" + transTileId);


					if(!iframe) {
/*						adScript.contentWindow.location.replace(strHTML); */
						adScript.src = strHTML;
					}
					else {
/*						iframe.contentWindow.location.replace(strHTML); */
						iframe.src = strHTML;
					}
		
	}
}
