﻿
window.onload = function () {
    loadRollovers();
    setInterval('hideAllInactiveMenus()', 50);
}

var menus = new Array();

var currentMenuID = 'none';
var currentMenuStatus = 'inactive';

function hideAllInactiveMenus() {
    for (var i = 0; i < menus.length; i++) {
        if (currentMenuID != menus[i]) {
            performHideMenu(menus[i]);
        }
    }
}

function showMenu(id) {
    if (menus[id] == null) {
        menus.push(id);
    }
    hideAllInactiveMenus();
    if (currentMenuStatus == 'inactive') {
        var obj = $('.' + id);
        obj.fadeIn(210);
        currentMenuID = id;
        hideAllInactiveMenus();
    }
}

function hideMenu(id) {
    setTimeout("performHideMenu('" + id + "')", 200);
}

function performHideMenu(id) {
    if (currentMenuStatus == 'inactive') {
        $('.' + id).hide();
    }
}

function setCurrentMenuID(id) {
    currentMenuID = id;
}

/*** start rollover code ***/
var EventCollection = new Array();
// custom event object used to store pre-existing events
function Event() {
    this.ObjectReference = null;
    this.MouseOver = null;
    this.MouseOut = null;
    this.Key = null;
}
function loadRollovers() {
    var imgs = document.getElementsByTagName('img');
    for (var i = 0; i < imgs.length; i++) {

        // catalog and stack existing event listeners into a custom object
        // and attach to the object
        if (imgs[i].src.indexOf('_off') > -1 ||
           imgs[i].src.indexOf('_active') > -1) {
            var existingMouseover = imgs[i].onmouseover;
            var existingMouseout = imgs[i].onmouseout;
            var tempEvent = new Event();
            var addEvent = false;
            tempEvent.Key = Guid();
            if (existingMouseover != undefined) {
                tempEvent.MouseOver = existingMouseover;
                addEvent = true;
            }
            if (existingMouseout != undefined) {
                tempEvent.MouseOut = existingMouseout;
                addEvent = true;
            }
            if (addEvent) {
                EventCollection[tempEvent.Key] = tempEvent;
                imgs[i].EventKey = tempEvent.Key;
                imgs[i].Event = tempEvent;
            }
        }
        // modify the event listeners to handle the rollover image changes
        // and fire the existing event listeners if they exist
        if (imgs[i].src.indexOf('_off') > -1) {
            var tmpImage = new Image();
            tmpImage.src = imgs[i].src.replace('_off', '_over');
            imgs[i].onmouseover = function () {
                this.src = this.src.replace('_off', '_over');
                if (this.Event != null && this.Event.MouseOver != null) {
                    this.Event.MouseOver();
                }
            }
            imgs[i].onmouseout = function () {
                this.src = this.src.replace('_over', '_off');
                if (this.Event != null && this.Event.MouseOut != null) {
                    this.Event.MouseOut;
                }
            }
        }
        if (imgs[i].src.indexOf('_active') > -1) {
            imgs[i].onmouseover = function () {
                if (this.Event != null && this.Event.MouseOver != null) {
                    this.Event.MouseOver();
                }
            }
            imgs[i].onmouseout = function () {
                if (this.Event != null && this.Event.MouseOut != null) {
                    this.Event.MouseOut;
                }
            }
        }
    }
}
function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
function Guid() {
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}
/*** end rollover code ***/

//Text Box Counter

function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
    else
        countfield.value = maxlimit - field.value.length;
}
