/**************************************************************
 Daemon.js
 Date: 2009.1
 --------------------------------------------------------
 Note:This file is based on "/script/config.js" for some configurations:
  _ModelName
  _Wireless
**************************************************************/



function WizardDaemon()
{
  this._GlobalVar = [];
  this._GlobalVarDefault = {
    ModelName:                      _ModelName,
    isWPS:                          0,
    isWireless:                     _Wireless,
    isPC_Online:                    0,
    isDevice_Online:                0,
    isRemote_Access:                0,
    isLocal_Ip_Accessible:          0,
    isLocal_Ip_Accessible_Msg:      "",
    Is_UPnP_Support:                -1,
    Is_UPnP_Support_Msg:            "",
    User_Portal_URL:                "",
    Device_Portal_URL:              "",
    DlifeNo:                        "",
    Dlife_Key:                      "",
    DevicePasswd:                   "",
    Language:                       "",
    isMydlink:                      _isMydlink,
    isWAN_Test_OK:                  0,
    isIntranetOnly:                 0,
	Session_Key:					"",
    Temp:                           []
  };
  this.ResetDefault();
  this._PageFlow = []
  
}

WizardDaemon.prototype = {
  ResetDefault:function()
  {
    for(v in this._GlobalVarDefault)
    {
      this._GlobalVar[v] = this._GlobalVarDefault[v]; 
    }
  },
  ResetGlobalVar:function(varName)
  {
    this._GlobalVar[varName] = this._GlobalVarDefault[varName];
  },
  setGlobalVar:function(varName, value)
  {
    try
    {
      this._GlobalVar[varName] = value;
    }catch(e){}
  },
  getGlobalVar:function(varName)
  {
    return this._GlobalVar[varName];
  },
  getFilename:function(PageID)
  {
    for(p in this._PageFlow)
    {
      if(this._PageFlow[p]["PageID"] == PageID) return this._PageFlow[p]["Filename"];
    }
    return "";
  },
  getClassPageOrder:function(PageID)
  {
    for(p in this._PageFlow)
    {
      if(this._PageFlow[p]["PageID"] == PageID) return this._PageFlow[p]["ClassPageOrder"];
    }
    return 1;
  },
  getClassPageTotal:function(PageID)
  {
    for(p in this._PageFlow)
    {
      if(this._PageFlow[p]["PageID"] == PageID) return this._PageFlow[p]["ClassPageTotal"];
    }
    return 1;
  },
  getNextPage:function(PageID)
  {
    var is_searched = 0;
    var currentPageFilename = "";
    for(p=0;p<this._PageFlow.length;p++)
    {
      if(this._PageFlow[p]["PageID"] == PageID || is_searched)
      {
        if(!is_searched)currentPageFilename = this._PageFlow[p]["Filename"]; 
        is_searched = 1;
        if(parseInt(p,10) < this._PageFlow.length - 1)
        {
          is_condition_matched = 1;
          p_next = parseInt(p,10)+1;
          for(c in this._PageFlow[p_next]["Condition"])
          {
            if(this._GlobalVar[c]!=this._PageFlow[p_next]["Condition"][c])
            {
              is_condition_matched = 0;
              break;
            }
          }
          if(!is_condition_matched) continue;
          
          return this._PageFlow[p_next]["Filename"];
        }
      }
    }
    return currentPageFilename;
  },
  getPrePage:function(PageID)
  {
    var is_searched = 0;
    var currentPageFilename = "";
    for(p=this._PageFlow.length-1;p>=0;p--)
    {
      if(this._PageFlow[p]["PageID"] == PageID || is_searched)
      {
        if(!is_searched)currentPageFilename = this._PageFlow[p]["Filename"]; 
        is_searched = 1;
        if(parseInt(p,10) > 0)
        {
          is_condition_matched = 1;
          p_pre = parseInt(p,10)-1;
          for(c in this._PageFlow[p_pre]["Condition"])
          {
            if(this._GlobalVar[c]!=this._PageFlow[p_pre]["Condition"][c])
            {
              is_condition_matched = 0;
              break;
            }
          }
          if(!is_condition_matched) continue;
          
          return this._PageFlow[p_pre]["Filename"];
        }
      }
    }
    return currentPageFilename;
  }

  
  
  
}