var ww = ww||{
  msg: function (msgText) {
    ww.msgbox.show('Windows', msgText);
  },
  msgbox: {
    show: function (msgTitle, msgText, msgIcon, msgButton, oExtend) {
      var oInit = {
        title: (msgTitle)?msgTitle:'Window',
        msg: msgText,
        minWidth: 500,
        modal: true,
        icon: msgIcon,
        buttons: (msgButton)?msgButton:Ext.Msg.OK
      }
      oInit = ww.extend(oInit, oExtend);
      Ext.Msg.show(oInit);
    },
    alert: function (msgTitle, msgText) {
      Ext.Msg.alert((msgTitle)?msgTitle:'Windows', msgText);
    },
    prompt: function (msgTitle, msgText, fnCallback) {
      Ext.Msg.prompt((msgTitle)?msgTitle:'Windows', msgText, function(btn, sInput){
          if (btn == 'ok'){
              fnCallback(sInput);
          }
      });
    },
    confirm: function (msgText, fnYes, fnNo) {
      this.fnYes = (typeof(fnYes)=='function')?fnYes:ww.empty('function');
      this.fnNo = (typeof(fnNo)=='function')?fnNo:ww.empty('function');
      ww.msgbox.yn(msgText, {
        fn: function (btn) {
          if (btn=='yes') ww.msgbox.fnYes();
          if (btn=='no') ww.msgbox.fnNo();
          ww.msgbox.fnYes = ww.empty('function');
          ww.msgbox.fnNo = ww.empty('function');
        }
      });
    },
    err: function (msgText, oExtend) {
      ww.msgbox.show('Error', msgText, Ext.Msg.ERROR, Ext.Msg.OK, oExtend);
    },
    warning: function (msgText, oExtend) {
      ww.msgbox.show('Warning', msgText, Ext.Msg.WARNING, Ext.Msg.OK, oExtend);
    },
    info: function (msgText, oExtend) {
      ww.msgbox.tInfo('Information', msgText, oExtend);
    },
    tInfo: function (msgTitle, msgText, oExtend) {
      ww.msgbox.show(msgTitle, msgText, Ext.Msg.INFO, Ext.Msg.OK, oExtend);
    },
    cancel: function (msgText, oExtend) {
      ww.msgbox.show('Information', msgText, Ext.Msg.INFO, Ext.Msg.CANCEL, oExtend);
    },
    yn: function (msgText, oExtend) {
      ww.msgbox.show('Question', msgText, Ext.Msg.QUESTION, Ext.Msg.YESNO, oExtend);
    },
    yncancel: function (msgText, oExtend) {
      ww.msgbox.show('Question', msgText, Ext.Msg.QUESTION, Ext.Msg.YESNOCANCEL, oExtend);
    },
    okcancel: function (msgText, oExtend) {
      ww.msgbox.show('Question', msgText, Ext.Msg.QUESTION, Ext.Msg.OKCANCEL, oExtend);
    }
  },
  _extendFunction: function (st, nd, isAppendTop) {
    if (typeof(st) != 'function') return st;
    if (typeof(nd) != 'function') return st;
    sParam = this.getFunction_parameters(st);
    if (!isAppendTop) {
      eval('var newFunc = function ' + sParam + '{' + this.getFunction_code(st) + ';' + this.getFunction_code(nd) + '}');
    } else {
      eval('var newFunc = function ' + sParam + '{' + this.getFunction_code(nd) + ';' + this.getFunction_code(st) + '}');
    }
    return newFunc;
  },
  _extendJSON: function (st, nd) {
    if (typeof(st) != 'object') return st;
    if (typeof(nd) != 'object') return st;
    var newJSON = st;
    for(var i in nd) newJSON[i] = nd[i];
    return newJSON;
  },
  extend: function (st, nd, isAppendTop) {
    if ((typeof(st) == 'object') && (typeof(nd) == 'object')) return this._extendJSON(st, nd);
    if ((typeof(st) == 'function') && (typeof(nd) == 'function')) return this._extendFunction(st, nd, isAppendTop);
    return st;
  },
  apply: function (C, D, B) {
    if (B) ww.apply(C, B);
    if (C && D && typeof(D) == "object") {
      for (var A in D) C[A] = D[A];
    }
    return C;
  },
  isNullOrUndefined: function (obj) {
    if (obj==null) return true;
    if (typeof(obj)=='undefined') return true;
    return false;
  },
  clone: function (obj) {
    if(ww.isNullOrUndefined(obj)) return obj;
    var oReturn = new obj.constructor();
    for (var i in obj) {
      if (typeof(obj[i]) == 'object') oReturn[i] = ww.clone(obj[i]);
        else oReturn[i] = obj[i];
    }
    return oReturn;
  },
  dbStore: {
    JSON: function (key, oFields, oParams) {
      return (
        new Ext.data.JsonStore({
          proxy: new Ext.data.HttpProxy({
            url: '/CMSControl/storage.asp'
          }),
          baseParams: ww.extend((oParams||{}), {key: key||''}),
          root: 'records',
          totalProperty: 'totalCount',
          fields: oFields
        })
      );
    }
  },
  location: {
    getProtocol: function () {
      var sn = document.location.toString();
      return ((sn.indexOf('https') > -1)?'https://':'http://');
    },
    domainname: function () {
      var sn = document.location.toString();
      sn = (sn.indexOf('https') > -1)?sn.replace('https://', ''):sn.replace('http://', '');
      sn = sn.substring(0, sn.indexOf('/'));
      return sn;
    },
    filename: function () {
      var sn = document.location.toString();
      sn = sn.substring(sn.lastIndexOf('/')+1, sn.length);
      if (sn.indexOf('?') > 0) sn = sn.substring(0, sn.indexOf('?'));
      if (sn.indexOf('#') > 0) sn = sn.substring(0, sn.indexOf('#'));
      return sn;
    },
    scriptname: function () {
      var sn = document.location.toString();
      sn = (sn.indexOf('https') > -1)?sn.replace('https://', ''):sn.replace('http://', '');
      sn = sn.substring(sn.indexOf('/'), sn.length);
      if (sn.indexOf('?') > 0) sn = sn.substring(0, sn.indexOf('?'));
      if (sn.indexOf('#') > 0) sn = sn.substring(0, sn.indexOf('#'));
      return sn;
    },
    scriptpath: function () {
      var url = document.location.toString();
      var sn = ww.doc.scriptname(url);
      var fn = ww.doc.filename(url);
      return sn.substring(0, sn.length - fn.length);
    },
    details: function () {
      var url = document.location.toString();
      return {
        http: ww.doc.getProtocol(url),
        dn: ww.doc.domainname(url),
        sn: ww.doc.scriptname(url),
        fn: ww.doc.filename(url),
        path: ww.doc.scriptpath(url)
      }
    }
  }
};
ww.el = {
  getObject_viaSingle: function (obj, arrName, indexOf, isIndexAsValue) {
    indexOf = indexOf||0;
    if (indexOf.parseInt) indexOf=indexOf.parseInt();

    var oReturn = {}
    oReturn[arrName[1]] = (typeof(obj)=='string')?obj:'';
    oReturn[arrName[0]] = (isIndexAsValue)?indexOf:oReturn[arrName[1]];
    if (typeof(obj)=='object') {
      var iCur = 0;
      for (var i in  obj) {
        if (iCur++ == indexOf) {
          var oReturn = {}
          oReturn[arrName[0]] = i;
          oReturn[arrName[1]] = obj[i];
          break;
        }
      }
    }
    return oReturn;
  },
  alertDetails: function (objs) {
    var s='';
    for (var i in objs) {
      if ((typeof(objs[i]) == 'string') || (typeof(objs[i]) == 'number')) s+=i+' ==> '+objs[i]+'; ';
        else s+=i+' ==> '+typeof(objs[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);
  },
  removeHTML: function (sHTML) {
    var sReturn = sHTML
    sReturn = sReturn.replace(/<[bB][rR]?[^>]+\/?>/gi, ' ');
    sReturn = sReturn.replace(/<\/[tT][aA][bB][lL][eE]?[^>]+>/gi, '</table> ');
    sReturn = sReturn.replace(/<\/[dD][iI][vV]?[^>]+>/gi, '</div> ');
    sReturn = sReturn.replace(/<\/[pP]?[^>]+>/gi, '</p> ');
    sReturn = sReturn.replace(/<.*?>/gi, '');
    sReturn = sReturn.replace('\r', '');
    sReturn = sReturn.replace('\n', ' ');
    var iDblSpace = sReturn.indexOf('  ');
    while (iDblSpace>-1) {
      sReturn = sReturn.replace(/  /gi, ' ');
      iDblSpace = sReturn.indexOf('  ');
    }
    return sReturn;
  }
}

