function HubDesignUtils_VarDump(e) {
    var s = "";
    for(x in e) {
        s = s + x + ": " + e[x] + ",";
    }
    return s;
}
function HubDesignUtils_XMLHttp() {
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
    return new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
   return new ActiveXObject("Microsoft.XMLHTTP");
  }    
}
function HubDesignUtils_ElementSize(elt) {
    var res = new Object();
    res.width = elt.clientWidth;
    res.height = elt.clientHeight;
    return res;
}

function HubDesignUtils_CenterElementToBrowser(elt) {
	var x = 0, y = 0;
        element_size = HubDesignUtils_ElementSize;
	if(navigator.appName == "Microsoft Internet Explorer") {
		//code whose sole purpose is just to find out how
		//large the window is
		//and position the image elt accordingly
		//*if* we're running IE
		if (document.compatMode=='CSS1Compat' &&
		    document.documentElement &&
		    document.documentElement.offsetWidth ) 
		{
			x = document.documentElement.offsetWidth;
			y = document.documentElement.offsetHeight;
		} else if (document.body && document.body.offsetWidth) {
			x = document.body.offsetWidth;
			y = document.body.offsetHeight;
		}
                var sz = element_size(elt);
		x = (x - sz.width) / 2;
		y = (y - sz.height) / 2;
	} else {
		//code whose sole purpose is just to find out how
		//large the window is
		//and position the image elt accordingly
		//if client is *not* running IE
		x = (window.innerWidth - elt.clientWidth) / 2;
		y = (window.innerHeight - elt.clientHeight) / 2;
	}
        if(y < 0) { y = 0;}
        if(x < 0) { x = 0; }
	elt.style.top = y + "px";
	elt.style.left = x + "px";
    
}
function HubDesignUtils_cancelEvent() {
    if(window.event) {
        window.event.returnValue = false;		
        if(window.event.preventDefault) window.event.preventDefault();
    }
    return false;
}
function HubDesignUtils_findFirstChildNodeById(node, id) {
    var res = undefined;
    if(node != undefined) {
        for(var i = 0; i < node.childNodes.length && res == undefined; i++) {
            if(node.childNodes[i].id == id) {
                res = node.childNodes[i];                
            } else {
                res = HubDesignUtils_findFirstChildNodeById(node.childNodes[i], id);
            }            
        }
    }
    return res;
}
function HubDesignUtils_findAllMatchingChildNodes(node, fn) {
    var res = new Array();  
    if(node != undefined) {
        for(var i = 0; i < node.childNodes.length; i++) {
            if(fn(node.childNodes[i])) {
                res.push(node.childNodes[i]);
            } else {
                //shouldn't actually be inside the else but it *should* be safe
                //to assume that a matching node won't be inside another matching
                //node
                //without it being inside the else sometimes you get duplicate 
                //results
                res = res.concat(HubDesignUtils_findAllMatchingChildNodes(node.childNodes[i], fn));
            }
       }
    }
    return res;    
}
function HubDesignUtils_findFirstMatchingChildNode(node, fn) {
    var res = undefined;  
    if(node != undefined) {
        for(var i = 0; i < node.childNodes.length && res == undefined; i++) {
            if(fn(node.childNodes[i])) {
                res = node.childNodes[i];                
            } else {
                res = HubDesignUtils_findFirstMatchingChildNode(node.childNodes[i], fn);
            }            
        }
    }
    return res;
}

function HubDesignUtils_parseQueryString() {
    var tmp = document.URL;
    var res = new Object();
    var idx = tmp.indexOf("?");
    if(idx != 0) {
        var last_idx = tmp.indexOf("#");
        if(last_idx < 0) last_idx = tmp.length;
        var items = tmp.substr(idx + 1, last_idx - (idx + 1)).split("&");
        for(var i= 0; i < items.length; i++) {
            var item = items[i].split("=");
            res[item[0]] = unescape(item[1]);
        }
    }
    return res;
}
function HubDesignUtils_GetCurrentScriptElement() {
    var scripts = document.getElementsByTagName("script");
    if(scripts.length > 0) {
        return scripts[scripts.length-1];
    } else {
        return null;
    }
}
