var DLP_HEADLINE_TEXT           = "dlpHeadlineText";
var DLP_SUB_HEADLINE_TEXT       = "dlpSubHeadlineText";
var DLP_CREATIVE_INCLUDE        = "dlpCreativeInclude";
var DLP_FORM_AREA               = "dlpFormArea";
var DLP_LOAN_TYPE_LABEL         = "dlpLoanTypeLabel";
var DLP_LOAN_TYPE_CONTENT       = "dlpLoanTypeContent";
var DLP_HOME_DESCRIPTION_LABEL  = "dlpHomeDescriptionLabel";
var DLP_CREDIT_PROFILE_LABEL    = "dlpCreditProfileLabel";
var DLP_SUBMIT_BUTTON           = "dlpSubmitButton";
var DLP_CLICKABLE_AREA          = "dlpClickableArea";
var DLP_ANCHOR                  = "dlpAnchor";
var DLP_FORCE_PRESENTATION      = "dlpForcePresentation";
var DLP_CREATIVE_TEXT           = "dlpCreativeText";
var DLP_CREATIVE_IMAGE          = "dlpCreativeImage";
var DLP_CREATIVE_FLASH          = "dlpCreativeFlash";
var DLP_STYLESHEET_NAME         = "dynamicState.css";

var LOAN_TYPE_FIELD             = "typeOfLoan";
var LHP_LOAN_TYPE_VALUE         = "lhp";
var SEARCH_PHRASE_ELEMENT_ID    = "searchPhrase";
var STATE_TEXT_ELEMENT_ID       = "stateText";
var JS_MARKUP_TYPE              = "js";
var STATE_DISPLAY_TYPE          = "brief";
var JS_STUB                     = "<script type=\"text/javascript\"> function _execute(){eval(jsInstructions);}</script>";
var DEFAULT_SUBMIT_ACTION       = "javascript:ValidatePage1Form(document.application); document.application.submit();";
var ACCEPTABLE_FLASH_VERSION    = "7";
var _searchPhraseEnabled        = true;
var _stateDisplayEnabled        = true;


function DlpObject() {
    this.dlpElementId = null;
}

DlpObject.prototype.setPosition =
    function (xCoordinate, yCoordinate, elementId) {
        var _id = elementId;
        if (_id == null) {
            _id = this.dlpElementId;
        }

        try {
            document.getElementById(_id).style.top = yCoordinate+"px";
            document.getElementById(_id).style.left = xCoordinate+"px";
        } catch (exception) {} // Ignore. This element does not exist.
    }

DlpObject.prototype.setNudge =
    function (xNudgeAmount, yNudgeAmount, elementId) {
        var _id = elementId;
        var pixelUnitPattern = /(.+)px/;

        if (_id == null) {
            _id = this.dlpElementId;
        }

        try {
            if (yNudgeAmount != null) {
                var currentTopPosition = document.getElementById(_id).style.top;
                if (currentTopPosition == "") { // no inline style value exists.
                    currentTopPosition = dlpHelper.getGenericStyleValue(_id, "top");
                    if (currentTopPosition == null) { // no style sheet value exists. reset.
                        currentTopPosition = 0;
                    } else {
                        currentTopPosition = currentTopPosition.replace(pixelUnitPattern, "$1");
                    }
                }
                document.getElementById(_id).style.top = (parseInt(currentTopPosition) + parseInt(yNudgeAmount))+"px";
            }
            if (xNudgeAmount != null) {
                var currentLeftPosition = document.getElementById(_id).style.left;
                if (currentLeftPosition == "") {
                    currentLeftPosition = dlpHelper.getGenericStyleValue(_id, "left");
                    if (currentLeftPosition == null) {
                        currentLeftPosition = 0;
                    } else {
                        currentLeftPosition = currentLeftPosition.replace(pixelUnitPattern, "$1");
                    }
                }
                document.getElementById(_id).style.left = (parseInt(currentLeftPosition) + parseInt(xNudgeAmount))+"px";
            }
        } catch (exception) {} // Ignore. This element does not exist.
    }

