var Plavix = Plavix || {};

Plavix.DDG = function() {
    //-- Doctor Discussion Guide Class
    //-- Private variables (configuration)    
    var baseURL = "";
    var guideScript = "/ddg/customchecklist.aspx";
    var heartURL = "/heart-attack/heart-attack-questions.aspx";
    var strokeURL = "/stroke/stroke-questions.aspx";
    var padURL = "/pad/pad-questions.aspx";

    //-- Private functions
    function focusSWF() {
        /* gives the swf focus so you can begin typing in flash text fields right away */
        var fl = document.getElementById("PlavixDDG");
        if (fl) { fl.focus(); }
    }

    //-- Public Functions
    return {
        insertGuide: function(mode, container) {
            /* uses SWF Object to embed ddg flash onto webpage
            * mode - the mode you want the guide to open to.
            * container - html dom element where the flash will be embedded
            * configure urls in flashvars below
            */
           
            var checkRedirected = false;
            if ((window.location.href).indexOf("redirected") != -1) {
                checkRedirected = true;
            }
            var flashvars = {
                mode: mode,
                redirected: checkRedirected,
                baseURL: baseURL,
                guideScript: guideScript,
                heartURL: heartURL,
                strokeURL: strokeURL,
                padURL: padURL
            };
            var params = {
                menu: "false",
                wmode: "transparent"
            };
            var attributes = {
                name: "PlavixDDG",
                id: "PlavixDDG"
            };

            swfobject.embedSWF(baseURL + "/ddg/DDG.swf", container, "546", "800", "9.0.0", "/ddg/playerProductInstall.swf", flashvars, params, attributes);
            swfobject.addLoadEvent(focusSWF);
        },

        generateGuide: function(postURL, postData) {
            /* posts the user's input to a .NET page as form data, to generate a dynamic webpage (the guide)
            * this javascript form method is used to bypass some browser's popup blockers instead of posting the data via flash
            */
         
            var tempForm = document.createElement("form");
            tempForm.method = "post";
            tempForm.target = "_blank";
            tempForm.action = postURL;
            for (var i in postData) {
                var data = document.createElement("input");
                data.setAttribute("type", "hidden");
                data.setAttribute("name", i);
                data.setAttribute("value", postData[i]);
                tempForm.appendChild(data);
            }
            //give it 1 second so unica tag fires
            setTimeout(function() {
            document.body.appendChild(tempForm);
            tempForm.submit();
            document.body.removeChild(tempForm);
            }, 1000);
        },

        unicaTracking: function(mode, eventObject) {

            /* configure any unica tag names here.
            * switch cases are button/page ids from flash
            */
          
            var modeTag = "";
            var eventTag = "";

            switch (mode) {
                case "heart":
                    modeTag = "DDG_Heart_";
                    break;
                case "stroke":
                    modeTag = "DDG_Stroke_";
                    break;
                case "PAD":
                    modeTag = "DDG_PAD_";
                    break;
                default:
                    modeTag = "";
                    break;
            }

            switch (eventObject) {
                case "btn_generalHeart":
                    eventTag = "Condition_1";
                    break;
                case "btn_generalStroke":
                    eventTag = "Condition_2";
                    break;
                case "btn_generalPAD":
                    eventTag = "Condition_3";
                    break;
                case "btn_step1Continue":
                    eventTag = "Step1/Cont_Button";
                    break;
                case "btn_step2Continue":
                    eventTag = "Step2/Cont_Button";
                    break;
                case "btn_step3Continue":
                    eventTag = "Step3/Cont_Button";
                    break;
                case "btn_step4Finish":
                    eventTag = "Step4/Finish_Button";
                    break;
                case "btn_print":
                    eventTag = "Checklist/Print_Button";
                    break;
                case "steps": case "step1":
                    eventTag = "Step1";
                    break;
                case "step2":
                    eventTag = "Step2";
                    break;
                case "step3":
                    eventTag = "Step3";
                    break;
                case "step4":
                    eventTag = "Step4";
                    break;
                case "results":
                    eventTag = "Checklist";
                    break;
            }

            ntptEventTag("ev=" + modeTag + eventTag);
        }

} //end public
    } ();