/*

  (c) 2006 TUFaT.com. All Rights Reserved

*/

/* sound options enumeration for sound options tab in options window */
optionsSound = new Array (
  "LeaveRoom",
  "InitialLogin",
  "EnterRoom",
  "Logout",
  "OtherUserEnters",
  "UserMenuMouseOver",
  "ReceiveMessage",
  "RoomOpenClose",
  "SubmitMessage",
  "ComboListOpenClose",
  "PrivateMessageReceived",
  "PopupWindowOpen",
  "InvitationReceived",
  "PopupWindowCloseMin",
  "UserBannedBooted",
  "PressButton"
);

function createCPicker () {
  var cpDiv = document.createElement ("div");

  if (cpDiv == null)
    return;

  setElementSaP (cpDiv, null, {"id": "colorPicker"});

  var colors = new Array ();

  for (var i = 0; i < 6; i++)
    for (var j = 0; j < 6; j++)
      for (var k = 0; k < 6; k++) {
        var b = i * 51;
        var r = j * 51;
        var g = k * 51;

        var idx = (i * 18) + (j * 6) + k;
        //colors[idx] = "rgb(" + r + ", " + g + ", " + b + ")";
        colors[idx] = dec2hex (r) + dec2hex (g) + dec2hex (b);
      }

  for (var i = 0; i < 6; i ++)
    for (var j = 3; j < 6; j ++)
      for (var k = 0; k < 6; k ++) {
        var b = i * 51;
        var r = j * 51;
        var g = k * 51;

        var idx = 108 + (i * 18) + ((j - 3) * 6) + k;
        //colors[idx] = "rgb(" + r + ", " + g + ", " + b + ")";
        colors[idx] = dec2hex (r) + dec2hex (g) + dec2hex (b);
      }

  var newTABLE = document.createElement ("table");
  newTABLE.setAttribute ("border", "1");
  newTABLE.setAttribute ("cellpadding", "0");
  newTABLE.setAttribute ("cellspacing", "1");

  for (var i = 0; i < 12; i++) {
    var row = newTABLE.insertRow (i);
    for (var j = 0; j < 18; j++) {
      var newCell = row.insertCell (j);

      newCell.style["backgroundColor"] = "#" + colors[(i * 18) + j];
      newCell.hexColor = colors[(i * 18) + j];
      newCell.cpDiv = cpDiv;
      newCell.onclick = cpColorClickHandler;
    }
  }

  cpDiv.appendChild (newTABLE);

  cpDiv.style["visibility"] = "hidden";
  
  return cpDiv;
}

function showCPWindow (node, doNotCloseButtonWindows) {
  var cpDiv = document.getElementById ("colorPicker");
	
  if (cpDiv == null)
    return;

  var divLayout = document.getElementById ("layoutDiv");
  if (divLayout == null)
    return;

  var cNPosition = getTLfromNode (node, divLayout);

  /* this condition fixes workaround for IE 6 */
  if (cpDiv.style["display"] != "block")
    cpDiv.style["display"] = "block";

  if (cpDiv.style["visibility"] == "hidden") {	  
	if (doNotCloseButtonWindows!=true)
		closeAllButtonWindows();
    cpDiv.style["left"] = (cNPosition[0]) + "px";
    cpDiv.style["top"] = (cNPosition[1] - cpDiv.clientHeight - 4) + "px";

    cpDiv.style["visibility"] = "visible";
  }
  else
    cpDiv.style["visibility"] = "hidden";

  cpDiv.isFor = node;
}

function cpColorClickHandler () {
  var cpDiv = this.cpDiv;

  var isFor = cpDiv.isFor;

  isFor.style["backgroundColor"] = "#" + this.hexColor;

  if (isFor.changeHandler != null)
    isFor.changeHandler (this.hexColor);

  cpDiv.style["visibility"] = "hidden";
  
  toChangeChatColors(isFor.id);
}

