public void addScriptElements(IWContext iwc) { if (this.isShowDay) { if (this.showYear) { this.theYear.setOnChange( "iwPopulateDaysWithYear(this,this.form." + this.theMonth.getName() + ",this.form." + this.theDay.getName() + ",'" + this.dayString + "');iwSetValueOfHiddenDateWithAllInputs(this.form." + this.theYear.getName() + ",this.form." + this.theMonth.getName() + ",this.form." + this.theDay.getName() + ",this.form." + this.theWholeDate.getName() + ");"); this.theMonth.setOnChange( "iwPopulateDaysWithYear(this.form." + this.theYear.getName() + ",this,this.form." + this.theDay.getName() + ",'" + this.dayString + "');iwSetValueOfHiddenDateWithAllInputs(this.form." + this.theYear.getName() + ",this.form." + this.theMonth.getName() + ",this.form." + this.theDay.getName() + ",this.form." + this.theWholeDate.getName() + ");"); this.theDay.setOnChange( "iwSetValueOfHiddenDateWithAllInputs(this.form." + this.theYear.getName() + ",this.form." + this.theMonth.getName() + ",this.form." + this.theDay.getName() + ",this.form." + this.theWholeDate.getName() + ");"); } else { this.theMonth.setOnChange( "iwPopulateDaysWithMonth('" + this.selectedYear + "',this,this.form." + this.theDay.getName() + ",'" + this.dayString + "');iwSetValueOfHiddenDateWithDay('" + this.selectedYear + "',this.form." + this.theMonth.getName() + ",this.form." + this.theDay.getName() + ",this.form." + this.theWholeDate.getName() + ");"); this.theDay.setOnChange( "iwSetValueOfHiddenDateWithDay('" + this.selectedYear + "',this.form." + this.theMonth.getName() + ",this.form." + this.theDay.getName() + ",this.form." + this.theWholeDate.getName() + ");"); } } else { if (this.showYear) { this.theYear.setOnChange( "iwSetValueOfHiddenDateWithYear(this.form." + this.theYear.getName() + ",this.form." + this.theMonth.getName() + ",this.form." + this.theWholeDate.getName() + ");"); this.theMonth.setOnChange( "iwSetValueOfHiddenDateWithYear(this.form." + this.theYear.getName() + ",this.form." + this.theMonth.getName() + ",this.form." + this.theWholeDate.getName() + ");"); } else { this.theMonth.setOnChange( "iwSetValueOfHiddenDateWithMonth('" + this.selectedYear + "',this.form." + this.theMonth.getName() + ",'01',this.form." + this.theWholeDate.getName() + ");"); } } if (this.isSetAsNotEmpty) { if (this.showYear) { this.theYear.setAsNotEmpty(this.notEmptyErrorMessage, "YY"); } this.theMonth.setAsNotEmpty(this.notEmptyErrorMessage, "00"); if (this.isShowDay) { this.theDay.setAsNotEmpty(this.notEmptyErrorMessage, "00"); } } if (this.earliestDate != null) { if (getParentForm() != null) { Form form = getParentForm(); form.setOnSubmit("return checkSubmit(this)"); Script script = form.getAssociatedFormScript(); if (script == null) { script = new Script(); } if (script.getFunction("checkSubmit") == null) { script.addFunction("checkSubmit", "function checkSubmit(inputs){\n\n}"); } IWTimestamp earlyDate = new IWTimestamp(this.earliestDate.getTime()); earlyDate.setTime(0, 0, 0, 0); script.addToBeginningOfFunction( "checkSubmit", "if (checkEarliestDate (findObj('" + getName() + "')," + earlyDate.getDate().getTime() + ", '" + this.earliestDateErrorMessage + "') == false ){\nreturn false;\n}\n"); StringBuffer buffer = new StringBuffer(); buffer.append("function checkEarliestDate(input, date, warnMsg) {").append("\n\t"); buffer.append("var returnBoolean = true;").append("\n\t"); buffer.append("var dateString = input.value;").append("\n\t"); buffer.append("if (dateString.length > 0) {").append("\n\t\t"); buffer.append("var oldDate = new Date(date);").append("\n\t\t"); buffer.append("var month = dateString.substring(5,7) - 1;").append("\n\t\t"); buffer .append( "var newDate = new Date(dateString.substring(0,4),month,dateString.substring(8,10));") .append("\n\t\t"); buffer.append("var difference = oldDate - newDate;").append("\n\t\t"); buffer.append("if (difference > 0)").append("\n\t\t\t"); buffer.append("returnBoolean = false;").append("\n\t"); buffer.append("}").append("\n\n\t"); buffer.append("if (!returnBoolean)").append("\n\t\t"); buffer.append("alert(warnMsg);").append("\n\t"); buffer.append("return returnBoolean;").append("\n}"); script.addFunction("checkEarliestDate", buffer.toString()); form.setAssociatedFormScript(script); } } if (this.latestDate != null) { if (getParentForm() != null) { Form form = getParentForm(); form.setOnSubmit("return checkSubmit(this)"); Script script = form.getAssociatedFormScript(); if (script == null) { script = new Script(); } if (script.getFunction("checkSubmit") == null) { script.addFunction("checkSubmit", "function checkSubmit(inputs){\n\n}"); } script.addToFunction( "checkSubmit", "if (checkLatestDate (findObj('" + getName() + "')," + this.latestDate.getTime() + ", '" + this.latestDateErrorMessage + "') == false ){\nreturn false;\n}\n"); StringBuffer buffer = new StringBuffer(); buffer.append("function checkLatestDate(input, date, warnMsg) {").append("\n\t"); buffer.append("var returnBoolean = true;").append("\n\t"); buffer.append("var dateString = input.value;").append("\n\t"); buffer.append("if (dateString.length > 0) {").append("\n\t\t"); buffer.append("var oldDate = new Date(date);").append("\n\t\t"); buffer.append("var month = dateString.substring(5,7) - 1;").append("\n\t\t"); buffer .append( "var newDate = new Date(dateString.substring(0,4),month,dateString.substring(8,10));") .append("\n\t\t"); buffer.append("var difference = newDate - oldDate;").append("\n\t\t"); buffer.append("if (difference > 0)").append("\n\t\t\t"); buffer.append("returnBoolean = false;").append("\n\t"); buffer.append("}").append("\n\n\t"); buffer.append("if (!returnBoolean)").append("\n\t\t"); buffer.append("alert(warnMsg);").append("\n\t"); buffer.append("return returnBoolean;").append("\n}"); script.addFunction("checkLatestDate", buffer.toString()); form.setAssociatedFormScript(script); } } }