
Utils = {
    addLoadEvent : function(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        }
        else {
            window.onload = function() {
                oldonload();
                func();
            }
        }
    }
}


// Swap.js - start
var ExpandImage = 'expand.jpg';
var CollapseImage = 'collapse.jpg';

function GetTag(TagID) {
//returns a reference to the HTML element with ID = TagID
	var Ret=document.getElementById(TagID);
	if (!Ret) alert("GetTag: tag '"+TagID+"' does not exist.");
	return Ret;
}

function ToggleExpand(ExpandID, ImagePath) {
	var ExpandButton = GetTag(ExpandID + "_expand_button");
	var ShortHTML = GetTag(ExpandID + "_short_html");
	var LongHTML = GetTag(ExpandID + "_long_html");

	if (ShortHTML.style.display == "none") {
		ShortHTML.style.display = "";
		LongHTML.style.display = "none";
		ExpandButton.src = ImagePath+ExpandImage;
	} else {
		ShortHTML.style.display = "none";
		LongHTML.style.display = "";
		ExpandButton.src = ImagePath+CollapseImage;
	}
}

function ShowHide(ExpandID, SelectID, Value) {
	var ShortHTML = GetTag(ExpandID + "_short_html");
	var LongHTML = GetTag(ExpandID + "_long_html");
	var Select = document.getElementById(SelectID);
	if (!Select) alert("ShowHide: tag '"+SelectID+"' does not exist.");

	if (Select.options[Select.selectedIndex].value == Value) {
		ShortHTML.style.display = "none";
		LongHTML.style.display  = "";
		SetHiddenField(ExpandID,'true');
	} else {
		ShortHTML.style.display = "";
		LongHTML.style.display  = "none";
		SetHiddenField(ExpandID,'false');
	}
}

function SetHiddenField(FieldID, Value) {
	var HiddenField = document.getElementById(FieldID);
	HiddenField.value = Value;
}

function showDiv(divId) {
    var div = document.getElementById(divId);
    if (div) {
        div.className = "";
    }
}

function hideDiv(divId) {
    var div = document.getElementById(divId);
    if (div) {
        div.className = "hiddenDiv";
    }
}

AjaxUtils = {
    replaceInnerHTMLWithUrl : function(targetElementId,url) {
        var targetElement = document.getElementById(targetElementId);
        targetElement.innerHTML = "<img src='images/folders/loading.gif'>";        
        var callback = {
        //if our XHR call is successful, we want to make use of the returned data and create child nodes.
            success: function(oResponse) {
                var targetElement = document.getElementById(targetElementId);
                var responseText = oResponse.responseText;
                if(targetElement != null) {
                    targetElement.innerHTML = responseText;
                    YAHOO.log("innerHTML added sucessfully", "info", "example");
                }                
            },

            failure: function(oResponse) {
                YAHOO.log("Failed to process XHR transaction.", "info", "example");
            },

            argument: {

            },

            timeout: 30000,

            cache: false
        };
        YAHOO.util.Connect.asyncRequest('GET', url, callback);
    }

}

