/*
** LayerMaker API
** David Rautert
** April 28, 2008
*/


// Configurable Directives
var leavingSiteActiveLink;
var leavingSiteExcludeSites = Array();
var leavingSiteOwnSites = Array('sankyopharma.com', 'www.dsus.com','FDA.gov');
var overlayOpacity = 0.6;
var anchorIdent = 'headerArea';
var didYouKnowActiveSendTo;

var layerSets = {
    'Leaving the Site': {
        isActive: true,
        animate: true,
        overlayer: true,
        init: function() { initLeaveSite(); return false; },
        activate: function(activeLink) {
            sandbox = document.getElementById('leavingTheSiteLayer').getElementsByTagName("*");
            for (var a = 0; a < sandbox.length; a++) {
                if (sandbox[a].className == "continueButton") {
                    sandbox[a].getElementsByTagName("a")[0].href = activeLink.href;
                    sandbox[a].getElementsByTagName("a")[0].setAttribute("target", "_blank");
                    sandbox[a].getElementsByTagName("a")[0].onclick = function() { layerMaker_info.deactivate(); setTimeout("", 300); };
                }
            }
            return false;
        },
        layerIdent: 'leavingTheSiteLayer',
        layerClass: 'popoverLayerWrap',
        closeButton: true,
        headerCopy: 'You are leaving EVOXAC.com',
        bodyCopy: 'Please note: You are about to leave the EVOXAC.com website by opening a new web page. Daiichi Sankyo, Inc. does not control the content of the website connected to this link.',
        bodyIdent: '',
        buttonArea: Array("cancel", "continue"),
        continueBtnId: "leavingTheSiteContinueBtn"
    },
    'HCP Disclaimer': {
        isActive: true,
        animate: true,
        overlayer: true,
        init: function() { initHCPDisclaimer(); return false; },
        activate: function(activeLink) {
            workingId = layerSets['HCP Disclaimer']['continueBtnId'];
            var workingObj = document.getElementById(workingId);
            workingObj.href = activeLink;
            workingObj.onclick = function() { hcpDisclaimerConfirmed(); };
        },
        layerIdent: 'hcpDisclaimerLayer',
        layerClass: 'popoverLayerWrap',
		headerCopy: 'Notice and Healthcare Provider Certification',
        closeButton: true,
        bodyCopy: Array('The following information is intended only for healthcare professionals licensed and practicing in the United States and is designed to be an educational aid that supplements and draws upon the professional training, experience, and knowledge of such healthcare professionals. If you are a patient or consumer, or are seeking the information for the benefit of a patient or consumer, please see the patient information section of our site, which has been specifically designed to provide information of interest to patients and consumers.', 'Do you certify that you are a healthcare professional licensed and practicing your profession in the United States?'),
        bodyIdent: '',
        buttonArea: Array("cancel", "continue"),
        continueBtnId: "hcpDisclaimerContinueBtn"
    },
    'External DSI Disclaimer': {
        isActive: true,
        animate: true,
        overlayer: true,
        init: function() { initLeaveToDSI(); return false; },
        activate: function(activeLink) {
            sandbox = document.getElementById('externalDSILayer').getElementsByTagName("*");
            for (var a = 0; a < sandbox.length; a++) {
                if (sandbox[a].className == "continueButton") {
                    sandbox[a].getElementsByTagName("a")[0].href = activeLink.href;
                    sandbox[a].getElementsByTagName("a")[0].setAttribute("target", "_blank");
                    sandbox[a].getElementsByTagName("a")[0].onclick = function() { layerMaker_info.deactivate(); setTimeout("", 300); };
                }
            }
            return false;
        },
        layerIdent: 'externalDSILayer',
        layerClass: 'popoverLayerWrap',
        closeButton: true,
        headerCopy: 'You are leaving EVOXAC.com',
        bodyCopy: 'Please note: You are about to leave the EVOXAC.com website and go to the Daiichi Sankyo, Inc. corporate website.',
        bodyIdent: '',
        buttonArea: Array("cancel", "continue"),
        continueBtnId: "externalDSIContinueBtn"
    },	
    'Email Confirmation': {
        isActive: true,
        animate: false,
        overlayer: true,
        layerIdent: 'emailThisPageConfirmationLayer',
        layerClass: 'popoverLayerWrap',
        closeButton: true,
        headerCopy: 'Email this page confirmation',
        bodyCopyAlignment: 'center',
        bodyCopy: Array('Your e-mail has been sent', 'Thank you for sharing this page.'),
        buttonArea: Array("close")
    },
    'Email This Page': {
        isActive: true,
        animate: true,
        overlayer: true,
        layerIdent: 'emailThisPageLayer',
        layerClass: 'popoverLayerWrap',
        closeButton: true,
        headerCopy: '',
        bodyCopy: 'After completing the fields below and clicking "SUBMIT," your friend or colleague will receive an e-mail with a link to this page.',
        bodyIdent: 'emailThisPageBodyArea',
		headerCopy:'E-mail this page',
        formArea: function() {
            if (window.location.href.match(/http(s)?:\/\//)) {
                handler = window.location.href.split("/");
                sandbox = handler[0] + "/" + handler[1] + "/" + handler[2];
            }
            // action:sandbox+'/EmailService',
            var emailThisPageForm = Builder.node('form', { id: 'emailThisPageForm', name: 'emailThisPageForm', action: sandbox + '/EmailService', method: 'post', onsubmit: 'return validateForm.init(this)' }, [
				Builder.node('div', { className: 'formlistAreaPop' }, [
					Builder.node('p', [
						Builder.node('strong', '* Required information'),
					]),
				]),
				Builder.node('input', { type: 'hidden', name: 'success', id: 'emailThisPageSuccess', value: '' }),
				Builder.node('input', { type: 'hidden', name: 'page_url', value: '' }),
				Builder.node('input', { type: 'hidden', name: 'subject', value: 'I thought this page might interest you', value: '' }),
				Builder.node('input', { type: 'hidden', name: 'targetAudience', value: '' }),
				Builder.node('div', { id: 'emailThisPageErrorContent' }),
				Builder.node('div', { className: 'clearBoth' }),
				Builder.node('div', { className: 'spacer height15' }),

				Builder.node('div', { className: 'formlistArea4' }, [
					Builder.node('p', "* Your first name"),
					Builder.node('input', { type: 'text', name: 'firstName', className: 'formTextInputArea2 required' })
				]),
				Builder.node('div', { className: 'clearBoth' }),

				Builder.node('div', { className: 'formlistArea4' }, [
					Builder.node('p', '* Your last name'),
					Builder.node('input', { type: 'text', name: 'lastName', className: 'formTextInputArea2 required' }),
				]),
				Builder.node('div', { className: 'clearBoth' }),

				Builder.node('div', { className: 'formlistArea4' }, [
					Builder.node('p', '* Your e-mail address'),
					Builder.node('input', { type: 'text', name: 'fromEmailAddress', className: 'formTextInputArea2 required' })
				]),
				Builder.node('div', { className: 'clearBoth' }),

				Builder.node('div', { className: 'formlistArea4' }, [
					Builder.node('span', { id: 'recipient1' }, '* Recipient\'s e-mail address'),
					Builder.node('input', { type: 'text', id: 'toAddress', name: 'toAddress', className: 'formTextInputArea2 required' })
				]),
				Builder.node('div', { className: 'clearBoth' }),

				Builder.node('span', { id: 'extraEmailInputs', style: 'display:none;' }),

				Builder.node('div', { className: 'formlistArea4' }, [
					Builder.node('p', { id: 'addMoreFriendLink' }, [
						Builder.node('a', { href: 'javascript:void(0);', onclick: 'addFriendInput(); return false;' }, 'Add more friends'),
					]),
				]),
				Builder.node('div', { className: 'clearBoth' }),
			]);
            document.getElementById('emailThisPageBodyArea').appendChild(emailThisPageForm);
        },
        buttonArea: Array("cancel", "sendemail")
    },
    'Form Error Layer': {
        isActive: true,
        animate: true,
        overlayer: true,
        layerPosition: 'default',
        layerIdent: 'formErrorLayer',
        layerClass: 'popoverLayerWrap',
        closeButton: true,
        headerCopy: '',
        bodyCopy: 'Error Message',
        bodyIdent: 'formErrorContentArea',
        buttonArea: Array("close")
    },
    'Why year of birth tooltip': {
        isActive: true,
        animate: true,
        overlayer: true,
        init: function() { initYearHelper(); return false; },
        activate: function() {

        },
        layerPosition: 'attachToAnchor',
        layerIdent: 'whyYearBirthLayer',
        layerClass: 'popoverLayerWrap',
        closeButton: true,
        headerCopy: 'Why we ask for your year of birth',
        bodyCopy: 'Daiichi Sankyo, Inc. does not collect information from people aged 17 years and younger. In addition, the information that you provide to us may be shared in a "blinded" format with our business partners for purposes related to Daiichi Sankyo, Inc. market research and related business uses.',
        bodyIdent: '',
        buttonArea: Array("close")
    },
    'Did you know Send To': {
        isActive: true,
        animate: true,
        overlayer: true,
        activate: function() {
            for (var n in didYouKnowSets) {
                if (didYouKnowSets[n]["inputName"] == didYouKnowActiveSendTo.replace("anchor_", "")) {
                    var myFormArea = document.getElementById('dykSendToFormArea');
                    // grab emails entered
                    var inputs = document.tellAFriend.getElementsByTagName("input");
                    var didEmails = new Array();
                    var counter = 0;
                    for (var x = 0; x < inputs.length; x++) {
                        if (inputs[x].getAttribute("name")) {
                            if (inputs[x].getAttribute("name").match(/address_/) && inputs[x].value != "") {
                                didEmails[counter] = inputs[x].value;
                                counter++;
                            }
                        }
                    }
                    myFormArea.innerHTML = "";
                    for (var x = 0; x < didEmails.length; x++) {
                        var inputLine = Builder.node('div'/*, {style:'margin:10px 0px 0px 0px; padding:0px 0px 0px 40px;'}*/, [
							Builder.node('input', { type: 'checkbox', id: 'tempCheckbox_', onclick: '', checked: 'checked'/*, style:'float:left;line-height:13px;'*/ }),
							Builder.node('p'/*, {style:'float:left; margin:0px 0px 0px 5px; width:100px; font-family:Arial; font-size:12px; line-height:13px;'}*/, didEmails[x])/*,
							Builder.node('div', {className:'clearBoth'})*/
						]);
                        myFormArea.appendChild(inputLine);
                    }
                    if (didEmails.length < 1) {
                        var inputLine = Builder.node('p'/*, {style:'float:left; margin:10px 0px 0px 20px;font-family:Arial; font-size:12px; line-height:13px;'}, 'Please enter a recipient e-mail address.'*/);
                        myFormArea.appendChild(inputLine);
                    }
                    var clearBoth = Builder.node('div', { className: 'clearBoth' });
                    myFormArea.appendChild(clearBoth);
                }
            }
        },
        layerPosition: 'attachToAnchor',
        layerIdent: 'dykSendToLayer',
        layerClass: 'popoverLayerWrap',
        closeButton: true,
        headerCopy: 'Send To...',
        formArea: function() {
            var formContainer = Builder.node('div', { id: 'dykSendToFormArea' });
            document.getElementById('dykSendToBody').appendChild(formContainer);
        },
        bodyCopy: 'Choose which friends below you\'d like to send this \'Did You Know\' to:',
        bodyIdent: 'dykSendToBody',
        buttonArea: Array("close", "cancel")
    },
	'Find a Rheumatologist': {
        isActive: true,
        animate: true,
		activate: function(activeLink) {
            sandbox = document.getElementById('rheumatologistSiteLayer').getElementsByTagName("*");
            for (var a = 0; a < sandbox.length; a++) {
                if (sandbox[a].className == "continueButton") {
                    sandbox[a].getElementsByTagName("a")[0].href = activeLink.href;
                    sandbox[a].getElementsByTagName("a")[0].setAttribute("target", "_blank");
                    sandbox[a].getElementsByTagName("a")[0].onclick = function() { layerMaker_info.deactivate(); setTimeout("", 300); };
                }
            }
            return false;
        },
        overlayer: true,
		layerIdent: 'rheumatologistSiteLayer',
        layerClass: 'popoverLayerWrap',
        closeButton: true,
        headerCopy: 'You are leaving EVOXAC.com',
        bodyCopy: Array('Daiichi Sankyo is providing this service to help patients find rheumatologists in their area. No fees have been received by or paid to rheumatologists for participation in this specialist locator service. Inclusion of a physician in this directory does not represent an endorsement by or a recommendation from Daiichi Sankyo. You are ultimately responsible for the selection of a physician and it is an important decision that you should consider carefully. This rheumatologist locator tool is just one source of information available to you.'),
        buttonArea: Array("cancel", "continue"),
		 continueBtnId: "externalDSIContinueBtn"
    }
};


/*

	
** *************************** **
** Do Not Edit Below This Line **
** *************************** **
*/

var layerMaker_info = {
    init: function() {
        layerMaker_info.rebuildTheDarkness();
        for (var x in layerSets) {
            if (layerSets[x]['isActive'] == true) {
                layerMaker_info.construct(layerSets[x]);
                if (layerSets[x]['init']) {
                    layerSets[x].init();
                }
            }
        }
    },

    activate: function(layerName, activatedObj) {
        /*toggleSelect("hide");
        toggleFlash("hide");*/
        if (layerSets[layerName]['overlayer'] == true) {
            layerMaker_info.rebuildTheDarkness();
            new Effect.Appear(document.getElementById('overlayer'), { duration: 0.25, from: 0.0, to: overlayOpacity });
        }
        if (layerSets[layerName]['activate']) {
            layerSets[layerName].activate(activatedObj);
        }
        layerMaker_info.setPosition(layerName);

        new Effect.Appear(document.getElementById(layerSets[layerName].layerIdent), { duration: 0.75 });
    },

    continueBtn: function() {

    },

    deactivate: function() {
        for (var layer in layerSets) {
            if (document.getElementById(layerSets[layer]['layerIdent'])) {
                workingObj = document.getElementById(layerSets[layer]['layerIdent']);
                new Effect.Fade(workingObj, { duration: 0.25 });
            }
        }
        new Effect.Fade(document.getElementById('overlayer'), { duration: 0.25 });
        toggleSelect("show");
        toggleFlash("show");
    },

    setPosition: function(layerName) {

        var layerObj = document.getElementById(layerSets[layerName]['layerIdent']);
        var workingElem = anchorIdent;
        var curtop = 0;
        var curleft = 0;
        var xScroll, yScroll;
        var windowWidth, windowHeight;
        var objWidth = getStyle(layerObj, "width");
        var objHeight = getStyle(layerObj, "height");

        if (layerSets[layerName]['layerPosition']) {
            switch (layerSets[layerName]['layerPosition']) {
                case "attachToAnchor":
                    break;
                case "default":
                    break;
            }
        } else {

        }

        if (workingElem.offsetParent) {
            curleft = workingElem.offsetLeft;
            curtop = workingElem.offsetTop;
            while (workingElem = workingElem.offsetParent) {
                curleft += workingElem.offsetLeft;
                curtop += workingElem.offsetTop;
            }
        }

        if (self.pageYOffset) {
            yScroll = self.pageYOffset;
            xScroll = self.pageXOffset;
        } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
            yScroll = document.documentElement.scrollTop;
            xScroll = document.documentElement.scrollLeft;
        } else if (document.body) {// all other Explorers
            yScroll = document.body.scrollTop;
            xScroll = document.body.scrollLeft;
        }

        if (self.innerHeight) {	// all except Explorer
            if (document.documentElement.clientWidth) {
                windowWidth = document.documentElement.clientWidth;
            } else {
                windowWidth = self.innerWidth;
            }
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }

        xChange = parseInt(windowWidth) / 2 - parseInt(objWidth) / 2;
        yChange = parseInt("175px") + parseInt(yScroll);
        layerObj.style.top = parseInt(curtop) + parseInt(yChange) + "px";
        layerObj.style.left = parseInt(curleft) + parseInt(xChange) + "px";
    },

    /* ====================== ==
    ** The __construct method ==
    */
    construct: function(layerObj) {
        var objBody = document.getElementsByTagName("body").item(0);

        if (document.getElementById(layerObj['layerIdent'])) {
            objBody.removeChild(document.getElementById(layerObj['layerIdent']));
        }

        var popoverWrap = Builder.node('div', { id: layerObj['layerIdent'], className: layerObj['layerClass'], style: 'display:none; position:absolute;' });
        objBody.appendChild(popoverWrap);


        var popoverTopArea = Builder.node('div', { className: 'popoverTopArea' }, [
			Builder.node('h3', { className: 'closePopoverBtn' }, [
				Builder.node('a', { onclick: 'layerMaker_info.deactivate(); return false;' }, 'Close'
				),
			]),
		]);
        popoverWrap.appendChild(popoverTopArea);

        if (!layerObj['bodyIdent']) {
            layerObj['bodyIdent'] = "";
        }
        var popoverContentArea = Builder.node('div', { id: layerObj['bodyIdent'], className: 'popoverContentArea' }, [
			Builder.node('h2', { className: 'popoverMainTitle' }, [
				Builder.node('span', { className: 'headerMessage' }, layerObj['headerCopy'])
			]),
		]);
        if (layerObj['bodyCopyAlignment']) {
            popoverContentArea.style.textAlign = layerObj['bodyCopyAlignment'];
        }
        popoverWrap.appendChild(popoverContentArea);

        if (layerObj['bodyCopy']) {
            if (typeof (layerObj['bodyCopy']) == "string") {
                bodyObj = Builder.node('p', { className: 'popoverContentBlock' }, layerObj['bodyCopy']);
                popoverContentArea.appendChild(bodyObj);
            } else {
                var bodyObj = new Array();
                for (var b = 0; b < layerObj['bodyCopy'].length; b++) {
                    bodyObj[b] = Builder.node('p', { className: 'popoverContentBlock' }, layerObj['bodyCopy'][b]);
                    popoverContentArea.appendChild(bodyObj[b]);
                }
            }

        }


        if (layerObj['formArea']) {
            if (typeof (layerObj['formArea']) == "function") {
                layerObj.formArea();
            }
        }


        if (layerObj['buttonArea']) {
            var popoverButtonArea = Builder.node('div', { className: 'popoverBtnArea' });
            popoverContentArea.appendChild(popoverButtonArea);
            buttonObjs = new Array();
            for (var i = 0; i < layerObj['buttonArea'].length; i++) {
                switch (layerObj['buttonArea'][i]) {
                    case "cancel":
                        buttonObjs[i] = Builder.node('h3', { className: 'cancelButton' }, [
							Builder.node('a', { onclick: 'layerMaker_info.deactivate(); return false;' }, [
								Builder.node('span', { className: 'headerMessage' }, 'Cancel Button')
							]),
						]);
                        popoverButtonArea.appendChild(buttonObjs[i]);
                        break;
                    case "continue":
                        if (layerObj['continueBtnId']) {
                            workingIdent = layerObj['continueBtnId'];
                        } else {
                            workingIdent = "";
                        }
                        buttonObjs[i] = Builder.node('h3', { className: 'continueButton' }, [
							Builder.node('a', { id: workingIdent, onclick: 'layerMaker_info.continueBtn();' }, [
								Builder.node('span', { className: 'headerMessage' }, 'Continue Button')
							]),
						]);
                        popoverButtonArea.appendChild(buttonObjs[i]);
                        break;
                    case "close":
                        buttonObjs[i] = Builder.node('h3', { className: 'closeButton' }, [
							Builder.node('a', { onclick: 'layerMaker_info.deactivate(); return false;' }, 'Close'),
						]);
                        popoverButtonArea.appendChild(buttonObjs[i]);
                        break;
                    case "send":
                        buttonObjs[i] = Builder.node('h3', { className: 'sendButton' }, [
							Builder.node('a', [
								Builder.node('span', { className: 'headerMessage' }, 'Send Button')
							]),
						]);
                        popoverButtonArea.appendChild(buttonObjs[i]);
                        break;
                    case "sendemail":
                        buttonObjs[i] = Builder.node('h3', { className: 'sendButton', onclick: 'submitEmailThisPage();' }, [
							Builder.node('a', [
								Builder.node('span', { className: 'headerMessage' }, 'Send Button')
							]),
						]);
                        popoverButtonArea.appendChild(buttonObjs[i]);
                        break;
                }
            }
        }

        var popoverBottomArea = Builder.node('div', { className: 'popoverBottomArea' });
        popoverWrap.appendChild(popoverBottomArea);

    },

    rebuildTheDarkness: function() {
        var objBody = document.getElementsByTagName("body").item(0);

        if (document.getElementById('overlayer')) {
            objBody.removeChild(document.getElementById('overlayer'));
        }

        var overLayer = Builder.node('div', { id: 'overlayer', style: 'position:absolute; top:0px; left:0px; display:none; background-color:#000000; z-index:9999;' });
        objBody.appendChild(overLayer);

        var arrayPageSize = getPageSize();
        overLayer.style.width = "100%";
        overLayer.style.height = arrayPageSize[1] + "px";
        overLayer.onclick = function() { layerMaker_info.deactivate(); return false; };
    }
};

