/*  Created Date:  1/26/2007 4:00 PM
 * 	Author:  Irvin Owens Jr
 *  For: Epocrates, Inc.
 *  Project: EOL 2 / Topamax
 *  Description:  This file will comprise of the topamax class.  The purpose of this class is to
 *                insert the appropriate sponsored content into the page based upon a parameter passed
 *                into it.  Options 1 - 5 for sponsored content, and then 0 for a registry.
 *  Libraries Used:  /noFrame/js/uiLibrary.js, /noFrame/js/toolLibrary.js
 */

/* globals */



/* constructors */

function SponsoredPillar(adVersion /* integer */,objectToAttach /* DOMObject */){
	this.adVersion = adVersion;
	this.objectToAttach = objectToAttach;
}

function SponsoredFactory(){
	
}

/* prototypes */

/* sponsored pillar prototypes */

SponsoredPillar.prototype.SponsoredFactory = new SponsoredFactory();
SponsoredPillar.prototype.showSponsored = showSponsored;
SponsoredPillar.prototype.toggleHidden = hideMeNow;

/* sponsored factory prototypes */

SponsoredFactory.prototype.createSponsoredContent = createSponsoredContent;


/* implementations */

function showSponsored(){
	var sponsoredDiv = this.SponsoredFactory.createSponsoredContent(this.adVersion);
	this.objectToAttach.innerHTML = "";
	this.objectToAttach.appendChild(sponsoredDiv);
	if(this.adVersion == 5){
		this.objectToAttach.style.display = 'none';
	}
}

function hideMeNow(){
	if(this.objectToAttach.getElementsByTagName("object").length != 0){
		if(this.objectToAttach.style.display == "none"){
			this.objectToAttach.style.display = "block";
		}else{
			this.objectToAttach.style.display = "none";
		}
	}
}

