// $Revision: 4$
// $Date: 7/24/2007 11:18:39 PM$
// $Author: Donnie Tognazzini$

function SMS_View( )
{
}

SMS_View.prototype =
{
    getElement : function(id)
    {
        return document.getElementById(id);
    },

    displayElement : function(id)
    {
        this.getElement(id).style.display = 'block';
    },

    hideElement : function(id)
    {
        this.getElement(id).style.display = 'none';
    },

    enableElement : function(id)
    {
        this.getElement(id).removeAttribute("disabled");
    },

    disableElement : function(id)
    {
        this.getElement(id).setAttribute("disabled", "true");
    },

    selectElement : function(id)
    {
        try
        {
            this.getElement(id).select();
        }
        catch (e)
        {
            // do nothing
        }
    },

    bruteForceSelectElement : function( id )
    {
        try
        {
            // Brute-force way of making sure that if a Text input field's value is selected
            // that that selection is cleared.

            var tmp = this.getElement( id ).value;
            this.getElement( id ).value = "";
            this.getElement( id ).value = tmp;
        }
        catch (e)
        {
            // do nothing
        }
    },

    focusElement : function(id)
    {
        try
        {
            this.getElement(id).focus();
        }
        catch (e)
        {
            // do nothing
        }
    },

    setStatusMsgInfo : function(msg)
    {
        this.m_viewController.setStatusMsgInfo(msg);
    },

    setStatusMsgError : function(msg)
    {
        this.m_viewController.setStatusMsgError(msg);
    },

    setCursorWait : function()
    {
        document.body.style.cursor = 'wait';
    },

    setCursorDefault : function()
    {
        document.body.style.cursor = 'default';
    },

    isInputEmpty: function(id)
    {
        return this.getElement(id).value == '';
    },

    keyDownIsEnter : function(evt)
    {
        evt = (evt) ? evt : event;

        var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);

        return (charCode == 13 || charCode == 3);
    },

    flipStyle : function(defaultValue, formField)
    {
        var txtSearch = document.getElementById(formField);

        if (txtSearch != null && txtSearch.style.color != "black" && txtSearch.style.fontStyle != "normal")
        {
            txtSearch.style.color = "black";
            txtSearch.style.fontStyle = "normal"
        }
        if (txtSearch != null && txtSearch.value == defaultValue)
        {
            txtSearch.value = "";
            txtSearch.focus();
        }
        return true;
    },

    setDropdown : function(elemId, val)
    {
        var elem = this.getElement(elemId);

        if (typeof elem != 'undefined')
        {
            for (var i = 0; i < elem.options.length; i++)
            {
                if (elem.options[i].value == val)
                {
                     elem.options[i].selected = true;
                     break;
                }
            }
            elem.style.color = 'black';
            elem.style.fontStyle = 'normal';
        }
    },

    setDropdownPrompt : function(elemId)
    {
        var elem = this.getElement(elemId);

        if (typeof elem != 'undefined')
        {
            elem.selectedIndex = 0;
            elem.style.color = '#666';
            elem.style.fontStyle = 'italic';
        }
    },

    setTextInput : function(elemId, val)
    {
        var elem = this.getElement(elemId);

        elem.value = val;

        this.setNonEmptyInputStyle( elemId );
    },

    setNonEmptyInputStyle : function( elemId )
    {
        var elem = this.getElement( elemId );

        elem.style.color = 'black';
        elem.style.fontStyle = 'normal';
    },

    setEmptyInputStyle : function( elemId )
    {
        var elem = this.getElement( elemId );

        elem.style.color = '#666';
        elem.style.fontStyle = 'italic';
    },

    setTextInputPrompt : function(elemId, prompt)
    {
        var elem = this.getElement(elemId);

        if (typeof elem != 'undefined')
        {
            elem.value = prompt;

            this.setEmptyInputStyle( elemId );
        }
    },

    updateInputStyle : function( elementId, prompt )
    {
        var element = this.getElement( elementId );
        if ( element.value === '' || element.value === prompt )
        {
            this.setTextInputPrompt( elementId, prompt );
            return true;
        }

        this.setNonEmptyInputStyle( elementId );
        return false;
    },

    stripCharsInBag : function(s, bag)
    {
        var i;
        var returnString = "";

        // Search through string's characters one by one.
        // If character is not in bag, append to returnString.
        for (i = 0; i < s.length; i++)
        {
            // Check that current character isn't whitespace.
            var c = s.charAt(i);
            if (bag.indexOf(c) == -1) returnString += c;
        }
        return returnString;
    },

    isNumeric : function(sText)
    {
        var validChars = "0123456789";
        var isNumber = true;
        var chr;

        for (i = 0; i < sText.length && isNumber == true; i++)
        {
          chr = sText.charAt(i);
          if (validChars.indexOf(chr) == -1)
             {
                isNumber = false;
             }
        }

        return isNumber;
    },

    isValidEmail : function(emailAddress)
    {
        return (/^(([^\x00-\x1F\x7F-\xFF <>()[\]\\.,;:@"]|\\[\x00-\x7F])+(\.([^\x00-\x1F\x7F-\xFF <>()[\]\\.,;:@"]|\\[\x00-\x7F])+)*|"([^\n\r\\"\x80-\xFF]|\\[\x00-\x7F])+")@[0-9A-Za-z][-0-9A-Za-z]*[0-9A-Za-z](\.[0-9A-Za-z][-0-9A-Za-z]*[0-9A-Za-z])+$/.test(emailAddress))
    }
}