function trim(str) { str = leftTrim(str); str = rightTrim(str); return str; } function leftTrim(sString) { while (sString.substring(0,1) == ' ') { sString = sString.substring(1, sString.length); } return sString; } function rightTrim(sString) { while (sString.substring(sString.length-1, sString.length) == ' ') { sString = sString.substring(0,sString.length-1); } return sString; } function validateGroupPermissionForm(thisForm) { var emptyMsg = "Please provide values for all fields indicated with '*'."; with (thisForm) { if (emptyValidation(groupID,emptyMsg) == false ) { groupID.focus(); return false; } if (emptyValidation(permissionID,emptyMsg) == false ) { permissionID.focus(); return false; } if (emptyValidation(expires,emptyMsg) == false ) { expires.focus(); return false; } if (dateValidation(expires,"Please enter a date in the indicated format.") == false ) { expires.focus(); return false; } if (emptyValidation(numUsers,emptyMsg) == false ) { numUsers.focus(); return false; } if (numUsersValidation(numUsers,emptyMsg) == false ) { numUsers.focus(); return false; } } return true; } function validatePermissionForm(thisform) { var emptyMsg = "Please provide values for all fields indicated with '*'."; with (thisform) { if (emptyValidation(urlPattern,emptyMsg) == false ) { urlPattern.focus(); return false; } } return true; } function validateUserForm(thisform) { var emptyMsg = "Please provide values for all fields indicated with '*'."; with (thisform) { // Trim all values: firstName.value = trim(firstName.value); lastName.value = trim(lastName.value); email.value = trim(email.value); confirmEmail.value = trim(confirmEmail.value); if (emptyValidation(firstName,emptyMsg) == false ) { firstName.focus(); return false; } if (emptyValidation(lastName,emptyMsg) == false ) { lastName.focus(); return false; } if (emptyValidation(email,emptyMsg) == false ) { email.focus(); return false; } if( emailValidation(email,"Invalid email.") == false) { email.focus(); return false; } if (emptyValidation(confirmEmail,emptyMsg) == false ) { confirmEmail.focus(); return false; } if( email.value != confirmEmail.value ) { alert("Your email and confirmation email do not match."); confirmEmail.focus(); return false; } } return true; } function validateProductCodeForm(thisform) { var emptyMsg = "Please provide values for all fields indicated with '*'."; with (thisform) { if (emptyValidation(permissionRoot,emptyMsg) == false ) { permissionRoot.focus(); return false; } if (emptyValidation(description,emptyMsg) == false ) { description.focus(); return false; } if (emptyValidation(swapPrefix,emptyMsg) == false ) { swapPrefix.focus(); return false; } } return true; } function validateGroupForm(thisform) { var emptyMsg = "Please provide values for all fields indicated with '*'."; with (thisform) { if (emptyValidation(groupName,emptyMsg) == false ) { groupName.focus(); return false; } if (emptyValidation(contactName,emptyMsg) == false ) { contactName.focus(); return false; } if (emptyValidation(email,emptyMsg) == false ) { email.focus(); return false; } if( emailValidation(email,"Invalid email.") == false) { email.focus(); return false; } if (emptyValidation(contactPhone,emptyMsg) == false ) { contactPhone.focus(); return false; } if (emptyValidation(teacherLaunchPage,emptyMsg) == false ) { teacherLaunchPage.focus(); return false; } if (emptyValidation(studentLaunchPage,emptyMsg) == false ) { studentLaunchPage.focus(); return false; } } return true; } function validateLoginForm(thisform) { var emptyMsg = "Please provide a username and password to login."; with (thisform) { if (emptyValidation(userName,emptyMsg) == false ) { userName.focus(); return false; } if (emptyValidation(pwd,emptyMsg) == false ) { pwd.focus(); return false; } } } function validateLogoutForm(thisform) { var emptyMsg = "Please provide a username and password to logout."; with (thisform) { if (emptyValidation(userName,emptyMsg) == false ) { userName.focus(); return false; } if (emptyValidation(pwd,emptyMsg) == false ) { pwd.focus(); return false; } } } function validateEmailPasswordForm(thisform) { var emptyMsg = "Please provide your email address."; with (thisform) { if (emptyValidation(email,emptyMsg) == false ) { email.focus(); return false; } if( emailValidation(email,emptyMsg) == false) { email.focus(); return false; } } return true; } function emptyValidation(entered, alertbox) { with (entered) { if (value == null || value == "") { if (alertbox != "") { alert(alertbox); } return false; } else { return true; } } } function emailValidation(entered, alertbox) { with (entered) { if( echeck(value) == false ) { if (alertbox) { alert(alertbox); } return false; } else { return true; } } } function dateValidation(entered, alertbox) { // We are expecting YYYY-MM-DD, 10 characters: dateString = entered.value; if( dateString.length != 10 ) { if (alertbox) { alert(alertbox); } return false; } for (i = 0; i < dateString.length; i++) { theChar = dateString.charAt(i); if( i != 4 && i != 7 ) { if( !isDigit(theChar) ) { if (alertbox) { alert(alertbox); } return false; } } else { if( theChar != '-' ) { if (alertbox) { alert(alertbox); } return false; } } } return true; } function numUsersValidation(entered, alertBox) { numUsers = entered.value; for (i = 0; i < numUsers.length; i++) { theChar = numUsers.charAt(i); if ( !isDigit(theChar) ) { if (alertbox) { alert(alertbox); } return false; } } return true; } function isDigit(num) { if (num.length>1) { return false; } var string="1234567890"; if (string.indexOf(num) != -1) { return true; } return false; } function isEmailChar(ch) { if (ch.length > 1) { return false; } var string="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@"; if (string.indexOf(ch) != -1) { return true; } return false; } /////////////////////// function echeck(str) { var at = "@" var dot = "." var lat = str.indexOf(at) var lstr = str.length var ldot = str.indexOf(dot) if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) { return false } if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) { return false } if (str.indexOf(at,(lat+1)) != -1) { return false } if (str.substring(lat-1,lat) == dot || str.substring(lat+1,lat+2) == dot) { return false } if (str.indexOf(dot,(lat+2)) == -1) { return false } if (str.indexOf(" ") != -1) { return false } // Check for bogus chars: for (i = 0; i < str.length; i++) { ch = str.charAt(i); if( isEmailChar(ch) == false ) return false; } return true }