	function AjaxHelper() {
  this.initialize.apply(this, arguments);
}
AjaxHelper.prototype = {
  initialize: function(renderingStrategy, errorPageUrl, exceptionHandler) {
    this.renderingStrategy = renderingStrategy;
    this.errorPageUrl = errorPageUrl;
    if(exceptionHandler == null) {
      this.onException = this.handleException;
    } else {
      this.onException = exceptionHandler;
    }
  },
  handleResponse: function(response) {
    if(response == null) {
      this.onException(response);
    }
    if(response.error != null) {
      this.onException(response);
      return;
    }
    this.renderingStrategy(response);
  },
  handleException: function(response) {
    location.href = this.errorPageUrl;
  }
}

var ElementUtil = {
  getElementById: function(id) {
    if(StringUtil.isNullString(id)) {
      return null;
    }
    var element;
    if(document.getElementById) {
      element = document.getElementById(id);
      if(element == null) {
		element = document.getElementById(id.replace(":", "_"));
	   }
    } else if (document.all) {
      element = document.all(id);
    } else if (document.layers) {
      for(var i = 0; i < document.forms.length; i++) {
        for(var j = 0; j < document.forms[i].elements.length; j++) {
          if(document.forms[i].elements[j].name == id) {
            element = document.forms[i].elements[j];
            break;
          }
        }
        if(element != null) {
          break;
        }
      }
    }
    return element;
  },
  getLayerById: function(id) {
    if(StringUtil.isNullString(id)) {
      return null;
    }
    var element;
    if(document.getElementById) {
      element = document.getElementById(id);
    } else if (document.all) {
      element = document.all(id);
    } else if (document.layers) {
      element = document.layers[id];
    }
    return element;
  },
  getValueById: function(id) {
    if(StringUtil.isNullString(id)){
      return null;
    }
    return this.getElementById(id).value;
  },
  setValueById: function(id, value) {
    if(StringUtil.isNullString(id)) {
      return;
    }
    this.getElementById(id).value = value;
  },
  writeHTMLById: function(id, html) {
    if(StringUtil.isNullString(id)) {
      return;
    }
    var element = this.getLayerById(id);
    if(document.getElementById) {
      element.innerHTML = html;
    } else if(document.all) {
      element.innerHTML = html;
    } else if(document.layers) {
      with(element.document) {
        open();
        write(html);
        close();
      }
    }
  },
  eraseHTMLById: function(id) {
    if(StringUtil.isNullString(id)) {
      return;
    }
    var element = this.getLayerById(id);
    if(document.getElementById) {
      element.innerHTML = "";
    } else if (document.all) {
      element.innerHTML = "";
    } else if (document.layers) {
      with(element.document) {
        open();
        write("");
        close();
      }
    }
  },
  showLayer: function(id) {
    if(StringUtil.isNullString(id)) {
      return;
    }
    var element = this.getLayerById(id);
    if(document.getElementById) {
      element.style.visibility = "visible";
    } else if (document.all) {
      element.style.visibility = "visible";
    } else if (document.layers) {
      element.visibility = "show";
    }
  },
  hideLayer: function(id) {
    if(StringUtil.isNullString(id)) {
      return;
    }
    var element = this.getLayerById(id);
    if(document.getElementById) {
      element.style.visibility = "hidden";
    } else if (document.all) {
      element.style.visibility = "hidden";
    } else if (document.layers) {
      element.visibility = "hide";
    }
  }
}

var CheckBoxUtil = {
  checkAll: function(formName, elementName) {
    this.changeCheckState(formName, elementName, true);
  },
  uncheckAll: function(formName, elementName) {
    this.changeCheckState(formName, elementName, false);
  },
  changeCheckState: function(formName, elementName, state) {
    if(StringUtil.isNullString(formName) || StringUtil.isNullString(elementName)) {
      return;
    }
    var element = document.forms[formName].elements[elementName];
    if(!this.isCheckBox(element)) {
      return;
    }
    if(element.length > 0) {
      for(var i = 0; i < element.length; i++) {
        element[i].checked = state;
      }
    } else {
      element.checked = state;
    }
  },
  isCheckBox: function(element) {
    if(element == null) {
      return false;
    }
    if(element.length > 0) {
      return (element[0].type == "checkbox");
    } else {
      return (element.type == "checkbox");
    }
  }
}

var StringUtil = {
  isNullString: function(string) {
    if((string == "") || (string == null)) {
      return true;
    }
    return false;
  },
  trim: function(value) {
    if(this.isNullString(value)) {
      return value;
    }
    return this.trimEnd(this.trimStart(value));
  },
  trimStart: function(value) {
    if(this.isNullString(value)) {
      return value;
    }
    return this.trimExpStart(value, "\\s@");
  },
  trimEnd: function(value) {
    if(this.isNullString(value)) {
      return value;
    }
    return this.trimExpEnd(value, "\\s@");
  },
  trimExp: function(value, exp) {
    if(this.isNullString(value)) {
      return value;
    }
    if(this.isNullString(exp)) {
      return value;
    }
    return this.trimExpEnd(this.trimExpStart(value, exp), exp);
  },
  trimExpStart: function(value, exp) {
    if(this.isNullString(value)) {
      return value;
    }
    if(this.isNullString(exp)) {
      return value;
    }
    return value.replace(eval("/^[" + exp + "]+/"), "");
  },
  trimExpEnd: function(value, exp) {
    if(this.isNullString(value)) {
      return value;
    }
    if(this.isNullString(exp)) {
      return value;
    }
    return value.replace(eval("/[" + exp + "]+$/"), "");
  },
  startsWith: function(value, prefix) {
    if(this.isNullString(value)) {
      return false;
    }
    if(this.isNullString(prefix)) {
      return true;
    }
    if(prefix.length > value.length) {
      return false;
    }
    return (prefix == value.substring(0, prefix.length));
  
  },
  endsWith: function(value, suffix) {
    if(this.isNullString(value)) {
      return false;
    }
    if(this.isNullString(suffix)) {
      return true;
    }
    if(suffix.length > value.length) {
      return false;
    }
    return (suffix == value.substring(value.length - suffix.length));
  },
  format: function(value, args) {
    if(StringUtil.isNullString(value)){
      return value;
    }
    if(args == null) {
      return value;
    }
    var replacedValue = value;
    for(var i = 0; i < args.length; i++) {
      replacedValue = replacedValue.replace("{" + i + "}", args[i]);
    }
    return replacedValue;
  }
}

var TextBoxUtil = {
	countLength : function(stringToCount,writeobj){
		
		do{
			before = stringToCount;
			stringToCount = stringToCount.replace("\r\n","--");
			if(before != stringToCount){
				continue;
			}
			stringToCount = stringToCount.replace("\n","--");
		}while(before != stringToCount)
		
		var len = stringToCount.length;
		
		
		var tagObj = document.getElementById(writeobj);
		
		if (navigator.userAgent.indexOf("Firefox") > -1) {
		    tagObj.textContent = len;
		}else{
		    tagObj.innerHTML = len;
		}
	}
}