// -*- mode: javascript -*-

var dodo = {};

dodo.ONLOAD_ARRAY = new Array ();
dodo.ONRESIZE_ARRAY = new Array ();

dodo.contentRefresh = function () {
	dodo.calcContentHeight ();
	if (document.recalc)
		document.recalc (true);
}

dodo.handlersCall = function (array, arg) {
	for (var i = 0; i < array.length; i++)
		if (array[i] != null)
			array[i] (arg);
}

dodo.handlersPush = function (array, func) {
	array.push (func);
	return array.length;
}

dodo.delayRun = function (func, delay) {
	if (!delay)
		delay = 1;
	window.setTimeout (func, delay);
}

dodo.windowOnResize = function (event) {
	dodo.handlersCall (dodo.ONRESIZE_ARRAY, event);
}

dodo.bodyOnLoad = function (event) {
	// IE Update problem: http://www.amarasoftware.com/flash-problem.htm
	var objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++) { 
	  if (objects[i].className.indexOf ("ie7_anon") == -1)
		objects[i].outerHTML = objects[i].outerHTML;
	}

	window.onresize = dodo.windowOnResize;

	if (!top.SITE)
		top.SITE = {noLogin: true};
	top.SITE.document = document;

	dodo.handlersCall (dodo.ONLOAD_ARRAY, event);
}

dodo.frameDocument = function (doc, id) {
	var frame = doc.getElementById (id);
	return frame.contentDocument? frame.contentDocument: doc.frames[id].document;
}

dodo.frameWindow = function (doc, id) {
	var frame = doc.getElementById (id);
	return frame.contentWindow? frame.contentWindow: doc.frames[id];
}

dodo.onLoadPush = function (func) {
	return dodo.handlersPush (dodo.ONLOAD_ARRAY, func);
}

dodo.onResizePush = function (func) {
	return dodo.handlersPush (dodo.ONRESIZE_ARRAY, func);
}

dodo.cookieSet = function (c_name, value, expiredays) {
	var exdate = new Date ();
	exdate.setDate (exdate.getDate () + expiredays);
	document.cookie = c_name + "=" + encodeURI (value) +
		((expiredays == null)? "" : ";expires=" + exdate.toGMTString ());
}

dodo.cookieGet = function (c_name) {
	if (document.cookie.length > 0) {
		var c_start = document.cookie.indexOf (c_name + "=");
		if (c_start != -1) { 
			c_start = c_start + c_name.length + 1;
			var c_end = document.cookie.indexOf (";", c_start);
			if (c_end == -1) 
				c_end = document.cookie.length;
			return decodeURI (document.cookie.substring (c_start, c_end));
		}
	}
	return "";
}

dodo.hashSort = function (hash, key, asc) {
	hash.sort (function (a, b) {
		if (a[key] < b[key]) return -1 * asc;
		if (a[key] > b[key]) return 1 * asc;
		return 0;
	});
}
