add Router PreRequisite functions

parent 4f3f1444
//Frederick, 060605 Add function to close window without warning{
function closeWindow() {
var currBrowser;
currBrowser = GetBrowserOS();
switch (currBrowser) {
case "msiewin": //ie windows
case "msiemac": //ie mac
case "netslin": //mozilla linux
window.opener = self;
window.close();
break;
case "netswin": //netscape windows
case "firelin": //firefox linux
case "firewin": //firefox windows
case "firemac": //firefox mac
window.open('', '_parent', '');
window.close();
break;
default:
window.opener = self;
window.close();
break;
}
}
//Frederick, 060605}
function op() {}
function do_checkstr(string) {
var detect = navigator.userAgent.toLowerCase();
place = detect.indexOf(string) + 1;
thestring = string;
return place;
}
//Function Name: GetBrowserOS
//Description: Gets the current OS version and browser version of OS
//Parameters: none
//Output: <browser><OS>
function GetBrowserOS() {
var detect = navigator.userAgent.toLowerCase();
var OS, browser, version, total, thestring, browseVer;
if (do_checkstr('konqueror')) {
browser = "Konqueror";
OS = "Linux";
} else if (do_checkstr('safari')) browser = "safa";
else if (do_checkstr('omniweb')) browser = "omni";
else if (do_checkstr('opera')) browser = "oper";
else if (do_checkstr('webtv')) browser = "webt";
else if (do_checkstr('icab')) browser = "icab";
else if (do_checkstr('msie')) browser = "msie";
//Frederick,060721 Add firefox detection
else if (navigator.userAgent.indexOf("Firefox") != -1) {
var versionindex = navigator.userAgent.indexOf("Firefox") + 8;
if (parseInt(navigator.userAgent.charAt(versionindex)) >= 1)
browser = "fire";
} else if (!do_checkstr('compatible')) {
browser = "nets";
} else browser = "unknown";
if (browser != "unknown")
if (!OS) {
if (do_checkstr('linux')) OS = "lin";
else if (do_checkstr('x11')) OS = "uni";
else if (do_checkstr('mac')) OS = "mac";
else if (do_checkstr('win')) OS = "win";
else OS = "unknown";
}
browseVer = browser + OS;
return browseVer;
}
// Checks whether a digit is a valid hexadecimal digit!
var isHexaDigit = function(digit) {
var hexVals = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "a", "b", "c", "d", "e", "f");
var len = hexVals.length;
var i = 0;
var ret = false;
for (i = 0; i < len; i++) {
if (digit == hexVals[i]) {
break;
}
}
if (i < len) {
ret = true;
}
return ret;
};
// Checks whether a number (val) is a valid HexaDecimal number!
// val == HexaDecimal Number
// size = Length of val
var isValidHexKey = function(val, size) {
var ret = false;
if (val.length == size) {
for (i = 0; i < val.length; i++) {
if (isHexaDigit(val.charAt(i)) === false) {
break;
}
}
if (i == val.length) {
ret = true;
}
}
return ret;
};
var isValidDate = function(year, month, day) {
var f;
if (month == 2) {
if (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0)) {
if (day > 29) {
f = false;
}
} else {
if (day > 28) {
f = false;
}
}
} else if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) {
if (day > 30) {
f = false;
}
} else {
f = true;
}
return f;
};
var BLANK_VALID = true;
var BLANK_INVALID = false;
var SPACE_VALID = true;
var SPACE_INVALID = false;
var SLASH_VALID = true;
var SLASH_INVALID = false;
//Add is invalid message
//Function Name: alertInvalid(fieldname, fieldvalue [,additional])
//Description: alerts invalid message containing fieldname and value
//Parameters: fieldname, fieldvalue, additional - Any additional comments to be added
//Output: MessageBox(invalid message)
function alertInvalid(fieldname, fieldvalue, additional) {
if (additional === undefined)
alert(fieldname + " " + fieldvalue + " is invalid.");
else
alert(fieldname + " " + fieldvalue + " is invalid, " + additional + ".");
}
//Function Name: isValidEmail(fieldvalue,[fieldname]))
//Description: Check if email address entered is valid
//Parameters: fieldvalue, fieldname
//Output: true - no error
// false - error
function isValidEmail(fieldvalue, fieldname) {
var hasField = false;
if (fieldname !== undefined) hasField = true;
if (!isValidName(fieldvalue, fieldname, BLANK_INVALID, SPACE_INVALID)) return false;
var tmpIndex = fieldvalue.indexOf('@');
var dotIndex = fieldvalue.indexOf('.');
if ((tmpIndex == -1) || (dotIndex == -1) || (tmpIndex == fieldvalue.length - 1) || (dotIndex == fieldvalue.length - 1) ||
(tmpIndex === 0) || (dotIndex === 0)) {
if (hasField) alertInvalid(fieldname, fieldvalue);
return false;
}
return true;
}
// Check if a name valid
//Frederick,060731 add fields and modify error checks
//check if the name is URL friendly
//Function Name: isValidName(name[,fieldname][,isblankvalid][,isSpaceValid])
//Description: Check that name contains no unnecessary characters
//Parameters: name, fieldname(optional): show error message when error encountered
// isblankvalid: BLANK_VALID - allow empty values | BLANK_INVALID(default) - don't allow empty values
// isSpaceValid: SPACE_VALID - allow space characetrs | SPACE_INVALID(default) - don't allow space characters
//output: true:no error false: error
function isValidName(name, fieldname, isblankvalid, isSpaceValid, isSlashValid) {
var i = 0;
var hasField = false;
if (fieldname !== undefined) hasField = true;
if (name === "")
if ((isblankvalid === undefined) || (isblankvalid === false)) {
if (hasField) alertInvalid(fieldname, name);
return false;
}
if ((isSpaceValid === undefined) || (isSpaceValid === false)) {
for (i = 0; i < name.length; i++) {
if (isNameUnsafe(name.charAt(i)) === true) {
if (hasField) alertInvalid(fieldname, name);
return false;
}
}
} else {
for (i = 0; i < name.length; i++) {
if (isCharUnsafe(name.charAt(i)) === true) {
if (hasField) alertInvalid(fieldname, name);
return false;
}
}
}
if (isSlashValid == SLASH_INVALID) {
if (name.indexOf("/") != -1) {
if (hasField) alertInvalid(fieldname, name);
return false;
}
}
return true;
}
function isNameUnsafe(compareChar) {
// Jerry 20040628, @ . is allow
// var unsafeString = "\"<>%\\^[]`\+\$\,='#&@.: \t";
var unsafeString = "\"<>%\\^[]`\+\$\,='#&: \t;";
if (unsafeString.indexOf(compareChar) == -1 && compareChar.charCodeAt(0) > 32 &&
compareChar.charCodeAt(0) < 123)
return false; // found no unsafe chars, return false
else
return true;
}
// same as is isNameUnsafe but allow spaces
function isCharUnsafe(compareChar) {
var unsafeString = "\"<>%\\^[]`\+\$\,='#&@.:\t;";
if (unsafeString.indexOf(compareChar) == -1 && compareChar.charCodeAt(0) >= 32 &&
compareChar.charCodeAt(0) < 123)
return false; // found no unsafe chars, return false
else
return true;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment