﻿function showWindow(url, name, width, height)
{
	var win = window.open(url, name, 'width=' + width + ',height=' + height + ',top=20,left=20,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no', true);
	if (win)
	{
		win.focus();
	}
	return win;
}
function showGallery(id, width, height)
{
	showWindow('gallery.php?id=' + id, 'gallery', width, height);
}
function showFlyer(id, width, height)
{
	showWindow('flyer.php?id=' + id, 'gallery', width, height);
}

var ie = (document.all)?true:true;
var ns4 = (document.layers)?true:false;
var ns5 = (navigator.appName == 'Netscape' && parseFloat(navigator.appVersion.substring(0,3)) >= 5.0);

var offset = 0;
var diff = 0;
var serverMillis = 0;
var clientMills =0;
function initClock(millis){
    serverMillis = millis +5000;
    clientMills = new Date().getTime();
    offset = (new Date().getTimezoneOffset())*60000;
    if(document.layers){
        document.layers['clockLayer'].left = document.layers['clockLayer'].left-5; // somehow left=x doesn't work in layer ???
    }
     clockTicker();
}

function addZero(val){
	if (val < 10)
		return '0' + val;
	else
		return val;
}

function clockTicker(){
    pcMillis = new Date().getTime();
    timePased =  pcMillis -clientMills;
    currentServerTime = timePased + serverMillis;
    var themonths = new Array("Sausio","Vasario","Kovo","Balandžio","Gegužės","Birželio","Liepos","Rugpjūčio","Rugsėjo","Spalio","Lapkričio","Gruodžio");
    var nodays = new Array("31","28","31","30","31","30","31","31","30","31","30","31");
    date2 = new Date(currentServerTime);
    hour = date2.getHours();
    if(hour == 24){hour = 0;}
    min = addZero(date2.getMinutes());
    sec = addZero(date2.getSeconds());
    date = date2.getDate();
    lemonth = date2.getMonth();
	
// check date
	if(nodays[lemonth] < date){lemonth = lemonth + 1;}
	if(lemonth == 13){lemonth = 1; date = 1;}


    hour = addZero(hour); 
	showmonth = themonths[lemonth];


    strHTML =  '<span class="CLOCK">' + showmonth + ' ' + date + '&nbsp; ' + hour + ':' + min + ':' + sec + '</span>';
   if (ie || ns5){
        var lyr = document.getElementById('clockLayer');
        lyr.innerHTML = strHTML;
   
    } else if (ns4){
        //var lyr = document.clockLayer;
        var lyr = document.layers['clockLayer'];
        lyr.document.open();
        document.write(strHTML);
        lyr.document.close();
    
    }

	setTimeout('clockTicker()', 1000);
}