function createOptionsWindow (handlers) {
  var newWin = new AC_Window (winTypes.BUTTONCLOSE | winTypes.HASBUTTONS, "optionsWindow", {"width": "470", "height": "380"});
  //var newWin = new AC_Window (winTypes.BUTTONCLOSE | winTypes.HASBUTTONS, null, {"width": "470", "height": "380"});

  if (! newWin)
    return null;

  newWin.userData["winType"] = "optionsWindow";
  
  var contentDoc = document.createDocumentFragment ();

  var contentTable = document.createElement ("table");
  setElementSaP (contentTable, {"width": "100%"}, {"border": "0", "cellSpacing": "0", "cellPadding": "4", "font-size": "8px"});  
  var row = contentTable.insertRow (0);
  var cell = row.insertCell (0);

  var tabs = new Array ();

  for (var i = 0; i < optionsTabs.length; i++) {
    var tabLabel = addSpanWText (cell, {"class": "optionsTab"}, null, getLanguageString ("dialog", optionsTabs[i], config["defaultLanguage"], null));
    tabLabel.langType = "dialog";
    tabLabel.langStr = optionsTabs[i];
    tabLabel.tabId = i;

    tabs[i] = new Array ();
    tabs[i][0] = tabLabel;

    if (i == 0)
      tabLabel.className += " active";

    tabLabel.onclick = function () { activateOWTab (tabs, this); }
  }

  newWin.userData["tabs"] = tabs;

  var row = contentTable.insertRow (1);
  var cell = row.insertCell (0);

  /*

    tab - index 0

  */

  var themesDiv = document.createElement ("div");
  themesDiv.className = "optionsTabContent";
  displayBLOCKByNode (themesDiv);

  tabs[0][1] = themesDiv;

  var divCT = document.createElement ("table");
  setElementSaP (divCT, {"width": "100%"}, {"border": "0", "cellSpacing": "1", "cellPadding": "1"});
	
  var divCTRow = divCT.insertRow (0);
  var divCTCell = divCTRow.insertCell (0);
  setElementSaP (divCTCell, {"verticalAlign": "top"}, {"colSpan": "2"});

  var themeSpan = addSpanWText (divCTCell, null, null, getLanguageString ("dialog", "skin:selectBigSkin", config["currentLanguage"], null));
  themeSpan.langType = "dialog";
  themeSpan.langStr = "skin:selectBigSkin";

  divCTCell.appendChild (document.createTextNode (" "));

  var themeSelect = document.createElement ("select");

  for (var i = 0; i < config["themes"].length; i++) {
    var tS_option = document.createElement ("option");

    if (config["themes"][i] == config["theme"])
      tS_option.setAttribute ("selected", "selected");

    tS_option.appendChild (document.createTextNode (config["themes"][i]["title"]));
    tS_option.value = i;

    themeSelect.appendChild (tS_option);
  }

  themeSelect.onchange = changeTheme;

  divCTCell.appendChild (themeSelect);

  /* the others options from theme */

  for (var i = 0; i < parseInt (skinOpts.length / 2 ); i++) {
    divCTRow = divCT.insertRow (i + 1);

    for (var j = 0; j < 2; j++) {
      divCTCell = divCTRow.insertCell (j);

      var skinOpt = skinOpts[(i * 2) + j];

      var optTable = document.createElement ("table");
      setElementSaP (optTable, {"width": "100%"}, {"border": "0", "cellSpacing": "0", "cellPadding": "0"});

      oTRow = optTable.insertRow (0);
      oTCellLeft = oTRow.insertCell (0);
      setElementSaP (oTCellLeft, {"textAlign": "left", "paddingLeft": "2px"}, null);

      oTCellRight = oTRow.insertCell (1);
      setElementSaP (oTCellRight, {"textAlign": "right"}, null);

      var textSpan = addSpanWText (oTCellLeft, null, null, getLanguageString ("dialog", "skin:" + skinOpts[(i * 2) + j], config["currentLanguage"], null));

      textSpan.langType = "dialog";
      textSpan.langStr = "skin:" + skinOpt;

      var colorBtn = document.createElement ("input");
      setElementSaP (colorBtn, {"class": "optColorBtn"}, {"type": "button"});
	  colorBtn.setAttribute ("id", "colorBtn_" + skinOpts[(i * 2) + j]);  
      colorBtn.onclick = function () { showCPWindow (this,true) };

      oTCellRight.appendChild (colorBtn);

      divCTCell.appendChild (optTable);
    }

  }

  themesDiv.appendChild (divCT);
  cell.appendChild (themesDiv);

  /*

    tab - index 1

  */

  var textDiv = document.createElement ("div");
  textDiv.className = "optionsTabContent";
  displayNONEByNode (textDiv);

  tabs[1][1] = textDiv;

  var divCT = document.createElement ("table");
  setElementSaP (divCT, {"width": "100%"}, {"border": "0", "cellSpacing": "0", "cellPadding": "4"});

  var row_number=0;
  if(config["allowLanguage"]){ 
	  var divCTRow = divCT.insertRow (row_number++);
	  var divCTCell = divCTRow.insertCell (0);
	  var divCTCell2 = divCTRow.insertCell (1);
	  setElementSaP (divCTCell, {"verticalAlign": "top", "textAlign": "right", "width": "38%"}, null);
	  setElementSaP (divCTCell2, {"verticalAlign": "top", "textAlign": "left", "width": "62%"}, null);
	
	  var langSpan = addSpanWText (divCTCell, null, null, getLanguageString ("dialog", "text:language", config["currentLanguage"], null));
	  langSpan.langType = "dialog";
	  langSpan.langStr = "text:language";
	
	  var langSelect = document.createElement ("select");
	
	  for (key in loginLangs) {
	    var langOpt = document.createElement ("option");
	    langOpt.setAttribute ("value", key);
	
	    if (key == config["defaultLanguage"])
	      langOpt.setAttribute ("selected", "selected");
	
	    langOpt.appendChild (document.createTextNode (loginLangs[key]["name"]));
	
	    langSelect.appendChild (langOpt);
	  }
	
	  setSelectOptionByValue (langSelect, config["currentLanguage"]);
	
	  if ((handlers != null) && (handlers["changeLang"] != null))
	    langSelect.onchange = handlers["changeLang"];
	
	  divCTCell2.appendChild (langSelect);
  }  
  
  var divCTRow = divCT.insertRow (row_number++);
  var divCTCell = divCTRow.insertCell (0);
  var divCTCell2 = divCTRow.insertCell (1);

  setElementSaP (divCTCell, {"verticalAlign": "top", "textAlign": "right", "width": "38%"}, null);
  setElementSaP (divCTCell2, {"verticalAlign": "top", "textAlign": "left", "width": "62%"}, null);

  var itcSpan = addSpanWText (divCTCell, null, null, getLanguageString ("dialog", "text:itemChange", config["currentLanguage"], null));
  itcSpan.langType = "dialog";
  itcSpan.langStr = "text:itemChange";

  var itcSelect = document.createElement ("select");
  itcSelect.setAttribute ("id", "itcSelect");

  if (config["itc"]["mainChat"] != null) {
    var opt = document.createElement ("option");
    opt.setAttribute ("value", "mainChat");

    var valText = document.createTextNode (getLanguageString ("dialog", "text:mainChat", config["currentLanguage"], null));
    opt.langType = "dialog";
    opt.langStr = "text:mainChat";

    opt.appendChild (valText);

    itcSelect.appendChild (opt);
  }

  if (config["itc"]["interface"] != null) {
    var opt = document.createElement ("option");
    opt.setAttribute ("value", "interface");

    var valText = document.createTextNode (getLanguageString ("dialog", "text:interfaceElements", config["currentLanguage"], null));

    opt.langType = "dialog";
    opt.langStr = "text:interfaceElements";

    opt.appendChild (valText);

    itcSelect.appendChild (opt);
  }

  if (config["itc"]["title"] != null) {
    var opt = document.createElement ("option");
    opt.setAttribute ("value", "title");

    var valText = document.createTextNode (getLanguageString ("dialog", "text:title", config["currentLanguage"], null));
    opt.langType = "dialog";
    opt.langStr = "text:title";

    opt.appendChild (valText);

    itcSelect.appendChild (opt);
  }


  itcSelect.onchange = adjustTextSelects;

  divCTCell2.appendChild (itcSelect);

  var divCTRow = divCT.insertRow (row_number++);
  var divCTCell = divCTRow.insertCell (0);
  var divCTCell2 = divCTRow.insertCell (1);

  setElementSaP (divCTCell, {"verticalAlign": "top", "textAlign": "right", "width": "32%"}, null);
  setElementSaP (divCTCell2, {"verticalAlign": "top", "textAlign": "left", "width": "68%"}, null);

  var fSizeSpan = addSpanWText (divCTCell, null, null, getLanguageString ("dialog", "text:fontSize", config["currentLanguage"], null));
  fSizeSpan.langType = "dialog";
  fSizeSpan.langStr = "text:fontSize";

  divCTCell.appendChild (document.createTextNode (" "));

  var fsSelect = document.createElement ("select");
  fsSelect.setAttribute ("id", "fsSelect");

  for (i = 0; i < config["itc"]["sizes"].length; i++) {
    var opt = document.createElement ("option");
    opt.setAttribute ("value", config["itc"]["sizes"][i]);

    opt.appendChild (document.createTextNode (config["itc"]["sizes"][i]));

    fsSelect.appendChild (opt);
  }

  fsSelect.onchange = changeTextSize;

  divCTCell2.appendChild (fsSelect);

  
  var divCTRow = divCT.insertRow (row_number++);
  var divCTCell = divCTRow.insertCell (0);
  var divCTCell2 = divCTRow.insertCell (1);

  setElementSaP (divCTCell, {"verticalAlign": "top", "textAlign": "right", "width": "32%"}, null);
  setElementSaP (divCTCell2, {"verticalAlign": "top", "textAlign": "left", "width": "68%"}, null);

  var fFamilySpan = addSpanWText (divCTCell, null, null, getLanguageString ("dialog", "text:fontFamily", config["currentLanguage"], null));
  fFamilySpan.langType = "dialog";
  fFamilySpan.langStr = "text:fontFamily";

  divCTCell.appendChild (document.createTextNode (" "));

  ffSelect = document.createElement ("select");
  ffSelect.setAttribute ("id", "ffSelect");

  for (i = 0; i < config["itc"]["families"].length; i++) {
    var opt = document.createElement ("option");
    opt.setAttribute ("value", config["itc"]["families"][i]);

    opt.appendChild (document.createTextNode (config["itc"]["families"][i]));

    ffSelect.appendChild (opt);
  }

  ffSelect.onchange = changeTextFamily;

  divCTCell2.appendChild (ffSelect);

  if (config["itc"]["mainChat"] != null)
  	setSelectOptionByValue (fsSelect, config["itc"]["mainChat"]["fontSize"]);
  else if (config["itc"]["interface"] != null)
  	setSelectOptionByValue (fsSelect, config["itc"]["interface"]["fontSize"]);
  else if (config["itc"]["title"] != null)
  	setSelectOptionByValue (fsSelect, config["itc"]["title"]["fontSize"]);
  
  if (config["itc"]["mainChat"] != null)
  	setSelectOptionByValue (ffSelect, config["itc"]["mainChat"]["fontFamily"]);
  else if (config["itc"]["interface"] != null)
  	setSelectOptionByValue (ffSelect, config["itc"]["interface"]["fontFamily"]);
  else if (config["itc"]["title"] != null)
  	setSelectOptionByValue (ffSelect, config["itc"]["title"]["fontFamily"]);

  //textDiv.appendChild (divCT);
  //cell.appendChild (textDiv);

  
  var divCTRow = divCT.insertRow (row_number++);
  var divCTCell = divCTRow.insertCell (0);
  var divCTCell2 = divCTRow.insertCell (1);

  setElementSaP (divCTCell, {"verticalAlign": "middle", "textAlign": "right", "width": "32%"}, null);
  setElementSaP (divCTCell2, {"verticalAlign": "middle", "textAlign": "left", "width": "68%"}, null);

  var checkMyTextColor = document.createElement ("input");
  checkMyTextColor.setAttribute ("type", "checkbox");
  checkMyTextColor.setAttribute ("name", "checkMyTextColor");
  checkMyTextColor.setAttribute ("id", "checkMyTextColor");
  checkMyTextColor.onclick  = function () { config["itc"]["mytextcolor"] = document.getElementById("checkMyTextColor").checked; applyMyTextColor(); }
  
  divCTCell.appendChild (checkMyTextColor);

  divCTCell.appendChild (document.createTextNode (" "));
  
  var txtMyTextColor = addSpanWText (divCTCell2, null, null, getLanguageString ("dialog", "text:mytextcolor", config["currentLanguage"], null));
  txtMyTextColor.langType = "dialog";
  txtMyTextColor.langStr = "text:mytextcolor"

  textDiv.appendChild (divCT);
  cell.appendChild (textDiv);
  
  
  /*

    tab - index 2

  */

  var effDiv = document.createElement ("div");
  effDiv.className = "optionsTabContent";
  displayNONEByNode (effDiv);

  tabs[2][1] = effDiv;

  var divCT = document.createElement ("table");
  setElementSaP (divCT, {"width": "100%"}, {"border": "0", "cellSpacing": "0", "cellPadding": "4"});

  var divCTRow = divCT.insertRow (0);
  var divCTCell = divCTRow.insertCell (0);
  var divCTCell2 = divCTRow.insertCell (1);
   
  setElementSaP (divCTCell, {"verticalAlign": "top", "textAlign": "left", "width": "50%"}, null);
  setElementSaP (divCTCell2, {"verticalAlign": "top", "textAlign": "left", "width": "50%"}, null);

  var avatarSpan = addSpanWText (divCTCell, {"class": "optionsTitle1"}, null, getLanguageString ("dialog", "effects:avatars", config["currentLanguage"], null));
  avatarSpan.langType = "dialog";
  avatarSpan.langStr = "effects:avatars";

  var photoSpan = addSpanWText (divCTCell2, {"class": "optionsTitle1"}, null, getLanguageString ("dialog", "effects:photo", config["currentLanguage"], null));
  photoSpan.langType = "dialog";
  photoSpan.langStr = "effects:photo";

  var divCTRow = divCT.insertRow (1);
  var divCTCell = divCTRow.insertCell (0);
  var divCTCell2 = divCTRow.insertCell (1);
  setElementSaP (divCTCell, {"verticalAlign": "top", "textAlign": "left", "width": "50%"}, null);
  setElementSaP (divCTCell2, {"verticalAlign": "top", "textAlign": "left", "width": "50%"}, {"rowSpan": "4"});

  var checkMCAvatar = document.createElement ("input");
  checkMCAvatar.setAttribute ("type", "checkbox");
  checkMCAvatar.setAttribute ("name", "checkMCAvatar");
  checkMCAvatar.setAttribute ("id", "checkMCAvatar");

  divCTCell.appendChild (checkMCAvatar);

  divCTCell.appendChild (document.createTextNode (" "));

  var mcAvatarSpan = addSpanWText (divCTCell, null, null, getLanguageString ("dialog", "effects:mainchat", config["currentLanguage"], null));
  mcAvatarSpan.langType = "dialog";
  mcAvatarSpan.langStr = "effects:mainchat";

  divCTCell.appendChild (document.createTextNode (" "));

  var mcAvatarSelect = document.createElement ("select");

  smiArray = config["smiArray"];

  for (var i = 0; i < smiArray.length; i++) {
    var opt = document.createElement ("option");
    opt.setAttribute ("value", smiArray[i]);
	if (smiArray[i] == config["effects"]["avatarsmainchat-avatar"])
		opt.setAttribute ("selected", "true");
    opt.appendChild (document.createTextNode (smiArray[i]));

    mcAvatarSelect.appendChild (opt);
  }  
  
  divCTCell.appendChild (mcAvatarSelect);
  mcAvatarSelect.setAttribute ("id", "mcAvatarSelect");
  
  divCTCell.appendChild (document.createElement ("br"));

  var checkRLAvatar = document.createElement ("input");
  checkRLAvatar.setAttribute ("type", "checkbox");
  checkRLAvatar.setAttribute ("name", "checkRLAvatar");
  checkRLAvatar.setAttribute ("id", "checkRLAvatar");
  checkRLAvatar.onclick = previewPersonalRoomAvatar;
  
  divCTCell.appendChild (checkRLAvatar);
  divCTCell.appendChild (document.createTextNode (" "));

  var rlAvatarSpan = addSpanWText (divCTCell, null, null, getLanguageString ("dialog", "effects:roomlist", config["currentLanguage"], null));
  rlAvatarSpan.langType = "dialog";
  rlAvatarSpan.langStr = "effects:roomlist";

  divCTCell.appendChild (document.createTextNode (" "));

  var rlAvatarSelect = document.createElement ("select");

  smiArray = config["smiArray"];
  
  for (var i = 0; i < smiArray.length; i++) {
    var opt = document.createElement ("option");
    opt.setAttribute ("value", smiArray[i]);
	if (smiArray[i] == config["effects"]["avatarsroomlist-avatar"])
		opt.setAttribute ("selected", "true");
    opt.appendChild (document.createTextNode (smiArray[i]));

    rlAvatarSelect.appendChild (opt);
  }
  
  divCTCell.appendChild (rlAvatarSelect);
  rlAvatarSelect.setAttribute ("id", "rlAvatarSelect");
  rlAvatarSelect.onchange = previewPersonalRoomAvatar;

  var photoCustomBtn = document.createElement ("input");
  photoCustomBtn.setAttribute ("type", "button");
  photoCustomBtn.className = "button";
  photoCustomBtn.value = getLanguageString ("dialog", "effects:custom", config["currentLanguage"], null);
  photoCustomBtn.langType = "dialog";
  photoCustomBtn.langStr = "effects:custom";
  photoCustomBtn.onmouseover = function () { this.style["backgroundColor"] = skinOptsValuesTmp["buttonover"]; }
  photoCustomBtn.onmouseout  = function () { this.style["backgroundColor"] = skinOptsValuesTmp["button"]; }
  photoCustomBtn.style["top"]="0px";
  if ((handlers != null) && (handlers["customPhoto"] != null))
    photoCustomBtn.onclick = handlers["customPhoto"];

  divCTCell2.appendChild (photoCustomBtn);

  var noPhotoCustom = new ImgButton ("close");

  divCTCell2.appendChild (document.createTextNode ("  "));
  divCTCell2.appendChild (noPhotoCustom.node);
  
  noPhotoCustom.clickHandler = function () { 
	  		 config["effects"]["mypicture-temp"] = "imgs/blank.gif"; 
	  		 document.getElementById("myPicture").innerHTML = "";
	  	}
  
  divCTCell2.appendChild (document.createElement ("br"));
  divCTCell2.appendChild (document.createElement ("br"));
  
  var picDiv = document.createElement ("div");
  setElementSaP (picDiv, null, {"id": "myPicture"});
  
  divCTCell2.appendChild(picDiv);
  if (config["effects"]["mypicture"])
  	picDiv.innerHTML="<img src=\"." + config["effects"]["mypicture"] + "\" width=\"120px\">"; 	  		  		
  config["effects"]["mypicture-temp"] = config["effects"]["mypicture"];
  //setElementSaP (divCTCell2, null, {"rowspan": "4"});
  

  var divCTRow = divCT.insertRow (2);
  var divCTCell = divCTRow.insertCell (0);
  var divCTCell2 = divCTRow.insertCell (1);
  setElementSaP (divCTCell, {"verticalAlign": "top", "textAlign": "left", "width": "50%"}, null);
  setElementSaP (divCTCell2, {"verticalAlign": "top", "textAlign": "left", "width": "50%"}, null);

  var backgroundSpan = addSpanWText (divCTCell, {"class": "optionsTitle1"}, null, getLanguageString ("dialog", "effects:background", config["currentLanguage"], null));
  backgroundSpan.langType = "dialog";
  backgroundSpan.langStr = "effects:background";

  divCTCell.appendChild (backgroundSpan);

  var divCTRow = divCT.insertRow (3);
  var divCTCell = divCTRow.insertCell (0);
  var divCTCell2 = divCTRow.insertCell (1);
  setElementSaP (divCTCell, {"verticalAlign": "top", "textAlign": "left", "width": "50%"}, null);
  setElementSaP (divCTCell2, {"verticalAlign": "top", "textAlign": "left", "width": "50%"}, null);

  var shBackCheck = document.createElement ("input");
  shBackCheck.setAttribute ("type", "checkbox");
  shBackCheck.setAttribute ("name", "showBackgroundCh");
  shBackCheck.setAttribute ("id", "showBackgroundCh");

  divCTCell.appendChild (shBackCheck);
  divCTCell.appendChild (document.createTextNode (" "));

  shBackCheck.onclick = ifShowBackground;
  
  var shBackSpan = addSpanWText (divCTCell, null, null, getLanguageString ("dialog", "effects:showBackgroundImages", config["currentLanguage"], null));
  shBackSpan.langType = "dialog";
  shBackSpan.langStr = "effects:showBackgroundImages";

  divCTCell.appendChild (document.createElement ("br"));
  divCTCell.appendChild (document.createElement ("br"));

  var backCustomBtn = document.createElement ("input");

  backCustomBtn.setAttribute ("type", "button");
  backCustomBtn.className = "button";
  backCustomBtn.value = getLanguageString ("dialog", "effects:custom", config["currentLanguage"], null);
  backCustomBtn.langType = "dialog";
  backCustomBtn.langStr = "effects:custom";
  backCustomBtn.style["top"]="0px";
  backCustomBtn.onmouseover = function () { this.style["backgroundColor"] = skinOptsValuesTmp["buttonover"]; }
  backCustomBtn.onmouseout  = function () { this.style["backgroundColor"] = skinOptsValuesTmp["button"]; }

  if ((handlers != null) && (handlers["customBackground"] != null))
    backCustomBtn.onclick = handlers["customBackground"];

  divCTCell.appendChild (backCustomBtn);

  var noBackCustom = new ImgButton ("close");
  divCTCell.appendChild (document.createTextNode ("  "));
  divCTCell.appendChild (noBackCustom.node);
  
  config["effects"]["background-image-temp"] =  config["effects"]["background-image"];
  config["effects"]["background-image-lockthemes-temp"] = config["effects"]["background-image-lockthemes"];
  
  noBackCustom.clickHandler = function () {
	  		config["effects"]["background-image-temp"] = "themes/" + config["theme"]["name"] + "/" + config["theme"]["background-default"];
	  		config["effects"]["background-image-lockthemes-temp"]=0;
	  		ifShowBackground();
	  	}

  var divCTRow = divCT.insertRow (4);
  var divCTCell = divCTRow.insertCell (0);
  var divCTCell2 = divCTRow.insertCell (1);
  setElementSaP (divCTCell, {"verticalAlign": "top", "textAlign": "left", "width": "50%"}, null);
  setElementSaP (divCTCell2, {"verticalAlign": "top", "textAlign": "left", "width": "50%"}, null);

  var focusCheck = document.createElement ("input");
  focusCheck.setAttribute ("type", "checkbox");
  focusCheck.setAttribute ("name", "focusCheck");
  focusCheck.setAttribute ("id", "focusCheck");
  
  
  divCTCell.appendChild (focusCheck);
  
  divCTCell.appendChild (document.createTextNode (" "));

  var focusSpan = addSpanWText (divCTCell, null, null, getLanguageString ("dialog", "effects:splashWindow", config["currentLanguage"], null));
  focusSpan.langType = "dialog";
  focusSpan.langStr = "effects:splashWindow";

  divCTCell.appendChild (focusSpan);

  effDiv.appendChild (divCT);
  cell.appendChild (effDiv);
  
  /*

    tab - index 3

  */

  var soundDiv = document.createElement ("div");
  soundDiv.className = "optionsTabContent";
  displayNONEByNode (soundDiv);

  tabs[3][1] = soundDiv;

  var divCT = document.createElement ("table");
  setElementSaP (divCT, {"width": "96%"}, {"border": "0", "cellSpacing": "1", "cellPadding": "1"});

  var divCTRow = divCT.insertRow (0);
  var divCTCell = divCTRow.insertCell (0);
  var divCTCell2 = divCTRow.insertCell (1);
  setElementSaP (divCTCell, {"width": "45%", "textAlign": "right", "paddingBottom": "12px"}, null);
  setElementSaP (divCTCell2, {"width": "55%", "textAlign": "right", "paddingBottom": "12px"}, null);

  var volumeSpan = addSpanWText (divCTCell, null, null, getLanguageString ("dialog", "sound:volume", config["currentLanguage"], null));
  volumeSpan.langType = "dialog";
  volumeSpan.langStr = "sound:volume";

  divCTCell.appendChild (document.createTextNode (" "));

  var volumeSelect = document.createElement ("select");

  for (var i = 0; i < 21; i++) {
    var opt = document.createElement ("option");

    var valueStr = i * 5;

    opt.setAttribute ("value", valueStr.toString ());

    opt.appendChild (document.createTextNode (valueStr.toString () + "%"));

    volumeSelect.appendChild (opt);
  }

  if (config["sound"]["volume"] != null)
    setSelectOptionByValue (volumeSelect, config["sound"]["volume"]);

  volumeSelect.onchange = function () { changeVolume (this); };

  divCTCell.appendChild (volumeSelect);

  var muteAllSpan = addSpanWText (divCTCell2, null, null, getLanguageString ("dialog", "sound:muteall", config["currentLanguage"], null));
  muteAllSpan.langType = "dialog";
  muteAllSpan.langStr = "sound:muteall";

  muteAllCheck = document.createElement ("input");
  muteAllCheck.setAttribute ("type", "checkbox");
  muteAllCheck.setAttribute ("name", "muteAll");
  muteAllCheck.setAttribute ("id", "muteAll");
  muteAllCheck["mutes"] = "all";
  muteAllCheck.onchange = function () { muteUnmute (this); };

  divCTCell2.appendChild (document.createTextNode (" "));
  divCTCell2.appendChild (muteAllCheck);
  
  for (var i = 0; i < parseInt (optionsSound.length / 2); i++) {
    var divCTRow = divCT.insertRow (i + 1);

    for (var j = 0; j < 2; j++) {
      var divCTCell = divCTRow.insertCell (j);
      setElementSaP (divCTCell, {"width": "50%", "textAlign": "right"}, null);

      var sndOpt = optionsSound[(i * 2) + j];

      var strLowerCase=sndOpt.toLowerCase ();
      if (strLowerCase=="receivemessage")
      	strLowerCase="reveivemessage";      	
      var sndOptSpan = addSpanWText (divCTCell, null, null, getLanguageString ("dialog", "sound:" + strLowerCase, config["currentLanguage"], null));

      divCTCell.appendChild (document.createTextNode (" "));

      var muteCheck = document.createElement ("input");
      muteCheck.setAttribute ("type", "checkbox");
      muteCheck.setAttribute ("name", "mute" + sndOpt);
      muteCheck.setAttribute ("id", "mute" + sndOpt);
      muteCheck["mutes"] = sndOpt;

      divCTCell.appendChild (muteCheck);
      
      /*//alert(config["sound"]["ev"][sndOpt]["muted"]);
      if (config["sound"]["ev"][sndOpt]["muted"] != true) {
        /*if (browserISIE ()) {
          muteCheck.setAttribute ("checked", "checked");
          muteCheck.checked = true;
        }
        else/
        //alert(config["sound"]["ev"][sndOpt]["muted"]);
          //muteCheck.setAttribute ("checked", "true");
          //muteCheck.checked = true;
      }*/
      //muteCheck.setAttribute ("checked", "true");

      
      divCTCell.appendChild (document.createTextNode (" "));

      var imgSndTest = document.createElement ("img");
      imgSndTest.setAttribute ("border", "0");
      imgSndTest.src = "imgs/speaker.gif";
      imgSndTest.style["cursor"] = "pointer";
      imgSndTest["tests"] = sndOpt;

      imgSndTest.onclick = function () { testSound (this); };

      muteCheck.onchange = function () { muteUnmute (this); };

      divCTCell.appendChild (imgSndTest);
    }
  }

  soundDiv.appendChild (divCT);
  cell.appendChild (soundDiv);

  /*

    tab - index 4

  */

  var aboutDiv = document.createElement ("div");
  aboutDiv.className = "optionsTabContent";
  displayNONEByNode (aboutDiv);

  tabs[4][1] = aboutDiv;

  var divCT = document.createElement ("table");
  setElementSaP (divCT, {"width": "100%"}, {"border": "0", "cellSpacing": "1", "cellPadding": "1"});

  var divCTRow = divCT.insertRow (0);
  var divCTCell = divCTRow.insertCell (0);
  setElementSaP (divCTCell, {"width": "100%", "textAlign": "left", "paddingTop": "10px", "paddingLeft": "20px"}, null);

  divCTCell.appendChild (document.createTextNode (" "));

  var ACVersDiv = addDiv (divCTCell, null, null)
  ACVersDiv.innerHTML = "<font class=\"optionsAbout1\">AJAX Chat</font>&nbsp;&nbsp;&nbsp;v" + config["ajaxVersion"] + "<br/><br/>";

  var copyDiv = addDiv (divCTCell, null, null);  
  copyDiv.innerHTML = "(c) 2007 TUFaT.com, All Rights Reserved";

  divCTCell.appendChild (document.createElement ("br"));  

  var DGSpan = addSpanWText (divCTCell, null, null, "Darren Gates");
  divCTCell.appendChild (document.createElement ("br"));
  var CCSpan = addSpanWText (divCTCell, null, null, "Adrian Cical");
  divCTCell.appendChild (document.createElement ("br"));
  var CCSpan = addSpanWText (divCTCell, null, null, "Claudiu Cismaru");

  aboutDiv.appendChild (divCT);
  cell.appendChild (aboutDiv);

  /*

    end of tab content

  */

  contentDoc.appendChild (contentTable);
  newWin.addContent (contentDoc);

  var okButton=newWin.addButton ("dialog", "common:okBtn", null, actionTypes.OK);
  okButton.onmouseover = function () { this.style["backgroundColor"] = skinOptsValuesTmp["buttonover"]; }
  okButton.onmouseout  = function () { this.style["backgroundColor"] = skinOptsValuesTmp["button"]; }
  
  return newWin;
}

