﻿/* http://dean.edwards.name/weblog/2005/09/busted/ */

/* DO NOT DELETE THIS BLOCK!!! */
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32) {
	var loc = document.location.toString();
	var index = loc.indexOf(":");
	var protocol = loc.substring(0,index);

	if (protocol == "http") {
		document.write("<script defer src=../js/ie_sslInit.js><\/script>");
	}
	else {
		document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
		var script = document.getElementById("__ie_onload");
		script.onreadystatechange = function() {
			if (this.readyState == "complete") {
				init(); // call the onload handler
			}
		}
	}
};
/*@end @*/

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = init;

function init() {
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_timer) clearInterval(_timer);
	// do stuff
	prep();
	//rotateBanner();
	
	
};

function prep() {
	if (location.href.indexOf("/tools/glossary.aspx") > -1) {
		if (window.glossaryToggle) {
			glossaryToggle();
		}
	}	
	
	if(document.getElementById("pfizerCode")) {
		//document.getElementById("pfizerCode").innerHTML="LPU01292L1";
		document.getElementById("pfizerCode").innerHTML="LPU01292I3";
	}
	
	//var contentArea3Removed = false;
	if(location.href.indexOf("/tools/") > -1)
	{
	    //alert("test");
	    //HideNextLink();
	    hidediv("contentArea_3");
	    //contentArea3Removed = true;
	}


}

/************* FAQs realted javascript ********************************/

function ExpandorCollapse(parentNode)
{
   if (parentNode.getElementsByTagName('div')[0].style.display == 'none')
    {
         parentNode.getElementsByTagName('div')[0].style.display = 'block';
    } 
    else
    {
         parentNode.getElementsByTagName('div')[0].style.display = 'none';
    }
}

/************* End of FAQs realted javascript ********************************/

function HideNextLink()
{
    document.getElementById('divNextLink').className="nextLinkHide";
}
/********************** Moved from universal to common.js *****************************************/
function pageInit() {
}
function addToPageInit() {
	var initialContents = pageInit;
	var functionList = new String;
	functionList[0] = initialContents;
	for (var i=1;i<=arguments.length;i++) {
		functionList[i] += arguments[i];
	}
	pageInit = functionList;
}

/*******************************Script used for search control****************************/

function OpenPartnerUrl(urlId, name, link) {
   PartnerLinkClicked(name,link); 
   url = null; 
   switch(urlId) {
      case '1' : {
         url = "http://labeling.pfizer.com/ShowLabeling.aspx?id=588"; 
         break; 
         }
          case '2' : {
         url = "http://labeling.pfizer.com/ShowLabeling.aspx?id=587"; 
         break; 
         }
       }
         if(url) {
      window.open(url); 
      }
}

function GoToPartnerUrl(urlId, name, link) {
   PartnerLinkClicked(name,link); 
   url = null; 
   switch(urlId) {
      case '1' : {
         url = "http://labeling.pfizer.com/ShowLabeling.aspx?id=587"; 
         break; 
         }
      case '2' : {
         url = "http://www.pfizer.com"; 
         break; 
         }
          case '3' : {
         url = "http://pfizer.com/pfizer/privacy/mn_privacy_truste.jsp"; 
         break; 
         }
          case '7' : {
         url = "http://pfizer.com/pfizer/privacy/mn_privacy_truste.jsp"; 
         break;
         } 
           case '8' : {
         url = "http://www.pfizer.com/general/terms.jsp"; 
         break; 
         }
      }
  if(url) {
      window.location = url; 
      }
 }
 
var SessionValue ="";   
        
function GetSessionValue(key) 
{
   try {
      xmlHttp = new XMLHttpRequest(); 
      }
   catch (e) {
      try {
         xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 
         }
      catch (e) {
         try {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
            }
         catch (e) {
            alert("Your browser does not support AJAX!"); 
            return false; 
            }
         }
      }
   url = "../GetSessionValue.aspx?key=" + key + "&dummy=" + new Date().getTime(); 
   xmlHttp.open("GET", url, false); 
   xmlHttp.send(null); 
      if(xmlHttp.status == 200)
      {
         SessionValue = xmlHttp.responseText; 
      }
     return SessionValue;
 }

 function GetHTTPSSessionValue(key)
 {
     try {
         xmlHttp = new XMLHttpRequest();
     }
     catch (e) {
         try {
             xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
         }
         catch (e) {
             try {
                 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
             }
             catch (e) {
                 alert("Your browser does not support AJAX!");
                 return false;
             }
         }
     }
     var urlHostName = document.location.hostname;

     if (getHostName() == 'true')
     {
         url = "https://" + urlHostName + "/GetSessionValue.aspx?key=" + key + "&dummy=" + new Date().getTime();
     }

     else
     {
         url = "http://" + urlHostName + "/GetSessionValue.aspx?key=" + key + "&dummy=" + new Date().getTime();
     }

     xmlHttp.open("GET", url, false);
     xmlHttp.send(null);
     if (xmlHttp.status == 200) {
         SessionValue = xmlHttp.responseText;
     }
     return SessionValue;
 }

