// $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, '&').replace(new RegExp("<", "g"), '<');
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 += '
' + text + '<' + '/pre>';
}
function Q(value)
{
return typeof value == "undefined" ? "" : value.toString().replace(/&/g, '&').replace(/\"/g, '"').replace(new RegExp("<", "g"), '<').replace(/>/g, '>');
}
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 it_extend(subclass, superclass)
{
function Dummy(){}
Dummy.prototype = superclass.prototype;
subclass.prototype = new Dummy();
subclass.prototype.constructor = subclass;
subclass.superclass = superclass;
subclass.superproto = superclass.prototype;
}
function it_array_flip(a)
{
var out = {};
for (var k in a)
out[a[k]] = k;
return out;
}
function it_array_keys(a)
{
var out = [];
for (var k in a)
if (a[k])
out[out.length] = k;
return out;
}
function it_rel_obj_pos(obj, ref)
{
var curtop = 0;
var curleft = 0;
if (obj.offsetParent)
while (obj && obj != ref)
{
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
else if (obj.x)
{
curleft += obj.x;
curtop += obj.y;
}
return [curleft, curtop];
}
function it_empty(obj)
{
if (typeof obj == 'object' && obj != null) {
var cont = false;
for (var k in obj) {
if (typeof obj[k] != 'function')
cont |= !it_empty(obj[k]);
}
return !cont;
}
return !obj;
}
var it_dom = {
_elem: function(a)
{
return typeof(a) == 'object' && a.style ? a : it_element(a);
},
set_class: function(element, value)
{
it_dom._elem(element).className = value;
},
set_style: function(element, prop, value)
{
var obj = it_dom._elem(element);
obj.style[prop] = value;
if (prop == 'opacity' && typeof obj.style.filter == "string")
obj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+ Math.floor(value*100) +")";
},
set_z: function(element, z)
{
element = it_dom._elem(element);
element.style.zIndex = z;
},
moveto: function(element, x, y)
{
element = it_dom._elem(element);
element.style.left = Math.round(x)+'px';
element.style.top = Math.round(y)+'px';
},
moveby: function(element, dx, dy)
{
element = it_dom._elem(element);
element.style.left = Math.round(element.offsetLeft + dx)+'px';
element.style.top = Math.round(element.offsetTop + dy)+'px';
},
resizeto: function(element, w, h)
{
element = it_dom._elem(element);
if (w !== null)
element.style.width = Math.round(w)+'px';
if (h !== null)
element.style.height = Math.round(h)+'px';
},
display: function(element, mode)
{
element = it_dom._elem(element);
var isie = document.all && !window.opera;
if (!mode) element.style.display = 'none';
else element.style.display = isie ? 'block' : (element.nodeName == 'TABLE' ? 'table' : (element.nodeName == 'TR' ? 'table-row' : (element.nodeName == 'TD' ? 'table-cell' : 'block')));
},
show: function(element)
{
it_dom.set_style(element, 'visibility', 'inherit');
},
hide: function(element)
{
it_dom.set_style(element, 'visibility', 'hidden');
},
computed_style: function(elm, prop, mze)
{
if (arguments.length==2)
mze = prop;
var el = elm;
if (typeof(elm)=='string')
el = elem(elm);
var val = false;
try {
if (el && el.currentStyle)
val = el.currentStyle[prop];
else if (el && document.defaultView && document.defaultView.getComputedStyle)
val = document.defaultView.getComputedStyle(el, null).getPropertyValue(mze);
}
catch(e) {
if (el)
val = el.style[prop];
}
if (val == 'auto' && prop == 'width')
val = (elm.scrollWidth || elm.offsetWidth) + 'px';
else if (val == 'auto' && prop == 'height')
val = (elm.scrollHeight || elm.offsetHeight) + 'px';
return val;
},
animate: function(element, p)
{
var elm = it_dom._elem(element);
if (p.before) {
for (var prop in p.before)
if (typeof prop == 'string')
it_dom.set_style(elm, prop, p.before[prop]);
}
var valexpr = /^([\d+-.]+)(.*)$/;
var curval = it_dom.computed_style(elm, p.prop).toString().match(valexpr);
if (curval)
p.start = p.curval = parseFloat(curval[1]);
var parts = p.value.toString().match(valexpr);
if (parts) {
p.end = parseFloat(parts[1]);
p.unit = parts[2] || '';
}
if (p.unit != 'px' && (p.prop == 'width' || p.prop == 'height')) {
elm.style[p.prop] = (p.end || 1) + p.unit;
p.start = p.curval = ((p.end || 1) / parseFloat(it_dom.computed_style(elm, p.prop))) * p.start;
it_dom.set_style(elm, p.prop, p.start + '' + p.unit);
}
if (p.start != p.end && p.duration) {
var steps = Math.round(p.duration / 20);
p.step = (p.end - p.start) / steps;
p.time = 0;
it_dom._animate_step(elm, p);
}
},
_animate_step: function(elm, p)
{
if (p.time < p.duration) {
p.time += 20;
p.curval += p.step;
it_dom.set_style(elm, p.prop, p.curval + '' + p.unit);
setTimeout(function(){ it_dom._animate_step(elm, p); }, 20);
}
else {
it_dom.set_style(elm, p.prop, p.end + '' + p.unit);
if (p.after) {
for (var prop in p.after)
if (typeof prop == 'string')
it_dom.set_style(elm, prop, p.after[prop]);
}
if (typeof p.callback == 'function')
p.callback(p);
}
}
};
function search_get_event(e)
{
return e ? e : window.event;
}
function search_check_event (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 search_get_target(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 search_mouse_pos(e)
{
var ev = search_get_event(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 search_rel_mouse_pos(e)
{
var ev = search_get_event(e);
if (typeof ev.layerX != "undefined")
return [ev.layerX, ev.layerY];
else if (typeof ev.offsetX != "undefined")
return [ev.offsetX, ev.offsetY];
else
return search_mouse_pos(e);
}
function search_client_size()
{
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 search_scroll_offset()
{
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 search_unfocus(o)
{
if(o.blur)
o.blur();
}
function search_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 search_user_agent()
{
var ua = window.navigator && navigator.userAgent ? navigator.userAgent : "";
var version = window.navigator ? navigator.appVersion : "";
var platform = String(navigator.platform).toLowerCase();
this.ie = document.all && !window.opera && version.match(/MSIE ([0-9.]+)/) ? parseFloat(RegExp.$1) : false;
this.ie5 = this.ie >= 5 && this.ie < 5.5;
this.ie7 = this.ie >= 7;
this.iemac = ua.match(/MSIE.*Mac/) && !window.opera;
this.safari = ua.match(/(safari|applewebkit)\/(\d+)/i) ? parseInt(RegExp.$2) : false;
this.opera = ua.match(/opera.(\d+)/i) ? parseInt(RegExp.$1) : false;
this.konqueror = ua.match(/Konqueror\/(\d+\.\d+)/) ? parseFloat(RegExp.$1) : false;
this.gecko = ua.match(/rv:(\d\.\d+)/i) ? parseFloat(RegExp.$1) : false;
this.oldgecko = (this.gecko && this.gecko < 1.8);
this.iphone = this.safari && ua.match(/iPhone/) ? (this.safari >= 525 ? 2 : 1) : false;
this.ipad = this.safari && ua.match(/iPad/);
this.win = (platform.indexOf('win') >= 0);
this.win2k = ua.match(/NT 5\.0/);
this.mac = (platform.indexOf('mac') >= 0);
this.x11 = (ua.indexOf('X11') > 0 || platform.indexOf('linux') >= 0 || platform.indexOf('unix') >= 0);
this.lang = (this.ie ? navigator.browserLanguage : navigator.language).substring(0,2);
this.dom = (document.createElement && document.documentElement) ? true : false;
this.dom2 = (document.addEventListener && document.removeEventListener) ? true : false;
this.vectors = (this.gecko >= 1.8 || this.safari >= 412 || this.opera >= 9 || (this.ie && window.G_vmlCanvasManager));
this.pngalpha = (this.gecko || this.opera >= 6 || this.ie >= 5.5 || this.safari) ? true : false;
this.it_state = !this.opera && !this.iemac;
}
function SearchChEvent()
{
this._events = {};
}
SearchChEvent.prototype = {
addEventListener: function(evt, func, obj)
{
if (!this._events)
this._events = {};
if (!this._events[evt])
this._events[evt] = [];
var e = {func:func, obj:obj ? obj : window};
this._events[evt][this._events[evt].length] = e;
},
removeEventListener: function(evt, func, obj)
{
if (typeof obj == 'undefined')
obj = window;
for (var h,i=0; this._events && this._events[evt] && i < this._events[evt].length; i++)
if ((h = this._events[evt][i]) && h.func == func && h.obj == obj)
this._events[evt][i] = null;
},
triggerEvent: function(evt, e)
{
var ret, h;
if (typeof e == 'undefined')
e = {};
e.event = evt;
if (this._events && this._events[evt] && !this._event_exec)
{
this._event_exec = true;
for (var i=0; i < this._events[evt].length; i++)
{
if ((h = this._events[evt][i]))
{
if (typeof h.func == 'function')
ret = h.func.call ? h.func.call(h.obj, e) : h.func(e);
else if (typeof h.obj[h.func] == 'function')
ret = h.obj[h.func](e);
if (typeof ret != 'undefined' && !ret)
break;
}
}
}
this._event_exec = false;
return ret || typeof ret == 'undefined';
}
}
function SearchChMap(p)
{
this.mapcontainer = "mapcontainer";
this.type = "aerial";
this.base = "";
this.poilist = this.env.poilist;
this.base_corr = this.env.base_corr;
this.contextmenu_default = [
{ label:this.env.text.zoomout, object:this, method:"zoom", param:-1, disabled:"contextmenu_zoomdisabled" }
];
this.useragent = new search_user_agent();
this.p = { center:"", autoresize:true, autoload:true, circle:true, enable:(this.useragent.iphone || this.useragent.ipad ? 'dragging,clickpoi' : 'dragging,clickzoom,pois'), nocss:false };
this.id = SearchChMap.instances.length;
this.dom_id_prefix = 'smap'+this.id+'_';
this.ref = 'SearchChMap.instances['+this.id+']';
this._events = {};
this.charset = document.characterSet ? document.characterSet.toUpperCase() : String(document.charset).toUpperCase();
this.ready = this.busy = this.loaded = this.is_error = false;
this.mapw = this.maph = 0;
this.maptop = this.mapleft = 0;
this.centerx = this.centery = 0;
if (this.useragent.opera)
this.charset = 'ISO-8859-1';
this.default_z = 1;
this.base_url = "/";
this.coord_base = "";
this.bandwidth = "high";
this.default_bandwidth = this.useragent.iphone || location.host.match('route') ? "low" : "high";
this.show_circle = false;
this.transform = this.env.transform;
this.dozoom_timer = this.load_control_timer = this.change_check_timer = 0;
this.dragpoll_timer = this.pan_timer = 0;
this.zi = 0;
this.mode = "";
this.popup = this.popup_bar = 0;
this.startuptimestamp = window.it_starttime ? it_starttime : it_now();
this.drag_limit = 16;
this.drag_timeout = 500;
this.drag_distance = this.drag_start_time = this.drag_started = 0;
this.screenx = this.screeny = this.prevx = this.prevy = 0;
this.map_mouseinside = false;
this.startx = this.starty = this.vx = this.vy = this.starttime = 0;
this.pressed = [];
this.poi = "";
this.poi_sticky = false;
this.poi_wannaload = this.poi_requested = this.poi_unpacked = this.poi_unpacked_url = this.poi_shown = "";
this.poi_packed = {foo:'bar'};
this.mousex = this.mousey = this.poi_mousex = this.poi_mousey = 9999;
this.poi_mouset = this.poi_oldmousex = this.poi_oldmousey = this.poi_oldmouset = this.poi_speed = 0;
this.dynpois = {};
this.showing_dyn_poi = 0;
this.popup_poi = this.popup_showtime = this.popup_checkposx = this.popup_checkposy = "";
this.popup_maxwidth = this.popup_maxheight = 0.8;
this.loader = new it_loader(this);
this.geocoder = new GeoCoder(this, true);
this.tt = null;
this.dbl_offset = this.preload_count = this.show_loading_timeout = this.switch_hard = 0;
this.topx = this.topy = this.tilew = this.tileh = this.ztilew = this.ztileh = this.boxleft = this.boxright = this.boxtop = this.boxbottom;
this.zl_adj = {bg:[], sym:[]};
this.hslayer = false;
this.currentclipping = {};
this.img = [];
this.circle_img = {};
this.circle_offset = [0,0];
this.ping_img = this.loading_img = false;
this.panspeed = 0.2;
this.zoomtime = 600;
this.zoommovex = this.zoommovey = this.zoomtargetlevel = 0;
this.s_centerx = this.s_centery = 1;
this.s_check = false;
this.lastping = this.lastactivity = 0;
this.x11factor = this.useragent.x11 ? 3 : 1;
this.fade_obj_shown = 0;
this.fade_obj_vis = false;
this.fade_obj = null;
this.fade_length = 250;
this.fade_max = 0.95;
this.controls = { type:true, zoom:true, ruler:true };
this.zoomtool_box = this.maptype_box = this.pantools_box = this.copyright_box = this.ruler_box = null;
this.active_events = {dragging:null, keyboard:null, clickzoom:null, mousewheel:null, pois:null, clickpoi:null};
this.registered_handlers = {};
SearchChMap.instances[this.id] = this;
if (typeof p == 'undefined')
p = {};
this.set(p);
if (this.p.internal)
this.p.nocss = true;
if (!this.p.nocss)
this.loadcss();
if (this.p.autoload && SearchChMap.pageloaded)
this.init();
}
SearchChMap.instances = [];
SearchChMap.pageloaded = false;
SearchChMap.cssloaded = false;
SearchChMap.prototype = {
set: function(p)
{
var run_update = false;
var updates = {};
for (var k in p)
if ((typeof this.p[k] == "undefined") || (this.p[k] != p[k]))
updates[k] = true;
if (p.center && typeof p.center == 'object')
this.p.center = [];
if (p.from && typeof p.from == 'object')
p.from = p.from.join(',');
if (p.to && typeof p.to == 'object')
p.to = p.to.join(',');
it_set(this.p, p);
if (updates.container) {
this.mapcontainer = p.container;
run_update = true;
}
if (p.zoom) {
var zi = this.zd2zi(this.p.zoom);
if (zi <= this.env.zoommax && zi != this.zi) {
this.zi = zi;
run_update = true;
}
}
if (updates.from || updates.to) {
this.p.route = (this.p.from && this.p.to) ? this.p.from+' to '+this.p.to : '';
updates.route = true;
}
if (updates.center) {
if (this.ready && !this.busy)
this.geo2base(this.p.center);
this.ready = false;
this.remove_fade_obj();
}
else if (!updates.route && (updates.x || updates.y)) {
this.centerx = this.fixoffset(p.x, 1);
this.centery = this.fixoffset(p.y, -1);
this.p.x = this.p.y = 0;
}
else if (p.center) {
this.centerx = this.centery = 0;
}
if (updates.route) {
if (!this.p.route) {
this.p.drawing = null;
run_update = true;
}
else if (this.ready) {
this.loadroute(this.p.route);
this.ready = false;
}
}
if (updates.drawing)
run_update = true;
if (updates.poigroups) {
this.update_poigroups(this.p.poigroups, 'set', this.ready);
}
if (!this.contextmenu || updates.contextmenu) {
this.contextmenu = [];
for (var i=0; i < this.contextmenu_default.length; i++)
this.contextmenu[i] = this.contextmenu_default[i];
if (p.contextmenu) {
this.contextmenu[this.contextmenu.length] = false;
for (var i=0; i < p.contextmenu.length; i++)
this.contextmenu[this.contextmenu.length] = p.contextmenu[i];
}
}
if (updates.controls) {
this.controls = {};
var a_controls = this.p.controls.replace(/all/, 'type,zoom,pan,ruler').replace(/default/, 'type,zoom,ruler').split(',');
for (var i=0; i < a_controls.length; i++)
this.controls[a_controls[i]] = true;
if (this.ready && !run_update)
this.set_gui_elements();
}
if (updates.type && this.p.type != this.type) {
this.bandwidth = this.p.type == 'street' || this.p.type == 'low' ? 'low' : 'high';
var old = this.type;
this.type = this.p.type;
if (this.ready && !run_update) {
this.hide_tiles(0, false);
this.finetune();
this.jumpto(this.centerx, this.centery, 0, 0, 0, 0, 1, false);
this.set_gui_elements();
this.triggerEvent("maptypechanged", { oldtype:old, newtype:this.type });
}
}
if (updates.circle) {
if (!run_update && this.ready && this.show_circle && this.p.circle)
this.object_jumpto(this.circle_img, this.circle_offset[0], this.circle_offset[1], this.centerx, this.centery, 1, -1, -1, -34, -34);
else if (!run_update && this.ready)
it_dom.moveto(this.circle_img, 0, this.maph + 1000);
}
if (this.ready && run_update) {
this.hide_tiles(0, false);
this.clear_all_tiles();
this.update_dyn_pois();
this.preload();
}
else if (this.ready && (p.dx || p.dy)) {
p = this.rel2abs(p);
this.jumpto((this.centerx = p.x), (this.centery = p.y), 0, 0, 0, 0, 1, false);
this.clippingchanged();
}
},
enable: function(s)
{
if (!this.ready) {
this.p.enable = s;
return;
}
var en = s == 'all' ? ['dragging','keyboard','clickzoom','mousewheel','pois'] : s.split(',');
for (var evt, i=0; i0 ? 2 : (i<0 ? 0.5 : 0)), false);
},
go: function(p)
{
if (p.center && !p.method && (typeof p.center == 'object' || typeof p.center == 'string')) {
p.method = 'go';
this.geocoder.m2p(p.center, p);
return;
}
if (p.dx || p.dy)
p = this.rel2abs(p);
if (p.error) {
this.alert(p.center + ':\n' + p.error);
this.triggerEvent("geolocationerror", { code:0 });
return;
}
p.x = p.x ? p.x : 0;
p.y = p.y ? p.y : 0;
var dx = p.x - this.centerx;
var dy = p.y - this.centery;
if (Math.abs(dx) > this.mapw*1.5 || Math.abs(dy) > this.maph*1.5) {
if (this.env.poilist.tel) {
this.circle_offset = [dx, dy];
return this.set({ dx:dx, dy:dy });
}
delete p.x; delete p.y; delete p.method;
return this.set(p);
}
if (typeof p.circle != 'undefined') {
this.circle_offset = [p.x, p.y];
this.p.circle = this.show_circle = p.circle;
if (this.show_circle && !dx && !dy)
this.object_jumpto(this.circle_img, this.circle_offset[0], this.circle_offset[1], this.centerx, this.centery, 1, -1, -1, -34, -34);
else if (!this.show_circle)
it_dom.moveto(this.circle_img, 0, this.maph + 1000);
}
var zi;
if (p.zoom && (zi = this.zd2zi(p.zoom)) != this.zi) {
this.popup_hide();
this.startzoom(dx, dy, 0, zi);
}
else if (dx || dy)
this.moveto(p);
},
geolocation: function()
{
if (navigator.geolocation) {
var self = this;
var count = 0;
navigator.geolocation.getCurrentPosition(function(position) {
var z = position.coords.accuracy > 1000 ? 32 : (position.coords.accuracy > 100 ? 2 : 1);
if (!count++) {
self.go({ center:[position.coords.latitude, position.coords.longitude], zoom:z, circle:true });
self.triggerEvent("geolocation", { latitude:position.coords.latitude, longitude:position.coords.longitude, accuracy:position.coords.accuracy });
}
},
function(error) {
self.triggerEvent("geolocationerror", { code:error.code });
},
{ });
}
else
this.alert('Operation not supported');
},
get: function(what)
{
var prop = {
zoom: this.get_zd(),
type: this.type,
center: this.base_url.substr(1),
drawing: this.p.drawing,
x: Math.round(this.p2m(this.centerx))+'m',
y: Math.round(this.p2m(this.centery))+'m',
poigroups: this.poi,
circle: this.show_circle && this.p.circle,
container: this.mapcontainer,
from: this.p.from,
to: this.p.to,
route: this.p.route,
routeinfo: this.p.routeinfo
};
if (!what || what == 'enabled')
prop.enabled = it_array_keys(this.active_events).join(',');
if (!what || what == 'controls')
prop.controls = it_array_keys(this.controls).join(',');
return what ? prop[what] : prop;
},
showPOIGroup: function(p)
{
if (p != '')
this.update_poigroups(p, 'add', true);
},
hidePOIGroup: function(p)
{
if (p != '')
this.update_poigroups(p, 'remove', true);
},
addPOI: function(poi)
{
if (!poi || typeof poi != 'object')
return false;
this.dynpois[poi.id] = poi;
if (this.ready)
this.set_dyn_poi({id:poi.id});
return true;
},
removePOI: function(poi)
{
var id = (typeof poi == 'object') ? poi.id : poi;
if (this.dynpois[id] && this.dynpois[id].p) {
if (this.mapcontainer)
this.mapcontainer.removeChild(this.dynpois[id].icon);
this.dynpois[id].ready = false;
this.dynpois[id] = null;
if (this.showing_dyn_poi && this.showing_dyn_poi.id == id)
this.hide_dyn_poi();
}
},
removeAllPOIs: function()
{
for (var id in this.dynpois)
this.removePOI(id);
},
getPermUrl: function(mode)
{
if (mode == 'directions' && this.p.route)
return this.service_url('/directions.html') + '?route=' + it_url_encode(this.p.route);
var append = '';
if (mode == 'print')
append = 'p=1';
else if (mode == 'email')
append = 'e=1';
return this.get_perm_url(append, false);
},
getZoom: function()
{
return this.get_zd();
},
init: function()
{
if (!SearchChMap.isBrowserCompatible()) {
this.fatal("Browser is not compatible");
return;
}
if (typeof this.mapcontainer == 'string')
this.mapcontainer = document.getElementById(this.mapcontainer);
if (!this.mapcontainer) {
this.fatal("Map container not found");
return;
}
var csspos = it_dom.computed_style(this.mapcontainer, 'position');
if (!csspos || csspos == 'static')
this.mapcontainer.style.position = 'relative';
this.mapcontainer.className = (this.mapcontainer.className ? this.mapcontainer.className+' ' : '') + 'search_mapwidget';
if (!this.p.nocss)
this.mapcontainer.className += ' search_reset';
this.mapcontainer.style.overflow = 'hidden';
this.get_map_size();
this.calc_abs_pos();
(this.loading_img = this.alloc_image(920)).src = this.service_url('/images/loading.gif');
(this.circle_img = this.alloc_image(200)).src = this.service_url("/images/icons/circle." + (this.useragent.ie5 ? 'gif' : 'png'));
this.pngfix(this.circle_img, 68, 68);
if (this.useragent.oldgecko)
for (var t = 0; t < this.env.tot_tiles * 2 + 3; t++)
this.img[t] = this.alloc_image(t+1);
this.setmode("");
this.ping_img = this.alloc_image(1);
if (this.p.center)
this.geo2base(this.p.center);
if (this.p.route && !this.p.internal)
this.loadroute(this.p.route);
else if (!this.p.center && !this.p.internal)
this.postinit();
},
postinit: function()
{
if (this.is_error)
return;
this.change_check_timer = new it_timer({ object:this, method:'change_check', continuous:true, timeout:1000 });
it_add_event({ element:this.mapcontainer, event:"mouseover", object:this, method:"mouseover" });
it_add_event({ element:this.mapcontainer, event:"mouseout", object:this, method:"mouseout" });
it_add_event({ element:document, event:"mousemove", object:this, method:"mousemoved"});
if (this.useragent.iphone >= 2 || this.useragent.ipad) {
it_add_event({ element:this.mapcontainer, event:"touchstart", object:this, method:"touchdown" });
it_add_event({ element:this.mapcontainer, event:"touchend", object:this, method:"touchup" });
it_add_event({ element:this.mapcontainer, event:"gesturestart", object:this, method:"gesturestart" });
it_add_event({ element:this.mapcontainer, event:"gestureend", object:this, method:"gestureend" });
it_add_event({ element:this.mapcontainer, event:"touchmove", object:this, method:"touchmoved" });
}
if (this.p.autoresize)
it_event({ element:window, event:'resize', object:this, method:'resized' });
this.ready = true;
this.finetune();
this.preload();
if (this.p.enable)
this.enable(this.p.enable);
if (this.p.disable)
this.disable(this.p.disable);
for (var pid in this.dynpois)
this.set_dyn_poi({id:pid});
this.geocoder.flush();
this.addEventListener("change", "update_links", this);
this.addEventListener("maptypechanged", "update_links", this);
},
update: function(ignorelayer)
{
if (this.is_error)
return;
this.popup_hide();
this.jumpto(this.centerx, this.centery, 0, 0, 0, 0, 1, false, ignorelayer);
this.set_gui_elements();
},
preload: function()
{
this.popup_hide();
this.set_gui_elements();
this.setmode("preload");
this.jumpto(this.centerx, this.centery, 0, 0, 0, 0, 1, this.loaded);
this.show_loading_timeout = it_now() + 2500;
this.switch_hard = this.show_loading_timeout + 5000;
this.switch_tiles();
if (this.load_control_timer)
this.load_control_timer.stop();
this.load_control_timer = new it_timer({ object:this, method:'load_control', continuous:true, timeout:100});
this.s_centerx = this.centerx, this.s_centery = this.centery, this.s_check = true;
},
alloc_image: function(z)
{
var no = function() { return false; };
var im = it_create_element(this.mapcontainer, 'img', { onmousedown:no, oncontextmenu:no, style:{position:"absolute", top:1000 + this.maph + 'px', zIndex:z}, unselectable:"on" });
if (document.all && !document.getElementById)
im.src = this.service_url("/images/0.gif");
return im;
},
p2p: function(pixels, z_from, z_to)
{
if (typeof z_from == 'undefined') z_from = this.env.zoommax;
if (typeof z_to == 'undefined') z_to = this.zi;
return this.env.rect[z_from] / this.env.rect[z_to] * pixels;
},
p2m: function(pixels)
{
var zd = parseFloat(this.env.zoomlevels[this.zi]);
return pixels * zd;
},
zd2zi: function(zd)
{
var diff, last = 0x7fffffff;
for (var zi=0; zi this.env.zoomlevels[zi] ? zd / this.env.zoomlevels[zi] : this.env.zoomlevels[zi] / zd;
if (diff >= last) {
zi--;
break;
}
last = diff;
}
return Math.min(this.env.zoommax, zi);
},
fixoffset: function(val, mul)
{
var zd = parseFloat(this.env.zoomlevels[this.zi]) * mul;
if (zd && String(val).match(/^(-?[0-9\.]+)m$/))
return parseFloat(RegExp.$1) / zd;
return val * 1.6;
},
rel2abs: function(p)
{
if (p.dx && p.dx <= 1 && p.dx >= -1)
p.dx *= this.mapw;
if (p.dy && p.dy <= 1 && p.dy >= -1)
p.dy *= this.maph;
p.x = this.centerx + (p.dx ? p.dx : 0);
p.y = this.centery + (p.dy ? p.dy : 0);
return p;
},
setmode: function(newmode)
{
if ((this.mode = newmode) == "")
;
},
calc_abs_pos: function()
{
this.mapleft = it_get_obj_x(this.mapcontainer);
this.maptop = it_get_obj_y(this.mapcontainer);
},
get_map_size: function()
{
var w = this.mapcontainer.clientWidth || this.mapcontainer.offsetWidth || parseInt(it_dom.computed_style(this.mapcontainer, 'width'));
var h = this.mapcontainer.clientHeight || this.mapcontainer.offsetHeight || parseInt(it_dom.computed_style(this.mapcontainer, 'height'));
this.mapw = Math.min(1200, Math.max(200, w));
this.maph = Math.min(1200, Math.max(200, h));
if (this.mapw != w || this.maph != h)
it_dom.resizeto(this.mapcontainer, this.mapw, this.maph);
return [this.mapw, this.maph];
},
set_map_size: function(w, h)
{
this.mapw = w;
this.maph = h;
it_dom.resizeto(this.mapcontainer, w, h);
},
resized: function()
{
var w = this.mapw;
var h = this.maph;
this.get_map_size();
if (this.ready && (this.mapw != w || this.maph != h)) {
this.finetune();
this.jumpto(this.centerx, this.centery, 0, 0, 0, 0, 1, false);
this.clippingchanged();
}
},
clippingchanged: function()
{
var new_clipping = this.get_boundingbox();
if (new_clipping.base != this.currentclipping.base ||
new_clipping.route != this.currentclipping.route ||
new_clipping.zd != this.currentclipping.zd ||
new_clipping.x1 != this.currentclipping.x1 || new_clipping.x2 != this.currentclipping.x2 ||
new_clipping.y1 != this.currentclipping.y1 || new_clipping.y2 != this.currentclipping.y2) {
this.currentclipping = new_clipping;
this.triggerEvent("change", this.currentclipping);
}
},
service_url: function(s, addkey)
{
return this.env.map_server + s + (addkey && this.env.apikey ? "&key=" + this.env.apikey : "");
},
get_perm_url: function(append, rel)
{
var q = "";
var z = this.get_z();
var poi = this.poi_compact(this.poi_active());
var base = this.p.route ? '/' : this.base_url;
q += this.p.route ? "&route=" + it_url_encode(this.p.route) : "";
q += this.centerx ? "&x="+Math.round(this.p2m(this.centerx) + (this.p.route_offset ? this.p.route_offset[0] : 0))+'m' : "";
q += this.centery ? "&y=" + Math.round(this.p2m(-this.centery) + (this.p.route_offset ? this.p.route_offset[1] : 0))+'m' : "";
q += this.env.publictelparams ? ("&" + this.env.publictelparams) : "";
q += (z != this.default_z) ? "&z=" + z : ""
q += this.poi_sticky ? "&poi=" + poi : "";
q += this.bandwidth != this.default_bandwidth ? "&b="+this.bandwidth : "";
q += append ? "&"+append : "";
if (base.indexOf('?') < 0)
q = q.replace(/&/, '?');
return (rel ? base : this.service_url(base)) + q;
},
change_check: function()
{
if (it_now() - this.lastping > 9999 && it_now() - this.lastactivity < 10000) {
this.lastping = it_now();
if (this.ping_img && !this.env.noads)
this.ping_img.src = this.service_url('/images/ping.gif?x=' + this.lastactivity + '/' + "" + '/' + this.get_perm_url('', true));
}
},
get_boundingbox: function(stretched)
{
var stretch = stretched ? this.env.zoomlevels[this.zi]/this.env.zoomlevels[this.env.zoommax] : 1;
return {
base: this.base,
route: this.p.route,
x1: this.topx * stretch,
y1: this.topy * stretch,
x2: (this.topx + this.mapw) * stretch,
y2: (this.topy + this.maph) * stretch,
zd: this.get_zd(),
z: this.get_z()
};
},
get_z: function()
{
return this.env.zoomparams[this.zi];
},
get_zd: function()
{
return this.env.zoomlevels[this.zi];
},
geo2base: function(geodata)
{
var request = { zd: this.get_zd(), lang:this.env.language };
if (typeof geodata == 'object')
request.coords = geodata.join(',');
else
request.address = geodata;
if (this.base)
request.oldbase = this.base;
this.busy = true;
this.loader.clear();
this.loader.post(this.service_url("/api/?action=getbase&charset=" + this.charset, true), request);
},
loadroute: function(route)
{
if (!this.routeloader)
this.routeloader = new it_loader(this);
var request = { route:route, zd: this.get_zd() };
if (this.base)
request.base = this.base;
this.busy = true;
this.routeloader.clear();
this.routeloader.post(this.service_url("/api/?action=route&charset=" + this.charset, true), request);
},
set_base: function(p)
{
this.base = p.base;
this.base_url = p.base_url;
this.coord_base = p.coord_base;
this.default_z = p.z;
this.show_circle = p.circle;
this.transform = p.transform;
this.circle_offset = (p.circle && p.circle_offset) ? p.circle_offset : [0,0];
if (p.drawing)
this.p.drawing = p.drawing;
if (p.base_corr)
this.base_corr = p.base_corr;
if (!this.p.zoom)
this.zi = p.zi;
this.centerx = this.p.x ? this.fixoffset(this.p.x, 1) : (p.x ? this.fixoffset(p.x, 1) : 0);
this.centery = this.p.y ? this.fixoffset(this.p.y, -1) : (p.y ? this.fixoffset(p.y, -1) : 0);
if (this.p.x || this.p.y)
this.p.x = this.p.y = 0;
if (p.candidates && p.candidates.length && !this.p.internal) {
p.message = '
' + p.message + '
' + this.env.text.result_candidates + '
';
for (var i=0; i < p.candidates.length; i++)
p.message += '' + p.candidates[i].name + ' ';
}
if (p.message)
this.display_message(p.message);
if (p.dx || p.dy) {
p.dx = this.p2p(p.dx, p.zi, this.env.zoommax);
p.dy = this.p2p(p.dy, p.zi, this.env.zoommax)
for (var i in this.dynpois)
if (this.dynpois[i] && this.dynpois[i].p) {
this.dynpois[i].px += p.dx;
this.dynpois[i].py += p.dy;
}
}
if (!this.loaded)
this.postinit();
else if (!this.ready) {
this.ready = true;
this.hide_tiles(0, false);
this.clear_all_tiles();
this.update_dyn_pois();
this.finetune();
this.preload();
}
},
render: function(loader)
{
if (loader.attr.pois) {
this.poi_packed[loader.baseurl] = loader.attr.pois;
this.poi_findpopup();
}
else if (loader.attr.request && loader.attr.request == 'getbase') {
this.busy = false;
this.set_base(loader.attr);
}
else if (loader.attr.request && loader.attr.request == 'route') {
this.busy = false;
this.p.route = loader.attr.route;
this.p.drawing = loader.attr.drawing;
this.p.routeinfo = { distance: loader.attr.distance, time:loader.attr.time, text:loader.attr.description };
if (loader.attr.from) this.p.from = loader.attr.from.text;
if (loader.attr.to) this.p.to = loader.attr.to.text;
var oldzoom = this.zi;
if (!this.p.zoom && loader.attr.from && loader.attr.to) {
var width = Math.abs(loader.attr.from.x - loader.attr.to.x);
var height = Math.abs(loader.attr.from.y - loader.attr.to.y);
for (var zd, zi=this.env.zoommax; zi >= 0; zi--) {
if (this.p2p(width, this.env.zoommax, zi) <= this.mapw && this.p2p(height, this.env.zoommax, zi) <= this.maph) {
this.p.zoom = this.env.zoomlevels[zi];
this.zi = loader.attr.zi = zi;
break;
}
}
}
if (!this.p.center)
this.set_base(loader.attr);
else {
this.preload_count = 0;
this.jumpto(this.centerx, this.centery, 0, 0, 0, 0, 1, false, (oldzoom == this.zi ? 'bg' : ''));
this.clippingchanged();
}
this.ready = true;
}
else if (loader.attr.redirect)
location.href = loader.attr.redirect;
if (loader.attr.verbose)
ED(loader.attr.verbose);
},
mouseover: function(e)
{
this.map_mouseinside = true;
this.triggerEvent("mouseover");
},
mouseout: function(e)
{
this.map_mouseinside = false;
this.triggerEvent("mouseout");
},
mousemoved: function(e)
{
var coords = search_mouse_pos(e);
var src = search_get_target(e);
this.screenx = coords[0];
this.screeny = coords[1];
if (src.offsetParent == this.mapcontainer) {
var rel = search_rel_mouse_pos(e);
this.mapleft = this.screenx - rel[0] - src.offsetLeft;
this.maptop = this.screeny - rel[1] - src.offsetTop;
}
this.mousex = this.screenx - this.mapleft;
this.mousey = this.screeny - this.maptop;
this.poi_mouset = it_now();
if (this.map_mouseinside) {
this.triggerEvent("mousemove", this.map_event());
}
return !(this.map_mouseinside || this.mode == 'drag');
},
mousedown: function(e)
{
var ev = search_get_event(e);
var button = ((ev.button && ev.button == 2) || (ev.which && ev.which == 2) || ev.shiftKey || ev.ctrlKey) ? 2 : 1;
if (button == 2) {
this.contextmenu_timer = new it_timer({ object:this, method:'contextmenu_show', timeout:(!this.active_events.clickzoom || this.contextmenu_shown() || ev.ctrlKey ? 0 : 250), x:this.mousex, y:this.mousey });
}
else if (this.contextmenu_shown()) {
this.contextmenu_hide();
return false;
}
if (this.popup_mouseinside(true) || this.contextmenu_shown() || !this.map_mouseinside)
return true;
if (this.mode == "" && (this.active_events.dragging || this.active_events.clickzoom)) {
this.setmode("drag");
this.drag_start_time = it_now();
this.drag_started = false;
this.drag_distance = 0;
var coords = search_mouse_pos(e);
this.prevx = coords[0], this.prevy = coords[1];
if (this.useragent.gecko && this.active_events.dragging)
this.set_cursor('-moz-grabbing');
this.dragpoll_timer = new it_timer({ object:this, method:'dragpoll', continuous:true, timeout:20 });
}
this.mousemoved(e);
if (e.istouch && this.mode == 'drag' && this.popup_mouseinside(true)) {
this.setmode('');
return true;
}
return (this.active_events.dragging || this.active_events.clickzoom) ? it_event_void(e) : true;
},
deselectall: function()
{
var selection;
if (window.getSelection && (selection = window.getSelection()))
selection.removeAllRanges();
},
dragpoll: function()
{
var dx = this.screenx - this.prevx;
var dy = this.screeny - this.prevy;
this.prevx = this.screenx;
this.prevy = this.screeny;
this.drag_distance += dx*dx + dy*dy;
if (this.mode == "drag" && this.active_events.dragging && (dx || dy)) {
if (!this.drag_started) {
this.drag_started = true;
this.triggerEvent("dragstart");
}
this.jumpto(this.centerx -= dx, this.centery -= dy, dy>0, dx<0, dy<0, dx>0, 1, false);
}
},
mouseup: function(e)
{
if (this.contextmenu_timer) {
this.contextmenu_timer.stop();
this.contextmenu_timer = null;
}
if (this.contextmenu_mouseinside() || (this.contextmenu_shown() > 1))
return this.contextmenu_click(e);
if ((this.popup_mouseinside(true) && this.mode != "drag") || this.mode == "preload")
return true;
var clickpoi = this.active_events.clickpoi;
var ev = search_get_event(e);
var map_event = this.map_event();
map_event.button = ((ev.button && ev.button == 2) || (ev.which && ev.which == 2) || ev.shiftKey || ev.ctrlKey) ? 2 : 1;
if (this.mode == "drag") {
if (this.useragent.gecko && this.active_events.dragging)
this.set_cursor('-moz-grab');
if (this.dragpoll_timer) {
this.dragpoll_timer.stop();
this.dragpoll_timer = null;
}
if (this.drag_started)
this.triggerEvent("dragend");
this.setmode("");
this.drag_started = false;
if (this.drag_distance < this.drag_limit && it_now() < (this.drag_start_time+this.drag_timeout)) {
if (this.triggerEvent("mouseclick", map_event) && this.active_events.clickzoom && !this.linkclicked(ev)) {
if (map_event.button == 2)
this.startzoom(0, 0, 0.5, false);
else
this.startzoom(map_event.x, map_event.y, 2, false);
}
}
if (this.drag_distance >= this.drag_limit)
clickpoi = false;;
}
if (clickpoi && this.map_mouseinside) {
this.poi_mousex = this.mousex + this.topx;
this.poi_mousey = this.mousey + this.topy;
if (this.triggerEvent("mouseclick", map_event))
this.poi_trigger();
}
if (this.active_events.dragging || this.mode != "")
this.endpan();
return true;
},
touchevent: function(e)
{
return { pageX:e.pageX, pageY:e.pageY, offsetX:e.pageX - e.target.offsetLeft, offsetY:e.pageY - e.target.offsetTop, target:e.target, istouch:true };
},
touchdown: function(e)
{
if (e.touches.length == 1) {
this.map_mouseinside = true;
if (!this.mousedown(this.touchevent(e.touches[0])))
e.preventDefault();
}
},
touchup: function(e)
{
var now = it_now();
if (this.touch_time && this.mode == 'drag' && !this.popup_mouseinside(true) && (now - this.touch_time) < 600) {
this.setmode("");
this.startzoom(this.mousex - this.mapw/2, this.mousey - this.maph/2, 2, false);
e.preventDefault();
}
else if (e.changedTouches.length) {
this.mouseup(this.touchevent(e.changedTouches[0]));
}
this.touch_time = this.touch_time ? 0 : now;
},
touchmoved: function(e)
{
if (e.changedTouches.length) {
if (!this.mousemoved(this.touchevent(e.changedTouches[0])))
e.preventDefault();
}
},
gesturestart: function()
{
this.setmode("");
},
gestureend: function(e)
{
if (e.scale > 0 && (e.scale < 1 || e.scale > 1))
this.zoom(e.scale - 1);
this.touch_time = 0;
},
triggerEvent: function(evt, e)
{
var transform = e && this.transform && this.transform[this.zi];
if (transform && (typeof e.x != "undefined")) {
e.mx = Math.round((e.x + this.centerx) * transform[0] + transform[1]);
e.my = Math.round((e.y + this.centery) * transform[2] + transform[3]);
}
if (transform && (typeof e.x1 != "undefined")) {
e.mx1 = Math.round((e.x1) * transform[0] + transform[1]);
e.my1 = Math.round((e.y1) * transform[2] + transform[3]);
e.mx2 = Math.round((e.x2) * transform[0] + transform[1]);
e.my2 = Math.round((e.y2) * transform[2] + transform[3]);
}
return this._triggerEvent(evt, e);
},
linkclicked: function(ev)
{
var elm = ev.target || ev.srcElement;
return elm &&
((elm.nodeName && elm.nodeName == "A") ||
(elm.parentNode && elm.parentNode.nodeName && elm.parentNode.nodeName == "A"));
},
mousewheeled: function(e)
{
if (this.popup_mouseinside())
return true;
var ev = search_get_event(e);
var vx = 0;
var vy = ev.wheelDelta ? ev.wheelDelta/120*30 : (ev.detail ? -ev.detail*30 : 0);
if (this.useragent.opera)
vy = -vy;
if (ev.shiftKey || ev.ctrlKey || (e.axis && e.axis == e.HORIZONTAL_AXIS) || e.wheelDeltaX) {
vx = vy;
vy = 0;
}
this.setmode("mousewheel");
this.jumpto(this.centerx -= vx, this.centery -= vy, vy>0, vx<0, vy<0, vx>0, 1, false);
this.setmode("");
return false;
},
pan_mousedown: function(e)
{
var obj = search_get_target(e);
var rel = search_rel_mouse_pos(e);
if (!this.useragent.ie) {
var pos = search_mouse_pos(e);
var ref = it_rel_obj_pos(obj, this.mapcontainer);
var offx = this.useragent.gecko ? parseInt(this.mapcontainer.style.getPropertyValue('border-left-width')) : 1;
var offy = this.useragent.gecko ? parseInt(this.mapcontainer.style.getPropertyValue('border-top-width')) : 1;
rel[0] = pos[0] - this.mapleft - ref[0] - (isNaN(offx) ? 1 : offx);
rel[1] = pos[1] - this.maptop - ref[1] - (isNaN(offy) ? 1 : offy);
}
rel[0] -= Math.floor(obj.offsetWidth / 2);
rel[1] -= Math.floor(obj.offsetHeight / 2);
this.startpan(rel[0] > 6 ? 1 : (rel[0] < -6 ? -1 : 0), rel[1] > 6 ? 1 : (rel[1] < -6 ? -1 : 0));
},
pan_mouseup: function(e)
{
this.endpan();
},
startpan: function(dx, dy)
{
this.starttime = it_now();
this.startx = this.centerx;
this.starty = this.centery;
this.vx = this.panspeed * dx;
this.vy = this.panspeed * dy;
if (this.mode == "" && (dx || dy)) {
this.setmode("pan");
this.triggerEvent("panstart");
if (!this.pan_timer)
this.pan_timer = new it_timer({ object:this, method:'dopan', continuous:true, timeout:20*this.x11factor});
}
return false;
},
dopan: function()
{
var t = it_now() - this.starttime;
this.jumpto(this.centerx = this.startx + this.vx * t, this.centery = this.starty + this.vy * t, this.vy<0, this.vx>0, this.vy>0, this.vx<0, 1, false);
},
endpan: function()
{
if (this.pan_timer) {
this.pan_timer.stop();
this.pan_timer = null;
}
if (this.mode == "pan") {
this.setmode("");
this.triggerEvent("panend");
this.clippingchanged();
}
else if (this.mode.indexOf("zoom") != 0)
this.clippingchanged();
return false;
},
moveto: function(p)
{
this.starttime = it_now();
this.startx = this.centerx;
this.starty = this.centery;
p.dx = p.x - this.startx;
p.dy = p.y - this.starty;
p.duration = p.duration ? p.duration : ((Math.abs(p.dx) > this.mapw) || (Math.abs(p.dy) > this.maph) ? 3000 : 1000);
this.move_params = p;
if (this.mode == "") {
this.setmode("move");
this.move_timer = new it_timer({ object:this, method:'move', continuous:true, timeout:20*this.x11factor });
}
},
move: function()
{
var percent, perc;
var t = it_now() - this.starttime;
var p = this.move_params;
percent = perc = Math.min(1, t/p.duration);
perc = Math.sin(perc*1.57);
var dx = p.dx*perc, dy = p.dy*perc;
if(((Math.abs(dx) < this.mapw) && (Math.abs(dy) < this.maph)) || ((Math.abs(p.dx-dx) < this.mapw) && (Math.abs(p.dy-dy) < this.maph)))
this.jumpto(this.centerx = this.startx+Math.round(p.dx*perc), this.centery = this.starty+Math.round(p.dy*perc), 0, 0, 0, 0, 1, false);
else
this.clear_all_tiles();
if (percent >= 1)
this.endmove();
},
endmove: function()
{
this.move_timer.stop();
this.move_timer = 0;
if (this.mode == "move")
this.setmode("");
if (this.move_params.zoomto_zi && (this.move_params.zoomto_zi > this.zi))
this.startzoom(0, 0, 0, this.move_params.zoomto_zi);
this.clippingchanged();
},
keydown: function(e)
{
var ev = search_get_event(e);
var key = ev.keyCode;
if (!this.active_events.keyboard || this.ignore_event(ev) || this.irrelevant_key(ev))
return true;
if (!this.pressed[key]) {
this.pressed[key] = 1;
if (key >=37 && key <= 40 && this.mode.indexOf("zoom") != 0)
this.startpan((this.pressed[37]?-1:0) + (this.pressed[39]?1:0), (this.pressed[38]?-1:0) + (this.pressed[40]?1:0));
else if (key == 107 && this.mode == "")
this.startzoom(0, 0, 2, false);
else if (key == 109 && this.mode == "")
this.startzoom(0, 0, 0.5, false);
}
return it_event_void(e);
},
keypress: function(e)
{
var ev = search_get_event(e);
return (this.ignore_event(ev) || this.irrelevant_key(ev)) ? true : it_event_void(e);
},
keyup: function(e)
{
var ev = search_get_event(e);
var key = ev.keyCode;
var nomore = true;
if (!this.active_events.keyboard)
return false;
else if (this.ignore_event(ev) || this.irrelevant_key(ev))
return true;
this.pressed[key] = 0;
for (var i=0; i=37 && key <= 40 && this.mode == "pan")
this.startpan((this.pressed[37]?-1:0) + (this.pressed[39]?1:0), (this.pressed[38]?-1:0) + (this.pressed[40]?1:0));
return false;
},
irrelevant_key: function(ev)
{
var key = ev.keyCode;
return ev.altKey || key<37 || (key>40 && key!=107 && key!=109);
},
ignore_event: function(ev)
{
var t = search_get_target(ev);
return ((t.tagName == "INPUT" && t.type == "text") || (t.tagName == "SELECT") || (t.tagName == "TEXTAREA") || ev.metaKey || ev.ctrlKey)
},
contextmenu_show: function(p)
{
this.deselectall();
this.contextmenu_hide();
this.setmode('');
this.set_cursor('');
var div = this.contextmenudiv;
if (!div) {
div = this.contextmenudiv = document.createElement('div');
div.className = "search_reset search_mapwidget_contextmenu";
it_event({ element:div, event:'mousedown', object:this, method:'contextmenu_ignore' });
it_event({ element:div, event:'contextmenu', object:this, method:'contextmenu_ignore' });
it_event({ element:div, event:'mouseup', object:this, method:'contextmenu_click' });
it_event({ element:div, event:'click', object:this, method:'contextmenu_click' });
document.body.appendChild(div);
}
if (!div.shown) {
this.contextmenu_event = p;
var x = p.x + this.mapleft + 2;
var y = p.y + this.maptop - 10;
var html = [], h = 0;
for (var i=0; i < this.contextmenu.length; i++) {
var item = this.contextmenu[i];
if (item) {
var classname = !item.method || this.contextmenu_call(item, "disabled") ? "disabled" : "enabled";
html[h++] = "" + item.label + "";// Hover css only works on A tag in IE6
}
else if (typeof item != 'undefined')
html[h++] = "";// Using tag HR was causing layout problems with IE6
}
try { div.innerHTML = "