function adjustTextSelects () {
  var currentOption = this.value;

  if (config["itc"][currentOption] != null) {
    var fsSelect = document.getElementById ("fsSelect");
    var ffSelect = document.getElementById ("ffSelect");

    setSelectOptionByValue (fsSelect, config["itc"][currentOption]["fontSize"]);
    setSelectOptionByValue (ffSelect, config["itc"][currentOption]["fontFamily"]);
  }
}

function changeTextSize () {
  var currentOption = this.value;

  var itcSelect = document.getElementById ("itcSelect");
 	
  config["itc"][itcSelect.value]["fontSize"] = currentOption;
  optFontChange[itcSelect.value].style["fontSize"] = currentOption + "px";
  
  if (itcSelect.value=="interface")
     setInterfaceFont();
  
  if (itcSelect.value=="mainChat")
  	optFontChange["inputMessage"].style["fontSize"] = currentOption + "px";
  
}

function changeTextFamily () {

  var currentOption = this.value;

  var itcSelect = document.getElementById ("itcSelect");
	
  config["itc"][itcSelect.value]["fontFamily"] = currentOption;
  optFontChange[itcSelect.value].style["fontFamily"] = currentOption;
  
  if (itcSelect.value=="interface"){
	 setInterfaceFont();
	 /*
     var allSel= document.getElementsByTagName("select");
     for (var i in allSel)
  	 	if (allSel[i] &&  allSel[i].value)
  	 		allSel[i].style["fontFamily"] = currentOption;	 	
	 var allSel= document.getElementsByTagName("input");
  	 for (var i in allSel)
  	 	if (allSel[i] &&  allSel[i].value)
  	 		allSel[i].style["fontFamily"] = currentOption;
  	 var allSel= document.getElementsByTagName("div");
  	 for (var i in allSel)
  	 	if (allSel[i] &&  allSel[i].value)
  	 		allSel[i].style["fontFamily"] = currentOption;
  	 var allSel= document.getElementsByTagName("td");
  	 for (var i in allSel)
  	 	if (allSel[i] &&  allSel[i].value)
  	 		allSel[i].style["fontFamily"] = currentOption;  	*/ 
  }
  
  if (itcSelect.value=="mainChat")
  	optFontChange["inputMessage"].style["fontFamily"] = currentOption;
}

