
/** version: 1.2.1 */

// ED = ETERNA_DEBUG, FN = FUNCTION, FNC = FUNCTION_CALLED, COM = COMPONENT
var ED_GET_VALUE = 0x1;
var ED_EXECUTE_SCRIPT = 0x2;
var ED_SHOW_CREATED_HTML = 0x4;
var ED_SHOW_OTHERS = 0x8;
var ED_BASE = 0x10;
var ED_HIGHER = 0x80;
var ED_FN_CALLED = 0x30;
var ED_FNC_STACK = 0x40;
var ED_COM_CREATED = 0x20;

// EE = ETERNA_EVENT
var EE_SET_PARENT_ETERNA = "eterna_parent";
var EE_SUB_WINDOW_CLOSE = "lock_close";
var eterna_table_td_empty_value = "&nbsp;";
var eterna_tableForm_title_pluse = "";
var eterna_tableForm_requared_fn = function (tdObjTitle, tdObjContainer, cellConfig, _eterna)
{
   if (tdObjTitle != null)
   {
      tdObjTitle.html("<font color=\"red\">*</font>" + tdObjTitle.html());
   }
};
var eterna_tableList_title_fn = function (columnConfig, titleObj, titleValue, upTitle, _eterna)
{
   if (titleValue.exists && titleValue.value != "")
   {
      if (titleValue.html)
      {
         titleObj.html(titleValue.value);
      }
      else
      {
         titleObj.text(titleValue.value);
      }
   }
   else
   {
      titleObj.html(eterna_table_td_empty_value);
   }
};
var eterna_select_default_value = [["","-不限-"]];

var eterna_com_stack = new Array();
var eterna_fn_stack = new Array();

// eg = eterna_globe
var EG_SMA = "searchManager_attributes";
var EG_DATA_TYPE = "dataType";
var EG_DATA_TYPE_ONLYRECORD = "onlyRecord";
var EG_DATA_TYPE_ALL = "all";
var EG_DATA_TYPE_WEB = "web";

var eg_cache = {
   openWindowOnLoad:[], openWindowOnLoad_threadStarted:false,
   willInitEterna:{}, willInitEterna_threadStarted:false,
   willInitObjs:[]
};

var EG_TEMP_NAMES = [
   "dataName", "srcName", "index", "columnCount", "rowNum",
   "rowType", /* row, title, beforeTable, afterTable, beforeTitle, afterTitle, beforeRow, afterRow */
   "name", "caption", "valueObj", "param", "tempData"
];

var eg_temp = {};

var eg_caculateWidth_fix;
var eg_defaultWidth = 80;


