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;
  },
  getCookie: function (search_name) {
    var tab_cookies = document.cookie.split( ';' );
    for ( i = 0; i < tab_cookies.length; i++ ) {
      var cookie_tmp = tab_cookies[i].split('=');
      var cookie_name = cookie_tmp[0].replace(/^\s+|\s+$/g, '');
      if (cookie_name==search_name) {
        if (cookie_tmp.length>1) {
          return unescape( cookie_tmp[1].replace(/^\s+|\s+$/g, '') );
        }
        return null;
      }
    }
    return null;     
  }
};
ww.el = {
  auto_manipulate: function(objs) {
    for (var i in objs) {
      if (objs[i]) {
        if (typeof(objs[i])=='object') {
          if (typeof(objs[i].manipulate)=='function') objs[i].manipulate();
        }
      }
    }
  },
  options: function (arr, sMatchValue, sReplace) {
    var obj;
    var oReturn = [];
    for (var i=0;i<arr.length;i++) {
      obj = {inputValue: arr[i], boxLabel: arr[i]}
      if (typeof(sMatchValue)=='string') {
        if (arr[i]==sMatchValue) obj = {inputValue: sReplace, boxLabel: arr[i]};
      }
      oReturn.push(obj);
    }
    return oReturn
  },
  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;
  }
}