function createRoomPassWindow (userData) {
  var newWin = new AC_Window (winTypes.BUTTONCLOSE | winTypes.HASBUTTONS, null, null);

  if (! newWin)
    return null;

  newWin.userData["forRoom"] = userData["room"];
  newWin.userData["winType"] = "askRoomPass";

  var contentDoc = document.createDocumentFragment ();

  var contentTable = document.createElement ("table");
  setElementSaP (contentTable, {"width": "100%"}, {"border": "0", "cellSpacing": "0", "cellPadding": "4"});

  var row = contentTable.insertRow (0);
  var cell = row.insertCell (0);

  var rlSpan = addSpanWText (cell, null, null, "");
  rlSpan.innerHTML = getLanguageString ("lang", "roomlock", config["currentLanguage"], null);

  var row = contentTable.insertRow (1);
  var cell = row.insertCell (0);

  var passInput = addInput (cell, {"class": "textInput", "marginTop": "8px", "width": "98%"}, null);
  passInput.onkeyup = submitOnEnter;
  newWin.node.userForm.elems["roomPass"] = passInput;

  contentDoc.appendChild (contentTable);
  newWin.addContent (contentDoc);

  newWin.addButton ("dialog", "common:okBtn", null, actionTypes.OK);

  return newWin;
}

