function popUp(URL)
{
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=1,width=700,height=640,left = 290,top = 187');");
}

var expHours = 24*400; // number of hours the cookie should last

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
  var j = i + alen;
  if (document.cookie.substring(i, j) == arg)
  return getCookieVal (j);
  i = document.cookie.indexOf(" ", i) + 1;
  if (i == 0) break;
  }
  return null;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date();
exp.setTime(exp.getTime() + (expHours*60*60*1000));

function amt(){
  var count = GetCookie('count1')
  if(count == null) {
  SetCookie('count1','1')
  return 1
  }
  else {
  var newcount = parseInt(count) + 1;
  DeleteCookie('count1')
  SetCookie('count1',newcount,exp)
  return count
     }
}

function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
  var count = GetCookie('count1');
  if (count == null) {
  count=1;
  SetCookie('count1', count, exp);

  document.getElementById('bannerdiv').style.display = 'block';


  count++;
  SetCookie('count1', count, exp);
     }
}


function initKeywordsForm(html1, html2, texts)
{
  $(document).ready(function()
  {
    function chkeywords()
    {
      var name = $(this).attr("name");
      var prefix = "keywords";
      var n = parseInt(name.substr(prefix.length)) + 1;
      if (n == 5) return;
      var a = $("#keywords input[name="+prefix+n+"]");
      if (!a.length)
      {
        $("#keywords").append(html1+n+html2);
        $("#keywords input[name=keywords"+n+"]").change(chkeywords).keydown(chkeywords);
      }
    }

    $("#keywords input[name=keywords0]").change(chkeywords).keydown(chkeywords);
    $("#keywords input[name=keywords1]").change(chkeywords).keydown(chkeywords);
    $("#keywords input[name=keywords2]").change(chkeywords).keydown(chkeywords);

    $("#keywordsform").submit(function()
//      $("#keywordsform input[type=button]").click(function()
    {
      if ($("#keywordsform input[name=domain]").attr("value").length < 3)
      {
        alert(texts.ievadiet_domenu_warn)
        return false;
      }

      var kwords = [];
      for (var i=0; i<5; i++)
      {
        var kw = $("#keywordsform input[name=keywords"+i+"]").attr("value");
        if (!kw) continue;
        if (kw.length)
        {
          if (kw.length < 2)
          {
            alert(texts.av_garums)
            return false;
          }
          kwords.push(kw);
        }
      }
      if (!kwords.length)
      {
        alert(texts.ievadiet_vismaz_av)
        return false;
      }
      return true;
    })
  });

}


  function setActiveTab(num, id)
  {
    var numi = num - 1;
    if(activetab[numi])
      activetab[numi].className = activetab[numi].className.replace('active', '');
    if(activetabpanel[numi])
      activetabpanel[numi].style.display = 'none';

    var node = document.getElementById(id);
    if(node)
      node.className += ' active';
    activetab[numi] = node;

    var nodet = document.getElementById(id + '_div');
    if(nodet && nodet.style)
      nodet.style.display = 'block';
    activetabpanel[numi] = nodet;
  }

  function ms_setActiveTab1()
  {
    setActiveTab(1, this.id);
    return false;
  }

  function ms_setActiveTab2()
  {
    setActiveTab(2, this.id);
    return false;
  }

  function initTabDiv(num, id)
  {
    var menu = document.getElementById(id);
    if(menu)
    {
      var as = menu.childNodes;
      for(var f = 0; f < as.length; f++)
      {
        var node = as[f];
        if(node.nodeType == 1)
        {
          node.onclick = eval('ms_setActiveTab' + num);
          var nodet = document.getElementById(node.id + '_div');
          if(nodet && nodet.style)
            nodet.style.display = 'none';
        }
      }
    }
  }

  function processTabedThingies()
  {
    initTabDiv(1, 'menu_1');
    initTabDiv(2, 'menu_2');

    activetab = new Array(0, 0);
    activetabpanel = new Array(0, 0);
    setActiveTab(1, 'menu_13');
    setActiveTab(2, 'menu_21');

  }
