// Global Variables var i = 1; var n = 1; var digits = "0123456789"; var defaultEmptyOK = false // whitespace characters var whitespace = " \t\n\r"; // ---------- Validation messages ------------- // Validation messages var requiredPrefix = "Не внесовте вредност во" var requiredSuffix = "полето.Ова е задолжително поле. Ве молиме внесете вредност." var requiredEmailPrefix = "Внесовте невалидна email адреса во" var requiredEmailSuffix = "полето. Мора да биде валидна (пр. avon@avon.com).Ве молиме внесете ја повторно." var requiredEmailAreaPrefix = "E-mail адресата" var requiredEmailAreaSuffix = "е невалидна. Мора да биде валидна (пр. avon@avon.com).Ве молиме внесете ја повторно." var requiredCheckboxPrefix = "Не го штиклиравте " var requiredCheckboxSuffix = "полето. Ова е задолжително поле. Ве молиме штиклирајте го, инаку формуларот нема да се прати." var requiredMaxSizePrefix = "Вредноста која ја внесовте во" var requiredMaxSizeMiddle= "полето е поголема од макслималната должина. Ве молиме внесете помалку од" var requiredMaxSizeSuffix = "карактери." var requiredEmailMaxSizePrefix = "E-mail адресата" var requiredEmailMaxSizeMiddle= " е предолга. Максимална должина на e-mail адреса е" var requiredEmailMaxSizeSuffix = "." var requiredRadioButtonPrefix = "Не го селектиравте" var requiredRadioButtonSuffix = "опционото копче. Ова е задолжително поле. Ве молиме селектирајте го." var requiredRadioButton = "Не селектиравте опционо копче. Ова е задолжително поле. Ве молиме селектирајте го." var errorRadioButtonYes = "" var minSizePrefix="Полето" var minSizeMiddle="мора да содржи минимум" var minSizeSuffix=" карактери. Ве молиме обидете се повторно." // Numeric fields var invalidNumericStringPrefix = "Не внесовте валидна бројчана вредност во" var invalidNumericStringSuffix = "полето. Полето може да се пополни само со бројки(0123456789)." // Alphabetic fields var invalidAlphaStringPrefix = "Не внесовте валидна карактерна вредност во" var invalidAlphaStringSuffix = "полето. Полето може да се пополни само со букви." // Date messages var iDatePrefix = "Ден, Месец и Година за " var iDateSuffix = " не формиравте правилна дата. Ве молиме внесете повторно." var dateFormatPrefix = "\nНевалиден формат на Дата" var dateFormat = "dd.MM.yyyy" var InvalidDay = "\nНевалиден Ден.\nВе молиме внесете ден." var InvalidMonth = "\nНевалиден Месец.\nВе молиме внесете Месец." var InvalidYear = "\nНевалидна Година.\nВе молиме внесете Година во формат XXXX." // non-digit characters which are allowed in phone numbers var phoneNumberDelimiters = "()- " // characters which are allowed in international phone numbers // (a leading + is OK) var validWorldPhoneChars = digits + phoneNumberDelimiters + "+"; // non-digit characters which are allowed in ZIP Codes var ZIPCodeDelimiters = "-" // Extra messages for local SK functions var requiredCardMessage = "Не одбравте картичка. Ова е задолжително поле. Ве молиме селектирајте една." /* FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. */ // Notify user that required field theField is empty. // String cur describes expected contents of theField.value. // Put focus in theField and return false. function warnEmpty (theField, cur) { theField.focus(); alert(requiredPrefix + cur + requiredSuffix); return false; } // Notify user that contents of field theField are invalid. // String c describes expected contents of theField.value. // Select theField, put focus in it, and return false. function warnInvalid (theField, cur) { theField.focus(); theField.select(); alert(requiredEmailPrefix + cur + requiredEmailSuffix); return false; } function warnInvalidEmailArea (theField, cur) { theField.focus(); theField.select(); alert(requiredEmailAreaPrefix + cur + requiredEmailAreaSuffix); return false; } // Email Area function warnInvalidMaxSize (theField, cur, maxsize) { theField.focus(); theField.select(); alert(requiredEmailMaxSizePrefix + cur + requiredEmailMaxSizeMiddle + maxsize + requiredEmailMaxSizeSuffix); return false; } // Numbers function warnInvalidNumericString (theField, cur) { theField.focus(); theField.select(); alert(invalidNumericStringPrefix + cur + invalidNumericStringSuffix); return false; } // Alphabetic function warnInvalidAlphaString (theField, cur) { theField.focus(); theField.select(); alert(invalidAlphaStringPrefix + cur + invalidAlphaStringSuffix); return false; } // DateFormat function warnInvalidDateFormat (theField, cur) { theField.focus(); theField.select(); alert(cur + ": " + dateFormatPrefix + dateFormat); return false; } // Day function warnInvalidDay (theField, cur) { theField.focus(); theField.select(); alert(cur + ": " + InvalidDay); return false; } // Month function warnInvalidMonth (theField, cur) { theField.focus(); theField.select(); alert(cur + ": " + InvalidMonth); return false; } // Year function warnInvalidYear (theField, cur) { theField.focus(); theField.select(); alert(cur + ": " + InvalidYear); return false; } // Check whether string cur is empty. function isEmpty(cur) { return ((cur == null) || (cur.length == 0)); } function ConverttoUpper(cur) { cur.value = cur.value.toUpperCase(); } // ---------------- Clear String Whitespace --------------- // Removes all characters which appear in string bag from string s. function stripCharsInBag (s, bag) { var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } // Removes all trailing characters which appear in string bag from string s. function stripTrailingWhitespace (s, bag) { var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += " " + c; } return returnString.substring(1); } // Removes all trailing characters which appear in string bag from string s. function stripLeadingAndTrailingWhitespace (s, bag) { var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. var start = -1; var end = -1; for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (bag.indexOf(c) == -1) end = i; } for (i = s.length; i >= 0; i--) { // Check that current character isn't whitespace. var c = s.charAt(i); if (bag.indexOf(c) == -1) start = i; } if (start == -1 && end == -1) return returnString; return s.slice(start, end +1); } // Removes all whitespace characters from s. // Global variable whitespace (see above) // defines which characters are considered whitespace. function stripWhitespaceEmail (s) { return stripLeadingAndTrailingWhitespace (s, whitespace) } function isWhitespace (cur) { var i; // Is cur empty? if (isEmpty(cur)) return true; // Search through string's characters one by one // until we find a non-whitespace character. // When we do, return false; if we don't, return true. for (i = 0; i < cur.length; i++) { // Check that current character isn't whitespace. var c = cur.charAt(i); if (whitespace.indexOf(c) == -1) return false; } // All characters are whitespace. return true; } function isWhitespaceEmail (cur) { var i; // Is cur empty? if (isEmpty(cur)) return true; // Search through string's characters one by one // until we find a whitespace character. // When we do, return true for (i = 0; i < cur.length; i++) { // Check that current character isn't whitespace. var c = cur.charAt(i); if (whitespace.indexOf(c) == 0) { return true; } } // No characters are whitespace. return false; } var testresults function isEmail(s){ var str = stripWhitespaceEmail(s); var filter=/^((\w|\-)+(?:(\.|\')(\w|\-)+)*)@((?:\w+(\.))*\w[\w-]{0,66})\.([a-z]{2,3}(?:\.[a-z]{2})?)$/i if (filter.test(str)) testresults=true else{ testresults=false } return (testresults) } function checkString (theField, cur, emptyOK) { // Next line may be needed on to avoid "undefined is not a number" error // in equality comparison below. if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK; if ((emptyOK == true) && (isEmpty(theField.value))) return true; if (isWhitespace(theField.value)) return warnEmpty (theField, cur); else return true; } function checkEmail (theField, cur, emptyOK) { if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK; theField.value = stripWhitespaceEmail(theField.value); if ((emptyOK == true) && (isEmpty(theField.value))) return true; else if (!isEmail(theField.value)) return warnInvalid (theField, cur); else return true; } function checkAreaEmail (theField, cur, emptyOK, maxlength) { if (checkAreaEmail.arguments.length == 1) emptyOK = defaultEmptyOK; if ((emptyOK == true) && (isEmpty(theField.value))) return true; else { var number = 1; var temp = theField.value; var second = temp.indexOf(','); while (second != -1) { var email = temp.substring(0, second); email = stripWhitespaceEmail(email); if (email != "") { if (email.length > maxlength) return warnInvalidMaxSize (theField, email, maxlength); if (!isEmail(email)) return warnInvalidEmailArea (theField, email); } temp = temp.substring(second+1, temp.length); second = temp.indexOf(','); number++; } temp = stripWhitespaceEmail(temp); if (temp != "") { if (temp.length > maxlength) return warnInvalidMaxSize (theField, temp, maxlength); if (!isEmail(temp)) return warnInvalidEmailArea (theField, temp); } return true; } } // Check that checkbox is checked function isChecked (theField, cur) { if (theField.checked) { return true; } alert(requiredCheckboxPrefix + cur + requiredCheckboxSuffix) return false; } // Check that radio button is checked function isRadioChecked (theField, cur) { for (var i = 0; i < theField.length; i++) { if (theField[i].checked) { return true; } } alert(requiredRadioButtonPrefix + cur + requiredRadioButtonSuffix) return false; } // Check that radio button is checked function isRadioChecked2 (theField) { for (var i = 0; i < theField.length; i++) { if (theField[i].checked) { return true; } } alert(requiredRadioButton) return false; } // Check radio that radio button is able only 'Yes' value function radioCheckedYes (theField, valueYes) { for (var i = 0; i < theField.length; i++) { if (theField[i].checked && i == (valueYes-1)) { return true; } } alert(errorRadioButtonYes) return false; } function withinMaxLength (theField, cur, maxsize) { // var maxsize = 2000; val = theField.value if (val.length > maxsize) { theField.focus() theField.select() alert(requiredMaxSizePrefix + cur + requiredMaxSizeMiddle + maxsize + requiredMaxSizeSuffix); return false; } // Value is not > max Size return true; } // Checks to ensure the value entered by the user is greater than // the min allowed length. //Note: The check will be skipped if the user hasn't entered a value. // If the field should have a value, then set the mandatory flag to Y in // page property file and the warnEmpty Funtion will then be called. function checkMinLength(theField, cur, minlength){ var val = theField.value; if ( (val.length>0) && (val.length< minlength) ) { return warnInvalidMinLength(theField, cur, minlength); } // Value is > min length return true; } function warnInvalidMinLength(theField, cur, minlength){ theField.focus() theField.select() alert(minSizePrefix + cur + minSizeMiddle + minlength + minSizeSuffix); return false; } function submit_onClick(form) { return validateRequired(form); } //----------------- Number -------------------- // Beginning of Input, followed by one or more digits, followed by End of Input. var reIntegers = /^\d+$/ // isIntegerString (STRING s [, BOOLEAN emptyOK]) // Returns true if all characters in string s are numbers. // Accepts non-signed integers only. function isIntegerString (s) { var i; if (isEmpty(s)) if (isIntegerString.arguments.length == 1) return defaultEmptyOK; else return (isIntegerString.arguments[1] == true); return reIntegers.test(s) } function checkNumberString(theField, cur, emptyOK) { if (checkNumberString.arguments.length == 1) emptyOK = defaultEmptyOK; if ((emptyOK == true) && (isEmpty(theField.value))) return true; if (!isIntegerString(theField.value)) return warnInvalidNumericString (theField, cur); else return true; } // ---------------- Alphabetic -------------- // Beginning of Input, followed by one or more lower or uppercase English letters, // followed by End of Input. //var reAlphabetic = /^[a-zA-Z\s]+$/ var reAlphabetic = /^[^0-9?]+$/ // isAlphabetic (STRING s [, BOOLEAN emptyOK]) // Returns true if string s is English letters // (A .. Z, a..z) only. // NOTE: Need extra validation to support extra European characters. function isAlphabetic (s) { var i; if (isEmpty(s)) if (isAlphabetic.arguments.length == 1) return defaultEmptyOK; else return (isAlphabetic.arguments[1] == true); else { return reAlphabetic.test(s) } } function checkAlphaString(theField, cur, emptyOK) { if (checkAlphaString.arguments.length == 1) emptyOK = defaultEmptyOK; if ((emptyOK == true) && (isEmpty(theField.value))) return true; if (!isAlphabetic(theField.value)) return warnInvalidAlphaString (theField, cur); else return true; } // ---------------------- Date ----------------------- function checkDigit( value ) { var i = value.length; var ch; var j=0; for ( j=0;j='0' && ch <= '9') ) { return false; } } return true; } function checkDigitRange( value, min, max ) { //alert("value: "+ value + ", min: " + min + ", max: " + max) if ( checkDigit( value ) ) { if ( value >= min && value <=max ) { // alert( 'Within Range ' + min + " -- " + max ); return true; } else { // alert( 'NOT Within Range ' + min + " -- " + max ); return false; } } else { //alert( 'not digit ' + "[" + value + "] " + min + " -- " + max ); return false; } } /** Visszadja kibontva a datum reszeit * value: erteket tart. valtozo * part: melyik resz kisbetuvel (mm, dd, yy) es a hossza adja meg az ertkek hosszat (yy:2, yyyy:4) */ function getPartOfDate( value, part ) { var place = dateFormat.toLowerCase().indexOf(part); if (place != -1) { if (place != 0 && dateFormat.charAt(place-1) != value.charAt(place-1)) return (-2); var v = value.substring(place,place+part.length); if (isIntegerString(v)) return (v); else return (-3); } else return (-4); } function getMM( value ) { var i = value.indexOf( '/' ); if (dateFormat == "MM/DD/YYYY") { return value.substring(0,i); } else { var j= value.lastIndexOf( '/' ); return value.substring( i+1, j ); } } function getDD( value ) { var i= value.indexOf( '/' ); if (dateFormat == "MM/DD/YYYY") { var j= value.lastIndexOf( '/' ); return value.substring( i+1, j ); } else { return value.substring(0,i); } } function getYYYY( value ) { var i = value.length; var j = value.lastIndexOf( '/' ); return value.substring( j+1, i+1 ); } function getFullYear(d) { var y = d.getYear(); if ( y < 1000 ) y += 1900; return y; } function checkDate(theField, cur, emptyOK ) { if (checkDate.arguments.length == 1) emptyOK = defaultEmptyOK; if ((emptyOK == true) && (isEmpty(theField.value))) return true; if ( theField.value.length != 10 ) { return warnInvalidDateFormat (theField, cur); } var mm=getPartOfDate( theField.value, "mm" ); var dd=getPartOfDate( theField.value, "dd" ); var yy=getPartOfDate( theField.value, "yyyy" ); days_in_month=returnDaysInMonth(mm,yy); var dt = new Date(); var curYear = getFullYear(dt); var curMonth = dt.getMonth(); curMonth = curMonth + 1; var curDay = dt.getDate(); //alert ("dd = " + dd + " mm = " + mm + "yy = " + yy); if ( !checkDigitRange( dd,1,days_in_month) ) { return warnInvalidDateFormat (theField, cur); } if ( !checkDigitRange( mm,1,12) ) { return warnInvalidDateFormat (theField, cur); } if ( !(checkDigitRange( yy,1900,curYear )) ) { return warnInvalidDateFormat (theField, cur); } if (yy == curYear) { if ( !checkDigitRange( mm,1,curMonth) ) { return warnInvalidDateFormat (theField, cur); } if (mm == curMonth) { if ( !checkDigitRange( dd,1,curDay )) { return warnInvalidDateFormat (theField, cur); } } } return true; } function returnDaysInMonth(mm,yy) { var days_in_month = 0; if (mm == 01) days_in_month = 31; else if (mm == 02) if ((yy % 4) == 0) { days_in_month = 29; } else days_in_month = 28; else if (mm == 03) days_in_month = 31; else if (mm == 04) days_in_month = 30; else if (mm == 05) days_in_month = 31; else if (mm == 06) days_in_month = 30; else if (mm == 07) days_in_month = 31; else if (mm == 8) days_in_month = 31; else if (mm == 9) days_in_month = 30; else if (mm == 10) days_in_month = 31; else if (mm == 11) days_in_month = 30; else if (mm == 12) days_in_month = 31; return (days_in_month); } //-----------------------Listbox---------------------------- function warnEmptyList (theField, cur) { cur.focus() //cur.select() alert(requiredPrefix + theField + requiredSuffix) return false } // Get selected value from listbox function getListboxValue (list) { return list.options[list.selectedIndex].value } // Verify Listbox function checkListbox (cur, theField, emptyOK) { var selectedValue = getListboxValue (cur) // Next line may be needed on to avoid "undefined is not a number" error // in equality comparison below. if (checkListbox.arguments.length == 2) emptyOK = defaultEmptyOK; if ((emptyOK == true) && (isEmpty(selectedValue))) return true; if (isWhitespace(selectedValue)) return warnEmptyList (theField, cur); else return true; } // *** Phone number validation *** function checkAreaPhone(areaNumber, phoneNumber) { phoneSTD = areaNumber.value; phone = phoneNumber.value; if (phone!="") { if (phoneSTD=="") { areaNumber.focus(); areaNumber.select(); alert("Не внесовте вредност во полето за телефон. Ова е задолжително поле. Ве молиме внесете вредност."); return false; } } return true; } //Checks if a greeting card type has been selected function isCardChecked(theField){ for (var i = 0; i < theField.length; i++) { if (theField[i].checked) { return true; } } alert(requiredCardMessage) return false; } function withinDays(day, month, withindays, msg){ var day = day.value; var month = month.value; var dt = new Date(); var curYear = getFullYear(dt); var curMonth = dt.getMonth(); curMonth = curMonth + 1; var curDay = dt.getDate(); if (month > curMonth || month == curMonth && day >= curDay) { var dt1 = new Date(curYear, month - 1, day); var diff1 = dt1 - dt;//milliseconds if (diff1 > withindays*86400000) { alert (msg); return false; } } if (month < curMonth || month == curMonth && day < curDay) { var dt2 = new Date(curYear + 1, month - 1, day); var diff2 = dt2 - dt; if (diff2 > withindays*86400000) { alert (msg); return false; } } return true; } function withinDate(day, month, year, withindays, msg) { var day = day.value; var month = month.value; var year = year.value; var dt = new Date(year, month-1, day); var curDate = new Date(); curDate.setHours(0); curDate.setMinutes(0); curDate.setSeconds(0); curDate.setMilliseconds(0); var dif = dt.getTime() - curDate.getTime(); if (dif < 0 || dif > withindays*86400000) { alert(msg); return false; } return true; } function AVsitestatForm(frmNm) { }