function Cookie(path) {

	this.path = path;

	this.set = function(name, value) {
		document.cookie = name + '=' + escape(value) + '; path=' + this.path;
	}

	this.get = function(name) {
		var cookie = document.cookie.split('; ');
		for (var i = 0; i < cookie.length; i++) {
			var crumb = cookie[i].split('=');
			if (name == crumb[0])
			return unescape(crumb[1]);
		}
		return null;
	}

	this.remove = function(name) {
		document.cookie = name + '=null; expires=Fri, 31 Dec 1999 23:59:59 GMT;';
	}

}

function doShowAllObjectsReg(expr) {
	for (var id in document.all) {
		var str = new String(id);
		if (str.search(expr) == 0) {
			doShowHideObjectEx(id, 1);
		}
	}
}
function doHideAllObjectsReg(expr) {
	for (var id in document.all) {
		var str = new String(id);
		if (str.search(expr) == 0) {
			doShowHideObjectEx(id, 0);
		}
	}
}
function doShowHideAllObjectsReg(expr) {
	for (var id in document.all) {
		var str = new String(id);
		if (str.search(expr) == 0) {
//			alert("found " + id);
			doShowHideObject(id);
		}
	}
}

function getById(id) {
	if (document.getElementById) {
		var object = document.getElementById(id);
	} else if (document.all) {
		var object = document.all[id];
	}
	return object;
}

function doShowHidePanel(id) {
	var object = getById(id);
	if (object) {
		var cookie = new Cookie('/');
		var trigger_img = document.images['trigger_' + id];
		if ('none' == object.style.display) {
			object.style.display = 'block';
			trigger_img.src = '/images/btn_expand.gif';
			cookie.set(id, '1', null);
		} else {
			object.style.display = 'none';
			trigger_img.src = '/images/btn_collapse.gif';
			cookie.set(id, '0', null);
		}
	}
}

function doShowHideObject(id) {
	var object = getById(id);
	if (object) {
		if ('none' == object.style.display) {
			object.style.display = 'block';
//			alert("block" + id);
		} else {
			object.style.display = 'none';
//			alert("none" + id);
		}
	}
}

function doShowHideObjectEx(id, show) {
	var object = getById(id);
	if (object)
		if (show) {
			object.style.display = 'block';
		} else {
			object.style.display = 'none';
		}
}

function doShowHideObjectCond(optElem, radioGroup, checkValue, show, defaultHide) {
	if (defaultHide == null)
		defaultHide = true;
	var radio = document.frm.elements[radioGroup];
	for (var i=0; i<radio.length; i++)
		if (radio[i].checked) {
			if (radio[i].value==checkValue)
				doShowHideObjectEx(optElem, show);
			else
				doShowHideObjectEx(optElem, !show);
			return;
		}
	if (defaultHide)
		doShowHideObjectEx(optElem, false);
}

function doShowChildren(id) {
	var object = getById(id);
	doShowChildrenHelper(object);
}

function doShowChildrenHelper(object) {
	if (object) {
		if (object.style && 'none' == object.style.display) {
			object.style.display = 'block';
		}
		for (var i = 0; i < object.children.length; i++) {
			doShowChildrenHelper(object.children[i]);
		}
	}
}

function doHideChildren(id) {
	var object = getById(id);
	doHideChildrenHelper(object);
}

function doHideChildrenHelper(object) {
	if (object) {
		if (object.style && 'block' == object.style.display) {
			object.style.display = 'none';
		}
		for (var i = 0; i < object.children.length; i++) {
			doHideChildrenHelper(object.children[i]);
		}
	}
}

function popUpWindow(url, target, width, height, scrolling) {
	var left, top;
	if (typeof(scrolling)=='undefined')
		scrolling = 1;
	if (typeof(screen)=='undefined') {
		left = top = 100;
	} else {
		left = parseInt((screen.width - width) / 3);
		if (left<0) {
			left = 0;
			width = screen.width;
		}
		top = parseInt((screen.height - height) / 3);
		if (top<0) {
			top = 0;
			height = screen.height;
		}
	}
	//alert("width="+width+",height="+height);
	var wnd;
	if (scrolling)
		wnd = window.open(url, target, "width="+width+",height="+height+",scrollbars,left="+left+",top="+top);
	else
		wnd = window.open(url, target, "width="+width+",height="+height+",left="+left+",top="+top);
	wnd.focus();
	return false;
}

function popUpWindowXY(url, target, left, top, width, height) {
	window.open(url, target, "width="+width+",height="+height+",scrollbars,left="+left+",top="+top).focus();
	return false;
}

