//================================= CLASS CONSTRUCTOR ========================================
function ResMgr()
{
//MEMBER VARIABLES
//The resource map that this manager contains ...
 this.resMap = new Array();
}

//====================================== STATIC ==============================================

//====================================== MEMBERS =============================================
//This will put a specified resource(value) into the groupid->id resource ...
ResMgr.prototype.setResource = function(id,value)
{
//Using associative arrays to store id data
 this.resMap[id] = value;
}

ResMgr.prototype.replaceParams = function(resStr,params)
{
 var
  pid = 0,
  id = 0,
  nid = 0,
  str1 = "";

//Example of one parameter: %FILE_NAME%
//Getting the first id of % ...
 id = resStr.indexOf("%");
 while (id != -1)
 {
//Getting first string part ...
  str1 = resStr.slice(0,id);
//Deleting all chars till the "%" ...
  resStr = resStr.slice(id+1);
//Finding the second "%" ...
  nid = resStr.indexOf("%");
  if (nid == -1)
   return null;
//Deleting all chars till the "%" ...
  resStr = resStr.slice(nid+1);
//We'll reformat the string ...
  resStr = str1 + params[pid++] + resStr;
//Finding the next % ...
  id = resStr.indexOf("%");
 }
 return resStr;
}

//This will return a resource found in id resource ...
ResMgr.prototype.getResource = function(id,params)
{
 var
  value = null;

 value = this.resMap[id];
 if (value == undefined)
 {
  alert('Request for undefined resource => ['+id+']');
  return null;
 }
//Replacing the params ...
 value = this.replaceParams(value,params);
 if (value == null)
  alert('Resource parameters are not correct => ['+id+']');
 return value;
}

ResMgr.prototype.getResource0 = function(id)
{
 var
  prm = new Array();

 return this.getResource(id,prm);
}

ResMgr.prototype.getResource1 = function(id,p1)
{
 var
  prm = new Array();

 prm.push(p1);
 return this.getResource(id,prm);
}

ResMgr.prototype.getResource2 = function(id,p1,p2)
{
 var
  prm = new Array();

 prm.push(p1);
 prm.push(p2);
 return this.getResource(id,prm);
}

ResMgr.prototype.getResource3 = function(id,p1,p2,p3)
{
 var
  prm = new Array();

 prm.push(p1);
 prm.push(p2);
 prm.push(p3);
 return this.getResource(id,prm);
}

