function AttachPanelLinks() {
	var tabLinks = document.getElementById("nav_tabs").getElementsByTagName("a");
	for (i=0; i<tabLinks.length; i++) {
		tabLinks[i].onclick = function() {
			return ToggleTabPanel(this.href);
		}
	}
}

function ToggleTabPanel(element) {
	parentID = element.split("#")[1];
	tabLIs = document.getElementById("nav_tabs").getElementsByTagName("li");
	for (i=0; i<tabLIs.length; i++) {
		tabLink = tabLIs[i].getElementsByTagName("a")[0];
		targetID = tabLink.href.split("#")[1];
		target = document.getElementById(targetID);
		if (target){
			if (tabLIs[i].className == "current") {
				tabLIs[i].className = "";
				target.className = "tab_panel";
			}
			if (targetID == parentID) {
				tabLIs[i].className = "current";
				target.className = "tab_panel current";
			}
		}
	}
	return false;
}

function checkForm(theform) {
	name = trim(theform.txtName.value);
	email = trim(theform.txtEmail.value);
	comments = trim(theform.txtComments.value);
	errored = false;
	errorMsg = "The following fields are required:\n";
	if (name.length == 0) {
		errored = true;
		errorMsg += "\nName";
	}
	if (email.length == 0) {
		errored = true;
		errorMsg += "\nEmail";
	}
	if (comments.length == 0) {
		errored = true;
		errorMsg += "\nComments";
	}
	if (errored == true) {
		alert(errorMsg);
		return false;
	}
}

function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}