function closeAllButtonWindows(){
	if(document.getElementById("optionsWindow"))
		document.getElementById("optionsWindow").object.closeWindow();
		
	var smilesNode = document.getElementById ("smilesList");
  	if (smilesNode != null)
  		smilesNode.style["visibility"] = "hidden";
	
	var cpDiv = document.getElementById ("colorPicker");
	if (cpDiv != null)
		cpDiv.style["visibility"] = "hidden";
}

function setInterfaceFont(){
  if(config["itc"]["interface"] == null)
  	return;
  /*var allSel= document.getElementsByTagName("table");
  for (var i in allSel)
 	if (allSel[i] && allSel[i].style)
 		allSel[i].style["fontSize"] = config["itc"]["interface"]["fontSize"] + "px";	  
 	*/
  var allSel= document.getElementsByTagName("textarea");
  for (var i in allSel)
	if (allSel[i])
	if (allSel[i].className=="textInput"){
 		allSel[i].style["fontSize"] = config["itc"]["interface"]["fontSize"] + "px";
 		allSel[i].style["fontFamily"] = config["itc"]["interface"]["fontFamily"];
	}
 		
  var allSel= document.getElementsByTagName("select");
  for (var i in allSel)
 	if (allSel[i] && allSel[i].value){
 		allSel[i].style["fontSize"] = config["itc"]["interface"]["fontSize"] + "px";	 	
 		allSel[i].style["fontFamily"] = config["itc"]["interface"]["fontFamily"];
	}
  var allSel= document.getElementsByTagName("input");
  for (var i in allSel)
 	if (allSel[i] && allSel[i].value){
 		allSel[i].style["fontSize"] = config["itc"]["interface"]["fontSize"] + "px";
 		allSel[i].style["fontFamily"] = config["itc"]["interface"]["fontFamily"];
	}
  var allSel= document.getElementsByTagName("table");
  for (var i in allSel)
 	if (allSel[i] && allSel[i].style){
 		allSel[i].style["fontSize"] = config["itc"]["interface"]["fontSize"] + "px";	 
 		allSel[i].style["fontFamily"] = config["itc"]["interface"]["fontFamily"];
	}
}

function setOptionsWindow(){
  config["theme_old"]=config["theme"]["name"];
  for (var i in skinOpts)
  	skinOptsValues[skinOpts[i]]=skinOptsValuesTmp[skinOpts[i]];
  	
  //theme color
  var color_t = new RGBColor(skinOptsValues["bodyText"]).toHex().replace("#","");	
  changeColor(color_t);
  	
  var newval, change;
  if(document.getElementById("checkMCAvatar"))
	if(document.getElementById("checkMCAvatar").checked==true)
    	config["effects"]["avatarsmainchat"]=1;
    else
		config["effects"]["avatarsmainchat"]=0;  

  if(document.getElementById("mcAvatarSelect"))
  	config["effects"]["avatarsmainchat-avatar"] = document.getElementById("mcAvatarSelect").value;
  	
  // Main chat avatar
  change=0; 
  newval=0;		  
  if(document.getElementById("checkMCAvatar"))
	if(document.getElementById("checkMCAvatar").checked==true)
    	newval=1;
    else
		newval=0;  
  if (newval!=config["effects"]["avatarsmainchat-avatar"]){
  	config["effects"]["avatarsmainchat"]=newval;
  	change=1;
  }
  newval="";
  if(document.getElementById("mcAvatarSelect"))	  
  	newval = document.getElementById("mcAvatarSelect").value;
  if (newval!=config["effects"]["avatarsmainchat-avatar"]){
	  config["effects"]["avatarsmainchat-avatar"]=newval;
	  change=1;
  }
  if (change==1){
	  var valavatar=config["effects"]["avatarsmainchat-avatar"];
	  if (config["effects"]["avatarsmainchat"]==0)
	  	valavatar="";
	  	
	  var data = formatSetMainChatAvatar (null, valavatar);
	  clearTimeout (timeOutId);
	  enqueueMessage (data, sendQueue);
	  timeOutId = setTimeout ("chatLoop ()", 1);		
  }
  // --

  // Room list avatar
  change=0; 
  newval=0;	  
  if(document.getElementById("checkRLAvatar"))
	if(document.getElementById("checkRLAvatar").checked==true)
    	newval=1;
    else
		newval=0;  
  if (newval!=config["effects"]["avatarsroomlist-avatar"]){
  	config["effects"]["avatarsroomlist"]=newval;
  	change=1;
  }
  newval="";
  if(document.getElementById("rlAvatarSelect"))	  
  	newval = document.getElementById("rlAvatarSelect").value;
  if (newval!=config["effects"]["avatarsroomlist-avatar"]){
	  config["effects"]["avatarsroomlist-avatar"]=newval;
	  change=1;
  }
  if (change==1){
	  var valavatar=config["effects"]["avatarsroomlist-avatar"];
	  if (config["effects"]["avatarsroomlist"]==0)
	  	valavatar="";
	  	
	  var data = formatSetRoomAvatar (null, valavatar);
	  clearTimeout (timeOutId);
	  enqueueMessage (data, sendQueue);
	  timeOutId = setTimeout ("chatLoop ()", 1);		
  }
  // --
  			
  if(document.getElementById("showBackgroundCh"))
	if(document.getElementById("showBackgroundCh").checked==true)
    	config["effects"]["showbackground"]=1;
    else
		config["effects"]["showbackground"]=0;  

  config["effects"]["background-image"] = config["effects"]["background-image-temp"];
  config["effects"]["background-image-lockthemes"] = config["effects"]["background-image-lockthemes-temp"];  
		
  if(document.getElementById("focusCheck"))
	if(document.getElementById("focusCheck").checked==true)
    	config["splashWindow"]=1;
    else
		config["splashWindow"]=0;
 
  if(config["effects"]["mypicture-temp"] == "imgs/blank.gif" || config["effects"]["mypicture-temp"] == ""){
	config["effects"]["mypicture-temp"] = "";
  	config["effects"]["mypicture"] = "";
  }else
    config["effects"]["mypicture"]=config["effects"]["mypicture-temp"] + "?" + Math.random();  
  var data = formatSetPicture (null, config["effects"]["mypicture"]);
  clearTimeout (timeOutId);
  enqueueMessage (data, sendQueue);
  timeOutId = setTimeout ("chatLoop ()", 1);  
}