function createSponsoredContent(adVersion){
	var epocAdLink1, epocAdLink2;
	if(_isFrontPorch){
		epocAdLink1 = "http://www.epocrates.com/honors/?icid=epocad_honors";
		epocAdLink2 = "http://www.epocrates.com/products/rx/?icid=epocad_rxdrugref";
	}else{
		epocAdLink1 = "http://www.epocrates.com/honors/?icid=adeolhonors";
		epocAdLink2 = "http://www.epocrates.com/products/rx";
		epocAdLink3 = "https://www.epocrates.com/honorsEnroll.do?src=eolhonors&ru=http://www.epocrates.com/honors/thanks.html&icid=adeolhonors"; //honors
		epocAdLink4 = "https://www.epocrates.com/EOLRedir.do?project=EOL&mode=0&ad_id=2"; //mobile
	}
	switch(adVersion){
		case 0:
			var containerDiv = createDiv("sponsoredDivContent","sponsoredDivContent","class_sponsored_inherited","1 = Topomax<br />2 = Migrane Class<br />3 = ePocrates placeholder single<br />4 = ePocrates placeholder both<br />5 = none");
			return containerDiv;
		break;
		
		case 1:
			var containerDiv = createDiv("sponsoredDivContent","sponsoredDivContent","class_sponsored_inherited","");
				containerDiv.innerHTML = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"170\" height=\"350\"><param name=\"movie\" value=\"" + getServer() + "noFrame/img/sponsored/170_X_350_BANNERS2b.swf\"><param name=\"quality\" value=\"high\"><param name=\"wmode\" value=\"transparent\"><embed src=\"" + getServer() + "noFrame/img/sponsored/170_X_350_BANNERS2b.swf\" quality=\"high\" pluginspage=\"https://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"170\" height=\"350\" wmode=\"transparent\" ></embed></object>";
				containerDiv.appendChild(createFeedbackPopup());
			return containerDiv;
		break;
		
		case 2:
			var containerDiv = createDiv("sponsoredDivContent","sponsoredDivContent","class_sponsored_inherited","");
				containerDiv.innerHTML = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"170\" height=\"350\"><param name=\"movie\" value=\"" + getServer() + "noFrame/img/sponsored/170_X_350_BANNERS1b.swf\"><param name=\"quality\" value=\"high\"><param name=\"wmode\" value=\"transparent\"><embed src=\"" + getServer() + "noFrame/img/sponsored/170_X_350_BANNERS1b.swf\" quality=\"high\" pluginspage=\"https://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"170\" height=\"350\" wmode=\"transparent\" ></embed></object>";
				containerDiv.appendChild(createFeedbackPopup());
			return containerDiv;
		break;
		
		case 3:
			var containerDiv = createDiv("sponsoredDivContent","sponsoredDivContent","class_sponsored_inherited","");
				var singleGifDiv = createDiv("topEpocSponsored","topEpocSponsored","class_sponsored_inherited","");
					var epocSponsoredLink = createHyperObject("epocHonorsLink","epocHonorsLink","class_sponsored_inherited",epocAdLink1,"Get Paid For Your Clinical Opinions! - Join Epocrates Honors Market Research Panel","","","_blank");
					singleGifDiv.appendChild(epocSponsoredLink);
						var imageItem = createImageObject("sponsoredImageObjEpoc","sponsoredImageObj","class_sponsored_inherited",getServer() + "noFrame/img/sponsored/online_ad_170x200.gif","Get Paid For Your Clinical Opinions! - Join Epocrates Honors Market Research Panel");
                                                    imageItem.style.width = "170px";
                                                    imageItem.style.height = "200px";
                                                singleGifDiv.appendChild(epocSponsoredLink);
				containerDiv.appendChild(singleGifDiv);
				containerDiv.appendChild(createFeedbackPopup());
			return containerDiv;
		break;
		
		case 4:
			var containerDiv = createDiv("sponsoredDivContent","sponsoredDivContent","class_sponsored_inherited","");
				var singleGifDiv = createDiv("topEpocSponsored","topEpocSponsored","class_sponsored_inherited","");
				var epocSponsoredLink = createHyperObject("epocHonorsLink","epocHonorsLink","class_sponsored_inherited",epocAdLink1,"Get Paid For Your Clinical Opinions! - Join Epocrates Honors Market Research Panel","","","_blank");
					singleGifDiv.appendChild(epocSponsoredLink);
					var imageItem = createImageObject("sponsoredImageObjEpoc","sponsoredImageObj","class_sponsored_inherited",getServer() + "noFrame/img/sponsored/online_ad_170x200.gif","Get Paid For Your Clinical Opinions! - Join Epocrates Honors Market Research Panel");
                                            imageItem.style.width = "170px";
                                            imageItem.style.height = "200px";
                                        epocSponsoredLink.appendChild(imageItem);
				containerDiv.appendChild(singleGifDiv);
				var secondGifContainer = createDiv("bottomEpocSponsored","bottomEpocSponsored","class_sponsored_inherited","");
				var epocSponsoredLink = createHyperObject("epocRxLink","epocRxLink","class_sponsored_inherited",epocAdLink2,"Get This Free Content On Your PDA! - Epocrates Rx Mobile Drug Reference","","","_blank");
					secondGifContainer.appendChild(epocSponsoredLink);
					var bottomImageItem = createImageObject("sponsoredImageObjEpoc2","sponsoredImageObj","class_sponsored_inherited",getServer() + "noFrame/img/sponsored/online_banner_ad_170x230.gif","Get This Free Content On Your PDA! - Epocrates Rx Mobile Drug Reference");
                                            bottomImageItem.style.width = "170px";
                                            bottomImageItem.style.height = "230px";
                                        epocSponsoredLink.appendChild(bottomImageItem);
				containerDiv.appendChild(secondGifContainer);
				containerDiv.appendChild(createFeedbackPopup());
			return containerDiv;
		break;
		
		case 5:
			var containerDiv = createDiv("sponsoredDivContent","sponsoredDivContent","class_sponsored_inherited","");
			return containerDiv;
		break;
                
        case 6:
                    // noFrame promo ad
			var containerDiv = createDiv("sponsoredDivContent","sponsoredDivContent","class_sponsored_inherited","");
				var singleGifDiv = createDiv("topEpocSponsored","topEpocSponsored","class_sponsored_inherited","");
				var epocSponsoredLink = createHyperObject("epocHonorsLink","epocHonorsLink","class_sponsored_inherited",getServer() + "noFrame/rxtabs.do?method=diseases","Detailed disease content in Epocrates Online under the Disease tab","","","_self");
					singleGifDiv.appendChild(epocSponsoredLink);
					var imageItem = createImageObject("sponsoredImageObjEpoc","sponsoredImageObj","class_sponsored_inherited",getServer() + "noFrame/img/sponsored/online_ad_170x200_disease.gif","Detailed disease content in Epocrates Online under the Disease tab");
                           imageItem.style.width = "170px";
                           imageItem.style.height = "200px";
                           epocSponsoredLink.appendChild(imageItem);
				containerDiv.appendChild(singleGifDiv);
				var secondGifContainer = createDiv("bottomEpocSponsored","bottomEpocSponsored","class_sponsored_inherited","");
				var epocSponsoredLink = createHyperObject("epocRxLink","epocRxLink","class_sponsored_inherited",epocAdLink4,"Access Epocrates Info On the Go with Mobile Products","","","_blank");
					secondGifContainer.appendChild(epocSponsoredLink);
					var bottomImageItem = createImageObject("sponsoredImageObjEpoc2","sponsoredImageObj","class_sponsored_inherited",getServer() + "noFrame/img/sponsored/mobileAd.png","Access Epocrates Info On the Go with Mobile Products");
                                            bottomImageItem.style.width = "170px";
                                            bottomImageItem.style.height = "230px";
                                        epocSponsoredLink.appendChild(bottomImageItem);
				containerDiv.appendChild(secondGifContainer);
				containerDiv.appendChild(createFeedbackPopup());
			return containerDiv;
		break;
                
                case 7:
                    // front porch promo ad
			var containerDiv = createDiv("sponsoredDivContent","sponsoredDivContent","class_sponsored_inherited","");
				var singleGifDiv = createDiv("topEpocSponsored","topEpocSponsored","class_sponsored_inherited","");
				var epocSponsoredLink = createHyperObject("epocHonorsLink","epocHonorsLink","class_sponsored_inherited",
"https://www.epocrates.com/referral.do?p_r_name=EOLPREMIUM3MONTH&icid=EOLPREMTRIEOLAD","Try Epocrates Only Premium FREE 3 month trial","","","_self");
					singleGifDiv.appendChild(epocSponsoredLink);
					var imageItem = createImageObject("sponsoredImageObjEpoc","sponsoredImageObj","class_sponsored_inherited",getServer() + "noFrame/img/sponsored/banner-premium.gif","Try Epocrates Only Premium FREE 3 month trial");
                                            imageItem.style.width = "170px";
                                            imageItem.style.height = "200px";
                                        epocSponsoredLink.appendChild(imageItem);
				containerDiv.appendChild(singleGifDiv);
				var secondGifContainer = createDiv("bottomEpocSponsored","bottomEpocSponsored","class_sponsored_inherited","");
				var epocSponsoredLink = createHyperObject("epocRxLink","epocRxLink","class_sponsored_inherited",getServer() + "noFrame/rxtabs.do?method=diseases","Detailed disease content in Epocrates Online under the Disease tab","","","_self");
					secondGifContainer.appendChild(epocSponsoredLink);
					var bottomImageItem = createImageObject("sponsoredImageObjEpoc2","sponsoredImageObj","class_sponsored_inherited",getServer() + "noFrame/img/sponsored/online_ad_170x230_disease.gif","Detailed disease content in Epocrates Online under the Disease tab");
                                            bottomImageItem.style.width = "170px";
                                            bottomImageItem.style.height = "230px";
                                        epocSponsoredLink.appendChild(bottomImageItem);
				containerDiv.appendChild(secondGifContainer);
				containerDiv.appendChild(createFeedbackPopup());
			return containerDiv;
		break;
		
        case 8: //top like 6
			var containerDiv = createDiv("sponsoredDivContent","sponsoredDivContent","class_sponsored_inherited","");
			var singleGifDiv = createDiv("topEpocSponsored","topEpocSponsored","class_sponsored_inherited","");
			var epocSponsoredLink = createHyperObject("epocHonorsLink","epocHonorsLink","class_sponsored_inherited",getServer() + "noFrame/rxtabs.do?method=diseases","Detailed disease content in Epocrates Online under the Disease tab","","","_self");
				singleGifDiv.appendChild(epocSponsoredLink);
				var imageItem = createImageObject("sponsoredImageObjEpoc","sponsoredImageObj","class_sponsored_inherited",getServer() + "noFrame/img/sponsored/online_ad_170x200_disease.gif","Detailed disease content in Epocrates Online under the Disease tab");
                       imageItem.style.width = "170px";
                       imageItem.style.height = "200px";
                       epocSponsoredLink.appendChild(imageItem);
                       containerDiv.appendChild(singleGifDiv);
        	var secondGifContainer = createDiv("bottomEpocSponsored","bottomEpocSponsored","class_sponsored_inherited","");
        	var epocSponsoredLink = createHyperObject("epocRxLink","epocRxLink","class_sponsored_inherited",epocAdLink3,"Get paid for your clinical insights! - Join Epocrates Honor Market Research Panel","","","_blank");
        		secondGifContainer.appendChild(epocSponsoredLink);
        		var bottomImageItem = createImageObject("epocHonorsLink","epocHonorsLink","class_sponsored_inherited",getServer() + "noFrame/img/sponsored/banner-honors.jpg","Get paid for your clinical insights! - Join Epocrates Honor Market Research Panel");
                        bottomImageItem.style.width = "170px";
                        bottomImageItem.style.height = "230px";
                        epocSponsoredLink.appendChild(bottomImageItem);
        		containerDiv.appendChild(secondGifContainer);
        		containerDiv.appendChild(createFeedbackPopup());
        	return containerDiv;
        break;
        		
		default:
			var containerDiv = createDiv("sponsoredDivContent","sponsoredDivContent","class_sponsored_inherited","");
			return containerDiv;
		break;
	}
}

function createFeedbackPopup(){
	var feedbackLink = createDiv("feedbackLink","feedbackLink","feedbackLink","<p class=\"feedbackLink\">Have Feedback?</p>");
					feedbackLink.firstChild.onclick = function() { this.parentNode.childNodes[1].firstChild.style.display = "block"; };
				var feedbackPop = createDiv("feedBackPop","feedBackPop","feedbackPopup","<div id=\"topamaxNeedHelpLink\" class=\"topamaxNeedHelp\" style=\"display: none;\"><div><h1><a id=\"feedbackLinkActualA\" style=\"cursor:pointer\" onclick=\"this.parentNode.parentNode.parentNode.style.display='none';\"><img alt=\"close\" src=\"/noFrame/img/ico_close.gif\"/></a>Please Send Us Your Feedback</h1><p>NoFrame This advertisement is part of a limited pilot to test banner advertising.<br/><br/>If you have comments or suggestions about this feature, please write us at <a id='pilotMailto' href='mailto:suggestionbox@epocrates.com?subject=Comments on Epocrates banner ad pilot' title='sendfeedback'>suggestionbox@epocrates.com</a></p></div></div>");
						feedbackLink.appendChild(feedbackPop);
	return feedbackLink;
}