function hidediv(id) 
{
   //safe function to hide an element with a specified id
   if (document.getElementById) { // DOM3 = IE5, NS6
 		document.getElementById(id).style.display = 'none';
   }
   else {
		if (document.layers) { // Netscape 4
			document.id.display = 'hidden';
		}
		else { // IE 4
			document.all.id.style.display = 'hidden';
		}
   }
}

function getHostName() 
{            
	var hostName = "";
	if((location.hostname.toLowerCase() == 'www.lipitor.com') || (location.hostname.toLowerCase() == 'lipitor.com'))
		hostName="true" // Production ;
	else
		hostName="false" // dev
    
	return hostName;    
}

/********************************************************
    Copay Card
********************************************************/
var firstPrereqQuestion = "default";
var secondPrereqQuestion = "default";
var thirdPrereqQuestionChecked = false;

var copayCardRotatorItemCount = 0;
var copayCardIndex = 0;
var copayCardLandingRotatorDelay = 8000; /* Time in miliseconds 8000 = 8 sec */
var rotatorDelayTimeout;
var rotatorStopped = false;

var omniturePageName = "";

$(function ()
{
    var referrerURL = document.location.href;

    initCopayCardRotator();

    distributeErrorMessaging();

    processHashTag();

    $('ul#tabbedContainer li').click(function () {
        var recipeTabSelectedIndex = $('ul#tabbedContainer li').index(this);

        processRecipeTabContainers(recipeTabSelectedIndex);
    });

    // Vanity URL Redirect - Tracking (Function found in urlRedirectTracking.js file)
    setVanityURLTracking();

    if (referrerURL == '' || referrerURL == null || referrerURL.indexOf('https') != -1) {
        $('a.diplomatDirectDelivery').attr("href", "/toolsResources/DiplomatDirectDeliverySecured.aspx");
    }

    $('a.diplomatDirectDelivery').live('click', function () {
        $.Boxen.open(this,
        {
            showTitleBar: false,
            showCloseButton: false,
            width: 800,
            height: 600,
            overlayOpacity: 0.8,
            modal: false
        });

        return false;
    });

    if (referrerURL == '' || referrerURL == null || referrerURL.indexOf('https') != -1) {
        $('a.emailAFriend').attr("href", "/emailAFriendSecured.aspx");
    }

    $('a.emailAFriend').live('click', function () {
        var s = s_gi(s_account);
        s.linkTrackVars = 'events';
        s.linkTrackEvents = 'event37';
        s.events = 'event37';
        s.tl(this, 'o', '');

        $.Boxen.open(this,
        {
            showTitleBar: false,
            showCloseButton: false,
            width: 720,
            height: 302,
            overlayOpacity: 0.8,
            modal: false
        });

        return false;
    });

    if ($('.inputFieldDefaultTextOptional').val() == '') {
        $('.inputFieldDefaultTextOptional').val('(Optional)');
    }

    $('.inputFieldDefaultText').click(function () {
        if ($(this).val() == '(Optional)' || $(this).val() == 'Enter e-mail address') {
            $(this).val('');
        }
    });

    // Copay Card Landing Page Rotator 
    $('div#rotatorControls ul li').click(function () {
        var currentRotatorIndex = $('div#rotatorControls ul li').index($(this));
        rotatorStopped = true;
        populateCopayCardLandingRotator(currentRotatorIndex);
    });

    // Copay Card Registration and Activation
    checkPrereqQuestions();

    $('.scrollToLocation, .scrollToLocationBackToTop').live('click', function (e) {
        var getScrollToLocation = $(this).attr('data-scrollTo');

        processScrollTo(getScrollToLocation);

        return false;
    });

    $('input:radio[name=medicare]').click(function () {
        if ($(this).attr('id') == 'Q12232|A15692') {
            firstPrereqQuestion = true;
            regristrationIneligibleRedirect();
        }

        if ($(this).attr('id') == 'Q12232|A15693') {
            firstPrereqQuestion = false;
        }

        processPrereqQuestions();
    });

    $('input:radio[name=Q13244]').click(function () {
        if ($(this).attr('id') == 'Q13244|A18722') {
            secondPrereqQuestion = true;
            regristrationIneligibleRedirect();
        }

        if ($(this).attr('id') == 'Q13244|A18723') {
            secondPrereqQuestion = false;
        }

        processPrereqQuestions();
    });

    $('.atLeastEighteenCheckBox').click(function () {
        if ($(this).is(':checked') === true) {
            thirdPrereqQuestionChecked = true;
        }

        else {
            regristrationIneligibleRedirect();
            thirdPrereqQuestionChecked = false;
        }

        processPrereqQuestions();
    });

    /************* Search Box realted javascript ********************************/
    $('input#txtKeywords').focus(function () {
        $(this).css('height', '15px');
    });

    if ($.client.os == 'Mac') {
        $('div#header ul#mainNav li ul li a').css('padding-top', '5px');
    }

    $('.importantInfoRegistrationRedirect').click(function () {
        window.parent.closeIFRAME();
        window.parent.location = "http://" + window.location.host + "" + $(this).attr('href');
    });

    $('input.frmSubmit').hover(function () {
        $(this).attr('src', '/images/buttons/btnSubmitOver.gif');
    },
		function () {
		    $(this).attr('src', '/images/buttons/btnSubmitOff.gif');
		}
	);

    $('input.frmSendEmail').hover(function () {
        $(this).attr('src', '/images/buttons/btnSendEmailOver.gif');
    },
	function () {
	    $(this).attr('src', '/images/buttons/btnSendEmailOff.gif');
	});

    if (window != top) {
        $('body').css({ 'background': '#333' });
    }

    $('p.btnClose, p.btnReturnToPage').click(function () {
        window.parent.closeIFRAME();
    });

    if (referrerURL == '' || referrerURL == null || referrerURL.indexOf('https') != -1) {
        $('a.findADoctor').attr("href", "/toolsResources/DoctorLookupIFrameSecured.aspx");
    }

    $('.findADoctor').boxen(
    {
        showTitleBar: false,
        showCloseButton: false,
        width: 720,
        height: 680,
        overlayOpacity: 0.8,
        modal: false
    });

    if (referrerURL == '' || referrerURL == null || referrerURL.indexOf('https') != -1) {
        $('a.informationYouNeedToEnroll').attr("href", "/toolsResources/InformationYouNeedToEnrollSecured.aspx");
    }

    $('a.informationYouNeedToEnroll').boxen(
    {
        showTitleBar: false,
        showCloseButton: false,
        width: 720,
        height: 300,
        overlayOpacity: 0.8,
        modal: false
    });


    /***********************************************
    Costco / Walgreens :: Javascript
    ***********************************************/
    $('body#lipitorCostco span#siteUtilitiesContainer a.emailAFriend, body#lipitorWalgreens span#siteUtilitiesContainer a.emailAFriend').hide();
});

