function JSNetUi() {
  this.names = [];

  this.anchorFormSubmit = function(netuiName, newAction) {
    for (var i=0; i < document.forms.length; i++) {
      var f = document.forms[i];
      if (f.id == netuiName) {
         f.method = "POST";
         f.action = newAction;
	 if (f.submitContent) {
	   f.submitContent()
	 } else {
           f.submit();
	 }
      }
    }
  }

  this.setFocus = function(netuiFormName, netuiInputName) {
    var f = document.forms[netuiFormName];
    if (f) {
      var i = f[netuiInputName];
      if (i && i.type != "hidden") {
        i.focus();
      }
    }
  }

  this.swapImage = function (control, image) {
    control.src = image;
  }

  this.addMapping = function(name, realName) {
    this.names[name] = realName;
  }

  this.getMapping = function(name) {
	this.overrideDeprecateNetui();
  	if ( this.netuiOverrided ) {
	    return this.getLocalMapping(name);
  	} else {
  		return window.getNetuiTagName(name);
    }
  }
  
  this.getLocalMapping = function(name) {
    return this.names[name];
  }
  
  this.getNetuiTagName = function(id, tag){
   var scopeId = NetUi.getScopeId(tag);
   if (scopeId == "") {
      return NetUi.getMapping(id);
   } else {
      return NetUi.getMapping(scopeId  + "__" + id);
   }
  }
  
  this.getScopeId = function(tag){
	if (tag == null){
		return "";
	}
	if (tag.getAttribute) { 
		if (tag.getAttribute('scopeId') != null){
			return tag.getAttribute('scopeId');
		}
	}
	if (tag.scopeId != null){
		return tag.scopeId;
	} else {
		return this.getScopeId(tag.parentNode);
	}
  }
  
  this.overrideDeprecateNetui = function(){
	if ( typeof this.netuiOverrided == 'undefined' ) {
		this.netuiOverrided = typeof getNetuiTagName == 'undefined';
	  	if ( this.netuiOverrided ) {
	  		window.getNetuiTagName = this.getNetuiTagName;
	  	}
	}
  }

}

var NetUi = new JSNetUi();