
//* Convenience DOM-Functions
function $(n, index, element, specification, state) {
/* Valid State Provided */
if(typeof(state) == 'string')
return $(n + '[' + index + ']', element, specification, state);
/* Valid Specification Provided */
if(typeof(specification) == 'string')
return $(n + '[' + index + ']', element, specification);
/* Valid Element Provided */
if(typeof(element) == 'string')
return $(n + '[' + index + ']', element);
/* Only Node Provided */
if(typeof(index) == 'undefined') {
if(typeof(n) == 'object')
return n;
if(typeof(n) != 'string')
return null;
return document.getElementById(n);
}
/* Valid Index Provided */
return $(n + '[' + index + ']');
}
function $_REVERSE(node) {
var n = $(node);
// Substract Values
var a = n.id.replace(/]/g, '').split('[');
// Return Value
var r = {};
r['n'] = a[0];
r['index'] = a[1];
r['element'] = a[2];
r['specification'] = a[3];
return r;
}
function $_EXIST(n, index, element, specification, state) {
return $(n, index, element, specification, state) != null;
}
function $Element(n, classname) {
var e = document.createElement(n);
if(classname)
e.className = classname;
return e;
}
function $Text(n, style) {
if(style != undefined) {
var span = $Span();
for(s in style)
span.style[s] = style[s];
span.appendChild(document.createTextNode(n));
return span;
}
else
return document.createTextNode(n);
}
function $Div(classname, width) {
var e = $Element('div', classname);
if(width != undefined)
e.style.width = width + 'px';
return e;
}
function $Span(classname, width) {
var e = $Element('span', classname);
if(width != undefined)
e.style.width = width + 'px';
return e;
}
function $Img(src, classname, width, height) {
var e = $Element('img', classname);
e.src = src;
if(width)
e.style.width = width + 'px';
if(height)
e.style.height = height + 'px';
return e;
}
function $Table(classname) {
return $Element('table', classname);
}
function $Tr(classname) {
return $Element('tr', classname);
}
function $Td(classname, colspan, width) {
var e = $Element('td', classname);
if(colspan)
e.colSpan = colspan;
if(width)
e.style.width = width + 'px';
return e;
}
function $Link(url, content, target, classname, title) {
var a = $Element('a', classname);
a.href = url;
if(target)
a.target = target;
if(typeof(content) == 'object')
a.appendChild(content);
else
a.appendChild($Text(content));
if(title)
a.setAttribute('title', title);
return a;
}
function setClass(e, classname, exclusive) {
e = $(e);
if(!e)
return;
exclusive = (exclusive == undefined) ? false : exclusive;
if(exclusive == true) {
e.className = classname;
return;
}
var cn = e.className.split(' ');
if(cn.indexOf(classname) != -1)
return;
cn.push(classname);
e.className = cn.join(' ');
}
function unsetClass(e, classname) {
e = $(e);
if(!e)
return;
var cn = e.className.split(' ');
var i = cn.indexOf(classname);
if(i == -1)
return;
cn.splice(i, 1);
e.className = cn.join(' ');
}
function display(node, type) {
var n = $(node);
if(!n)
return;
n.style.display = type;
}
function toggle_display(node, type_on, type_off) {
var n = $(node);
if(!n)
return;
if(n.style.display == type_on)
n.style.display = type_off;
else if(n.style.display == type_off)
n.style.display = type_on;
}
function show(node, optional_index) {
unsetClass($(node, optional_index), 'hide');
}
function hide(node, optional_index) {
setClass($(node, optional_index), 'hide');
}
function isHidden(node) {
return hasClass(node, 'hide');
}
function clear(node) {
var n = $(node);
if(!n)
return;
while(n.firstChild)
n.removeChild(n.firstChild)
}
function setText(node, s, style) {
clear(node);
if(typeof(s) != 'string')
return;
$(node).appendChild($Text(s, style));
}
function resetForm(node) {
var n = $(node);
if(!n)
return;
n.reset();
}
function getText(node) {
var n = $(node);
if(!n)
return '';
if(node.innerText)
return node.innerText;
if(node.textContent)
return node.textContent;
return '';
}
function nextNode(node, name) {
if(node == null)
return null;
var x = node.nextSibling;
while(x != null) {
if(x.nodeName.toLowerCase() == name)
return x;
x = x.nextSibling;
}
return null;
}
function getMaxHeight(node) {
var n = $(node);
if(!n)
return 0;
var posy = n.offsetTop;
while((n = n.offsetParent) != null)
posy += n.offsetTop;
var innerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
return (innerHeight - posy);
}
function maximizeElement(name, offset) {
var height = getMaxHeight(name) + offset;
$(name).style.height = height + 'px';
}
function swap_visibility(hide, show) {
display(hide, 'none');
display(show, '');
}
function getAbsolutePosition(node) {
var n = $(node);
var pos = {x: 0, y: 0};
pos.x = n.offsetLeft;
pos.y = n.offsetTop;
while((n = n.offsetParent) != null) {
pos.x += n.offsetLeft;
pos.y += n.offsetTop;
}
return pos;
}
function getDimension(node) {
var dim = { topleft: {x: 0, y: 0}, bottomright: {x: 0, y: 0}};
dim.topleft = getAbsolutePosition(node);
dim.bottomright.x = dim.topleft.x + node.offsetWidth;
dim.bottomright.y = dim.topleft.y + node.offsetHeight;
return dim;
}
function getRelativePosition(child, parent) {
var cpos = this.getAbsolutePosition(child);
var ppos = this.getAbsolutePosition(parent);
var pos = {x: 0, y: 0};
pos.x = cpos.x - ppos.x;
pos.y = cpos.y - ppos.y;
return pos;
}
function getPageDimension() {
var dim = {x: 0, y: 0};
if (document.body.scrollHeight > document.body.offsetHeight) {
dim.x = document.body.scrollWidth;
dim.y = document.body.scrollHeight;
}
else {
dim.x = document.body.offsetWidth;
dim.y = document.body.offsetHeight;
}
return dim;
}
function getInnerDimension() {
var dim = {x: 0, y: 0};
if (self.innerHeight) {
dim.x = self.innerWidth;
dim.y = self.innerHeight;
}
else if(document.documentElement && document.documentElement.clientHeight) {
dim.x = document.documentElement.clientWidth;
dim.y = document.documentElement.clientHeight;
}
else if(document.body) {
dim.x = document.body.clientWidth;
dim.y = document.body.clientHeight;
}
return dim;
}
//* AJAX Toolkit
//* Copyright 2006 OPAG Online Promotion AG
function AJAX(url, callback, data, sync) {
this.sync = sync || false;
if(window.ActiveXObject)
this.request = new ActiveXObject('Microsoft.XMLHTTP');
else
this.request = new XMLHttpRequest();
if(this.sync == false) {
this.request.open('POST', url + '?rand=' + Math.random(), true);
var a = this;
this.request.onreadystatechange = function() {
var r = a.request;
if(r.readyState == 4) {
try { a.ontransferend(); } catch(e) {}
if(r.status == 200)
a.callback(a.parseJSON(r.responseText), a.data);
else
a.callback(null, a.data);
}
};
}
else
this.request.open('POST', url + '?rand=' + Math.random(), false);
this.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
if(callback)
this.callback = callback;
else
this.callback = this.success;
this.data = data;
this.parameter = '';
}
AJAX.prototype.success = function(s, d) {
alert(s);
}
AJAX.prototype.parseJSON = function(text) {
if(text.length == 0)
return null;
var rex = /[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/
var reprex = /"(\\.|[^"\\])*"/g
if(rex.test(text.replace(reprex, '')) == true)
return null;
var obj;
try {
obj = eval('(' + text + ')');
}
catch(e) {
obj = null;
}
return obj;
}
AJAX.prototype.setParameter = function(parameter, value) {
this.parameter = this.parameter + '&' + encodeURIComponent(parameter) + '=' + encodeURIComponent(value);
}
AJAX.prototype.setForm = function(fid) {
var f = document.getElementById(fid);
if(!f)
return;
var p = '';
for(var i = 0; i < f.elements.length; i++) {
switch(f.elements[i].type) {
case 'hidden':
case 'text':
case 'password':
case 'textarea':
p = p + '&' + encodeURIComponent(f.elements[i].name) + '=' + encodeURIComponent(f.elements[i].value);
break;
case 'checkbox':
case 'radio':
if(f[i].checked)
p = p + '&' + encodeURIComponent(f.elements[i].name) + '=' + encodeURIComponent(f.elements[i].value);
break;
case 'select-one':
p = p + '&' + encodeURIComponent(f.elements[i].name) + '=' + encodeURIComponent(f.elements[i].value);
break;
case 'select-multiple':
for(var j = 0; j < f.elements[i].options.length; j++) {
if(f.elements[i].options[j].selected)
p = p + '&' + encodeURIComponent(f.elements[i].name) + '=' + encodeURIComponent(f.elements[i].options[j].value);
}
break;
case 'button':
case 'submit':
case 'reset':
default:
break;
}
}
this.parameter = this.parameter + p;
}
AJAX.prototype.send = function() {
try { this.ontransferstart(); } catch(e) {}
this.request.send('utf8=ä' + this.parameter);
if(this.sync == false)
return;
if(this.request.status == 200) {
try { this.ontransferend(); } catch(e) {}
return this.parseJSON(this.request.responseText);
}
try { this.ontransferend(); } catch(e) {}
return null;
}
AJAX.prototype.ontransferstart = function() {}
AJAX.prototype.ontransferend = function() {}
function enhanceEvent(event, target) {
if(!event)
event = window.event;
event.overrideTarget = null;
if(target)
event.overrideTarget = target;
event.getAbsoluteXY = function() {
var x, y;
// Den absoluten Abstand des Mauszeigers vom linken Rand des Dokuments bestimmen
if(this.pageX)
x = this.pageX;
else if(this.clientX)
x = this.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
// Den absoluten Abstand des Mauszeigers vom oberen Rand des Dokuments bestimmen
if(this.pageY)
y = this.pageY;
else if(this.clientY)
y = this.clientY + document.documentElement.scrollTop + document.body.scrollTop;
return {
x: x,
y: y
};
}
event.getAbsoluteX = function() {
return this.getAbsoluteXY().x;
}
event.getAbsoluteY = function() {
return this.getAbsoluteXY().y;
}
event.getRelativeXY = function() {
var a = this.getAbsoluteXY();
var t = this.getTargetXY();
return {
x: a.x - t.x,
y: a.y - t.y
};
}
event.getRelativeX = function() {
return this.getRelativeXY().x;
}
event.getRelativeY = function() {
return this.getRelativeXY().y;
}
event.getTarget = function() {
if(this.overrideTarget)
return this.overrideTarget;
if(this.target)
return this.target;
return this.srcElement;
}
event.getTargetXY = function() {
var x, y;
var n = this.getTarget();
x = n.offsetLeft;
y = n.offsetTop;
while((n = n.offsetParent) != null) {
x += n.offsetLeft;
y += n.offsetTop;
}
return {
x: x,
y: y
};
}
event.getTargetX = function() {
return this.getTargetXY().x;
}
event.getTargetY = function() {
return this.getTargetXY().y;
}
event.getWindowXY = function() {
var x, y;
x = 0;
y = 0;
if(this.clientX)
x = this.clientX;
if(this.clientY)
y = this.clientY;
return {
x: x,
y: y
};
}
event.getWindowX = function() {
return this.getWindowXY().x;
}
event.getWindowY = function() {
return this.getWindowXY().y;
}
event.getKeycode = function() {
if(this.which)
return this.which;
return this.keyCode;
}
event.stopBubble = function() {
this.cancelBubble = true;
if(this.stopPropagation)
this.stopPropagation();
}
return event;
}
function addEvent(object, type, handler) {
if(object.addEventListener)
object.addEventListener(type, handler, false);
else if(object.attachEvent)
object.attachEvent('on' + type, handler);
else
object['on' + type] = handler;
}
function removeEvent(object, type, handler) {
if(object.removeEventListener)
object.removeEventListener(type, handler, false);
else if(object.detachEvent)
object.detachEvent('on' + type, handler);
else
object['on' + type] = '';
}
var _dnd = null;
function dragTag(pos, style, name, source) {
_dnd = $Div(style);
_dnd.style.position = 'absolute';
_dnd.appendChild($Text(name));
_dnd.setAttribute('name', name);
_dnd.setAttribute('source', source);
_dnd.style.left = (pos.x + 5) + 'px';
_dnd.style.top = (pos.y + 5) + 'px';
_dnd.style.zIndex = '99999';
document.onmousemove = function(e) {
e = enhanceEvent(e);
var pos = e.getAbsoluteXY();
_dnd.style.left = (pos.x + 5) + 'px';
_dnd.style.top = (pos.y + 5) + 'px';
return false;
}
document.body.appendChild(_dnd);
}
function dragEnd() {
if(_dnd == null)
return;
document.body.removeChild(_dnd);
_dnd = null;
document.onmousemove = function(e) {};
}
var locals = {
tagout: false
};
function load() {
if(globals.mypage)
init_tags();
}
function init_tags() {
var tags = $('moveable_tags');
if(tags) {
var f = tags.getElementsByTagName('span');
for(var i = 0; i < f.length; i++) {
f[i].onmousedown = taglist_mousedown;
if(f[i].innerText)
f[i].id = 't_' + f[i].innerText;
else
f[i].id = 't_' + f[i].textContent;
}
}
for(var i = 0; i < globals.webcams.length; i++) {
tags = $('wt_' + globals.webcams[i]);
f = tags.getElementsByTagName('span');
for(var j = 0; j < f.length; j++) {
f[j].setAttribute('webcamid', globals.webcams[i]);
f[j].onmousedown = webcamtaglist_mousedown;
}
}
$('moveable_tag').onkeydown = function(e) {
if(!e)
e = window.event;
var key = null;
if(e.which)
key = e.which;
else
key = e.keyCode;
if(key == 10 || key == 13)
add_tag();
return;
}
document.body.onmouseup = function() {
dnd_remove_webcam_tag();
}
}
function taglist_mousedown(e) {
e = enhanceEvent(e);
var pos = e.getAbsoluteXY();
var tag = getText(this);
dragTag(pos, 'dndtag', tag, 'taglist');
return false;
}
function webcamtaglist_mousedown(e) {
e = enhanceEvent(e);
var pos = e.getAbsoluteXY();
var webcamid = this.getAttribute('webcamid');
var tag = getText(this);
locals.tagout = false;
var n = $('w_' + webcamid);
n.onmouseout = function() { locals.tagout = true; };
n.onmouseover = function() { locals.tagout = false; };
dragTag(pos, 'dndtag', tag, 'webcam_' + webcamid);
return false;
}
function add_tag() {
var n = $('moveable_tag');
var tag = n.value;
if(tag.length == 0)
return;
tag = tag.replace('/', '-', 'g');
tag = tag.replace(/"+/g, '"');
tag = tag.replace(/\s+/g, ' ');
var tags = tag.split(' ');
var combined_tag = '';
for(var i = 0; i < tags.length; i++) {
if(combined_tag.length == 0) {
if(tags[i].charAt(0) == '"') {
if(tags[i].charAt(tags[i].length - 1) != '"')
combined_tag = tags[i].substr(1);
else
add_single_tag(tags[i].substr(1, tags[i].length - 2));
}
else
add_single_tag(tags[i]);
}
else {
combined_tag = combined_tag + ' ' + tags[i];
if(tags[i].charAt(tags[i].length - 1) == '"') {
add_single_tag(combined_tag.substr(0, combined_tag.length - 1));
combined_tag = '';
}
}
}
n.value = '';
return;
}
function add_single_tag(tag) {
if(tag.length == 0 || tag.length == 1)
return;
var tags = $('moveable_tags');
var f = tags.getElementsByTagName('span');
for(var i = 0; i < f.length; i++) {
if(f[i].id == 't_' + tag)
return;
}
var span = $Span();
span.id = 't_' + tag;
span.onmousedown = taglist_mousedown;
span.appendChild($Text(tag));
if(f.length != 0)
tags.appendChild($Text(', '));
tags.appendChild(span);
var taglist = $('moveable_taglist');
webcamid = taglist.getAttribute('webcamid');
if(webcamid) {
update_webcam_taglist('add', webcamid, tag);
save_webcam_tag('add', webcamid, tag);
}
tags = $('tags');
var link = $Link('/tags/' + tag, tag);
li = $Element('li');
li.appendChild(link);
tags.appendChild(li);
return;
}
function dnd_add_webcam_tag(webcam) {
if(_dnd == null)
return;
var source = _dnd.getAttribute('source');
var tag = _dnd.getAttribute('name');
dragEnd();
if(source != 'taglist' && !source.match(/^webcam_(.*)/))
return;
if(tag.length == 0)
return;
var webcamid = webcam.id.substr(2);
update_webcam_taglist('add', webcamid, tag);
save_webcam_tag('add', webcamid, tag);
return;
}
function dnd_remove_webcam_tag() {
if(_dnd == null)
return;
var source = _dnd.getAttribute('source');
var tag = _dnd.getAttribute('name');
dragEnd();
if(locals.tagout == false)
return;
var m = source.match(/^webcam_(.*)/);
if(m == null)
return;
var webcamid = m[1];
var n = $('w_' + webcamid);
n.onmouseout = function() {};
n.onmouseover = function() {};
if(tag.length == 0)
return;
update_webcam_taglist('remove', webcamid, tag);
save_webcam_tag('remove', webcamid, tag);
return;
}
function update_webcam_taglist(mode, webcamid, tag) {
var n = $('wt_' + webcamid);
var tags = globals.tags['w_' + webcamid];
if(mode == 'add') {
for(var i = 0; i < tags.length; i++) {
if(tags[i] == tag)
return;
}
tags.push(tag);
}
else if(mode == 'remove') {
pos = -1;
for(var i = 0; i < tags.length; i++) {
if(tags[i] == tag) {
pos = i;
break;
}
}
if(pos == -1)
return;
tags.splice(pos, 1)
}
clear(n);
var span = null;
for(var i = 0; i < tags.length - 1; i++) {
span = $Span();
span.appendChild($Text(tags[i]));
span.setAttribute('tag', tags[i]);
span.setAttribute('webcamid', webcamid);
span.onmousedown = webcamtaglist_mousedown;
n.appendChild(span);
n.appendChild($Text(', '));
}
if(tags.length > 0) {
span = $Span();
span.appendChild($Text(tags[tags.length - 1]));
span.setAttribute('tag', tags[tags.length - 1]);
span.setAttribute('webcamid', webcamid);
span.onmousedown = webcamtaglist_mousedown;
n.appendChild(span);
}
}
function save_webcam_tag(mode, webcamid, tag) {
var a = new AJAX('/ajax/tag.php', function(response, data) {
if(response == null)
return;
if(response.status != 200)
return;
}, null, false);
a.setParameter('a', mode);
a.setParameter('tag', tag);
a.setParameter('webcamid', webcamid);
a.send();
return;
}
function show_moveable_tags(webcamid) {
var mt = $('mt_' + webcamid);
if(!mt)
return;
hide_moveable_tags();
var tags = $('moveable_taglist');
tags.setAttribute('webcamid', webcamid);
tags.parentNode.removeChild(tags);
mt.appendChild(tags);
$('addlink_' + webcamid).style.visibility = 'hidden';
display(tags, '');
return;
}
function hide_moveable_tags() {
var tags = $('moveable_taglist');
var b = document.getElementsByTagName('body')[0];
webcamid = tags.getAttribute('webcamid');
if(webcamid)
$('addlink_' + webcamid).style.visibility = 'visible';
display(tags, 'none');
tags.removeAttribute('webcamid');
tags.parentNode.removeChild(tags);
b.appendChild(tags);
return;
}

