FormMap.prototype=new HashMap();
function FormMap(){
  var form;
  this.clear();  
  this.readForm=function(f){
    if(f!=null){
      form=f;
      for(var i=0;i<f.length;i++){
        if(f[i].name=='')continue;
        var value=getValue(f[i]);
        if (value==null)continue;
        if(this.containsKey(f[i].name)){
          var ary=this.get(f[i].name);
          if(ary instanceof Array) {
            ary.push(value);
          } else {
            this.set(f[i].name, new Array(ary,value));
          }
        } else {
          this.set(f[i].name,value);
        }
      }
    }
    function getValue(x){
      if(x==null)return null;
      var v=null;
      if (x.tagName.search(/input/i)==0){
        if(x.type.search(/text|hidden/i)==0){
          v=x.value;
        }else if(x.type.search(/radio|checkbox/i)==0){
          if(x.checked)v=x.value;
        }
      }else if(x.tagName.search(/select/i)==0){
        v='';
        for(var j=0;j<x.options.length;j++){
          if(x.options[j].selected)v+=','+x.options[j].value;
        }
        v=v.substr(1);
      }
      return v;
    }
  }
  this.getForm=function(){
    return form;
  }
  this.post=function(url, target){
    target=target||window;
    var ff=target.document.createElement('form');
    ff.action=url;
    ff.method='post';
    var keys=this.getKeys();
    for(var i=0;i<keys.length;i++){
      var value=this.get(keys[i]);
      if(value instanceof Array){
        for(var j=0;j<value.length;j++){
          ff.appendChild(createInput(keys[i],value[j]));
        }
      }else{
        ff.appendChild(createInput(keys[i],value));
      }
    }
    target.document.body.appendChild(ff);
    ff.submit();
    function createInput(name, value){
      var input=target.document.createElement('input');
      input.type='hidden';input.name=name;
      input.value=value;
      return input;
    }
  }
}