function val_AULIssueCodes() {
	goFlag = true;
	msg = "";
	if (regXtrim($("sCode").value) == "Enter your Master Code" || regXtrim($("sCode").value) == "") {
		//tagError("classID","Enter a class ID");
		goFlag = false;
		msg = "Enter a Master Code";
	}
	else if (regXtrim($("sCode").value).length > 10) {
		goFlag = false;
		msg = "Sorry, that is not a valid master code. Please try again.";
	}

	if (!goFlag) {
		document.getElementById('AULerrFlag').innerHTML = msg;
		document.getElementById('AULerrFlag').style.display = "block";
		//$("AULerrFlag").innerHTML = msg;
		//$("AULerrFlag").style.display = "block";
		return false;
	}
	else {
		jQuery.ajax({
			url: '/campus/home/licensehome/LicenseLogin.cfm',
			data: "sCode=" + jQuery('#sCode').val(),
			success:function(data) {
				if (data.toLowerCase().indexOf("success") > 0) {
					location.href='/gateway/index.cfm?fa=aul.codeBank';
				}
				else {
					document.getElementById('AULerrFlag').innerHTML = data;
					document.getElementById('AULerrFlag').style.display = "block";
				}
			}
		});
	}
}

function isEmail(string) {
	// Check for a properly placed @ sign
	if (!string) return false;
	var whereitsat = string.indexOf("@");
	if (whereitsat == -1) return false; 							// if no @ 
	else if (whereitsat == 0) return false;							// if @ is first char
	else if (whereitsat == (string.length-1)) return false;			// if @ is last char
	else if (string.indexOf("@", whereitsat + 1) != -1) return false;	// if more than one @

	// Check for the rest of the formatting
	var arrayString = string.split("@");
	if (arrayString[1].indexOf(".") == -1) return false;			// if no .
	else if (arrayString[1].indexOf(".") == 0) return false;		// if . is right after @
	else if (arrayString[1].charAt(arrayString[1].length-1) == ".") return false; // if . is last char
	else if (arrayString[0].charAt(arrayString[0].length-1) == ".") return false; // if . is right before @

	// Check for certain false tendencies
	if (string.indexOf("asdf") != -1) return false;					// if found asdf
	else if (string.indexOf("asfd") != -1) return false;			// if found asfd
	else if (string.indexOf("adsf") != -1) return false;			// if found adsf
	else if (string.indexOf("sdfg") != -1) return false;			// if found sdfg
	else if (string.indexOf("..") != -1) return false;				// if found ..

	return true;
} 

function Form_Validator(theForm) {
	var OrderCount = 0;
	var CourseCount = 0;
	for(j = 0; j <= 9; j++) {
		if (!parseInt(document.emails.qty[j].value)) {
			document.emails.qty[j].value = 0;
		}
		if (parseInt(document.emails.qty[j].value) < 0) {
			document.emails.qty[j].value = 0;
		}
	 	CourseCount = CourseCount + Math.round(document.emails.qty[j].value);
	 	OrderCount = OrderCount + Math.round(document.emails.price[j].value)* Math.round(document.emails.qty[j].value);
	}

	if (CourseCount == 0) {
		alert("No course is selected or the number of students is 0. \nChoose the course and enter the number of students, then try again. ");
		return (false);
	}

	if (CourseCount > 200) {
		alert("The maximum number of codes you can request at one time is 200. \nPlease reduce the number of codes and try again.");
		return (false);
	}

	if (OrderCount > document.emails.availableSeats.value) {
		alert("Your request exceeded the " + document.emails.availableSeats.value + " VC Dollars you have available.\nPlease update your request and try again.");
		return (false);
	}

	//if the repmail field exists, then check if the value has been selected
	if (document.emails.repemail) {
		if(document.emails.repemail.value == "") {
			alert("Please select who is issuing the codes, then try again.");
			return false;
		}
		if (document.emails.EmailtoSend.value != "") {
			if (isEmail(document.emails.EmailtoSend.value) == false) {
				alert("Please enter a valid e-mail address, then try again.");
				document.emails.EmailtoSend.focus();
				return (false);
			}
		}
	}

	var msg = "Course Access Codes requested: " + CourseCount + "\n"
				+ "VC Dollars Spent: " + OrderCount + "\n\n"
				+ "The codes cannot be exchanged or returned.\n\n"
				+ "Do you want to continue?\n\n"
				+ "Click OK to continue.\n"
				+ "Click CANCEL to change your request for codes.\n";
	if (confirm(msg))
		document.emails.submit();
	else return (false);
}

function recalculate(linenumber) {
	var digits = "0123456789";
	var mystring = eval('document.emails.product' + linenumber + '.options[document.emails.product' + linenumber + '.selectedIndex].value');
	//if quantity, price or sub-total are not available, stop processing
	if(!mystring) {
		document.emails.qty[linenumber-1].value = 0;
		document.emails.price[linenumber-1].value = 0;
		document.emails.subtotal[linenumber-1].value = 0;
		return false;
	}

	for (var i = 0; i < document.emails.qty[linenumber-1].value.length; i++) {
		temp = document.emails.qty[linenumber-1].value.substring(i, i+1);
		if (digits.indexOf(temp) == -1 && document.emails.qty[linenumber-1].value != "") {
			document.emails.qty[linenumber-1].value =0;
		}
	}

	var numseats = document.emails.qty[linenumber-1].value;
	var pos = mystring.indexOf("_"); 
	var lengthofstring =  mystring.length;
	var product_id = mystring.substring(0,pos);
	var courseprice = parseInt(mystring.substring(pos+1,lengthofstring));

	if (isNaN(courseprice)) {
		return(false);
	}

	var updatesubtotal = numseats*courseprice;
	document.emails.price[linenumber-1].value = courseprice;
	document.emails.subtotal[linenumber-1].value = updatesubtotal;
	var updatefinaltotal = 0;
	for (j = 0; j <= 9; j++) {
		updatefinaltotal += Math.round(document.emails.subtotal[j].value);
	}
	document.emails.total.value = updatefinaltotal;
	return false;
}

