//Library of common and universally used functions throughout ebusiness.byu.edu
var rightBarContent;

function hideRightBar() {
	var rightbar = document.getElementById("rightbar");
	rightBarContent = rightbar.innerHTML;
	rightbar.style.width = "2%";
	rightbar.innerHTML = '<div style="padding:2px;"><a href="javascript:showRightBar();">Show panel</a></div>';
	var bigleftarea = document.getElementById("bigleftarea");
	bigleftarea.style.width = "97%";
} //hides the right content panel from a level 3 page.


function showRightBar() {
	var rightbar = document.getElementById("rightbar");
	rightbar.innerHTML = rightBarContent;
	rightbar.style.width = "16%";
	var bigleftarea = document.getElementById("bigleftarea");
	bigleftarea.style.width = "82%";
} //returns the right content panel to its normal size and position


function checkPasswords(form) {
	if((form.password.value.length < 6) || (form.password_retype.value.length < 6)) {
		alert('Please enter, and re-enter, your password.  Your password must be at least 6 characters.');
		form.password.focus();
		return false;
	}
	if(form.password.value != form.password_retype.value) {
		return false;
	}
	else {
		return true;
	}
} //checks the password fields of the eBusiness Idea Competition Entry form


function trimField(field) {
	var value = field.value; // get the text in the field	
	var start = 0; // keeps track of the starting point to trim
	var end = value.length; // get the original string's length
	while(value.charAt(start) == " ") {
		start++; // increase the trim starting point
	}
	while(value.charAt(end-1) == " ") {
		end--; // decrease the length of the string to be trimmed
	}
	if(end == 0) {
		field.value = "";
	} else {
		field.value = value.substring(start,end); // return the trimmed string
	}
} //function trimField


function openWindow(url, windowname, parameters) {
	popup = window.open(url,windowname,parameters);
	popup.focus();
} //function openWindow -- this opens up a window with the given parameters


function editPresenter() {
	var presenterID = document.getElementById('presenterID').value;
	var win = openWindow('admin_edit_presenter.php?presenterID='+presenterID,'edit_presenter','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,top=200,left=200,width=550,height=450');
	win.focus();
}						

function newPresenter() {
	var win = openWindow('admin_new_presenter.php','new_presenter','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,top=200,left=200,width=550,height=450');
	win.focus();
}


function toggleDiv(item) {
	var area = document.getElementById(item);
	if(area.style.display == 'block') {
		hideDiv(item);
	} else {
		showDiv(item);
	}
}

function showDiv(item) {
	document.getElementById(item).style.display = 'block';
}

function hideDiv(item) {
	document.getElementById(item).style.display = 'none';
}

function showNextFeature() {
	if(index < (features.length - 1)) {
		index++;
	} else {
		index = 0;
	}
	showStory(features[index]);
}

function showPrevFeature() {
	if(index > 0) {
		index--;
	} else {
		index = (features.length - 1);
	}
	showStory(features[index]);
}

function showStory(feature) {
	var content = "<h2>" + feature[2] + "</h2><p>" + feature[3] + "&nbsp; <a href=\"" + feature[4] + "\">More...</a></p>";
	document.getElementById("featureContent").innerHTML = content;
}