function previewPersonalRoomAvatar(){
  if(document.getElementById("checkRLAvatar"))
	if(document.getElementById("checkRLAvatar").checked==true)
    	avatarsroomlist=1;
    else
		avatarsroomlist=0;  
  if(document.getElementById("rlAvatarSelect"))	  
  	avatarsroomlist_avatar = document.getElementById("rlAvatarSelect").value;
  
  var valavatar=avatarsroomlist_avatar;
  if (avatarsroomlist==0)
  	valavatar="";
  	
  var data = formatSetRoomAvatar (user["uid"], valavatar);
  clearTimeout (timeOutId);
  enqueueMessage (data, sendQueue);
  timeOutId = setTimeout ("chatLoop ()", 1);
}

function resetAvatar(){
	if(document.getElementById("rlAvatarSelect")){	   
		  var valavatar=config["effects"]["avatarsroomlist-avatar"];
		  if (config["effects"]["avatarsroomlist"]==0)
		  	valavatar="";		  	
		  var data = formatSetRoomAvatar (user["uid"], valavatar);
		  clearTimeout (timeOutId);
		  enqueueMessage (data, sendQueue);
		  timeOutId = setTimeout ("chatLoop ()", 1);
	}	
}

function ifRollbackTheme(){
	if (config["theme_old"]!=config["theme"]["name"])
		for (var i = 0; i < config["themes"].length; i++)
    		if (config["themes"][i]["name"] == config["theme_old"])
    			changeTheme (i);
}

function resetThemeColors(){
	for (var i in skinOpts){
		skinOptsValuesTmp[skinOpts[i]]="";
		skinOptsValues[skinOpts[i]]="";
		toChangeChatColors("colorBtn_" + skinOpts[i],true);
	}	
}

function applyColorChanges(){		
	for (var i in skinOpts)
		toChangeChatColors("colorBtn_" + skinOpts[i]);  	
}

