function IsBlank(p_strFormName, p_strFieldName, p_strErrorMessage) { var objFormField = eval("document." + p_strFormName + "." + p_strFieldName); if (objFormField != null) { if (Trim(objFormField.value) == "") { return "\n - " + p_strErrorMessage; } else { return ""; } } } function IsNoValue(p_strFormName, p_strFieldName, p_strErrorMessage) { var objFormField = eval("document." + p_strFormName + "." + p_strFieldName); if (objFormField != null) { if (Trim(objFormField.value) == "" || Trim(objFormField.value) == "0") { return "\n - " + p_strErrorMessage; } else { return ""; } } } function IsAlphabetic(p_strFormName, p_strFieldName, p_strErrorMessage) { var objFormField = eval("document." + p_strFormName + "." + p_strFieldName); if (objFormField != null) { var strValue = new String(Trim(objFormField.value)); if (strValue.search(/[^A-Z\.\s]/gi) != -1) { return "\n - " + p_strErrorMessage; } else { return ""; } } } function IsAlphaNumeric(p_strFormName, p_strFieldName, p_strErrorMessage) { var objFormField = eval("document." + p_strFormName + "." + p_strFieldName); if (objFormField != null) { var strValue = new String(Trim(objFormField.value)); if (strValue.search(/[^A-Z0-9\.\s]/gi) != -1) { return "\n - " + p_strErrorMessage; } else { return ""; } } } function IsNumeric(p_strFormName, p_strFieldName, p_strErrorMessage) { var objFormField = eval("document." + p_strFormName + "." + p_strFieldName); if (objFormField != null) { var strValue = new String(Trim(objFormField.value)); if (strValue.search(/[^0-9\.\s]/gi) != -1) { return "\n - " + p_strErrorMessage; } else { return ""; } } } function IsEmail(p_strFormName, p_strFieldName, p_strErrorMessage) { var objFormField = eval("document." + p_strFormName + "." + p_strFieldName); if (objFormField != null) { var strValue = new String(Trim(objFormField.value)); if (strValue.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/gi) == -1) { return "\n - " + p_strErrorMessage; } else { return ""; } } } function IsURL(p_strFormName, p_strFieldName, p_strErrorMessage) { var objFormField = eval("document." + p_strFormName + "." + p_strFieldName); if (objFormField != null) { var strValue = new String(Trim(objFormField.value)); if (strValue.search(/^(ftp|http|https)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/gi) == -1) { return "\n - " + p_strErrorMessage; } else { return ""; } } } function IsValidFile(p_strFormName, p_strFieldName, p_strFileList, p_strErrorMessage) { var objFormField = eval("document." + p_strFormName + "." + p_strFieldName); if (objFormField != null) { var strValue = new String(Trim(objFormField.value)); if (strValue.search(eval("/\.(" + p_strFileList + ")$/gi")) == -1) { return "\n - " + p_strErrorMessage; } else { return ""; } } } function IsDate(p_strFormName, p_strYearFieldName, p_strMonthFieldName, p_strDayFieldName, p_strErrorMessage) { var objFormYearField = eval("document." + p_strFormName + "." + p_strYearFieldName); var objFormMonthField = eval("document." + p_strFormName + "." + p_strMonthFieldName); var objFormDayField = eval("document." + p_strFormName + "." + p_strDayFieldName); if (objFormYearField != null && objFormMonthField != null && objFormDayField != null) { var dtNewDate = new Date(); dtNewDate.setFullYear(objFormYearField.value); dtNewDate.setMonth(objFormMonthField.value - 1); dtNewDate.setDate(objFormDayField.value); if (dtNewDate.getFullYear() != objFormYearField.value || dtNewDate.getMonth() != objFormMonthField.value - 1 || dtNewDate.getDate() != objFormDayField.value) { return "\n - " + p_strErrorMessage; } else { return ""; } } } function Sum(p_argArguments) { if (Sum.arguments.length > 0) { var dSum = 0; for (var i = 0; i < Sum.arguments.length; i++) { if (isNaN(parseFloat(Sum.arguments[i])) == false) { dSum += parseFloat(Sum.arguments[i]); } } return dSum; } else { return 0; } } function ArraySum(p_arrValues) { if (p_arrValues.length > 0) { var dSum = 0; for (var i = 0; i < p_arrValues.length; i++) { if (isNaN(parseFloat(p_arrValues[i].value)) == false) { dSum += parseFloat(p_arrValues[i].value); } } return dSum; } else { return 0; } } function Average(p_argArguments) { if (Average.arguments.length > 0) { var dAverage = 0; var iValues = 0; for (var i = 0; i < Average.arguments.length; i++) { if (isNaN(parseFloat(Average.arguments[i])) == false) { dAverage += parseFloat(Average.arguments[i]); iValues++; } } return parseFloat(dAverage / iValues); } else { return 0; } } function ArrayAverage(p_arrValues) { if (p_arrValues.length > 0) { var dAverage = 0; var iValues = 0; for (var i = 0; i < p_arrValues.length; i++) { if (isNaN(parseFloat(p_arrValues[i].value)) == false) { dAverage += parseFloat(p_arrValues[i].value); iValues++; } } return parseFloat(dAverage / iValues); } else { return 0; } } function InputInteger() { if (window.event.keyCode >= 48 && window.event.keyCode <= 57) { return true; } else { return false; } } function InputFloat(evt) { var intKeyCode = (evt.which) ? evt.which : event.keyCode if (intKeyCode == 46 || (intKeyCode >= 48 && intKeyCode <= 57)) { //if (intKeyCode == 46) { // if (window.event.srcElement.value.indexOf(".") != -1) { // return false; // } else { // return true; // } //} else { return true; //} } else { return false; } } function FormatNumber(p_strValue, p_intDecimalPlaces) { if (Trim(p_strValue) != "") { if (isNaN(parseFloat(p_strValue)) != true) { var strTempValue = new String(); strTempValue = (Math.ceil(parseFloat(p_strValue) * Math.pow(10, p_intDecimalPlaces))).toString(); if (strTempValue.length < ((Math.pow(10, p_intDecimalPlaces)).toString()).length) { strTempValue = "0." + Replicate("0", p_intDecimalPlaces - strTempValue.length) + strTempValue; } else { strTempValue = strTempValue.substr(0, strTempValue.length - p_intDecimalPlaces) + "." + strTempValue.substr(strTempValue.length - p_intDecimalPlaces, p_intDecimalPlaces); } return strTempValue; } else { return 0; } } else { return 0; } } function Replicate(p_strValue, p_intReplications) { var strTempValue = ""; if (isNaN(parseInt(p_intReplications)) != true) { for (var i = 0; i < p_intReplications; i++) { strTempValue += p_strValue; } } return strTempValue; } function Trim(p_strValue) { var strValue = new String(p_strValue); strValue = strValue.replace(/^\s+/gi, ""); strValue = strValue.replace(/\s+$/gi, ""); return strValue; } function GetElementByFormName(p_strFormName, p_strFieldName) { var objFormControl = eval("document." + p_strFormName + "." + p_strFieldName); return objFormControl; } // Admin functions... function RevealFieldNames() { if (document.forms.length > 0) { for (var i = 0; i < document.forms.length; i++) { if (document.forms[i].elements.length > 0) { for (var j = 0; j < document.forms[i].elements.length; j++) { if (document.forms[i].elements[j].type == "text") { document.forms[i].elements[j].value = document.forms[i].elements[j].name; } } } } } } function formatCurrency(num) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + num + '.' + cents); }