function processRecipeTabContainers(selectedIndex)
{
    $('ul#tabbedContainer li').removeClass('active');
    $('ul#tabbedContainer li').eq(selectedIndex).addClass('active');

    $('div#tabMainContainer div.tabContainers').removeClass('active');
    $('div#tabMainContainer div.tabContainers').eq(selectedIndex).addClass('active');
}

function processHashTag()
{
    processScrollTo(retrieveHashTag);
}

function retrieveHashTag()
{
    var currentHashTag = window.location.hash;
    var cleanedUpLocation;

    if(currentHashTag)
    {
        cleanedUpLocation = currentHashTag.replace('#', '');
        cleanedUpLocation = cleanedUpLocation.substring(0, cleanedUpLocation.indexOf('?'));
    }

    return cleanedUpLocation;
}

function closeIFRAME()
{
    $('#boxen_overlay, #boxen_container').fadeOut('fast',function ()
    {
        $('#boxen_overlay, #boxen_container').remove();
    });
}

function initCopayCardRotator()
{
    copayCardRotatorItemCount = $('#rotatorInitialCopyContainer div.rotatorContainer').size()-1;
    
    populateCopayCardLandingRotator(copayCardIndex);
}

// Copay Card Landing Page Rotator
function populateCopayCardLandingRotator(index)
{
    clearTimeout(rotatorDelayTimeout);
    
    $('#copayCardRotatorDisplayContainer div#copayCardRotatorImage').html($('#rotatorInitialCopyContainer div.rotatorContainer').eq(index).children('.rotatorImage').html());
    $('#copayCardRotatorDisplayContainer div#copayCardRotatorContent').html($('#rotatorInitialCopyContainer div.rotatorContainer').eq(index).children('.rotatorContent').html());
    $('#copayCardRotatorDisplayContainer div#copayCardRotatorContent').height($('#rotatorInitialCopyContainer div.rotatorContainer').eq(index).children('.rotatorContent').css('height'));
    $('div#rotatorControls ul li').removeClass('active');
    $('div#rotatorControls ul li').eq(index).addClass('active');
    
    copayCardRotatorLoop();
}