DlpObject.prototype.setDimensions =
    function (width, height, elementId) {
        var _id = elementId;
        if (_id == null) {
            _id = this.dlpElementId;
        }

        try {
            document.getElementById(_id).style.width = width+"px";
            document.getElementById(_id).style.height = height+"px";
        } catch (exception) {} // Ignore. This element does not exist.
    }

DlpObject.prototype.setStackingOrder =
    function (zIndex, elementId) {
        var _id = elementId;
        if (_id == null) {
            _id = this.dlpElementId;
        }

        try {
            document.getElementById(_id).style.zIndex = zIndex;
        } catch (exception) {} // Ignore. This element does not exist.
    }

DlpObject.prototype.isVisible =
    function (isVisible, elementId) {
        var _id = elementId;
        if (_id == null) {
            _id = this.dlpElementId;
        }

        try {
            if (isVisible) {
                document.getElementById(_id).style.display = '';
            } else if (!isVisible) {
                document.getElementById(_id).style.display = 'none';
            }
        } catch (exception) {} // Ignore. This element does not exist.
    }

DlpObject.prototype.setDebugMode =
    function (isDebug, elementId) {
        var _id = elementId;
        if (_id == null) {
            _id = this.dlpElementId;
        }

        try {
            if (isDebug) {
                document.getElementById(_id).style.borderWidth = '1px';
            } else {
                document.getElementById(_id).style.borderWidth = '0px';
            }
        } catch (exception) {} // Ignore. This element does not exist.
    }

// Headline Text
function DlpHeadlineText() {
    this.dlpElementId = DLP_HEADLINE_TEXT;
    this.rotationDelay = 3000;
    this.currentHeadlineIndex = 0;
    this.headlines = new Array();
    this.timeoutId = "";
}

DlpHeadlineText.prototype = new DlpObject();

DlpHeadlineText.prototype.init =
    function () {
        window.clearTimeout(this.timeoutId);
        this.rotate();
    }

DlpHeadlineText.prototype.rotate =
    function () {
        document.getElementById(DLP_HEADLINE_TEXT).innerHTML = this.getNextHeadline();
        if (this.headlines.length > 1) {
            this.timeoutId = window.setTimeout("headlineText.rotate()", this.rotationDelay);
        }
    }

DlpHeadlineText.prototype.getNextHeadline =
    function () {
        var headline = "";
        if(this.currentHeadlineIndex < this.headlines.length) {
            headline = this.headlines[this.currentHeadlineIndex];
        } else {
            this.currentHeadlineIndex = 0;
            headline = this.headlines[this.currentHeadlineIndex];
        }

        this.currentHeadlineIndex++;
        return headline;
    }

DlpHeadlineText.prototype.setRotationDelay =
    function (delayInMilliseconds) {
        this.rotationDelay = delayInMilliseconds;
    }

DlpHeadlineText.prototype.setText =
    function (headlineArray) {
        this.headlines = headlineArray;
        this.init();
    }

DlpHeadlineText.prototype.setMOIDText =
    function (moidHeadlineArray, defaultHeadline) {
        try {
            if(moidHeadlineArray.length > 0
                    && !moidHeadlineArray[0].blank()
                    && !moidHeadlineArray[0].include("$180")) {
                this.headlines = moidHeadlineArray;
            } else if(defaultHeadline.length > 0 
                    && !defaultHeadline[0].blank()) {
                this.headlines = defaultHeadline;
            } else {
                this.headlines = ["Federal Funds Rate Dropped to 2.0% on April 30!"];
            }
        } catch(ex) {
            this.headlines = ["Federal Funds Rate Dropped to 2.0% on April 30!"];
        }

        this.init();
    }

