var frmobj = new Array(); function ButCancel(retval) { document.frmInpForm.Action.value = "Cancel"; document.location = retval;} function ButDelete() { document.frmInpForm.Action.value = "Delete"; document.frmInpForm.submit();} function ButConfirm() { document.frmInpForm.Action.value = "Update"; frmMod = eval("document.frmInpForm"); if (validate(frmMod)){ document.frmInpForm.submit(); } } function frmMod(){ this.fields = new Array(); this.name = 'frmInpForm'; this.addItem = addItem; } function addItem(item){ if(!this.created){ this.fields[this.fields.length] = item; this.name = 'frmInpForm'; }} function fldItem(name, opts, dataType, cond, msg){this.cond = cond; this.name = name; this.opts = opts; this.dataType = dataType; this.msg = msg; this.type = ''; this.setType = setFldType; this.getType = getFldType;} function setFldType(type){ if(!this.created) this.type = type;} function getFldType(){ return this.type; } function chkInput(I1, I2, I3, I4, I5){ var theField; var form; theField = new fldItem(I1, I2, I3, I4, I5); form = new frmMod(); if(frmobj.length == 0){ frmobj[0] = form; } frmobj[0].addItem(theField); } function checkBoxChk(obj){ if(obj.checked) return true; else return false;} function passwordChk(obj){ if(obj.value.length != 0) return true; else return false;} function recVerify(){ var ErrMsgInt = ''; var ErrMsgIntCount = 1; for(var i=0; i < frmobj[0].fields.length; i++){ if (typeof(eval('document.frmInpForm.' + frmobj[0].fields[i].name)) == "undefined"){ ErrMsgInt+= ErrMsgIntCount++ + ") " + frmobj[0].fields[i].name + "\n"; } else { var temp = eval('document.frmInpForm.' + frmobj[0].fields[i].name); if(typeof(temp.type) == "undefined"){ frmobj[0].fields[i].setType("radio"); } else frmobj[0].fields[i].setType(temp.type); }} if(ErrMsgInt != ''){ alert("Warning: The Following item(s) do not exists in this form.\n\n" + ErrMsgInt); return "noField"; } else return true; } function valCondFlds(){ var fieldErrMsg = ''; var fieldErrMsgCount = 1; var chkVal = false; var toFocus = false; for(var i=0; i < frmobj[0].fields.length; i++) { if(frmobj[0].fields[i].cond.toLowerCase() == "null") { chkVal = fldValid(i);} else{ if(eval("document." + frmobj[0].fields[i].cond)){ chkVal = fldValid(i);} else chkVal = true;} if(!chkVal){ fieldErrMsg += fieldErrMsgCount++ + ") " + frmobj[0].fields[i].msg + "\n"; if(!toFocus){ var obj = eval("document.frmInpForm." + frmobj[0].fields[i].name); if(typeof(obj.type) == "undefined") { obj[0].focus(); toFocus = true; } else { if(obj.type != "hidden") { obj.focus(); toFocus = true; }}}}} if(fieldErrMsg != ''){ alert("Niet alle verplichte velden zijn ingevuld:\n\n"+ fieldErrMsg); return false; } else return true;} function fldValid(index){ var chkVal = false; var obj = eval("document.frmInpForm." + frmobj[0].fields[index].name); switch(frmobj[0].fields[index].type){ case "text": chkVal = textChk(index, obj); break; case "textarea": chkVal = textareaChk(obj); break; case "radio": chkVal = radioChk(index, obj); break; case "select-one": case "select-multiple": chkVal = selectChk(index, obj); break; case "hidden": chkVal = textChk(index, obj); break; case "checkbox": chkVal = checkBoxChk(obj); break; case "password": chkVal = passwordChk(obj);} return chkVal;} function textChk(frmobjIndex, obj){ var chkVal = false; if(frmobj[0].fields[frmobjIndex].opts == 1){ if(obj.value.length != 0){ switch(frmobj[0].fields[frmobjIndex].dataType) { case 'alphanum': chkVal=alphanumChk(obj); break; case 'numeric': chkVal=numericChk(obj); break; case 'date:d-m-y': case 'date:m-d-y': case 'date:y-m-d':chkVal=dateChk(frmobjIndex, obj); break; case 'email':chkVal=emailChk(obj); break; default :alert("Internal Error Message: \nThere is no datatype: '" + frmobj[0].fields[frmobjIndex].dataType + "'."); }}} else { if(frmobj[0].fields[frmobjIndex].opts == 0){ if(obj.value.length != 0) chkVal = true; } else alert("Internal Error Message: \nThe option of the field: '" + frmobj[0].fields[frmobjIndex].name + "' should be only 1 or 0.");} return chkVal;} function alphanumChk(obj){ if(isNaN(obj.value)) return true; else { if (obj.value!='') return true; else return false;}} function numericChk(obj){ var numStr = ""; if(obj.value.indexOf(".") != -1) { var periodArr = obj.value.split("."); if((periodArr.length > 2) || (periodArr[1].length == 0)) return false; else { if(periodArr[1].indexOf(",") != -1) return false; if(periodArr[0].indexOf(",") != -1){ var commaArr = periodArr[0].split(","); if((commaArr[0].length > 3) || (commaArr[0].length == 0)) return false; if(commaArr.length > 1){ for(var i=1; i < commaArr.length; i++){ if(commaArr[i].length != 3) return false;}} for(var i=0; i < commaArr.length; i++) numStr+=commaArr[i]; numStr+="." + periodArr[1];} else {if(periodArr[1].indexOf(",") != -1) return false; numStr+= periodArr[0] + "." + periodArr[1];}}} else numStr+=obj.value; if(!isNaN(numStr)) return true; else return false;} function dateChk(frmobjIndex, obj){ var theDate = obj.value; var notAllowStr = ' /-+'; var dateArr; var formation; var toDate; var dateStr; var dateIdent; var str; var tmp = frmobj[0].fields[frmobjIndex].dataType; var tmpArr = tmp.split(":"); formation = tmpArr[1]; dateArr = dateParts(theDate); if((dateArr == -1) || (dateArr.length != 3) || (dateArr[0]=='') || (dateArr[dateArr.length-1]=='')) return false; switch(formation){ case 'd-m-y' : dateStr = formatting(dateArr[1], dateArr[1], dateArr[0], dateArr[2]); dateIdent = dateArr[0]; break; case 'm-d-y' : dateStr = formatting(dateArr[0], dateArr[0], dateArr[1], dateArr[2]); dateIdent = dateArr[1]; break; case 'y-m-d' : dateStr = formatting(dateArr[1], dateArr[1], dateArr[2], dateArr[0]); dateIdent = dateArr[2]; break; default : alert('Please check if the defined date format allowed.'); return false;} var dateObj = Date.parse(dateStr); if(dateObj.toString() == "NaN"){ return false; } else toDate = new Date(dateStr); for(j=0; j < dateArr.length; j++){ for(k=0; k < dateArr[j].length; k++){ subArray = dateArr[j].substring(k, k+1); if(notAllowStr.indexOf(subArray) != -1) return false; }} str = toDate.toString(); dateGen = str.split(' '); if(eval(dateGen[2]) != eval(dateIdent)) return false; obj.value = obj.value.toLowerCase(); return true;} function formatting(month, elem1, elem2, elem3){ var dateStr = ' '; if(elem3.length!=4) return dateStr; if(isNaN(month)){ if (month.length < 3) return dateStr; dateStr = elem1+' '+elem2+' '+elem3; } else { if((month>12) || (month<1) || (month.length > 2) || (elem3.length != 4)) return dateStr; dateStr = elem1+'/'+elem2+'/'+elem3; } return dateStr; } function dateParts(dateIn){ var dateArr; var separator = ' /-'; var subSep; var isSeparator = false; for(j=0; j < separator.length; j++) { subSep = separator.substring(j, j+1); if(dateIn.indexOf(subSep) != -1){ dateArr = dateIn.split(subSep); isSeparator = true; break; } else isSeparator = false; } if(!isSeparator) return -1; return dateArr; } function emailChk(obj){ var emailAdd = obj.value; var emailExp = /[^\w\.@\_-]/; var frontAt = /^[\._\-]/; var rareAt = /[\._\-]$/; var emailAd = /@/; var underStream = /_{2,}/; var hyphenStream = /\-{2,}/; var dotStream = /\.{2,}/; var hyphenSpec = /\-/; var dotSpec = /\./; var addArr; var dotArr; var hyphenArr; if(emailExp.test(emailAdd)) return false; if(!emailAd.test(emailAdd)) return false; if((underStream.test(emailAdd)) || (hyphenStream.test(emailAdd)) || (dotStream.test(emailAdd))) return false; addArr = emailAdd.split('@'); if((addArr.length>2) || (addArr.length<1) || (addArr[0] == '') || (addArr[1] == '')) return false; if((frontAt.test(addArr[0])) || (rareAt.test(addArr[0]))) return false; if((frontAt.test(addArr[1])) || (rareAt.test(addArr[1]))) return false; if(!dotSpec.test(addArr[1])) return false; dotArr = emailAdd.split('.'); for(j=0; j < dotArr.length; j++){ if((frontAt.test(dotArr[j])) || (rareAt.test(dotArr[j]))) return false;} if(hyphenSpec.test(emailAdd)) { hyphenArr = emailAdd.split('-'); for(j=0; j < hyphenArr.length; j++){ if((frontAt.test(hyphenArr[j])) || (rareAt.test(hyphenArr[j]))) return false;}} return true;} function textareaChk(obj){ if(obj.value == '') return false; else return true; } function selectChk(frmobjIndex, obj){ var chkVal = false; if(frmobj[0].fields[frmobjIndex].opts == "Null"){ for(var i=0; i < obj.options.length; i++){ if(obj.options[i].selected){ chkVal = true; break;}}} else{ for(var i=0; i < obj.options.length; i++){ if(obj.options[i].selected){ if(frmobj[0].fields[frmobjIndex].opts == i){ chkVal = false; break;} else chkVal = true;}}} return chkVal;} function validate(obj){ var chkItemExists = recVerify(); if(chkItemExists == "noField") return false; else { var chkVal = valCondFlds(); return chkVal; }} function radioChk(frmobjIndex, obj){ var radioName = frmobj[0].fields[frmobjIndex].name; var chkVal = false; var singleRadio = ""; singleRadio += obj.length; if(singleRadio.toLowerCase() == "undefined"){ if(obj.checked) chkVal = true; } else { for(var i=0; i < obj.length; i++) if((obj[i].name == radioName) && (obj[i].checked)){ chkVal = true; }} return chkVal;}