var ns6 = document.getElementById && !document.all;
function getUrl(PVID, reelID, referenceID, tid, isDedicated) {
	var distribution = getQueryVariable("dist");
	var newURL = baseDomain + "/fc/LoadFC.do?pvid=" + PVID + "&reel=" + reelID + "&ref=" + referenceID + "&tid=" + tid + "&pn=" + personNumber + "&dist=" + distribution + "&dedicated=" + isDedicated;
	return newURL;
}
/*function getUrl2(page,inReel){
	var newUrl = 'http://www.peerviewpress.com/dedicated.do?page='+page+'&inReel='+inReel;
	alert(newUrl);
	var returnUrl = window.open(newUrl, '', 'width=700,height=540,scrollbars=yes,menubar=no,status=yes,resizable=yes');
 return returnUrl;
}*/
/*
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
function scrollObj(newTitleUrl, newReelID, newPVID, newDoctorName, newDateLocation, isNewSystem, pvName, windowHeight, contentID, redLabel, isDedicated) {
	this.titleUrl = cutTooLongLabel(newTitleUrl);
	this.reelID = newReelID;
	this.PVID = newPVID;
	this.doctorName = cutTooLongLabel(newDoctorName);
	this.dateLocation = cutTooLongLabel(newDateLocation);
	this.isNewSystem = isNewSystem;
	this.pvName = pvName;
	this.windowHeight = windowHeight;
	this.redLabel = redLabel;
	this.contentID = contentID;
	this.isDedicated = isDedicated; 
}	 
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

 */


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Name   : slideFunctions_getACCMEDate
//Desc   : Get the default lauching ACCME screen in for browser coding (should be the same
//as what we have in the server side.
//Result : Date
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function slideFunctions_getACCMEDate(){
	var numberMonth = new Number(0); // January
	var numberDay  = new Number(1);
	var numberYear = new Number(2008); 
	var aDate = new Date (numberYear,numberMonth,numberDay);
	return aDate;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Name   : slideFunctions_isPgmOnACCMETargetDate
//Desc   : Is the passed date of the pgr is on target with the accm Date
//param  : program date (String in format YYYYMMDD)
//Result : true = the program date is on target with accme panel
//false = the program date is not on target accme date 
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function slideFunctions_isPgmOnACCMETargetDate(aPgmDate){
	//alert("slideFunctions_getACCMEDate()=<"+slideFunctions_getACCMEDate()+"> aPgmDate=<"+aPgmDate+">");   
	
	var thePgmDate = slideFunctions_getStdDate(aPgmDate);
	if (thePgmDate < slideFunctions_getACCMEDate() ) {
		return false;
	} else {
		return true;
	}
}




/*=============================================================
 * Name           : slideFunctions_getStdDate
 * Desc           : Get the standard java script date object
 *                  from the passed string parameter 
 * Param          : strDate =  format date Ex.: YYYYMMDD
 * return         : Date object
 * ==================================================================*/
function slideFunctions_getStdDate(strDate)
{
   var aString = new String(strDate);
   var aYear = new String(aString.charAt(0)+aString.charAt(1)+aString.charAt(2)+aString.charAt(3));
   if (aString.charAt(4) == '0') {
	    var aMonth = new String(aString.charAt(5));
	    } else {
	    var aMonth = new String(aString.charAt(4)+aString.charAt(5));
	   }
   var aDay    = new String(aString.charAt(6)+aString.charAt(7));
   var numberMonth = new Number(aMonth);
   numberMonth = numberMonth-1;
   var numberDay  = new Number(aDay);
   var numberYear = new Number(aYear);
   var aDate = new Date (numberYear,numberMonth,numberDay);

   //alert ("slideFunctions_getStdDate() result="+aDate);

   return aDate
}

function doSlideFromImage() {
	if (showScrollerItems) {
		isNew = scrollingLinksArray[currentScrollIndex].isNewSystem;
		reelId = scrollingLinksArray[currentScrollIndex].reelID;
		pvid = scrollingLinksArray[currentScrollIndex].PVID;
		pvName = scrollingLinksArray[currentScrollIndex].pvName;
		var theDateLive = scrollingLinksArray[currentScrollIndex].dateLive;


		// if scroller item Date (theDateLive) is not on target for the accme project than we display the media player
		// ortherwise we must open pvp for displaying the accme popup
		if(slideFunctions_isPgmOnACCMETargetDate(theDateLive)) {	 
			goToPVP(pvName,reelId);
		}
		else {
			DisplaySlide( 'slideContent' , reelId, pvid, 785 , 580 , 1 , 2000 , 1, (isNew ? 2 : 1), pviReferenceID, 6);
		}

	} else {
		window.open("http://www.peerviewpress.com");
	}
}


function hideControls() {

	if (ns6) {
		document.getElementById("hideSection1").style.visibility = 'hidden';
		document.getElementById("hideSection2").style.visibility = 'hidden';
	} else {
		document.all['hideSection1'].style.visibility = 'hidden';
		document.all['hideSection2'].style.visibility = 'hidden';
	}
}

function showControls() {

	if (ns6) {
		document.getElementById("hideSection1").style.visibility = 'visible';
		document.getElementById("hideSection2").style.visibility = 'visible';
	} else {
		document.all['hideSection1'].style.visibility = 'visible';
		document.all['hideSection2'].style.visibility = 'visible';
	}
}

function autoServeSlide(pvid, maxReels, displayMethod, referenceId, clickThroughTypeID, isDedicated) {

	if (WM_readCookie( "fcshown" ) == "1") {
		return;
	}

	doSlide = false;
	showReel = 1;
	cookieName = "pvin_" + pvid;
	cookieVal = WM_readCookie(cookieName);

	if (displayMethod == 0){
		doSlide = true;
	}

	if (cookieVal == "" || cookieVal == null || cookieVal.length < 1) {
		doSlide = true;
	} else {
		var currentCounter = eval(cookieVal.charAt(cookieVal.length-1));
		if (currentCounter < maxReels) {
			showReel = currentCounter + 1;
			doSlide = true;
		}
	}

	if (doSlide) {
		handle = setTimeout("DisplaySlide('slideContent', " + showReel + ", " +  pvid + ", 785 , 580  , 1 , 2000 ," + displayMethod + ", 2, " + referenceId + ", " + clickThroughTypeID + ", " + isDedicated + ");",200);
		if (displayMethod == 1){
			WM_setCookie(cookieName , showReel, 24 * 365);
			WM_setCookie ('fcshown', '1', 0.25, '');
		}
		fcshown = true;
		InterstitialSeen = 1;
	}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//Name   : slideFunctionsjs_isACCMEBMSDisplay

//Desc   : Do we need to call the accme function in order to display it ?

//Based on the fact that the accme.inc is include and if the bussiness rule
//apply (see accme_isACCMEBMSDisplay in accme.inc).
//When var accme_inc_loaded it mean that the accme.inc file is include in the document

//return : boolean value 
//true  = the caller must call the appropriate accme function
//false = the caller must not call a accme function

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function slideFunctionsjs_isACCMEBMSDisplay(){
	//alert ("slideFunctionsjs_isACCMEBMSDisplay(): typeof accme_inc_loaded="+typeof accme_inc_loaded);
	if (typeof accme_inc_loaded == "undefined" ){
		return false;	
	}  else  {
		return accme_isACCMEBMSDisplay();
	} 
}

function DisplaySlide( name , newReelID, newPVID, iwidth , iheight , autoclose , duration , islide, version, referenceID, ctTypeID, isDedicated ) {

	if (slideFunctionsjs_isACCMEBMSDisplay() == true ){
		accme_display_fromDisplaySlide( name , newReelID, newPVID, iwidth , iheight , autoclose , duration , islide, version, referenceID, ctTypeID, isDedicated );
	} else {
		slideFunctionsjs_doDisplaySlide( name , newReelID, newPVID, iwidth , iheight , autoclose , duration , islide, version, referenceID, ctTypeID, isDedicated );
	}
}

function slideFunctionsjs_doDisplaySlide( name , newReelID, newPVID, iwidth , iheight , autoclose , duration , islide, version, referenceID, ctTypeID, isDedicated ) {

	if (slidePanelActive)  {
		clearInterval(surveyIntervalID);
		secs = 0;
	} else {
		slidePanelActive = true;
	}
	if (isDedicated == null){
		isDedicated = false;
	}

	if (version>1) {
		if (!isSafari && (IE || ns6)) {
			slideType = "IE";
			scroll(0,0);
			clearInterval(intervalID);
			window.frames['slideIFrame'].location.href = getUrl(newPVID, newReelID, referenceID, ctTypeID, isDedicated);

			if(ns6) {
				controlBannerFlash();
				document.getElementById("scrollDiv").className="scrollHide";
				layerFrame =  document.getElementById("slideContent").style ;
				layerFrame.visibility="visible";
				layerFrame.display="block";
			}
            	else {

                document.all["scrollDiv"].className="scrollHide";
            }


			with ( slideBanner = cbeGetElementById( name ).cbe) {
				resizeTo( iwidth , iheight );
				if( islide == 1 ) {
					moveTo( 0 , -10 * height());
					show();
					slideTo(0, 0 , 1000);
				} else {
					moveTo( 1, 1);
					show();
				}
			}
			if ( autoclose == 0 ) {
				timerid = setTimeout( "CloseSlide( '" + name + "' , '" + islide  + "')", duration );
			}
		} else {
			slideType = "OTHER";
            var popup = window.open(getUrl(newPVID, newReelID, referenceID, ctTypeID, isDedicated), 'container', 'width='+iwidth+',height='+iheight+',menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,location=no');
			if (isSafari && !popup) {
				alert("Popup blocker is enabled on this computer. \nPlease disable it while viewing this presentation.");
			}

		}
	} else {
		// This is a version 1 popup.
		var baseURL = "http://ww3.peerviewpress.com/misc/fc.nsf/dispatch/" + scrollingLinksArray[currentScrollIndex].pvName;
		var windowHeight = scrollingLinksArray[currentScrollIndex].windowHeight;
		var url = baseURL + '?OpenDocument&ref=' + fcPageType + '&video=' + scrollingLinksArray[currentScrollIndex].reelID + "&dist=" + distType + "&num=" + distNumber;

		WindowWidth=700;
		leftPosition = (screen.width) ? (screen.width-WindowWidth)/2 : 0;
		topPosition = (screen.height) ? (screen.height-windowHeight)/2 : 0;
		window.open(url,"container","width=700,height=" + windowHeight + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",top=" + topPosition + ",left=" + leftPosition + ",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,location=no");

		scrollerClickThroughNumber = -1;
		scrollerRequestedNumber = 1;
	}

}


function CloseReminder( name ) {
	slidePanelActive = false;
	if (ns6) {

		layerFrame =  document.getElementById("slideContent").style ;
		layerFrame.top="0px";

	} else {

		with ( slideBanner = cbeGetElementById( name ).cbe) {
			slideTo(144,-1 * height(), 1000);
		}

	}
}

function CloseSlide( name , islide ) {
	slidePanelActive = false;
	if (ns6) {
		if (navigator.userAgent.indexOf("Firefox")==-1 && !isSafari) {
			try {
				var flashMovie=frames["slideIFrame"].document.getElementById('inSession');
				flashMovie.StopPlay();
			} catch (e) {
				var flashMovie=frames["slideIFrame"].document.inSession;
				flashMovie.StopPlay();
			}
			flashMovie.TStopPlay("screen");
		}


		layerFrame =  document.getElementById("slideContent").style ;
		layerFrame.top="0px";
		dropstart=setInterval("dropin()",10)


		//showControls();
		if (window.bouncestart) clearInterval(bouncestart);

		intervalID = setInterval('switchContent();', scrollSpeed);
		scrollIntervalID = setTimeout('showScroll();', 1000);
	} else {
		//showControls();

		clearInterval(surveyIntervalID);

		//showSurvey();

		if (parent.flashVersion >= 5  || parent.flashVersion == null || parent.flashVersion == 0) {

			var flashObj = frames["slideIFrame"].document.all['inSession'];
			if (flashObj) {
				flashObj.stop();
				flashObj.TStopPlay("container");
				flashObj.TStopPlay("screen");
				}
			
			window.location.reload(true);

		}

		with ( slideBanner = cbeGetElementById( name ).cbe) {
			if( islide == 1 ) {
				slideTo(0,-1 * height(), 1000);
			} else {
				hide();
			}
		}

		intervalID = setInterval('switchContent();', scrollSpeed);
	    scrollIntervalID = setTimeout('showScroll();', 1000); 
	}
}

function dropin(){
	scroll_top= window.pageYOffset
	layerFrame_height = layerFrame.height;
	if (parseInt(layerFrame.top) > -parseInt(layerFrame_height))
		layerFrame.top=parseInt(layerFrame.top)-30+"px"
		else{
			layerFrame.visibility="hidden";
			layerFrame.display="none";
			clearInterval(dropstart);
			controlBannerFlash();
		}
}

function showScroll() {
	if (ns6) {
		document.getElementById("scrollDiv").className="scroll";
	}else {
		document.all["scrollDiv"].className="scroll";
	}
}


//Verify is threre are  flash banner and hide or show them (for mozilla and firefox)
function controlBannerFlash() {
	var flashID;
	var nbMaxBannerFlash = 10;
	for (var i = 1; i <= nbMaxBannerFlash; i++) {
		flashID =  "FlashMovie" + i;
		if(document.getElementById(flashID) != null) {
			bannerFlash = document.getElementById(flashID).style ;
			if (bannerFlash.visibility == "visible" || bannerFlash.visibility == "") {
				bannerFlash.visibility="hidden";
			} else {
				bannerFlash.visibility="visible";
			}
		} else {
			break;
		}
	}
}

function getWindowWidth() {
	if (is.nav4) {
		return window.innerWidth;
	} else {
		return document.body.clientWidth;
	}
}

function getWindowHeight() {
	if (is.nav4) {
		return window.innerHeight;
	} else {
		return document.body.clientHeight;
	}
}

function getCenterLeft( iwidth ) {
	var x;
	if (getWindowWidth() < iwidth) {
		x=0;
	} else {
		var windowWidth = getWindowWidth();
		x = Math.round((windowWidth/2) - (iwidth/2));
	}
	return x;
}

function getCenterTop( iheight ) {
	var y;

	if (getWindowHeight() < iheight) {
		y=0;
	} else {
		y = Math.round((getWindowHeight()/2) - (iheight/2));
	}
	return y;
}