DlpHeadlineText.prototype.setTextStyle =
    function (fontSize, fontWeight, fontStyle, fontColor, fontColorEm, fontStyleEm) {
        if (fontSize != null && fontSize.length >= 1) {
            document.getElementById(DLP_HEADLINE_TEXT).style.fontSize = fontSize+"px";
        }

        if (fontWeight != null && fontWeight.length >= 1) {
            document.getElementById(DLP_HEADLINE_TEXT).style.fontWeight = fontWeight;
        }

        if (fontStyle != null && fontStyle.length >= 1) {
            document.getElementById(DLP_HEADLINE_TEXT).style.fontStyle = fontStyle;
        }

        if (fontColor != null && fontColor.length >= 1) {
            document.getElementById(DLP_HEADLINE_TEXT).style.color = fontColor;
        }

        /* TODO: Remove the hard coded stylesheet references and use get/setGenericStyleValue() helpers.
        */
        if (fontColorEm != null && fontColorEm.length >= 1) {
            if (navigator.appName.indexOf("Microsoft") >= 0) {
                document.styleSheets[6].addRule("div#dlpAnchor div#dlpHeadlineText em", "color: "+fontColorEm);
            } else {
                for(i=0; i < document.styleSheets[6].cssRules[0].styleSheet.cssRules.length; i++) {
                    if (document.styleSheets[6].cssRules[0].styleSheet.cssRules[i].selectorText == "div#dlpAnchor div#dlpHeadlineText em") {
                        document.styleSheets[6].cssRules[0].styleSheet.cssRules[i].style.color = fontColorEm;
                        break;
                    }
                }
            }
        }

        /* TODO: Remove the hard coded stylesheet references and use get/setGenericStyleValue() helpers.
        */
        if (fontStyleEm != null && fontStyleEm.length >= 1) {
            if (navigator.appName.indexOf("Microsoft") >= 0) {
                document.styleSheets[6].addRule("div#dlpAnchor div#dlpHeadlineText em", "font-style: "+fontStyleEm);
            } else {
                for(i=0; i < document.styleSheets[6].cssRules[0].styleSheet.cssRules.length; i++) {
                    if (document.styleSheets[6].cssRules[0].styleSheet.cssRules[i].selectorText == "div#dlpAnchor div#dlpHeadlineText em") {
                        document.styleSheets[6].cssRules[0].styleSheet.cssRules[i].style.fontStyle = fontStyleEm;
                        break;
                    }
                }
            }
        }
    }

// SubHeadline Text
function DlpSubHeadlineText() {
    this.dlpElementId = DLP_SUB_HEADLINE_TEXT;
    this.headlines = new Array();
    this.currentHeadlineIndex = 0;
    this.timeoutId = "";
}

DlpSubHeadlineText.prototype = new DlpHeadlineText();

DlpSubHeadlineText.prototype.rotate =
    function () {
        document.getElementById(DLP_SUB_HEADLINE_TEXT).innerHTML = this.getNextHeadline();
        if (this.headlines.length > 1) {
            this.timeoutId = window.setTimeout("subHeadlineText.rotate()", this.rotationDelay);
        }
    }

DlpSubHeadlineText.prototype.setTextStyle =
    function (fontSize, fontWeight, fontStyle, fontColor) {
        if (fontSize != null && fontSize.length >= 1) {
            document.getElementById(DLP_SUB_HEADLINE_TEXT).style.fontSize = fontSize+"px";
        }

        if (fontWeight != null && fontWeight.length >= 1) {
            document.getElementById(DLP_SUB_HEADLINE_TEXT).style.fontWeight = fontWeight;
        }

        if (fontStyle != null && fontStyle.length >= 1) {
            document.getElementById(DLP_SUB_HEADLINE_TEXT).style.fontStyle = fontStyle;
        }

        if (fontColor != null && fontColor.length >= 1) {
            document.getElementById(DLP_SUB_HEADLINE_TEXT).style.color = fontColor;
        }
    }

