﻿/// <reference path="http://yui.yahooapis.com/combo?2.7.0/build/utilities/utilities.js" />

YAHOO.namespace("BB");
YAHOO.BB.FormHandler = new function() {

    /****************** Private Properties ******************/
    var m_oYEVNT = YAHOO.util.Event, //Contains Event Fxns
        m_oYDOM = YAHOO.util.Dom; //Contains DOM Manip Fxns


    /****************** Private Functions ******************/
    var OverlayFlashHeader = function() {
        var oParams = {
        menu: "false",
        quality: "autohigh",
        wmode: "transparent",
        allowscriptaccess: "always"
        };

        swfobject.embedSWF("flash/logo.swf", "MOHdrFlash", "350", "120", "8.0.0", null, null, oParams, null);
    }

    var BBFocus = function(obj) {
        m_oYDOM.replaceClass(this, "unvisited", "visited");
        m_oYDOM.addClass(this, "focussed");

        switch (this.value) {
            case "First Name":
                this.value = "";
                break;
            case "Last Name":
                this.value = "";
                break;
            case "Email Address":
                this.value = "";
                break;
            case "Phone Number":
                this.value = "";
                break;
            case "Offer":
                this.value = "";
                break;
            default:
                break;
        }
    }

    var BBBlur = function(obj) {
        m_oYDOM.removeClass(this, "focussed");
        if (this.value != "") return;

        if (this.id.match("FirstName$") == "FirstName") {
            m_oYDOM.replaceClass(this, "visited", "unvisited");
            this.value = "First Name";
        }
        else if (this.id.match("LastName$") == "LastName") {
            m_oYDOM.replaceClass(this, "visited", "unvisited");
            this.value = "Last Name";
        }
        else if (this.id.match("Email$") == "Email") {
            m_oYDOM.replaceClass(this, "visited", "unvisited");
            this.value = "Email Address";
        }
        else if (this.id.match("HomePhone$") == "HomePhone") {
            m_oYDOM.replaceClass(this, "visited", "unvisited");
            this.value = "Phone Number";
        }
        else if (this.id.match("Offer$") == "Offer") {
            m_oYDOM.replaceClass(this, "visited", "unvisited");
            this.value = "Offer";
        }
    }

    return {

        /****************** Public Properties ******************/

        /****************** Public Functions ******************/
        init: function() {
            //we'll defer making list items draggable until the DOM is fully loaded:
            m_oYEVNT.onDOMReady(this.BBFormInit, this, true);
        },

        BBFormInit: function(o) {
            //Add the flash header
            OverlayFlashHeader();

            //Input blur/focus effects
            var iInputIdx = 0,
                oInputs = m_oYDOM.getElementsByClassName("frmTxt", "input");

            m_oYDOM.addClass(oInputs, "unvisited");

            for (iInputIdx in oInputs) {
                m_oYEVNT.addListener(oInputs[iInputIdx], "focus", BBFocus, oInputs[iInputIdx], true);
                m_oYEVNT.addListener(oInputs[iInputIdx], "blur", BBBlur, oInputs[iInputIdx], true);
            }
        }

    }
} ();
YAHOO.BB.FormHandler.init();