//-- One text fields, can be pressed which submits the form and bypasses validation. Prevent key from //-- acting as a "submit" -- only "Next" & "Finish" buttons can be used for this. var ns4=(document.layers)?true:false; var ie4=(document.all)?true:false; var logFieldHadFocus = false; if (ns4) { document.captureEvents(Event.KEYPRESS); } document.onkeypress = keycheck; function keycheck(e) { //- cannot be used to advance to the next question -- disable it now. if (ns4) { intKeyPress = e.which; // store value in global var.... }else { intKeyPress = event.keyCode; // store value in global var... } if (intKeyPress==13) { if (logFieldHadFocus==false){ return false; } else { //- Multi-line text fields must have the key enabled -- the only scenerio where this can happen. return true; } } } function setFieldHasFocus( logHasFocus ) { logFieldHadFocus = logHasFocus; return true; } //-- end.... var submitted=false; function PreviewSurveyReport(){ var thisform = document.forms[1]; var strView = "vwSurveySummary"; var strDBPath = thisform.DBPath.value; var strSurveyUNID = thisform.SurveyReport_UNID.value; strURL = strDBPath+"/"+strView+"/"+strSurveyUNID+"?OpenDocument"; location=strURL; } function unloadfunc(){ } function loadfunc(){ if (history.forward() != null) self.location.reload(); if (document.forms[1].Print.value == "YES") { alert("To print this Survey select File => Print from the menu bar or hold down the 'Ctrl and P' keys."); } } function lib_bwcheck(){ this.ver=navigator.appVersion this.agent=navigator.userAgent this.dom=document.getElementById?1:0 this.opera5=this.agent.indexOf("Opera 5")>-1 this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0; this.ie4=(document.all && !this.dom && !this.opera5)?1:0; this.ie=this.ie4 || this.ie5 || this.ie6 this.mac=this.agent.indexOf("Mac")>-1 this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; this.ns4=(document.layers && !this.dom)?1:0; this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5) return this } var bw=new lib_bwcheck() fromX=5 //How much from the actual mouse X should the description box appear? fromY=-30////How much from the actual mouse Y should the description box appear? //Makes crossbrowser object. function makeObj(obj){ this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0; if(!this.evnt) return false this.css=bw.dom||bw.ie4?this.evnt.style:bw.ns4?this.evnt:0; this.wref=bw.dom||bw.ie4?this.evnt:bw.ns4?this.css.document:0; this.writeIt=b_writeIt; return this } function b_writeIt(text){if(bw.ns4){this.wref.write(text);this.wref.close()} else this.wref.innerHTML=text} //Capturing mousemove var descx=0 var descy=0 function popmousemove(e){descx=bw.ns4||bw.ns6?e.pageX:event.x; descy=bw.ns4||bw.ns6?e.pageY:event.y} var oDesc; //Shows the messages function popup(msg){ if(oDesc){ oDesc.writeIt('
'+msg+'
'); if(bw.ie5||bw.ie6) descy=descy+document.body.scrollTop; oDesc.css.left=descx+fromX; oDesc.css.top=descy+fromY; oDesc.css.visibility='visible'; } } //Hides it function popout(num){ if(oDesc) oDesc.css.visibility='hidden' } function setPopup(){ if(bw.ns4)document.captureEvents(Event.MOUSEMOVE) document.onmousemove=popmousemove; oDesc=new makeObj('divDescription') } ///survey script function qtype( qname){ var ctrlname = eval("document.forms[1]."+qname+"Type"); return ctrlname.value; } function allowties( qname){ var ctrlname = eval("document.forms[1]."+qname+"Allowties"); return ctrlname.value=="1"?true:false; } function getRBvalue(obj,emptyvalue){ var rbvalue = emptyvalue?emptyvalue:""; if(obj.length){ for(var i = 0; i < obj.length; i++){ if( obj[i].checked ) rbvalue = obj[i].value } } else{ if( obj.checked ) rbvalue = obj.value } return rbvalue; } function uniquearr( arr ){ var result = true if(arr.length > 1){ arr.sort(); for(var i = 0; i < arr.length-1; i++){ if(arr[i] != "-"){ //Added this if statement to skip comparison of "-" value - Robert C (10/03/01) if(arr[i] == arr[i+1]){ result=false; break; } } } } return result; } function getcode ( qname ){ var obj = eval("document.forms[1]."+qname+"Code"); return obj.value; } //-- Function to check if field entry is numeric... function isNumber(inputStr) { for (var i = 0; i < inputStr.length; i++) { var oneChar = inputStr.substring(i, i + 1) if (oneChar !="$" && oneChar !="," && oneChar!="." && oneChar!="-") { if (oneChar < "0" || oneChar > "9") { return false } } } return true } //-- end.... //-- Trim function to support checks for all spaces in a field function Trim(TRIM_VALUE){ if(TRIM_VALUE.length < 1){ return ""; } TRIM_VALUE = RTrim(TRIM_VALUE); TRIM_VALUE = LTrim(TRIM_VALUE); if(TRIM_VALUE==""){ return ""; } else{ return TRIM_VALUE; } } function RTrim(VALUE){ var w_space = String.fromCharCode(32); var v_length = VALUE.length; var strTemp = ""; if(v_length < 0){ return""; } var iTemp = v_length -1; while(iTemp > -1){ if(VALUE.charAt(iTemp) == w_space){} else{ strTemp = VALUE.substring(0,iTemp +1); break; } iTemp = iTemp-1; } return strTemp; } function LTrim(VALUE){ var w_space = String.fromCharCode(32); if(v_length < 1){ return""; } var v_length = VALUE.length; var strTemp = ""; var iTemp = 0; while(iTemp < v_length){ if(VALUE.charAt(iTemp) == w_space){} else{ strTemp = VALUE.substring(iTemp,v_length); break; } iTemp = iTemp + 1; } return strTemp; } //-- end function validatedata(){ var questionOK = true; var questionOtherOK = true; var requiredobj; var focusobj; var obj; var otherobj; var value; var qname; var msg = "This is a required question - please answer and then continue."; var objSelectedCount; var objLimit; for(var i = 1; i <= qcount; i++){ qname="Q"+i; if (qtype(qname) == "99") {continue}; requiredobj = eval("document.forms[1]."+qname+"Required"); if (requiredobj.value=="1"){ obj = eval("document.forms[1]."+qname); otherobj = eval("document.forms[1]."+qname+"Other"); switch (qtype(qname)){ case "1-1": //radio buttons value=getRBvalue(obj); questionOK = !(value==""); focusobj=obj.length?obj[0]:obj; if(value=="Other"){ //-- Fix if "Other Text" field not available.... if (doesFieldExist( "document.forms[1]."+qname+"Other" )==true){ // Only validate the "Other Text" field if it actually exists on the form... //questionOtherOK=!(otherobj.value == ""); ---LW July 27, 2005 questionOtherOK=!(Trim(otherobj.value) == "") focusobj=otherobj; } else { questionOtherOK = true; } //- end.... } break; case "1-2": // combobox questionOK=(obj.selectedIndex > 0); focusobj=obj; if(questionOK && (obj.options[obj.selectedIndex].text=="Other")){ //-- if "Other Text" field not available.... if (doesFieldExist( "document.forms[1]."+qname+"Other" )==true){ // Only validate the "Other Text" field if it actually exists on the form... //questionOtherOK=!(otherobj.value==""); ---LW July 27, 2005 questionOtherOK=!(Trim(otherobj.value) == "") focusobj=otherobj; } else { questionOtherOK = true; } //- end... } break; case "1-3": // 2004-11-14 BG - Sliders // nothing to see here...ok set the value of the slider to the Qx field value slider_set_value(window.sliders[i-1],i); focusobj=obj; break; case "2": //checkboxes if(obj.length) { objSelectedCount = 0; questionOK=false; for(var n=0; n objLimit.value) { msg = 'Please provide at most ' + objLimit.value + ' answers to this question'; questionOK = false; } break; } } } else{ questionOK=obj.checked; focusobj=obj; } break; case "3": //textbox // Add in additional check for "Numeric Entry Only" and check upper/lower limits.... //----Ensure that a value has been entered here.... var trimmedObj; // trimmedObj=Trim(obj); trimmedObj=obj; //questionOK=!(trimmedObj.value==""); ---- LW July 27, 2005 questionOK=!(Trim(trimmedObj.value)==""); focusobj=obj; if (questionOK==false){ break; } //-- Now, check to see if this answer is Numeric Only. If so, check that value is number and //-- that it has not exceed Upper/Lower number limit (if any specified).... strNumericEntryOnly = eval("document.forms[1].NumericEntryOnly_" + qname + ".value"); if (strNumericEntryOnly=="2"){ // Answer is text -- we've already done all validation that we need to on this form. break } // Numeric Entry Only -- ensure value entered is numeric, and is within Upper/Lower limit range... strCheckValue = obj.value; if (isNumber(strCheckValue)==false){ msg = "Please enter numbers only."; questionOK = false; break; } intCheckValue = parseInt( strCheckValue, 10 ); // Ensure that value entered is within allowed upper/lower limit range (if any specified).... strLowerLimit = eval("document.forms[1].NumericLowerLimit_" + qname + ".value"); strUpperLimit = eval("document.forms[1].NumericUpperLimit_" + qname + ".value"); if (strLowerLimit!=""){ //- Only check if a lower limit was specified.... intLowerLimit = parseInt( strLowerLimit, 10 ); if (intCheckValue < intLowerLimit){ msg = "The number entered is lower than the range specified by the Lower Limit (" + intLowerLimit + ")."; questionOK = false; break; } } if (strUpperLimit!=""){ //- Only check if an upper limit was specified.... intUpperLimit = parseInt( strUpperLimit, 10 ); if (intCheckValue > intUpperLimit){ msg = "The number entered is greater than the range specified by the Upper Limit (" + intUpperLimit + ")."; questionOK = false; break; } } //-- end.... break; case "4": //texarea //questionOK=!(obj.value==""); ---- LW July 27, 2005 questionOK=!(Trim(obj.value)==""); focusobj=obj; break; case "5": //multipoint var rowsobj; var mpvalues; mpvalues = new Array(); rowsobj = eval("document.forms[1]."+qname+"Rows"); for(n = 0; n < Number(rowsobj.value); n++){ obj = eval("document.forms[1]."+qname+"S"+(n+1)); mpvalues[n]=getRBvalue(obj,"-"); questionOK=!(mpvalues[n]=="-"); if(!questionOK){ focusobj=obj.length?obj[0]:obj; break; } } if (questionOK && !allowties(qname)){ if(!uniquearr(mpvalues)){ msg = 'This question does not support duplicate answers. Please make sure each ranking is unique.'; questionOK = false; focusobj=obj.length?obj[0]:obj; } } break; } questionOK = questionOK && questionOtherOK; if(!questionOK){ alert(questionOtherOK?msg:msg +'\nThe other answer is missing.'); focusobj.focus(); return questionOK; } } //Multipoint, Not required, No ties - question // Created by Robert C. - Oct. 10/01. // This section checks for question which have the following: // 1. No Required Answer. // 2. Allow Ties Turned OFF. // Review the change in the "uniquearr" function, to suit this function. if (requiredobj.value=="2" && qtype(qname)=="5"){ var rowsobj; var mpvalues; mpvalues = new Array(); rowsobj = eval("document.forms[1]."+qname+"Rows"); for(n = 0; n < Number(rowsobj.value); n++){ obj = eval("document.forms[1]."+qname+"S"+(n+1)); mpvalues[n]=getRBvalue(obj,"-"); } if (questionOK && !allowties(qname)){ if(!uniquearr(mpvalues)){ msg = 'This question does not support duplicate answers. Please make sure each ranking is unique.'; alert(msg); questionOK = false; focusobj=obj.length?obj[0]:obj; focusobj.focus(); } } } //Multipoint, Not required, No ties - question } return questionOK; } function prevsubmitsurvey(){ document.Survey.SurveyAction.value='PREV'; document.Survey.submit(); } function nextSubmit(action){ if(submitted) return; document.Survey.SurveyAction.value=action; if (validatedata()){ document.Survey.submit(); submitted=true; } } //- LW Nov01, 2004 for Survey Reset and Question Reset buttons function quesResetSurvey(){ document.Survey.SurveyAction.value='QUESRESET'; document.Survey.submit(); } function surveyResetSurvey(){ document.Survey.SurveyAction.value='SURVEYRESET'; document.Survey.submit(); } //- "Other" field fix. function doesFieldExist( fieldName ){ //- Used when validating Other field. Sometimes, a user may add "Other" in manually as a selection option, and //- not required an "Other" text field. If the value of a button is "Other", then before validating the "Other Text" field, //- ensure that it actually exists. if (fieldName.indexOf("document.forms[") > -1){ var intLen = fieldName.length; var intStart = 18; var intEnd = intLen - intStart; var checkField = fieldName.substring( intStart ); var checkForm = fieldName.substring( 0, intStart); } else { var checkField = fieldName; var checkForm = "document.forms[1]."; } var searchString = checkForm + "elements;" var objList = eval( searchString ); if (objList.length < 0) return false; for (i=0; i <= objList.length; i++){ var obj = objList[i]; if (obj != null){ if (obj.name==checkField){ return true; } } } return false; } //- end // 2004-11-?? - LW - to support web upload function openFloatWindow(){ href=location.href.toLowerCase(); pos=href.lastIndexOf('.ns', href.length-1); dbpath=href.substring(0,pos+4); opts="toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=300,height=150,alwaysRaised"; //var theDocID = document.forms[0].appDocID.value; formname="/frmwebupload?Openform"; floatWindow=window.open(dbpath+formname, "Confirmation",opts) }