// Creative Include
function DlpCreativeInclude() {
    this.dlpElementId = DLP_CREATIVE_INCLUDE;

    this.writeExecutorStub = function (elementId) {
        document.getElementById(elementId).innerHTML = JS_STUB;
    }
}

DlpCreativeInclude.prototype = new DlpObject();

DlpCreativeInclude.prototype.setText =
    function (text, elementId, markupType) {
        var _id = elementId;
        if (_id == null) {
            _id = DLP_CREATIVE_TEXT;
        }

        // TODO: perfect javascript injection functionality.
        if (markupType == JS_MARKUP_TYPE) {
            //this.writeExecutorStub(_id);
            //document.getElementById(_id).innerHTML += "<script type=\"text/javascript\">var jsInstructions = \""+text+"\";_execute();</script>";
        } else {
            document.getElementById(_id).innerHTML = text;
        }
    }

DlpCreativeInclude.prototype.setTextPosition =
    function (xCoordinate, yCoordinate) {
        document.getElementById(DLP_CREATIVE_INCLUDE).getElementsByTagName("div")[0].style.top = yCoordinate+"px";
        document.getElementById(DLP_CREATIVE_INCLUDE).getElementsByTagName("div")[0].style.left = xCoordinate+"px";
    }

DlpCreativeInclude.prototype.setSearchText =
    function (enabledImagePath, enabledImageWidth, enabledImageHeight,
              disabledImagePath, disabledImageWidth, disabledImageHeight,
              maxLength, _searchPhraseEnabled, elementId) {

        creativeInclude.createDiv(elementId);
        if ((_searchPhrase.length > 0) && _searchPhraseEnabled) {
            var sp_formatted = "";
            if (_searchPhrase.length >= maxLength) {
                sp_formatted = _searchPhrase.substring(0, maxLength);
                sp_formatted += "...";
            } else {
                sp_formatted = _searchPhrase;
            }
            creativeInclude.setImage(enabledImagePath, enabledImageWidth, enabledImageHeight, elementId);
            creativeInclude.createDiv(SEARCH_PHRASE_ELEMENT_ID);
            document.getElementById(SEARCH_PHRASE_ELEMENT_ID).innerHTML = sp_formatted;
            creativeInclude.attachElementChild(SEARCH_PHRASE_ELEMENT_ID, elementId);
        } else {
            creativeInclude.setImage(disabledImagePath, disabledImageWidth, disabledImageHeight, elementId);
        }
    }

DlpCreativeInclude.prototype.setStateText =
    function (callToActionText, stateDisplayType, enabledFontSize, enabledFontStyle,
              enabledFontWeight, enabledFontFamily, enabledWidth, enabledColor,
              disabledFontSize, disabledFontStyle, disabledFontWeight, disabledFontFamily,
              disabledWidth, disabledColor, _stateDisplayEnabled) {

        var actionText = callToActionText;
        if (_stateDisplayEnabled) {
            creativeInclude.createDiv(STATE_TEXT_ELEMENT_ID);
            if ((_propStateCode != "null")) {
                document.getElementById(STATE_TEXT_ELEMENT_ID).style.fontSize = enabledFontSize+"px";
                document.getElementById(STATE_TEXT_ELEMENT_ID).style.fontStyle = enabledFontStyle;
                document.getElementById(STATE_TEXT_ELEMENT_ID).style.fontWeight = enabledFontWeight;
                document.getElementById(STATE_TEXT_ELEMENT_ID).style.fontFamily = enabledFontFamily;
                document.getElementById(STATE_TEXT_ELEMENT_ID).style.width = enabledWidth+"px";
                document.getElementById(STATE_TEXT_ELEMENT_ID).style.color = enabledColor;

                if (stateDisplayType == STATE_DISPLAY_TYPE) {
                    actionText += " in "+_propStateCode.toUpperCase();
                } else {
                    actionText += " in "+_propStateFullName;
                }
            } else {
                document.getElementById(STATE_TEXT_ELEMENT_ID).style.fontSize = disabledFontSize+"px";
                document.getElementById(STATE_TEXT_ELEMENT_ID).style.fontStyle = disabledFontStyle;
                document.getElementById(STATE_TEXT_ELEMENT_ID).style.fontWeight = disabledFontWeight;
                document.getElementById(STATE_TEXT_ELEMENT_ID).style.fontFamily = disabledFontFamily;
                document.getElementById(STATE_TEXT_ELEMENT_ID).style.width = disabledWidth+"px";
                document.getElementById(STATE_TEXT_ELEMENT_ID).style.color = disabledColor;
            }
            document.getElementById(STATE_TEXT_ELEMENT_ID).innerHTML = actionText;
        }
    }