function copayCardRotatorLoop()
{
    if(copayCardRotatorItemCount > 1 && rotatorStopped == false)
    {
        clearTimeout(rotatorDelayTimeout);

        if(copayCardIndex >= copayCardRotatorItemCount)
        {
            copayCardIndex = 0;
        }
        
        else
        {
            copayCardIndex++;
        }
        
        rotatorDelayTimeout = setTimeout('populateCopayCardLandingRotator("'+copayCardIndex+'");', copayCardLandingRotatorDelay);
    }
}

function checkPrereqQuestions()
{
    if(($('input:radio[name=medicare]:checked').val() == 'A15693|No') && ($('input:radio[name=Q13244]:checked').val() == 'A18723|No') && $('.atLeastEighteenCheckBox').is(':checked'))
    {
        $('#lipitorForYouRegistrationContainer, #lipitorForYouRegistrationBtmContainer').show();
        $('input:radio[name=medicare], input:radio[name=Q13244], .atLeastEighteenCheckBox').attr('disabled', 'disabled');
    }
}

function processPrereqQuestions()
{
    if(firstPrereqQuestion == false && secondPrereqQuestion == false && thirdPrereqQuestionChecked == true)
    {
        $('#lipitorForYouRegistrationContainer, #lipitorForYouRegistrationBtmContainer').fadeIn(500);
        $('input:radio[name=medicare], input:radio[name=Q13244], .atLeastEighteenCheckBox').attr('disabled', 'disabled');

        if($('#lipitorForYouRegistrationContainer').hasClass('registrationPageEligibleContent'))
        {
            var s=s_gi(s_account);
            s.events='event22';
            s.t();
        }

        else if($('#lipitorForYouRegistrationContainer').hasClass('activationPageEligibleContent'))
        {
            var s=s_gi(s_account);
            s.events='event28';
            s.t();
        }
    }
    
    else
    {
        $('#lipitorForYouRegistrationContainer, #lipitorForYouRegistrationBtmContainer').fadeOut(500);
    }
}

function regristrationIneligibleRedirect()
{
    var siteDomain = "http://" + window.location.host;
    
    if($('body').hasClass('lipitorForPatients'))
    {
        window.location = siteDomain + "/patients/LipitorCoPayCardNotEligible.aspx";
    }

    else if($('body').attr('id') == 'lipitorCostco')
    {
        window.location = siteDomain + "/costco/LipitorCoPayCardNotEligible.aspx";
    }

    else if($('body').attr('id') == 'lipitorWalgreens')
    {
        window.location = siteDomain + "/unbranded/LipitorCoPayCardNotEligible.aspx";
    }

    else
    {
        window.location = siteDomain + "/patients/LipitorCoPayCardNotEligible.aspx";
    }
}

function distributeErrorMessaging()
{
    // total # of errorContainer class divs
    var errorMessageContainerSize = $('.errorContainer').size();

    for (var i = 0; i < errorMessageContainerSize; i++)
    {
        // total # of span containers with error class in each .errorContainer div
        var interiorPossibleErrorSize = $('.errorContainer').eq(i).children('span.error').size();

        for (var u = 0; u < interiorPossibleErrorSize; u++)
        {
            if($('.errorContainer').eq(i).children('span.error').eq(u).text().length > 0) {
                
                $('.errorContainer').eq(i).show();
                $('.errorContainer').eq(i).parent('div').children('div.errorFieldContainer').eq(u).addClass('errorField');
            }
        }
    }
}

function clearDoctorSearchCookie()
{
    set_cookie("doctorSearchBtnClicked", "", -1, "/");
}

/***********************************************************************
    processScrollTo :: Function
***********************************************************************/
function processScrollTo(id)
{
    if($('#' + id).length)
    {
        var targetOffset = $('#' + id).offset().top;
        $('html, body').animate({ scrollTop: targetOffset }, 500);
    }
}

/***********************************************************************
    Cookie :: Function
***********************************************************************/
function set_cookie(name, value, expires, path)
{	
    var cookie_string = name + "=" + escape(value) + "; ";

	if(expires)
	{
		expires = setExpiration(expires);
		cookie_string += "expires=" + expires + "; ";
	}
	
	if(path)
	{
		cookie_string += "path=" + path + "; ";
	}

    document.cookie = cookie_string;
}

function get_cookie(cookie_name)
{
    var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

    if (results)
    {
        return (unescape(results[2]));
    }

    else
    {
        return null;
    }
}

function setExpiration(cookieLife)
{
    var today = new Date();
    var expr = new Date(today.getTime() + cookieLife * 24 * 60 * 60 * 1000);
    return expr.toGMTString();
}


/***********************************************************************
    Get URL Parameter :: Function
***********************************************************************/
function getURLParameter(name)
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+ name +"=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    
    if(results == null)
    {
        return "";
    }

    else
    {
        return results[1];
    }
}

