// ---------------- variables -------------------------------------------------- var clock_host = 'http://clock.time.in.ua/'; var clock_html = 'clock.html'; var offsetCookie = 'to'; var req, reqstart, reqend, response, offset; var time_width,time_height,time_border,time_bg,w,h,undef; // ---------------- SNTP via HTTP syncronization ------------------------------- function loadXMLDoc(url) { // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = processReqChange; req.open("GET", url, true); req.setRequestHeader('Pragma', 'no-cache'); req.setRequestHeader('Cache-control', 'no-cache'); req.send(null); } else if (window.ActiveXObject) { // branch for IE/Windows ActiveX version req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = processReqChange; req.open("GET", url, true); req.setRequestHeader('Pragma', 'no-cache'); req.setRequestHeader('Cache-control', 'no-cache'); req.send(); } } } function processReqChange() { // only if req shows "complete" if (req.readyState == 4) { // only if "OK" if (req.status == 200 || req.responseText != undef) { // ...processing statements go here... response = req.responseText; reqend = (new Date()).getTime(); offset = (reqend-reqstart)/2; // real time (in microseconds) is response * 1000 + offset // user's time (in microseconds) is reqend // difference is reqend - (response * 1000 + offset) offset = reqend - response*1000 - offset; var expire = new Date(); expire.setTime(expire.getTime() + 300 * 1000); // 1 hour if (Math.abs(offset) < 1e4) setCookie(offsetCookie, offset, expire.toGMTString()); display(); } else { alert("There was a problem retrieving the XML data:\n" + req.statusText); } } } function display() { var timer = (new Date()).getTime(); var real = timer + offset; real = Math.round(real); real = real.toString(); real = 1000-real.substr(real.length-3); setTimeout("displayTime()", real); var im = document.getElementById("img"); if (im) { if (Math.abs(offset) > 1000) im.src = "http://clock.time.in.ua/images/clock-no.png"; else im.src = "http://clock.time.in.ua/images/clock-ok.png"; im.title = "Your system clock is "+(offset >= 0 ? 'faster' : 'slower')+" in "+Math.abs(offset)+" ms"; } } function startSync() { offset = parseInt(getCookie(offsetCookie)); if (offset) { display(offset); } else { url = clock_host + "?r=" + Math.random(); loadXMLDoc(url); } } function displayTime() { var div = document.getElementById("time"); var time = new Date(); time.setTime(time.getTime() - offset); div.innerHTML = d2(time.getHours())+":"+d2(time.getMinutes())+":"+d2(time.getSeconds()); setTimeout("displayTime()", 1000); } function d2(val) { if (val < 10) val = "0"+val; return val; } function setCookie (name, value, expires, path, domain, secure) { document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); } function getCookie(name) { var cookie = " " + document.cookie; var search = " " + name + "="; var setStr = null; var offset = 0; var end = 0; if (cookie.length > 0) { offset = cookie.indexOf(search); if (offset != -1) { offset += search.length; end = cookie.indexOf(";", offset); if (end == -1) end = cookie.length; setStr = unescape(cookie.substring(offset, end)); } } return(setStr); } // ---------------- CSS definition -------------------------------------------- function css() { try { if (time_width == undef || time_height == undef || time_width == 0 || time_height == 0) { time_width = undef; time_height = undef; } if (time_width == undef) time_width = 88; if (time_height == undef) time_height = 31; var w=time_width,h=time_height; if (time_border == undef) time_border = 'black 1px solid'; if (time_border == '') time_border = '0px none'; if (match = time_border.match(/\b([0-9]+)px\b/)) { w -= match[1]*2; h -= match[1]*2; } if (time_bg == undef) time_bg = 'http://clock.time.in.ua/images/clock-bg-'+time_width+'-'+time_height+'-1.gif'; var obj = document.getElementById("timeinua"); if (obj) { if (obj.style) { obj.style.margin = '0px'; obj.style.padding = '0px'; obj.style.fontSize = '1px'; obj.style.width = w+'px'; obj.style.height = h+'px'; obj.style.border = time_border; obj.style.overflow = 'hidden'; obj.style.whiteSpace = 'nowrap'; if (time_bg) { if (time_bg.indexOf('#') == 0) obj.style.backgroundColor = time_bg; else if (time_bg.indexOf('http://') == 0) obj.style.background = "url('"+time_bg+"')"; } } var obj1 = obj.getElementsByTagName('div'); for(var i=0; i'); }