// $Id: it.js 31196 2010-01-20 11:31:53Z tbruederli $
function CED(txt)
{
var element = document.getElementById('jsdebug');
if (element)
element.innerHTML = txt ? txt : "";
}
function ED()
{
var element;
var text = "";
if (!(element = document.getElementById('jsdebug')))
return;
for (var i = 0; i < arguments.length; i++)
{
var variable = arguments[i];
if (typeof variable == "string")
variable = variable.replace(/&/g, '&amp;').replace(new RegExp("<", "g"), '&lt;');
text += (typeof variable) + " " + variable;
if (typeof variable == "object")
{
text += ":";
for (field in variable)
{
text += field + "=";
try { text += typeof variable[field] == 'function' ? 'function' : variable[field]; }
catch (e) { text += "*" + e + "*"; }
text += "\n";
}
text += "\n";
}
text += "\n";
}
element.innerHTML += '<pre style="background-color:#FEE; margin:0">'  + text + '<' + '/pre>';
}
function Q(value)
{
return typeof value == "undefined" ? "" : value.toString().replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(new RegExp("<", "g"), '&lt;').replace(/>/g, '&gt;');
}
String.prototype.T = function(values)
{
var result = this;
for (key in values)
result = result.replace(new RegExp("{" + key + "}", "g"), values[key]);
return result;
}
function it_event(p)
{
var oldhandler = p.element["on" + p.event];
p.element["on" + p.event] = function(ev)
{
var pp = arguments.callee.p ? arguments.callee.p : p;
var oo = arguments.callee.oldhandler ? arguments.callee.oldhandler : oldhandler;
var result = pp.object[pp.method](ev ? ev : window.event, pp);
if (result && oo)
result = oo(ev);
return result;
}
p.element["on" + p.event].p = p;
p.element["on" + p.event].oldhandler = oldhandler;
}
function it_add_event(p)
{
if (!p.object || !p.method) 
return;
if (!p.element)
p.element = document;
if (!p.object._it_events)
p.object._it_events = [];
var evt = p.event;
var key = p.event + '*' + p.method;
var p_closure = p;
if (!p.object._it_events[key])
p.object._it_events[key] = function(e){ return p_closure.object[p_closure.method](e, p_closure); };
if (p.element.addEventListener)
p.element.addEventListener(evt, p.object._it_events[key], false);
else if (p.element.attachEvent)
p.element.attachEvent('on'+evt, p.object._it_events[key]);
else
{
p.element['on'+evt] = function(e)
{
var ret = true;
for (var k in p_closure.object._it_events)
if (p_closure.object._it_events[k] && k.indexOf(evt) == 0)
ret = p_closure.object._it_events[k](e);
return ret;
};
}
}
function it_remove_event(p)
{
if (!p.element)
p.element = document;
var key = p.event + '*' + p.method;
if (p.object && p.object._it_events && p.object._it_events[key]) {
if (p.element.removeEventListener)
p.element.removeEventListener(p.event, p.object._it_events[key], false);
else if (p.element.detachEvent)
p.element.detachEvent('on'+p.event, p.object._it_events[key]);
p.object._it_events[key] = null;
}
}
function it_event_void(evt)
{
var e = evt ? evt : window.event;
if (e.preventDefault)
e.preventDefault();
if (e.stopPropagation)
e.stopPropagation();
e.cancelBubble = true;
e.returnValue = false;
return false;
}
function it_get_obj_x(obj)
{       
var curleft = 0;
if (obj.offsetParent)
while (obj)
{
curleft += obj.offsetLeft;
obj = obj.offsetParent;
}
else if (obj.x)
curleft += obj.x;
return curleft;
}       
function it_get_obj_y(obj)
{	       
var curtop = 0;
if (obj.offsetParent)
while (obj)
{
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
else if (obj.y)
curtop += obj.y;
return curtop;
}
function it_find_obj(obj)
{
if (document.getElementById)
return document.getElementById(obj);
else if (document.all)
return document.all[obj];
else if (document.layers)
return document.layers[obj];
return null;
}
function it_element(label)
{
var tmp = it_find_obj(label);
return tmp ? tmp : { style:{}, src:"", value:"", isundefined:true };
}
function it_get_iframe_document(iframe)
{
return iframe.contentWindow ? iframe.contentWindow.document : iframe.contentDocument;
}
function it_create_element(doc, type, init)
{
var e = document.createElement(type);
it_set(e, init);
doc.appendChild(e);
return e;
}
function it_set(dst, src)
{
if (dst)
{
for (var i in src)
{
if (typeof src[i] == 'object')
{
if (dst[i])
it_set(dst[i], src[i]);
}
else
dst[i] = src[i];
}
}
}
function it_now()
{
return new Date().getTime();
}
function it_url_encode(str)
{
var result = window.encodeURIComponent ? encodeURIComponent(str) : escape(str).replace(/\+/g, "%2B");
return result.replace(/%20/gi, "+").replace(/%2C/gi, ",").replace(/%3B/gi, ";").replace(/%28/gi, "(").replace(/%29/gi, ")");
}
function it_pngfix(img, w, h, mode)
{
var old_IE = navigator.platform == "Win32" && String(navigator.userAgent).match(/MSIE ((5\.5)|6)/);
if (img.src && img.src.match(/\.png($|\?)/) && old_IE) {
img.style.width = (w || img.width) + 'px';
img.style.height = (h || img.height) + 'px';
img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img.src+"',sizingMethod='"+(mode ? mode : 'crop')+"')";
img.src = '/images/0.gif';
}
else if (img && old_IE)
img.style.filter = 'none';
}
function it_http(cb)
{
this.instance = it_http.instances++;
this.callback = cb ? cb : {};
this.req = null;
this.scrpt = [];
this.callid = 0;
this.busy = false;
it_http['__inst' + this.instance] = this;
}
it_http.prototype = {
get: function(url, callback)
{
if (typeof callback != 'undefined')
this.callback = callback;
this.send(url, 'GET');
},
post: function(url, data, callback)
{
if (typeof callback != 'undefined')
this.callback = callback;
var postdata = '';
if (typeof data == 'object') 
{
for (var k in data)
postdata += (postdata ? '&' : '') + it_url_encode(k) + "=" + it_url_encode(data[k]);
}
else
postdata = data;
this.send(url, 'POST', postdata);
},
send: function(url, method, postdata)
{
this.stop();
this.busy = true;
this.req = null;
var samehost = (url.indexOf('http://') < 0 || url.indexOf(window.location.hostname) > 0);
if (samehost)
{
try
{
this.req = new XMLHttpRequest();
}
catch (e)
{
var classnames = [ 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ];
for (var i=0; i < classnames.length; i++)
{
try
{
this.req = new ActiveXObject(classnames[i]);
break;
}
catch (e) { }
}
}
try
{
this.req.open(method, url);
var me = this;
this.req.onreadystatechange = function() { me.ready_state_changed(); }
var workingxmlhttp = this.req.onreadystatechange;
if (!workingxmlhttp)
this.req = null;
}
catch (e) { }
}
this.starttime = new Date().getTime();
if (this.req)
{
if (method == "POST")
this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this.req.send(postdata);
}
else
{
url += (url.match(/\?/) ? "&" : "?") + "itjs_call=it_http.__inst" + this.instance + "&itjs_callid=" + (++this.callid) + (postdata ? '&' + postdata : "");
if (samehost || (window.opera && !window.XMLHttpRequest))	
{
var scrpt = document.createElement("iframe");
scrpt.style.width = scrpt.style.height = 1;
url += "&itjs_iframe=1";
}
else
{
var scrpt = document.createElement("script");
this.req = { starttime: this.starttime };
try
{
this.scrpt[this.callid] = scrpt;
if (!document.all) scrpt.src = url;
document.body.appendChild(scrpt);
if (document.all) scrpt.src = url;
}
catch (e) { return false; }
}
}
return true;
},
ready_state_changed: function()
{
var req = this.req;
if (req && (req.readyState == 4))
{
var data = null;
try
{
if (req.responseText != "")
data = eval("(" + req.responseText + ")");
}
catch (e)
{
if (typeof this.callback == 'object' && this.callback.errorhandler)
{
var obj = this.callback.object ? this.callback.object : window;
if (typeof obj[this.callback.errorhandler] == 'function')
obj[this.callback.errorhandler](req.responseText);
}
else
ED(e, req.responseText);
}
if (data)
this.dataReady(data, this.callid);
this.unlink(this.callid);
}
},
dataReady: function(data, callid)
{
var fixkonqueror33gcbug = this.req;
var loadtime = new Date().getTime() - this.starttime;
this.req = null;
if ((typeof data == "object") && (this.callid == callid))
{
data.loadtime = loadtime;
if (typeof this.callback == 'function')
this.callback(data);
else if (typeof this.callback == 'object' && this.callback.method)
{
var obj = this.callback.object ? this.callback.object : window;
if (typeof obj[this.callback.method] == 'function')
obj[this.callback.method](data);
}
}
},
stop: function()
{
try { this.req.abort(); }
catch (e) { }
this.unlink(this.callid);
},
unlink: function(callid)
{
if (this.req)
this.req = null;
if (this.scrpt[callid])
{
if (!(document.all && String(navigator.userAgent).indexOf('MSIE 5.0') > 0))
document.body.removeChild(this.scrpt[callid]);
this.scrpt[callid] = null;
}
this.busy = false;
}
}
it_http.instances = 0;
it_http.get_instance = function()
{
var inst;
for (var i=0; i < it_http.instances; i++)
if ((inst = it_http['__inst'+i]) && inst.pub && !inst.busy)
return inst;
inst = new it_http();
inst.pub = true;
return inst;
}
it_http.get = function(url, callback)
{
var inst = it_http.get_instance();
inst.callback = callback;
inst.get(url);
}
it_http.post = function(url, postdata, callback)
{
var inst = it_http.get_instance();
inst.callback = callback;
inst.post(url, postdata);
}
function it_loader(handler)
{
this.http = null;
this.handler = handler;
this.callback = { object:this, method:'dataReady', errorhandler:'onerror' };
this.clear();
}
it_loader.prototype =
{
clear: function()
{
this.entry = new Array();
this.start = this.end = 0;
this.attr = { num: 0, loadtime: 0 };
if (this.handler.clear)
this.handler.clear();
},
load: function(baseurl, pos, num, query_volatile, retry)
{
pos -= 0;
num -= 0;
if (isNaN(retry))
retry = 0;
if (baseurl != this.baseurl)
{
this.clear();
this.baseurl = baseurl;
this.start = this.end = pos;
}
this.pos = pos;
this.num = num;
this.query_volatile = query_volatile;
this.stop();
while ((num > 0) && (typeof this.entry[pos] != "undefined"))
{
pos++;
num--;
}
if (this.attr.eof)
num = Math.min(num, this.end - pos);
if (num > 0)
{
this.retry = retry;
this.http = it_http.get_instance();
this.http.get(baseurl + (baseurl.match(/\?/) ? "&" : "?") + "pos=" + pos + "&num=" + num + (retry ? "&retry=" + retry : "") + (query_volatile ? query_volatile : ""), this.callback);
}
else
this.handler.render(this);
return true;
},
post: function(baseurl, data)
{
this.clear();
this.http = it_http.get_instance();
this.http.post(baseurl, data, this.callback);
},
retryload: function(p)
{
this.load(p.baseurl, p.pos, p.num, p.query_volatile, p.retry);
},
dataReady: function(data)
{
if ((typeof data == "object"))
{
this.attr = {};
for (var key in data)
{
var value = data[key];
var id = key - 0;
if (!isNaN(id))
{
this.start = Math.min(this.start, id);
this.end = Math.max(this.end, id + 1);
this.entry[id] = data[key];
}
else
this.attr[key] = data[key];
}
if (this.attr.eof)
this.attr.num = this.end;
this.handler.render(this);
if (!this.attr.eof && (this.end < this.pos + this.num))
this.load(this.baseurl, this.end, this.pos + this.num - this.end);
it_loader.sequence += "h";
this.http = null;
}
},
onerror: function(response)
{
var retry = this.retry + 1;
if (retry < 10)
it_timer({ object: this, method: "retryload", timeout: Math.pow(5, Math.min(retry, 5)), baseurl: this.baseurl, pos: this.pos, num: this.num, query_volatile: this.query_volatile, retry: retry });
else
ED(response);
},
stop: function()
{
if (this.http)
this.http.stop();
}
}
it_loader.sequence = "";
var it_state =
{
it_iframe: null,
it_history_field: null,
it_state_saved: false,
it_store_handlers: [],
it_restore_handlers: [],
register_store_handler: function(p)
{
this.it_store_handlers[this.it_store_handlers.length] = p;
},
register_restore_handler: function(p)
{
this.it_restore_handlers[this.it_restore_handlers.length] = p;
if (this.it_history_field && this.it_history_field.value)
p.object[p.method]();
},
new_history_entry: function(p)
{
this.store_state();
this.it_state_saved = true;
if (!this.it_iframe && !(this.it_iframe = document.getElementById('it_state')))
ED('it_state::new_history_entry(): it_state object not found!');
var idoc;
if ((idoc = it_get_iframe_document(this.it_iframe)))
{
idoc.title = document.title;
idoc.forms[0].submit();
}
this.it_history_field = null;
},
restore_history: function()
{
if (!this.it_iframe && !(this.it_iframe = document.getElementById('it_state')))
ED('it_state::restore_history(): it_state object not found!');
var idoc = it_get_iframe_document(this.it_iframe);
this.it_history_field = idoc ? idoc.getElementById('state') : {};
this.it_state_saved = false;
if (this.it_history_field.value)
{
var res = eval('({' + this.it_history_field.value + '})');
for (var key in res)
this[key] = res[key];
}
for (var i in this.it_restore_handlers)
{
if (this.it_history_field.value || (this.it_restore_handlers[i].initial && (!idoc || !idoc.location.href.match(/s=/))))
this.it_restore_handlers[i].object[this.it_restore_handlers[i].method]();
}
},
store_state: function()
{
if (!this.it_iframe && !(this.it_iframe = document.getElementById('it_state')))
ED('it_state::store_state(): it_state object not found!');
var idoc = it_get_iframe_document(this.it_iframe);
this.it_history_field = idoc ? idoc.getElementById('state') : {};
for (var i in this.it_store_handlers)
this.it_store_handlers[i].object[this.it_store_handlers[i].method]();
var ser = [];
for (var key in this)
{
var value = this[key], type = typeof(value);
if (!key.match(/^it_/) && type.match(/boolean|number|string/))
ser[ser.length] = key + ':' + ((type == 'string') ? "'" + value.replace(/([\\'])/g, '\\\1') + "'" : value);
}
this.it_history_field.value = ser.join(',');
}
}
function it_state_restore_history()
{
it_state.restore_history();
}
function it_timer(p)
{
this.func = p.continuous ? "Interval" : "Timeout";
return this.timer = window["set" + this.func](function() { p.object[p.method](p) }, p.timeout);
}
it_timer.prototype =
{
stop: function()
{
if (this.timer)
{
window["clear" + this.func](this.timer);
this.timer = null;
}
}
}
function it_timerlog(label, print)
{
if (window.it_timerlog_active)
{
var end = new Date().getTime();
if (typeof window.it_timernow != "undefined")
{
var start = window.it_timernow;
if (window.it_timerlogmsg != "")
window.it_timerlogmsg += ", ";
window.it_timerlogmsg += label + ":" + (end - start);
}
else
window.it_timerlogmsg = "";
window.it_timernow = end;
if (print)
{
ED("timerlog: " + window.it_timerlogmsg);
window.it_timerlogmsg = "";
}
}
}
it_timerlog("");
function findObj(obj)
{
var result = null;
if (document.getElementById)
result = document.getElementById(obj);
else if (document.all)
result = document.all[obj];
else if (document.layers)
result = document.layers[obj];
return result;
}
function elem(label)
{
var tmp = findObj(label);
return tmp ? tmp : {style:{}, src:""};
}
function createElem(doc, type, init)
{
var e = document.createElement(type);
it_set(e, init);
doc.appendChild(e);
return e;
}
function getEvent(e)
{
return e ? e : window.event;
}
function checkEvent (ev, elemId)
{
var elem;
if (ev.srcElement && typeof ev.srcElement != "undefined")
elem = ev.srcElement;
else if (ev.target && typeof ev.target != "undefined")
elem = ev.target;
return (elem.id && elem.id == elemId) ? true : false;
}
function getTarget(e)
{
var t;
if (!e)
e = window.event;
if (e.target)
t = e.target;
else if (e.srcElement)
t = e.srcElement;
if (t && t.nodeType == 3)
t = t.parentNode;
return t;
}
function getMousePos(e)
{
var ev = getEvent(e);
if (typeof ev.pageX != "undefined")
return [ev.pageX, ev.pageY];
else if (typeof ev.clientX != "undefined")
return [ev.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
ev.clientY + document.body.scrollTop + document.documentElement.scrollTop];
else
return [0, 0];
}
function getRelMousePos(e)
{
var ev = getEvent(e);
return (ev.screenX && !window.safari) ? new Array(ev.screenX, ev.screenY) : getMousePos(e);
}
function getClientSize()
{
if (self.innerHeight)
return [self.innerWidth, self.innerHeight];
else if (document.documentElement && document.documentElement.clientHeight)
return [document.documentElement.clientWidth, document.documentElement.clientHeight];
else if (document.body && document.body.clientHeight)
return [document.body.clientWidth, document.body.clientHeight];
else
return [800, 600];
}
function getScrollOffset()
{
var pagex = window.scrollX;
var pagey = window.scrollY;
if (window.pageXOffset)
pagex = window.pageXOffset;
else if (document.documentElement && document.documentElement.scrollLeft)
pagex = document.documentElement.scrollLeft;
else if (document.body)
pagex = document.body.scrollLeft;
if (window.pageYOffset)
pagey = window.pageYOffset;
else if (document.documentElement && document.documentElement.scrollTop)
pagey = document.documentElement.scrollTop;
else if (document.body)
pagey = document.body.scrollTop;
return [pagex, pagey];
}
function now()
{
return new Date().getTime();
}
function unfocus(o)
{
if(o.blur)
o.blur();
}
function win(url, w, h, name, features)
{
var wi, f = features ? features : 'status=yes,scrollbars=yes,resizable=yes';
if ((wi = window.open(url, name, f+',width='+w+',height='+h)))
setTimeout(function(){ try { wi.focus(); } catch(ex) {} }, 20);
return wi;
}
function C64()
{
this.applet = findObj('c64_applet');
}
C64.prototype =
{
paused: false,
reset: function()
{
if (this.applet)
this.applet.reset();
},
enter_text: function(text, delay)
{
new it_timer({object:this, method:'_enter_text', timeout:delay, text:text});
},
_enter_text: function(p)
{
if (this.applet)
this.applet.enterText(p.text);
},
toggle_pause: function()
{
if (this.applet)
{
if ((this.paused = !this.paused))
this.applet.pause();
else
this.applet.unpause();
}
},
toggle_help: function()
{
if (this.helpwindow && !this.helpwindow.closed)
{
this.helpwindow.close();
this.helpwindow = null;
}
else
this.helpwindow = window.open('/help', 'help', 'resizable=yes,left=200,top=440,width=728,height=260');
},
toggle_info: function()
{
if (this.infowindow && !this.infowindow.closed)
{
this.infowindow.close();
this.infowindow = null;
}
else
this.infowindow = window.open(document.location.href.replace(/\.html$/, '') + '/info.html', 'info', 'scrollbars=yes,resizable=yes,left=200,top=40,width=640,height=512');
},
end_of_the_world: "as we know it"
}
function scroller(p)
{
this.p = p;
this.init();
new it_timer({object:this, method:'update', timeout:1000/50, continuous:true})
}
scroller.prototype =
{
chars: [],
ti: 0,		
charpos: 0,
numchars: 0,	
bouncespeed: 1/10,
scrollstep: 3,	
scrollspacing: 2,
char_size: 24,	
overcount:4,	
init: function()
{
this.s = document.getElementById(this.p.id);
this.char_totalsize = this.char_size + this.scrollspacing * this.scrollstep;
this.startleft = this.s.clientWidth + this.overcount * this.char_totalsize;
this.numchars = (Math.ceil(this.s.clientWidth / this.char_totalsize) + this.overcount +1) & 254;
this.s.style.fontSize = this.char_totalsize + "px";
this.bouncewidth = this.numchars;
for (var i = 0; i < this.numchars; i++)
{
var chrimg = new Image;
chrimg.leftpos = this.startleft + (i+1) * this.char_totalsize;
chrimg.style.left = chrimg.leftpos + "px";
this.chars[i] = chrimg;
this.s.appendChild(chrimg);
}
},	
update: function()
{
this.ti++;
var bounceheight = this.s.clientHeight - this.chars[0].clientHeight, ch;
var cycle = "0px " + ((this.cycle ? -this.ti : -135) % 159) + "px";
for (var i = 0; i < this.numchars; i++)
{
var chrimg = this.chars[i];
if (chrimg.leftpos == this.startleft)
{
if ((ch = this.p.text.charAt(this.charpos++)) == 'c')
{
this.cycle = !this.cycle;
ch = this.p.text.charAt(this.charpos++);
}
chrimg.src = "/fonts/" + this.p.font + "-3/" + ch + "r.gif";
if (this.charpos >= this.p.text.length)
this.charpos = 0;
}
if ((chrimg.leftpos -= this.scrollstep) <= -this.char_totalsize)
chrimg.leftpos = this.startleft;
chrimg.style.left = chrimg.leftpos + "px";
chrimg.style.top = bounceheight - Math.round(bounceheight * Math.abs(Math.sin(this.ti * this.bouncespeed + 2 * Math.PI * i / this.bouncewidth)*Math.cos(this.ti * 1.07 * this.bouncespeed + 2 * Math.PI * i / this.bouncewidth))) + "px";
chrimg.style.backgroundPosition = cycle;
}
}
}
function glow(p)
{
this.p = p;
this.g = document.getElementById(this.p.id);
new it_timer({object:this, method:'update', timeout:1000/50, continuous:true})
}
glow.prototype =
{
numglows: 6,
glowlength: 13,
glows:[],
startleft: [33, 129, 235, 18, 183, 269],
starttop:  [29,  29,  29, 97, 105, 132],
startframe: [10, 50, 100, 125, 200, 250],
maxoffset: 16,
ti: 0,
addimg: function(i)
{
var glowimg = new Image;
glowimg.src = "/images/glow0.png";
glowimg.className = "glow";
glowimg.style.left = (this.startleft[i]-24) + "px";
glowimg.style.top = (this.starttop[i]-30) + "px";
glowimg.style.padding = "0";
this.glows[i] = glowimg;
this.g.appendChild(glowimg);	
},
update: function()
{
this.ti++;
for (var i = 0; i < this.numglows; i++)
{
if(this.ti >= this.startframe[i])
{
if(this.ti == this.startframe[i])
this.addimg(i);
var glowimg = this.glows[i];
glowimg.src = "/images/glow" + (this.ti/10)%13 + ".png";
var ti = this.ti - this.startleft[i];
var curleft = (this.startleft[i] + (ti/5)) % (this.startleft[i] + this.maxoffset);
glowimg.style.left = curleft + "px";
}
}
}
}