DlpCreativeInclude.prototype.setImage =
    function (imagePath, imageWidth, imageHeight, elementId) {
        var _id = elementId;
        if (_id == null) {
            _id = DLP_CREATIVE_IMAGE;
        }

        document.getElementById(_id).style.backgroundImage = 'url('+_akamai+imagePath+')';
        document.getElementById(_id).style.backgroundRepeat = 'no-repeat';
        document.getElementById(_id).style.backgroundPosition = 'left center';
        document.getElementById(_id).style.width = imageWidth+"px";
        document.getElementById(_id).style.height = imageHeight+"px";
        document.getElementById(_id).style.display = 'block';
    }

DlpCreativeInclude.prototype.setImagePosition =
    function (xCoordinate, yCoordinate) {
        document.getElementById(DLP_CREATIVE_IMAGE).style.top = yCoordinate+"px";
        document.getElementById(DLP_CREATIVE_IMAGE).style.left = xCoordinate+"px";
    }

DlpCreativeInclude.prototype.setFlash =
    function (moviePath, movieWidth, movieHeight, noFlashImage, noFlashImageWidth,
              noFlashImageHeight, elementId) {

        var _id = elementId;
        if (_id == null) {
            _id = DLP_CREATIVE_FLASH;
        }

        if (dlpHelper.isFlashInstalled()) {
            document.getElementById(_id).innerHTML =
                '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'+
                '                    id="'+_id+'_EMBED">'+
                '                   <PARAM NAME=movie VALUE="'+_akamai+moviePath+'">'+
                '                    <PARAM NAME=quality VALUE=high>'+
                '                    <PARAM NAME="wmode" VALUE="transparent">'+
                '                    <EMBED src="'+_akamai+moviePath+'" quality=high'+
                '                        NAME="stateFlash" ALIGN="" wmode="transparent" TYPE="application/x-shockwave-flash"'+
                '                        PLUGINSPAGE="https://www.macromedia.com/go/getflashplayer" id="'+_id+'_EMBED">'+
                '                    </EMBED>'+
                '                </OBJECT>'+
                '                <script type="text/javascript" src="'+_akamai+'/loans/resources/flashMarkup.js"></script>'+
                '                <noscript>'+
                '                    <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'+
                '                        WIDTH="'+movieWidth+'" HEIGHT="'+movieHeight+'" id="'+_id+'_EMBED">'+
                '                        <PARAM NAME=movie VALUE="'+_akamai+moviePath+'">'+
                '                        <PARAM NAME=quality VALUE=high>'+
                '                        <PARAM NAME="wmode" VALUE="transparent">'+
                '                        <EMBED src="'+_akamai+moviePath+'" quality=high WIDTH="'+movieWidth+'" HEIGHT="'+movieHeight+'"'+
                '                            NAME="stateFlash" ALIGN="" wmode="transparent" TYPE="application/x-shockwave-flash"'+
                '                            PLUGINSPAGE="https://www.macromedia.com/go/getflashplayer" id="'+_id+'_EMBED">'+
                '                        </EMBED>'+
                '                    </OBJECT>'+
                '                </noscript>';
            document.getElementById(_id).style.display = 'block';
            document.getElementById(_id).style.width = movieWidth+"px";
            document.getElementById(_id).style.height = movieHeight+"px";
            document.getElementById(_id+'_EMBED').style.width = movieWidth+"px";
            document.getElementById(_id+'_EMBED').style.height = movieHeight+"px";
        } else {
            creativeInclude.createDiv(_id+"NoFlashImage");
            creativeInclude.setDimensions(noFlashImageWidth, noFlashImageHeight, _id+"NoFlashImage");
            creativeInclude.attachImage(noFlashImage, noFlashImageWidth, noFlashImageHeight,
                    _id+"NoFlashImage");
        }
    }

