﻿// The one lookup method:
function mLookup(strKeyName) {
		return(this[strKeyName]);
}

// The meta Add method:
function mAdd() {
	for (c=0; c<mAdd.arguments.length; c+=2) {
		this[mAdd.arguments[c]] = mAdd.arguments[c+1];
	}
}

// The Delete method
function mDelete(strKeyName) {
	for (c=0; c<mDelete.arguments.length; c++) {
			this[mDelete.arguments[c]] = null;
	}
}

// A dictionary object
function CreateDictionary() {
    this.Add = mAdd;
    this.Delete = mDelete
    this.Lookup = mLookup;
}

// Create a dictionary object to stored the state of the floating divs iu
var popupOpen = new CreateDictionary();

function ShowFloatingDivContent(divId) {
		HideAllFloatingDivs();
		if (popupOpen[divId] == null) {
        popupOpen.Add(divId, true);
    }
    else {
        popupOpen[divId] = true;
    }
    
    ChangeFloatingDivContent(divId, true);
}
function HideAllFloatingDivs() {
	var content = document.getElementById('floatingDivs');
	var divs = document.getElementsByName('_floating');
	if (divs.length == 0) {
		divs = GetElementsByName(content, 'div', '_floating');
	}
	//IE hack to fix getElementByName heratic behavior
	if (divs.length > 0) {
		for (var i=0; i < divs.length; i++)
			HideFloatingDivContent(divs[i].id);	
	}
}

function HideFloatingDivContent(divId) {
    if (popupOpen[divId] == null) {
        popupOpen.Add(divId, false);
    }
    else {
        popupOpen[divId] = false;
    }
    ChangeFloatingDivContent(divId, false);
}
function ShowFloatingDivContentDelay(divId) {
    if (popupOpen[divId] == null) {
        popupOpen.Add(divId, true);
    }
    else {
        popupOpen[divId] = true;
    }
    
    ChangeFloatingDivContentDelay(divId, true, 0);
}

function HideFloatingDivContentDelay(divId) {
    if (popupOpen[divId] == null) {
        popupOpen.Add(divId, false);
    }
    else {
        popupOpen[divId] = false;
    }
    ChangeFloatingDivContentDelay(divId, false, 0);
}
function ChangeFloatingDivContentDelay(divId, enabled, delay) {
    setTimeout('ChangeFloatingDivContent("'+ divId +'", '+ enabled +');', delay);
}

function ChangeFloatingDivContent(divId, enabled) {
	var lDiv = document.getElementById(divId);
	if (lDiv != null) {
	    if (popupOpen[divId] != null && popupOpen[divId] == enabled) {
	        if (enabled) {
	            lDiv.style.display = "block";
	        }
	        else {
	            lDiv.style.display = "none";
	        }
	    }
	}
}

function GetElementsByName(parent, tag, name) {
	var elements = [];
	var divs = parent.getElementsByTagName(tag);
	var attribute = '';
	if (divs.length > 0) {
		for (var i = 0; i < divs.length; i++) {
			attribute = divs[i].getAttribute('name');
			if (attribute != '' && attribute == name) {
				elements[elements.length] = divs[i];
			}
		}
	}
	return elements;
}

