var C_EVENT_LOG_ERROR_URL = "/include-mt/ajax-log-client-msg.asp";
// This is the global error setup for the window.onerror handler below.
function mtGlobalErrorHandler(msg, url, lno) {
// var sMsg = "A client page error has occurred.\n" +
// "Error: " + msg + "\n" +
// "URL: " + url + "\n" +
// "Line Number: " + lno;
//
mtLogClientException(msg, url, null, lno);
// suppress the default error dialog box
return true;
} // mtGlobalErrorHandler
// Used to log a client-side (javascript) info or debug data. Will be posted to the Event Log table in Maxim Tech.
function mtLogClientInfo(sMsg, sFile, sExtraInfo) {
mtLogMessage("1", sMsg, sFile, sExtraInfo);
} // mtLogClientInfo
// Used to log a client-side (javascript) warning. Will be posted to the Event Log table in Maxim Tech.
function mtLogClientWarning(sMsg, sFile, sExtraInfo) {
mtLogMessage("2", sMsg, sFile, sExtraInfo);
} // mtLogClientWarning
// Used to log a client-side (javascript) security event. Will be posted to the Event Log table in Maxim Tech.
function mtLogClientSecurity(sMsg, sFile, sExtraInfo) {
mtLogMessage("3", sMsg, sFile, sExtraInfo);
} // mtLogClientSecurity
// Used to log a client-side (javascript) error. Will be posted to the Event Log table in Maxim Tech.
function mtLogClientError(sMsg, sFile, sExtraInfo) {
mtLogMessage("4", sMsg, sFile, sExtraInfo);
} // mtLogClientError
// Used to log a client-side (javascript) exception. Will be posted to the Event Log table in Maxim Tech.
// This is equivalent to a FATAL error on the server side.
function mtLogClientException(sMsg, sFile, sExtraInfo, sLineNum) {
mtLogMessage("5", sMsg, sFile, sExtraInfo, sLineNum);
} // mtLogClientException
// Internal log function, can be called directly if needed, generally will
// use one of the _log???? functions above.
function mtLogMessage(sMsgLevel, sMsg, sFile, sExtraInfo, sLineNum) {
var sPostData;
sPostData = "errMsg=" + encodeURIComponent((sMsg == null) ? "" : sMsg);
sPostData = sPostData + "&errMsgExt=" + encodeURIComponent((sExtraInfo == null) ? "" : sExtraInfo);
sPostData = sPostData + "&httpHost=" + encodeURIComponent(window.location.hostname);
sPostData = sPostData + "&fileName=" + encodeURIComponent((sFile == null) ? "" : sFile);
sPostData = sPostData + "&lineNum=" + encodeURIComponent((sLineNum == null) ? "" : sLineNum);
sPostData = sPostData + "&clientIP=" + encodeURIComponent("38.107.191.98");
sPostData = sPostData + "&browser=" + encodeURIComponent(navigator.userAgent);
sPostData = sPostData + "&referrer=" + encodeURIComponent(document.referrer);
sPostData = sPostData + "&scriptName=" + encodeURIComponent(window.location.pathname);
sPostData = sPostData + "&cookieStr=" + encodeURIComponent(document.cookie);
sPostData = sPostData + "&queryStr=" + encodeURIComponent(window.location.search);
sPostData = sPostData + "&errLevel=" + encodeURIComponent((sMsgLevel == null) ? "1" : sMsgLevel);
sPostData = sPostData + "&errLoc=" + encodeURIComponent("CLIENT");
// Need to use the PostSync for 2 reasons:
// 1. sync post is simpler logic and for logging that is better.
// 2. sync post will work with back to back messages, async post will not.
try {
Ajax(C_EVENT_LOG_ERROR_URL + "?sectoken={86A65BA5-0C8D-4831-972C-85A1BF16C758}", sPostData);
}
catch (e) {
//alert("mtLogMessage: " + e.message);
// eat errors so not to cause recursion.
}
} // mtLogMessage
// Setup global error handler (unless one is already defined on the page).
if (window.onerror == null)
window.onerror = mtGlobalErrorHandler;
function mtIsValidEmail(sEmail) {
if (sEmail == null)
return false;
else if (sEmail.search(/^[A-Z0-9_%'!#`~&=\+\-\$\*\/\?\|\^\{\}]+(?:\.[A-Z0-9_%'!#`~&=\+\-\$\*\/\?\|\^\{\}]+)*@(?:[A-Z0-9-]+\.)+(?:[A-Z]{2,4}|(?:museum)|(?:local))$/i) == -1)
return false;
else if (sEmail.length > 320) // max of 320 chars total.
return false;
else if (sEmail.indexOf("@") > 64) // max of 64 chars in local part.
return false;
else
return true;
} // mtIsValidEmail
function mtStandardizeEmailList(strEmail, bAllowBlank) {
if (bAllowBlank == null)
bAllowBlank = true;
if (strEmail == null || strEmail == "") {
if (bAllowBlank == true)
return "";
else
throw mtCreateException("Email list can not be blank");
}
// Standardize the format.
var strEmail = strEmail.replace(/(,|\s|\/|\\|&)+/g, ";");
var stdValue = "";
// Break it up and check each individual email.
var arr = strEmail.split(";");
var bValid = true;
for (var i = 0; i < arr.length && bValid == true; i++) {
// Skip blank emails.
if (arr[i] != null && arr[i] != "") {
bValid = mtIsValidEmail(arr[i]);
//alert("checking: [" + arr[i] + "]; valid = " + bValid);
stdValue += (stdValue == "") ? "" : ";";
stdValue += arr[i];
}
}
if (bValid == true) {
// check if all emails in the list were blank.
if (stdValue == "") {
if (bAllowBlank == true)
return "";
else
throw mtCreateException("Email list can not be blank");
}
return stdValue;
}
else
throw mtCreateException("Email list contains an invalid email address")
} // mtStandardizeEmailList
function mtValidate(frm)
{
var i, e;
var req = "";
var maxLen = "";
var minLen = "";
var sMaskMsg = "";
var retVal = true;
var bPassedRequired;
var bFocusSet = false;
try {
for (i = 0; i < frm.length; i++) {
e = frm.elements[i];
bPassedRequired = true;
// Skip non-input elements and hidden/disabled elements.
// if (e.type != null && e.disabled == false && e.name.indexOf('_xz') == -1) {
if (e.type != null && e.disabled == false && e.name.indexOf('_xz') == -1 && e.type != "hidden" && IsVisible(e)) {
// alert(e.name);
//if (e.name == "bank_routing_number") {
// alert("style.display = [" + e.style.display + "]");
// alert("style.visibility = [" + e.style.visibility + "]");
// alert("IsVisible = [" + IsVisible(e) + "]");
//}
/*
var compact = (e.getAttribute("compact") != null) ? e.getAttribute("compact") : (e.getAttribute("Compact") != null) ? e.getAttribute("compact") : e.getAttribute("COMPACT");
var currency = (e.getAttribute("currency") != null) ? e.getAttribute("currency") : (e.getAttribute("Currency") != null) ? e.getAttribute("Currency") : e.getAttribute("CURRENCY");
var friendlyName = (e.getAttribute("friendlyname") != null) ? e.getAttribute("friendlyname") : (e.getAttribute("friendlyName") != null) ? e.getAttribute("friendlyName") : (e.getAttribute("FriendlyName") != null) ? e.getAttribute("FriendlyName") : (e.getAttribute("Friendlyname") != null) ? e.getAttribute("Friendlyname") : e.getAttribute("FRIENDLYNAME");
var email = (e.getAttribute("email") != null) ? e.getAttribute("email") : (e.getAttribute("Email") != null) ? e.getAttribute("Email") : e.getAttribute("EMAIL");
var maxLength = (e.getAttribute("maxlength") != null) ? e.getAttribute("maxlength") : (e.getAttribute("maxLength") != null) ? e.getAttribute("maxLength") : (e.getAttribute("MaxLength") != null) ? e.getAttribute("MaxLength") : (e.getAttribute("Maxlength") != null) ? e.getAttribute("Maxlength") : e.getAttribute("MAXLENGTH");
var minLength = (e.getAttribute("minlength") != null) ? e.getAttribute("minlength") : (e.getAttribute("minLength") != null) ? e.getAttribute("minLength") : (e.getAttribute("MinLength") != null) ? e.getAttribute("MinLength") : (e.getAttribute("Minlength") != null) ? e.getAttribute("Minlength") : e.getAttribute("MINLENGTH");
var numeric = (e.getAttribute("numeric") != null) ? e.getAttribute("numeric") : (e.getAttribute("Numeric") != null) ? e.getAttribute("Numeric") : e.getAttribute("NUMERIC");
var required = (e.getAttribute("required") != null) ? e.getAttribute("required") : (e.getAttribute("Required") != null) ? e.getAttribute("Required") : e.getAttribute("REQUIRED");
var url = (e.getAttribute("url") != null) ? e.getAttribute("url") : (e.getAttribute("Url") != null) ? e.getAttribute("Url") : e.getAttribute("URL");
*/
// mtGetAttribute returns a blank string instead of a null when the attribute isn't found so use mtGetRawAttribute instead.
var compact = mtGetRawAttribute(e, "compact", "Compact", "COMPACT");
var currency = mtGetRawAttribute(e, "currency", "Currency", "CURRENCY");
var friendlyName = mtGetRawAttribute(e, "friendlyname", "friendlyName", "FriendlyName", "Friendlyname", "FRIENDLYNAME");
//alert("friendly: " + friendlyName);
var email = mtGetRawAttribute(e, "email", "Email", "EMAIL");
var emailList = mtGetRawAttribute(e, "emaillist", "emailList", "EmailList", "Emaillist", "EMAILLIST");
var maxLength = mtGetRawAttribute(e, "maxlength", "maxLength", "MaxLength", "Maxlength", "MAXLENGTH");
var minLength = mtGetRawAttribute(e, "minlength", "minLength", "MinLength", "Minlength", "MINLENGTH");
var numeric = mtGetRawAttribute(e, "numeric", "Numeric", "NUMERIC");
var required = mtGetRawAttribute(e, "required", "Required", "REQUIRED");
var url = mtGetRawAttribute(e, "url", "Url", "URL");
var percentage = mtGetRawAttribute(e, "percentage", "Percentage", "PERCENTAGE");
//alert("about to declare");
// var date = mtGetRawAttribute(e, "dateonly", "DateOnly", "DATEONLY");
var date = mtGetRawAttribute(e, "date", "Date", "DATE");
var time = mtGetRawAttribute(e, "time", "Time", "TIME");
var datetime = mtGetRawAttribute(e, "datetime", "dateTime", "DateTime", "Datetime", "DATETIME");
//alert("after declare");
var pswdMatch = mtGetRawAttribute(e, "pswdmatch", "pswdMatch", "PswdMatch", "Pswdmatch", "PSWDMATCH");
var creditCard = mtGetRawAttribute(e, "creditcard", "creditCard", "CreditCard", "Creditcard", "CREDITCARD");
// Fill in some default values.
if (friendlyName == null) {
friendlyName = (e.name == null || e.name == "") ? ((e.id == null || e.id == "") ? "field" : e.id) : e.name;
//alert("friendly: " + friendlyName);
e.setAttribute("friendlyName", friendlyName);
}
// Get a lower case version for comparison sake below.
var sFriendlyLower = friendlyName.toLowerCase();
// Remember original value to see if it changes.
var sOriginalVal = e.value;
// Remove leading and trailing spaces on text fields.
if (e.type.search(/text|textarea|password|file/) != -1)
e.value = Trim(e.value);
// Check if all white space needs to be removed.
if (compact != null)
e.value = e.value.replace(/\s/g, "");
if (required != null && IsVisible(e) == true) {
if (e.type == "radio" && req.indexOf(sFriendlyLower) == -1) {
// Calls the function at the top to see if any radio button in a particular group was checked
if (IsRadioGroupChecked(frm, e.name) == false) {
req += " " + friendlyName + "\n";
bPassedRequired = false;
}
}
else if (e.value == "") {
req += " " + friendlyName + "\n";
bPassedRequired = false;
}
}
if (bPassedRequired && (e.value != "" && (sFriendlyLower == "email address" || sFriendlyLower == "email" || email != null))) {
if (mtIsValidEmail(e.value) == false)
sMaskMsg += " " + friendlyName + " as entered is not a valid email address.\n";
if (bFocusSet == false) {
e.focus();
bFocusSet == true;
}
}
if (bPassedRequired && e.value != "" && emailList != null) {
var sPreStdValue = e.value;
try {
e.value = mtStandardizeEmailList(e.value, false);
//alert(e.value);
}
catch (exc) {
//alert("exception: " + exc.message);
// IE seems to mess up the value in the assignment above throws an exception.
e.value = sPreStdValue;
sMaskMsg += " " + friendlyName + " as entered is not a valid email(s).\n";
if (bFocusSet == false) {
e.focus();
bFocusSet == true;
}
}
}
if (bPassedRequired && numeric != null && e.value != "" && !IsNumeric(e.value)) {
sMaskMsg += " " + friendlyName + " as entered is not a valid number.\n";
if (bFocusSet == false) {
e.focus();
bFocusSet == true;
}
}
if (bPassedRequired && currency != null && e.value != "" && !IsCurrency(e.value)) {
sMaskMsg += " " + friendlyName + " as entered is not a valid currency.\n";
if (bFocusSet == false) {
e.focus();
bFocusSet == true;
}
}
if (bPassedRequired && percentage != null && e.value != "" && !IsPercentage(e.value)) {
sMaskMsg += " " + friendlyName + " as entered is not a valid percentage.\n";
if (bFocusSet == false) {
e.focus();
bFocusSet == true;
}
}
if (bPassedRequired && date != null && e.value != "") {
try {
e.value = mtStandardizeDate(e.value, false);
}
catch (exc) {
sMaskMsg += " " + friendlyName + " as entered is not a valid date. " + exc.message + "\n";
if (bFocusSet == false) {
e.focus();
bFocusSet == true;
}
}
}
if (bPassedRequired && time != null && e.value != "") {
try {
e.value = mtStandardizeTime(e.value, false);
}
catch (exc) {
sMaskMsg += " " + friendlyName + " as entered is not a valid time. " + exc.message + "\n";
if (bFocusSet == false) {
e.focus();
bFocusSet == true;
}
}
}
if (bPassedRequired && datetime != null && e.value != "") {
try {
e.value = mtStandardizeDateTime(e.value, false);
}
catch (exc) {
sMaskMsg += " " + friendlyName + " as entered is not a valid date/time. " + exc.message + "\n";
if (bFocusSet == false) {
e.focus();
bFocusSet == true;
}
}
}
if (bPassedRequired && (maxLength != null && maxLength > 0)) {
if (e.value.length > maxLength) {
maxLen = maxLen + " " + friendlyName + " (max length of " + maxLength + ")\n";
if (bFocusSet == false) {
e.focus();
bFocusSet == true;
}
}
}
if (bPassedRequired && (minLength != null && minLength > 0)) {
if (e.value != "" && e.value.length < minLength) {
minLen = minLen + " " + friendlyName + " (min length of " + minLength + ")\n";
if (bFocusSet == false) {
e.focus();
bFocusSet == true;
}
}
}
// Check for a URL.
if (bPassedRequired && e.value != "" && url != null) {
try {
e.value = StandardizeUrl(e.value, mtGetRawAttribute(e, "protocol", "Protocol", "PROTOCOL"));
}
catch (exc) {
sMaskMsg += " " + friendlyName + " as entered is not a valid URL.\n";
if (bFocusSet == false) {
e.focus();
bFocusSet == true;
}
}
}
// Check for password confirm field.
if (bPassedRequired && pswdMatch != null) {
var oPswdField = frm[pswdMatch];
if (oPswdField == null)
sMaskMsg += " Could not find field [" + pswdMatch + "] to match password to.\n";
else if (oPswdField.value != e.value)
sMaskMsg += " Passwords don't match, please try again.\n";
}
// Check for password confirm field.
if (bPassedRequired && creditCard != null) {
try {
e.value = StandardizeCreditCard(e.value);
}
catch (exc) {
sMaskMsg += " " + friendlyName + ": " + exc.message + "\n";
if (bFocusSet == false) {
e.focus();
bFocusSet == true;
}
}
}
} // if enabled input
// Check if element is data bound. If so force the update of the XML data island.
if (window.islands != null && sOriginalVal != e.value && mtGetAttribute(e, "datafield", "Datafield", "DataField", "dataField", "DATAFIELD") != "")
islands.changeEvent(e);
} // end for
} // try
catch (e) {
alert(" Validation Error\n____________________________________\n\nInternal Error Occurred:\n\n" + e.message);
retVal = false;
}
if (req != "") {
alert(" Validation Error\n____________________________________\n\nRequired Fields:\n\n" + req);
retVal = false;
}
if (maxLen != "") {
alert(" Validation Error\n____________________________________\n\nMaximum Length Exceeded:\n\n" + maxLen);
retVal = false;
}
if (minLen != "") {
alert(" Validation Error\n____________________________________\n\nMinimum Length Not Reachd:\n\n" + minLen);
retVal = false;
}
if (sMaskMsg != "") {
alert(" Validation Error\n____________________________________\n\nValidation Error:\n\n" + sMaskMsg);
retVal = false;
}
return retVal;
} // mtValidate
function mtValidateAndEmail(oForm) {
var bRetVal = mtValidate(oForm);
if (bRetVal == true) {
var sMsg = "";
var retVal = ( {} );
// If no custom ajax page use the canned one.
var url = "/include-mt/ajax-xml-save.asp";
url += "?debug=true";
url += "§oken=" + '{86A65BA5-0C8D-4831-972C-85A1BF16C758}';
url += "&dryrun=false";
url += "&action=email";
var sSubject = mtFormFieldSubstitutions(oForm, mtGetAttribute(oForm, "subject", "Subject", "SUBJECT"));
var sBody = mtFormToText(oForm);
var sFrom = mtFormFieldSubstitutions(oForm, mtGetAttribute(oForm, "from", "From", "FROM"));
var sTo = mtFormFieldSubstitutions(oForm, mtGetAttribute(oForm, "to", "To", "TO"));
var sCC = mtFormFieldSubstitutions(oForm, mtGetAttribute(oForm, "cc", "Cc", "CC"));
var sBCC = mtFormFieldSubstitutions(oForm, mtGetAttribute(oForm, "bcc", "Bcc", "BCC"));
// If no FROM address then default to the "to" address.
if (sFrom == "")
sFrom = (sTo != "") ? sTo : sCC;
var sXml = "";
//alert("DEBUG XML: " + sXml);
var jsonMsg = '';
try {
//alert("URL: " + url);
// jsonMsg = Ajax(url, encodeURIComponent('' + sXml + ''));
jsonMsg = Ajax(url, '' + sXml + '');
//alert("in try block: " + jsonMsg);
}
catch (e) {
var sError = e.message;
if (sError.indexOf("403") >= 0) {
//alert(sError);
sError = "Security token authorization failed (may need to refresh your page).";
}
//alert("HTTP error: " + sError);
jsonMsg = '( { "errorList": [ { "rowid": 0, "message": "Call to [' + url + '] failed. Status code: ' +
sError.replace(/\'/g, "\'").replace(/\r/g, "\\r").replace(/\n/g, "\\n") +
'"} ], "warningList": [ ], "infoList": [ ] } )';
}
//alert(jsonMsg);
retVal = eval(jsonMsg);
bRetVal = retVal.errorList.length == 0;
// Loop thru and build message list to show user.
for (var j = 0; j < retVal.errorList.length; j++) {
sMsg += "ERROR: " + retVal.errorList[j].message + "\n";
}
for (var j = 0; j < retVal.warningList.length; j++) {
sMsg += "WARNING: " + retVal.warningList[j].message + "\n";
}
for (var j = 0; j < retVal.infoList.length; j++) {
sMsg += "INFO: " + retVal.infoList[j].message + "\n";
}
// Show the user any necessary info.
if (sMsg != "")
alert("Email Results\n---------------------\n\n" + sMsg);
}
return bRetVal;
} // mtValidateAndEmail
// This function will get the real value (can return null), the mtGetAttribute will return a space if the attr is null.
// Can pass in multiple attribute names, will return the first non-null value.
function mtGetRawAttribute(oNode, sAttrName) {
if (oNode == null)
return null;
else {
var sValue = null;
// Might have passed in multiple names (may be different cases or different attributes altogether).
for (var i = 1; sValue == null && i < arguments.length; i++)
sValue = oNode.getAttribute(arguments[i]);
// Check for a IE data binding hack - this should be an empty string since the attribute is preset.
if (sValue == "~crazyIE~3217654~")
sValue = "";
return sValue;
}
} // mtGetRawAttribute
// Can pass in multiple attribute names, will return the first non-null value.
function mtGetAttribute(oNode, sAttrName) {
if (oNode == null)
return "";
else {
var sValue = null;
// Might have passed in multiple names (may be different cases or different attributes altogether).
for (var i = 1; sValue == null && i < arguments.length; i++)
sValue = oNode.getAttribute(arguments[i]);
// Check for a IE data binding hack.
if (sValue == "~crazyIE~3217654~")
sValue = "";
return (sValue == null) ? "" : sValue;
}
} // mtGetAttribute
function mtAttributesToQueryString(oNode, bSpecifiedOnly) {
if (bSpecifiedOnly == null)
bSpecifiedOnly = false;
var qs = "";
if (oNode != null) {
for (var i = 0; i < oNode.attributes.length; i++) {
if (oNode.attributes[i].specified == true)
qs += oNode.attributes[i].name + "=" + mtGetAttribute(oNode, oNode.attributes[i].name) + "&";
}
qs = qs.substr(0, qs.length - 1);
}
return qs;
} // mtGetAttribute
// This function returns an Array of elements matching the parameters.
// The document.getElementsByName only works for these elements in IE since they "officially" have a NAME attribute.
// BUTTON, TEXTAREA, APPLET, SELECT, FORM, FRAME, IFRAME, IMG, A, INPUT, OBJECT, MAP, PARAM and META
function mtGetElementsByTagAndName(sTagName, sName) {
var retArray = new Array();
if (sTagName == null || sName == null)
return retArray;
//alert("mtGetElementsByTagAndName");
var oList = document.getElementsByTagName(sTagName.toUpperCase());
//alert(oList.length);
for (var i = 0; i < oList.length; i++) {
if (oList.item(i).getAttribute("name") == sName) {
retArray[retArray.length] = oList.item(i);
}
}
//alert(retArray.length);
return retArray;
} // mtGetElementsByTagAndName
Array.prototype.mtIndexOf = function (searchItem, bCaseSensitive) {
if (bCaseSensitive == null)
bCaseSensitive = true;
if (bCaseSensitive == false)
searchItem = searchItem.toString().toUpperCase();
for (var i = 0; i < this.length; i++) {
if (bCaseSensitive == true) {
if (this[i] == searchItem)
return i;
}
else if (this[i].toString().toUpperCase() == searchItem)
return i;
}
return -1;
} // mtIndexOf
function mtGetElem(elemID) {
if (document.all) {
// IE will search by ID and also by Name.
return document.getElementById(elemID);
}
else {
var elem = document.getElementById(elemID);
if (elem == null) {
var elemArray = document.getElementsByName(elemID);
// If exactly one match then we're good.
if (elemArray.length == 1)
elem = elemArray[0];
}
return elem;
}
} // mtGetElem
//function mtFormToXmlRow(oForm, sRowName, bIncludeDisabled, arrIgnoreTypes) {
function mtFormToXmlAttributes(oForm, bIncludeDisabled, arrIgnoreTypes) {
var sName;
// if (sRowName == null)
// sRowName = "row";
if (bIncludeDisabled == null)
bIncludeDisabled = false;
if (arrIgnoreTypes == null)
arrIgnoreTypes = ['reset', 'submit', 'button'];
// var sXml = "<" + sRowName;
var sXml = "";
// var radioList = new Object();
var sValue, oElem;
for (var i = 0; i < oForm.length; i++) {
oElem = oForm.elements[i];
// Skip non-input elements.
if (oElem.type != null && arrIgnoreTypes.mtIndexOf(oElem.type) == -1) {
//alert("mtFormToXmlAttributes type = " + oElem.type);
// Check if we are skipping disabled elements. Reverse the condition in case an element doesn't have a disabled property - will still take it.
if (bIncludeDisabled == true || !(oElem.disabled == true)) {
// The friendlyName is set during the mtValidate procedure.
sName = (oElem.id != "") ? oElem.id : (oElem.name != "") ? oElem.name : "";
if (sName == null)
sName = mtGetRawAttribute(oElem, "friendlyname", "friendlyName", "FriendlyName", "Friendlyname", "FRIENDLYNAME");
//alert("mtFormToXmlAttributes sName = " + sName);
if (sName != "") {
if (oElem.type == "radio") {
if (oElem.checked)
sValue = oElem.value;
else
sName = ""; // blank out the name so we don't create an item.
}
else if (oElem.type == "checkbox")
sValue = (oElem.checked) ? oElem.value : (oElem.getAttribute("unvalue") == null) ? "" : oElem.getAttribute("unvalue");
else
sValue = oElem.value;
// Only get the value for a radio the first time. This will also give a blank value if none of the radio buttons are checked.
// if (oElem.type != "radio" || radioList[sName] != true) {
if (sName != "") {
sXml += ' ' + sName + '="' + mtXmlEncode(sValue) + '" ';
// if (oElem.type == "radio")
// radioList[sName] = true;
}
}
}
}
}
// sXml += ">" + sRowName + ">";
radioList = null;
/*
var oList = oForm.getElementsByTagName("INPUT");
for (var i = 0; i < oList.length; i++) {
if (oList[i].type != "submit" && oList[i].type != "reset") {
var sName = (oList[i].id != "") ? oList[i].id : (oList[i].name != "") ? oList[i].name : "";
//alert("mtFormToXml sName = " + sName);
if (sName != "") {
sXml += sName + '="' + mtXmlEncode(oList[i].value) + '" ';
}
}
//alert("mtFormToXml sXml = " + sXml);
}
var oList = oForm.getElementsByTagName("TEXTAREA");
for (var i = 0; i < oList.length; i++) {
var sName = (oList[i].id != "") ? oList[i].id : (oList[i].name != "") ? oList[i].name : "";
//alert("mtFormToXml sName = " + sName);
if (sName != "") {
sXml += sName + '="' + mtXmlEncode(oList[i].value) + '" ';
}
}
*/
// alert("mtFormToXmlAttributes, sXml = " + sXml);
return sXml;
} // mtFormToXmlAttributes
// To DO:
// * currently they have to be in the same order
// * currently the value also includes the ="" so if one has ="" and the other ='' they won't match.
// Fairly safe now since it errs on the side of mismatch.
function mtChangedXmlAttributes(sOldAttr, sNewAttr, bCaseSensitive) {
if (bCaseSensitive == null)
bCaseSensitive = true;
if (bCaseSensitive == false) {
sOldAttr = sOldAttr.toUpperCase();
sNewAttr = sNewAttr.toUpperCase();
}
// Get a name/value pair.
var arrOldPairName = sOldAttr.match(/[^\s\=<>\/]+(?=\s*\=)/g);
var arrOldPairValue = sOldAttr.match(/(?:\=\s*)(?:(?:"[^"]*")|(?:'[^']*'))/g);
var arrNewPairName = sNewAttr.match(/[^\s\=<>\/]+(?=\s*\=)/g);
var arrNewPairValue = sNewAttr.match(/(?:\=\s*)(?:(?:"[^"]*")|(?:'[^']*'))/g);
var sChangeList = ",";
var i;
for (i = 0; arrOldPairName != null && i < arrOldPairName.length; i++) {
//alert("old list: " + arrOldPairName[i]);
if (i >= arrNewPairName.length)
sChangeList += arrOldPairName[i] + ",";
else if (arrOldPairName[i] != arrNewPairName[i])
sChangeList += arrOldPairName[i] + ",";
else if (arrOldPairValue[i] != arrNewPairValue[i])
sChangeList += arrOldPairName[i] + ",";
}
// Tack on any attributes in the new list not found in the old list.
for (i = i; arrNewPairName != null && i < arrNewPairName.length; i++) {
//alert("new list: " + arrNewPairName[i]);
sChangeList += arrNewPairName[i] + ",";
}
// return (sChangeList == "") ? "" : sChangeList.substring(0, sChangeList.length - 1);
// return sChangeList;
// Make sure if there are columns in this list that it starts AND ends with a comma.
return (sChangeList == ",") ? "" : sChangeList;
} // mtChangedXmlAttributes
function mtFormToText(oForm) {
var sXml = "";
for (var i = 0; i < oForm.length; i++) {
// Skip non-input elements.
if (oForm.elements[i].type != null && oForm.elements[i].type != "submit" && oForm.elements[i].type != "reset") {
// The friendlyName is set during the mtValidate procedure.
var sName = mtGetRawAttribute(oForm.elements[i], "friendlyname", "friendlyName", "FriendlyName", "Friendlyname", "FRIENDLYNAME");
if (sName == null)
sName = (oForm.elements[i].id != "") ? oForm.elements[i].id : (oForm.elements[i].name != "") ? oForm.elements[i].name : "";
var sValue = "";
//alert("mtHtmlContainerToXml sName = " + sName);
if (sName != "") {
sValue = mtGetHtmlValue(oForm.elements[i]);
sXml += sName + ': ' + sValue + "\r\n\r\n";
}
}
//alert("mtHtmlContainerToXml sXml = " + sXml);
} // for
return sXml;
} // mtFormToText
// Will build a string for submitting a form in the format:
// myInput=fred&nextInput=wilma
function mtBuildFormKeyValues(oForm) {
var sData = "";
for (var i = 0; i < oForm.length; i++) {
// Skip non-input elements - if a radio then only tack on the value of the clicked radio.
if (oForm.elements[i].type != null && oForm.elements[i].type != "submit" && oForm.elements[i].type != "reset" && oForm.elements[i].disabled != true && (oForm.elements[i].type != "radio" || oForm.elements[i].checked)) {
var sName = (oForm.elements[i].name != "") ? oForm.elements[i].name : (oForm.elements[i].id != "") ? oForm.elements[i].id : "";
var sValue = "";
//alert("mtHtmlContainerToXml sName = " + sName);
if (sName != "") {
sValue = mtGetHtmlValue(oForm.elements[i]);
sData += ((sData != "") ? "&" : "") + sName + '=' + encodeURIComponent(sValue);
}
}
//alert("mtHtmlContainerToXml sData = " + sData);
} // for
return sData;
} // mtBuildFormKeyValues
function mtGetHtmlValue(oElem) {
if (oElem == null)
return "";
else {
if (oElem.type == "radio")
return RadioValue(oElem);
else if (oElem.type == "checkbox")
return (oElem.checked) ? oElem.value : (oElem.getAttribute("unvalue") == null) ? "" : oElem.getAttribute("unvalue");
else
return oElem.value;
}
} // mtGetHtmlValue
function mtFormFieldSubstitutions(oForm, sValue) {
sValue = sValue.replace(/~([^~]*)~/g, function (sMatch, sSubExp1) {
return mtGetHtmlValue((oForm[sSubExp1] != null) ? oForm[sSubExp1] : (oForm[sSubExp1.toLowerCase()] != null) ? oForm[sSubExp1.toLowerCase()] : oForm[sSubExp1.toUpperCase()]);
} );
return sValue;
} // mtFormFieldSubstitutions
//====================================this function will focus the cursor on the first selectable item in the given form - (formName)
//IMPORTANT!!!!! you must call this function AFTER the form loads.
// formName is optional, if omitted it will use the first form on the page.
function mtFormFocus(formName) {
var newForm;
if (document.forms[formName] != null)
newForm = document.forms[formName].name;
else
newForm = document.forms[0];
if (newForm != null) {
var dobreak = false;
for (var i = 0; i < eval(newForm + ".elements.length"); i++) {
if (((eval(newForm + ".elements[i].value") == '') || (eval(newForm + ".elements[i].value") == 0)) && (eval(newForm + ".elements[i].name") != 'Header1:LoginSearch1:txbSearch') && (eval(newForm + ".elements[i].type") != 'hidden') && (eval(newForm + ".elements[i].disabled") != true)) {
if (document.all.tags("div") && document.all.tags("div").length > 0) {
// alert(document.all.tags("div").length);
// alert(eval(newForm + ".elements[i].name"));
for (var q = 0; q < document.all.tags("div").length; q++) {
if ((document.all.tags("div")[q].style.display == '')) {
// alert(eval(newForm + ".elements[i].name"));
eval(newForm + ".elements[i].focus()");
dobreak = true;
break;
}
}
}
else {
// alert(eval(newForm + ".elements[i].name"));
eval(newForm + ".elements[i].focus()");
dobreak = true;
}
if (dobreak = true) {
break;
}
}
} // for
} // if newForm
} // mtFormFocus
function mtCreateXmlDoc(sXml) {
var oDoc;
if (document.implementation && document.implementation.createDocument) {
oDoc = document.implementation.createDocument("", "", null);
//alert("dom 1");
}
else {
try {
oDoc = new ActiveXObject("Msxml2.XMLDOM");
//alert("dom 2");
}
catch (e1) {
try {
oDoc = new ActiveXObject("Microsoft.XMLDOM");
//alert("dom 3");
}
catch (e2) {
oDoc = null;
//alert("dom 4");
}
}
} // else
// oDoc.async = false
if (oDoc != null && sXml != "")
oDoc.loadXML(sXml);
return oDoc;
} // mtCreateXmlDoc
function mtXmlEncode(str) {
var oStr = (str == null) ? new String("") : new String(str);
return oStr.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(//g, ">");
} // mtXmlEncode
function IsRadioGroupChecked(frm, sName) {
if (frm[sName].length == null || frm[sName].length == 1)
return frm[sName].checked;
else {
for (var i = 0; i < frm[sName].length; i++) {
if (frm[sName][i].checked) {
return true;
}
}
return false;
}
} // IsRadioGroupChecked
function mtAddLoadEvent(func) {
var oldonload = window.onload;
if (typeof oldonload != 'function') {
window.onload = func;
}
else {
window.onload = function() {
oldonload();
func();
}
}
} // mtAddLoadEvent
// NOTE: can pass in ADDITIONAL pairs of arguments for name/value pairs to setup.
function mtCreateElement(sTag, sName) {
sTag = sTag.toUpperCase();
var oElem;
if (sName == null || sName == "") {
// Just create a simple tag.
oElem = document.createElement(sTag);
}
else {
if (document.all)
oElem = document.createElement("<" + sTag + " name='" + sName + "' id='" + sName + "' />");
else {
oElem = document.createElement(sTag);
oElem.setAttribute("name", sName);
oElem.setAttribute("id", sName);
}
}
// If they passed in pairs of values init them now.
if (arguments.length > 2) {
for (var i = 2; i < arguments.length; i = i + 2)
oElem.setAttribute(arguments[i], arguments[i + 1]);
}
return oElem;
} // mtCreateElement
function GetSpamBusterInputTag() {
return "";
} // GetSpamBusterInputTag
function Trim(str)
{
var objStr = new String(str);
var pat = /^\s*(\S*(\s+\S+)*)\s*$/;
return objStr.replace(pat, "$1");
}
function StripRequired(which)
{
var i;
for (i=0;i 0) {
if (num.indexOf(".") < 0)
num = num + ".";
while (num.indexOf(".") > (num.length - decimalPlaces - 1))
num = num + "0";
}
if (thousandSep != "") {
// var iSeps = 0;
var iStart = (num.indexOf(".") < 0) ? num.length - 1 : num.indexOf(".") - 1;
var iEnd = (num.indexOf("-") < 0) ? 0 : 1;
for (var i = iStart - 3; i >= iEnd; i -= 3) {
// if ((iStart - i - iSeps) % 3 == 0) {
//alert("i = " + i + "; sub1 = [" + num.substr(0, i + 1) + "]; sub2 = [" + num.substr(i + 1) + "]");
num = num.substr(0, i + 1) + thousandSep + num.substr(i + 1);
// iSeps += 1;
// }
}
}
//alert("mtFormatNumber: 10");
return num;
} // mtFormatNumber
// Search up the object hierarchy to find an element with the given tag name.
// ParentID is OPTIONAL, only used if there are several elements with the same tag name, ie nested tables.
function findParentElement(oElem, parentTagName, parentID) {
parentTagName = parentTagName.toUpperCase();
while (oElem != null && (oElem.nodeType != 1 /*element*/ || oElem.tagName.toUpperCase() != parentTagName || (parentID != null && oElem.id != parentID))) {
//alert(oElem.tagName);
oElem = oElem.parentNode;
}
return oElem;
} // findParentElement
function findParentByAttribute(oElem, sAttrName, sAttrVal) {
if (oElem == null)
return null;
//alert("findParent 1");
while (oElem != null) {
//alert("findParent 3");
//if (oParent.getAttribute == null)
// alert(oElem.nodeName);
var oAttr = (oElem.nodeType != 1 /*element*/) ? null : ((oElem.getAttribute == null) ? null : oElem.getAttribute(sAttrName));
//alert("findParent 4");
if (oAttr != null && (arguments.length <= 2 || oAttr == sAttrVal))
return oElem;
//alert("findParent 5");
oElem = oElem.parentNode;
}
return oElem;
} // findParentByAttribute
function findChildByAttribute(oParent, sAttrName, sAttrVal, bRecursive) {
if (oParent == null)
return null;
if (bRecursive == null)
bRecursive = false;
var oChild = oParent.firstChild;
while (oChild != null) {
if (oChild.nodeName != '#text') {
var oAttr = oChild.getAttribute(sAttrName);
/*
if (oAttr != null || oChild.type == "checkbox") {
// alert("oChild.name = [" + oChild.name + "]\noChild.id = [" + oChild.id + "]\nsAttrName = [" + sAttrName + "]\n sAttrVal = [" + sAttrVal + "]\n found Attr = [" + oAttr + "]\n checkbox value = [" + oChild.checked + "]\n oChild.getAttribute() = [" + oChild.getAttribute("checked") + "]\n oChild.getAttribute(default) = [" + oChild.getAttribute("defaultChecked") + "]\n oChild.getAttribute(check) = [" + oChild.getAttribute("check") + "]\n ");
alert("oChild.name = [" + oChild.name + "]\n looking for sAttrName = [" + sAttrName + "]\n looking for sAttrVal = [" + sAttrVal + "]\n found Attr = [" + oAttr + "]\n checkbox value = [" + oChild.checked + "]\n oChild.getAttribute() = [" + oChild.getAttribute("checked") + "]\n ");
if (sAttrName == "checked")
alert(1);
if (sAttrVal == null)
alert(2);
if (oChild.checked == sAttrVal)
alert(3);
}
*/
if (oAttr != null && (sAttrVal == null || oAttr == sAttrVal))
return oChild;
// Special hack for firefox - the "checked" attribute is always null when calling getAttribute - weird.
else if (oChild.type == "checkbox" && sAttrName == "checked" && (sAttrVal == null || oChild.checked == sAttrVal))
return oChild;
else if (bRecursive == true) {
var oTemp = findChildByAttribute(oChild, sAttrName, sAttrVal, true);
if (oTemp != null)
return oTemp;
}
}
oChild = oChild.nextSibling;
}
return oChild;
} // findChildByAttribute
/* other possibly renamed attributes
if (attribute == "class")
node.className = value;
else if (attribute == "checked")
node.defaultChecked = value;
else if (attribute == "for")
node.htmlFor = value;
else if (attribute == "style")
node.style.cssText = value;
*/
function findFirstNonTextChild(oParent) {
if (oParent != null) {
oParent = oParent.firstChild;
while (oParent != null && oParent.nodeName == '#text')
oParent = oParent.nextSibling;
}
return oParent;
} // findFirstNonTextChild
// This can be called by:
//if (document.addEventListener)
// document.addEventListener("DOMContentLoaded", mtInitPageFireFox, false);
function mtInitPageFireFox() {
try {
// Set select boxes back to their default behavior - this allows IE and Firefox
// to function the same on a Refresh. Currently firefox resets select boxes
// back to what the user last picked - this is different than IE which sets it back to
// the initial value.
var arrSelects = document.getElementsByTagName("select");
//alert(arrSelects.length);
for (var iSel = 0; iSel < arrSelects.length; iSel++) {
var oSelect = arrSelects[iSel];
for (var i = 0; i < oSelect.length; i++) {
if (oSelect.options[i].defaultSelected == true)
oSelect.selectedIndex = i;
}
}
}
catch(e) {
alert("mtInitPageFireFox(): " + e.message);
}
} // mtInitPageFireFox
// ****************** THIS IS A GLOBAL FIX **********
// Firefox fix for the drop down boxes init.
if (document.addEventListener)
document.addEventListener("DOMContentLoaded", mtInitPageFireFox, false);
// ***************************************************
function mtLeftPad(sString, nWidth, sChar) {
if (sChar == null)
sChar = " ";
// Ensure the input is a string data type.
if (sString == null)
sString = "";
else
sString = new String(sString);
var sPad = "";
var nLen = sString.length;
while (nLen + sPad.length < nWidth)
sPad = sChar + sPad;
return sPad + sString;
} // mtLeftPad
function mtRightPad(sString, nWidth, sChar) {
if (sChar == null)
sChar = " ";
// Ensure the input is a string data type.
if (sString == null)
sString = "";
else
sString = new String(sString);
var sPad = "";
var nLen = sString.length;
while (nLen + sPad.length < nWidth)
sPad = sChar + sPad;
return sString + sPad;
} // mtRightPad
function mtZeroPad(val, width) {
return mtLeftPad(val, width, "0");
} // mtZeroPad
function IsNumeric(str) {
var objStr = Trim(str).replace(/\,/g, "");
return ( objStr.match(/(^\-?\d+$)|(^\-?\d*\.\d{0,2}$)/) != null );
} // IsNumeric
function IsInteger(str) {
var objStr = new String(str).replace(/\,/g, "");
return objStr.match(/^\-?\d+$/) != null;
} // IsInteger
function IsCurrency(str) {
var objStr = Trim(str).replace(/\$|\,/g, "");
return ( objStr.match(/(^\-?\d+$)|(^\-?\d*\.\d{0,2}$)/) != null );
} // IsCurrency
function IsPercentage(str) {
var objStr = Trim(str).replace(/\%|\,/g, "");
return ( objStr.match(/(^\d+$)|(^\d*\.\d+$)/) != null );
} // IsPercentage
function IsDate(str) {
var l_date = new Date( str );
return !isNaN( l_date.getDate() );
} // IsDate
// Returns the number of days in the given month.
function mtGetDaysInMonth(month, year) {
if (year == null)
year = new Date().getFullYear();
var arrDaysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
arrDaysInMonth[1] = 29;
return arrDaysInMonth[month - 1];
} // mtGetDaysInMonth
// For IE the oEvent param will be undefined. For Firefox it will be the "event" object within the object's event handler.
// To cancel the onclick handler of a parent element do this in the target/child element:
// onclick="mtCancelBubble(event);"
function mtCancelBubble(oEvent) {
// IE has a different event handling than Firefox.
if (window.event != null)
window.event.cancelBubble = true;
else
oEvent.cancelBubble = true;
return;
} // mtCancelBubble
function mtCreateException(sMsg) {
// IE has a different constructor than Firefox.
if (window.navigator.userAgent.search('MSIE') >= 0)
return new Error(0, sMsg);
else
return new Error(sMsg);
} // mtCreateException
// Date format function:
// http://blog.stevenlevithan.com/archives/date-time-format
// Return date in a MM/DD/YYYY format or throw an exception if the date is not valid.
function mtStandardizeDate(strDate, bAllowBlank) {
var minYear=1900;
var maxYear=2100;
if (bAllowBlank == null)
bAllowBlank = true;
// Standardize the format.
strDate = strDate.replace(/-|\\|\./g, "/");
strDate = strDate.replace(/\0|\s/g, "");
// // DCS 9/28/09. Only replace spaces around the / delimiter - maybe could replace all spaces, but this should at least help.
// strDate = strDate.replace(/\s*\/\s*/g, "/");
// // Remove extra spaces - maybe blank after this.
// strDate = Trim(strDate);
//alert("mtStandardizeDate 1: [" + strDate + "]");
if (strDate == "" && bAllowBlank)
return "";
// If only day/month then tack on current year.
if (strDate.indexOf('/') >= 0 && strDate.indexOf('/') == strDate.lastIndexOf('/'))
strDate += "/" + (new Date()).getYear();
// DCS 9/29/09 - use regex to parse out date parts.
var datePartArr = strDate.match(/^(\d{1,2})\/+(\d{1,2})\/+(\d{1,4})$/);
if (datePartArr == null || datePartArr.length < 4)
throw mtCreateException("Invalid date (regex). Please enter in form mm/dd/yyyy")
var nMonth = datePartArr[1];
var nDay = datePartArr[2];
var nYear = new Number(datePartArr[3]);
// Check for 2 digit year.
if (nYear < 100) {
if (nYear >= 50)
nYear += 1900;
else
nYear += 2000;
}
if (nYear < minYear || nYear > maxYear)
throw mtCreateException('Invalid date: the year is out of range.');
else if (nMonth < 1 || nMonth > 12 || nDay < 1 || nDay > mtGetDaysInMonth(nMonth, nYear))
throw mtCreateException('Invalid month and/or day.');
strDate = mtZeroPad(nMonth, 2) + '/' + mtZeroPad(nDay, 2) + '/' + nYear;
//alert("mtStandardizeDate 2: [" + strDate + "]");
// if (!IsDate(strDate))
// throw mtCreateException("Invalid date (js): please enter in form mm/dd/yyyy")
// var nMonth = parseInt(strDate, 10);
// var nDay = parseInt(strDate.substr(strDate.indexOf('/') + 1, 2), 10);
// var nYear = parseInt(strDate.substr(strDate.lastIndexOf('/') + 1, 4), 10);
//alert(4);
// if (isNaN(nYear))
// throw mtCreateException('Invalid date (year): please enter in form mm/dd/yyyy');
//alert(5);
// // Check for 2 digit year.
// if (nYear < 100) {
// if (nYear >= 50)
// nYear += 1900;
// else
// nYear += 2000;
// }
//
// if (nYear < minYear || nYear > maxYear)
// throw mtCreateException('Invalid date: the year is out of range.');
//
// if (nMonth > 12 || nMonth < 1 || nDay > mtGetDaysInMonth(nMonth, nYear) || nDay < 1)
// throw mtCreateException('Invalid month and/or day.');
// else
// strDate = mtZeroPad(nMonth, 2) + '/' + mtZeroPad(nDay, 2) + '/' + nYear;
return strDate;
} // mtStandardizeDate
// Return date in a H:MM:SS AM/PM format or throw an exception if the date is not valid.
function mtStandardizeTime(strStd, bAllowBlank) {
if (bAllowBlank == null)
bAllowBlank = true;
// Standardize the format.
strStd = Trim(strStd).replace(/\s/g, ":");
strStd = strStd.replace(/\:*(A|P)/i, " $1");
strStd = strStd.replace(/\0|\t|\r|\n/g, "");
//alert("mtStandardizeTime 1: [" + strStd + "]");
if (strStd == "") {
if (bAllowBlank)
return "";
else
throw mtCreateException('Invalid time: can not be blank.');
}
var dt = new Date("1/1/2000 " + strStd);
//alert("mtStandardizeTime 2: [" + dt.toString() + "]");
// if (isNaN(dt))
// throw mtCreateException('Invalid time: please enter in form HH:MM:SS AM/PM or in a 24 hour format.');
var hour = dt.getHours();
if (isNaN(hour))
throw mtCreateException('Invalid time: please enter in form HH:MM:SS AM/PM or in a 24 hour format.');
var minute = dt.getMinutes();
var second = dt.getSeconds();
var ampm;
if (hour < 12)
ampm = "AM";
else {
ampm = "PM";
hour -= 12;
}
return hour + ":" + mtLeftPad(minute, 2, "0") + ":" + mtLeftPad(second, 2, "0") + " " + ampm;
} // mtStandardizeTime
// Return date in a MM/DD/YYYY H:MM:SS AM/PM format or throw an exception if the date is not valid.
function mtStandardizeDateTime(strStd, bAllowBlank) {
//alert("mtStandardizeDateTime 0: [" + strStd + "]");
var minYear=1900;
var maxYear=2100;
if (bAllowBlank == null)
bAllowBlank = true;
// Standardize the format.
strStd = strStd.replace(/-|\\|\./g, "/");
strStd = Trim(strStd.replace(/\0|\t|\r|\n/g, ""));
//alert("mtStandardizeDateTime 1: [" + strStd + "]");
if (strStd == "" && bAllowBlank)
return "";
//alert("mtStandardizeDateTime 2: [" + strStd + "]");
var sDate;
var sTime;
// Split up the date and time.
var arrMatches = strStd.match(/^([^\/]{1,3}\/[^\/]{1,3}(?:\/\d+)?)\s*(.*)$/);
//alert("mtStandardizeDateTime length: [" + arrMatches.length + "]");
if (arrMatches.length < 2)
throw mtCreateException("Invalid date/time. Please enter in form mm/dd/yyyy hh:mm:ss AM/PM")
else if (arrMatches.length == 2 || (arrMatches.length == 3 && arrMatches[2] == "")) {
//alert("mtStandardizeDateTime 3: [" + arrMatches[1] + "]");
sDate = mtStandardizeDate(arrMatches[1], bAllowBlank);
sTime = "12:00:00 AM"
}
else {
//alert("mtStandardizeDateTime 4: [" + arrMatches[1] + "]");
//alert("mtStandardizeDateTime 5: [" + arrMatches[2] + "]");
sDate = mtStandardizeDate(arrMatches[1], bAllowBlank);
sTime = mtStandardizeTime(arrMatches[2], bAllowBlank);
}
return sDate + " " + sTime;
} // mtStandardizeDateTime
// Converts a string to a number, else returns 0.
function mtParseNumericValue(sVal) {
sVal = sVal.replace(/\$|,|\s/g, "");
if (sVal == "")
return 0;
else {
if (sVal.search(/(^\d+$)|(^\d*\.\d*$)/) == -1)
return 0;
else
return new Number(sVal);
}
} // mtParseNumericValue
function StandardizeUrl(str, protocol) {
if (protocol == null)
protocol = "";
// Standardize the protocol.
protocol = Trim(protocol).replace(/:\/?\/?/, "");
// Allow user to specify a blank protocol.
protocol = (protocol.length == 0) ? "" : protocol + "://";
// Strip off any protocol from the URL.
str = Trim(str).replace(/\\/g, "/");
str = str.replace(/^https?/, "");
str = str.replace(/^:\/?\/?/, "");
return protocol + str;
} // StandardizeUrl
function StandardizeCreditCard(str) {
// If blank then don't check any further.
str = Trim(str);
if (str == "")
return "";
// Remove anything but numbers, spaces, and dashes.
str = str.replace(/[^\d \-]+/g, "");
// Remove leading and trailing spaces and dashes.
str = str.replace(/^(\s|\-)+/, "");
str = str.replace(/(\s|\-)+$/, "");
// Remove any multiple dash sequences.
str = str.replace(/(\s*\-\s*)+/g, "-");
// Remove any multiple space sequences.
str = str.replace(/\s+/g, " ");
// Work off of a copy since we don't want to modify their format if they used spaces or dashes between numbers.
var cc = str;
cc = cc.replace(/[^\d]+/g, "");
var len = cc.length; // The length of the submitted cc number
if (len < 13)
throw mtCreateException("Card number is invalid.")
var iCCN = parseInt(cc); // integer of cc number
var sCCN = cc.toString(); // string of cc number
var iTotal = 0; // integer total set at zero
// var bResult = false; // by default assume it is NOT a valid cc
var temp; // temp variable for parsing string
var calc; // used for calculation of each digit
var iPrefix = parseInt(cc.substr(0, 4));
// Do some quick checks.
if (iPrefix >= 4000 && iPrefix <= 4999) {
if (len != 16) // no longer have 13 digit cards.
throw mtCreateException("Card number is invalid for VISA.")
}
else if (iPrefix >= 5100 && iPrefix <= 5599) {
if (len != 16)
throw mtCreateException("Card number is invalid for MasterCard.")
}
else if (iPrefix == 2149 || (iPrefix >= 3060 && iPrefix <= 3399) || (iPrefix >= 3700 && iPrefix <= 3799)) {
if (len != 15)
throw mtCreateException("Card number is invalid for AMEX.")
}
else if (iPrefix == 6011 || (iPrefix >= 6221 && iPrefix <= 6229) || (iPrefix >= 6440 && iPrefix <= 6499) || (iPrefix >= 6500 && iPrefix <= 6599)) {
if (len != 16)
throw mtCreateException("Card number is invalid for Discover.")
}
else if (iPrefix >= 3528 && iPrefix <= 3589) {
if (len != 16)
throw mtCreateException("Card number is invalid for JCB.")
}
else if (iPrefix == 5602 || iPrefix == 5610) {
if (len != 16)
throw mtCreateException("Card number is invalid for Bankcard.")
}
else if ((iPrefix >= 3000 && iPrefix <= 3059) || (iPrefix >= 3600 && iPrefix <= 3699)) {
if (len != 14)
throw mtCreateException("Card number is invalid for Dinners Club Cart Blanche / International.")
}
else if (iPrefix == 1800 || iPrefix == 2014 || iPrefix == 2149) {
if (len != 15)
throw mtCreateException("Card number is invalid for Dinners Club enRoute.")
}
else
throw mtCreateException("Unsupported card type for prefix " + iPrefix)
if (iPrefix != 1800 && iPrefix != 2014 && iPrefix != 2149) { // Diners Club enRoute doesn't use Mod 10 / Luhn validation - or any validation.
for (var i=len; i>0; i--) { // LOOP throught the digits of the card
calc = parseInt(iCCN) % 10; // right most digit
calc = parseInt(calc); // assure it is an integer
iTotal += calc; // running total of the card number as we loop - Do Nothing to first digit
i--; // decrement the count - move to the next digit in the card
iCCN = iCCN / 10; // subtracts right most digit from cc
calc = parseInt(iCCN) % 10 ; // NEXT right most digit
calc = calc * 2; // multiply the digit by two
// Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
// I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
switch (calc){
case 10: calc = 1; break; //5*2=10 & 1+0 = 1
case 12: calc = 3; break; //6*2=12 & 1+2 = 3
case 14: calc = 5; break; //7*2=14 & 1+4 = 5
case 16: calc = 7; break; //8*2=16 & 1+6 = 7
case 18: calc = 9; break; //9*2=18 & 1+8 = 9
default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers
}
iCCN = iCCN / 10; // subtracts right most digit from ccNum
iTotal += calc; // running total of the card number as we loop
} // END OF LOOP
if ((iTotal % 10) != 0) // check to see if the sum Mod 10 is zero
throw mtCreateException("Invalid credit card number.")
} // if len
return str;
} // StandardizeCreditCard
function mtBuildOptionsFromArray(oSelect, arr, initialVal, emptyText, bDeleteOptions) {
if (oSelect == null || arr == null) {
//alert("BuildDropDownFromArray 0");
return oSelect;
}
if (emptyText == null)
emptyText = "None";
if (bDeleteOptions == null)
bDeleteOptions = true;
// Clear out existing options.
if (bDeleteOptions == true) {
while (oSelect.length > 0)
oSelect.remove(0);
}
// Add in a default selection.
if (arr.length == 0) {
arr.push(new Object());
arr[0].text = emptyText;
arr[0].value = "";
}
var bSelected = false;
for (var i = 0; i < arr.length; i++) {
var oOption = mtCreateElement("OPTION");
oSelect.appendChild(oOption);
//alert("BuildDropDownFromArray 3");
oOption.value = arr[i]["value"];
//alert("BuildDropDownFromArray 4");
if (bSelected == false && (arr.length == 1 || oOption.value == initialVal)) {
oOption.selected = true;
bSelected = true;
//alert("BuildDropDownFromArray 5");
}
// For whatever reason this has to be done after the appendChild.
oOption.text = arr[i]["text"];
//alert("BuildDropDownFromArray 6");
}
//alert("BuildDropDownFromArray 7");
return oSelect;
} // mtBuildOptionsFromArray
function InitRadio(rbtn, val) {
var i;
if (rbtn != null) {
// if ( val != '' ) {
if (rbtn.length == null || rbtn.length == 1) {
rbtn.checked = ( rbtn.value == val );
}
else {
for (i = 0; i < rbtn.length; i++)
rbtn[i].checked = ( rbtn[i].value == val );
}
// }
}
}
function RadioValue(rbtn) {
if (rbtn != null) {
if (rbtn.length == null || rbtn.length == 1) {
if (rbtn.checked)
return rbtn.value;
}
else {
for (var i = 0; i < rbtn.length; i++) {
if (rbtn[i].checked)
return rbtn[i].value;
}
}
}
return "";
} // RadioValue
function InitCheckBox(chkBox, val) {
var i;
if (chkBox.length == null)
chkBox.checked = (chkBox.value == val);
else {
for (i = 0; i < chkBox.length; i++)
chkBox[i].checked = (chkBox[i].value == val);
}
} // InitCheckBox
function CheckBoxValue(chkBox) {
if (chkBox != null) {
if (chkBox.checked)
return chkBox.value;
else if (chkBox.getAttribute("unvalue") != null) // if they set an unvalue attribute return that when not checked.
return chkBox.getAttribute("unvalue");
}
return "";
} // CheckBoxValue
function InitDropDown(dropdown, val) {
var i;
for (i = 0; i < dropdown.options.length; i++) {
if (dropdown.options[i].value == val) {
dropdown.selectedIndex = i;
return true;
}
}
return false;
} // InitDropDown
function DropDownValue(dropdown) {
if (dropdown != null && dropdown.selectedIndex >= 0) {
return dropdown.options[dropdown.selectedIndex].value;
}
return "";
} // DropDownValue
function ShowObject(htmlObj, iIndex) {
var obj = htmlObj;
// If a name or ID was passed it then get the actual object reference.
if (typeof(obj) == "string") {
obj = GetObject(obj, iIndex);
}
if (obj == null)
return false;
if (document.getElementById || document.all) {
obj.style.visibility = 'visible';
obj.style.display = '';
}
else if (document.layers) {
obj.visibility = 'visible';
}
return true;
} // ShowObject
function HideObject(htmlObj, iIndex) {
var obj = htmlObj;
// If a name or ID was passed it then get the actual object reference.
if (typeof(obj) == "string") {
obj = GetObject(obj, iIndex);
}
if (obj == null)
return false;
if (document.getElementById || document.all) {
obj.style.visibility = 'hidden';
obj.style.display = 'none';
}
else if (document.layers) {
obj.visibility = 'hidden';
}
return true;
} // HideObject
function IsVisible(htmlObj, iIndex) {
var obj = htmlObj;
// If a name or ID was passed it then get the actual object reference.
if (typeof(obj) == "string") {
obj = GetObject(obj, iIndex);
}
if (obj == null) {
return false;
}
if (document.getElementById != null || document.all != null) {
return obj.style.visibility != 'hidden' && obj.style.display != 'none';
}
else if (document.layers && document.layers[htmlObj]) {
return obj.visibility != 'hidden';
}
return true;
} // IsVisible
// Pass in a name or an ID and it will return the object, or null if not found.
function GetObject(sName, iIndex) {
var obj = null;
if (document.getElementById != null) {
obj = document.getElementById(sName);
//alert("GO 1 obj = " + obj.selectedIndex);
if (obj == null)
obj = document.getElementsByName(sName);
//alert("GO 2 obj = " + obj);
}
else if (document.layers != null && document.layers[sName] != null) {
obj = document.layers[sName];
}
else if (document.all != null) {
obj = document.all[sName];
}
// Get the indexed item if an index was passed in.
if (obj != null && obj.length != null && obj.length > 1) {
//alert("GO 3 obj = " + obj.selectedIndex);
if (iIndex == null)
obj = obj[0];
else
obj = obj[iIndex];
//alert("GO 4 obj = " + obj.selectedIndex);
}
return obj;
} // GetObject
// returns just the file name (including the extension).
function ExtractFileName(path) {
var pathSep, pos, pageName;
if ( path.indexOf( 'file://' ) >= 0 )
pathSep = '\\';
else
pathSep = '/';
pos = path.lastIndexOf( pathSep );
if ( pos == -1 )
pageName = path.substr(0);
else
pageName = path.substr(pos + 1);
return pageName;
}
// Returns ONLY the page name part - NO extension.
function ExtractPageName(path) {
var pathSep, pos, page, pageName;
pageName = ExtractFileName(path);
pageName = pageName.substring(0, pageName.indexOf( '.' ) );
return pageName;
}
function OpenVerse( vs ) {
var w = window.open('http://bible.gospelcom.net/cgi-bin/bible?passage=' + vs + '&version=NIV&showfn=yes&showxref=no&language=english', 'verse', "resizable=yes,scrollbars=yes,menubar=yes,location=yes,status=yes,toolbar=yes,left=0,screenX=0,top=0,screenY=0");
w.focus();
}
function OpenInfoWindow(url, winWidth, winHeigth, winName) {
// Check if there is a cookie to disable this popup.
if (GetCookie(url) == "") {
if (winName == null)
winName = "infoWin";
var w = window.open(url, winName, "width=" + winWidth + ",height=" + winHeigth + ",resizable=yes,scrollbars=yes,menubar=no,location=no,status=no,toolbar=no,left=0,screenX=0,top=0,screenY=0");
w.focus();
}
return void(0);
}
function GetCookie(name) {
return decodeURIComponent(GetPairValue(document.cookie, name));
} // GetCookie
// Expires is in number of days. 0 means never expire.
function SetCookie(name, value, expires, path, domain, secure) {
if (!navigator.cookieEnabled)
alert("Your browser does not allow cookies to be set, this info can not be saved.");
var sCookie = name + "=" + encodeURIComponent(value);
// Check if the cookie is being removed.
if (value == "")
sCookie += "; max-age=0";
else {
if (expires) {
// convert to milliseconds
expires = expires * 24 * 60 * 60 * 1000;
var dtExpire = new Date();
if (expires == 0)
dtExpire.setFullYear(dtExpire.getFullYear() + 50);
else
dtExpire.setTime(dtExpire.getTime() + expires);
sCookie += ";expires=" + dtExpire.toGMTString();
}
if (path)
sCookie += ";path=" + path;
if (domain)
sCookie += ";domain=" + domain;
if (secure)
sCookie += ";secure=true";
}
//alert("setCookie = " + sCookie);
document.cookie = sCookie;
} // SetCookie
function GetPairValue(pairs, name) {
var value = "";
var pos = pairs.indexOf(name + "=");
if (pos != -1) {
var start = pos + name.length + 1;
var end = pairs.indexOf(";", start);
if (end == -1)
end = pairs.length;
value = pairs.substring(start, end);
}
return value;
} // GetPairValue
// Synchronous AJAX – will return the text of the reply.
function Ajax(a_sURL, a_sPostData) {
return mtAjaxEx(a_sURL, a_sPostData, "", "sync");
} // Ajax
// Will return an object (not text) or null if the reply is blank.
function mtAjaxJson(a_sURL, a_sPostData) {
var sData = "";
try {
//throw mtCreateException("test exception: dude's gonna blow \\ up \n newline");
//throw mtCreateException("test exception");
sData = mtAjaxEx(a_sURL, a_sPostData, "", "sync");
/*
sData = "( {" + "\r\n" +
"'errorList': [ ]," + "\r\n" +
"'warningList': [ ]," + "\r\n" +
"'infoList': [ ]" + "\r\n" +
"} )" + "\r\n";
*/
if (Trim(sData) == "")
return null;
else
return eval(sData);
}
catch (e) {
alert(e.message);
}
return null;
} // mtAjaxJson
// Will return an XML document based on the return data.
function mtAjaxXml(a_sURL, a_sPostData) {
var sData = "";
try {
sData = mtAjaxEx(a_sURL, a_sPostData, "", "sync");
return mtCreateXmlDoc(sData);
}
catch (e) {
alert(e.message);
}
return null;
} // mtAjaxXml
// Returns immediately so the return value will generally be blank.
function mtAjaxAsync(a_sURL, a_sPostData) {
return mtAjaxEx(a_sURL, a_sPostData, "", "async", 0);
} // mtAjaxAsync
function mtAjaxEx(a_sURL, a_sPostData, a_sContentType, a_sSyncType, a_iWait) {
if (a_sPostData == null)
a_sPostData = "";
if (a_sContentType == null)
a_sContentType = "";
if (a_sSyncType == null)
a_sSyncType = "sync";
if (a_iWait == null)
a_iWait = 0;
//alert("ajax 1");
var xmlHttp = null;
try {
//alert("ajax 2");
xmlHttp = new XMLHttpRequest();
}
catch (e) {
try {
//alert("ajax 3");
xmlHttp = new ActiveXObject("Msxml2.XMLHttp");
}
catch (e2) {
try {
//alert("ajax 4");
xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
}
catch (e3) {
//alert("ajax 5");
xmlHttp = null;
}
}
}
//alert(1);
var sResponse = "";
if (xmlHttp == null)
throw mtCreateException("Unable to create HTTP object.");
else {
var bAsync = a_sSyncType.toLowerCase() == "async";
//alert(2);
// This method is valid for some clients (checks below if not null). (lResolve (def 0 - infinite), lConnect (def 60000), lSend (def 30000), lReceive (def 30000))
// With a lot of servers buffering their responses give the Receive a little longer.
if (xmlHttp.setTimeouts != null) {
if (a_iWait != 0)
xmlHttp.setTimeouts(30000, 60000, 30000, (a_iWait * 1000) + 1000);
else
xmlHttp.setTimeouts(30000, 60000, 30000, 600000);
}
try {
if (a_sPostData == "")
xmlHttp.open("GET", a_sURL, bAsync);
else
xmlHttp.open("POST", a_sURL, bAsync);
}
catch (e) {
throw mtCreateException("HTTP Status 404: Page Not Found");
}
//alert(3);
// If we are posting data then a content type needs to be included.
if (a_sPostData != "") {
if (a_sContentType == "") {
// This is the default HTTP post type.
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}
else {
// Allow caller to provide their own content type.
xmlHttp.setRequestHeader("Content-Type", a_sContentType);
}
}
//alert(xmlHttp.waitForResponse);
//alert("about to post to: " + a_sURL);
xmlHttp.send(a_sPostData);
//alert(5);
if (bAsync == true) {
// NOTE: waitForResponse is NOT globally supported in the client-side HTTP component. It checks below to see if it is available.
// See if we are supposed to wait after firing off the request. (only available in IE).
if (a_iWait != 0 && xmlHttp.waitForResponse != null) {
// If this returns true then the response came back and this will be treated as a synchronous request.
if (xmlHttp.waitForResponse(a_iWait) == true) // -1 would be infinite
bAsync = false;
}
}
// Check again, see if it changed above.
if (bAsync == true)
xmlHttp = null;
else {
var sStatus = xmlHttp.status;
//alert("status returned: " + sStatus);
var sStatusText = xmlHttp.statusText;
sResponse = xmlHttp.responseText;
//alert("response returned: " + sResponse);
xmlHttp = null;
//alert(6);
// Log a warning so we have an idea what is going on.
if (sStatus == "403") {
// Make sure not to get stuck in an infinite loop since the logging function calls this function.
if (a_sURL.toLowerCase().indexOf(C_EVENT_LOG_ERROR_URL.toLowerCase()) == -1) {
mtLogClientSecurity("AJAX call to page [" + a_sURL + "] failed with 403 security error.", "inc-javascript.asp");
}
}
if (sStatus != "200") {
throw mtCreateException("HTTP Status " + sStatus + ": " + sStatusText);
}
}
}
return sResponse;
} // mtAjaxEx
function mtHtmlDecode(str) {
var oStr = new String(str);
return oStr.replace(/"/g, '"').replace(/'/g, "'").replace(/
/g, "\r").replace(/
/g, "\n");
} // mtHtmlDecode
function mtHandleJsonReturnMessages(oReturn) {
if (oReturn == null) {
alert("A communications or server error might have occurred, please try again.");
return false;
}
else {
var sMsg = "";
var bRetVal = true;
for (var j = 0; j < oReturn.errorList.length; j++) {
sMsg += "Error: " + oReturn.errorList[j].message + "\n";
}
if (sMsg != "") {
alert(sMsg);
bRetVal = false;
}
// They can continue with warnings.
sMsg = "";
for (var j = 0; j < oReturn.warningList.length; j++) {
sMsg += "Notice: " + oReturn.warningList[j].message + "\n";
}
if (sMsg != "" && bRetVal == true && window.confirm(sMsg + "\nWould you like to continue anyhow?") == false) {
bRetVal = false;
}
// This is just for any debug messages.
sMsg = "";
for (var j = 0; j < oReturn.infoList.length; j++) {
sMsg += "INFO: " + oReturn.infoList[j].message + "\n";
}
if (sMsg != "") {
alert(sMsg);
}
}
return bRetVal;
} // mtHandleJsonReturnMessages