var maxConfig=
{
};
maxConfig.defaultFile="$main";
maxConfig.files=
{
};
maxConfig.silentChange=false;
maxConfig.setActiveFile=function(_1,_2)
{
  if(!_1)
  {
    _1=maxConfig.defaultFile;
  }
  if(_2==undefined)
  {
    _2=false;
  }
  if(!maxConfig.files[_1])
  {
    maxConfig.files[_1]=
    {
      api:null,modified:false,saveOnChange:_2
    };
    try
    {
      maxConfig.files[_1].api=external.max_getObject(max_security_id,"INIManager");
    }
    catch(e)
    {
      alert("maxConfig :: INIT OBJECT FAILED");
      return;
    }
    maxConfig.files[_1].api.fileName=_1;
    if(!maxConfig.files[_1].api.load())
    {
      alert("maxConfig :: LOAD FILE FAILED - "+_1);
      return;
    }
  }
  maxConfig.activeFile=maxConfig.files[_1];
};

maxConfig.ui=
{
};
maxConfig.ui.buildItems=function(_3)
{
  var _4="";
  for(var i=0;i<_3.length;i++)
  {
    var _6=_3[i];
    var _7="";
    if(!_6.type)
    {
      alert("maxConfig.ui.buildItems :: missing item type\n"+$toJSON(_6));
      continue;
    }
    if((_6.id&&!_6.key)||(!_6.id&&_6.key))
    {
      alert("maxConfig.ui.buildItems :: missing item id/key for \""+_6.id+"\"");
      continue;
    }
    switch(_6.type)
    {
      case "header":
      _7="<h5>"+_6.html+"</h5>\n";
      _6.noWrapper=true;
      break;
      case "html":
      _7=_6.html;
      _6.noWrapper=true;
      break;
      case "text":
      _7=_6.text.$encodeHTML();
      break;
      case "hr":
      _7="<hr />\n";
      _6.noWrapper=true;
      break;
      case "checkbox":
      _7=maxConfig.ui.checkbox.build(_6);
      break;
      case "textbox":
      _7=maxConfig.ui.textbox.build(_6);
      break;
      case "textarea":
      _7=maxConfig.ui.textbox.buildArea(_6);
      break;
      case "color":
      _7=maxConfig.ui.color.build(_6);
      break;
      case "key":
      _7=maxConfig.ui.key.build(_6);
      break;
      case "radio":
      _7=maxConfig.ui.radio.build(_6);
      break;
      case "folder":
      _7=maxConfig.ui.folder.build(_6);
      break;
      default:
      alert("maxConfig.ui.buildPage :: unknown type of item\n"+$toJSON(_6));
    }
    if(_6.noWrapper)
    {
      _4+=_7;
    }
    else
    {
      if(_6.type=="text")
      {
        _4+="<p>"+_7+"</p>";
      }
      else
      {
        _4+="<div class=\""+(_6.disabled?"item-disabled":"item")+"\" id=\"item_"+_6.id+"\">"+_7+"</div>";
      }
    }
  }
  return _4;
};
maxConfig.ui.disableItem=function(_8)
{
  var _9=$id(_8);
  if(_9)
  {
    _9.disabled=true;
  }
  var _a=$name(_8);
  if(_a)
  {
    for(var i=0;i<_a.length;i++)
    {
      _a[i].disabled=true;
    }
  }
  var _9=$id("item_"+_8);
  if(!_9)
  {
    return;
  }
  _9.className="item-disabled";
};
maxConfig.ui.enableItem=function(_c)
{
  var _d=$id(_c);
  if(_d)
  {
    _d.disabled=false;
  }
  var _e=$name(_c);
  if(_e)
  {
    for(var i=0;i<_e.length;i++)
    {
      _e[i].disabled=false;
    }
  }
  var _d=$id("item_"+_c);
  if(!_d)
  {
    return;
  }
  _d.className="item";
};
maxConfig.ui.getItemValue=function(_10)
{
  if(_10.html==undefined)
  {
    _10.html=$lang(_10.id);
  }
  if(_10.pre==undefined)
  {
    _10.pre="";
  }
  if(_10.suf==undefined)
  {
    _10.suf="";
  }
  if(_10.onAfterClick==undefined)
  {
    _10.onAfterClick="";
  }
  
  if(bDebug)
  	var _11 = null;
  else
  	var _11 = external.GetSetting(_10.key);
  if(_11==null || _11=="")
  {
    if(_10.defaultValue)
    {
      return _10.defaultValue;
    }
    else
    {
      return "";
    }
  }
  else
  {
    return _11;
  }
};
maxConfig.ui.checkbox=
{
};
maxConfig.ui.checkbox.build=function(_12)
{
  var _13="";
  if(maxConfig.ui.getItemValue(_12)=="1")
  {
    _13+=" checked=\"checked\"";
  }
  if(_12.disabled)
  {
    _13+=" disabled=\"disabled\"";
  }
  _13+=" onclick=\"maxConfig.ui.checkbox.set('"+_12.id+"', '"+_12.key+"', '"+_12.section+"', '"+_12.file+"');"+_12.onAfterClick+"\"";
  _13="<input type=\"checkbox\" id=\""+_12.id+"\""+_13+" />"+"<label for=\""+_12.id+"\"> "+_12.html+"</label>";
  _13=_12.pre+_13+_12.suf;
  return _13;
};
maxConfig.ui.checkbox.set=function(_14,key,_16,_17)
{
  var obj=$id(_14);
  if(obj)
  {
    if(obj.checked)
    {
      external.SetSetting(key,"1");
    }
    else
    {
      external.SetSetting(key,"0");
    }
  }
  else
  {
    alert("maxConfig.ui.checkbox.set :: invalid id "+_14);
  }
};
maxConfig.ui.textbox=
{
};
maxConfig.ui.textbox.build=function(_19,_1a)
{
  var _1b="";
  _1b+=" value=\""+maxConfig.ui.getItemValue(_19).$encodeHTML()+"\"";
  if(_19.disabled)
  {
    _1b+=" disabled=\"disabled\"";
  }
  _1b+=" onchange=\"maxConfig.ui.textbox.set('"+_19.id+"', '"+_19.key+"', '"+_19.section+"', '"+_19.file+"');\"";
  if(_19.tagx)
  {
    _1b+=" "+_19.tagx;
  }
  _1b=" <input type=\"text\" class=\"text\" id=\""+_19.id+"\""+_1b+" /> ";
  _1b=_19.pre+_1b+_19.suf;
  return _1b;
};
maxConfig.ui.textbox.buildArea=function(_1c)
{
  var _1d="";
  var _1e=maxConfig.ui.getItemValue(_1c).$encodeHTML(true);
  if(_1c.disabled)
  {
    _1d+=" disabled=\"disabled\"";
  }
  _1d+=" onchange=\"maxConfig.ui.textbox.set('"+_1c.id+"', '"+_1c.key+"', '"+_1c.section+"', '"+_1c.file+"');\"";
  if(_1c.tagx)
  {
    _1d+=" "+_1c.tagx;
  }
  _1d=" <textarea id=\""+_1c.id+"\""+_1d+">"+_1e+"</textarea>";
  _1d=_1c.pre+_1d+_1c.suf;
  return _1d;
};
maxConfig.ui.textbox.set=function(_1f,key,_21,_22)
{
  var obj=$id(_1f);
  if(obj)
  {
    external.SetSetting(key,obj.value);
  }
  else
  {
    alert("maxConfig.ui.textbox.set :: invalid id "+_1f);
  }
};
maxConfig.ui.color=
{
};
maxConfig.ui.color.build=function(_24)
{
  var _25=maxConfig.ui.getItemValue(_24);
  var _26=maxConfig.ui.color.calculateInvertColor(_25);
  var _27="";
  _27+=" <span id=\""+_24.id+"\" class=\"color-spot\" style=\"color: "+_26+";background: "+_25.$encodeHTML()+";\""+" onclick=\"this.blur();maxConfig.ui.color.set('"+_24.id+"', '"+_24.key+"', '"+_24.section+"', '"+_24.file+"');"+_24.onAfterClick+"\">"+_25.$encodeHTML()+"</span> ";
  _27=_24.pre+_27+_24.suf;
  return _27;
};
maxConfig.ui.color.set=function(_28,key,_2a,_2b)
{
  var obj=$id(_28);
  if(!obj)
  {
    return;
  }
  var _2d=obj.innerHTML;
  var _2e=external.max_getObj(max_security_id,"utilities");
  var _2f=_2e.getColor(_2d);
  if(_2f!=undefined)
  {
    maxConfig.ini.setValue(_2a,key,_2f);
    maxConfig.ui.color.updateUI(_28,_2f);
  }
};
maxConfig.ui.color.calculateInvertColor=function(_30)
{
  var _31=_30.replace(/[^0-9a-f]/ig,"");
  if(_31.length!=6)
  {
    return "#FFFFFF";
  }
  var _32="";
  for(var i=0;i<3;i++)
  {
    var _34=_31.substr(i*2,2);
    var _35=parseInt(_34,16);
    _35=255-_35;
    _34=_35.toString(16);
    if(_34.length!=2)
    {
      _34="0"+_34;
    }
    _32+=_34.toUpperCase();
  }
  return _32;
};
maxConfig.ui.color.updateUI=function(_36,_37)
{
  var obj=$id(_36);
  if(obj)
  {
    obj.style.color=maxConfig.ui.color.calculateInvertColor(_37);
    obj.style.background=_37;
    obj.innerHTML=_37.$encodeHTML();
  }
};
maxConfig.ui.radio=
{
};
maxConfig.ui.radio.build=function(_39)
{	
  var _3a=maxConfig.ui.getItemValue(_39);  
  if(_39.inline)
  {
    _39.inlineSpacer=_39.inlineSpacer?_39.inlineSpacer:" &nbsp; ";
  }
  var _3b="";
  if(!_39.noHeader)
  {
    _3b+="<h5>"+_39.html+"</h5>\n";
  }
  for(var i=0;i<_39.choices.length;i++)
  {
    var _3d=_39.choices[i];
    _3b+=(_39.inline?"<span class=\"radio-item-inline"+(_3d.disabled?" radio-item-disabled":"")+"\">":"<div class=\"radio-item"+(_3d.disabled?" radio-item-disabled":"")+"\">")+(_3d.pre?_3d.pre:"")+"<input type=\"radio\" name=\""+_39.id+"\" id=\""+_39.id+"_"+i+"\" value=\""+_3d.value+"\""+" onclick=\"maxConfig.ui.radio.set('"+_39.id+"', '"+_39.key+"', '"+_39.section+"', '"+_39.file+"');"+_39.onAfterClick+"\""+" "+((_3a==_3d.value)?"checked=\"checked\"":"")+" "+(_39.disabled||_3d.disabled?"disabled=\"disabled\"":"")+"/>"+"<label for=\""+_39.id+"_"+i+"\"> "+_3d.html+"</label>"+(_3d.suf?_3d.suf:"")+(_39.inline?"</span>"+_39.inlineSpacer:"</div>");
  }
  
  _3b=_39.pre+_3b+_39.suf;
  return _3b;
};
maxConfig.ui.radio.set=function(_3e,key,_40,_41)
{
  var _42=$name(_3e);
  if(_42)
  {
    var _43=_42[0].value;
    for(var i=0;i<_42.length;i++)
    {
      if(_42[i].checked)
      {
        _43=_42[i].value;
        break;
      }
    }
    external.SetSetting(key,_43);
  }
  else
  {
    alert("maxConfig.ui.radio.set :: invalid id "+_3e);
  }
};
maxConfig.ui.key=
{
};
maxConfig.ui.key.build=function(_45)
{
  var _46=maxConfig.ui.key.parseData(maxConfig.ui.getItemValue(_45));
  var _47="";
  _47+=" <span id=\""+_45.id+"\" class=\"label-item\">"+_46[1].$encodeHTML()+"</span> ";
  _47+=" &nbsp; <a href=\"javascript:;\" onclick=\"this.blur();maxConfig.ui.key.set('"+_45.id+"', '"+_45.key+"', '"+_45.section+"', '"+_45.file+"');"+_45.onAfterClick+"\">"+$lang("set_key")+"</a> ";
  _47=_45.pre+_47+_45.suf;
  return _47;
};
maxConfig.ui.key.set=function(_48,key,_4a,_4b)
{
  var _4c=external.max_invoke("GetHotKey");
  if(_4c!=-1)
  {
    maxConfig.ini.setValue(_4a,key,_4c);
    maxConfig.ui.key.updateUI(_48,_4c);
  }
};
maxConfig.ui.key.parseData=function(_4d)
{
  if(_4d==undefined)
  {
    _4d="";
  }
  var arr=_4d.split("$:$");
  if(arr.length==2)
  {
    if(arr[1]!="")
    {
      return arr;
    }
  }
  arr[0]="csa_0";
  arr[1]="none";
  return arr;
};
maxConfig.ui.key.updateUI=function(_4f,_50)
{
  var obj=$id(_4f);
  if(obj)
  {
    var _52=maxConfig.ui.key.parseData(_50);
    if(_52[1]=="none")
    {
      try
      {
        _52[1]=$lang("none");
      }
      catch(e)
      {
      }
    }
    obj.innerHTML=_52[1].$encodeHTML();
  }
  else
  {
    alert("maxConfig.ui.key.updateUI :: invalid id "+_4f);
  }
};
maxConfig.ui.folder=
{
};
maxConfig.ui.folder.build=function(_53)
{
  var _54=maxConfig.ui.getItemValue(_53);
  if(_54=="")
  {
    _54="...";
  }
  _54=maxConfig.ui.folder.cutString(_54);
  _53.subType=_53.subType?_53.subType:"folder";
  var _55="";
  _55+="<span id=\""+_53.id+"\" class=\"label-item\">"+_54+"</span>";
  _55+=" &nbsp; <a href=\"javascript:;\" onclick=\"this.blur();maxConfig.ui.folder.set('"+_53.id+"', '"+_53.key+"', '"+_53.section+"', '"+_53.file+"', '"+_53.subType+"');"+_53.onAfterClick+"\">"+$lang("browse")+"</a> ";
  _55=_53.pre+_55+_53.suf;
  return _55;
};
maxConfig.ui.folder.set=function(_56,key,_58,_59,_5a)
{
  var _5b=(_5a=="fav")?external.max_invoke("SelFavFolder"):external.max_invoke("SelFolder");
  if(_5b!=0)
  {
    maxConfig.ini.setValue(_58,key,_5b);
    maxConfig.ui.folder.updateUI(_56,_5b);
  }
};
maxConfig.ui.folder.cutString=function(_5c)
{
  if(_5c.length>50)
  {
    var _5d="";
    var pos=_5c.lastIndexOf("/");
    if(pos>25)
    {
      _5d=_5c.substring(pos,_5c.length);
    }
    else
    {
      _5d=_5c.substring(_5c.length-25,_5c.length);
    }
    return _5c.substr(0,25)+"..."+_5d;
  }
  return _5c;
};
maxConfig.ui.folder.updateUI=function(_5f,_60)
{
  var obj=$id(_5f);
  if(obj)
  {
    if(_60=="")
    {
      _60=="...";
    }
    _60=maxConfig.ui.folder.cutString(_60);
    obj.innerHTML=_60.$encodeHTML();
  }
  else
  {
    alert("maxConfig.ui.folder.updateUI :: invalid id "+_5f);
  }
};
maxConfig.ini=
{
};
maxConfig.ini.encodeChars=function(str,_63)
{
  if(typeof (str)!="string")
  {
    return str;
  }
  str=str.replace(/\t/g,"\\t");
  str=str.replace(/\n/g,"\\n");
  str=str.replace(/\r/g,"\\r");
  if(_63!=undefined)
  {
    str=str.replace(/\=/g,"&#61;");
    str=str.replace(/\[/g,"{{");
  }
  return str;
};

maxConfig.ini.decodeChars=function(str,_65){
if(typeof (str)!="string"){
return str;
}
str=str.replace(/\\t/g,"\t");
str=str.replace(/\\n/g,"\n");
str=str.replace(/\\r/g,"\r");
if(_65!=undefined){
str=str.replace(/\&\#61;/g,"=");
str=str.replace(/\{\{/g,"[");
}
return str;
};

