// This file contains james's library of shortcuts and UI specific functions. 

var DOM = YAHOO.util.Dom;  
var EVENT = YAHOO.util.Event;

function $(elemID) {
	// Refactor document.getElementById alias.
	return document.getElementById(elemID);
}	

function goTo(dest,win) {
	// This is just a simple hack to let me stop having to write so much!
	document.location.href=dest;
}

function popUp(theURL,winName,features) {
	// Launches a popup window with the url, name and size specified.

	if (features == '') 
		features = 'width=500,height=500,resizable,scrollbars';
	newWindow=window.open(theURL,winName,features);
	if (newWindow) newWindow.focus();
}

function getRadioValue(elem) {
	// Gets the value of a radio button.. must be passed a valid document pathname for the elem
	// Used by board.js
	var value = false;
	for(var i=0; i < elem.length; i++) {
		if(elem[i].checked) 
			value=elem[i].value;
	}
	return value;
}

function setRadioValue(elem, value) {
	// Sets the value of a radio element to 'value' - If value dosen't match return false
	// Used by board.js
	for(var i in elem) {
		if(elem[i].value == value) {
			elem[i].checked = true;
			return true;
		}
	}
	return false;
}

function fade(node, clr_from, clr_to) {
	// Crippled.. the clr_from and clr_to aren't working yet.
	var level = 1;
	if(!clr_from) var clr_from = 'ffff00';
	if(!clr_to) var clr_to = 'f6f6f6';
	var step = function() {
		var hex = level.toString(16);
		node.style.backgroundColor = '#ffff' + hex + hex;
		if(level < 14) {
			level += 1;
			setTimeout(step, 100);
		} else {
			node.style.backgroundColor = '#' + clr_to;
		}
	};
	setTimeout(step,100);
}
	
