var whitespace = " \t\n\r"; var intG = 0; function charInString (c, s) { for (i = 0; i < s.length; i++) { if (s.charAt(i) == c) return true; } return false } function startAll() { intG = 0; } function stripCharsInBag (s, bag) { var i; var returnString = ""; // Search through string chars one by one. // If character is not in bag, append to returnString. for (i = 0; i < s.length; i++) { // Check that current character isn not whitespace. var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function ltrimInput(s) { var i = 0; var whitespace = " "; while ((i < s.length) && (s.charAt(i) == whitespace)) i++; return s.substring (i, s.length); } function checkEmpty(qtext,qorder,qmust) { var strText; strText = eval("document.FormBuilder.QUESTION_" + qorder + ".value"); if (strText == null || strText == "") { if(qmust == 1) { alert("\"" + qtext + "\" is a required field."); return false; } else{ intG++; return true; } } else //there is an input just left trim it and give a proper msg to user if nec. { strText = ltrimInput(strText); if (strText == null || strText == "") { alert("Please properly answer question\n" + "\"" + qtext + "\""); return false; } else{ return true;} } } function checkEmailPattern(strText) { var regEx = /^([^\s@]+)@{1}([A-Za-z0-9\-\.]+)\.{1}([A-Za-z]+)$/; return regEx.test(strText); } function checkContactInfo(qorder,qmust) { strName = eval("document.FormBuilder.QUESTION_" + qorder + "_NAME.value"); strName = ltrimInput(strName); strEmail = eval("document.FormBuilder.QUESTION_" + qorder + "_EMAIL.value"); strAddress = eval("document.FormBuilder.QUESTION_" + qorder + "_ADDRESS.value"); strAddress = ltrimInput(strAddress); intPhone = eval("document.FormBuilder.QUESTION_" + qorder + "_PHONE.value"); intPhone = ltrimInput(intPhone); intFax = eval("document.FormBuilder.QUESTION_" + qorder + "_FAX.value"); intFax = ltrimInput(intFax); strTitle = eval("document.FormBuilder.QUESTION_" + qorder + "_TITLE.value"); strTitle = ltrimInput(strTitle); strCompany = eval("document.FormBuilder.QUESTION_" + qorder + "_COMPANY.value"); strCompany = ltrimInput(strCompany); // check if any the fields are null or empty if ((strName == null || strName == "") || (strEmail == null || strEmail == "") || (strAddress == null || strAddress == "") || (intPhone == null || intPhone == "") || (intFax == null || intFax == "") || (strTitle == null || strTitle == "") || (strCompany == null || strCompany == "")) { if(qmust == 1) { alert("\"Contact information (Name, Address, ...)\" are all required fields."); return false; } else { if ((strName == null || strName == "") && (strEmail == null || strEmail == "") && (strAddress == null || strAddress == "") && (intPhone == null || intPhone == "") && (intFax == null || intFax == "") && (strTitle == null || strTitle == "") && (strCompany == null || strCompany == "")) { intG++; return true; } else // some empty, some not { // check whether email field is valid or not if it is not null or empty if (strEmail != "") { if (checkEmailPattern(strEmail)) { return true; } else { alert("Please enter a valid e-mail address."); return false; } } else { return true; } } } } else // none of the fields is null or empty { if (checkEmailPattern(strEmail)) { return true; } else { alert("Please enter a valid e-mail address."); return false; } } } function checkCountry(qorder,qmust) { var strCity; var strState; var strZip; var strCountry; strCity = eval("document.FormBuilder.QUESTION_" + qorder + "_CITY.value"); strCity = ltrimInput(strCity); strState = eval("document.FormBuilder.QUESTION_" + qorder + "_STATE.value"); strState = ltrimInput(strState); strZip = eval("document.FormBuilder.QUESTION_" + qorder + "_ZIP.value"); strZip = ltrimInput(strZip); strCountry = eval("document.FormBuilder.QUESTION_" + qorder + "_COUNTRY.value"); strCountry = ltrimInput(strCountry); if ((strCity == null || strCity == "") || (strState == null || strState == "") || (strZip == null || strZip == "") || (strCountry == null || strCountry == "")) { if(qmust == 1) { alert("Questions: \"City, State, Zip, Country\" are required." + "\nPlease fill in the questions."); return false; } else { if ((strCity == null || strCity == "") && (strState == null || strState == "") && (strZip == null || strZip == "") && (strCountry == null || strCountry == "")) { intG++; return true; } else{ return true; } } } else{ return true; } } function checkNumber(qtext,qorder,intlow,inthigh,qmust,valmsg) { var intVal; var intYes; var strMsgWithRange = "\nPlease enter a number between " + intlow + " and " + inthigh + "."; var strMsgNoRage = "\nPlease enter a number."; var strMsg = ""; if (parseFloat(intlow) == parseFloat(inthigh)) { strMsg = strMsgNoRage; } else { strMsg = strMsgWithRange; } intVal = eval("document.FormBuilder.QUESTION_" + qorder + ".value"); if (intVal == null || intVal == "") { if(qmust == 1) { if(valmsg == "" || valmsg == null) { alert("\"" + qtext + "\" is required." + strMsg); } else { alert(valmsg) } return false; } else{ intG++; return true; } } else //box is not empty { intVal = ltrimInput(intVal); if (intVal == null || intVal == "") { if(valmsg == "" || valmsg == null) { alert("Please properly answer question\n" + "\"" + qtext + "\""); } else { alert(valmsg) } return false; } else { parseInt(intVal); if(isNaN(intVal)) //box is not empty and entry is not a number { if(intlow != inthigh) { if(valmsg == "" || valmsg == null) { alert("Please enter a number between " + intlow + " and " + inthigh + " in question\n\"" + qtext + "\""); } else { alert(valmsg) } } else { if(valmsg == "" || valmsg == null) { alert("Please enter a number in question\n\"" + qtext + "\""); } else { alert(valmsg) } } return false; } else //box has a number { if(intlow <= inthigh) { if(intlow == 0 && inthigh == 0) //any number is good { return true; } else { if ((intVal < intlow) || (intVal > inthigh)) //number is out of range. { if(valmsg == "" || valmsg == null) { alert("\"" + qtext + "\" must have an answer between " + intlow + " and " + inthigh + "\nPlease answer properly."); } else { alert(valmsg) } return false; } else{ return true; } } } else{ return true; } } } } } function checkEmail(qtext,qorder,qmust) { var strText = eval("document.FormBuilder.QUESTION_" + qorder + ".value"); if ( (strText == null || strText == "") && (qmust == 1) ) { alert("\"" + qtext + "\" is required." + "\nPlease enter your e-mail address."); return false; } else if ( (strText == null || strText == "") && (qmust == 0) ) { intG++; return true; } else if (!checkEmailPattern(strText)) { alert("\"" + qtext + "\" is required." + "\nPlease enter a valid e-mail address."); return false; } else { return (true); } } function checkDate(qtext,qorder,dtmlow,dtmhigh,dtmMlow,dtmMhigh,dtmDlow,dtmDhigh,dtmYlow,dtmYhigh,qmust,valmsg) { var regEx; var dtmVal; var strMsg1 = "\"" + qtext + "\" must have an answer between " + dtmlow + " and " + dtmhigh + "."; var strMsg2 = "\"" + qtext + "\" is required." + "\nPlease enter a date between " + dtmlow + " and " + dtmhigh + "." dtmVal = eval("document.FormBuilder.QUESTION_" + qorder + ".value"); //alert("dtmVal is: " + dtmVal); if (dtmVal == null || dtmVal == "") { if(qmust == 1) { if(dtmlow != dtmhigh) { if(valmsg == "" | valmsg == null) { alert(strMsg2); } else { alert(valmsg) } } else { if(valmsg == "" | valmsg == null) { alert("\"" + qtext + "\" is required." + "\nPlease enter a date.") } else { alert(valmsg) } } return false; } else{ intG++; return true; } } else { dtmVal = ltrimInput(dtmVal); if (dtmVal == null || dtmVal == "") //box had only spaces { if(dtmlow != dtmhigh) { if(valmsg == "" | valmsg == null) { alert(strMsg1); } else { alert(valmsg) } } else { if(valmsg == "" | valmsg == null) { alert("Please properly answer question\n" + "\"" + qtext + "\""); } else { alert(valmsg) } } return false; } else //box is not empty { regEx = /\b(1[0-2]|0?[1-9])[\-\/](0?[1-9]|[12][0-9]|3[01])[\-\/]((19|20)\d{2})/ var arrDate = regEx.exec(dtmVal) if(arrDate) { //alert("in if(arrDate)") var intMonth = arrDate[1] intMonth = parseInt(intMonth, 10) var intDay = arrDate[2] intDay = parseInt(intDay, 10) var intYear = arrDate[3] intYear = parseInt(intYear, 10) //alert("intmonth is: " + intMonth); //alert("intDay is: " + intDay); //alert("intYear is: " + intYear); var monthOk; monthOk = checkMonth(qtext,intYear,intMonth, intDay); if (monthOk == false){return false;} intMonth -= 1; dtmMlow -= 1; dtmMhigh -= 1; var dtmLow = new Date(dtmYlow,dtmMlow,dtmDlow) //alert("dtmlow is: " + dtmLow) var dtmHigh = new Date(dtmYhigh,dtmMhigh,dtmDhigh) //alert("dtmHigh is: " + dtmHigh) var dtmInput = new Date(intYear,intMonth,intDay) //alert("dtmInput is: " + dtmInput) if (dtmlow != dtmhigh) { if(dtmLow<=dtmInput && dtmInput<=dtmHigh) { return true; } else { if(valmsg == "" | valmsg == null) { alert(strMsg1); } else { alert(valmsg) } return false; } } else{ return true; } } else { if(dtmlow != dtmhigh) { if(valmsg == "" | valmsg == null) { alert(strMsg1); } else { alert(valmsg) } } else { if(valmsg == "" | valmsg == null) { alert("Please enter a date in question:\n\"" + qtext + "\".") } else { alert(valmsg) } } return false; } } } } function checkMonth(qtext,intyear,intmonth, intday) { var months = new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); intmonth = parseInt(intmonth); intday = parseInt(intday); intyear = parseInt(intyear); if((intmonth == 4 || intmonth == 6 || intmonth == 9 || intmonth == 11) && intday > 30) { alert(months[intmonth] + " has only 30 days. Please correct question:\n\"" + qtext + "\"" ); return false; } else { if(intday > 31) { alert(months[intmonth] + " has only 31 days. Please correct question:\n\"" + qtext + "\"" ); return false; } } if(intmonth == 2) { if(intyear % 4 > 0 && intday > 28) { alert("February of " + intyear + " has only 28 days. Please correct question:\n\"" + qtext + "\"" ); return false; } else { if(intday > 29) { alert("February of " + intyear + " has only 29 days. Please correct question:\n\"" + qtext + "\"" ); return false; } } } return true; } function checkMultiSelect(qtext,qorder,qmust) { var strVal; strVal = eval("document.FormBuilder.QUESTION_" + qorder); var strOption = strVal.options[strVal.selectedIndex].value; if(strOption == "" || strVal == null) { if(qmust == 1) { alert("\"" + qtext + "\" is required." + "\nPlease select an option."); return false; } else{ intG++; return true; } } else{ return true; } } function checkMultiRadio(qtext,qorder,qmust) { var blnReturn = false; var intLen = eval("document.FormBuilder.QUESTION_" + qorder + ".length"); parseInt(intLen); if (intLen == null){ intLen = 1 } //in this case there will be no array for(var i=0; i