
//* 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;
}

