
/* SHOW/HIDE OBJECTS */

function show(objectId) {
	document.getElementById(objectId).style.display = "";
}

function hide(objectId) {
	document.getElementById(objectId).style.display = "none";
}

function showHide(objectId) {
	var object = document.getElementById(objectId);
	object.style.display = (object.style.display == 'none') ? "" : "none";
}

function isHidden(objectId) {
	return (document.getElementById(objectId).style.display == "none");
}

/* SET FOCUS */

function setFocus(objectId) {
	document.getElementById(objectId).focus();
}

/* SELECT TEXT */

function selectText(fieldId, start, end) {
	var field = document.getElementById(fieldId);
	start = (!start) ? 0 : start;
	end = (!end) ? field.value.length : end;
	if(field.createTextRange) {
		var selRange = field.createTextRange();
		selRange.collapse(true);
		selRange.moveStart('character', start);
		selRange.moveEnd('character', (end - start));
		selRange.select();
	} else if(field.setSelectionRange) {
		field.setSelectionRange(start, end);
	} else if (field.selectionStart) {
		field.selectionStart = start;
		field.selectionEnd = end;
	}
	field.focus();
}

/* CHECK CHECKBOXES */

function check(checkBox) {
	if(typeof checkBox.length == 'number') {
		for(i = 0; i < checkBox.length; i++) {
			checkBox[i].checked = true; 
		}
	} else {
		checkBox.checked = true;
	}
}

/* UNCHECK CHECKBOXES */

function unCheck(checkBox) {
	if(typeof checkBox.length == 'number') {
		for(i = 0; i < checkBox.length; i++) {
			checkBox[i].checked = false; 
		}
	} else {
		checkBox.checked = false;
	}
}

/* COUNT CHECKED CHECKBOXES */

function countChecked(checkBox) {
	var checked = 0;
	if(typeof checkBox.length == 'number') {
		for(i = 0; i < checkBox.length; i++) {
			if(checkBox[i].checked) {
				checked++;
			}
		}
	} else {
		if(checkBox.checked) {
			checked++;
		}
	}
	return checked;
}

/* UNESCAPE HTML */

String.prototype.unescapeHtml = function() {
	var temp = document.createElement("div");
	temp.innerHTML = this;
	var result = temp.childNodes[0].nodeValue;
	temp.removeChild(temp.firstChild);
	return result;
}

/* ANALYTICS OUTBOUND LINK */

function recordOutboundLink(link, category, action) {
	try {
		var pageTracker = _gat._getTracker("UA-3135118-1");
		pageTracker._trackEvent(category, action);
		setTimeout("document.location = \"" + link.href + "\"", 100);
	} catch(e) {}
}