DlpCreativeInclude.prototype.setFlashPosition =
    function (xCoordinate, yCoordinate) {
        document.getElementById(DLP_CREATIVE_FLASH).style.top = yCoordinate+"px";
        document.getElementById(DLP_CREATIVE_FLASH).style.left = xCoordinate+"px";
    }

DlpCreativeInclude.prototype.createDiv =
    function (divId) {
        var newDiv = document.createElement("div");
        newDiv.id = divId;
        newDiv.style.position = "relative";
        newDiv.style.width = "300px";
        newDiv.style.height = "300px";
        newDiv.style.borderWidth = "0px";
        newDiv.style.borderStyle = "dotted";
        newDiv.style.borderColor = "#666666";

        document.getElementById(DLP_CREATIVE_INCLUDE).appendChild(newDiv);
    }

DlpCreativeInclude.prototype.attachText =
    function (text, elementId) {
        this.setText();
    }

DlpCreativeInclude.prototype.attachImage =
    function (imagePath, imageWidth, imageHeight, elementId) {
        this.setImage(imagePath, imageWidth, imageHeight, elementId);
    }

DlpCreativeInclude.prototype.attachFlash =
    function (moviePath, movieWidth, movieHeight, elementId) {
        this.setFlash(moviePath, movieWidth, movieHeight, elementId);
    }

DlpCreativeInclude.prototype.attachClickableArea =
    function (elementId, link) {
        if (link == null) {
            link = DEFAULT_SUBMIT_ACTION;
        }

        var newAnchor = document.createElement("a");
        newAnchor.style.position = "absolute";
        newAnchor.style.top = "0px";
        newAnchor.style.left = "0px";
        newAnchor.style.width = "100%";
        newAnchor.style.height = "100%";
        newAnchor.style.borderWidth = "0px";
        newAnchor.style.borderStyle = "dotted";
        newAnchor.style.borderColor = "#ff0000";
        newAnchor.style.zIndex = 1000;

        newAnchor.id = elementId+"ClickableArea";
        newAnchor.href = link;

        document.getElementById(elementId).appendChild(newAnchor);
    }

DlpCreativeInclude.prototype.attachElementChild =
    function (childElement, parentElement) {
        document.getElementById(parentElement).appendChild(document.getElementById(childElement));
    }

// Form Area
function DlpFormArea() {
    this.dlpElementId = DLP_FORM_AREA;
}

DlpFormArea.prototype = new DlpObject();

DlpFormArea.prototype.setLoanTypeLabel =
    function (label) {
        document.getElementById(DLP_LOAN_TYPE_LABEL).innerHTML = label;
    }

DlpFormArea.prototype.setHomeDescriptionLabel =
    function (label) {
        document.getElementById(DLP_HOME_DESCRIPTION_LABEL).innerHTML = label;
    }

DlpFormArea.prototype.setCreditProfileLabel =
    function (label) {
        document.getElementById(DLP_CREDIT_PROFILE_LABEL).innerHTML = label;
    }

DlpFormArea.prototype.setMediaDayMode =
    function () {
        var selectField = document.getElementsByName(LOAN_TYPE_FIELD)[0];
        for (i=0; i < selectField.options.length; i++) {
            if (selectField.options[i].value.toLowerCase() == LHP_LOAN_TYPE_VALUE) {
                selectField.options[i] = null;
                break;
            }
        }
    }

