function getElementsByClassName(classname,tag,node) {
	if(tag == null) {
		tag = '*';
	}
	if(node == null) {
		node = document;
	}
	var result = new Array();
	var elements = node.getElementsByTagName(tag);
	var len = elements.length;
	var pattern = new RegExp('(^|\\s)'+classname+'(\\s|$)');
	for(i=0,j=0; i<len; i++) {
		if(pattern.test(elements[i].className)) {
			result[j++] = elements[i];
		}
	}
	return result;
}

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

function addUnloadEvent(func) {
	if(typeof window.onunload != 'function') {
		window.onunload = func;
	} else {
		var oldonunload = window.onunload;
		window.onunload = function() {
			oldonunload();
			func();
		}
	}
}

// other

function openwin(url,defx,defy) {
	var sizes = defy ? "width="+defx+",height="+defy+"," : "";
	var popwin = window.open(url,"popwin",sizes+"menubar=no,directories=no,location=no,toolbar=no,scrollbars=no");
	if(popwin) {
		popwin.focus(); 
		if(defy) {
			popwin.resizeTo(defx+20,defy+40);
		}
		return(false);
	} else {
		return(true);
	}
}

function initinput(id,defval) {
	addLoadEvent(function() { 
		var input = document.getElementById(id);
		if(input) {
			if(!input.value) { 
				input.value = defval; 
			}
			input.onfocus = function() { if(this.value == defval) { this.value = ''; } };
			input.onblur = function() { if(this.value == '') { this.value = defval; } };
		}
	});
}

function initradios() {
	var hrefs = getElementsByClassName('radio','A');
	for(i=0; i<hrefs.length; i++) {
		if(hrefs[i].previousSibling && hrefs[i].previousSibling.tagName == 'INPUT') {
			hrefs[i].onclick = function() { 
				this.previousSibling.checked = true; 
				return false; 
			};
		}
	}
}

function initconfirms(prefix,suffix) {
	var hrefs = getElementsByClassName('confirm','A');
	for(i=0; i<hrefs.length; i++) {
		hrefs[i].onclick = function() { 
			return window.confirm(prefix+this.title+suffix); 
		};
	}
}

addLoadEvent(initradios);
addLoadEvent(function() { initconfirms('','?'); });
