﻿

function roll(img_name, img_src) {
    document[img_name].src = img_src;
}

function IsValidInstance(pItem)
{
    return !((typeof pItem == "undefined") || (pItem == null));
}

function GetObj(id) {
    if (!IsValidInstance(id)) 
        return null;
    
    if (typeof id != 'string') 
        return id; //already an object
        
    if (id != "") {
      if (document.getElementById)  
         return document.getElementById(id); 
      else if (document.all)  
         return document.all[id]; 
   }
}



function showIt(pElementId, pIsInline)
{
    var element = GetObj(pElementId);
    if (element == null) {
        window.status ("showIt Can't find element by id: " + pElementId);
    } else {
        if (typeof pIsInline == "undefined")
            pIsInline = false;    

        //try to recover the setting set by hideIt()
        if (getElementAttribute(pElementId, "oldStyleDisplay") != null)
            element.style.display = getElementAttribute(pElementId, "oldStyleDisplay");
        else
            element.style.display = (pIsInline ? "inline" : "block");
    }
}

function hideIt(pElementId)
{
    var element = GetObj(pElementId);
    if (element == null)
        window.status ("hideIt Can't find element by id: " + pElementId);
    else {
        if (typeof element.style.display != 'undefined' && (element.style.display != "none" && element.style.display != "NONE"))    
            setElementAttribute(pElementId, "oldStyleDisplay", element.style.display); //save this for use in showIt
        element.style.display = "none";
    }
}

function toggleVis(pElementId) {
    var element = GetObj(pElementId);
    if (element == null) {
		window.status ("toggleVis Can't find element by id: " + pElementId);
	} else {
		if (element.style.display == "NONE" || element.style.display == "none")
		{
			showIt(pElementId);
		} else {
			hideIt(pElementId);
		}
	}
}

function setVis(pElementId, pShowIt) {
	if (pShowIt)
	{
		showIt(pElementId);
	} else {
		hideIt(pElementId);
	}
}

function getElementAttribute(pField, pAttribute) 
{
    var el = typeof(pField) == "string" ? GetObj(pField) : pField;
    if (IsValidInstance(el)) {
        if (el.getAttribute)
            return el.getAttribute(pAttribute);
        else
            return null;
    }
    else 
        window.status = "getElementAttribute: Unable to get attribute value on null field: [" + pField + "]";

    return null;
}

function setElementAttribute(pField, pAttribute, pValue)
{
    var el = typeof(pField) == "string" ? GetObj(pField) : pField;
    if (IsValidInstance(el))
        el.setAttribute(pAttribute, pValue);
    else 
        window.status = "setElementAttribute: Unable to set attribute value on null field: [" + pField + "]";
}



var mapPage = false;
var LateStartList = new Array();

function LoadScriptLate(target,content,script)
{
    var lsi = new LateStartItem();
    lsi.content = content;
    lsi.target = target;
    lsi.scripts = script;
    LateStartList[LateStartList.length] = lsi;
} 
 
function LateStartItem()
{
    this.content= "";
    this.target = "";
    this.scripts = "";
}

 $(document).ready(function(){
    if(!mapPage)
    {
        LoadLateItems();
    }
});


var beenCalled = false;
function LoadLateItems() {
    if (!beenCalled) {
        beenCalled = true;
        for (var x = 0; x < LateStartList.length; x++) {
            if (LateStartList[x].scripts != undefined) {
                eval(LateStartList[x].scripts);
            }
            if (LateStartList[x].target.length > 0) {
                var target = document.getElementById(LateStartList[x].target);
                target.innerHTML += LateStartList[x].content;
            }
        }
    }
}
