var MSGTIMER = 20; var MSGSPEED = 20; var MSGOFFSET = 5; var MSGHIDE = 3; // build out the divs, set attributes and call the fade function // function inlineMsg(target,string,autohide,setfocusOn,setfocus) { var msg; var msgcontent; setfocus = (setfocus) ? setfocus : '1'; if(!document.getElementById('msg')) { msg = document.createElement('div'); msg.id = 'msg'; msgcontent = document.createElement('div'); msgcontent.id = 'msgcontent'; document.body.appendChild(msg); msg.appendChild(msgcontent); msg.style.filter = 'alpha(opacity=0)'; msg.style.opacity = 0; msg.alpha = 0; } else { msg = document.getElementById('msg'); msgcontent = document.getElementById('msgcontent'); } msgcontent.innerHTML = string; msg.style.display = 'block'; var msgheight = msg.offsetHeight; var targetdiv = document.getElementById(target); var setfocusOnObj = document.getElementById(setfocusOn); if (setfocus == 1){ setfocusOnObj.focus(); } var targetheight = targetdiv.offsetHeight; var targetwidth = targetdiv.offsetWidth; var topposition = topPosition(targetdiv) - (((msgheight - targetheight) / 2) - 3); var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET; msg.style.top = topposition + 'px'; msg.style.left = leftposition + 'px'; clearInterval(msg.timer); msg.timer = setInterval("fadeMsg(1)", MSGTIMER); if(!autohide) { autohide = MSGHIDE; } // The following line has been commented so that the message doesnt hide after a few secs window.setTimeout("hideMsg()", (autohide * 1000)); } // hide the form alert // function hideMsg(msg) { var msg = document.getElementById('msg'); if(!msg.timer) { msg.timer = setInterval("fadeMsg(0)", MSGTIMER); } } // face the message box // function fadeMsg(flag) { if(flag == null) { flag = 1; } var msg = document.getElementById('msg'); var value; if(flag == 1) { value = msg.alpha + MSGSPEED; } else { value = msg.alpha - MSGSPEED; } msg.alpha = value; msg.style.opacity = (value / 100); msg.style.filter = 'alpha(opacity=' + value + ')'; if(value >= 99) { clearInterval(msg.timer); msg.timer = null; } else if(value <= 1) { msg.style.display = "none"; clearInterval(msg.timer); } } // calculate the position of the element in relation to the left of the browser // function leftPosition(target) { var left = 0; if(target.offsetParent) { while(1) { left += target.offsetLeft; if(!target.offsetParent) { break; } target = target.offsetParent; } } else if(target.x) { left += target.x; } return left; } // calculate the position of the element in relation to the top of the browser window // function topPosition(target) { var top = 0; if(target.offsetParent) { while(1) { top += target.offsetTop; if(!target.offsetParent) { break; } target = target.offsetParent; } } else if(target.y) { top += target.y; } return top; } // preload the arrow // if(document.images) { arrow = new Image(7,80); arrow.src = "images/msg_arrow.gif"; } function getObjVars(){ this.fieldN = new Array(); // Field name this.fieldI = new Array(); // Field Id this.fieldT = new Array(); // Field type (text, editor, checkbox, radio, select, mselect, date) this.fieldV = new Array(); // Error message to be dispayed this.fieldCF = new Array(); // Check for equal field this.fieldCV = new Array(); // To check if field value is equal to a specific value. Give error if field value <> specified value this.fieldCVE = new Array(); // To check if field value is equal to a specific value. Give error if field value == specified value this.fieldCM = new Array(); // Error message to be displayed after comparing two fields this.fieldFocus = new Array(); // Set focus to this field, always give the ID of the field this.setFocus = new Array(); // whether to set focus to this field, if not specified it takes as 'yes' this.fieldValidate = new Array(); // this is specially used if you want to validate the field this.fieldValidateMsg = new Array(); // message this.fieldNumeric = new Array(); // if set as 1 checks for numeric value this.fieldText = new Array(); // if set as 1 checks for text this.fieldAllowSpace = new Array(); //if set as 1 checks for text, allows space aswell this.fieldAlphaNumeric = new Array(); //check alphanumeric if set as 1 } function validateForm(formN, objvar){ var err = ""; var returnVal = ""; var msgArr = new Array(); var frmObj = eval("document." + formN); for(var i=0; i= 0) || (objvar.fieldN[i].indexOf("email") >= 0)) { if(!checkEmail(frmElm.value)) { inlineMsg(objvar.fieldI[i],'Ungültige E-Mail Adresse',3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; }else if (objvar.fieldValidate[i]){ inlineMsg(objvar.fieldI[i],objvar.fieldValidateMsg[i],3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } }else if(objvar.fieldCF[i]){ var frmCElm = eval("frmObj." + objvar.fieldCF[i]); if(frmElm.value != frmCElm.value){ inlineMsg(objvar.fieldI[i],objvar.fieldCM[i],3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } }else if(objvar.fieldCV[i]){ if(frmElm.value != objvar.fieldCV[i]){ inlineMsg(objvar.fieldI[i],objvar.fieldCM[i],3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } }else if(objvar.fieldCVE[i]){ if (frmElm.value == objvar.fieldCVE[i]){ var dis_msg = (objvar.fieldCM[i]) ? objvar.fieldCM[i] : objvar.fieldV[i]; inlineMsg(objvar.fieldI[i],dis_msg,3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } }else if (objvar.fieldValidateMsg[i] == 1){ var dis_msg = (objvar.fieldValidateMsg[i]) ? objvar.fieldValidateMsg[i] : objvar.fieldV[i]; inlineMsg(objvar.fieldI[i],dis_msg,3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; }else if (objvar.fieldNumeric[i]){ if(!isNumeric(frmElm.value)){ inlineMsg(objvar.fieldI[i],objvar.fieldNumeric[i],3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } }else if (objvar.fieldText[i]){ if(!isAlpha(frmElm.value)){ inlineMsg(objvar.fieldI[i],objvar.fieldText[i],3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } }else if (objvar.fieldAlphaNumeric[i]){ if((isNumeric(frmElm.value)) || (isAlpha(frmElm.value))){ inlineMsg(objvar.fieldI[i],objvar.fieldAlphaNumeric[i],3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } }else if (objvar.fieldAllowSpace[i]){ returnVal = ""; returnVal = allowSpace(frmElm.value,objvar.fieldN[i]); msgArr[0] = objvar.fieldText[i]; msgArr[1] = objvar.fieldAllowSpace[i]; if(returnVal !== true){ inlineMsg(objvar.fieldI[i],msgArr[returnVal],3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } } } if(objvar.fieldT[i] == "radio"){ var frmElm = eval("frmObj." + objvar.fieldN[i]); var checkedI = false; var tol_options = frmElm.length; for(var j=0; j< frmElm.length; j++) { if(frmElm[j].checked == true) { checkedI = true; if(objvar.fieldN[i].indexOf("learning_disability") >= 0 && frmElm[j].value == 1){ if(!checkDisability()){ inlineMsg(objvar.fieldI[i],"As you selected Yes in this question, please select an option under 'Disability' and/or 'Learning Difficulty'",3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } } } } if(checkedI === false) { inlineMsg(objvar.fieldI[i],objvar.fieldV[i],3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } } // if(objvar.fieldT[i] == "checkbox"){ // var frmElm = eval("frmObj." + objvar.fieldN[i]); // if(frmElm.checked === false) { // inlineMsg(objvar.fieldI[i],objvar.fieldV[i],3,objvar.fieldFocus[i],objvar.setFocus[i]); // return false; // } // } if(objvar.fieldT[i] == "checkbox"){ var frmElm = eval("frmObj." + objvar.fieldN[i]); var checkedI = false; var tol_options = frmElm.length; for(var j=0; j< frmElm.length; j++) { if(frmElm[j].checked == true) { checkedI = true; } } if(checkedI === false) { inlineMsg(objvar.fieldI[i],objvar.fieldV[i],3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } } if(objvar.fieldT[i] == "validate"){ var frmElm = eval("frmObj." + objvar.fieldN[i]); inlineMsg(objvar.fieldI[i],objvar.fieldV[i],3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } if(objvar.fieldT[i] == "captcha"){ if (grecaptcha.getResponse() == ""){ //inlineMsg(objvar.fieldI[i],objvar.fieldV[i],3,objvar.fieldFocus[i],objvar.setFocus[i]); return false; } } } return true; } function demo(){ var objVar = new getObjVars(); objVar.fieldN[0] = "demofieldName1"; objVar.fieldV[0] = "demofield1 error message to be displayed"; objVar.fieldT[0] = "text"; objVar.fieldI[0] = "demofieldId1"; objVar.fieldN[1] = "demofieldName2"; objVar.fieldV[1] = "demofield2 error message to be displayed"; objVar.fieldT[1] = "text"; objVar.fieldI[1] = "demofieldId2"; return validateForm('formName',objVar); } function update(counterObj,textObj,limit) { var old = counterObj.value; counterObj.value = textObj.value.length; if(counterObj.value >= limit) { alert('Maximum '+limit+' characters only!'); if(document.styleSheets) { counterObj.style.fontWeight = 'bold'; counterObj.style.color = '#ff0000'; } textObj.value = textObj.value.substring(0,limit); counterObj.value = textObj.value.length; }else if(counterObj.value < limit && old > limit && document.styleSheets ) { counterObj.style.fontWeight = 'normal'; counterObj.style.color = '#000000'; } } function getAge(){ var bday = parseInt(document.academyForm.day.value); var bmo = (parseInt(document.academyForm.month.value)-1); var byr = parseInt(document.academyForm.year.value); var byr; var age; var now = new Date(); tday = now.getDate(); tmo = (now.getMonth()); tyr = (now.getFullYear()); if((tmo > bmo)||(tmo==bmo & tday>=bday)){ age = byr; }else{ age = byr+1; } // alert("As of today, "+now+' \n'+", you are:"+(tyr-age)+ " years old"); document.academyForm.age.value = (tyr-age); } function checkDisability(){ var disabilityObj = document.academyForm.disability; var learningObj = document.academyForm.learning_disabilities; if(disabilityObj.value=="select" && learningObj.value=="select"){ return false; }else{ return true; } } function isNumeric(objectVal){ var numericExpression = /^[0-9 ]+$/; if(objectVal.match(numericExpression)){ return true; }else{ return false; } } function isAlpha(objectVal){ var numericExpression = /^[a-zA-Z]+$/; if(objectVal.match(numericExpression)){ return true; }else{ return false; } } function allowSpace(objectVal,obj){ var numericExpression = /^[a-zA-Z ]+$/; if(objectVal.match(numericExpression)){ if(obj.indexOf("nursery_manager")>=0){ var splitArr = objectVal.split(" "); if(splitArr.length>1 && splitArr[1] != ""){ return true; }else{ return 0; } }else{ return true; } }else{ return 1; } } function isAlphaNumeric(objectVal){ var expression = /^[0-9a-zA-Z ]+$/; if(objectVal.match(expression)){ return true; }else{ return false; } } function checkEmail(fieldValue){ var chkAt = fieldValue.indexOf("@"); var chkDot= fieldValue.indexOf("."); var chkHack= fieldValue.indexOf("@."); var chkHackA= fieldValue.indexOf(".@"); if((chkAt >= 0) && (chkDot >= 0) && (chkHack == -1) && (chkHackA == -1) ) { return true; } return false; }