var ww = ww||{};
if (!Ext.ww) Ext.ww = {}
ww.el = {
  alertDetails: function (objs) {
    var s='';
    for (var i in objs) s+=i+'; ';
    alert(s);
  },
  alertObjValues: function (objs) {
    var s='';
    for (var i in objs) s+= i + ' => ' + objs[i] + '; ';
    alert(s);
  },
  initConfig: function (tag) {
    var oInt = {}
    switch (tag) {
      case 'img': oInt = {border: 0}; break;
      case 'iframe': oInt = {frameBorder: 0}; break;
      default: break;
    }
    return oInt;
  },
  dom: function(tag, oExt) {
    oExt = (typeof(oExt)=='object')?oExt:{};
    var oInt = ww.extend(oExt, this.initConfig(tag));
    var El = document.createElement(tag);
    for (var i in oInt) if (i!='style') El[i] = oInt[i];
    var oReturn = Ext.get(El)
    if (oInt.style) oReturn.setStyle(oInt.style);
    return oReturn;
  },
  create: function(tag, oExt, renderTo, isHide, domBefore) {
    if (typeof(oExt)=='string') { renderTo=oExt; oExt={}; }
    renderTo = (typeof(oExt)=='string')?oExt:renderTo;
    oExt = (typeof(oExt)=='object')?oExt:{};

    var obj= null;var isInsertFrist = false;
    if (renderTo) { obj = Ext.fly(renderTo); } else {
      obj=Ext.getBody(); isInsertFrist=true;
    }
    if (!obj) { obj=Ext.getBody(); isInsertFrist=true; }
    /*var obj = (renderTo)?Ext.fly(renderTo):Ext.getBody();
    obj = obj||Ext.getBody();*/
    var oInt = ww.extend({tag: tag}, this.initConfig(tag));
    if (isHide) {oExt.style = (oExt.style||'') + 'display: none;';}
    var el = null;
    if (!isInsertFrist) el = obj.createChild(ww.extend(oInt, oExt), domBefore);
      else el = obj.insertFirst(ww.extend(oInt, oExt));
    return(el);
  },
  popup: function (renderTo, conf, fn, isHide, prtDiv) {
    conf = conf||{};
    conf.style = (conf.style||'') + ';text-align: center; background: #fff; border: 1px solid #e0e0e0;'
    var elReturn = this.create('div', conf, renderTo);
    elReturn.elTop = ww.el.create('div', {style: 'height: 10px;', html: '&nbsp;'}, elReturn);
    elReturn.elCont = ww.el.create('div', {}, elReturn);
    elReturn.elSub = ww.el.mount_panelClose(elReturn, fn, isHide, prtDiv);
    elReturn.add = function (tag, oExt, isHide, domBefore) {
      return (ww.el.create(tag, oExt, this.elCont, isHide, domBefore));
    }
    return (elReturn);
  },
  mount_panelClose: function (renderTo, fn, isHide, prtDiv) {
    var iWidth = (renderTo.dom.style.width)?'width: ' + renderTo.dom.style.width + ';':'';
    var divStyle = iWidth + 'height: 42; text-align: right; padding-top: 10px;' + ((isHide)?'display: none;':'');
    if (typeof(renderTo)!='object') return null;
    var elPanel = ww.el.create('div', {style: divStyle, cls: (prtDiv||'')}, renderTo);
    elPanel.elSpacer = this.create('img', {src: '/admin/img/ext/s.gif', width:10, Height:22, cls: prtDiv}, elPanel);
    elPanel.elClose = this.create('img', {src: '/admin/img/common/sb_closelabel.gif', style: 'cursor: pointer;'}, elPanel);
    elPanel.elClose.elMain = renderTo;
    if (typeof(fn)=='boolean') {
      if (fn) {
        fn=function () {
          this.elMain.setVisible(false, {duration: .3, callback: function () { this.dom.style.display='none' }});
        }
      }
    }
    fn = fn||function () {
      this.elMain.setVisible(false, {duration: .3,
        callback: function () { this.elMain.remove(); },
        scope: this
      });
    }
    elPanel.elClose.on('click', fn);
    return elPanel;
  }
}
