﻿function openDetails(theFile) {
	var winProperties = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,";
	var w = 520;
	var h = 340;
	var winl = 0;
	var wint = 15;
	var settings = 'height=' + h + ',width=' + w + ',top=' + wint + ',';
	settings += 'left=' + winl + ',' + winProperties;

	var popItWin = window.open(theFile, "subWin", settings);

	popItWin.focus();
	return false;
}
function isValidMark(theCntrl, lang, theName, outOf) {
	if (isNumericOnly(theCntrl, theName, 8, 0)) {
		var theMark = theCntrl.value
		if (theMark > outOf) {
			if (lang == "fr")
				alert(theName + " ne peuvent pas excéder " + outOf);
			else
				alert(theName + " entry cannot be more than " + outOf);
				
			theCntrl.value = "0"
			return false
		} else if (theMark.indexOf(".") >= 0) {		

			alert("Please round off the value. Mark entry cannot have a decimal place. ");
			theCntrl.value = "0"
			return false
		}

	}
	else return false;
}

function isNumericOnly(inputField, fieldLabel, numSize, deciSize) {  
	oneDecimal = false		
	var strIn = inputField.value
	var inputStr = strIn.toString()		
	var actualNumSize = numSize - deciSize - 1
	for(var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)		
		if(oneChar == "." && !oneDecimal) {		
			oneDecimal = true;	
			continue;
		}
		if(i > actualNumSize &&  oneDecimal==false) {  
			alert("The required " + fieldLabel + " must be equal or less than " + (actualNumSize+ 1 ) + " interger with "  + deciSize + " decimal place")
			inputField.value = "0"
			inputField.focus();		
			return false
		}
		if(oneChar < "0" || oneChar > "9") {	
			alert("The required " + fieldLabel + " should be a numeric value.");   
			inputField.value = "0"
			inputField.focus();		
			return false;
		}
	}
	return true;
}

function addMark(m1, m2, m3) {
	var totalMark
	var f1 = document.getElementById(m1);
	var f2 = document.getElementById(m2);
	var f3 = document.getElementById(m3);
	
	var mark1 = Number(f1.value)
	var mark2 = Number(f2.value)
		totalMark = mark1 + mark2 
	f3.value = totalMark
}

function isMaxLength(oTxtBox, sTxtBox, sMaxNum) {

	if (oTxtBox) {
		var iMaxNum = new Number(sMaxNum); 
		if (oTxtBox.value.length > iMaxNum) {
			oTxtBox.value = oTxtBox.value.substring(0, iMaxNum);
			alert("Maximum " + sMaxNum + " characters are allowed in field " + sTxtBox);
		}
	}
}


function openFile(theFile) {
	var winProperties = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,";
	var w = 520;
	var h = 340;
	var winl = 0;
	var wint = 15;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',' + winProperties;

	var popItWin = window.open(theFile, "subWin", settings);
	if (navigator.appName.substring(0, 8) == "Netscape")
		popup.location = popItWin;
	else
		popItWin.location.reload();
	popItWin.focus();
}

function openInfo(theFile) {
	var winProperties = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,";
	var w = 499;
	var h = 350;
	var winl = 0;   
	var wint = 16;   
	if (theFile.indexOf("4") > 0) {
		h = 330
	}
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',' + winProperties;

	var popItWin = window.open(theFile, "subWin", settings);
	if (navigator.appName.substring(0, 8) == "Netscape")
		popup.location = popItWin;
	else
		popItWin.location.reload();
	popItWin.focus();
}

function openPrintable(theFile) {
	var winProperties = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,";
	var w = 720; var h = 630;
	var winl = 0; var wint = 15;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',' + winProperties;

	var popItWin = window.open(theFile, "subWin", settings);
	if (navigator.appName.substring(0, 8) == "Netscape")
		popup.location = popItWin;
	else
		popItWin.location.reload();
	popItWin.focus();
}

function openPrintableReport(theView, theVal, rptType, theFile) {
	var winProperties = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,";
	var w = 700; var h = 600;
	var winl = 0; var wint = 15;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',' + winProperties;
	var theFile = theFile + "?view=" + theView + "&sVal=" + theVal + "&rType=" + rptType
	var popItWin = window.open(theFile, "subWin", settings);
	if (navigator.appName.substring(0, 8) == "Netscape")
		popup.location = popItWin;
	else
		popItWin.location.reload();
	popItWin.focus();
}
function toNextPage(theUrl) {
	window.location.href = theUrl
}

function selectUniversity(theCntrl, thePage) {
	var theName = theCntrl.name
	var selectNum = theName.substring(theName.length - 1, theName.length)
	thePage = thePage
	document.frmFCIP.action = thePage
	document.frmFCIP.submit()
}

function selectCourse(cntrlIn, theNum) {
	var courseCntrl = eval("document.frmFCIP.txtCourseID" + theNum)
	var coursesAndID = document.frmFCIP.hidUniCourseAndID.value
	var str = coursesAndID.substring(coursesAndID.indexOf(cntrlIn.value + '='), coursesAndID.length)
	var pos = str.indexOf("=") + 1;
	var end = str.indexOf(',');
	str = str.substring(pos, end)
	var isSame = 0;
	var totCourses = 0
	for (var i = 1; i < 7; i++) {
		var theCntrl = eval("document.frmFCIP.txtCourseID" + i)
		if (str == theCntrl.value && !(theNum == i)) {
			alert("You cannot select more than one course with the same FCIP Code. ")
			cntrlIn.value = ""
			isSame = 1
		}
	}
	if (!(isSame == 1)) {
		courseCntrl.value = str
	}
}

