// All global funtions
$(document).ready(function(){
//add target blank to footer links because Strict XHTML doesn't allow it
$("#footerContainer a[href^=http]").click( function() {
if(this.href!="http://www.fda.gov/medwatch" && this.href!="http://pparx.org/" && this.href!="http://americanhumane.org/"){
window.open(this.href);
}
return false;
});
//Create a cookie with the current URL
myCurrentURL();
myCurrentFontSize();
if (getUrlVars()){
modifyLogo();
}
$(".track").live("click", function(){
var name = $(this).attr('name');
var arr = name.split('|');
_gaq.push(['_trackEvent', arr[0], arr[1], arr[2]]);
});
});
function myCurrentURL() {
var myURL = window.location.href;
createCookie('myCurrentURL', myURL,1);
}
//Get all the variables from the URL
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];
//Get the URL variables
var myVariable = hash[0];
var myVariableValue = hash[1];
//Remove all the CSS for the print page
if (myVariable == "printPop" && myVariableValue == 'true'){
removeCSSFiles();
flashPrintView();
return true;
}
//Active the TAB in the MAIN NAV
if (myVariable == "tab"){
//Call the function to active the tab
activeTab(myVariableValue);
}
}
}
/******************PRINT FUNCTIONALITY**************************/
// Set the printPop variable to open a print view page
function printView(){
//Create a cookie to remember my current path
var myTabPath = window.location.href;
//Add Variable to Print View
var myPath = window.location.pathname.split('?');
if ( myPath[0].indexOf("patient-support-program/content") > -1){
var recipePage = myPath[0].substring(myPath[0].lastIndexOf('/')+1, myPath[0].lastIndexOf('.'))
myTabPath = parent.window.location.pathname.split('?') + "?openLayer=" + recipePage;
createCookie('myRememberPath', myTabPath,1);
parent.window.location.href= myPath+'?printPop=true';
}else{
createCookie('myRememberPath', myTabPath,1);
window.location.href= myPath+'?printPop=true';
}
}
function modifyLogo(){
$('#wrapper .header ul li.logo a img').attr('src','/assets/images/print/icn-spiriva-print.gif');
var myRememberURL = readCookie('myRememberPath');
//$('#wrapper .header #printBtns a#back').attr('href',myRememberURL);
$('#wrapper .header #printBtns a#back').attr('href',myRememberURL);
$('.recipe_content #printBtns a#back').attr('href',myRememberURL);
}
// Remove all CSS and add a new one for print styles
function removeCSSFiles(){
$("link[href*='.css']").each(function() {
if($(this).attr("href").indexOf("Font.css")<=0){
$(this).remove();
}
$('a.close').css('display', 'none');
});
//Add default font to print recipe popup
if( window.location.href.indexOf("patient-support-program/content") > -1){
var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", "/assets/css/defaultFont.css");
if (typeof fileref!="undefined") {
document.getElementsByTagName("head")[0].appendChild(fileref);
}
}
//Add My CSS to print
var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", "/assets/css/reset-min.css");
if (typeof fileref!="undefined") {
document.getElementsByTagName("head")[0].appendChild(fileref);
}
//Add My CSS to print
var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", "/assets/css/print-popup.css");
if (typeof fileref!="undefined") {
document.getElementsByTagName("head")[0].appendChild(fileref);
}
//Add My CSS Media Print
var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("media", "print");
fileref.setAttribute("href", "/assets/css/print-media.css");
if (typeof fileref!="undefined") {
document.getElementsByTagName("head")[0].appendChild(fileref);
}
//Change logo image
var fileref=document.createElement("img");
fileref.setAttribute("witdth", "208");
fileref.setAttribute("height", "47");
fileref.setAttribute("alt", "SPIRIVA");
fileref.setAttribute("src", "/assets/images/print/icn-spiriva-print.gif");
if (typeof fileref!="undefined") {
$('.header .logo').html(fileref);
}
if( $('.slide_show').children().length > 0){
pspPrintSlideShow();
}
$('#mainInformation a').click(function(e) {
e.preventDefault();
});
$('a.fancy-leave').removeClass("fancy-leave");
$('#fancybox-overlay, #fancybox-wrap').remove();
}
function flashPrintView(){
var goURL=window.location.href;
var removesearchString =window.location.search;
goURL = goURL.replace(removesearchString, "");
textFlashPrint='This content cannot be printed. To view video, go to '+ goURL +'';
$(".fancy-interactive-house").parent().append(''+ textFlashPrint + '
');
$("#spiriva-video").append(''+ textFlashPrint +'
');
$(".fancy-lung-tour").parent().append(''+ textFlashPrint +'
');
$("#flash-obj").parent().append(''+ textFlashPrint +'
');
/*$(".fancy-psp-video-gallery").parent().prepend(''+ textFlashPrint +'
');*/
$(''+ textFlashPrint +'
').insertAfter(".stories");
if( $('.interactive-house').length > 0){
$(''+ textFlashPrint +'
').insertAfter("#video_container");
}
}
function pspPrintSlideShow(){
var newSlideShow="";
for(var i =0; i < $('.text_content .slide_show').children().length*2; i++){
newSlideShow= $('#video_container .slide_show li')[0];
$(".text_content .slide_show li:eq("+[i]+")").after(newSlideShow);
i++;
}
$('#video_container .slide_show').remove();
/*$('.text_content').html('');
for(var j =0; j < newSlideShow.length; j++){
$('.text_content .compressSlideShow').append(newSlideShow[j]);
}*/
}
/***************CHANGE THE FONT SIZE UTILITY*************/
function changeFont(myFontChange, myElement) {
removeClass();
$(myElement).addClass('current');
switch(myFontChange){
case 'small':
addNewFont('default');
setMyFont('small');
break;
case 'medium':
addNewFont('medium');
setMyFont('medium');
break;
case 'large':
addNewFont('large');
setMyFont('large');
break;
default:
break;
}
}
function removeClass() {
$('#infoUtilities ul li.last a').each(function(index) {
$(this).removeClass('current');
});
$('#tool_bar li.text_size a').each(function(index) {
$(this).removeClass('current');
});
}
function addNewFont(fontSize) {
$("head link[href$='Font.css']").attr('href', '/assets/css/'+fontSize+'Font.css');
}
function setMyFont(size){
createCookie('myCurrentFontSize', size);
}
function myCurrentFontSize(){
var myFontSize = readCookie('myCurrentFontSize');
switch(myFontSize){
case 'small':
addNewFont('default');
removeClass();
$('#infoUtilities ul li.last a.small').addClass('current');
$('#tool_bar li.text_size a.small').addClass('current');
break;
case 'medium':
addNewFont('medium');
removeClass();
$('#infoUtilities ul li.last a.medium').addClass('current');
$('#tool_bar li.text_size a.medium').addClass('current');
break;
case 'large':
addNewFont('large');
removeClass();
$('#infoUtilities ul li.last a.large').addClass('current');
$('#tool_bar li.text_size a.large').addClass('current');
break;
default:
addNewFont('default');
setMyFont('small');
}
}
/********************************************Cookie Funtionality****************************************/
function createCookie(name,value,days) {
if (days) {
var futdate = new Date();
var expdate = futdate.getTime();
expdate += 3600*1000;
futdate.setTime(expdate);
var expires = "; expires="+futdate.toGMTString();
} else {
var expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
/****/
function closeFancy() {
parent.jQuery.fancybox.close();
/*showpopupFlash();*/
return false;
}
function showpopupFlash(){
if($("#fancybox-rounded-border-top").length == 1){
$("#fancybox-rounded-border-top").remove();
$("#fancybox-rounded-border-bottom").remove();
}
$('#fancybox-content').css('background-color','transparent');
}
function openShareDialog(parameter){
var myURL = window.location.href;
createCookie('myCurrentURL', myURL+parameter,1);
$(".share-link").trigger('click');
}
function openLeaveDialog(){
$(".fancy-leave").trigger('click');
}
function onCloseShareDialog(){
var myURL = window.location.href;
createCookie('myCurrentURL', myURL,1);
}
function openVideoFancy(){
parent.openedit();
}
function openedit(){
$(".fancy-video").fancybox().trigger('click');
}
function removeClose(){
//$('#fancybox-close').remove();
}
function continueFancy() {
window.open( $("#continue").attr('href') );
return false;
}
function processMessage(result, nextUrl, message){
try{
$('#fancybox-frame').contents().find('.contentPopup .loading').addClass('hide');
if(result==true){
$('#fancybox-frame').contents().find("#successmessage").html(message);
if(nextUrl!=null)
window.location=nextUrl;
else{
//close this pop up in 10 sec
setTimeout('jQuery.fancybox.close()', 10000);
return false;
}
}else{
$('#fancybox-frame').contents().find(".contentPopup .error").removeClass('hide');
$('#fancybox-frame').contents().find("#errormessage").html(message);
}
}catch(ex){alert(ex.message);}
}