// Submit Button
function DlpSubmitButton() {
    this.dlpElementId = DLP_SUBMIT_BUTTON;
}

DlpSubmitButton.prototype = new DlpObject();

DlpSubmitButton.prototype.setImage =
    function (imagePath) {
        document.getElementById(DLP_SUBMIT_BUTTON).getElementsByTagName("input")[0].src = _akamai+imagePath;
    }

// Clickable Area
function DlpClickableArea() {
    this.dlpElementId = DLP_CLICKABLE_AREA;
}

DlpClickableArea.prototype = new DlpObject();


// General Page Functions
function DlpPage() {
}

DlpPage.prototype.setBackgroundImage =
    function (imagePath, imageWidth, imageHeight) {
        document.getElementById(DLP_ANCHOR).style.backgroundImage = 'url('+_akamai+imagePath+')';
        document.getElementById(DLP_ANCHOR).style.backgroundRepeat = 'no-repeat';
        document.getElementById(DLP_ANCHOR).style.backgroundPosition = 'left center';
        document.getElementById(DLP_ANCHOR).style.width = imageWidth+"px";
        document.getElementById(DLP_ANCHOR).style.height = imageHeight+"px";
    }

DlpPage.prototype.setDebugMode =
    function (isDebug) {
        if (isDebug) {
            document.getElementById(DLP_HEADLINE_TEXT).style.borderWidth        = '1px';
            document.getElementById(DLP_SUB_HEADLINE_TEXT).style.borderWidth    = '1px';
            document.getElementById(DLP_CREATIVE_INCLUDE).style.borderWidth     = '1px';
            document.getElementById(DLP_FORM_AREA).style.borderWidth            = '1px';
            document.getElementById(DLP_SUBMIT_BUTTON).style.borderWidth        = '1px';
            document.getElementById(DLP_CLICKABLE_AREA).style.borderWidth       = '1px';
            document.getElementById(DLP_ANCHOR).style.borderWidth               = '1px';
            document.getElementById(DLP_CREATIVE_IMAGE).style.borderWidth       = '1px';
            document.getElementById(DLP_CREATIVE_FLASH).style.borderWidth       = '1px';
        } else {
            document.getElementById(DLP_HEADLINE_TEXT).style.borderWidth        = '0px';
            document.getElementById(DLP_SUB_HEADLINE_TEXT).style.borderWidth    = '0px';
            document.getElementById(DLP_CREATIVE_INCLUDE).style.borderWidth     = '0px';
            document.getElementById(DLP_FORM_AREA).style.borderWidth            = '0px';
            document.getElementById(DLP_SUBMIT_BUTTON).style.borderWidth        = '0px';
            document.getElementById(DLP_CLICKABLE_AREA).style.borderWidth       = '0px';
            document.getElementById(DLP_ANCHOR).style.borderWidth               = '0px';
            document.getElementById(DLP_CREATIVE_IMAGE).style.borderWidth       = '0px';
            document.getElementById(DLP_CREATIVE_FLASH).style.borderWidth       = '0px';
        }
    }

DlpPage.prototype.setForcedPresentation =
    function (presentationId) {
        document.getElementById(DLP_FORCE_PRESENTATION).value = presentationId;
    }

DlpPage.prototype.isVisible =
    function (isVisible) {
        if (isVisible) {
            document.getElementById(DLP_ANCHOR).style.display = 'block';
        } else if (!isVisible) {
            document.getElementById(DLP_ANCHOR).style.display = 'none';
        }
    }

DlpPage.prototype.setPosition =
    function (xCoordinate, yCoordinate) {
        document.getElementById(DLP_ANCHOR).style.top = yCoordinate+"px";
        document.getElementById(DLP_ANCHOR).style.left = xCoordinate+"px";
    }

