var MyCookie = {
    Write:function(name,value,days) {
        var D = new Date();
        D.setTime(D.getTime()+86400000*days)
        document.cookie = escape(name)+"="+escape(value)+
            ((days == null)?"":(";expires="+D.toGMTString()))
        return (this.Read(name) == value);
    },
    Read:function(name) {
        var EN=escape(name)
        var F=' '+document.cookie+';', S=F.indexOf(' '+EN);
        return S==-1 ? null : unescape(     F.substring(EN=S+EN.length+2,F.indexOf(';',EN))    );
    }
}

function SetLang ( Lang )
{
  	document.formLang.SetLang.value = Lang;
  	document.formLang.submit();
}

function LightButton ( Id )
{
 var Id;
 var Button = document.getElementById ( 'visible-button'+Id );
 Button.style.background = '#BD0E0E';
}

function DarkButton ( Id )
{
 var Id;
 var Button = document.getElementById ( 'visible-button'+Id );
 Button.style.background = '#CFBDBD';
}

function SetDisplayAlbumNick()
{
  NickPanel = document.getElementById("display_album_nick");
  NickPanel.style.display = "block";
  PwdPanel = document.getElementById("display_album_pwd");
  PwdPanel.style.display = "none";
}
function SetDisplayAlbumPwd()
{
  PwdPanel = document.getElementById("display_album_pwd");
  PwdPanel.style.display = "block";
  NickPanel = document.getElementById("display_album_nick");
  NickPanel.style.display = "none";
}
function SetDisplayAlbumNone()
{
  PwdPanel = document.getElementById("display_album_pwd");
  PwdPanel.style.display = "none";
  NickPanel = document.getElementById("display_album_nick");
  NickPanel.style.display = "none";
}

function smile( n )
{
  var v = this.document.form.Txt;
  var add = "!" + n + "!";
  v.focus();
  if (document.selection) {
    sel = document.selection.createRange();
    sel.text = add;
  } else if( v.selectionStart || v.selectionStart == "0" ) {
    var startPos = v.selectionStart;
    var endPos = v.selectionEnd;
    var len = v.value.length;
    v.value = v.value.substring(0, startPos) + add + v.value.substring(endPos, len);
  } else {
    v.value += add;
  }
}

function ConfirmTask(Str) {
  if(Str != undefined) {
    return confirm("Opravdu chcete provést úlohu '"+Str+"' ?");
  } else {
    return confirm("Opravdu chcete provést úlohu ?");
  }
}

function parsecookies() {
  var cookieList=document.cookie.split("; ");
  var cookieArray = new Array();
  for (var i=0; i < cookieList.length; i++){
    var name = cookieList[i].split("=");
    cookieArray[unescape(name[0])] = unescape(name[1]);
  } return cookieArray;
}

function SetProfileMenu() {
  var DefaultOpen = new Array(
  		"menu_profile_main",
  		"menu_profile_message",
  		"menu_profile_photo",
  		"menu_profile_video",
  		"menu_profile_user",
  		"menu_profile_pet",
  		"menu_profile_meet",
  		"menu_profile_blog"
  		);
  var ItemsMenu = new Array(
  		"menu_profile_main",
  		"menu_profile_message",
  		"menu_profile_photo",
  		"menu_profile_video",
  		"menu_profile_blog",
  		"menu_profile_user",
  		"menu_profile_pet",
  		"menu_profile_meet",
  		"menu_profile_catalog",
  		"menu_profile_support"
  		);

  for(i in ItemsMenu){
    if(typeof ItemsMenu[i] != "function") {
      var Item = document.getElementById(ItemsMenu[i]);
      if(MyCookie.Read(ItemsMenu[i]) == 1) {
        Item.style.display = 'block';
      } else if(MyCookie.Read(ItemsMenu[i]) == null && DefaultOpen.indexOf(ItemsMenu[i]) != -1) {
        Item.style.display = 'block';
      } else {
        Item.style.display = 'none';
      }
    }
  }
}

function DisplayBlock(Str) {
 var Item = document.getElementById(Str);
 if(Item.style.display == 'none') {
   Item.style.display = 'block';
   MyCookie.Write(Str, 1, 365);
 } else {
   Item.style.display = 'none';
   MyCookie.Write(Str, 0, 365);
 }
}

function DisplayUiBox(id)
{
  document.getElementById("ui_personal_box").style.display = "none";
  document.getElementById("ui_figure_box").style.display = "none";
  document.getElementById("ui_stats_box").style.display = "none";
  document.getElementById(id).style.display = "block";
}

function SetFlashPlayer() {
   if(MyCookie.Read('FlashPlayerType') == 'old') {
     document.getElementById("flash-div").style.display = "none"; 
     document.getElementById("flash-div-old").style.display = "block"; 
   } else {
     document.getElementById("flash-div-old").style.display = "none"; 
     document.getElementById("flash-div").style.display = "block"; 
   }
}

function SwitchFlashPlayer() {
  if(document.getElementById("flash-div").style.display == "none") {
    document.getElementById("flash-div-old").style.display = "none";
    document.getElementById("flash-div").style.display = "block";
    MyCookie.Write('FlashPlayerType', 'new', 14); 
  } else {
    document.getElementById("flash-div").style.display = "none";
    document.getElementById("flash-div-old").style.display = "block";
    MyCookie.Write('FlashPlayerType', 'old', 14); 
  }
}
