﻿// JavaScript Document
function initHighlight() {
    if (!document.getElementsByTagName) { return; }

    var allfields = document.getElementsByTagName("input");

    // loop through all input tags and add events
    for (var i = 0; i < allfields.length; i++) {
        var field = allfields[i];
        if ((field.getAttribute("type") == "text") || (field.getAttribute("type") == "password")) {
            field.onfocus = function () {
                /*this.className = 'txt-field txt-field-active';*/
                this.className += ' txt-field-active';
            }
            field.onblur = function () {
                /*this.className = 'txt-field';*/
                this.className.replace(/txt-field-active/, "");
                this.className = this.className.replace(/txt-field-active/g, "");
            }
        }
    }

    var allareas = document.getElementsByTagName("textarea");
    for (var i = 0; i < allareas.length; i++) {
        var txtarea = allareas[i];
        txtarea.onfocus = function () {
            //this.className ='textarea textarea-active';
            this.className += ' textarea-active';
        }
        txtarea.onblur = function () {
            //this.className = this.className + 'textarea';
            //this.className.replace("textarea-active", ""); 
            //this.className.replace(/*textarea-active/g, "");
            this.className = this.className.replace(/textarea-active/g, "");
            //alert(this.className);

        }

    }


}

// Nifty function to add onload events without overwriting
// ones already there courtesy of the lovely and talented
// Simon Willison http://simon.incutio.com/
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function () {
            oldonload();
            func();
        }
    }
}

addLoadEvent(initHighlight);