DlpPage.prototype.setMargin =
    function (marginTop, marginRight, marginBottom, marginLeft) {
        if (marginTop != null && (typeof marginTop == "number")) {
            document.getElementById(DLP_ANCHOR).style.marginTop = marginTop+'px';
        }

        if (marginRight != null && (typeof marginRight == "number")) {
            document.getElementById(DLP_ANCHOR).style.marginRight = marginRight+'px';
        }

        if (marginBottom != null && (typeof marginBottom == "number")) {
            document.getElementById(DLP_ANCHOR).style.marginBottom = marginBottom+"px";
        }

        if (marginLeft != null && (typeof marginLeft == "number")) {
            document.getElementById(DLP_ANCHOR).style.marginLeft = marginLeft+'px';
        }
    }

// Helper Functions
function DlpHelper() {
}

DlpHelper.prototype.getGenericStyleValue =
    function (selectorPattern, styleName) {
        var stylesheetLocation = "";
        var dlpStyleSheetReference = "";
        var styleSheetNamePattern = new RegExp("\\b"+DLP_STYLESHEET_NAME+"$\\b");
        var cssRuleSelectorPattern = new RegExp("\\b"+selectorPattern+"$\\b");

        //find dlp style sheet
        for (i=0; i<document.styleSheets.length; i++) {
            stylesheetLocation = document.styleSheets[i].href;
            if (styleSheetNamePattern.test(stylesheetLocation)) {
                dlpStyleSheetReference = document.styleSheets[i];
                break;
            }
        }

        //find applicable selector within style sheet
        if (navigator.appName.indexOf("Microsoft") >= 0) {
            for (i=0; i<dlpStyleSheetReference.rules.length; i++) {
                var cssRuleSelector = dlpStyleSheetReference.rules[i].selectorText;
                if (cssRuleSelectorPattern.test(cssRuleSelector)) {
                    return eval("dlpStyleSheetReference.rules[i].style."+styleName);
                }
            }
        } else {
            for (i=0; i<dlpStyleSheetReference.cssRules.length; i++) {
                var cssRuleSelector = dlpStyleSheetReference.cssRules[i].selectorText;
                if (cssRuleSelectorPattern.test(cssRuleSelector)) {
                    return eval("dlpStyleSheetReference.cssRules[i].style."+styleName);
                }
            }
        }
    }

DlpHelper.prototype.setGenericStyleValue =
    function () {

    }

DlpHelper.prototype.isFlashInstalled =
    function () {
        var flashAcceptable = false;
        var playerVersion = {
            major : 0,
            minor : 0,
            revision : 0
        }

        if (navigator.plugins && navigator.mimeTypes.length) {
		    var flashPlugin = navigator.plugins["Shockwave Flash"];
		    if (flashPlugin && flashPlugin.description) {
			    var t = flashPlugin.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".");
                playerVersion.major    = t[0];
                playerVersion.minor    = t[1];
                playerVersion.revision = t[2];
            }
	    } else {
		    try {
			    var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		    } catch (e) {
			    try {
				    var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
                    playerVersion.major    = 6;
                    playerVersion.minor    = 0;
                    playerVersion.revision = 0;
			    } catch (e) {
			    }
			    try {
				    axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			    } catch (e) {}
		    }
		    if (axo != null) {
			    var t = axo.GetVariable("$version").split(" ")[1].split(",");
                playerVersion.major    = t[0];
                playerVersion.minor    = t[1];
                playerVersion.revision = t[2];
            }
	    }

        if (playerVersion.major >= ACCEPTABLE_FLASH_VERSION) {
            flashAcceptable = true;
        }
        return flashAcceptable;
    }

var headlineText = new DlpHeadlineText();
var subHeadlineText = new DlpSubHeadlineText();
var creativeInclude = new DlpCreativeInclude();
var formArea = new DlpFormArea();
var submitButton = new DlpSubmitButton();
var clickableArea = new DlpClickableArea();
var dlpPage = new DlpPage();
var dlpHelper = new DlpHelper();

var dlpError = new Object();
dlpError.contentElementId = "";
dlpError.contentElementName = "";
dlpError.errorType = "dlpValueError";
dlpError.error = "";