function toChangeChatColors(elemId, removeall){	
	var x;
	if (elemId.indexOf("colorBtn_")!=0)
		return;	
	if (removeall!=true)	
		x=document.getElementById(elemId);	
	switch(elemId){
		case "colorBtn_background":
				if (browserISIE7())
					break;
				if (x)
					skinOptsValuesTmp["background"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["background"]=skinOptsValues["background"];
				//document.getElementById("AC_main").style["backgroundColor"]=skinOptsValuesTmp["background"];	
				//alert(skinOptsValuesTmp["background"]);
				//document.bgColor=skinOptsValuesTmp["background"];
				//alert(document.bgColor);
				document.body.style["backgroundColor"]=skinOptsValuesTmp["background"];	
				//document.getElementById("AC_main").style["display"]="none";
				//document.getElementById("AC_main").style["display"]="block";
				//document.getElementById("AC_main").style["backgroundColor"]=skinOptsValuesTmp["background"];	
				
			break;
		case "colorBtn_titleText":
				if (x)
					skinOptsValuesTmp["titleText"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["titleText"]=skinOptsValues["titleText"];
				if(document.getElementById("AC_mainTitleRow"))		
					document.getElementById("AC_mainTitleRow").style["color"]=skinOptsValuesTmp["titleText"];
			break;
		case "colorBtn_buttonText":
				if (x)
					skinOptsValuesTmp["buttonText"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["buttonText"]=skinOptsValues["buttonText"];
				var allSel= document.getElementsByTagName("input");
				for (var i in allSel)
					if (allSel[i])
					if (allSel[i].type=="button")
				 		allSel[i].style["color"] = skinOptsValuesTmp["buttonText"];	
			break;
		case "colorBtn_button":				
				if (x)
					skinOptsValuesTmp["button"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["button"]=skinOptsValues["button"];
				var allSel= document.getElementsByTagName("input");
				for (var i in allSel)
					if (allSel[i])
					if (allSel[i].type=="button" && allSel[i].className!="optColorBtn" && allSel[i].id!="colorBtn")
				 		allSel[i].style["backgroundColor"] = skinOptsValuesTmp["button"];
				var skip=0;	
				if (skinOptsValuesTmp["button"])
			 		color = new RGBColor(skinOptsValuesTmp["button"]);					
				else if (document.getElementById("helpBtn"))
					color = new RGBColor(getStyle(document.getElementById("helpBtn"),"background-color","backgroundColor"));
				else if (document.getElementById("loginBtn"))
					color = new RGBColor(getStyle(document.getElementById("loginBtn"),"background-color","backgroundColor"));
				else
					skip=1;
				if (skip!=1)
				if (color.ok) { 
				    color.r=parseInt(color.r*3/4);
				    color.g=parseInt(color.g*3/4);
				    color.b=parseInt(color.b*3/4);
				    skinOptsValuesTmp["buttonover"] = color.toHex();
				    
				}
			break;
		case "colorBtn_buttonBorder":
		        if (x)
					skinOptsValuesTmp["buttonBorder"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["buttonBorder"]=skinOptsValues["buttonBorder"];
				var allSel= document.getElementsByTagName("input");
				for (var i in allSel)
					if (allSel[i])
					if (allSel[i].type=="button")
				 		allSel[i].style["borderColor"] = skinOptsValuesTmp["buttonBorder"];					 		
			break;
		case "colorBtn_inputBoxBackground":
				if (x)
					skinOptsValuesTmp["inputBoxBackground"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["inputBoxBackground"]=skinOptsValues["inputBoxBackground"];
				if (document.getElementById("textInputMsgDiv_alpha"))
					document.getElementById("textInputMsgDiv_alpha").style["backgroundColor"] = skinOptsValuesTmp["inputBoxBackground"];	
				var allSel= document.getElementsByTagName("textarea");
				for (var i in allSel)
					if (allSel[i])
					if (allSel[i].className=="textInput")
				 		allSel[i].style["backgroundColor"] = skinOptsValuesTmp["inputBoxBackground"];	
				var allSel= document.getElementsByTagName("input");
				for (var i in allSel)
					if (allSel[i])
					if (allSel[i].className=="pW_input" || allSel[i].className=="textInput")  
				 		allSel[i].style["backgroundColor"] = skinOptsValuesTmp["inputBoxBackground"];					
			break;
		case "colorBtn_borderColor":
				if (x)
					skinOptsValuesTmp["borderColor"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["borderColor"]=skinOptsValues["borderColor"];
				var allSel= document.getElementsByTagName("div");
				for (var i in allSel)
					if (allSel[i]){
						if (allSel[i].className != null)
							if (allSel[i].className=="pW_messages" || allSel[i].className=="window")
				 				allSel[i].style["borderColor"] = skinOptsValuesTmp["borderColor"];			 		
					 	if (allSel[i].id != null)
					 		if (allSel[i].id=="roomList")
					 			allSel[i].style["borderColor"] = skinOptsValuesTmp["borderColor"];
					 		if (allSel[i].id=="chatMessages")
					 			allSel[i].style["borderColor"] = skinOptsValuesTmp["borderColor"];
			 		}		 		
				 	
				var allSel= document.getElementsByTagName("textarea");
				for (var i in allSel)
					if (allSel[i])
					if (allSel[i].className=="textInput" || allSel[i].className=="textInputMsg")
				 		allSel[i].style["borderColor"] = skinOptsValuesTmp["borderColor"];	
				var allSel= document.getElementsByTagName("input");
				for (var i in allSel)
					if (allSel[i])
					if (allSel[i].className=="pW_input" || allSel[i].className=="textInput")  
						allSel[i].style["borderColor"] = skinOptsValuesTmp["borderColor"];	
				
			break;
		case "colorBtn_dialog":
		        if (x)
					skinOptsValuesTmp["dialog"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["dialog"]=skinOptsValues["dialog"];				
				var allSel= document.getElementsByTagName("div");
				for (var i in allSel)
					if (allSel[i])
						if (allSel[i].className=="window")
				 			allSel[i].style["backgroundColor"] = skinOptsValuesTmp["dialog"];					 		
			break;
		case "colorBtn_dialogTitle":
		        if (x)
					skinOptsValuesTmp["dialogTitle"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["dialogTitle"]=skinOptsValues["dialogTitle"];				
				var allSel= document.getElementsByTagName("div");
				for (var i in allSel)
					if (allSel[i])
						if (allSel[i].className=="windowTitleRow")
				 			allSel[i].style["backgroundColor"] = skinOptsValuesTmp["dialogTitle"];					 		
			break;
		case "colorBtn_userListBackground":
				if (x)
					skinOptsValuesTmp["userListBackground"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["userListBackground"]=skinOptsValues["userListBackground"];
				if(document.getElementById("roomList_alpha"))
					document.getElementById("roomList_alpha").style["backgroundColor"]=skinOptsValuesTmp["userListBackground"];
			break;
		case "colorBtn_room":
		        if (x)
					skinOptsValuesTmp["room"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["room"]=skinOptsValues["room"];				
				var allSel= document.getElementsByTagName("div");
				for (var i in allSel)
					if (allSel[i])
						if (allSel[i].className=="roomTitle" || allSel[i].className=="roomTitle disabled")
				 			allSel[i].style["backgroundColor"] = skinOptsValuesTmp["room"];					 		
			break;
		case "colorBtn_roomText":
		        if (x)
					skinOptsValuesTmp["roomText"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["roomText"]=skinOptsValues["roomText"];				
				var allSel= document.getElementsByTagName("div");
				for (var i in allSel)
					if (allSel[i])
						if (allSel[i].className=="roomTitle")
				 			allSel[i].style["color"] = skinOptsValuesTmp["roomText"];
				 		else if (allSel[i].className=="roomTitle disabled"){
					 		if (skinOptsValuesTmp["roomText"]){
						 		var color = new RGBColor(skinOptsValuesTmp["roomText"]);
								if (color.ok) { 
									if ((color.r+color.g+color.b)/3>150)
										rap=2./3;
									else if ((color.r+color.g+color.b)/3>50)
										rap=3./2;
									else if ((color.r+color.g+color.b)/3>20)
										rap=4./2;
									else{
										rap=6./2;
										color.r+=10; color.g+=10; color.b+=10;
									}
									color.r = Math.min(parseInt(color.r*rap),255);
								    color.g = Math.min(parseInt(color.g*rap),255);
								    color.b = Math.min(parseInt(color.b*rap),255);
								    allSel[i].style["color"] = color.toHex();
								}
							}else
								allSel[i].style["color"] = skinOptsValuesTmp["roomText"];
				 		}
			break;
		case "colorBtn_bodyText":
				if (browserISIE7())
					break;
				if (x)
					skinOptsValuesTmp["bodyText"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["bodyText"]=skinOptsValues["bodyText"];
				if (browserISIE7())
					break;
				document.getElementById("AC_main").style["color"]=skinOptsValuesTmp["bodyText"];
				//alert(skinOptsValues["bodyText"]);
				/*var allSel= document.getElementsByTagName("body");
				for (var i in allSel)
					if (allSel[i])
						//alert(allSel[i]);
						allSel[i].style["color"]=skinOptsValuesTmp["bodyText"];*/
				document.body.style["color"]=skinOptsValuesTmp["bodyText"];
				//document.bgColor=skinOptsValuesTmp["bodyText"];
				var allSel= document.getElementsByTagName("div");
				for (var i in allSel)
					if (allSel[i])
					if (allSel[i].className != null)
					if (allSel[i].className=="window")
				 		allSel[i].style["color"] = skinOptsValuesTmp["bodyText"];
			break;
		case "colorBtn_publicLogBackground":
				if (x)
					skinOptsValuesTmp["publicLogBackground"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["publicLogBackground"]=skinOptsValues["publicLogBackground"];
				if(document.getElementById("chatMessages_alpha"))		
					document.getElementById("chatMessages_alpha").style["backgroundColor"]=skinOptsValuesTmp["publicLogBackground"];
			break;
		case "colorBtn_privateLogBackground":
				if (x)
					skinOptsValuesTmp["privateLogBackground"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["privateLogBackground"]=skinOptsValues["privateLogBackground"];
				var allSel= document.getElementsByTagName("div");
				for (var i in allSel)
					if (allSel[i])
						if (allSel[i].className=="pW_messages")
				 			allSel[i].style["backgroundColor"] = skinOptsValuesTmp["privateLogBackground"];	
			break;
		case "colorBtn_enterRoomNotify":
				if (x)
					skinOptsValuesTmp["enterRoomNotify"]=x.style["backgroundColor"];
				else
					skinOptsValuesTmp["enterRoomNotify"]=skinOptsValues["enterRoomNotify"];				
			break;		
	}	
}
function getStyle(x,styleProp,stylePropF){
	if (!(stylePropF))
		stylePropF=styleProp;			
	if (x.currentStyle)
		var y = x.currentStyle[stylePropF];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function setColorOptions(){	
  if(document.getElementById("colorBtn_background")){
	document.getElementById("colorBtn_background").style["backgroundColor"]=document.bgColor;
	skinOptsValues["background"]=document.bgColor;
	skinOptsValuesTmp["background"]=document.bgColor;
  }
  if(document.getElementById("colorBtn_titleText")){
	var color=getStyle(document.getElementById("AC_mainTitleRow"),"color");
	document.getElementById("colorBtn_titleText").style["backgroundColor"]= color;
	skinOptsValues["titleText"]=color;
	skinOptsValuesTmp["titleText"]=color;
  }    
  if(document.getElementById("colorBtn_buttonText")){
	var color=getStyle(document.getElementById("helpBtn"),"color");
	document.getElementById("colorBtn_buttonText").style["backgroundColor"]= color;
	skinOptsValues["buttonText"]=color;
	skinOptsValuesTmp["buttonText"]=color;
  }  
  if(document.getElementById("colorBtn_button")){
	var color=getStyle(document.getElementById("helpBtn"),"background-color","backgroundColor");
	document.getElementById("colorBtn_button").style["backgroundColor"]= color;
	skinOptsValues["button"]=color;
	skinOptsValuesTmp["button"]=color;
  }  
  if(document.getElementById("colorBtn_buttonBorder")){	  
	var color=getStyle(document.getElementById("helpBtn"),"border-top-color","borderColor");
	document.getElementById("colorBtn_buttonBorder").style["backgroundColor"]= color;
	skinOptsValues["buttonBorder"]=color;
	skinOptsValuesTmp["buttonBorder"]=color;
  }  
  if(document.getElementById("colorBtn_inputBoxBackground")){	  
	var color=getStyle(document.getElementById("textInputMsgDiv_alpha"),"background-color","backgroundColor");
	document.getElementById("colorBtn_inputBoxBackground").style["backgroundColor"]= color;
	skinOptsValues["inputBoxBackground"]=color;
	skinOptsValuesTmp["inputBoxBackground"]=color;
  }
  if(document.getElementById("colorBtn_borderColor")){	  
	var color=getStyle(document.getElementById("roomList"),"border-top-color","borderColor");
	document.getElementById("colorBtn_borderColor").style["backgroundColor"]= color;
	skinOptsValues["borderColor"]=color;
	skinOptsValuesTmp["borderColor"]=color;
  }
  if(document.getElementById("colorBtn_dialog")){	 
	var color;
	if(skinOptsValues["dialog"])
		color=skinOptsValues["dialog"];
	else
		color=getStyle(document.getElementById("optionsWindow"),"background-color","backgroundColor");
	document.getElementById("colorBtn_dialog").style["backgroundColor"]= color;
	skinOptsValues["dialog"]=color;
	skinOptsValuesTmp["dialog"]=color;
  }
  if(document.getElementById("colorBtn_dialogTitle")){	 
	var color;
	if(skinOptsValues["dialogTitle"])
		color=skinOptsValues["dialogTitle"];
	else
		color=getStyle(document.getElementById("optionsWindowwinTitleRow"),"background-color","backgroundColor");
	document.getElementById("colorBtn_dialogTitle").style["backgroundColor"]= color;
	skinOptsValues["dialogTitle"]=color;
	skinOptsValuesTmp["dialogTitle"]=color;
  }
  if(document.getElementById("colorBtn_dialogTitle")){	 
	var color;
	if(skinOptsValues["dialogTitle"])
		color=skinOptsValues["dialogTitle"];
	else
		color=getStyle(document.getElementById("optionsWindowwinTitleRow"),"background-color","backgroundColor");
	document.getElementById("colorBtn_dialogTitle").style["backgroundColor"]= color;
	skinOptsValues["dialogTitle"]=color;
	skinOptsValuesTmp["dialogTitle"]=color;
  }
  if(document.getElementById("colorBtn_userListBackground")){	 
	var color;
	if(skinOptsValues["userListBackground"])
		color=skinOptsValues["userListBackground"];
	else
		color=getStyle(document.getElementById("roomList_alpha"),"background-color","backgroundColor");
	document.getElementById("colorBtn_userListBackground").style["backgroundColor"]= color;
	skinOptsValues["userListBackground"]=color;
	skinOptsValuesTmp["userListBackground"]=color;
  }
  if(document.getElementById("colorBtn_room")){	 
	var color;
	if(skinOptsValues["room"])
		color=skinOptsValues["room"];
	else{
		var allSel= document.getElementsByTagName("div");
		for (var i in allSel)
			if (allSel[i])
			if (allSel[i].className=="roomTitle")  
				color=getStyle(allSel[i],"background-color","backgroundColor");			
	}
	document.getElementById("colorBtn_room").style["backgroundColor"]=color;
	skinOptsValues["room"]=color;
	skinOptsValuesTmp["room"]=color;
  }
  if(document.getElementById("colorBtn_roomText")){	 
	var color;
	if(skinOptsValues["roomText"])
		color=skinOptsValues["roomText"];
	else{
		var allSel= document.getElementsByTagName("div");
		for (var i in allSel)
			if (allSel[i])
			if (allSel[i].className=="roomTitle")  
				color=getStyle(allSel[i],"color");			
	}
	document.getElementById("colorBtn_roomText").style["backgroundColor"]=color;
	skinOptsValues["roomText"]=color;
	skinOptsValuesTmp["roomText"]=color;
  }  
  if(document.getElementById("colorBtn_bodyText")){
	var color=getStyle(document.body,"color");
	document.getElementById("colorBtn_bodyText").style["backgroundColor"]=color;
	skinOptsValues["bodyText"]=color;
	skinOptsValuesTmp["bodyText"]=color;	
  }
  if(document.getElementById("colorBtn_publicLogBackground")){	 
	var color=getStyle(document.getElementById("chatMessages_alpha"),"background-color","backgroundColor");
	document.getElementById("colorBtn_publicLogBackground").style["backgroundColor"]= color;
	skinOptsValues["publicLogBackground"]=color;
	skinOptsValuesTmp["publicLogBackground"]=color;
  }
  if(document.getElementById("colorBtn_privateLogBackground")){	 
	var color;
	if(skinOptsValues["privateLogBackground"])
		color=skinOptsValues["privateLogBackground"];
	else{
		if(!(document.getElementById("divtest"))){
			addDiv (document.getElementById ("layoutDiv"), {"class": "pW_messages", "display": "none"}, {"id": "divtest"});
	  	}
		color=getStyle(document.getElementById("divtest"),"background-color","backgroundColor");	
	}
	document.getElementById("colorBtn_privateLogBackground").style["backgroundColor"]= color;
	skinOptsValues["privateLogBackground"]=color;
	skinOptsValuesTmp["privateLogBackground"]=color;
  }
  if(document.getElementById("colorBtn_enterRoomNotify")){	 
	var color;
	if(skinOptsValues["enterRoomNotify"]!="")
		color=skinOptsValues["enterRoomNotify"];
	else
		color=getStyle(document.getElementById("chatMessages"),"color");
	document.getElementById("colorBtn_enterRoomNotify").style["backgroundColor"]= color;
	skinOptsValues["enterRoomNotify"]=color;
	skinOptsValuesTmp["enterRoomNotify"]=color;
  }    
}

function configureOptionsWindow(){ 	
  config["theme_old"]=config["theme"]["name"];
  setColorOptions();
  
  if(document.getElementById("checkMCAvatar"))
  	if (config["effects"]["avatarsmainchat"]==1)
	  document.getElementById("checkMCAvatar").checked=true;	
	  
  if(document.getElementById("checkRLAvatar"))
  	if (config["effects"]["avatarsroomlist"]==1)
	  document.getElementById("checkRLAvatar").checked=true;

  if (!config["effects"]["avatarsmainchat_allow_override"])
  if(document.getElementById("checkMCAvatar")){
  	document.getElementById("mcAvatarSelect").disabled = true;
  	document.getElementById("checkMCAvatar").disabled = true;
  }
  
  if (!config["effects"]["avatarsroomlist_allow_override"])
  if(document.getElementById("checkRLAvatar")){
  	document.getElementById("rlAvatarSelect").disabled = true;
  	document.getElementById("checkRLAvatar").disabled = true;
  }	  
	  
  if(document.getElementById("showBackgroundCh"))
  	if (config["effects"]["showbackground"]==1)
	  document.getElementById("showBackgroundCh").checked=true;
	  
  if(document.getElementById("focusCheck"))
  	if (config["splashWindow"]==1)
	  document.getElementById("focusCheck").checked=true;

  if (config["sound"]["muteAll"] == "1")
    if(document.getElementById("muteAll"))	 
      document.getElementById("muteAll").checked=true;      
    
  if (config["itc"]["mytextcolor"] == true) 
  	if(document.getElementById("checkMyTextColor"))	 
      document.getElementById("checkMyTextColor").checked=true;          
    	 
  for (var i = 0; i < parseInt (optionsSound.length); i++)
	if (config["sound"]["ev"][optionsSound[i]]["muted"] == false)
	  if(document.getElementById("mute" + optionsSound[i]))		  
		document.getElementById("mute" + optionsSound[i]).checked=true;
}

function isFocusWindowOnNewMessages(){
	var valReturn;
	valReturn=(config["splashWindow"]==1) ? true : false;
	
	if(document.getElementById("focusCheck"))
		valReturn=document.getElementById("focusCheck").checked;
		
	return valReturn;
}

function ifShowBackground(){
	var showBg = false, bgImg;
	if(document.getElementById("showBackgroundCh")){
		if(document.getElementById("showBackgroundCh").checked==true)
			showBg=true;
	}else if (config["effects"]["showbackground"]==1)
		showBg=true;
	
	
	if(document.getElementById("showBackgroundCh"))
		bgImg = config["effects"]["background-image-temp"];
	else
		bgImg = config["effects"]["background-image"];		
	if(showBg==true){
		 if(document.getElementById("backgroundimage"))
  			document.getElementById("backgroundimage").src=bgImg;
	}
    else{
		 if(document.getElementById("backgroundimage"))
  			document.getElementById("backgroundimage").src="imgs/blank.gif";    	
	}	
}

function applyMyTextColor(){
	if (config["itc"]["mytextcolor"]){
		var allSel= document.getElementsByTagName("span");
		for (var i in allSel)
			if (allSel[i])
			if (allSel[i].className=="textcolorval")
		 		allSel[i].style["color"] = "#" + user["color"];
	 }else{
		 var allSel= document.getElementsByTagName("span");
		for (var i in allSel)
			if (allSel[i])
			if (allSel[i].className=="textcolorval")
		 		allSel[i].style["color"] = "";
	 }
}

function isSpecialLanguage(inLanguage) {	
	if (inLanguage == undefined)
		inLanguage = config["currentLanguage"];
	for (var i in config["special_language"])
		if (config["special_language"][i]==inLanguage)
			return true;			
	return false;	
}

function getAvatar() {
	var ret_val = null;
	switch(parseInt(user["role"]))
	{
		case config["role"]["ROLE_USER"]: 
		case config["role"]["ROLE_CUSTOMER"]: 
			if(user["gender"] == config["gender"]["GENDER_MALE"])			
				ret_val = config.avatars.user.male;
			else if(user["gender"] == config["gender"]["GENDER_FEMALE"])
				ret_val = config.avatars.user.female;
			//else ret_val = config.avatars.user.male;			
			break;
		case config["role"]["ROLE_ADMIN"]:
			if(user["gender"] == config["gender"]["GENDER_MALE"])
				ret_val = config.avatars.admin.male;
			else if(user["gender"] == config["gender"]["GENDER_FEMALE"])
				ret_val = config.avatars.admin.female;
			else ret_val = config.avatars.admin.male;			
			break;
		case config["role"]["ROLE_MODERATOR"]:
			if(user["gender"] == config["gender"]["GENDER_MALE"])
				ret_val = config.avatars.moderator.male;
			else if(user["gender"] == config["gender"]["GENDER_FEMALE"])
				ret_val = config.avatars.moderator.female;
			else 
				ret_val = config.avatars.moderator.male;
			break;	
		default:			
			break;
	}	
	return(ret_val);
}

