/* '# form validation and general utility functions for WinWithEveryone.com application
   '# as of 3.1.00 this remains a small file; included functions:
   '# iSwitch():		simulates VB's Switch function; used to good effect in the admin
   '#					dynamic font changing scheme (AdminNavPanel.asp: eatCookie() function)
   '# validateLogIn():	all validation checks for default.htm & BadLogIn.asp
   '# LogInStart():		called at start of default.htm;; runs CheckBrowz() and sets focus
						user name text box
   '# CheckBrowz():		check browser name and version; if it's determined that the browser
						is bad, and it's not the home page, itedirect to BadBrowser.asp
*/
isNav = false;
// isNav3 = false;
isIE = false;


// function vCheck(sName, num)
	// check that a checkbox group has

function checkRadio(rad, question, section, rLength) {
/* verify that one of an option group has been selected;
   if not, give message indicating which section and number 
   is the question & stop form submission  AK 3.20.00  */
//alert("rad length is " + document.forms[0].numhoursnegoweek.length);

/*	var strElem = "document.forms[0]." + rad + "[";
	for (var i = 0; i < rLength; i++) {
		objElem = eval(strElem + i + "]");	
		if (objElem.checked) {
			return true;
		}
	}
	var msg = "You need to complete question " + question;
	msg += " of section " + section + ".";
	alert(msg);
	return false;
	}
*/
}
function isBlank(s)
{
	if (s.length == 0 )
	{
		return true;
	}
	for(var i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

function iSwitch(arry, aVal) {
	/*  AK 3.1.00   replicates VB "Switch" function; calling method as:
		var myArray = new Array(8, 0, 10, 1, 12, 2, 14, 3, 16, 4);
		var selIndex = iSwitch(myArray, parseInt(CookieValue));
		
		2 lines can replace a very long if then else structure;
		in the above case, if passed "aVal" (CookieValue) = 8, 0 would be  returned;
		if it = 10, 1 would be returned; 12 then 2 would be returned, and so on  */

	for (var i = 0; i < arry.length - 1; i += 2) {
		if (parseInt(aVal) == arry[i]) {
			return arry[i + 1];
		}
	}
	return 0;
}
/* MC 3.02.00 - removed minimum length check for user and password */
function validateLogIn(form) {
	// function checks to see that valid information was entered by the
	// student in the log in form
	
	// if (document.frmLogIn.txtUserName.value = "") {
	if (form.txtUserName.value == "" || form.pwPassword.value == "") {
		alert("Both the user name and password boxes must be filled in.");
		return false;
	} 
	return true;
}
function LogInStart() {
	CheckBrowz(true);
	document.frmLogIn.txtUserName.focus();
}
function CheckBrowz() {
	var browz = navigator.appName;
	var badBrowz = true;
	var isNav3 = false;
	var verz = parseInt(navigator.appVersion);
	var ua = navigator.userAgent;
	
	if (browz == "Netscape") {
		if (verz >= 3) {
			isNav = true;
			if (verz == 3) isNav3 = true;
			badBrowz = false;
		}
	}
	else if (browz == "Microsoft Internet Explorer") {
	/* odd thing: the navigator.appVersion is coming up 4 for IE 5 !!
	   I decided that it would thus be best to do the version check
	   using the navigator.userAgent value   AK 1.25.0 */
	   
		pos4 = browz.substring("MSIE 4");
		pos5 = browz.substring("MSIE 5");
		if (pos4 || pos5) {
			isIE = true;
			badBrowz = false;
		}
	}
	//if (badBrowz == true) {
	/*  if this function is being called from the home (login) page, then we don't want
		to redirect if it's a bad browser; on the other hand if it's called from elsewhere,
		the "isHome" passed variable will be false, and so we then redirect AK 3.1.00  */
	//	if (isHome != true) {
	//		document.location.href = "BadBrowser.asp";
	//	}
	//}
}
function getCookie(cookieName) {
	var cooks = document.cookie;
	var start = cooks.indexOf(cookieName);
	var end = cooks.indexOf(";", start);
	if (end == -1) end = cooks.length;
	var cook = cooks.substring(start, end);
	cook = cook.split("=");
	return cook[1];
}