function Eterna(eternaData, eterna_debug, rootWebObj)
{
   this.initOver = false;

   this.eternaData = eternaData
   this.eterna_debug = eterna_debug;
   this.rootWebObj = rootWebObj;

   this.windowArray = new Array();
   this.nowWindow = null;
   this.rootWebObjOld_HTML = this.rootWebObj.html();

   function closeAllWindow()
   {
      for (var i = 0; i < closeAllWindow._eterna.windowArray.length; i++)
      {
         if (!closeAllWindow._eterna.windowArray[i].closed)
         {
            closeAllWindow._eterna.windowArray[i].close();
         }
      }
   }
   jQuery(window).unload(closeAllWindow);
   closeAllWindow._eterna = this;

   if(typeof Eterna._initialized == 'undefined' || Eterna._oldDebug != eterna_debug)
   {
      Eterna._initialized = true;
      Eterna._oldDebug = eterna_debug;

      Eterna.prototype.egTemp = function(temp)
      {
         var key;
         if (temp != null)
         {
            for(key in eg_temp)
            {
               eg_temp[key] = null;
            }
            for (var i = 0; i < EG_TEMP_NAMES.length; i++)
            {
               key = EG_TEMP_NAMES[i];
               if (temp[key] != null)
               {
                  eg_temp[key] = temp[key];
               }
            }
            return eg_temp;
         }
         else
         {
            temp = {};
            for (var i = 0; i < EG_TEMP_NAMES.length; i++)
            {
               key = EG_TEMP_NAMES[i];
               if (eg_temp[key] != null)
               {
                  temp[key] = eg_temp[key];
               }
            }
            return temp;
         }
      }

      Eterna.prototype.egTempParam = function(copy)
      {
         if (eg_temp.param == null)
         {
            eg_temp.param = {};
         }
         else
         {
            if (copy)
            {
               eg_temp.param = this.cloneJSON(eg_temp.param);
            }
         }
         return eg_temp.param;
      }

      Eterna.prototype.egTempData = function(copy)
      {
         if (eg_temp.tempData == null)
         {
            eg_temp.tempData = {};
         }
         else
         {
            if (copy)
            {
               eg_temp.tempData = this.cloneJSON(eg_temp.tempData);
            }
         }
         return eg_temp.tempData;
      }

      Eterna.prototype.isArray = function(obj)
      {
         return jQuery.isArray(obj);
      }

      Eterna.prototype.createJSON = function()
      {
         return {};
      }

      Eterna.prototype.cloneJSON = function(obj)
      {
         if (typeof obj == "object")
         {
            if (this.isArray(obj))
            {
               var newObj = [];
               for(var i = 0; i < obj.length; i++)
               {
                  newObj[i] = this.cloneJSON(obj[i]);
               }
               return newObj;
            }
            else
            {
               var newObj = {};
               for(var key in obj)
               {
                  newObj[key] = this.cloneJSON(obj[key]);
               }
               return newObj;
            }
         }
         else
         {
            return obj;
         }
      }

      Eterna.prototype.getRemoteJSON = function(url, formObj, async, successFunction, completeFunction)
      {
         var httpRequest = null;
         var successFn = function (data, textStatus)
         {
            successFn.data = data;
            successFn.status = textStatus;
            if ((successFn.eterna_debug & ED_SHOW_CREATED_HTML) != 0 && successFn.httpRequest != null)
            {
               successFn._eterna.showMessage(successFn.httpRequest.responseText
                     + "\n---------------------------------\n" + "status:" + successFn.status + ",url:" + url);
            }
            if (successFn.customerFn)
            {
               successFn.customerFn(data, textStatus);
            }
         }
         successFn.eterna_debug = this.eterna_debug;
         successFn._eterna = this;
         if (successFunction != null && jQuery.isFunction(successFunction))
         {
            successFn.customerFn = successFunction;
         }
         try
         {
            var opts = {dataType:"json",url:url,async:false,cache:false};
            if (typeof formObj == "string")
            {
               opts.type = formObj;
            }
            else if (typeof formObj == "object")
            {
               opts.type = "POST";
               opts.data = formObj.serialize();
            }
            if (async != null)
            {
               opts.async = async;
            }
            opts.success = successFn;
            if (completeFunction != null && jQuery.isFunction(completeFunction))
            {
               opts.complete = completeFunction;
            }
            httpRequest = jQuery.ajax(opts);
            if (async)
            {
               successFn.httpRequest = httpRequest;
            }
            else
            {
               if ((this.eterna_debug & ED_SHOW_CREATED_HTML) != 0 && httpRequest != null)
               {
                  this.showMessage(httpRequest.responseText + "\n---------------------------------\n"
                        + "status:" + successFn.status + ",url:" + url);
               }
            }
            return opts.async ? successFn : successFn.data;
         }
         catch (ex)
         {
            this.printException(ex);
            throw ex;
         }
      }

      Eterna.prototype.reInit = function()
      {
         if (this.initOver)
         {
            return 1;
         }
         try
         {
            if (this.eternaData.records.delayInit && eg_cache.parentEterna == null)
            {
               // 如果设置了延迟初始化，则在没有parentEterna的情况下延迟初始化
               eg_cache.willInitEterna[this.rootWebObj.attr("id")] = this;
               // 启动延迟初始化的检查进程
               jQuery(window).trigger(EE_SET_PARENT_ETERNA, [true]);
               eterna_delayInit();
               return -1;
            }
            if (eg_cache.willInitEterna[this.rootWebObj.attr("id")] != null)
            {
               eg_cache.willInitEterna[this.rootWebObj.attr("id")] == null
            }
            this.initOver = true;
            this.rootWebObj.html(this.rootWebObjOld_HTML);
            var needCreate = true;
            if (this.eternaData.beforeInit != null)
            {
               needCreate = this.executeScript(this.rootWebObj, this.eternaData, this.eternaData.beforeInit);
            }
            if (needCreate)
            {
               for (var i = 0; i < this.eternaData.view.length; i++)
               {
                  var tmpCom = this.createComponent(this.eternaData.view[i], this.rootWebObj);
                  if (tmpCom != null)
                  {
                     this.rootWebObj.append(tmpCom);
                  }
               }
               if (this.eternaData.init != null)
               {
                  this.executeScript(this.rootWebObj, this.eternaData, this.eternaData.init);
               }
            }
            eterna_doInitObjs();
         }
         catch (ex)
         {
            this.printException(ex);
            throw ex;
         }
         if ((this.eterna_debug & ED_SHOW_CREATED_HTML) != 0)
         {
            this.showMessage(this.rootWebObj.html());
         }
         return 1;
      }

      Eterna.prototype.queryWebObj = function(queryStr, container)
      {
         if (container == null)
         {
            container = this.rootWebObj;
         }
         return jQuery(queryStr, container);
      }

      Eterna.prototype.getWebObj = function(id, container, index)
      {
         if (container == null)
         {
            container = this.rootWebObj;
         }
         if (index == null)
         {
            return jQuery("#" + id, container);
         }
         else
         {
            return jQuery("#" + id + ":eq(" + index + ")", container);
         }
      }

      Eterna.prototype.reloadWebObj = function(webObj)
      {
         var temp = this.egTemp();
         var parentWebObj = null;
         var tmpCom = null;
         try
         {
            if (typeof webObj == "string")
            {
               webObj = this.getWebObj(webObj);
            }
            var myTemp = webObj.data("egTemp");
            this.egTemp(myTemp);
            parentWebObj = webObj.data("parentWebObj");
            tmpCom = this.createComponent(webObj.data("configData"), parentWebObj);
            if (tmpCom != null)
            {
               webObj.after(tmpCom);
            }
            webObj.remove();
            eterna_doInitObjs();
         }
         catch (ex)
         {
            this.egTemp(temp);
            this.printException(ex);
            throw ex;
         }
         this.egTemp(temp);
         if ((this.eterna_debug & ED_SHOW_CREATED_HTML) != 0 && parentWebObj != null)
         {
            this.showMessage("id:" + tmpCom.attr("id") + "\n" + tmpCom.html());
         }
         return tmpCom;
      }

      Eterna.prototype.detachTopOnfocus = function(theWindow, eventFunction)
      {
         try
         {
            jQuery(theWindow).unbind("focus", eventFunction);
            jQuery("*", theWindow.document).unbind("focus", eventFunction);
            var count = theWindow.frames.length;
            for (var i = 0; i < count; i++)
            {
               this.detachTopOnfocus(theWindow.frames[i], eventFunction);
            }
         }
         catch (ex)
         {
            this.printException(ex);
         }
      }

      Eterna.prototype.attachTopOnfocus = function(theWindow, eventFunction)
      {
         try
         {
            jQuery(theWindow).focus(eventFunction);
            jQuery("*", theWindow.document).focus(eventFunction);
            var count = theWindow.frames.length;
            for (var i = 0; i < count; i++)
            {
               this.attachTopOnfocus(theWindow.frames[i], eventFunction);
            }
         }
         catch (ex)
         {
            this.printException(ex);
         }
      }

      Eterna.prototype.openWindow = function(url, name, param, lock, closeEvent)
      {
         var theWindow = open(url, name, param);
         var canInsertIndex = -1;
         var needAdd = true;
         for (var i = 0; i < this.windowArray.length; i++)
         {
            if (this.windowArray[i] == theWindow)
            {
               needAdd = false;
               break;
            }
            if (this.windowArray[i].closed)
            {
               canInsertIndex = i;
            }
         }
         if (needAdd)
         {
            if (canInsertIndex == -1)
            {
               this.windowArray.push(theWindow);
            }
            else
            {
               this.windowArray[canInsertIndex] = theWindow;
            }
         }
         theWindow.focus();
         if (theWindow.eg_cache != null)
         {
            theWindow.eg_cache.parentEterna = this;
         }
         else if (needAdd)
         {
            var onLoad = function(event, fromTrigger)
            {
               try
               {
                  if (onLoad._theWindow.closed)
                  {
                     return 1;
                  }
                  if (onLoad._theWindow.eg_cache != null)
                  {
                     if (onLoad._theWindow.eg_cache.parentEterna != null)
                     {
                        return -1;
                     }
                     if (onLoad._eterna.eterna_debug >= ED_HIGHER)
                     {
                        onLoad._eterna.rootWebObj.append(jQuery("<span>nOver:" + onLoad._checkedTimes + ",</span>"));
                     }
                     onLoad._hasEterna = true;
                     onLoad._checkedTimes = 0;
                     onLoad._theWindow.eg_cache.parentEterna = onLoad._eterna;
                     return -1;
                  }
                  else
                  {
                     if (onLoad._eterna.eterna_debug >= ED_HIGHER)
                     {
                        onLoad._eterna.rootWebObj.append(jQuery("<span>None:" + onLoad._checkedTimes + ",</span>"));
                     }
                     if (!fromTrigger || !onLoad._hasEterna)
                     {
                        if (!onLoad._checkedTimes)
                        {
                           onLoad._checkedTimes = 1;
                        }
                        else if (onLoad._checkedTimes > 25)
                        {
                           // 如果检测25次以上的话，则退出
                           if (onLoad._cacheIndex != null)
                           {
                              eg_cache.openWindowOnLoad[onLoad._cacheIndex] = null;
                           }
                           return 1;
                        }
                        onLoad._checkedTimes += 1;
                     }
                     // 如果检测不到eg_cache, 则延迟几秒后再查
                     eterna_checkOpenWindowOnLoad(onLoad);
                     return -1;
                  }
               }
               catch (ex)
               {
                  if (onLoad._eterna.eterna_debug >= ED_HIGHER)
                  {
                     onLoad._eterna.rootWebObj.append(jQuery("<span>Err:" + onLoad._checkedTimes + ",</span>"));
                  }
                  if (!onLoad._errorTimes)
                  {
                     onLoad._errorTimes = 1;
                  }
                  else if (onLoad._errorTimes > 75)
                  {
                     // 如果出错75次以上的话，则退出
                     if (onLoad._cacheIndex)
                     {
                        eg_cache.openWindowOnLoad[onLoad._cacheIndex] = null;
                     }
                     return 1;
                  }
                  onLoad._errorTimes += 1;
                  eterna_checkOpenWindowOnLoad(onLoad);
                  return -1;
               }
            }
            onLoad._theWindow = theWindow;
            onLoad._eterna = this;
            jQuery(theWindow).bind(EE_SET_PARENT_ETERNA, onLoad);
            jQuery(theWindow).ready(onLoad);
         }
         if (lock)
         {
            this.nowWindow = theWindow;
            if (jQuery.isFunction(closeEvent))
            {
               jQuery(window).bind(EE_SUB_WINDOW_CLOSE, closeEvent);
            }

            var onOpenWindowThisFocus = function(event)
            {
               var theEterna = onOpenWindowThisFocus._eterna;
               if (theEterna.nowWindow == null || theEterna.nowWindow.closed)
               {
                  theEterna.detachTopOnfocus(window.top, onOpenWindowThisFocus);
                  if (theEterna.nowWindow != null)
                  {
                     jQuery(window).trigger(EE_SUB_WINDOW_CLOSE);
                     jQuery(window).unbind(EE_SUB_WINDOW_CLOSE);
                  }
                  theEterna.nowWindow = null;
               }
               else
               {
                  theEterna.nowWindow.focus();
                  return false;
               }
            }
            onOpenWindowThisFocus._eterna = this;
            this.attachTopOnfocus(window.top, onOpenWindowThisFocus);
         }
         return theWindow;
      }

      Eterna.prototype.showMessage = function(msg, theWindow)
      {
         var winObj;
         if (theWindow == null || theWindow.closed)
         {
            winObj = this.openWindow("", "_blank", "resizable=yes", false);
            winObj.document.write("<html><body><textarea id='msg' style='border:0;width:100%;height:100%'></textarea></body></html>");
         }
         else
         {
            winObj = theWindow;
         }
         if (winObj.document.all.msg != null)
         {
            winObj.document.all.msg.value += msg;
         }
         return winObj;
      }

      Eterna.prototype.printException = function(ex, noShow)
      {
         if (this.eterna_debug < ED_BASE || ex.dealed)
         {
            return;
         }

         var str = "* exception info:\n";
         if (typeof ex == "object")
         {
            for(var key in ex)
            {
               str += "   " + key + ":" + ex[key] + "\n";
            }
         }
         else
         {
            str += "   " + ex;
         }

         str += "\n\n\n* component stack info:\n";
         for (var i = 0; i < eterna_com_stack.length; i++)
         {
            str += "   " + eterna_com_stack[i] + "\n";
         }

         str += "\n\n\n* now function info:\n";
         if (eterna_fn_stack.length > 0)
         {
            var fnInfo = eterna_fn_stack[eterna_fn_stack.length - 1];
            for (var i = 2; i < fnInfo.length; i += 2)
            {
               if (i > 2)
               {
                  str += ",\n"
               }
               var tmpParam = fnInfo[i + 1];
               str += "   " + fnInfo[i] + ":" + tmpParam;
               if (typeof tmpParam == "object" && tmpParam != null)
               {
                  if (tmpParam.name != null)
                  {
                     str += "[name:" + tmpParam.name + "]";
                  }
                  if (tmpParam.type != null)
                  {
                     str += "[type:" + tmpParam.type + "]";
                  }
               }
            }
            str += "\n\n" + fnInfo[0] + ":" + fnInfo[1];
         }


         if (this.eterna_debug >= ED_FNC_STACK)
         {
            for (var i = eterna_fn_stack.length - 2; i >= 0; i--)
            {
               str += "\n\n\n* stack(" + i + ") function info:\n";
               var fnInfo = eterna_fn_stack[i];
               for (var j = 2; j < fnInfo.length; j += 2)
               {
                  if (j > 2)
                  {
                     str += ",\n"
                  }
                  var tmpParam = fnInfo[j + 1];
                  str += "   " + fnInfo[j] + ":" + tmpParam;
                  if (typeof tmpParam == "object" && tmpParam != null)
                  {
                     if (tmpParam.name != null)
                     {
                        str += "[name:" + tmpParam.name + "]";
                     }
                     if (tmpParam.type != null)
                     {
                        str += "[type:" + tmpParam.type + "]";
                     }
                  }
               }
               str += "\n\n   " + fnInfo[0] + ":" + fnInfo[1];
            }
         }
         else
         {
            ex.dealed = true;
         }
         str += "\n\n\n-------------------------------------------------------------------\n\n";

         if (!noShow)
         {
            eg_cache.msgListWindow = this.showMessage(str, eg_cache.msgListWindow);
         }
         return str;
      }

      Eterna.prototype.pushFunctionStack = function(info)
      {
         if (this.eterna_debug >= ED_FN_CALLED)
         {
            eterna_fn_stack.push(info);
         }
      }

      Eterna.prototype.popFunctionStack = function()
      {
         if (this.eterna_debug >= ED_FN_CALLED)
         {
            eterna_fn_stack.pop();
         }
      }

   Eterna.prototype._f_getValue_fromRecords = function(dataName, srcName, index)
   {
      if (index == null)
      {
         var tmpStr = "[script]:valueObj.value=eternaData.records[valueObj.dataName][valueObj.srcName];valueObj.exists=(typeof valueObj.value=='undefined')?0:1;valueObj.valueData=eternaData.records[valueObj.dataName];";
         var valueObj = {html:0,value:"",exists:-1,dataName:dataName,srcName:srcName};
         return this.getValue(tmpStr, valueObj);
      }
      else
      {
         var tmpStr = "[script]:var mytmpData=eternaData.records[valueObj.dataName];valueObj.valueData=mytmpData;valueObj.value=mytmpData.rows[valueObj.index][mytmpData.names[valueObj.srcName]-1];valueObj.exists=(typeof valueObj.value=='undefined')?0:1;";
         var valueObj = {html:0,value:"",exists:-1,dataName:dataName,srcName:srcName,index:index};
         return this.getValue(tmpStr, valueObj);
      }
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.getValue_fromRecords = function(dataName, srcName, index)
         {
            this.pushFunctionStack(new Array("getValue_fromRecords", this._f_getValue_fromRecords,
                  "dataName", dataName, "srcName", srcName, "index", index));
            var result = this._f_getValue_fromRecords(dataName, srcName, index);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.getValue_fromRecords = this._f_getValue_fromRecords;
      }

   Eterna.prototype._f_getValue = function(str, valueObj)
   {
      if (str == null)
      {
         return {html:0,value:"",exists:0};
      }
      if (str == "")
      {
         return {html:0,value:"",exists:1};
      }
      // 如果是其他类型的数据, 需要转换成字符串
      str = str + "";
      if (str.indexOf("[script]:") == 0)
      {
         try
         {
            if (valueObj == null)
            {
               valueObj = {html:0,value:"",exists:-1};
            }
            var _eterna = this;
            var eternaData = this.eternaData;
            var eterna_debug = this.eterna_debug;
            var tmpResult = eval(str.substring(9));
            if (valueObj.exists == -1)
            {
               if (tmpResult != null && tmpResult != "")
               {
                  valueObj.exists = 1;
                  valueObj.value = tmpResult;
               }
               else
               {
                  valueObj.exists = 0;
               }
            }
            return valueObj;
         }
         catch (ex)
         {
            if ((this.eterna_debug & ED_GET_VALUE) != 0)
            {
               //var msg = "getValue(str:" + str + ",valueObj:" +　valueObj + ");\nex:" + ex + "/" + ex.message + "\n\n";
               this.pushFunctionStack(new Array("getValue", "str:" + str + ",valueObj:" +　valueObj));
               this.printException(ex);
               this.popFunctionStack();
            }
            if (valueObj != null)
            {
               valueObj.exists = 0;
               return valueObj;
            }
            else
            {
               return {html:0,value:"",exists:0};
            }
         }
      }
      else if (str.indexOf("[html]:") == 0)
      {
         return {html:1,value:str.substring(7),exists:1};
      }
      else if (str.indexOf("[text]:") == 0)
      {
         return {html:0,value:str.substring(7),exists:1};
      }
      else
      {
         return {html:0,value:str,exists:1};
      }
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.getValue = function(str, valueObj)
         {
            this.pushFunctionStack(new Array("getValue", this._f_getValue,
                  "str", str, "valueObj", valueObj));
            var result = this._f_getValue(str, valueObj);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.getValue = this._f_getValue;
      }

   Eterna.prototype._f_executeScript = function(webObj, objConfig, scriptStr)
   {
      var checkResult = true;
      try
      {
         var _eterna = this;
         var eternaData = this.eternaData;
         var eterna_debug = this.eterna_debug;
         var eventData = webObj; //重命名一个变量, 在event处理中使用, 不用和webObj混淆
         eval(scriptStr);
      }
      catch (ex)
      {
         if ((this.eterna_debug & ED_EXECUTE_SCRIPT) != 0)
         {
            this.pushFunctionStack(new Array("executeScript", scriptStr));
            //var msg = "executeScript:{" + scriptStr + "}\nex:" + ex + "/" + ex.message + "\n\n";
            this.printException(ex);
            this.popFunctionStack();
         }
      }
      return checkResult;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.executeScript = function(webObj, objConfig, scriptStr)
         {
            this.pushFunctionStack(new Array("executeScript", this._f_executeScript,
                  "webObj", webObj, "objConfig", objConfig, "scriptStr", scriptStr));
            var result = this._f_executeScript(webObj, objConfig, scriptStr);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.executeScript = this._f_executeScript;
      }

   Eterna.prototype._f_createComponent = function(configData, parent)
   {
      if (configData == null || configData.type == null)
      {
         return null;
      }

      if (this.eterna_debug >= ED_COM_CREATED)
      {
         eterna_com_stack.push("name:" + configData.name + ",type:" + configData.type);
      }

      var temp = this.egTemp();

      if (configData.beforeInit != null)
      {
         if (!this.executeScript(null, configData, configData.beforeInit))
         {
            if (this.eterna_debug >= ED_COM_CREATED)
            {
               eterna_com_stack.pop();
            }
            this.egTemp(temp);
            return null;
         }
      }

      var myTemp = this.egTemp();

      var returnNULL = false;
      var doLoop = false;
      var type = configData.type;
      var webObj = null;
      if (configData.creater != null && jQuery.isFunction(configData.creater))
      {
         webObj = configData.creater(configData, parent);
      }
      else if (type == "tableForm")
      {
         webObj = this.createTableForm(configData);
      }
      else if (type == "tableList")
      {
         webObj = this.createTableList(configData);
      }
      else if (type == "none")
      {
         webObj = parent;
         returnNULL = true;
      }
      else if (type == "loop")
      {
         webObj = parent;
         returnNULL = true;
         doLoop = true;
      }
      else if (type == "replacement")
      {
         var tmpObj = this.createComponent(this.eternaData.typical[configData.typicalComponent], parent);
         webObj = tmpObj;
      }
      else
      {
         var index = type.indexOf("-");
         if (index != -1)
         {
            var tmpType = type.substring(0, index);
            var extType = type.substring(index + 1);
            if (tmpType.toLowerCase() == "input")
            {
               webObj = this.createWebObj(configData, "input", {name:"type",value:extType});
            }
            else
            {
               webObj = this.createWebObj(configData, tmpType, {name:"",value:extType});
            }
         }
         else
         {
            webObj = this.createWebObj(configData, type, null);
         }
      }

      if (webObj != null)
      {
         if (configData.subs != null)
         {
            if (doLoop)
            {
               if (configData.loopCondition)
               {
                  while (this.executeScript(null, configData, configData.loopCondition))
                  {
                     this.dealSubComponent(configData, webObj);
                  }
               }
               else if (eg_temp.dataName != null && this.eternaData.records[eg_temp.dataName] != null)
               {

                  var theCount = null;
                  var theData = this.eternaData.records[eg_temp.dataName];
                  if (typeof this.eternaData.records[eg_temp.dataName] == "object")
                  {
                     theCount = this.eternaData.records[eg_temp.dataName].rowCount;
                     if (theCount == null)
                     {
                        theCount = this.eternaData.records[eg_temp.dataName].length;
                     }
                  }
                  else if (typeof this.eternaData.records[eg_temp.dataName] == "number")
                  {
                     theCount = this.eternaData.records[eg_temp.dataName];
                  }
                  if (theCount != null)
                  {
                     var temp_index = eg_temp.index;
                     for (var index = 0; index < theCount; index++)
                     {
                        eg_temp.index = index;
                        this.dealSubComponent(configData, webObj);

                        // 将数据重新赋值, 这样即使循环体里改变了, 这里能改回来
                        this.eternaData.records[eg_temp.dataName] = theData;
                     }
                     eg_temp.index = temp_index;
                  }
               }
            }
            else
            {
               this.dealSubComponent(configData, webObj);
            }
         }

         if (configData.init != null)
         {
            this.executeScript(returnNULL ? null : webObj, configData, configData.init);
         }

         if (!returnNULL)
         {
            if (configData.events != null)
            {
               this.dealEvents(configData, webObj, parent, myTemp);
            }
            webObj.data("parentWebObj", parent);
            webObj.data("configData", configData);
            webObj.data("egTemp", myTemp);
         }
      }

      this.egTemp(temp);
      if (this.eterna_debug >= ED_COM_CREATED)
      {
         eterna_com_stack.pop();
      }
      if (returnNULL)
      {
         return null;
      }
      return webObj;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.createComponent = function(configData, parent)
         {
            this.pushFunctionStack(new Array("createComponent", this._f_createComponent,
                  "configData", configData, "parent", parent));
            var result = this._f_createComponent(configData, parent);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.createComponent = this._f_createComponent;
      }

   Eterna.prototype._f_dealEvents = function(configData, webObj, parent, myTemp)
   {
      for (var i = 0; i < configData.events.length; i++)
      {
         var theEvent = configData.events[i];
         var objParam = false;
         var tmpParamData = {webObj:webObj,objConfig:configData,eventConfig:theEvent}

         if (parent != null)
         {
            tmpParamData.parentWebObj = parent;
         }
         tmpParamData.egTemp = myTemp;

         if (theEvent.param != null && theEvent.param.indexOf("[script]:") == 0)
         {
            objParam = this.executeScript(tmpParamData, configData, theEvent.param.substring(9));
         }
         if (!objParam)
         {
            tmpParamData.eventParam = theEvent.param;
         }
         webObj.bind(theEvent.type, tmpParamData, theEvent.fn);
      }
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.dealEvents = function(configData, webObj, parent, myTemp)
         {
            this.pushFunctionStack(new Array("dealEvents", this._f_dealEvents,
                  "configData", configData, "webObj", webObj, "parent", parent, "myTemp", myTemp));
            var result = this._f_dealEvents(configData, webObj, parent, myTemp);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.dealEvents = this._f_dealEvents;
      }

   Eterna.prototype._f_dealSubComponent = function(configData, webObj)
   {
      for (var i = 0; i < configData.subs.length; i++)
      {
         var sub = configData.subs[i];
         var tmpObj = this.createComponent(sub, webObj);
         if (tmpObj != null)
         {
            webObj.append(tmpObj);
         }
      }
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.dealSubComponent = function(configData, webObj)
         {
            this.pushFunctionStack(new Array("dealSubComponent", this._f_dealSubComponent,
                  "configData", configData, "webObj", webObj));
            var result = this._f_dealSubComponent(configData, webObj);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.dealSubComponent = this._f_dealSubComponent;
      }

   Eterna.prototype._f_createWebObj = function(configData, type, extType)
   {
      var objStr = type;
      if (extType != null && extType.name != "")
      {
         objStr += " " + extType.name + "=\"" + extType.value + "\"";
      }
      if (configData.objName != null)
      {
         var tmpObj = this.getValue(configData.objName);
         if (tmpObj.exists && tmpObj.value != "")
         {
            objStr += " name=\"" + tmpObj.value + "\"";
         }
      }
      else if (eg_temp.name != null)
      {
         if (type.toLowerCase() == "input" || type.toLowerCase() == "select"
               || type.toLowerCase() == "textarea" || type.toLowerCase() == "button")
         {
            objStr += " name=\"" + eg_temp.name + "\"";
         }
      }
      var obj = jQuery("<" + objStr + "/>");

      if (extType != null)
      {
         if (extType.name == "type" || extType.name == "")
         {
            type = type + "-" + extType.value;
         }
         else
         {
            type = type + "-" + extType.name + "." + extType.value;
         }
      }

      this.appendParam(obj, configData, type);
      if (configData.objValue != null)
      {
         var tmpObj = this.getValue(configData.objValue);
         if (tmpObj.exists)
         {
            obj.val(tmpObj.value);
         }
      }
      if (configData.text != null)
      {
         var tmpObj = this.getValue(configData.text);
         if (tmpObj.exists)
         {
            obj.text(tmpObj.value);
         }
      }
      else if (configData.htmlBody != null)
      {
         obj.html(configData.htmlBody);
      }
      else if (configData.html != null)
      {
         var tmpObj = this.getValue(configData.html);
         if (tmpObj.exists)
         {
            obj.html(tmpObj.value);
         }
      }

      return obj;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.createWebObj = function(configData, type, extType)
         {
            this.pushFunctionStack(new Array("createWebObj", this._f_createWebObj,
                  "configData", configData, "type", type, "extType", extType));
            var result = this._f_createWebObj(configData, type, extType);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.createWebObj = this._f_createWebObj;
      }

   Eterna.prototype._f_createTR = function(configData, tableObj, type, model)
   {
      if (configData != null && configData.preObj != null)
      {
         var oldTemp = eg_temp;
         var myTemp = configData.preTemp;
         eg_temp = myTemp;
         var preObj = configData.preObj;
         configData.preObj = null;
         configData.preTemp = null;
         if (configData.init != null)
         {
            this.executeScript(preObj, configData, configData.init);
         }
         if (configData.events != null)
         {
            this.dealEvents(configData, preObj, tableObj, myTemp);
         }
         preObj.data("parentWebObj", tableObj);
         preObj.data("configData", configData);
         preObj.data("egTemp", myTemp);
         eg_temp = oldTemp;
      }
      if (model == "final")
      {
         return;
      }
      if (model != "noBeforeInit" && configData != null && configData.beforeInit != null)
      {
         if (!this.executeScript(null, configData, configData.beforeInit))
         {
            return null;
         }
      }
      var trObj = jQuery("<tr></tr>");
      tableObj.append(trObj);
      this.appendParam(trObj, configData, type);
      if (configData != null)
      {
         if (model == "sub" && configData.subs != null)
         {
            this.dealSubComponent(configData, trObj);
         }
         configData.preObj = trObj;
         configData.preTemp = this.egTemp();
      }
      return trObj;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.createTR = function(configData, tableObj, type, model)
         {
            this.pushFunctionStack(new Array("createTR", this._f_createTR,
                  "configData", configData, "tableObj", tableObj, "type", type, "model", model));
            var result = this._f_createTR(configData, tableObj, type, model);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.createTR = this._f_createTR;
      }

   // 构造一个表单式的表格
   Eterna.prototype._f_createTableForm = function(configData)
   {
      var tableObj = jQuery("<table></table>");
      this.appendParam(tableObj, configData, "tableForm");

      var percentWidth = true;
      if (configData.percentWidth != null && !configData.percentWidth)
      {
         percentWidth = false;
      }

      var temp = this.egTemp();
      eg_caculateWidth_fix = 0;
      configData.rowOff = null;
      configData.used_counts = null;
      var columns = configData.columns;
      var columnLeft = columns.length;
      if (!percentWidth && configData.caculateWidth != null && configData.caculateWidth)
      {
         if (configData.caculateWidth_fix != null)
         {
            eg_caculateWidth_fix = configData.caculateWidth_fix;
         }
         else if (this.eternaData.global.tableForm.caculateWidth_fix != null)
         {
            eg_caculateWidth_fix = this.eternaData.global.tableForm.caculateWidth_fix;
         }
         var tmpWidth = this.ctf_getColWidth(columns, 0, columns.length, configData, configData);
         // 这里只需再补上2个，因为在计算时，中间的已经加了columns.length - 1个
         tmpWidth += eg_caculateWidth_fix * 2;
         tableObj.attr("width", tmpWidth);
      }
      eg_temp.columnCount = columns.length;
      eg_temp.rowNum = 0;
      eg_temp.rowType = "row";

      if (configData.cells.length >= 1 && configData.cells[0].clearRowNum)
      {
         eg_temp.rowNum = -1;
      }
      var trObj = this.ctf_tr(configData.tr, tableObj);
      for(var i = 0; i < configData.cells.length; i++)
      {
         var cell = configData.cells[i];
         var tmpSize = this.ctf_getSize(cell.title, configData) + this.ctf_getSize(cell.container, configData);
         var tmpLeft = columnLeft;
         var needNewRow = false;
         if ((tmpSize > columnLeft && columnLeft < columns.length)
               || (cell.clearRowNum && columnLeft < this.ctf_getColumnCount(configData)))
         {
            do
            {
               // 由于要在新的一行, 所以要将rowNum增1
               eg_temp.rowNum++;
               configData.rowOff = configData.rowOff == null ? 1 : configData.rowOff + 1;
               tmpLeft = this.ctf_getColumnCount(configData);
            } while (tmpLeft < tmpSize && tmpLeft < columns.length);
            needNewRow = true;
            // 可能要生成新的一行, 先将前一行的init-script执行了
            this.createTR(configData.tr, tableObj, "tableForm_tr", "final");
         }
         // 如果是要强制新行, 则将eg_temp.rowNum设为0
         var oldRowNum = eg_temp.rowNum;
         if (cell.clearRowNum)
         {
            eg_temp.rowNum = 0;
         }
         var cellObj = this.ctf_cell(columns, this.ctf_getColumnCount(configData) - tmpLeft, percentWidth, cell, configData);
         if (cell.clearRowNum)
         {
            // 恢复原来eg_temp.rowNum的值
            eg_temp.rowNum = oldRowNum;
         }
         if (configData.rowOff)
         {
            // 将rowNum恢复原值
            eg_temp.rowNum -= configData.rowOff;
            configData.rowOff = null;
         }
         if (cellObj.exists)
         {
            if (needNewRow)
            {
               do
               {
                  if (columnLeft > 0)
                  {
                     var tdObj = this.ctf_container(null, columnLeft, 1);
                     tdObj.html(eterna_table_td_empty_value);
                     tdObj.attr("width",
                           this.ctf_getColWidth(columns, this.ctf_getColumnCount(configData) - columnLeft, columnLeft, configData)
                           + (percentWidth ? "%" : ""));
                     trObj.append(tdObj);
                  }
                  if (cell.clearRowNum)
                  {
                     eg_temp.rowNum = -1;
                  }
                  // 生成新的一行, 并且更新相关信息
                  trObj = this.ctf_tr(configData.tr, tableObj);
                  if (configData.used_counts != null)
                  {
                     configData.used_counts.shift();
                     if (configData.used_counts.length == 0)
                     {
                        configData.used_counts = null;
                     }
                  }
                  columnLeft = this.ctf_getColumnCount(configData);
               } while (columnLeft < tmpSize && columnLeft < columns.length);
            }
            if (cell.rowSpan != null && cell.rowSpan > 1)
            {
               this.ctf_createUsedList(configData, this.ctf_getColumnCount(configData) - columnLeft, cell);
            }
            if (cellObj.title != null)
            {
               trObj.append(cellObj.title);
            }
            if (cellObj.container != null)
            {
               trObj.append(cellObj.container);
            }
            columnLeft -= tmpSize;
         }
      }
      if (columnLeft > 0)
      {
         var tdObj = this.ctf_container(null, columnLeft, 1);
         tdObj.html(eterna_table_td_empty_value);
         tdObj.attr("width",
               this.ctf_getColWidth(columns, this.ctf_getColumnCount(configData) - columnLeft, columnLeft, configData)
               + (percentWidth ? "%" : ""));
         trObj.append(tdObj);
      }
      this.createTR(configData.tr, tableObj, "tableForm_tr", "final");
      this.egTemp(temp);
      eg_caculateWidth_fix = 0;

      return tableObj;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.createTableForm = function(configData)
         {
            this.pushFunctionStack(new Array("createTableForm", this._f_createTableForm,
                  "configData", configData));
            var result = this._f_createTableForm(configData);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.createTableForm = this._f_createTableForm;
      }

      // 生成已使用列的列表
   Eterna.prototype._f_ctf_createUsedList = function(table, index, cell)
   {
      if (table.used_counts == null)
      {
         table.used_counts = [];
      }
      if (table.used_counts.length == 0)
      {
         table.used_counts.push({count:0, spaned:this.ctf_createSpanedArr(table)});
      }
      var cellSize = this.ctf_getSize(cell.title, table) + this.ctf_getSize(cell.container, table);
      for (var i = 1; i < cell.rowSpan; i++)
      {
         if (table.used_counts.length < i + 1)
         {
            table.used_counts.push({count:cellSize, spaned:this.ctf_createSpanedArr(table)});
         }
         else if (i == 1)
         {
            table.used_counts[i].count += cellSize;
         }
         var tmpSize = cellSize;
         for (var j = 0; j < table.columns.length && tmpSize > 0; j++)
         {
            if (j < index)
            {
               if (table.used_counts[i].spaned[j])
               {
                  index++;
               }
            }
            else
            {
               if (!table.used_counts[i].spaned[j])
               {
                  table.used_counts[i].spaned[j] = true;
                  tmpSize--;
               }
            }
         }
      }
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctf_createUsedList = function(table, index, cell)
         {
            this.pushFunctionStack(new Array("ctf_createUsedList", this._f_ctf_createUsedList,
                  "table", table, "index", index, "cell", cell));
            var result = this._f_ctf_createUsedList(table, index, cell);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctf_createUsedList = this._f_ctf_createUsedList;
      }

     // 创建一个和table的columns等长的数组
      Eterna.prototype.ctf_createSpanedArr = function(table)
      {
         var tmp = [];
         for (var i = 0; i < table.columns.length; i++)
         {
            tmp.push(false);
         }
         return tmp;
      }

      // 获得当前行的最大列数
   Eterna.prototype._f_ctf_getColumnCount = function(table)
   {
      if (table.used_counts != null)
      {
         if (table.rowOff && table.used_counts.length > table.rowOff)
         {
            return eg_temp.columnCount - table.used_counts[table.rowOff].count;
         }
         else
         {
            return eg_temp.columnCount - table.used_counts[0].count;
         }
      }
      return eg_temp.columnCount;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctf_getColumnCount = function(table)
         {
            this.pushFunctionStack(new Array("ctf_getColumnCount", this._f_ctf_getColumnCount,
                  "table", table));
            var result = this._f_ctf_getColumnCount(table);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctf_getColumnCount = this._f_ctf_getColumnCount;
      }

      // 获得size属性, 如果没有默认为1
   Eterna.prototype._f_ctf_getSize = function(configData, table)
   {
      var tmpSize = 1;
      if (configData.size != null)
      {
         if (configData.size < 0)
         {
            tmpSize = this.ctf_getColumnCount(table) + configData.size + 1;
         }
         else
         {
            tmpSize = configData.size;
         }
      }
      return tmpSize;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctf_getSize = function(configData, table)
         {
            this.pushFunctionStack(new Array("ctf_getSize", this._f_ctf_getSize,
                  "configData", configData, "table", table));
            var result = this._f_ctf_getSize(configData, table);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctf_getSize = this._f_ctf_getSize;
      }

   Eterna.prototype._f_ctf_getColWidth = function(columns, index, count, table)
   {
      var colCount = this.ctf_getColumnCount(table);
      if (index >= colCount)
      {
         return 0;
      }
      if (table.used_counts != null)
      {
         var tmpIndex = 0;
         if (table.rowOff)
         {
            tmpIndex = table.rowOff;
         }
         if (tmpIndex < table.used_counts.length)
         {
            var tmpColumns = [];
            for (var i = 0; i < columns.length; i++)
            {
               if (!table.used_counts[tmpIndex].spaned[i])
               {
                  tmpColumns.push(columns[i]);
               }
            }
            columns = tmpColumns;
         }
      }
      var sumWidth = 0;
      for (var i = index; i < colCount && count > 0; i++, count--)
      {
         sumWidth += columns[i];
         if (i > index)
         {
             sumWidth += eg_caculateWidth_fix;
         }
      }
      return sumWidth;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctf_getColWidth = function(columns, index, count, table)
         {
            this.pushFunctionStack(new Array("ctf_getColWidth", this._f_ctf_getColWidth,
                  "columns", columns, "index", index, "count", count, "table", table));
            var result = this._f_ctf_getColWidth(columns, index, count, table);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctf_getColWidth = this._f_ctf_getColWidth;
      }

   Eterna.prototype._f_ctf_cell = function(columns, colIndex, percentWidth, cell, table)
   {
      var temp = this.egTemp();

      eg_temp.name = cell.name;
      if (cell.container.value != null)
      {
         eg_temp.dataName = cell.container.value.dataName;
         eg_temp.srcName = cell.container.value.srcName;
      }
      var tmpObj;
      if (cell.container.value != null)
      {
         if (cell.container.needIndex && eg_temp.index != null)
         {
            tmpObj = this.getValue_fromRecords(cell.container.value.dataName, cell.container.value.srcName, eg_temp.index);
         }
         else
         {
            tmpObj = this.getValue_fromRecords(cell.container.value.dataName, cell.container.value.srcName);
         }
         if (!tmpObj.exists)
         {
            var tmpObj2 = this.getValue(cell.container.defaultValue);
            tmpObj.exists = tmpObj2.exists;
            tmpObj.html = tmpObj2.html;
            tmpObj.value = tmpObj2.value;
         }
      }
      else
      {
         tmpObj = this.getValue(cell.container.defaultValue);
      }
      eg_temp.valueObj = tmpObj;
      var valueObj = tmpObj;
      var titleObj;
      if (cell.title.caption != null)
      {
         titleObj = this.getValue(cell.title.caption);
         if (titleObj.exists && titleObj.value != "")
         {
            eg_temp.caption = titleObj.value;
         }
      }
      if (cell.initParam != null)
      {
         eg_temp.param = cell.initParam;
      }
      else
      {
         eg_temp.param = {};
      }
      var cellObj = {title:null,container:null,exists:false};
      if (cell.beforeInit != null)
      {
         if (!this.executeScript(null, cell, cell.beforeInit))
         {
            this.egTemp(temp);
            return cellObj;
         }
      }

      var titleSize = this.ctf_getSize(cell.title, table);
      var tdObj_t = this.ctf_title(cell.title, titleSize, cell.rowSpan);
      if (tdObj_t != null)
      {
         cellObj.title = tdObj_t;
         cellObj.exists = true;
         if (cell.title.caption != null)
         {
            if (titleObj.exists && titleObj.value != "")
            {
               if (titleObj.html)
               {
                  tdObj_t.html(titleObj.value + eterna_tableForm_title_pluse);
               }
               else
               {
                  tdObj_t.text(titleObj.value + eterna_tableForm_title_pluse);
               }
            }
            else
            {
               tdObj_t.html(eterna_table_td_empty_value);
            }
         }
         tdObj_t.attr("width",
               this.ctf_getColWidth(columns, colIndex, titleSize, table)
               + (percentWidth ? "%" : ""));
      }

      var containerSize = this.ctf_getSize(cell.container, table);
      var tdObj_c = this.ctf_container(cell.container, containerSize, cell.rowSpan);
      if (tdObj_c != null)
      {
         cellObj.container = tdObj_c;
         cellObj.exists = true;
         if (cell.subs == null && cell.typicalComponent == null)
         {
            if (valueObj.exists && valueObj.value != "")
            {
               if (valueObj.html)
               {
                  tdObj_c.html(valueObj.value);
               }
               else
               {
                  tdObj_c.text(valueObj.value);
               }
            }
            else
            {
               tdObj_c.html(eterna_table_td_empty_value);
            }
         }
         tdObj_c.attr("width",
               this.ctf_getColWidth(columns, colIndex + titleSize, containerSize, table)
               + (percentWidth ? "%" : ""));

         if (cell.subs != null)
         {
            this.dealSubComponent(cell, tdObj_c);
         }

         if (cell.typicalComponent != null)
         {
            var tmpObj = this.createComponent(this.eternaData.typical[cell.typicalComponent], tdObj_c);
            if (tmpObj != null)
            {
               tdObj_c.append(tmpObj);
            }
         }
      }

      if (cell.init != null)
      {
         this.executeScript(tdObj_c, cell, cell.init);
      }

      if (cell.container != null && cell.container.required)
      {
         if (eterna_tableForm_requared_fn != null)
         {
            eterna_tableForm_requared_fn(tdObj_t, tdObj_c, cell, this);
         }
      }

      this.egTemp(temp);
      return cellObj;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctf_cell = function(columns, colIndex, percentWidth, cell, table)
         {
            this.pushFunctionStack(new Array("ctf_cell", this._f_ctf_cell,
                  "columns", columns, "colIndex", colIndex, "percentWidth", percentWidth,
                  "cell", cell, "table", table));
            var result = this._f_ctf_cell(columns, colIndex, percentWidth, cell, table);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctf_cell = this._f_ctf_cell;
      }

   Eterna.prototype._f_ctf_title = function(configData, theSize, rowSpan)
   {
      if (theSize == 0)
      {
         return null;
      }
      var tdObj = jQuery("<td></td>");
      if (theSize > 1)
      {
         tdObj.attr("colSpan", theSize);
      }
      if (rowSpan != null && rowSpan > 1)
      {
         tdObj.attr("rowSpan", rowSpan);
      }
      this.appendParam(tdObj, configData, "tableForm_title");
      return tdObj;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctf_title = function(configData, theSize, rowSpan)
         {
            this.pushFunctionStack(new Array("ctf_title", this._f_ctf_title,
                  "configData", configData, "theSize", theSize, "rowSpan", rowSpan));
            var result = this._f_ctf_title(configData, theSize, rowSpan);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctf_title = this._f_ctf_title;
      }

   Eterna.prototype._f_ctf_container = function(configData, theSize, rowSpan)
   {
      if (theSize == 0)
      {
         return null;
      }
      var tdObj = jQuery("<td></td>");
      if (theSize > 1)
      {
         tdObj.attr("colSpan", theSize);
      }
      if (rowSpan != null && rowSpan > 1)
      {
         tdObj.attr("rowSpan", rowSpan);
      }
      this.appendParam(tdObj, configData, "tableForm_container");
      return tdObj;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctf_container = function(configData, theSize, rowSpan)
         {
            this.pushFunctionStack(new Array("ctf_container", this._f_ctf_container,
                  "configData", configData, "theSize", theSize, "rowSpan", rowSpan));
            var result = this._f_ctf_container(configData, theSize, rowSpan);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctf_container = this._f_ctf_container;
      }

   Eterna.prototype._f_ctf_tr = function(configData, tableObj)
   {
      eg_temp.rowNum++; // table form 新生成一行, 所以row number就增1
      return this.createTR(configData, tableObj, "tableForm_tr", "normal");
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctf_tr = function(configData, tableObj)
         {
            this.pushFunctionStack(new Array("ctf_tr", this._f_ctf_tr,
                  "configData", configData, "tableObj", tableObj));
            var result = this._f_ctf_tr(configData, tableObj);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctf_tr = this._f_ctf_tr;
      }

   // 构造一个列表式的表格
   Eterna.prototype._f_createTableList = function(configData)
   {
      var tableObj = jQuery("<table></table>");
      this.appendParam(tableObj, configData, "tableList");

      var percentWidth = true;
      if (configData.percentWidth != null && !configData.percentWidth)
      {
         percentWidth = false;
      }

      var temp = this.egTemp();
      // 先对每列执行初始化函数, 如果返回值为false则不显示该列
      var columns = new Array();
      var tmpColumns = configData.columns;
      eg_temp.rowNum = -1;
      for(var i = 0; i < tmpColumns.length; i++)
      {
         var column = tmpColumns[i];
         eg_temp.name = column.name;
         if (column.container.value != null)
         {
            eg_temp.dataName = column.container.value.dataName;
            eg_temp.srcName = column.container.value.srcName;
         }
         else
         {
            eg_temp.dataName = null;
            eg_temp.srcName = null;
         }
         if (column.done)
         {
            column.title.upTitles = this.cloneJSON(column.title.originUpTitles);
            column.done = false;
         }
         else if (column.title.originUpTitles == null)
         {
            column.title.originUpTitles = this.cloneJSON(column.title.upTitles);
         }
         if (column.initParam != null)
         {
            eg_temp.param = column.initParam;
         }
         else
         {
            eg_temp.param = {};
         }
         if (column.beforeInit != null)
         {
            if (this.executeScript(null, column, column.beforeInit))
            {
               columns.push(column);
            }
         }
         else
         {
            columns.push(column);
         }
      }
      eg_temp.columnCount = columns.length;

      eg_caculateWidth_fix = 0;
      if (!percentWidth && configData.caculateWidth != null && configData.caculateWidth)
      {
         if (configData.caculateWidth_fix != null)
         {
            eg_caculateWidth_fix = configData.caculateWidth_fix;
         }
         else if (this.eternaData.global.tableList.caculateWidth_fix != null)
         {
            eg_caculateWidth_fix = this.eternaData.global.tableList.caculateWidth_fix;
         }
         var tmpWidth = this.ctl_getColWidth(columns);
         if (tmpWidth != null)
         {
            // 这里只需再补上2个，因为在计算时，中间的已经加了columns.length - 1个
            tmpWidth += eg_caculateWidth_fix * 2;
            tableObj.attr("width", tmpWidth);
         }
      }

      this.ctl_tr(configData.tr, tableObj, "beforeTable");

      eg_temp.rowNum = 0;
      this.ctl_tr(configData.tr, tableObj, "beforeTitle");
      var maxLayer = this.ctl_dealUpTitle(columns);
      for (var layer = maxLayer - 1; layer >= 0; layer--)
      {
         var trObj = this.ctl_tr(configData.tr, tableObj, "title");
         if (trObj != null)
         {
            for(var i = 0; i < columns.length; i++)
            {
               var column = columns[i];
               this.ctl_title(percentWidth, trObj, column, layer);
            }
         }
      }
      this.ctl_tr(configData.tr, tableObj, "afterTitle");

      if (this.eternaData.records[configData.dataName] != null)
      {
         var rowCount = this.eternaData.records[configData.dataName].rowCount;
         eg_temp.dataName = configData.dataName;
         var nowRowNum = 1;
         for (var index = 0; index < rowCount; index++)
         {
            eg_temp.index = index;
            eg_temp.rowNum = nowRowNum;
            var trObj = this.ctl_tr(configData.tr, tableObj, "row");
            if (trObj != null)
            {
               nowRowNum++;
               // beforeRow 在ctl_tr中处理
               for(var i = 0; i < columns.length; i++)
               {
                  var column = columns[i];
                  this.ctl_container(index, percentWidth, trObj, column);
               }
               this.ctl_tr(configData.tr, tableObj, "afterRow");
            }
         }
      }

      eg_temp.index = null;
      eg_temp.rowNum = -1;
      this.ctl_tr(configData.tr, tableObj, "afterTable");

      this.createTR(configData.tr, tableObj, "tableList_tr", "final");
      this.egTemp(temp);
      eg_caculateWidth_fix = 0;

      return tableObj;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.createTableList = function(configData)
         {
            this.pushFunctionStack(new Array("createTableList", this._f_createTableList,
                  "configData", configData));
            var result = this._f_createTableList(configData);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.createTableList = this._f_createTableList;
      }

   Eterna.prototype._f_ctl_tr = function(configData, tableObj, rowType)
   {
      if (rowType == null || rowType == "row" || rowType == "title")
      {
         eg_temp.rowType = rowType == null ? "row" : rowType;
         if (configData != null && configData.beforeInit != null)
         {
            if (!this.executeScript(null, configData, configData.beforeInit))
            {
               return null;
            }
         }
         if (eg_temp.rowType == "row")
         {
            this.ctl_tr(configData, tableObj, "beforeRow");
            eg_temp.rowType = "row";
         }
         return this.createTR(configData, tableObj, "tableList_tr", "noBeforeInit");
      }
      else
      {
         eg_temp.rowType = rowType;
         if (configData != null)
         {
            var trObj = null;
            var old_moreRow = eg_cache.moreRow;
            do
            {
               eg_cache.moreRow = false;
               trObj = this.createTR(configData, tableObj, "tableList_tr", "sub");
            } while (trObj != null && eg_cache.moreRow);
            eg_cache.moreRow = old_moreRow;
         }
      }
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctl_tr = function(configData, tableObj, rowType)
         {
            this.pushFunctionStack(new Array("ctl_tr", this._f_ctl_tr,
                  "configData", configData, "tableObj", tableObj, "rowType", rowType));
            var result = this._f_ctl_tr(configData, tableObj, rowType);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctl_tr = this._f_ctl_tr;
      }

   Eterna.prototype.ctl_dealUpTitle_checkNone = function(columns, layer, start, count, setSame, upPlace)
   {
      // 检查是否都是未使用的空格
      var end = start + count;
      for(var i = start; i < end; i++)
      {
         var column = columns[i];
         if (column.title.upTitles != null)
         {
            if (column.title.upTitles.length > layer)
            {
               if (column.title.upTitles[layer].none)
               {
                  if (setSame)
                  {
                     column.title.upTitles[layer].none = false;
                     if (upPlace && i == start)
                     {
                        column.title.upTitles[layer].up = true;
                     }
                     else
                     {
                        column.title.upTitles[layer].same = true;
                     }
                  }
               }
               else
               {
                  return false;
               }
            }
         }
      }
      return true;
   }

   Eterna.prototype._f_ctl_dealUpTitle = function(columns)
   {
      var maxLayer = 0;
      for(var i = 0; i < columns.length; i++)
      {
         var column = columns[i];
         if (column.title.upTitles != null)
         {
            if (column.title.upTitles.length > maxLayer)
            {
               // 取出最高的层数
               maxLayer = column.title.upTitles.length;
            }
            // 初始化未设值的层
            for (var j = 0; j < column.title.upTitles.length; j++)
            {
               var upTitle = column.title.upTitles[j];
               if (upTitle.colSpan != null)
               {
                  upTitle.width = this.ctl_getColWidth(columns, i, upTitle.colSpan);
                  for (var k = i + 1; k < columns.length; k++)
                  {
                     var tmpCol = columns[k];
                     if (tmpCol.title.upTitles == null)
                     {
                        tmpCol.title.upTitles = new Array();
                     }
                     for (var tmpI = tmpCol.title.upTitles.length; tmpI <= j; tmpI++)
                     {
                        tmpCol.title.upTitles.push({none:true});
                     }
                     if (k - i < upTitle.colSpan)
                     {
                        tmpCol.title.upTitles[j].same = true;
                        tmpCol.title.upTitles[j].none = false;
                     }
                  }
               }
            }
         }
      }

      for(var i = 0; i < columns.length; i++)
      {
         var column = columns[i];
         if (column.title.upTitles != null)
         {
            for (var j = column.title.upTitles.length - 1; j >= 0; j--)
            {
               var upTitle = column.title.upTitles[j];
               if (upTitle.colSpan != null)
               {
                  upTitle.rowSpan = 1;
                  // 检测并合并上面的空格
                  for (var nowL = j + 1; nowL < maxLayer; nowL++)
                  {
                     if (this.ctl_dealUpTitle_checkNone(columns, nowL, i, upTitle.colSpan))
                     {
                        upTitle.rowSpan++;
                        this.ctl_dealUpTitle_checkNone(columns, nowL, i, upTitle.colSpan, true, true);
                     }
                     else
                     {
                        break;
                     }
                  }
                  // 检测并合并下方的空格
                  for (var nowL = j - 1; nowL >= 0; nowL--)
                  {
                     if (this.ctl_dealUpTitle_checkNone(columns, nowL, i, upTitle.colSpan))
                     {
                        upTitle.rowSpan++;
                        this.ctl_dealUpTitle_checkNone(columns, nowL, i, upTitle.colSpan, true, false);
                     }
                     else
                     {
                        break;
                     }
                  }
               }
            }
            // 处理底层标题的向上合并
            column.rowSpan = 1;
            for (var j = 0; j < column.title.upTitles.length; j++)
            {
               var upTitle = column.title.upTitles[j];
               if (upTitle.none)
               {
                  column.rowSpan++;
                  upTitle.none = false;
                  upTitle.up = true;
               }
               else
               {
                  break;
               }
            }
         }
         else if (maxLayer > 0)
         {
            column.rowSpan = maxLayer + 1;
         }
      }

      return maxLayer + 1; // 需要增加一层 本身的标题层
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctl_dealUpTitle = function(columns)
         {
            this.pushFunctionStack(new Array("ctl_dealUpTitle", this._f_ctl_dealUpTitle,
                  "columns", columns));
            var result = this._f_ctl_dealUpTitle(columns);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctl_dealUpTitle = this._f_ctl_dealUpTitle;
      }

   Eterna.prototype._f_ctl_getColWidth = function(columns, start, count)
   {
      if (start == null)
      {
         start = 0;
      }
      if (count == null)
      {
         count = columns.length;
      }
      var sumWidth = 0;
      var end = start + count;
      for (var i = start; i < end; i++)
      {
         if (columns[i].width == null)
         {
            return null;
         }
         sumWidth += columns[i].width;
         if (i > 0)
         {
             sumWidth += eg_caculateWidth_fix;
         }
      }
      return sumWidth;
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctl_getColWidth = function(columns, start, count)
         {
            this.pushFunctionStack(new Array("ctl_getColWidth", this._f_ctl_getColWidth,
                  "columns", columns, "start", start, "count", count));
            var result = this._f_ctl_getColWidth(columns, start, count);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctl_getColWidth = this._f_ctl_getColWidth;
      }

   Eterna.prototype._f_ctl_title = function(percentWidth, trObj, column, layer)
   {
      var temp = this.egTemp();

      eg_temp.name = column.name;
      if (column.container.value != null)
      {
         eg_temp.dataName = column.container.value.dataName;
         eg_temp.srcName = column.container.value.srcName;
      }
      if (column.initParam != null)
      {
         eg_temp.param = column.initParam;
      }
      else
      {
         eg_temp.param = {};
      }

      var showTitle = true;
      if (column.title.upTitles != null)
      {
         if (layer > 0)
         {
            // 层数大于0, 表示不是底层标题
            var nowL;
            if (column.title.upTitles.length > layer - 1)
            {
               nowL = layer - 1;
            }
            else
            {
               nowL = column.title.upTitles.length - 1;
            }
            var upTitle = column.title.upTitles[nowL];
            if (upTitle.same || upTitle.done)
            {
               // 如果是已处理或是和其他格相同, 则跳过
               upTitle = null;
               showTitle = false;
            }
            else if (upTitle.up)
            {
               // 如果是提升处理, 则判断下层的格
               upTitle.done = true;
               upTitle = null;
               for (var i = nowL - 1; i >= 0; i--)
               {
                  if (column.title.upTitles[i].up)
                  {
                     column.title.upTitles[i].done = true;
                  }
                  else
                  {
                     upTitle = column.title.upTitles[i];
                     break;
                  }
               }
            }
            if (upTitle != null)
            {
               showTitle = false;
               if (upTitle.none)
               {
                  // 空格的处理
                  var tdObj_t = jQuery("<td>" + eterna_table_td_empty_value + "</td>");
                  this.appendParam(tdObj_t, upTitle, "tableList_title");
                  if (column.width != null)
                  {
                     tdObj_t.attr("width", column.width + (percentWidth ? "%" : ""));
                  }
                  trObj.append(tdObj_t);
                  upTitle.done = true;
               }
               else
               {
                  // 上层标题的处理
                  var tdObj_t = jQuery("<td></td>");
                  this.appendParam(tdObj_t, upTitle, "tableList_title");
                  if (upTitle.width != null)
                  {
                     tdObj_t.attr("width", upTitle.width + (percentWidth ? "%" : ""));
                  }
                  if (upTitle.rowSpan != null && upTitle.rowSpan > 1)
                  {
                     tdObj_t.attr("rowSpan", upTitle.rowSpan);
                  }
                  if (upTitle.colSpan != null && upTitle.colSpan > 1)
                  {
                     tdObj_t.attr("colSpan", upTitle.colSpan);
                  }
                  var tmpObj;
                  if (upTitle.caption != null)
                  {
                     tmpObj = this.getValue(upTitle.caption);
                  }
                  else
                  {
                     tmpObj = {exists:0,value:"",html:0};
                  }
                  eterna_tableList_title_fn(column, tdObj_t, tmpObj, true, this);
                  trObj.append(tdObj_t);
                  upTitle.done = true;
               }
            }
         }
      }
      if (showTitle && !column.done)
      {
         var tdObj_t = jQuery("<td></td>");
         this.appendParam(tdObj_t, column.title, "tableList_title");
         if (column.rowSpan != null && column.rowSpan > 1)
         {
            tdObj_t.attr("rowSpan", column.rowSpan);
         }

         var tmpObj;
         if (column.title.caption != null)
         {
            var tmpObj = this.getValue(column.title.caption);
         }
         else
         {
            tmpObj = {exists:0,value:"",html:0};
         }
         eterna_tableList_title_fn(column, tdObj_t, tmpObj, false, this);
         if (column.width != null)
         {
            tdObj_t.attr("width", column.width + (percentWidth ? "%" : ""));
         }
         trObj.append(tdObj_t);
         column.done = true;
      }

      this.egTemp(temp);
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctl_title = function(percentWidth, trObj, column, layer)
         {
            this.pushFunctionStack(new Array("ctl_title", this._f_ctl_title,
                  "percentWidth", percentWidth, "trObj", trObj, "column", column,
                  "layer", layer));
            var result = this._f_ctl_title(percentWidth, trObj, column, layer);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctl_title = this._f_ctl_title;
      }

   Eterna.prototype._f_ctl_container = function(index, percentWidth, trObj, column)
   {
      var temp = this.egTemp();

      eg_temp.name = column.name;
      if (column.container.value != null)
      {
         eg_temp.dataName = column.container.value.dataName;
         eg_temp.srcName = column.container.value.srcName;
      }
      var tmpObj;
      if (column.container.value != null)
      {
         tmpObj = this.getValue_fromRecords(column.container.value.dataName, column.container.value.srcName, index);
         if (!tmpObj.exists)
         {
            var tmpObj2 = this.getValue(column.container.defaultValue);
            tmpObj.exists = tmpObj2.exists;
            tmpObj.html = tmpObj2.html;
            tmpObj.value = tmpObj2.value;
         }
      }
      else
      {
         tmpObj = this.getValue(column.container.defaultValue);
      }
      eg_temp.valueObj = tmpObj;
      if (column.initParam != null)
      {
         eg_temp.param = column.initParam;
      }
      else
      {
         eg_temp.param = {};
      }
      if (column.beforeInit != null && !column.DBI)
      {
         if (!this.executeScript(null, column, column.beforeInit))
         {
            this.egTemp(temp);
            return;
         }
      }

      var tdObj_c = jQuery("<td></td>");
      trObj.append(tdObj_c);
      this.appendParam(tdObj_c, column.container, "tableList_container");

      if (column.subs == null && column.typicalComponent == null)
      {
         if (tmpObj.exists && tmpObj.value != "")
         {
            if (tmpObj.html)
            {
               tdObj_c.html(tmpObj.value);
            }
            else
            {
               tdObj_c.text(tmpObj.value);
            }
         }
         else
         {
            tdObj_c.html(eterna_table_td_empty_value);
         }
      }
      if (column.width != null)
      {
         tdObj_c.attr("width", column.width + (percentWidth ? "%" : ""));
      }

      if (column.subs != null)
      {
         this.dealSubComponent(column, tdObj_c);
      }

      if (column.typicalComponent != null)
      {
         var tmpObj = this.createComponent(this.eternaData.typical[column.typicalComponent], tdObj_c);
         if (tmpObj != null)
         {
            tdObj_c.append(tmpObj);
         }
      }
      if (column.init != null)
      {
         this.executeScript(tdObj_c, column, column.init);
      }

      this.egTemp(temp);
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.ctl_container = function(index, percentWidth, trObj, column)
         {
            this.pushFunctionStack(new Array("ctl_container", this._f_ctl_container,
                  "index", index, "percentWidth", percentWidth, "trObj", trObj, "column", column));
            var result = this._f_ctl_container(index, percentWidth, trObj, column);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.ctl_container = this._f_ctl_container;
      }

   Eterna.prototype._f_appendParam = function(obj, configData, objType)
   {
      if (configData == null || configData.ignoreGlobal == null || !configData.ignoreGlobal)
      {
         if (this.eternaData.global[objType] != null)
         {
            if (this.eternaData.global[objType].className != null)
            {
               obj.addClass(this.eternaData.global[objType].className);
            }
            if (this.eternaData.global[objType].attr != null)
            {
               obj.attr(this.eternaData.global[objType].attr);
            }
            if (this.eternaData.global[objType].css != null)
            {
               obj.css(this.eternaData.global[objType].css);
            }
         }
      }
      if (configData != null)
      {
         if (configData.className != null)
         {
            obj.addClass(configData.className);
         }
         if (configData.attr != null)
         {
            obj.attr(configData.attr);
         }
         if (configData.css != null)
         {
            obj.css(configData.css);
         }
      }
   }
      if (this.eterna_debug >= ED_FN_CALLED)
      {
         Eterna.prototype.appendParam = function(obj, configData, objType)
         {
            this.pushFunctionStack(new Array("appendParam", this._f_appendParam,
                  "obj", obj, "configData", configData, "objType", objType));
            var result = this._f_appendParam(obj, configData, objType);
            this.popFunctionStack();
            if (typeof result != 'undefined')
            {
               return result;
            }
         }
      }
      else
      {
         Eterna.prototype.appendParam = this._f_appendParam;
      }

   }

}

// 添加一个需要等待初始化的对象
function eterna_addWillInitObj(obj, priority)
{
   if (priority == null)
   {
      eg_cache.willInitObjs.push(obj);
      return;
   }
   var tmp = parseInt(priority);
   if (isNaN(tmp) || tmp < 0)
   {
      throw new Error("Error priority:[" + priority + "].");
   }
   eg_cache.willInitObjs.push(obj);
   if (tmp < eg_cache.willInitObjs.length - 1)
   {
      for (var i = eg_cache.willInitObjs.length; i > tmp; i--)
      {
         eg_cache.willInitObjs[i] = eg_cache.willInitObjs[i - 1];
      }
      eg_cache.willInitObjs[tmp] = obj;
   }
}

// 触发所有等待初始化的对象的willInit事件
function eterna_doInitObjs()
{
   var objs = eg_cache.willInitObjs;
   eg_cache.willInitObjs = [];
   for (var i = 0; i < objs.length; i++)
   {
      objs[i].trigger("willInit");
   }
}

// 检查打开的窗口是否载入完成
function eterna_checkOpenWindowOnLoad(onLoadEvent)
{
   var needMore = false;
   if (onLoadEvent != null)
   {
      if (onLoadEvent._cacheIndex == null)
      {
         var canInsertIndex = -1;
         var arr = eg_cache.openWindowOnLoad;
         for (var i = 0; i < arr.length; i++)
         {
            if (arr[i] == null)
            {
               canInsertIndex = i;
               break;
            }
         }
         if (canInsertIndex == -1)
         {
            onLoadEvent._cacheIndex = arr.length;
            arr.push(onLoadEvent);
         }
         else
         {
            arr[canInsertIndex] = onLoadEvent;
            onLoadEvent._cacheIndex = canInsertIndex;
         }
      }
      if (!eg_cache.openWindowOnLoad_threadStarted)
      {
         eg_cache.openWindowOnLoad_threadStarted = true;
         needMore = true;
      }
      else
      {
         return;
      }
   }
   else
   {
      var arr = eg_cache.openWindowOnLoad;
      for (var i = 0; i < arr.length; i++)
      {
         if (arr[i] != null)
         {
            if (arr[i]() == -1)
            {
               needMore = true;
            }
         }
      }
   }

   if (needMore)
   {
      setTimeout("eterna_checkOpenWindowOnLoad();", 600);
   }
   else
   {
      eg_cache.openWindowOnLoad_threadStarted = false;
   }
}

// 检查延迟载入是否完成
function eterna_delayInit(inThread)
{
   var needMore = false;
   if (eg_cache.willInitEterna_threadStarted)
   {
      if (inThread)
      {
         var data = eg_cache.willInitEterna;
         for(var key in data)
         {
            if (data[key] != null)
            {
               if (data[key].reInit() == -1)
               {
                  needMore = true;
               }
            }
         }
      }
      else
      {
         return;
      }
   }
   else
   {
      needMore = true;
      eg_cache.willInitEterna_threadStarted = true;
   }
   if (needMore)
   {
      setTimeout("eterna_delayInit(true);", 600);
   }
   else
   {
      eg_cache.willInitEterna_threadStarted = false;
   }
}

/**
 * 格式化数字显示方式
 * 用法
 * formatNumber(12345.999, "#,##0.00");
 * formatNumber(12345.999, "#,##0.##");
 * formatNumber(123, "000000");
 * @param num
 * @param pattern
 */
function ef_formatNumber(num, pattern)
{
   if (typeof num != "number")
   {
      num = parseFloat(num);
   }
   if (isNaN(num))
   {
      return "?";
   }
   var firstStr = "";
   var lastStr = "";
   var strarr = num ? num.toString().split('.') : ['0'];
   var fmtarr = pattern ? pattern.split('.') : [''];
   var retstr = '';
   var fmt1 = null;
   var fmt2 = null;
   // 处理有多个"."的情况
   for (var i = 0; i < fmtarr.length; i++)
   {
      var tmpStr = fmtarr[i];
      if (fmt1 == null)
      {
         if (/[0#]/.test(tmpStr))
         {
            fmt1 = tmpStr;
            var checkStr = fmt1.substr(fmt1.length - 1, 1);
            if (checkStr != "#" && checkStr != "0" && checkStr != ",")
            {
               fmt2 = "";
            }
            if (i > 0)
            {
               checkStr = tmpStr.substr(0, 1);
               if (checkStr == "#" || checkStr == "0")
               {
                  firstStr = firstStr.substr(0, firstStr.length - 1);
                  fmt1 = "";
                  fmt2 = tmpStr;
               }
            }
         }
         else
         {
            firstStr += tmpStr + (i < fmtarr.length - 1 ? "." : "");
         }
      }
      else if (fmt2 == null)
      {
         fmt2 = tmpStr;
      }
      else
      {
         lastStr += "." + tmpStr;
      }
   }
   if (fmt1 == null)
   {
      fmt1 = "";
      fmt2 = "";
   }
   if (fmt2 == null)
   {
      fmt2 = "";
   }

   /* 整数部分 */
   var str = strarr[0];
   var fmt = fmt1;
   var i = str.length - 1;
   var comma = 0;
   var tmpCommaCount = 0;
   // 处理起始的format字符
   if (fmt.length > 0)
   {
      var tmpI = 0;
      var checkStr = fmt.substr(tmpI++, 1);
      while (checkStr != "#" && checkStr != "0" && checkStr != "," && tmpI < fmt.length)
      {
         firstStr += checkStr;
         checkStr = fmt.substr(tmpI++, 1);
      }
      if (checkStr != "#" && checkStr != "0" && checkStr != ",")
      {
         firstStr += checkStr;
      }
   }
   // 去掉其他的符号
   fmt = fmt.replace(/[^0,#]/g, "");
   // 处理负号
   var negative = "";
   if (str.length > 0)
   {
      if (str.substr(0, 1) == "-")
      {
         str = str.substr(1, str.length - 1);
         negative = "-";
         i--;
      }
   }
   for (var f = fmt.length - 1; f >= 0; f--)
   {
      switch (fmt.substr(f, 1))
      {
         case '#':
            if (i >= 0) retstr = str.substr(i--, 1) + retstr;
            tmpCommaCount++;
            break;
         case '0':
            if (i >= 0) retstr = str.substr(i--, 1) + retstr;
            else retstr = '0' + retstr;
            tmpCommaCount++;
            break;
         case ',':
            comma = tmpCommaCount;
            tmpCommaCount = 0;
            retstr = ',' + retstr;
            break;
      }
   }
   // 如果还有数字并且需要证书部分, 则补充数字
   if (i >= 0 && fmt != "")
   {
      if (comma)
      {
         var l = str.length;
         // 先把第一个","补齐
         if (i >= comma - tmpCommaCount && comma - tmpCommaCount > 0)
         {
            retstr = ',' + str.substr(i, comma - tmpCommaCount) + retstr;
            i -= comma - tmpCommaCount;
         }
         var tmpCount = 0;
         for (; i >= 0; i--)
         {
            tmpCount++;
            retstr = str.substr(i, 1) + retstr;
            // 根据计算得出的","间隔进行补充
            if (i > 0 && (tmpCount % comma) == 0) retstr = ',' + retstr;
         }
      }
      else retstr = str.substr(0, i + 1) + retstr;
  }

   retstr = retstr + '.';
   /* 处理小数部分 */
   str = strarr.length > 1 ? strarr[1] : '';
   var tmpLast = fmt2 == "" ? fmt1 : fmt2;
   fmt = fmt2;
   i = 0;
   // 处理结束的format字符
   if (tmpLast.length > 0)
   {
      var tmpI = tmpLast.length - 1;
      var checkStr = tmpLast.substr(tmpI--, 1);
      while (checkStr != "#" && checkStr != "0" && tmpI >= 0)
      {
         lastStr = checkStr + lastStr;
         checkStr = tmpLast.substr(tmpI--, 1);
      }
      if (checkStr != "#" && checkStr != "0")
      {
         lastStr = checkStr + lastStr;
      }
   }
   // 去掉其他的符号
   fmt = fmt.replace(/[^0#]/g, "");
   for (var f = 0; f < fmt.length; f++)
   {
      switch (fmt.substr(f, 1))
      {
         case '#':
            if (i < str.length) retstr += str.substr(i++, 1);
            break;
         case '0':
            if (i < str.length)
            {
               var tmpChar = str.substr(i++, 1);
               if (tmpChar != "0") retstr += tmpChar;
               else retstr += "(0)";
            }
            else retstr += "(0)"; // 这里补上(0), 以区分不需要的0
            break;
      }
   }
   //alert(retstr);

   var result = retstr.replace(/^,+/, '')     //去除前面的","
         .replace(/0+$/, '')                  //去除末尾的"0"
         .replace(/\(0\)/g, '0')                //将"(0)"替换回"0"
         .replace(/\.$/, '');                 //去除末尾的"."
   //alert(retstr);
   if (/^0*\.?0*$/.test(result))
   {
      negative = "";
   }
   return firstStr + negative + result + lastStr;
}
