function setFormIcon(ctrl, type,txt) { var n = ctrl + "_icon"; var cn = "formFieldIcon formField" + type; var ref = document["getElementById"](n); if (!ref) { var d = document.createElement("div"); d.className = cn; d.id = n; document["getElementById"](ctrl).appendChild(d); } else { ref.className = cn; } var tn = ctrl + "_errtxt"; var ref2 = document["getElementById"](tn); if (ref2) { var refPar = ref2.parentNode; refPar.removeChild(ref2); } if (txt != "" && txt != "undefined" && txt != undefined) { var d = document.createElement("div"); d.id = tn; d.className="formFieldErrorText"; document["getElementById"](ctrl).appendChild(d); d.innerHTML = txt; } } function onlyNumbers(strString) // check for valid numeric strings { var strValidChars = "0123456789"; var strChar; var blnResult = true; if (strString.length == 0) return false; // test strString consists of valid characters listed above for (i = 0; i < strString.length && blnResult == true; i++) { strChar = strString.charAt(i); if (strValidChars.indexOf(strChar) == -1) { blnResult = false; } } return blnResult; } function FormHandler(formName) { this.frmName_ = formName; this.fields_ = new Array(); this.frm_ = document["getElementById"](formName); this.registerField = function (field) { field.init(this.frm_[field.name_]); this.fields_.push(field); } this.getForm = function() { return this.frm_; } } function FormField(name,tooltip,validator) { this.TEXT = "text"; this.EMAIL = "email"; this.STATE_NONE = 0; this.STATE_ERROR = 1; this.STATE_OK = 2; this.name_ = name; this.tooltip_ = tooltip; this.container_ = null; this.onErrorHandler_ = null; this.onChangeHandler_ = null; this.state_ = this.STATE_NONE; this.validator_ = validator; this.tooltipClass = "formStatusBoxTooltip"; this.errorClass = "formStatusBoxError"; this.doBlur = function () { this.showStatus(false); var validated = true; if (this.container_.value.length == 0) { if (this.state_ == this.STATE_OK) this.updateState(this.STATE_NONE); //this.updateState(this.STATE_NONE); return; } if (this.validator_ != null) { if (!this.validator_.validate(this.container_.value)) { this.setError(this.tooltip_); validated = false; } else this.setOk(); } else { this.setOk(); } if (this.onChangeHandler_ != null) this.onChangeHandler_(this, validated); } this.getField = function() { return this.container_; } this.doFocus = function() { this.showStatus(true); } this.doSelectboxChange = function() { this.doBlur(); } this.showStatus = function(visible) { if (visible) document["getElementById"](this.name_ + "Status").style.display = ""; else document["getElementById"](this.name_ + "Status").style.display = "none"; var className = this.tooltipClass; switch(this.state_) { case this.STATE_NONE: className = this.tooltipClass; break; case this.STATE_ERROR: className = this.errorClass; break; case this.STATE_OK: className = this.tooltipClass; document["getElementById"](this.name_ + "Status").style.display = "none"; break; default: break; } document["getElementById"](this.name_ + "Status").className = className; } this.setStatusText = function(txt) { document["getElementById"](this.name_ + "StatusInner").innerHTML = txt; } this.updateState = function(state) { this.state_ = state; var ref = document["getElementById"](this.name_ + "Icon"); switch(this.state_) { case this.STATE_NONE: ref.src = "/images/formfield_default.gif"; break; case this.STATE_ERROR: ref.src = "/images/formfield_err.gif" break; case this.STATE_OK: ref.src = "/images/formfield_ok.gif"; break; default: ref.src = "/images/formfield_default.gif"; break; } } this.setError = function(txt) { this.updateState(this.STATE_ERROR); this.setStatusText(txt); } this.setOk = function() { this.updateState(this.STATE_OK); this.setStatusText(this.tooltip_); } this.setDefault = function() { this.updateState(this.STATE_NONE); this.setStatusText(this.tooltip_); } this.init = function(container) { this.container_ = container; var r = this; this.createStatusBox(); if (this.container_.type.indexOf("select") > -1) { //this.container_.onchange = function() { r.doSelectboxChange(); }; } else { this.container_.onblur = function() {r.doBlur();}; this.container_.onfocus = function() {r.doFocus();}; } this.setStatusText(this.tooltip_); } this.createStatusBox = function () { var d = document.createElement("span"); d.style.position = "relative"; var parentNode = this.container_.parentNode; parentNode.replaceChild(d,this.container_); d.appendChild(this.container_); var bb = document.createElement("span"); bb.className = "formStatusBoxContainer"; d.appendChild(bb); var icon = document.createElement("img"); icon.src="/images/formfield_default.gif"; icon.className = "formStatusIcon"; icon.id = this.name_ + "Icon"; bb.appendChild(icon); var e = document.createElement("span"); e.className = "formStatusBoxTooltip"; e.style.display = "none"; e.id = this.name_ + "Status"; var ee = document.createElement("div"); ee.className = "formStatusBoxInner"; ee.id = this.name_ + "StatusInner"; e.appendChild(ee); bb.appendChild(e); } this.getToolTip = function() { return this.tooltip_; } this.onError = function(handler) { this.onErrorHandler_ = handler; } this.onChange = function(handler) { this.onChangeHandler_ = handler; } } function TextValidator(min,max, regexp) { this.regexp_ = null; this.min_ = min; this.max_ = max; this.regexp_ = regexp; this.validate = function(value) { if (this.regexp_ != null) if (!this.regexp_.test(value)) return false; if (value.length == 0) return true; if (value.length >= this.min_ && value.length<= this.max_) return true; else return false; } } function EmailValidator() { this.validate = function(value) { var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if (filter.test(value)) { return true; } return false; } }