/* Start cookies */
function createCookie(name, value, days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    var expires = "; expires=" + date.toGMTString();
  }
  else var expires = "";
  document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') c = c.substring(1, c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  }
  return null;
}

function eraseCookie(name) {
  createCookie(name, "", -1);
}

/* End cookies */

function _preinitAll(){
  var d = new Date();
  var v = readCookie('uaTimezone');
  createCookie('uaTimezone', d.getTimezoneOffset(), 1);
  var l = window.location.href;
  if (v == null){
    if (l.indexOf('do=mobile') != -1){
      if (l.indexOf('_tt=setTZ') != -1){
        alert('Javascript and cookies must be enabled to work with site!');
      } else {
        window.location.replace('/?do=mobile&_tt=setTZ');
      }
    }
  } else {
    if (l.indexOf('do=mobile') != -1 && l.indexOf('_tt=setTZ') != -1){
      window.location.replace('/?do=mobile');
    }
  }
}

// Get local string. If local string is not exist, get one from English language
function l10nGetString(key){
    if (typeof(_LANG) != 'undefined' && typeof(_LANG[key]) != 'undefined'){
        return _LANG[key];
    }
    
    if (typeof(_LANG_EN) != 'undefined' && typeof(_LANG_EN[key]) != 'undefined'){
        return _LANG_EN[key];
    }

    return "";
}

////////////////////////////
_preinitAll();

