﻿

// Launches flash presentation if not logged function for modal popup
function OpenPopupOnNotLoggedIn()
{

    if( getCookie( "Blackmores.HealthcareProfessional" ) == null &&  getCookie( "Blackmores.DoNotShowPopup" ) == null)    
    {
        var a = $find("behaviorTakeATourLoad");
        if(a)
        {    
            a.show();
        }
        else
        {
            var b = $find("behaviorViewOnlineDemoLoad");
            if (b)
            {
                b.show();
            }
        }
        
    }
    else
    {
        setDoNotShowPopUp();
    }   
    
}

function setDoNotShowPopUp()
{
    setCookie("Blackmores.DoNotShowPopup", "1");
}




function OpenInteractions()
{
    var a = $find("behaviorOpenInteractions");
    
    if( a )
    {
        a.show();
    }
}
/**************/
/*Flash Popups*/
/**************/

/**/
function showPopupDemo(member){
    setOverlayHeight();
    var overlay=document.getElementById('overlay');
    var flashHolder=document.getElementById('flashHolder');
    flashHolder.style.height='595px';
    attachEventListener(overlay, "mousedown", hidePopup, false);
    overlay.style.display='block';
    overlayAnimation = new Animator({onComplete:function(){embedFlashDemo(member);},transition: Animator.makeEaseOut(2),duration: 400});
    
    var detectFF = detectMacXFF2();
    opacityTo=0.7;
    if(detectFF==1){
        opacityTo=1;
    }
    
    overlayAnimation.addSubject(new NumericalStyleSubject(overlay, 'opacity', 0, opacityTo));
    overlayAnimation.seekTo(1);
    DropDowns('');
}
function showPopup(){
    setOverlayHeight();
    urlPrefix = findUrl();
    var overlay=document.getElementById('overlay');
    var flashHolder=document.getElementById('flashHolder');
    overlay.style.display='block';
    flashHolder.style.height='800px';
    attachEventListener(overlay, "mousedown", hidePopup, false);
    
    var detectFF = detectMacXFF2();
    opacityTo=0.7;
    if(detectFF==1){
        opacityTo=1;
    }
    
    overlayAnimation = new Animator({onComplete:function(){embedFlash(urlPrefix);},transition: Animator.makeEaseOut(2),duration: 400});
    overlayAnimation.addSubject(new NumericalStyleSubject(overlay, 'opacity', 0, opacityTo));
    overlayAnimation.seekTo(1);
    DropDowns('');
}
function hidePopup(){
    DropDowns(1);
    document.getElementById('flashHolder').style.display='none';
    if(!$('nonFlash')){
        document.getElementById('flashHolder').innerHTML='';
    }
    var overlay = document.getElementById('overlay')
    overlay.style.display='none';
    overlayAnimation = new Animator({transition: Animator.makeEaseOut(2),duration: 400});
    overlayAnimation.addSubject(new NumericalStyleSubject(overlay, 'opacity', 0, 0));
    overlayAnimation.seekTo(1);
}
function DropDowns(visibility){
    
    var ddl=document.getElementsByTagName('select');
    for (var i=0; i<ddl.length; i++){
        if(visibility==''){
            ddl[i].style.visibility='hidden';
        }else{
            ddl[i].style.visibility='';
        }
    }
}
function findUrl(){
    var urlPrefix='';
    var url=window.location.href.split( "/" );
    for(var i=3;i<(url.length-1);i++){
        urlPrefix+='../';
    }
    return urlPrefix;
}
function setOverlayHeight(){
    var scrHeight=getScreenHeight();
    contentHeight=getElementsByClassName(document,'div','bodyOuter')[0].offsetHeight+100;
    var overlay=document.getElementById('overlay');
    if(contentHeight>scrHeight){
        overlay.style.height=contentHeight+'px';
    }
}
function getScreenHeight(){
    scrHeight=0;
    if(typeof( window.innerWidth ) == 'number') {
        scrHeight = window.innerHeight;
    }else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        scrHeight = document.documentElement.clientHeight;
    }else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        scrHeight = document.body.clientHeight;
    }
    return scrHeight;
}
function embedFlash(urlPrefix){
    var detectFF = detectMacXFF2();
    
	var fo = new SWFObject("/Flash/BLK_HCP_InteractionsTool.swf", "InteractiveTool", "800", "800", "8", "#ffffff");
	fo.addParam("quality", "high");
	fo.addParam("menu", "false");
	
	if(!detectFF){
	    fo.addParam("wmode", "transparent");
	}
	
	fo.addParam("allowScriptAccess", "always");
	fo.addVariable("xmlPath",urlPrefix+"Flash/");	
	fo.addVariable("productPrefix",urlPrefix+"ProductInformation/ProductDetail.aspx?ProductId=");
	fo.write("flashHolder");
	var flashHolder=document.getElementById('flashHolder');
    flashHolder.style.display='block';
}
function embedFlashDemo(member){
    var detectFF = detectMacXFF2();
    
    var fo = new SWFObject("/Flash/BLK_HCP_OnlineDemo.swf", "OnlineDemo", "905", "595", "7", "#ffffff");
	fo.addVariable("HCPmember", member);
	fo.addParam("quality", "high");
	
	if(!detectFF){
	    fo.addParam("wmode", "transparent");
	}
	
	fo.addParam("menu", "false");
	fo.write("flashHolder");
	var flashHolder=document.getElementById('flashHolder');
    flashHolder.style.display='block';
}


/*checking for url variable if present interaction tool will popup*/
function getUrlVars(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++){
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}
function urlTracker(){
    var hash = getUrlVars();
	var str=hash['showGuide'];
	if (str=='1'){
		showPopup();
	}
}
addLoadListener(urlTracker);

/*load page listener*/
function addLoadListener(fn)
{
	if(typeof window.addEventListener != 'undefined')
	{
		window.addEventListener('load',fn,false);
	}
	else if (typeof document.addEventListener != 'undefined')
	{
		document.addEventListener('load', fn, false);
	}
	else if (typeof window.attachEvent != 'undefined')
	{
		window.attachEvent('onload', fn);
	}
	else
	{
		var oldfn = window.onload;
		if(typeof window.onload != 'function')
		{
			window.onload = fn;
		}
		else
		{
			window.onload = function()
			{
				oldfn();
				fn();
			};
		}
	}
};

//detects Mac FF2 where flash does not show unless it is embeded without transparency
function detectMacXFF2() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (/firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
    var ffversion = new Number(RegExp.$1);
    if (ffversion < 3 && userAgent.indexOf('mac') != -1) {
      return true;
    }
  }
}