// JavaScript Document for synottip_portal

var timerID = null;
var timerRunning = false;
var infoWindowTop = 0;

function stopclock() {
  if(timerRunning) {
    clearInterval(timerID);
  }
  timerRunning = false;
}

function startclock(){
  stopclock();
  showclock();
  timerID = setInterval("showclock()",1000);
  timerRunning = true;
}

function showclock() {
  var actual_timestamp = gettimestamp()+difference_timestamp;
  var actual_date=new Date();
  actual_date.setTime(actual_timestamp*1000);
  //document.getElementById('actualtime').innerHTML = ' server:'+server_timestamp+' client:'+client_timestamp+' difference:'+difference_timestamp+' actual:'+actual_date.toLocaleString();
  var mymonth = (actual_date.getMonth()*1)+1;
  var el=document.getElementById('actualtime');
  if (el)
  {
    el.innerHTML = actual_date.getDate()+'.'+mymonth+'.'+actual_date.getFullYear()+' '+actual_date.getHours()+':'+(actual_date.getMinutes()<10?'0'+actual_date.getMinutes():actual_date.getMinutes())+':'+(actual_date.getSeconds()<10?'0'+actual_date.getSeconds():actual_date.getSeconds());
  }   
}

function showitem(itemid) {
  var item = document.getElementById(itemid);
  if (item) {
    item.style.display = "block";
  }
}

function hideitem(itemid) {
  var item = document.getElementById(itemid);
  if (item) {
    item.style.display = "none";
  }
}

function flipitem(itemid) {
  var item = document.getElementById(itemid);
  if (item)
  {
    if (item.style.display == "none") {
      item.style.display = "block";
    } else {
      item.style.display = "none";
    }
  }
}

function flipitem2(itemid,e) {
  var item = document.getElementById(itemid);
  if (item)
  {
    if (item.style.display == "none") {
      item.style.display = "block";
      /*
      if (infoWindowTop==0) {
        infoWindowTop = item.offsetTop+8;
      }
      item.style.top = (e.parentNode.offsetTop+infoWindowTop)+"px";
      */
      item.style.top = (e.parentNode.parentNode.parentNode.parentNode.offsetTop)+"px";
    } else {
      item.style.display = "none";
    }
  }
}

function gettimestamp() {
  var client_date=new Date();
  var temp=Math.round(client_date.getTime()/1000);
  return temp;
}

var client_timestamp=gettimestamp();
var difference_timestamp=server_timestamp-client_timestamp;
startclock();

function flipDiscussionForm(itemid,linktoid) {
  var discussionForms = Array('discussion_new','discussion_login','discussion_registration','forgotten_login');
  var item = document.getElementById(itemid);
  if (!item) return false;
  if (item.style.display == "none") {
    // schovani vsech formularu (aby jich nebylo zaroven zobrazeno vic najednou)
    for ($i=0;$i<discussionForms.length;$i++) {
      var others = document.getElementById(discussionForms[$i]);
      if (others) {
        others.style.display = "none";
      }
    }
    // presun formularou ke spodni nebo horni liste s linky
    var linkto = document.getElementById('discussionforms'+linktoid);
    if (linkto) {
      var itemdata = item;
      item.parentNode.removeChild(item);
      linkto.appendChild(itemdata);
      var item = document.getElementById(itemid);
    }
    // vypnuti nebo zapnuti formulare    
    item.style.display = "block";
  } else {
    item.style.display = "none";
  }
  // vypnuti chybovych hlasek pri prekliknuti
  var discussionerror = document.getElementById('discussionerror');
  if (discussionerror) {
    discussionerror.style.display = 'none';
  }
  //alert(item.outerHTML);
}

function dejOkno(soub,w,h,pridat,oznac,pozice)
{
  if(pozice!=1)
  {
	 var top = event.screenY;
	 var top_ideal = (top/2)-100;
	 var left = event.screenX;
	 var left_ideal = (left/2);
	}
	else
	{
	 var top = window.screen.availHeight;
	 var top_ideal = top-(top/1.5);
	 var left = window.screen.availWidth;
	 var left_ideal = left-(left/1.5);
	}
	var start=window.open(soub + '&w='+ w +'&h='+ h,'pridej'+ oznac,'width='+ w +',height=' + h +',top='+ top_ideal +',left='+ left_ideal +''+ pridat +'');
	start.focus();
}


function ukazNabidkuSynottip(link)
{
  var windowSynottip=window.open(link,"synottip_nabidka_z_tipuj");
  if (windowSynottip)
    windowSynottip.focus();      
}