Function.prototype.inherits = function(value) {
function temp() { };
temp.prototype = value.prototype;
this.prototype = new temp();
this.prototype.constructor = this;
this.parentClass = value;
};
Array.prototype.indexOf = function (value, offset) {
var len = this.length;
offset = offset || 0;
offset = offset < 0 ? Math.max(0, len + offset) : offset;
for (var i=offset; i<len; i++) {
if (this[i] === value) { return i; }
}
return -1;
}
Array.prototype.filter = function(func, scope) {
scope = scope || this;
var result = [], index = 0;
for (var i=0,l=this.lenth; i<l; l++) {
var item = this[i];
if (func.call(scope, item, i, this)) {
result[index++] = item;
}
}
return result;
};
Array.prototype.map = function(func, scope) {
scope = scope || this;
var result = [], index = 0;
for (var i=0,l=this.lenth; i<l; l++) {
result[index++] = func.call(scope, this[i], i, this);
}
return result;
};
String.prototype.trim = function() {
return this.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '');
};
String.prototype.toUcFirst = function() {
var str = this.toLowerCase();
return str.replace(/^([a-z])/g, function(x,l) { return l.toUpperCase() });
};
String.prototype.toUcWords = function() {
var str = this.toLowerCase();
return str.replace(/(^([a-z])|\s[a-z])/g, function(x,l) { return l.toUpperCase() });
};
String.prototype.toCamel = function() {
var str = this.toLowerCase();
return str.replace(/-([a-z])/g, function(x,l) { return l.toUpperCase() });
};
String.prototype.padLeft = function(len, chr) {
var str = this;
while (str.length < len) {
str = chr + str;
}
return str;
};
String.prototype.padRight = function(len, chr) {
var str = this;
while (str.length < len) {
str += chr;
}
return str;
};
String.prototype.truncate = function(size, noBreak) {
noBreak = !!noBreak;
var result = this, truncated = false;
if (size > 0 && this.length-1 > size) {
result = result.substring(0, size);
truncated = true;
}
noBreak && (result = result.replace(/(\r\n|\r|\n)+/g, '<br />'));
return truncated ? '<span class="caption" title="'+this+'">'+result+'<span class="dots">...</span></span>' : result;
};
var TUserAgent = {};
TUserAgent.AGENT = navigator.userAgent;
TUserAgent.PLATFORM = navigator.platform;
TUserAgent.WEBKIT = TUserAgent.AGENT.indexOf('WebKit') != -1;
TUserAgent.GECKO = TUserAgent.AGENT.indexOf('Gecko') != -1;
TUserAgent.OPERA = typeof opera != "undefined";
TUserAgent.IE = TUserAgent.AGENT.indexOf('MSIE') != -1;
TUserAgent.FIREFOX = TUserAgent.AGENT.indexOf('Firefox') != -1;
TUserAgent.CHROME = TUserAgent.AGENT.indexOf('Chrome') != -1;
TUserAgent.SAFARI = TUserAgent.AGENT.indexOf('Safari') == -1 && !TUserAgent.CHROME;
TUserAgent.KONQUEROR = TUserAgent.AGENT.indexOf('Konqueror') != -1;
TUserAgent.MAC = TUserAgent.PLATFORM.indexOf('Mac');
TUserAgent.WIN = TUserAgent.PLATFORM.indexOf('Win');
TUserAgent.LINUX = TUserAgent.PLATFORM.indexOf('Linux');
TUserAgent.VERSION = 0;
var matches = TUserAgent.AGENT.match(/WebKit\/([^\s]*)/);
if (matches && matches[1]) { TUserAgent.VERSION = parseFloat(matches[1]); };
matches = TUserAgent.AGENT.match(/Opera( Mini)?[\s\/]([^\s]*)/);
if (matches && matches[2]) { TUserAgent.VERSION = parseFloat(matches[2]); };
matches = TUserAgent.AGENT.match(/MSIE\s([^;]*)/);
if (matches && matches[1]) { TUserAgent.VERSION = parseFloat(matches[1]); };
matches = TUserAgent.AGENT.match(/Gecko\/([^\s]*)/);
if (matches && matches[1]) {
TUserAgent.VERSION = parseFloat(matches[1]);
matches = TUserAgent.AGENT.match(/rv:([^\s\)]*)/);
if (matches && matches[1]) { TUserAgent.VERSION = parseFloat(matches[1]); }
};
var TPoint = function (top,left) {
this.top = top || 0;
this.left = left || 0;
}
TPoint.prototype.top = 0;
TPoint.prototype.left = 0;
TPoint.prototype.toString = function() {
return "Top: " + this.top + "\nLeft: " + this.left;
}
var TRect = function (top,left,width,height) {
this.top = top || 0;
this.left = left || 0;
this.width = width || 0;
this.height = height || 0;
}
TRect.inherits(TPoint);
TRect.prototype.width = 0;
TRect.prototype.height = 0;
TRect.prototype.toString = function() {
return "Top: " + this.top + "\nLeft: " + this.left + "\nWidth: " + this.width + "\nHeight: " + this.height;
}
var TDOM = {};
TDOM._onLoad = [];
TDOM.documentLoaded = false;
TDOM.UNIQUE_ID_PROPERTY = 'tdom_unique_id_property';
TDOM.UNIQUE_ID_COUNTER = 1;
TDOM.NodeType = { ELEMENT: 1, ATTRIBUTE: 2, TEXT: 3, CDATA_SECTION: 4, ENTITY_REFERENCE: 5, ENTITY: 6, PROCESSING_INSTRUCTION: 7, COMMENT: 8, DOCUMENT: 9, DOCUMENT_TYPE: 10, DOCUMENT_FRAGMENT: 11, NOTATION: 12 };
TDOM._visibleStack = {};
TDOM._doOnLoad = function(e) {
TDOM.documentLoaded = true;
TEvents.unlisten(window,'load',TDOM._doOnLoad);
for (var i=0, l=TDOM._onLoad.length; i < l; i++) {
TDOM._onLoad[i].func.call(TDOM._onLoad[i].scope);
}
TDOM._onLoad = [];
}
TDOM.onLoad = function(f,scope) {
scope = scope || this;
TDOM.documentLoaded ? f.call(scope) : TDOM._onLoad.push({scope:scope, func:f});
}
TDOM.getElement = function(value) {
return typeof value == "string" ? document.getElementById(value) : value;
};
TDOM.getDocument = function(node) {
node = TDOM.getElement(node) || document;
return node.nodeType == TDOM.NodeType.DOCUMENT ? node : node.ownerDocument || node.document || document;
};
TDOM.getRootNode = function(node) {
var doc = TDOM.getDocument(node);
return document.compatMode == 'CSS1Compat' ? doc.documentElement : doc.body;
};
TDOM.getWindow = function(node) {
if (node && typeof node.opener != 'undefined') { return node; }
var doc = TDOM.getDocument(node);
return doc.parentWindow || doc.defaultView || window;
};
TDOM.getUniqueId = function(el) {
el = TDOM.getElement(el);
if (!el) { return; }
var p = TDOM.UNIQUE_ID_PROPERTY;
if (el.hasOwnProperty && el.hasOwnProperty(p)) {
var value = el[p];
if (value) {
return value;
}
}
if (!el[p]) {
var value = TDOM.UNIQUE_ID_COUNTER++;
el[p] = value;
}
return el[p];
};
TDOM.resolveNode = function(node, property, test) {
test = test || function (n) { return n.nodeType == TDOM.NodeType.ELEMENT; }
property = property || 'nextSibling';
while (node)  {
if (test(node)) { return node; }
try {
node = node[property];
} catch(e) {
return null;
}
}
return node;
};
TDOM.resolveTextNode = function(node) {
node = TDOM.getElement(node);
return TDOM.resolveNode(node, 'parentNode', function(n) { return n.nodeType == TDOM.NodeType.ELEMENT; });
};
TDOM.nextElement = function(node) {
node = TDOM.getElement(node);
return !!node && TDOM.resolveNode(node.nextSibling);
};
TDOM.previousElement = function(node) {
node = TDOM.getElement(node);
return !!node && TDOM.resolveNode(node.previousSibling, 'previousSibling');
};
TDOM.firstChild = function(node) {
node = TDOM.getElement(node);
return !!node && TDOM.resolveNode(node.firstChild, 'nextSibling');
};
TDOM.lastChild = function(node) {
node = TDOM.getElement(node);
node = node && node.lastChild;
return !!node && TDOM.resolveNode(node, 'nextSibling') || TDOM.resolveNode(node, 'previousSibling');
};
TDOM.firstHiddenParent = function(node) {
node = TDOM.getElement(node);
return !!node && TDOM.resolveNode(node, 'parentNode', function(n) { return n.nodeType == TDOM.NodeType.ELEMENT && TDOM.getStyle(n, "display") == "none" });
};
TDOM.getParentBy = function(node,test) {
return TDOM.resolveNode(node,'parentNode',test);
};
TDOM.insertElement = function(a, after, b) {
if (b && b.parentNode) {
c = after ? TDOM.nextElement(b) : b;
c ? b.parentNode.insertBefore(a,c) : b.parentNode.appendChild(a);
}
};
TDOM.createElement = function(name, attr) {
var el = document.createElement(name);
el && attr && TDOM.setAttributes(el,attr);
return el;
};
TDOM.setAttributes = function(el, attr) {
for (var a in attr) {
switch (a) {
case 'for': el.htmlFor = attr[a]; break;
case 'class': el.className = attr[a]; break;
case 'style': TDOM.setStyles(el, attr[a]); break;
default: el.setAttribute(a, attr[a]);
}
}
};
TDOM.setText = function(el, text) {
var node = node.nodeType == TDOM.NodeType.TEXT ? el : el.firstChild;
if (node && node.nodeType == TDOM.NodeType.TEXT) {
node.data = text;
} else {
el.appendChild(document.createTextNode(text));
}
}

TDOM.contains = function(parent, child, stopat) {
  if (parent == child) {
    return true;
  } else
  // IE and Safari
  if (parent.contains) {
    return parent.contains(child);
  } else
  // W3C DOM Level 3
  if (parent.compareDocumentPosition) {
    return !!(parent.compareDocumentPosition(child) & 16);
  // Others
  } else {
    stopat = stopat || TDOM.getDocument();
    while (child && stopat != child && parent != child) {
      child = child.parentNode;
    }
    return child == parent;
  }
};

TDOM.getText = function(el) {
var node = node.nodeType == TDOM.NodeType.TEXT ? el : el.firstChild;
return node && node.nodeType == TDOM.NodeType.TEXT ? node.data = text : '';
}
TDOM.matchSize = function(rec, el) {
rec.width -= parseInt(TDOM.getStyle(el,'paddingLeft'));
rec.width -= parseInt(TDOM.getStyle(el,'paddingRight'));
rec.width -= parseInt(TDOM.getStyle(el,'borderLeftWidth'));
rec.width -= parseInt(TDOM.getStyle(el,'borderRightWidth'));
rec.height -= parseInt(TDOM.getStyle(el,'paddingTop'));
rec.height -= parseInt(TDOM.getStyle(el,'paddingBottom'));
rec.height -= parseInt(TDOM.getStyle(el,'borderTopWidth'));
rec.height -= parseInt(TDOM.getStyle(el,'borderBottomWidth'));
return rec;
};
TDOM.toLocalCoordinates = function(p, el) {
var parent = TDOM.getElement(el);
do {
parent = TDOM.resolveNode(parent.parentNode,'parentNode',function(n) { return n.nodeType == TDOM.NodeType.ELEMENT && TDOM.getStyle(n,'position') != 'static'; });
if (parent) {
var point = TDOM.getPos(parent);
p.top -= point.top;
p.left -= point.left;
if (!TUserAgent.WEBKIT || TDOM.getStyle(el,'position') != 'fixed') {
var bt = parseInt(TDOM.getStyle(parent,'borderTopWidth'));
var bl = parseInt(TDOM.getStyle(parent,'borderLeftWidth'));
p.top -= isNaN(bt) ? 0 : bt;
p.left -= isNaN(bl) ? 0 : bl;
}
}
} while(parent);
return p;
};
TDOM.getSize = function(el, forceVisible) {
el = TDOM.getElement(el);
forceVisible !== false && TDOM.ensureVisible(el);
var w = el.offsetWidth;
var h = el.offsetHeight;
forceVisible !== false && TDOM.restoreVisible(el);
return new TRect(0, 0, Math.round(w), Math.round(h));
};
TDOM.getPos = function(el, forceVisible, toLocalCoordinates) {
el = TDOM.getElement(el);
var doc = TDOM.getDocument(el), viewport = TDOM.getRootNode(doc), point = new TPoint();
if (el == viewport) { return point; }
var scroll = TDOM.getDocumentScroll(doc);
forceVisible !== false && TDOM.ensureVisible(el);
if (el.getBoundingClientRect) {
var box = el.getBoundingClientRect();
point.top = box.top + scroll.top;
point.left = box.left + scroll.left;
if (TUserAgent.IE) { point.left -= 2; point.top -= 2; }
} else {
var parent = el;
do {
point.top += parent.offsetTop;
point.left += parent.offsetLeft;
if (parent != el) {
point.top += parent.clientTop || 0;
point.left += parent.clientLeft || 0;
}
if (TDOM.getStyle(parent,'position') == "fixed") {
point.top += scroll.top;
point.left += scroll.left;
break;
}
parent = parent.offsetParent;
} while (parent);
parent = el.parentNode;
while (parent && parent != doc.body) {
point.top -= parent.scrollTop;
point.left -= parent.scrollLeft;
parent = parent.parentNode;
}
}
toLocalCoordinates !== false && (point = TDOM.toLocalCoordinates(point,el));
forceVisible !== false && TDOM.restoreVisible(el);
return point;
};
TDOM.getBounds = function(el, forceVisible, toLocalCoordinates) {
el = TDOM.getElement(el);
forceVisible !== false && TDOM.ensureVisible(el);
var rec = TDOM.getSize(el, false), pos = TDOM.getPos(el, false, toLocalCoordinates);
rec.top = pos.top; rec.left = pos.left;
forceVisible !== false && TDOM.restoreVisible(el);
return rec;
};
TDOM.getDocumentScroll = function(node) {
var doc = TDOM.getDocument(node);
node = TDOM.getRootNode(node);
return new TPoint(Math.max(node.scrollTop,doc.body.scrollTop), Math.max(node.scrollLeft,doc.body.scrollLeft));
};
TDOM.getDocumentSize = function(node) {
var v = TDOM.getRootNode(node), s = TDOM.getViewportSize(node);
return new TRect(0,0,Math.max(v.scrollWidth, s.width), Math.max(v.scrollHeight, s.height));
};
TDOM.getViewportSize = function(node) {
var w = 0, h = 0, win = TDOM.getWindow(node);
if (typeof win.innerWidth != 'undefined') {
w = win.innerWidth;
h = win.innerHeight;
} else {
node = TDOM.getRootNode(node);
w = node.clientWidth;
h = node.clientHeight;
}
return new TRect(0,0,w,h);
};
TDOM.getViewportBounds = function(node) {
var pos = TDOM.getDocumentScroll(node), rec = TDOM.getViewportSize(node);
rec.top = pos.top; rec.left = pos.left;
return rec;
};
TDOM.align = function(el,torec,alignment,fixposition) {
var t=0, l=0, rec1 = TDOM.getBounds(el);
switch (alignment) {
case 'lt': t=torec.top; l=torec.left-rec1.width; break;
case 'lb': t=torec.top+torec.height-rec1.height; l=torec.left-rec1.width; break;
case 'lm': t=Math.round(torec.top+(torec.height/2)-(rec1.height/2)); l=torec.left-rec1.width; break;
case 'tl': t=torec.top-rec1.height; l=torec.left; break;
case 'tr': t=torec.top-rec1.height; l=torec.left+torec.width-rec1.width; break;
case 'tm': t=torec.top-rec1.height; l=Math.round(torec.left+(torec.width/2)-(rec1.width/2)); break;
case 'rt': t=torec.top; l=torec.left+torec.width; break;
case 'rb': t=torec.top+torec.height-rec1.height; l=torec.left+torec.width; break;
case 'rm': t=Math.round(torec.top+(torec.height/2)-(rec1.height/2)); l=torec.left+torec.width; break;
case 'bl': t=torec.top+torec.height; l=torec.left; break;
case 'br': t=torec.top+torec.height; l=torec.left+torec.width-rec1.width; break;
case 'bm': t=torec.top+torec.height; l=Math.round(torec.left+(torec.width/2)-(rec1.width/2)); break;
case 'tlc': case 'ltc': t=torec.top-rec1.height; l=torec.left-rec1.width; break;
case 'blc': case 'lbc': t=torec.top+torec.height; l=torec.left-rec1.width; break;
case 'trc': case 'rtc': t=torec.top-rec1.height; l=torec.left+torec.width; break;
case 'brc': default:    t=torec.top+torec.height; l=torec.left+torec.width; break;
}
if (fixposition !== false) {
var rec2 = TDOM.getViewportBounds(el);
rec2 = TDOM.toLocalCoordinates(rec2,el);
if (t+rec1.height>rec2.top+rec2.height) { t=torec.top-rec1.height; }
if (t<rec2.top) { t=torec.top+torec.height; }
if (l+rec1.width>rec2.left+rec2.width-20) { l=alignment.substring(1,2) == 'm' ? rec2.left+rec2.width-rec1.width-20 : torec.left-rec1.width; }
if (l<rec2.left) { l=alignment.substring(1,2) == 'm' ? rec2.left : torec.left+torec.width; }
}
var point = new TPoint(t,l);
el.style.top = point.top+'px';
el.style.left = point.left+'px';
return point;
};
TDOM.hasClass = function(el,value) {
el = TDOM.getElement(el);
var re = new RegExp('(^|\\s+)' + value + '(\\s+|$)');
return el && re.test(el.className);
};
TDOM.addClass = function(el,value) {
el = TDOM.getElement(el);
if (TDOM.hasClass(el,value) || !el) return;
if (!el.className) {
el.className = value;
} else {
el.className = [el.className.trim(), value].join(' ');
}
};
TDOM.removeClass = function(el,value) {
el = TDOM.getElement(el);
var re = new RegExp('(^|\\s+)?' + value + '(\\s+|$)?','g');
el && (el.className = el.className.replace(re,' ').trim());
};
TDOM.toggleClass = function(el, value) {
el = TDOM.getElement(el);
var set = !TDOM.hasClass(el,value);
TDOM[set ? 'addClass' : 'removeClass'](el,value);
};
TDOM.swapClass = function(el, class1, class2) {
el = TDOM.getElement(el);
if (!TDOM.hasClass(el, class1)) {
TDOM.addClass(class2);
} else {
var re = new RegExp('(^|\\s+)?' + class1 + '(\\s+|$)?','g');
el.className = el.className.replace(re,class2).trim();
}
};
TDOM.getStyle = function(el, attr) {
el = TDOM.getElement(el);
var doc = TDOM.getDocument(el);
if (doc.defaultView && doc.defaultView.getComputedStyle) {
var styles = doc.defaultView.getComputedStyle(el, "");
if (styles) {
if (attr == 'float') {
attr = 'cssFloat';
} else
if (attr == 'opacity') {
attr = "opacity" in styles ? "opacity" : ("MozOpacity" in styles ? "MozOpacity" : ("KhtmlOpacity" in styles ? "KhtmlOpacity" : attr));
}
return styles[attr];
}
} else
if (el.currentStyle) {
if (attr == 'opacity' && el.filters) {
var val=100;
try {
val = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;
} catch(e) {
try {
val = el.filters('alpha').opacity;
} catch(e) { }
}
return val/100;
}
attr = attr == 'float' ? 'styleFloat' : attr;
return el.currentStyle[attr];
}
return el.style[attr];
};
TDOM.setStyle = function(el, attr, value) {
el = TDOM.getElement(el);
if (attr == 'opacity') {
if (value < 0 || value > 1) {
return;
}
if ("opacity" in el.style) {
el.style.opacity = value;
} else
if ("MozOpacity" in el.style) {
el.style.MozOpacity = value;
} else
if ("KhtmlOpacity" in el.style) {
el.style.KhtmlOpacity = value;
} else
if ("filter" in el.style) {
if (value == 1) {
el.style.filter = "";
} else {
el.style.filter = "alpha(opacity=" + (value * 100) + ")";
}
}
return;
}
if (attr == 'float') {
attr = TUserAgent.IE ? 'styleFloat' : 'cssFloat';
}
el.style[attr] = value;
};
TDOM.setStyles = function(el, attrs) {
el = TDOM.getElement(el);
attrs = attrs.split(/\s*?;\s*?/);
for (var i=0,l=attrs.length; i<l; i++) {
attr = attrs[i];
attr = attr.split(/\s*?:\s*?/);
TDOM.setStyle(el,attr[0].toCamel().trim(),attr[1].trim());
}
};
TDOM.setUnselectable = function(el, value, recursion) {
el = TDOM.getElement(el);
if (TUserAgent.GECKO) {
el.style['MozUserSelect'] = value ? 'none' : '';
} else
if (TUserAgent.WEBKIT) {
el.style['WebkitUserSelect'] = value ? 'none' : '';
} else {
value ? el.setAttribute("unselectable", "on") : el.removeAttribute("unselectable");
}
if (recursion !== false) {
el = TDOM.firstChild(el);
while (el) {
TDOM.setUnselectable(el, value, recursion);
el = TDOM.nextElement(el);
}
}
}
TDOM.isVisible = function(node) {
return TDOM.firstHiddenParent(node) == null;
};
TDOM.ensureVisible = function(el) {
el = TDOM.getElement(el);
var id = TDOM.getUniqueId(el);
if (id && !TDOM._visibleStack[id]) {
var parent = TDOM.firstHiddenParent(el);
if (parent) {
TDOM._visibleStack[id] = [];
while (parent) {
TDOM._visibleStack[id].push([parent, parent.style.display, parent.style.position, parent.style.visibility]);
parent.style.visibility = "hidden";
parent.style.position = "absolute";
parent.style.display = "block";
parent = TDOM.firstHiddenParent(parent.parentNode);
}
}
}
}
TDOM.restoreVisible = function(el) {
el = TDOM.getElement(el);
var id = TDOM.getUniqueId(el);
if (id && TDOM._visibleStack[id]) {
var parent = TDOM._visibleStack[id].shift();
while (parent) {
parent[0].style.display = parent[1];
parent[0].style.position = parent[2];
parent[0].style.visibility = parent[3];
parent = TDOM._visibleStack[id].shift();
}
}
TDOM._visibleStack[id] = false;
}
TSelection = {};
TSelection.set = function(el, start, length) {
if (TDOM.isVisible(el)) {
length = length || 0;
var doc = TDOM.getDocument();
if (typeof el.selectionStart != 'undefined') {
el.selectionStart = start;
el.selectionEnd = start+length;
} else
if (el.createTextRange) {
var range = el.createTextRange();
range.collapse(true);
range.moveStart("character", start);
range.moveEnd("character", length);
range.select();
}
}
}
TSelection.get = function(el) {
var html = '';
var text = '';
var target = null;
var start = count = 0;
if (!el) { return; }
if (el.selectionStart) {
target = el;
start = el.selectionStart;
count = el.selectionEnd - start;
if (el.value) {
text = el.value.substr(start, count);
html = text;
}
} else
if (window.getSelection) {
text = window.getSelection();
if (text != '') {
if (text.getRangeAt) {
var range = text.getRangeAt(0);
} else {
var range = document.createRange();
range.setStart(text.anchorNode, text.anchorOffset);
range.setEnd(text.focusNode, text.focusOffset);
}
text = text.toString();
var div = document.createElement('div');
div.appendChild(range.cloneContents());
html = div.innerHTML;
if (html.indexOf('<') === 0) {
var regex = new RegExp(/<.*?>([\s\S]*)<\/.*>/);
regex.exec(html);
html = RegExp.$1;
}
target = TDOM.resolveNode(range.commonAncestorContainer, 'parentNode');
count = text.length;
}
} else
if (document.selection) {
if (document.selection.type == 'Text' || el) {
var range = document.selection.createRange();
if (range) {
text = range.text;
html = range.htmlText;
count = text.length;
target = range.parentElement();
var copy = range.duplicate();
copy.expand('textedit');
if (el != target) {
copy.moveToElementText(target);
}
copy.setEndPoint('EndToEnd',range);
start = copy.text.length - count;
}
}
}
return {start:start, length:count, target:target, text:text, html:html};
}
var TEventDispatcher = function () { };
TEventDispatcher.prototype.isDispatcher = true;
TEventDispatcher.prototype.addEventListener = function (type, callback, scope) {
TEvents.listen(this, type, callback, scope);
};
TEventDispatcher.prototype.unlisten = function (type, callback, scope) {
TEvents.unlisten(this, type, callback, scope);
};
TEventDispatcher.prototype.dispatch = function (type) {
var args = Array.prototype.slice.call(arguments,0);
args.unshift(this);
return TEvents.dispatch.apply(this, args);
};
TEventDispatcher.prototype.free = function () {
TEvents.unlistenAll(this);
};
var TEvent = function (type, target) {
this.type = type;
this.target = target;
this.currentTarget = target;
};
TEvent.prototype.stopPropagation = function() { };
TEvent.prototype.preventDefault = function() { };
TEvent.prototype.free = function() {
this.type = null;
this.target = null;
this.currentTarget = null
};
TEvents = function() {};
TEvents.nextIndex = 1;
TEvents.listeners = {};
TEvents._items = [];
TEvents.getId = function (obj) {
var prop = "dispatcher_unique_index";
if (!obj) { return; }
if (obj.hasOwnProperty && obj.hasOwnProperty(prop)) {
return obj[prop];
}
if (!obj[prop]) {
obj[prop] = 'e' + TEvents.nextIndex++;
}
return obj[prop];
};
TEvents.getListener = function (src, type, callback, scope) {
src = TDOM.getElement(src);
var id = TEvents.getId(src);
var obj = src.isDispatcher ? 'dispatcher' : 'element';
var list = TEvents.listeners;
if (list[id] && list[id][type] && list[id][type][obj]) {
list = list[id][type][obj];
for (var i = 0, c = list.length; i < c; i++) {
if (list[i].callback == callback && list[i].scope == scope) {
return list[i];
}
}
}
return null;
};
TEvents.listen = function (src, type, callback, scope) {
src = TDOM.getElement(src);
if (!src || !callback || !callback.call) { return false; }
scope = scope ? scope : src;
var l = TEvents.getListener(src, type, callback, scope);
if (!l) {
var id = TEvents.getId(src);
var obj = src.isDispatcher ? 'dispatcher' : 'element';
var list = TEvents.listeners;
list[id] = list[id] || {};
list[id][type] = list[id][type] || {};
list[id][type][obj] = list[id][type][obj] || [];
list = list[id][type][obj];
l = {src:src, type:type, callback:callback, scope:scope};
l.wrapper = function (e) {
e = e || window.event;
var event = new TDOMEvent(e, l.src);
var result = l.callback.call(l.scope, event) !== false;
event.free();
return result;
};
list.push(l);
if (src.addEventListener) {
if (!src.isDispatcher) {
src.addEventListener(type, l.wrapper, false);
}
} else
if (src.attachEvent) {
src.attachEvent("on" + type, l.wrapper);
} else {
return false;
}
}
return true;
};
TEvents.unlisten = function(src, type, callback, scope) {
src = TDOM.getElement(src);
if (!src) { return; }
var l = null;
var id = TEvents.getId(src);
var obj = src.isDispatcher ? 'dispatcher' : 'element';
var list = TEvents.listeners;
scope = scope ? scope : src;
if (list[id] && list[id][type] && list[id][type][obj]) {
list = list[id][type][obj];
for (var i = 0, c = list.length; i < c; i++) {
if (list[i].callback == callback && list[i].scope == scope) {
l = list[i];
list.splice(i, 1);
break;
}
}
}
if (l) {
if (src.removeEventListener) {
if (!src.isDispatcher) {
src.removeEventListener(type, l.wrapper, false);
}
} else
if (src.detachEvent) {
src.detachEvent("on" + type, l.wrapper);
}
l.wrapper = null;
}
};
TEvents.unlistenAll = function(src) {
src = TDOM.getElement(src);
var id = TEvents.getId(src);
if (TEvents.listeners[id]) {
for (var type in TEvents.listeners[id]) {
TEvents.unlistenType(src, type, 'dispatcher');
TEvents.unlistenType(src, type, 'element');
delete TEvents.listeners[id][type];
}
delete TEvents.listeners[id];
}
};
TEvents.unlistenType = function (src, type, obj) {
src = TDOM.getElement(src);
var id = TEvents.getId(src);
if (TEvents.listeners[id] && TEvents.listeners[id][type] && TEvents.listeners[id][type][obj]) {
var l = TEvents.listeners[id][type][obj][0];
while (l) {
TEvents.unlisten(l.src, l.type, l.callback, l.scope);
l = TEvents.listeners[id][type][obj][0];
}
delete TEvents.listeners[id][type][obj];
}
};
TEvents.dispatch = function (src, e) {
src = TDOM.getElement(src);
var owner = typeof e == 'string';
if (owner) { e = new TEvent(e, src); }
var id = TEvents.getId(src);
var result = true;
var list = TEvents.listeners;
if (list[id] && list[id][e.type] && list[id][e.type]['dispatcher']) {
list = list[id][e.type]['dispatcher'];
var args = Array.prototype.slice.call(arguments,2);
args.unshift(e);
for (var i=0, c=list.length; i < c; i++) {
result = result && list[i].callback.apply(list[i].scope, args) !== false;
}
}
owner && e.free();
return result;
};
TEvents.listen(window, 'load', TDOM._doOnLoad);
TDOMEvent = function (e, target) {
TEvent.prototype.constructor.call(this, e.type, target);
this.event = e;
target = e.target || e.srcElement;
this.target = TDOM.resolveTextNode(target);
this.relatedTarget = e.relatedTarget;
if (!this.relatedTarget) {
if (this.type == "mouseover") {
this.relatedTarget = e.fromElement;
} else
if (this.type == "mouseout") {
this.relatedTarget = e.toElement;
}
}
this.keyCode = e.keyCode || e.which || 0;
if (TUserAgent.FIREFOX && (this.type == "keyup" || this.type == "keydown")) {
this.charCode = (this.type == "keypress" ? e.keyCode : 0);
} else {
this.charCode = e.charCode || (this.type == "keypress" ? e.keyCode : 0);
}
this.ctrlKey = e.ctrlKey;
this.altKey = e.altKey;
this.shiftKey = e.shiftKey;
this.metaKey = e.metaKey;
this.screenX = e.screenX || 0;
this.screenY = e.screenY || 0;
this.offsetX = typeof e.layerX  != "undefined" ? e.layerX  : e.offsetX;
this.offsetY = typeof e.layerY  != "undefined" ? e.layerY  : e.offsetY;
this.clientX = typeof e.clientX != "undefined" ? e.clientX : e.pageX;
this.clientY = typeof e.clientY != "undefined" ? e.clientY : e.pageY;
this.buttons = TUserAgent.IE ? { left: e.button & 1, middle: e.button & 4, right: e.button & 2 } : { left: e.button == 0, middle: e.button == 1, right: e.which ? e.which == 3 : e.button == 2 };
};
TDOMEvent.inherits(TEvent);
TDOMEvent.prototype.stopPropagation = function () {
if(this.event.stopPropagation){
this.event.stopPropagation();
}else{
this.event.cancelBubble = true;
}
};
TDOMEvent.prototype.preventDefault = function () {
if(this.event.preventDefault){
this.event.preventDefault();
}else{
this.event.returnValue = false;
}
};
TDOMEvent.prototype.free = function() {
TEvent.prototype.free.call(this);
this.event = this.relatedTarget = this.button = null;
}
var THint = function() { }
THint.count = 0;
THint.cache = [];
THint.current = -1;
THint.currentElement = null;
THint.inner = null;
THint.iframe = null;
THint.container = null;
THint.timer = 0;
THint.over = false;
THint.setup = function() {
THint.container = document.createElement('div');
THint.container.className = 'THint';
THint.container.style.position = 'absolute';
THint.container.style.display = 'none';
THint.container.style.zIndex = 99899;
THint.inner = document.createElement('div');
THint.inner.className = 'inner';
TEvents.listen(THint.container,'mouseout',THint.hide);
TEvents.listen(THint.container,'mouseover',function() { clearTimeout(THint.timer); });
if (TUserAgent.IE && TUserAgent.VERSION < 7) {
THint.iframe = document.createElement("iframe");
THint.iframe.src = "javascript:false;";
THint.iframe.style.position = 'absolute';
THint.iframe.style.display = 'none';
THint.iframe.style.zIndex = 99898;
TDOM.setStyle(THint.iframe, "opacity", "0");
TEvents.listen(THint.iframe,'mouseout',THint.hide);
TEvents.listen(THint.iframe,'mouseover',function() { clearTimeout(THint.timer); });
document.body.appendChild(THint.iframe);
}
THint.container.appendChild(THint.inner);
document.body.appendChild(THint.container);
}
TDOM.onLoad(THint.setup);
THint.hide = function() {
if (THint.timer) {
clearTimeout(THint.timer);
THint.timer = null;
}
THint.over = false;
if (!THint.container) { return; }
THint.current = -1;
THint.currentElement = null;
THint.iframe && (THint.iframe.style.display = 'none');
THint.timer = setTimeout(function() { THint.container.style.display = 'none'; },100);
}
THint.show = function(el,html,pos) {
THint.over = true;
if (!THint.container) { return; }
if (THint.timer) {
clearTimeout(THint.timer);
THint.timer = null;
}
if (!el['thint_unique_identifier']) {
el['thint_unique_identifier'] = THint.count++;
}
THint.current = el['thint_unique_identifier'];
THint.currentElement = el;
THint.inner.innerHTML = html;
var rec = TDOM.getBounds(THint.container);
TDOM.align(THint.container,TDOM.getBounds(el,true,false),pos);
if (THint.iframe) {
rec = TDOM.getBounds(THint.container);
THint.iframe.style.width = rec.width + 6 + 'px';
THint.iframe.style.height = rec.height + 6 + 'px';
THint.iframe.style.top = rec.top - 4 + 'px';
THint.iframe.style.left = rec.left - 4 + 'px';
THint.iframe.style.display = 'block';
}
var This = this;
THint.timer = setTimeout(function() {
THint.over && (THint.container.style.display = 'block');
}, 250);
}
THint.showURL = function(url,el,pos,wm,cache) {
THint.over = true;
clearTimeout(THint.timer);
cache = typeof cache == 'undefined' ? 1 : cache;
if (!el['thint_unique_identifier']) {
el['thint_unique_identifier'] = THint.count++;
}
if (THint.current == el['thint_unique_identifier']) {
return;
}
if (cache && THint.cache[el['thint_unique_identifier']]) {
THint.show(el,THint.cache[el['thint_unique_identifier']],pos);
} else {
el.id = el.id ? el.id : 'THintID'+el['thint_unique_identifier'];
wm = wm ? wm : 'Obteniendo información<br />Por favor espere...';
THint.show(el,wm,pos);
THttp.send(url,THint.showURLCallback,null,'THintPos='+pos+'&THintElement='+el.id);
}
}
THint.showURLCallback = function(e) {
var values = {};
var params = e.target.params;
for (var i=0,l=params.length; i<l; i++) {
var p = params[i].split('=');
values[p[0]] = p[1];
}
var el = TDOM.getElement(values['THintElement']);
if (!el) { return; }
var html = e.target.toString();
if (html.match(/<hint>([\s\S]*?)<\/hint>/ig)) {
THint.cache[el['thint_unique_identifier']] = RegExp.$1;
if (el['thint_unique_identifier'] == THint.current) {
THint.over && THint.show(el,RegExp.$1,values['THintPos']);
}
} else {
THint.over && THint.show(el,'<h1>Error:</h1><p>Unknown response from server</p>',values['THintPos']);
}
}
var TModalWin = function(clickclose) {
this.modal = null;
this.color = '#000';
this.opacity = 0.8;
this.content = null;
this.opened = false;
this.iframe = null;
this.back = document.createElement('div');
this.back.style.zIndex = TModalWin.nextZIndex++;
this.back.style.display = 'none';
this.back.style.position = 'absolute';
this.back.setAttribute('tabIndex',-1);
this.back.hideFocus = true;
this.back.style.outline = 'none';
if (clickclose) { TEvents.listen(this.back, 'click', this.close, this); }
this.front = document.createElement('div');
this.front.style.zIndex = TModalWin.nextZIndex++;
this.front.style.display = 'none';
this.front.style.position = 'absolute';
this.front.style.textAlign = 'center';
TDOM.onLoad(function() {


if (document.body && document.body.firstChild) {
  document.body.insertBefore(this.back, document.body.firstChild);
  document.body.insertBefore(this.front, document.body.firstChild);
} else {
  document.body.appendChild(this.back);
  document.body.appendChild(this.front);
}


if (TUserAgent.IE && TUserAgent.VERSION < 7) {
this.iframe = document.createElement('iframe');
this.iframe.src = "javascript:false;";
this.iframe.style.position = 'absolute';
this.iframe.style.display = 'none';
this.iframe.style.zIndex = 99900;
TDOM.setStyle(this.iframe, "opacity", "0");

if (document.body && document.body.firstChild) {
  document.body.insertBefore(this.iframe, document.body.firstChild);
} else {
  document.body.appendChild(this.iframe);
}

}
}, this);
};
TModalWin.nextZIndex = 99990;
TModalWin.prototype.show = function(content) {
if (this.content && this.front) {
this.front.innerHTML = '';
this.content = null;
}
if (typeof content == "string") {
this.content = document.createElement('div');
this.content.innerHTML = content;
} else {
this.content = content;
}
this.open(this.modal);
}
TModalWin.prototype.open = function(modal) {
this.modal = modal;
if (!this.content) { return; }
this.content.style.display = 'block';
this.resize();
if (!this.modal && !this.opened) {
TEvents.listen(window, 'resize', this.resize, this);
TEvents.listen(window, 'scroll', this.resize, this);
}
this.opened = true;
}
TModalWin.prototype.resize = function() {
if (this.modal) {
var rec2 = TDOM.getBounds(this.modal, true);
if (TUserAgent.IE) { rec2.top -= 2; rec2.left -= 2; }
} else {
var size = TDOM.getDocumentSize();
var rec2 = {top:0, left:0, width:'100%', height:size.height};
}
this.front.style.top = '';
this.front.style.left = '';
this.front.style.width = '';
this.front.style.height = '';
this.front.appendChild(this.content);
var rec1 = TDOM.getBounds(this.front, true);
if (this.modal) {
this.front.style.top = rec2.top + Math.round(rec2.height / 2) - Math.round(rec1.height / 2) + 'px';
this.front.style.left = rec2.left + Math.round(rec2.width / 2) - Math.round(rec1.width / 2) + 'px';
} else {
var rec3 = TDOM.getViewportBounds();
this.front.style.top = rec3.top + Math.round(rec3.height / 2) - Math.round(rec1.height / 2) + 'px';
this.front.style.left = rec3.left + Math.round(rec3.width / 2) - Math.round(rec1.width / 2) + 'px';
}
this.back.style.top = rec2.top + 'px';
this.back.style.left  = rec2.left + 'px';
this.back.style.height = rec2.height + 'px';
this.back.style.width = typeof rec2.width == "string" ? rec2.width : rec2.width + 'px';
TDOM.setStyle(this.back, 'opacity', this.opacity);
TDOM.setStyle(this.back, 'backgroundColor', this.color);
this.back.style.display = 'block';
this.front.style.display = 'block';
if (this.iframe != null) {
this.iframe.style.display = 'block';
this.iframe.style.top = this.back.style.top;
this.iframe.style.left = this.back.style.left;
this.iframe.style.width = this.back.style.width;
this.iframe.style.height = this.back.style.height;
}
}
TModalWin.prototype.close = function() {
this.back.style.display = 'none';
this.front.style.display = 'none';
this.iframe != null && (this.iframe.style.display = 'none');
TEvents.unlisten(window, 'resize', this.resize, this);
TEvents.unlisten(window, 'scroll', this.resize, this);
this.opened = false;
}
TPopup = function(name, width, height, top, left) {
this.id        = name;
this.top       = !top ? -1 : top;
this.left      = !left ? -1 : left;
this.width     = !width ? 200 : width;
this.height    = !height ? 200 : height;
this.scrolls   = false;
this.toolbar   = false;
this.statusbar = false;
this.resizable = false;
this.opened    = false;
this.handler   = null;
this.open = function(url) {
this.top  = this.top < 0 ? (screen.height - this.height - 40) / 2 : this.top;
this.left = this.left < 0 ? (screen.width - this.width - 25) / 2 : this.left;
var settings  ='width='+this.width+',';
settings +='height='+this.height+',';
settings +='top='+this.top+',';
settings +='left='+this.left+',';
settings +='status='+(this.statusbar ? 1 : 0)+',';
settings +='toolbar='+(this.toolbar ? 1 : 0)+',';
settings +='resizable='+(this.resizable ? 1 : 0)+',';
settings +='scrollbars='+(this.scrolls ? 1 : 0);
this.handler = window.open(url,this.id,settings);
if (this.handler) {
this.handler.focus();
}
this.opened = true;
}
this.close = function() {
if (this.opened) {
this.handler.close();
this.opened = false;
}
}
this.showModal = function(url) {
this.open(url);
TEvents.listen(this.handler.opener,'focus',this._keepModal,this);
}
this._keepModal = function(win,e) {
try {
TEvents.unlisten(this.handler.opener,'focus',this._keepModal);
this.handler.close();
} catch (e) { }
}
this.minimize = function minimize(){
this.win.blur();
}
}
TPopup.New = function(name,width,height,src,scrolls,resizable,modal) {
var popup = new TPopup(name);
popup.scrolls = scrolls;
popup.resizable = resizable;
if (screen.height - 150 < height) {
height = screen.height - 150;
popup.scrolls = true;
}
if (screen.width - 150 < width) {
width = screen.width - 150;
popup.scrolls = true;
}
popup.width = width;
popup.height = height;
if (modal) {
popup.showModal(src);
} else {
popup.open(src);
}
return popup;
}
TCalendar = function (container) {
this._inner = null;
this._footer = null;
this._slider = null;
this._iframe = null;
this._months = [];
this._bindings = [];
this._container = TDOM.getElement(container);
this._activeInput = null;
this._overCalendar = false;
this._selectRange = false;
this._setupCalendar();
this.current = { year:0, month:0, count:0, startday:0 };
this.selected = { from:null, to:null };
this.rangeSelect = false;
this.forceSingleSelect = false;
this.foretime = true;
this._container.style.zIndex = 999999;
if (TUserAgent.IE && TUserAgent.VERSION < 7) {
TDOM.onLoad(this.createIframe,this);
}
};
TCalendar.inherits(TEventDispatcher);
TCalendar.ownAttribute = 'calendar_bind_id';
TCalendar.prototype.createIframe = function() {
this._iframe = document.createElement("iframe");
this._iframe.src = "javascript:false;";
this._iframe.style.zIndex = 1;
TDOM.setStyle(this._iframe, "opacity", "0");
this._container.appendChild(this._iframe);
}
TCalendar.prototype.update = function() {
var width = 0, height = 0;
var date = new Date(this.current.year, this.current.month-Math.floor((this.current.count-1)/2)-1, 1);
this._months = [];
this._slider.style.left = '0px';
while (this._slider.childNodes.length > 0) {
this._slider.removeChild(this._slider.childNodes[0]);
}
for (var i=0; i < this.current.count; i++) {
var cal = this._createCalendar(date.getFullYear(),date.getMonth()+1,width);
this._months.push({cal:cal, offset:width});
width += cal.size.width;
height = cal.size.height > height ? cal.size.height : height;
date.setMonth(date.getMonth()+1);
}
this._inner.style.width = width + 'px';
this._container.style.width = width + 'px';
this._footer.style.paddingTop = height + 'px';
if (this._iframe) {
this._iframe.style.width = (width+3) + 'px';
this._iframe.style.height = height + 'px';
}
}
TCalendar.prototype.show = function(y,m,count,startday) {
y = parseInt(y); m = parseInt(m); count = count || 1;
if (!isNaN(y) && !isNaN(m)) {
var date = new Date(y, m-1, 1);
m = date.getMonth()+1;
y = date.getFullYear();
if (y != this.current.year || m != this.current.month || this.current.count != count) {
this.current.year = y;
this.current.month = m;
this.current.count = count;
this.current.startday = startday;
this.update();
}
}
}
TCalendar.prototype.select = function(from,to) {

if (typeof from == 'string') {
from = this._parseDate(from);
}
if (typeof to == 'string') {
to = this._parseDate(to);
}
this.selected.from = from;
this.selected.to = to;
for (var i=0; i < this._months.length; i++) {
this._months[i].cal.select(from, to || from);
}
}
TCalendar.prototype.showNextMonth = function(e) {
var last = this._months[this._months.length-1], first = this._months.shift();
var m = (last.cal.m%12)+1, y = last.cal.y+(m==1?1:0), left = last.offset+last.cal.size.width;
var cal = this._createCalendar(y,m,left);
this._months.push({cal:cal, offset:left});
this.current.year = y;
this.current.month = m;
this._slider.style.left = parseInt(this._slider.style.left) - cal.size.width + 'px';
this._slider.removeChild(first.cal.container);
}
TCalendar.prototype.showPrevMonth = function(e) {
var first = this._months[0], last = this._months.pop();
var m = first.cal.m-1<1?12:first.cal.m-1, y = first.cal.y-(m==12?1:0), left = first.offset-first.cal.size.width;
var cal = this._createCalendar(y,m,left);
if (first.offset-cal.size.width != left) { left = first.offset-cal.size.width; }
cal.container.style.left = left + 'px';
this._months.unshift({cal:cal, offset:left});
this.current.year = y;
this.current.month = m;
this._slider.style.left = parseInt(this._slider.style.left) + cal.size.width + 'px';
this._slider.removeChild(last.cal.container);
}
TCalendar.prototype.hide = function() {
this._activeInput = null;
this._overCalendar = false;
this._container.style.display = 'none';
}
TCalendar.prototype.bind = function(input1, input2, pages, position, startday) {
pages = pages || 1;
startday = startday || 0;
input1 = TDOM.getElement(input1);
input2 = TDOM.getElement(input2);
if (!input1 || input1.nodeName.toLowerCase() != 'input' || input1.type.toLowerCase() != 'text') {
//alert("You can only bind calendar to INPUT elements of type TEXT");
return;
}
input1[TCalendar.ownAttribute] = this._bindings.length;
TEvents.listen(input1, 'blur', this._hideBinded, this);
TEvents.listen(input1, 'focus', this._showBinded, this);
if (input2) {
input2[TCalendar.ownAttribute] = this._bindings.length;
TEvents.listen(input2, 'blur', this._hideBinded, this);
TEvents.listen(input2, 'focus', this._showBinded, this);
}
this._bindings.push([input1,input2,pages,position || 'bm',startday]);
}
TCalendar.prototype._showBinded = function(e) {
if (this._overCalendar) { return; }
this._activeInput = e.currentTarget;
var bind = this._bindings[e.currentTarget[TCalendar.ownAttribute]];
if (bind) {
var torec = new TRect();
var rec1 = TDOM.getBounds(bind[0],null,false);
var rec2 = bind[1] ? TDOM.getBounds(bind[1],null,false) : rec1;
var date1 = this._parseDate(bind[0].value);
var date2 = bind[1] ? this._parseDate(bind[1].value) : date1;
torec.top = rec1.top < rec2.top ? rec1.top : rec2.top;
torec.left = rec1.left < rec2.left ? rec1.left : rec2.left;
torec.width = rec1.left < rec2.left ? rec2.left+rec2.width-rec1.left : rec1.left+rec1.width-rec2.left;
torec.height = rec1.top < rec2.top ? rec2.top+rec2.height-rec1.top : rec1.top+rec1.height-rec2.top;
this.select(date1,date2);
if (e.currentTarget == bind[1]) {
this.show(date2.getFullYear(), date2.getMonth()+1, bind[2], bind[4]);
} else {
this.show(date1.getFullYear(), date1.getMonth()+1, bind[2], bind[4]);
}
TDOM.align(this._container, TDOM.toLocalCoordinates(torec,this._container), bind[3]);
this._container.style.display = 'block';
this.rangeSelect = bind[1] != null && !cal.forceSingleSelect;
this._selectRange = e.currentTarget == bind[1];
TDOM[!this._selectRange ? 'addClass' : 'removeClass'](bind[0], 'capturing');
TDOM[ this._selectRange ? 'addClass' : 'removeClass'](bind[1], 'capturing');
if (cal.forceSingleSelect && (this.selected.from != this.selected.to)) {
this.select(this.selected.from,this.selected.from);
}
}
}
TCalendar.prototype._hideBinded = function(e) {
if (!this._overCalendar) {
if (this._activeInput) {
var bind = this._bindings[this._activeInput[TCalendar.ownAttribute]];
TDOM.removeClass(bind[0], 'capturing');
TDOM.removeClass(bind[1], 'capturing');
}
this.hide();
} else {
this._activeInput.focus();
e.preventDefault();
e.stopPropagation();
return false;
}
}
TCalendar.prototype._dateChange = function(e,y,m,d) {
var date = this._parseDate(d+'/'+m+'/'+y);
if (!this.foretime) {
var now = new Date();
now.setHours(0); now.setMinutes(0); now.setSeconds(0); now.setMilliseconds(0);
if (date < now) { return; }
}
if (this._selectRange && this.rangeSelect) {
this._selectRange = false;
if (date < this.selected.from) {
this.select(date, this.selected.from);
} else {
this.select(this.selected.from, date);
}
} else {
this._selectRange = true;
this.select(date, null);
}
var fy = this.selected.from.getFullYear();
var fm = this.selected.from.getMonth()+1;
var fd = this.selected.from.getDate();
var ty = this.selected.to && this.selected.to.getFullYear();
var tm = this.selected.to && this.selected.to.getMonth()+1;
var td = this.selected.to && this.selected.to.getDate();
if (this._activeInput) {
var bind = this._bindings[this._activeInput[TCalendar.ownAttribute]];
if (bind) {
TDOM[!this._selectRange ? 'addClass' : 'removeClass'](bind[0], 'capturing');
bind[0].value = fd.toString().padLeft(2,'0')+'/'+fm.toString().padLeft(2,'0')+'/'+fy;
if (bind[1]) {
TDOM[this._selectRange ? 'addClass' : 'removeClass'](bind[1], 'capturing');
if (this.selected.to) {
bind[1].value = td.toString().padLeft(2,'0')+'/'+tm.toString().padLeft(2,'0')+'/'+ty;
} else {
bind[1].value = fd.toString().padLeft(2,'0')+'/'+fm.toString().padLeft(2,'0')+'/'+fy;
}
}
}
}
this.dispatch('change',fy,fm,fd,ty,tm,td);
}
TCalendar.prototype._createCalendar = function (y,m,pos) {
var div = document.createElement("div");
div.style.position = 'absolute';
div.style.top = '0px';
div.style.left = pos + 'px';
this._slider.appendChild(div);
cal = new TMonthCalendar(div, y, m, this.current.startday);
cal.addEventListener('change',this._dateChange,this);
cal.select(this.selected.from, this.selected.to);
return cal;
}
TCalendar.prototype._setupCalendar = function() {
TDOM.addClass(this._container, 'calendar');
TEvents.listen(this._container,'focus',this._setFocusOut,this);
TEvents.listen(this._container,'mouseup',this._setFocusOut,this);
TEvents.listen(this._container,'mouseover',this._setMouseOver,this);
TEvents.listen(this._container,'mouseout',this._setMouseOut,this);
this._inner = document.createElement('div');
this._inner.style.position = 'relative';
this._inner.style.overflow = 'hidden';
TDOM.addClass(this._inner, 'inner');
this._container.appendChild(this._inner);
this._slider = document.createElement('div');
this._slider.style.position = 'absolute';
this._slider.style.top = '0px';
this._slider.style.left = '0px';
TDOM.addClass(this._slider, 'slider');
this._inner.appendChild(this._slider);
var div = document.createElement('div');
TDOM.addClass(div, 'next');
TEvents.listen(div, 'click', this.showNextMonth, this);
this._container.appendChild(div);
div = document.createElement('div');
TDOM.addClass(div, 'prev');
TEvents.listen(div, 'click', this.showPrevMonth, this);
this._container.appendChild(div);
this._footer = document.createElement('div');
TDOM.addClass(this._footer, 'footer');
this._inner.appendChild(this._footer);
var btn = document.createElement('a');
btn.innerHTML = 'cerrar';
TDOM.addClass(btn, 'close');
TEvents.listen(btn, 'click', this.hide, this);
this._footer.appendChild(btn);
}
TCalendar.prototype._parseDate = function(str) {
var date = new Date();
str = str.split('/');
str[0] = parseInt(str[0],10);
str[1] = parseInt(str[1],10);
str[2] = parseInt(str[2],10);
valid = !isNaN(str[0]) && !isNaN(str[1]) && !isNaN(str[2]);
valid = valid && str[1] <= 12 && str[1] > 0 && str[0] > 0;
if (valid) {
date.setDate(1);
date.setFullYear(str[2]);
date.setMonth(str[1]);
date.setDate(0);
str[0] = str[0] > date.getDate() ? date.getDate() : str[0];
date.setDate(str[0]);
}
return date;
}
TCalendar.prototype._setFocusOut = function(e) {
if (this._activeInput) {
this._activeInput.focus();
}
}
TCalendar.prototype._setMouseOver = function(e) {
this._overCalendar = true;
}
TCalendar.prototype._setMouseOut = function(e) {
if (e.currentTarget == this._container) {
this._overCalendar = false;
}
}
TMonthCalendar = function (container, y, m, startday) {
var now = new Date();
this.m = parseInt(m);
this.y = parseInt(y);
this.m = isNaN(m) ? now.getMonth()+1 : m;
this.y = isNaN(y) ? now.getFullYear() : y;
this.startday = startday || 0;
var date = new Date(this.y,this.m-1,1);
this.day_of_week = date.getDay();
date.setMonth(date.getMonth()+1);
date.setDate(0);
this.days_in_month = date.getDate();
this.selected = {from:-1,to:-1};
this.container = TDOM.getElement(container);
TEvents.listen(this.container,'click',this.dayClick,this);
this.invalidate();
}
TMonthCalendar.inherits(TEventDispatcher);
TMonthCalendar.days = ['Do','Lu','Ma','Mi','Ju','Vi','Sa'];
TMonthCalendar.months = ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];
TMonthCalendar.prototype.select = function(from, to) {
var fromd = -1, tod = -1;
if (from && to) {
if (this.y >= from.getFullYear()) {
if (this.y == from.getFullYear()) {
if (this.m >= from.getMonth()+1) {
fromd = this.m == from.getMonth()+1 ? from.getDate() : 1;
}
} else {
fromd = 1;
}
}
if (this.y <= to.getFullYear()) {
if (this.y == to.getFullYear()) {
if (this.m <= to.getMonth()+1) {
tod = this.m == to.getMonth()+1 ? to.getDate() : this.days_in_month;
}
} else {
tod = this.days_in_month;
}
}
}
fromd < 1 || tod < 1 ? this.clearSelection() : this._setSelected(fromd,tod);
}
TMonthCalendar.prototype.clearSelection = function() {
this._setSelected(-1,-1);
}
TMonthCalendar.prototype._setSelected = function(from, to) {
if (from != this.selected.from || to != this.selected.to) {
this.selected.from = from;
this.selected.to = to;
this.invalidate();
}
}
TMonthCalendar.prototype.getDayCell = function(el) {
while (el && el != this.container) {
if (el.nodeName == 'A') { return el; }
el = el.parentNode;
}
return null;
}
TMonthCalendar.prototype.dayClick = function(e) {
var cell = this.getDayCell(e.target);
if (cell) {
var day = parseInt(cell.innerHTML);
this.dispatch('change',this.y,this.m,day);
}
}
TMonthCalendar.prototype.invalidate = function() {
var now = new Date();
var cal = document.createElement('div');
cal.className = "month y' + this.y + ' m' + this.m + '";
while (this.container.childNodes.length > 0) {
this.container.removeChild(this.container.childNodes[0]);
}
var node = document.createElement('div');
node.className = 'title';
node.appendChild(document.createTextNode(TMonthCalendar.months[this.m-1] + ' ' + this.y));
cal.appendChild(node);
var weeks = document.createElement('div');
weeks.className = 'weeks';
cal.appendChild(weeks);
var week = document.createElement('div');
week.className = 'week w0';
weeks.appendChild(week);
for (var i=0; i < 7; i++) {
node = document.createElement('div');
node.className = 'dayname';
node.appendChild(document.createTextNode(TMonthCalendar.days[(i+this.startday)%7]));
week.appendChild(node);
}
var day = 0;
var dow = this.day_of_week-this.startday;
dow = dow < 0 ? 7+dow : (dow == 0 ? 7 : dow);
for (var w=0; w < 6; w++) {
week = document.createElement('div');
week.className = 'week w'+(w+1);
weeks.appendChild(week);
for (var d=0; d <= 6; d++) {
if (dow > 0 || day >= this.days_in_month) {
node = document.createElement('div');
node.className = 'day empty';
week.appendChild(node);
dow--;
} else {
day++;
var style = ['day'];
if (this.y >= now.getFullYear()) {
if (this.y == now.getFullYear()) {
if (now.getMonth() > this.m-1) {
style.push('past');
} else
if (now.getMonth() == this.m-1) {
if (now.getDate() == day) {
style.push('today');
} else
if (now.getDate() > day) {
style.push('past');
}
}
}
} else {
style.push('past');
}
var diw = d+this.startday;
if (day >= this.selected.from && day <= this.selected.to) {
var single = false;
style.push('selected');
if (this.selected.from != this.selected.to) {
if (day == this.selected.from || d == 0) {
single = true;
style.push('selstart');
}
if (day == this.selected.to || d == 6) {
style.push(single ? 'selone' : 'selend');
}
} else {
style.push('selone');
}
}
if (diw%6 == 0 || diw%7 == 0) {
style.push('weekend');
}
var daysn = document.createElement('div');
daysn.className = style.join(' ');
var wrapn = document.createElement('div');
daysn.appendChild(wrapn);
var linkn = document.createElement('a');
linkn.appendChild(document.createTextNode(day));
linkn.href = 'javascript:void(0)';
wrapn.appendChild(linkn);
week.appendChild(daysn);
}
}
}
this.container.appendChild(cal);
this.size = TDOM.getSize(this.container);
}
var TGrid = function(data, info) {
this.url = '';
this.data = TDOM.getElement(data);
this.modal = null;
this.modalWin = null;
this.rowstart = 0;
this.rowcount = 0;
this.rowtotal = 0;
this.sortcol  = 0;
this.sortmode = 0;
this.searchcol = 0;
this.searchmode = 0;
this.searchstring = '';
this.changed = false;
this.params = {};
this.updating = false;
this.http = new THttp();
this.http.addEventListener("complete", this.handleHttp, this);
}
TGrid.inherits(TEventDispatcher);
TGrid.prototype.nextPage = function() {
if (this.rowstart + this.rowcount < this.rowtotal ) {
this.rowstart = this.rowstart + this.rowcount;
this.send();
}
}
TGrid.prototype.prevPage = function() {
if (this.rowstart > 0) {
this.rowstart = this.rowstart - this.rowcount;
if (this.rowstart < 0) {
this.rowstart = 0;
}
this.send();
}
}
TGrid.prototype.setRowStart = function(value) {
value = parseInt(value);
if (!isNaN(value) && value >= 0) {
if (this.rowstart != value && value < this.rowtotal) {
this.rowstart = value;
this.changed = true;
}
}
}
TGrid.prototype.setRowCount = function(value) {
value = parseInt(value);
if (!isNaN(value) && value >= 5) {
if (this.rowcount != value) {
this.rowcount = value;
this.changed = true;
}
}
}
TGrid.prototype.setSearchCol = function(value) {
value = parseInt(value);
if (!isNaN(value) && value >= 0) {
if (this.searchcol != value) {
this.searchcol = value;
this.changed = true;
}
}
}
TGrid.prototype.setSearchMode = function(value) {
value = parseInt(value);
if (!isNaN(value) && value >= 0) {
if (this.searchmode != value) {
this.searchmode = value;
this.changed = true;
}
}
}
TGrid.prototype.setSearchString = function(value) {
if (this.searchstring != value) {
this.searchstring = value;
this.changed = true;
}
}
TGrid.prototype.sort = function(col) {
col = parseInt(col);
if (!isNaN(col) && col >= 0) {
if (col == this.sortcol) {
this.sortmode = this.sortmode == 1 ? 0 : 1;
} else {
this.sortcol = col;
this.sortmode = 0;
}
this.send();
}
return false;
}
this.deleteRow = function(id) {
var del = false;
var result = this.msgdlg.show(null,'mtDelete',['mbYes','mbNo'],this.deleteRow,this,arguments);
if (result == 'mrYes') {
this.data.Params['del'] = id;
this.getTableContent();
}
}
TGrid.prototype.handleSubmit = function(e, reset) {
e = e || window.event;
if (e && e.keyCode == 13) {
if (this.changed) {
if (reset) {
this.rowstart = 0;
}
this.changed = false;
this.send();
}
}
}
TGrid.prototype.handleHttp = function(e) {
this.modalWin && this.modalWin.close();
if (this.http.error) {
this.dispatch("error", this.http.lastError);
} else {
var html = this.http.toString();
var regex = new RegExp(/<grid:data>([\s\S]*)<\/grid:data>/);
if (regex.test(html)) {
this.data.innerHTML = RegExp.$1;
} else {
regex = new RegExp(/<grid:error>([\s\S]*)<\/grid:error>/);
if (regex.test(html)) {
this.dispatch("error", RegExp.$1, '');
} else {
regex = new RegExp(/<error>([\s\S]*)<\/error>/);
if (regex.test(html)) {
this.dispatch("error", RegExp.$1, '');
} else {
regex = new RegExp(/<exception>([\s\S]*)<\/exception>/);
if (regex.test(html)) {
this.dispatch("error", RegExp.$1, '');
} else {
this.dispatch("error", 'Unknown server response<div style="margin-top:5px;padding:3px;height:75px;border:1px solid #aaa;background:#fff;overflow:auto">'+html+'</div>', html);
}
}
}
}
regex = new RegExp(/<grid:rows>([\s\S]*)<\/grid:rows>/);
if (regex.test(html)) {
var rowtotal = parseInt(RegExp.$1);
if (!isNaN(rowtotal) && rowtotal >= 0) {
this.rowtotal = rowtotal;
}
}
}
this.dispatch("rowchange", this.rowstart, this.rowcount, this.rowtotal);
}
TGrid.prototype.send = function() {
this.modalWin && this.modalWin.open(this.modal);
this.http.clear();
this.http.addParam('rowstart', this.rowstart);
this.http.addParam('rowcount', this.rowcount);
this.http.addParam('sortcol', this.sortcol);
this.http.addParam('sortmode', this.sortmode);
this.http.addParam('searchcol', this.searchcol);
this.http.addParam('searchmode', this.searchmode);
this.http.addParam('searchstring', this.searchstring);
for (var p in this.params) {
this.http.addParam(p, this.params[p]);
}
this.http.post(this.url);
}
TAccMenu = function(menu, opened) {
this.menu    = TDOM.getElement(menu);
this.opened  = [];
this.count   = 0;
this.speed   = 0;
this.multiOpen = true;
this._anims = [];
this._recs  = [];
opened = opened || [];
if (this.menu && this.menu.tagName.toUpperCase() == 'DL') {
var dt = TDOM.firstChild(this.menu);
while (dt && dt.nodeName.toUpperCase() != 'DT') {
dt = TDOM.nextElement(dt);
}
while (dt) {
var dd = TDOM.nextElement(dt);
if (dd && dd.nodeName.toUpperCase() == 'DD') {
this.count++;
dt.id = dt.id == '' ? 'tab' + this.count : dt.id;
this._anims[dt.id] = [];
TDOM.addClass(dt, 'menu');
TEvents.listen(dt, 'click', this.doClick, this);
TEvents.listen(dt, 'mouseover', this.doOver, this);
TEvents.listen(dt, 'mouseout', this.doOut, this);
var open = false;
for (var i=0,l=opened.length; i<l; i++) {
open = open || opened[i] == dt.id;
}
open && this.opened.push(dt.id);
open ? TDOM.addClass(dt, 'open') : TDOM.removeClass(dt, 'open');
while (dd && dd.nodeName.toUpperCase() == 'DD') {
open ? TDOM.addClass(dd, 'open') : TDOM.removeClass(dd, 'open');
dd.style.display = open ? 'block' : 'none';
dd = TDOM.nextElement(dd);
}
}
dt = dd;
}
}
}
TAccMenu.inherits(TEventDispatcher);
TAccMenu.prototype.tabOpen = function (id) {
id = typeof id == "object" ? id.id : id;
for (var i = 0; i < this.opened.length; i++) {
if (this.opened[i] == id) {
return true;
}
}
return false;
}
TAccMenu.prototype.getTab = function(id) {
var dt = TDOM.firstChild(this.menu);
while (dt) {
if (dt.nodeName.toUpperCase() == 'DT' && dt.id == id) {
return dt;
}
dt = TDOM.nextElement(dt);
}
return null;
}
TAccMenu.prototype.doOver = function(e) {
TDOM.addClass(e.currentTarget, 'over');
this.dispatch("mouseover", e.currentTarget);
}
TAccMenu.prototype.doOut = function(e) {
TDOM.removeClass(e.currentTarget, 'over');
this.dispatch("mouseout", e.currentTarget);
}
TAccMenu.prototype.doClick = function(e) {
var dt = e.currentTarget;
this.dispatch("click", dt);
this.setOpen(dt, !this.tabOpen(dt));
this.dispatch("change");
}
TAccMenu.prototype.setOpen = function(dt, open) {
dt = typeof dt == "string" ? this.getTab(dt) : dt;
if (dt && dt.nodeName && dt.nodeName.toUpperCase() == 'DT') {
if (open) {
if (this.tabOpen(dt)) { return; }
if (!this.multiOpen) {
for (var i = 0; i < this.opened.length; i++) {
this.setOpen(this.opened[i], false);
}
}
TDOM.addClass(dt, 'open');
this.opened.push(dt.id);
} else {
if (!this.tabOpen(dt)) { return; }
TDOM.removeClass(dt, 'open');
for (var i = 0; i < this.opened.length; i++) {
if (this.opened[i] == dt.id) {
this.opened.splice(i, 1);
break;
}
}
}
this.speed = 0;
this.stopAnim(dt.id);
var dd = TDOM.nextElement(dt);
while (dd && dd.nodeName.toUpperCase() == 'DD') {
open ? TDOM.addClass(dd, 'open') : TDOM.removeClass(dd, 'open');
if (this.speed != 0) {
this._anims[dt.id].push(this.initAnim(dd, open));
} else {
dd.style.display = open ? 'block' : 'none';
}
dd = TDOM.nextElement(dd);
}
}
}
TAccMenu.prototype.stopAnim = function (id) {
var anims = this._anims[id];
if (anims && anims.length) {
while (anims.length > 0) {
var anim = anims.shift();
window.clearInterval(anim);
}
}
}
TAccMenu.prototype.initAnim = function (dd, open) {
var rec = TDOM.getBounds(dd);
var to = open ? rec.height : 0;
var from = open ? 0 : rec.height;
var speed = this.speed;
dd.style.overflow = 'hidden';
if (open) {
dd.style.height = '0px';
dd.style.display = 'block';
}
var This = this;
var anim = window.setInterval(
function () {
from = open ? from + speed : from - speed;
if (open && from > to) {
dd.style.height = '';
window.clearInterval(anim);
This.dispatch("animated");
return;
} else
if (!open && from < to) {
dd.style.display = 'none';
dd.style.height = '';
window.clearInterval(anim);
return;
}
dd.style.height = from + 'px';
}, 10);
return anim;
}
TMaskEdit = function(input, mask) {
this.autocomplete = true;
this.input = TDOM.getElement(input);
this.value = this.input ? this.input.value : '';
this.isRegExp = typeof mask != 'string';
this.mask = this.isRegExp ? mask : mask.toLowerCase();
if (this.input && (this.isRegExp || mask.length != 0)) {
var old = this.input.style.display;
this.input.style.display = 'none';
TEvents.listen(this.input, 'keyup', this.onKeyUp, this);
TEvents.listen(this.input, 'keypress', this.onKeyPress, this);
this.fixInput({start: 0,end: 0});
this.input.style.display = old;
}
}
TMaskEdit.inherits(TEventDispatcher);
TMaskEdit.allow = {
k8:  8,
k9:  9,
k13: 13,
k27: 27,
k33: 33,
k34: 34,
k35: 35,
k36: 36,
k37: 37,
k38: 38,
k39: 39,
k40: 40,
k46: 46
}
TMaskEdit.prototype.isMask = function(chr) {
return chr == '#' || chr == '9' || chr == 'a' || chr == 'l' || chr == 'c';
}
TMaskEdit.prototype.getPlainMask = function(mask) {
return mask.replace(/[#9alc]/g,"_");
}
TMaskEdit.prototype.validKey = function(mask,key,completemask) {
switch (mask) {
case '9': return key >= 48 && key <= 57;
case '#': return key == 45 || (key >= 48 && key <= 57);
case 'a': return (/[a-z0-9]/i).test(String.fromCharCode(key));
case 'l': return (/[a-z]/i).test(String.fromCharCode(key));
case 'c': return true;
}
return false;
}
TMaskEdit.prototype.fixInput = function(sel) {
var val = '', pos = 0, result = '';
var values = this.input.value.split('');
if (this.isRegExp) {
for (var i=0; i<values.length; i++) {
result += this.mask.test(values[i]) ? values[i] : '';
}
} else {
var mask = this.mask.split('');
var plain = this.getPlainMask(this.mask).split('');
while (pos < mask.length && values.length > 0) {
if (this.isMask(mask[pos])) {
val = values.shift();
if (this.validKey(mask[pos], val.charCodeAt(0))) {
result += val;
} else {
while (values.length > 0) {
val = values.shift();
if (this.validKey(mask[pos], val.charCodeAt(0))) {
result += val;
break;
}
}
}
} else {
result += plain[pos];
}
pos++;
}
if (this.autocomplete) {
plain = plain.join('');
result += plain.substr(result.length, plain.length);
}
}
if (this.input.value != result) {
this.input.value = result;
TSelection.set(this.input, sel.start, 0);
}
}
TMaskEdit.prototype.onKeyPress = function(e) {
var key = e.charCode;
var chr = String.fromCharCode(key).toLowerCase();
if ("k"+key in TMaskEdit.allow && !this.isRegExp) return;
if (e.ctrlKey && (chr=='c' || chr=='x' || chr=='v')) return;
var sel = TSelection.get(this.input);
var result = '';
var offset = sel.start;
if (this.isRegExp) {
var values = this.input.value ? this.input.value.split('') : [];
var re = new RegExp(this.mask);
if (!re.test(key)) {
e.stopPropagation();
e.preventDefault();
}
} else {
var mask = this.mask.split('');
if (this.isMask(mask[offset])) {
if (this.validKey(mask[offset], key)) {
TSelection.set(this.input, offset, 1);
} else {
e.stopPropagation();
e.preventDefault();
}
} else {
var result = this.input.value.substr(0, offset);
var remain = this.input.value.substr(offset, this.input.value.length);
while (offset < mask.length && !this.isMask(mask[offset])) {
result += mask[offset];
remain = remain.substr(1, remain.length);
offset++;
}
this.input.value = result + remain;
if (this.validKey(mask[offset], key)) {
TSelection.set(this.input, offset, 1);
} else {
TSelection.set(this.input, offset, 0);
e.stopPropagation();
e.preventDefault();
}
}
}
}
TMaskEdit.prototype.onKeyUp = function(e) {
this.fixInput(TSelection.get(this.input));
}
TComboBox = function (cb) {
this.count = 0;
this.selected = -1;
this.opened = false;
this.value = '';
this._cb = TDOM.getElement(cb);
this._input = null;
this._value = null;
this._button = null;
this._dropdown = null;
this._iframe = null;
this._id = TComboBox.cbCounter++;
if (!this._cb) return;
this._text = '';
this._items = [];
this._skipBackspace = false;
this._overDropDown = false;
this._overButton = false;
this._searching = false;
this._itemtag = 'P';
this._enabled = true;
this._height = 0;
this._changed = false;
this._stopOpera = false;
this._overItem = -1;
this._value = TDOM.firstChild(this._cb);
this._input = TDOM.nextElement(this._value);
this._button = TDOM.nextElement(this._input);
this._dropdown = TDOM.nextElement(this._button);
if (!this._input || !this._button || !this._value) { return }
if (!this._dropdown) {
this._dropdown = document.createElement('DIV');
this._dropdown.className = 'options';
this._cb.appendChild(this._dropdown);
}
this.value = this._value.value;
if (TDOM.hasClass(this._cb,'disabled')) {
this._enabled = false;
this._input.readOnly = true;
}
this._input.setAttribute("autocomplete","off");
TEvents.listen(this._input, 'click', this._onInputExit, this);
TEvents.listen(this._input, 'blur', this._onInputExit, this);
TEvents.listen(this._input, 'keyup', this._onInputKeyUp, this);
TEvents.listen(this._input, 'keydown', this._onInputKeyDown, this);
TEvents.listen(this._button, 'click', this._onButtonClick, this);
TEvents.listen(this._button, 'mouseover', this._onButtonOver, this);
TEvents.listen(this._button, 'mouseout', this._onButtonOut, this);
TEvents.listen(this._dropdown, 'click', this._onDropDownClick, this);
TEvents.listen(this._dropdown, 'mouseover', this._onDropDownEnter, this);
TEvents.listen(this._dropdown, 'mouseout', this._onDropDownExit, this);
this._height = 0;
var op = TDOM.firstChild(this._dropdown);
while (op) {
var index = this.count++;
var id = 'cb__'+this._id+'__option__'+index;
this._items.push({element:op, value: op.id ? op.id : ""});
op.id = id;
this._itemtag = op.nodeName;
if (TDOM.hasClass(op,'selected')) { this.select(index); }
op = TDOM.nextElement(op);
}
if (TDOM.hasClass(this._cb,'readonly')) { this.readonly(true); }
if (this.count == 0) { TDOM.addClass(this._button, 'empty'); }
TDOM.onLoad(this.resize,this);
};
TComboBox.inherits(TEventDispatcher);
TComboBox.cbCounter = 0;
TComboBox.prototype.resize = function() {
this._height = 0;
this._dropdown.style.overflowY = 'scroll';
var rec1 = TDOM.getBounds(this._cb);
this._input.style.width = (rec1.width - 23) + 'px';
this._dropdown.style.width = rec1.width-2 + 'px';
var rec2 = TDOM.getBounds(this._dropdown);
this._height = rec2.height;
if (this._height > 250) {
this._dropdown.style.height = '250px';
} else {
this._dropdown.style.overflow = 'hidden';
this._dropdown.style.overflowY = 'hidden';
rec2 = TDOM.getBounds(this._dropdown);
this._height = rec2.height;
this._dropdown.style.height = this._height+'px';
}
if (TUserAgent.IE && !TUserAgent.OPERA && TUserAgent.VERSION < 7) {
this._iframe = document.createElement('iframe');
this._iframe.src = 'javascript:false';
this._iframe.style.display = 'none';
this._iframe.style.position = 'absolute';
this._iframe.style.top = (rec1.height+1) + 'px';
this._iframe.style.left = '-1px';
TDOM.setStyle(this._iframe,'opacity',0);
this._iframe.style.height = this._dropdown.style.height;
this._iframe.style.width = rec1.width+2 + 'px';
this._cb.appendChild(this._iframe);
}
}
TComboBox.prototype.select = function(id) {
if (id == this.selected) { return; }
var op = this._items[id];
var el = op && op.element;
if (id < 0 && this._input.readOnly) { return; }
if (this.selected > -1 && this._items[this.selected]) {

TDOM.removeClass(this._items[this.selected].element, 'selected');
}
if (!op || !el) {
this._text = '';
this.value = '';
this._value.value = "";
this._input.value = "";
this.selected = -1;
} else {
this.selected = id;
this.value = op.value;
this._value.value = op.value;
var text = this.getOptionText(el);
this._input.value = text;
this._text = this._input.value;
this.makeVisible(id);
TDOM.addClass(el, 'selected');
}
this._changed = true;
if (!this._searching) {
this._changed = false;
this.dispatch("change");
}
}
TComboBox.prototype.getOptionText = function(option) {
var node = option.firstChild;
while (node && node.nodeType != 3) {
node = node.nextSibling;
}
var text = node ? node.data : '';
if (text == '') {
node = TDOM.firstChild(option);
while (node) {
if (TDOM.hasClass(node,'caption')) {
var node2 = node.firstChild;
while (node && node.nodeType != 3) { node = node.nextSibling; }
var text = node2 ? node2.data : '';
}
node = TDOM.nextElement(node);
}
}
return text;
}
TComboBox.prototype.makeVisible = function(id) {
if (!this._items[id] || !this.opened) { return }
var rec1 = TDOM.getBounds(this._items[id].element);
var rec2 = TDOM.getBounds(this._dropdown);
var top  = rec1.top;
if (top + rec1.height > rec2.height) {
this._dropdown.scrollTop = rec1.top + this._dropdown.scrollTop - rec2.height + rec1.height;
}
if (top < 0) {
this._dropdown.scrollTop = rec1.top - rec2.top + this._dropdown.scrollTop;
}
}
TComboBox.prototype.readonly = function(value) {
if (value && this.selected == -1) {
this.select(0);
}
this._input.readOnly = value;
}
TComboBox.prototype.enable = function() {
if (this._enabled) { return; }
TDOM.removeClass(this._cb, 'disabled');
this._input.readOnly = false;
this._enabled = true;
}
TComboBox.prototype.disable = function() {
if (!this._enabled) { return; }
TDOM.addClass(this._cb, 'disabled');
this._input.readOnly = true;
this._enabled = false;
}
TComboBox.prototype.readOnly = function(value) {
this._input.readOnly = value;
}
TComboBox.prototype.open = function() {
if (!this._enabled || this._items.length == 0) { return }
this.opened = true;
var rec1 = TDOM.getViewportBounds();
var rec3 = TDOM.getBounds(this._cb);
var rec4 = TDOM.getBounds(this._dropdown);
var ontop = rec1.top+rec1.height < rec3.top+rec3.height+this._height && ((this._height) * -1) + rec3.top >= 0;
var top = ontop ? ((this._height) * -1) - 2 : top = rec3.height - 2;
this._dropdown.style.top = top + 'px';
TDOM.addClass(this._button, 'open');
this._dropdown.style.display = 'block';
this._cb.style.zIndex = 9989;
this._dropdown.style.zIndex = 9989;
this.makeVisible(this.selected);
if (this._iframe) {
this._iframe.style.display = 'block';
this._iframe.style.zIndex = 1;
this._iframe.style.width = (rec4.width) + 'px';
}
this.dispatch("open");
}
TComboBox.prototype.close = function() {
this._dropdown.style.display = 'none';
this._iframe && (this._iframe.style.display = 'none');
TDOM.removeClass(this._button, 'open');
this._cb.style.zIndex = 0;
this._overDropDown = false;
this.opened = false;
this.dispatch("close");
}
TComboBox.prototype.clear = function() {
this.select(-1);
this._dropdown.innerHTML = '';
this._items = [];
this._value.value = '';
this._input.value = '';
TDOM.addClass(this._button, 'empty');
this.count = 0;
this._height = 0;
this._dropdown.style.height = 0;
this._dropdown.style.overflowY = 'hidden';
}
TComboBox.prototype.add = function(text, value) {
var id = this.count++;
var el = document.createElement('div');
el.className = 'item';
el.id = 'cb__'+this._id+'__option__'+id;
el.innerHTML = text;
this._dropdown.appendChild(el);
this._items.push({element:el, value:value});
TDOM.removeClass(this._button, 'empty')
if (this._height < 250) {
var rec = TDOM.getSize(el);
this._height += rec.height;
this._dropdown.style.height = this._height > 250 ? '250px' : this._height+'px';
this._dropdown.style.overflowY = this._height > 250 ? 'scroll' : 'hidden';
}
return el;
}
TComboBox.prototype.setValue = function(value) {
for (i=0; i < this._items.length; i++) {
if (this._items[i].value == value) {
this.select(i);
return;
}
}
this.value = value;
this._input.value = value;
}
TComboBox.prototype._onButtonClick = function(e) {
if (this.count == 0) { return; }
this.opened ? this.close() : this.open();
this._input.focus();
}
TComboBox.prototype._onButtonOver = function(e) {
TDOM.addClass(e.currentTarget, 'over');
this._overButton = true;
}
TComboBox.prototype._onButtonOut = function(e) {
TDOM.removeClass(e.currentTarget, 'over');
this._overButton = false;
}

TComboBox.prototype.getItem = function(el) {
while (el) {
if (el.parentNode == this._dropdown) { return el; }
el = el.parentNode;
}
}
TComboBox.prototype._onDropDownClick = function(e) {
var el = this.getItem(e.target);
if (el) {
var id = el.id;
id = parseInt(id.replace('cb__'+this._id+'__option__',''));
if (!isNaN(id)) {
this.select(id);
this._input.focus();
this.close();
}
}
}
TComboBox.prototype._onDropDownEnter = function(e) {
TDOM.addClass(this.getItem(e.target), 'over');
this._overDropDown = true;
}
TComboBox.prototype._onDropDownExit = function(e) {
TDOM.removeClass(this.getItem(e.target), 'over');
this._overDropDown = false;
}
TComboBox.prototype._onInputExit = function(e) {
if (!this._overDropDown && !this._overButton) {
this.close();
}
if (this._changed) {
this._changed = false;
this.dispatch("change");
}
}
TComboBox.prototype._onInputKeyUp = function(e) {
if (!this._enabled) { return; }
var el = e.currentTarget;
var key = e.keyCode;
var query = el.value.toLowerCase();
if (this._text === el.value) { return; }
this._text = el.value;
if (key == 38 || key == 40) { return; }
if (key == 8 && !this._skipBackspace) {
query = query.substr(0,query.length-1);
el.value = query;
}
this.value = this._value.value = el.value;
this._skipBackspace = false;
if (this._items[this.selected]) {
TDOM.removeClass(this._items[this.selected].element, 'selected');
this.selected = -1;
this._changed = true;
}
if (key == 46 || query == '') { this.close(); return; }
var found = false;
for(var i = 0; i < this._items.length; i++) {
var option = this._items[i].element;
var text = this.getOptionText(option).toLowerCase();
var pos = text.indexOf(query);
if (pos === 0) {
found = true;
this._searching = true;
this.select(i);
this._searching = false;
TSelection.set(el, query.length, el.value.length);
break;
}
}
i < this._items.length ? this.open() : this.close();
}
TComboBox.prototype._onInputKeyPress = function(e) {
if (TUSerAgent.OPERA && this._stopOpera) {
e.stopPropagation();
e.preventDefault();
this._stopOpera = true;
}
}
TComboBox.prototype.getNextAvailable = function() {
var index=this.selected, op=null;
do {
index++;
op=this._items[index];
} while (op && op.element.style.display == 'none');
return index < this._items.length ? index : this.selected;
}
TComboBox.prototype.getPrevAvailable = function() {
var index=this.selected, op=null;
do {
index--;
op=this._items[index];
} while (op && op.element.style.display == 'none');
return index >= 0 ? index : this.selected;
}
TComboBox.prototype._onInputKeyDown = function(e) {
if (!this._enabled) { return; }
switch (e.keyCode) {
case 9:  if (this.opened) { this.close(); e.currentTarget.focus(); }
break;
case 8:  var sel = TSelection.get(e.currentTarget);
this._skipBackspace = sel.length == 0;
break;
case 13: if (this.opened) {
this._changed = true;
TSelection.set(this._input,this._input.value.length,this._input.value.length);
this.close();
}
if (this._changed) {
this._changed = false;
this.dispatch("change");
e.stopPropagation();
e.preventDefault();
this._stopOpera = true;
}
break;
case 27: this.close();
break;
case 38: if (this.opened && this.selected > 0) {
this._searching = true;
this.select(this.getPrevAvailable());
this._searching = false;
}
this.open();
if (this.selected < 0) this.close();
e.stopPropagation();
e.preventDefault();
this._stopOpera = true;
return false;
case 40: var next = this.getNextAvailable();
if (this.opened) {
this._searching = true;
this.select(next);
this._searching = false;
}
if (this.count > 0) {
this.open();
}
e.stopPropagation();
e.preventDefault();
this._stopOpera = true;
return false;
}
}
TComboBoxEx = function (cb,min,url) {
TComboBox.prototype.constructor.call(this,cb);
this._text = this._input.value;
this._cache = {};
this.url = url;
this.min = min;
this._http = new THttp();
this._http.addEventListener('complete',this._onRequestComplete,this);
if (this._input.value.length < this.min) {
this._button.innerHTML = min-this._input.value.length;
TDOM.addClass(this._button,'incomplete');
}
};
TComboBoxEx.inherits(TComboBox);
TComboBoxEx.prototype.url = null;
TComboBoxEx.prototype.min = 0;
TComboBoxEx.prototype._cache = {};
TComboBoxEx.prototype._http = null;
TComboBoxEx.prototype._timer = null;
TComboBoxEx.prototype._token = '';
TComboBoxEx.prototype.open = function() {
if (this._input.value.length >= this.min) {
TComboBox.prototype.open.call(this);
}
}
TComboBoxEx.prototype.getOptionText = function(option) {
return option.innerHTML.replace(/<.*?>/g,'');
}
TComboBoxEx.prototype._onInputKeyUp = function(e) {
if (!this._enabled) { return; }
TDOM.removeClass(this._button,'error');
var el = e.currentTarget;
var key = e.keyCode;
var query = el.value.toLowerCase().trim();
if (this._text === el.value) { return; }
this._text = el.value;
if (key == 38 || key == 40) { return; }
this._changed = true;
if (query.length < this.min) {
TDOM.addClass(this._button,'incomplete');
this._button.innerHTML = this.min-query.length;
this._value.value = "";
this.value = '';
this.select(-1);
this.close();
} else {
TDOM.removeClass(this._button,'incomplete');
this._button.title = '';
this._button.innerHTML = '';
if (key == 8 && !this._skipBackspace) {
query = query.substr(0,query.length-1);
el.value = query;
}
this.value = this._value.value = el.value;
this._skipBackspace = false;
if (this._items[this.selected]) {
TDOM.removeClass(this._items[this.selected].element, 'selected');
this.selected = -1;
this._changed = true;
}
if (key == 46 || query == '') { this.close(); return; }
var token = query.substring(0,this.min);
this.close();
this.getResult(this.toPlain(token),query);
}
}
TComboBoxEx.prototype.getResult = function(token,filter) {
this.select(-1);
var dd = this._cache[token];
if (!dd) {
if (this._http.open) {
this._cache[this._http.token] = false;
}
this._cache[token] = true;
if (this._timer) {
clearTimeout(this._timer);
this._timer = null;
}
this.dispatch('beforerequest');
var url = this.url + (this.url.indexOf('?') != -1 ? '&' : '?') + 'f='+token;
this._http.token = token;
this._http.get(url);
TDOM.removeClass(this._button,'error');
TDOM.addClass(this._button,'requesting');
} else
if (dd.dropdown && dd.items) {
this.showResult(dd,token,filter);
}
}
TComboBoxEx.prototype.toPlain = function(str) {
str = str.toLowerCase();
str = str.replace(/á|â|ä|à/gi,'a');
str = str.replace(/é|ê|ë|è/gi,'e');
str = str.replace(/í|î|ï|ì/gi,'i');
str = str.replace(/ó|ô|ö|ò/gi,'o');
str = str.replace(/ù|û|ü|ù/gi,'u');
str = str.replace(/ñ/gi,'n');
return str;
}
TComboBoxEx.prototype.toRegex = function(str) {
str = str.toLowerCase();
str = str.replace(/á|â|ä|à|a/gi,'[á|â|ä|à|a]');
str = str.replace(/é|ê|ë|è|e/gi,'[é|ê|ë|è|e]');
str = str.replace(/í|î|ï|ì|i/gi,'[é|ê|ë|è|i]');
str = str.replace(/ó|ô|ö|ò|o/gi,'[ó|ô|ö|ò|o]');
str = str.replace(/ú|û|ü|ù|u/gi,'[ú|û|ü|ù|u]');
str = str.replace(/ñ|n/gi,'[ñ|n]');
return str;
}
TComboBoxEx.prototype.filter = function() {
var str = this.toPlain(this._input.value), count = 0;
this._dropdown.style.height = '';
this._dropdown.style.overflowY = '';
var count = 0, height=0;
for (var i=0,l=this._items.length; i<l; i++) {
var text = this._items[i].element.innerHTML;
text = this.getOptionText(this._items[i].element);
var show = this.toPlain(text).indexOf(str) != -1;
this._items[i].element.style.display = show ? 'block' : 'none';
if (show) {
count++;
try {
var re = new RegExp('('+this.toRegex(this._input.value)+')','i');
this._items[i].element.innerHTML = text.replace(re,'<span class="highlight">$1</span>').replace(/###/g, '<b>').replace(/&&&/g, '</b>').replace(/%%%/g, '<br />');
} catch (e) { }
}
}
this.resize();
return count;
}
TComboBoxEx.prototype.findMatch = function() {
var match = -1;
var str = this.toPlain(this._input.value);
for (var i=0,l=this._items.length; i<l; i++) {
var text = this._items[i].element.innerHTML;
text = this.getOptionText(this._items[i].element);
if (this.toPlain(text) == str) {
this._searching = false;
this.select(i);
return;
}
}
}
TComboBoxEx.prototype._onInputExit = function(e) {
this._changed && this.findMatch();
TComboBox.prototype._onInputExit.call(this,e);
if (this._http.open) {
this._http.abort();
TDOM.removeClass(this._button,'error');
}
}
TComboBoxEx.prototype.showResult = function(dd,filter) {
TDOM.removeClass(this._button,'requesting');
if (dd.dropdown != this._dropdown) {
this.close();
this._dropdown = dd.dropdown;
this._items = dd.items;
this.count = dd.items.length;
}
var count = this.filter(filter);
TDOM[count > 0 ? 'removeClass' : 'addClass'](this._button, 'empty');
this.open();
}
TComboBoxEx.prototype._onRequestComplete = function(e) {
var http = e.target;
var token = http.token;
var dd = document.createElement('div');
dd.className = 'options';
this._cb.appendChild(dd);
dd = {dropdown:dd,items:[],count:0};
this._dropdown = dd.dropdown;
this._items = dd.items;
this.count = dd.items.length;
this._cache[token] = dd;
TEvents.listen(this._dropdown, 'click', this._onDropDownClick, this);
TEvents.listen(this._dropdown, 'mouseover', this._onDropDownEnter, this);
TEvents.listen(this._dropdown, 'mouseout', this._onDropDownExit, this);
if (this.dispatch('httpdata',http)) {
this.showResult(dd,this._input.value);
} else {
TDOM.removeClass(this._button,'requesting');
this._cache[token] = false;
}
}
var TTabSet = function (tabset, selected) {
this.count    = 0;
this.tabset   = TDOM.getElement(tabset);
this.selected = typeof selected == "number" || selected >= 0 ? selected : -1;
if (this.tabset) {
var tab = TDOM.firstChild(this.tabset);
while (tab) {
var id = this.count++;
tab[TTabSet.ownAttr] = id;
this.selected == id ? TDOM.addClass(tab, 'selected') : TDOM.removeClass(tab, 'selected');
TEvents.listen(tab, 'click', this.doClick, this);
TEvents.listen(tab, 'mouseout', this.doOut, this);
TEvents.listen(tab, 'mouseover', this.doOver, this);
tab = TDOM.nextElement(tab);
}
this.selected = this.selected > this.count-1 ? -1 : this.selected;
}
}
TTabSet.inherits(TEventDispatcher);
TTabSet.ownAttr = "tabset_tab_unique_id";
TTabSet.prototype.doOut = function (e) {
TDOM.removeClass(e.currentTarget, 'over');
}
TTabSet.prototype.doOver = function (e) {
TDOM.addClass(e.currentTarget, 'over');
}
TTabSet.prototype.doClick = function (e) {
this.dispatch("click", e.currentTarget);
this.select(e.currentTarget);
}
TTabSet.prototype.getTabById = function (id) {
var tab = TDOM.firstChild(this.tabset);
while (tab) {
if (tab[TTabSet.ownAttr] == id) {
return tab;
}
tab = TDOM.nextElement(tab);
}
return null;
}
TTabSet.prototype.select = function (tab) {
if (typeof tab == 'number') {
var id = tab;
tab = this.getTabById(tab);
} else {
var id = tab[TTabSet.ownAttr];
}
if (id == this.selected) { return; }
id = id > this.count-1 || id < 0 ? -1 : id;
var old = this.getTabById(this.selected);
var canchange = this.dispatch("canchange", old, tab, id) !== false;
if (canchange) {
if (old) {
TDOM.removeClass(old, 'selected');
}
if (tab) {
TDOM.addClass(tab, 'selected');
}
this.selected = id;
this.dispatch("change", tab, id);
}
}
TEasing = {
easeNone: function(t,b,c,d) { return c*t/d+b; },
easeIn: function (t,b,c,d) { return c*(t/=d)*t+b; },
easeOut: function (t,b,c,d) { return -c*(t/=d)*(t-2)+b; },
easeInOut: function (t,b,c,d) { return (t/=d/2) < 1 ? c/2*t*t+b : -c/2*((--t)*(t-2)-1)+b; }
};
TEasing.Cubic = {
easeIn: function (t,b,c,d) { return c*(t/=d)*t*t+b; },
easeOut: function (t,b,c,d) { return c*((t=t/d-1)*t*t+1)+b; },
easeInOut: function (t,b,c,d) { return (t/=d/2)<1 ? c/2*t*t*t+b : c/2*((t-=2)*t*t+2)+b; }
}
TEasing.Quartic = {
easeIn: function (t,b,c,d) { return c*(t/=d)*t*t*t+b; },
easeOut: function (t,b,c,d) { return -c*((t=t/d-1)*t*t*t-1)+b; },
easeInOut: function (t,b,c,d) { return (t/=d/2)<1 ? c/2*t*t*t*t+b : -c/2*((t-=2)*t*t*t-2)+b; }
}
TEasing.Elastic = {
easeIn:     function (t,b,c,d,a,p) {
if (t==0) { return b; }
if ((t/=d)==1) { return b+c; }
if (!p) { p=d*0.3; }
if (!a || a < Math.abs(c)) {
a = c;
var s = p/4;
} else {
var s = p/(2*Math.PI)*Math.asin(c/a);
}
return -(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;
},
easeOut:    function (t,b,c,d,a,p) {
if (t==0) { return b; }
if ((t/=d)==1) { return b+c; }
if (!p) { p=d*0.3; }
if (!a || a < Math.abs(c)) {
a = c;
var s = p/4;
} else {
var s = p/(2*Math.PI)*Math.asin(c/a);
}
return a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b;
},
easeInOut:  function (t,b,c,d,a,p) {
if (t==0) { return b; }
if ((t/=d/2)==2) { return b+c; }
if (!p) { p=d*(0.3*1.5); }
if ( !a || a < Math.abs(c) ) {
a = c;
var s = p/4;
} else {
var s = p/(2*Math.PI)*Math.asin(c/a);
}
if (t < 1) { return -0.5*(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b; }
return a*Math.pow(2,-10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p)*0.5+c+b;
}
}
TEasing.Back = {
easeIn:     function (t,b,c,d,s) {
if (typeof s=='undefined') { s=1.70158; }
return c*(t/=d)*t*((s+1)*t-s)+b;
},
easeOut:    function (t,b,c,d,s) {
if (typeof s=='undefined') { s=1.70158; }
return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b;
},
easeInOut:  function (t,b,c,d,s) {
if (typeof s=='undefined') { s=1.70158; }
if ((t/=d/2)<1) { return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b; }
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b;
}
}
TEasing.Bounce = {
easeIn:     function (t,b,c,d) {
return c - TEasing.Bounce.easeOut(d-t,0,c,d)+b;
},
easeOut:    function (t,b,c,d) {
if ((t/=d)<(1/2.75)) { return c*(7.5625*t*t)+b; } else
if (t<(2/2.75)) { return c*(7.5625*(t-=(1.5/2.75))*t+0.75)+b; } else
if (t<(2.5/2.75)) { return c*(7.5625*(t-=(2.25/2.75))*t+0.9375)+b; }
return c*(7.5625*(t-=(2.625/2.75))*t+0.984375)+b;
},
easeInOut:  function (t,b,c,d) {
if (t<d/2) { return TEasing.Bounce.easeIn(t*2,0,c,d)*0.5+b;
}
return TEasing.Bounce.easeOut(t*2-d,0,c,d)*0.5+c*0.5+b;
}
}
TTween = function(el, attr, duration, method, paused) {
duration = parseFloat(duration);
this.element = TDOM.getElement(el);
this.method = method || TEasing.easeNone;
this.attributes = {};
this.duration = !isNaN(duration) && duration >= 0 ? duration : 1;
this.running = false;
this.totalFrames = Math.ceil(this.duration * TTweenManager.fps);
this.currentFrame = 0;
this.setAttributes(attr);
if (!paused) { this.play(); }
}
TTween.inherits(TEventDispatcher);
TTween.prototype.play = function() {
this.currentFrame = 0;
this.totalFrames = this.duration > 0 ? Math.ceil(this.duration * TTweenManager.fps) : 0;
TTweenManager.addTween(this);
this.step(1);
this.dispatch('end');
}
TTween.prototype.resume = function() {
TTweenManager.addTween(this);
this.step(this.totalFrames);
this.dispatch('end');
}
TTween.prototype.stop = function() {
TTweenManager.removeTween(this);
}
TTween.prototype.seek = function(frame) {
this.step(frame-this.currentFrame);
this.step(this.totalFrames);
//alert(1);
}
TTween.prototype.step = function(frames) {
if (this.currentFrame < this.totalFrames || this.totalFrames == 0) {
this.currentFrame += frames;
this.currentFrame = this.currentFrame >= 0 ? this.currentFrame : 0;
this.currentFrame = this.currentFrame <= this.totalFrames ? this.currentFrame : this.totalFrames;
for (var attr in this.attributes) {
var values = this.attributes[attr];
if ((/color$/i).test(attr)) {
var val = [];
for (var i=0; i < 3; i++) {
val[i] = this.method(this.currentFrame, values.from[i], values.to[i]-values.from[i], this.totalFrames);
val[i] = val[i] > 255 ? 255 : (val[i] < 0 ? 0 : Math.floor(val[i]));
}
TDOM.setStyle(this.element, attr, 'rgb('+val[0]+', '+val[1]+', '+val[2]+')');
} else
if (attr == 'scrollLeft') {
var val = this.method(this.currentFrame, values.from, values.to-values.from, this.totalFrames);
this.element[attr] = val;
} else {
var val = this.method(this.currentFrame, values.from, values.to-values.from, this.totalFrames);
if ((/width|height|opacity|padding/i).test(attr)) {
val = (val > 0) ? val : 0;
}
TDOM.setStyle(this.element, attr, val+(attr=='opacity' ? '' : values.unit));
}
}
this.dispatch('update',val);
} else {
this.dispatch('end');
this.stop();
}
}
TTween.prototype.setAttributes = function(attributes) {
this.attributes = {};
for (var attr in attributes) {
var values = attributes[attr];
if (typeof values != 'object' && typeof values.to == 'undefined' && typeof values.by == 'undefined') {
continue;
}
(/color$/i).test(attr) ? this.setColorAttribute(attr, values) : this.setNumericAttribute(attr, values);
}
}
TTween.prototype.setColorAttribute = function(attr, values) {
if (!(/color$/i).test(attr)) { return; }
values.unit = '';
if (typeof values.from == 'undefined') {
var val = TDOM.getStyle(this.element, attr).toLowerCase();
var regex = /^transparent|rgba\(0, 0, 0, 0\)$/;
if (regex.test(val)) {
var parent = TDOM.getParentBy(this.element, function(node) { return !regex.test(TDOM.getStyle(node, attr).toLowerCase()) });
val = parent ? TDOM.getStyle(parent, attr).toLowerCase() : [255,255,255];
}
values.from = val;
}
values.from = this.parseColor(values.from);
if (typeof values.to == 'undefined') {
values.to = [];
var color = this.parseColor(values.by);
for (var i=0; i < 3; i++) {
var sum = values.from[i]+color[i];
values.to[i] = sum > 255 ? 225 : sum;
}
} else {
values.to = this.parseColor(values.to);
}
for (var i=0; i < 3; i++) {
values.to[i] = values.to[i] > 255 ? 255 : (values.to[i] < 0 ? 0 : Math.floor(values.to[i]));
values.from[i] = values.from[i] > 255 ? 255 : (values.from[i] < 0 ? 0 : Math.floor(values.from[i]));
}
this.attributes[attr] = values;
}
TTween.prototype.setNumericAttribute = function(attr, values) {
values.unit = typeof values.unit == 'undefined' ? 'px' : values.unit;
if (typeof values.from == 'undefined') {
var val = TDOM.getStyle(this.element, attr).toLowerCase();
var unit = (/\d+(em|%|en|ex|pt|in|cm|mm|pc)$/).test(val);
if (val != 'auto' && unit == values.unit) {
values.from = parseFloat(val);
} else {
var type = {width:1, height:1, top:2, left:2}[attr];
if (type == 1) {
values.from = TDOM.getSize(this.element)[attr];
} else
if (type == 2 && TDOM.getStyle(this.element,'position') == 'absolute') {
values.from = TDOM.getPos(this.element)[attr];
} else {
values.from = 0;
}
}
}
if (typeof values.to == 'undefined') {
values.to = values.from + values.by;
}
this.attributes[attr] = values;
}
TTween.prototype.parseColor = function(color) {
if (color.length == 3) { return color; }
var regex = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
var match = regex.exec(color);
if (match) {
return [parseInt(match[1]+match[1],16), parseInt(match[2]+match[2],16), parseInt(match[3]+match[3],16)];
}
var regex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
var match = regex.exec(color);
if (match) {
return [parseInt(match[1],16), parseInt(match[2],16), parseInt(match[3],16)];
}
var regex = /^rgb\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\)$/i;
var match = regex.exec(color);
if (match) {
return [parseInt(match[1]), parseInt(match[2]), parseInt(match[3]) ];
}
return [255,255,255];
}
TTweenManager = {};
TTweenManager.fps = 25;
TTweenManager.stack = [];
TTweenManager.timer = null;
TTweenManager.indexOf = function(tween) {
for (var i = 0, c = TTweenManager.stack.length; i < c; i++) {
if (TTweenManager.stack[i] == tween) { return i; }
}
return -1;
}
TTweenManager.addTween = function(tween) {
if (TTweenManager.indexOf(tween) == -1) {
TTweenManager.stack.push(tween);
TTweenManager.start();
}
}
TTweenManager.removeTween = function(tween) {
TTweenManager.removeTweenAt(TTweenManager.indexOf(tween));
}
TTweenManager.removeTweenAt = function(index) {
if (index >= 0 && index < TTweenManager.stack.length) {
TTweenManager.stack.splice(index, 1);
var tween = TTweenManager.stack[index];
if (tween) {
tween.running = false;
tween.dispatch('stop');
}
if (TTweenManager.stack.length == 0) {
TTweenManager.stop();
}
}
}
TTweenManager.start = function() {
if (!TTweenManager.timer && TTweenManager.stack.length > 0) {
var interval = Math.floor(1000 / TTweenManager.fps);
TTweenManager.timer = setInterval(TTweenManager.onTimer, interval);
}
}
TTweenManager.stop = function() {
if (TTweenManager.timer) {
clearInterval(TTweenManager.timer);
TTweenManager.timer = null;
}
for (var i = TTweenManager.stack.length-1; i >= 0; i--) {
TTweenManager.removeTweenAt(i);
}
}
TTweenManager.onTimer = function() {
for (var i = 0, c = TTweenManager.stack.length; i < c; i++) {
var tween = TTweenManager.stack[i];
if (tween) {
if (!tween.running) {
tween.running = true;
tween.dispatch('start');
}
tween.step(1);
}
}
}
TFlash = function(name, movie, width, height) {
this._vars = [];
this._eattrs = {};
this._oattrs = {};
this._params = {};
this.name = name;
this.movie = movie;
this.width = width;
this.height = height;
this.version = '9,0,0,0';
this.transparent = false;
this.preventcache = false;
this.set('id', name);
this.set('src', movie);
this.set('menu', false);
this.set('quality', 'high');
this.set('allowScriptAccess','sameDomain');
this.set('type', 'application/x-shockwave-flash');
this.set('classid', 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000');
this.set('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
}
TFlash.GlobalContainer = null;
TFlash.prototype.addVar = function(name, value) {
this._vars.push(name + '=' + escape(value));
}
TFlash.prototype.addVars = function(vars) {
if (vars) {
vars = vars.split('&');
for (var i=0, c=vars.length; i < c; i++) {
this._vars.push(vars[i]);
}
}
}
TFlash.draw = function(movie, width, height, transparent, vars) {
var swf = new TFlash('', movie, width, height);
swf.transparent = transparent ? true : false;
swf.addVars(vars);
swf.draw();
}
TFlash.prototype.draw = function(container) {
var html = this.toHTML();
container = typeof container != 'undefined' ? TDOM.getElement(container) : null;
container ? container.innerHTML=html : document.write(html);
}
TFlash.prototype.toHTML = function() {

if (this.preventcache) {
var src = this._params["movie"];
src += src.indexOf('?') != -1 ? '&' : '?';
src += Math.random();
this.set('src', src);
}

this.set('width', this.width);
this.set('height', this.height);
this.set('wmode', this.transparent ? 'transparent' : 'window');
this.set('codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.version);
if (this._vars.length > 0) {
this.addVars(this._params['flashvars']);
this.set('flashvars', this._vars.join('&'));
}
var html = '';
if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
html += '<embed ';
for (var i in this._eattrs) {
html += i + '="' + this._eattrs[i] + '" ';
}
html += '> </embed>';
} else {
html += '<object ';
for (var i in this._oattrs) {
html += i + '="' + this._oattrs[i] + '" ';
}
html += '>';
for (var i in this._params) {
html += '<param name="' + i + '" value="' + this._params[i] + '" /> ';
}
html += '</object>';
}
return html;
}
TFlash.prototype.set = function(name, value) {
switch (name){
case "classid": this._oattrs[name] = value; break;
case "pluginspage": this._eattrs[name] = value; break;
case "src":
case "movie": this._eattrs["src"] = this._params["movie"] = value; break;
case "id":
case "name": this._eattrs["id"] = this._eattrs["name"] = this._oattrs["id"] = this._oattrs["name"] = value; break;
case "width":
case "height":
case "align":
case "vspace":
case "hspace":
case "class":
case "title":
case "accesskey":
case "tabindex": this._eattrs[name] = this._oattrs[name] = value; break;
case "onafterupdate":
case "onbeforeupdate":
case "onblur":
case "oncellchange":
case "onclick":
case "ondblclick":
case "ondrag":
case "ondragend":
case "ondragenter":
case "ondragleave":
case "ondragover":
case "ondrop":
case "onfinish":
case "onfocus":
case "onhelp":
case "onmousedown":
case "onmouseup":
case "onmouseover":
case "onmousemove":
case "onmouseout":
case "onkeypress":
case "onkeydown":
case "onkeyup":
case "onload":
case "onlosecapture":
case "onpropertychange":
case "onreadystatechange":
case "onrowsdelete":
case "onrowenter":
case "onrowexit":
case "onrowsinserted":
case "onstart":
case "onscroll":
case "onbeforeeditfocus":
case "onactivate":
case "onbeforedeactivate":
case "ondeactivate":
case "codebase": this._oattrs[name] = value; break;
default: this._eattrs[name] = this._params[name] = value;
}
}
TFlashIntf = function(movie, swf) {
this.id = movie;
this.container = null;
this._isintf = false;
this._connector = swf;
TFlashIntf.instances[movie] = this;
}
TFlashIntf.inherits(TEventDispatcher);
TFlashIntf.instances = [];
TFlashIntf.QueryJSIntf = function(movie) {
var movie = TFlashIntf.instances[movie];
if (movie) {
movie._isintf = true;
return true;
} else {
return false;
}
}
TFlashIntf.FromAS = function(movie, event, args) {
var movie = TFlashIntf.instances[movie];
if (movie) {
args.unshift(event);
movie.dispatch.apply(movie, args);
}
}
TFlashIntf.prototype.callAS = function(event, args) {
var movie = TUserAgent.IE ? window[this.id] : document[this.id];
if (movie != null) {
if (this._isintf) {
movie.CallAS(event, args);
} else {
this.container = TDOM.getElement(this.container);
var url = this._connector + (this._connector.indexOf('?') ? '&' : '?');
var swf = new TFlash("swfconn", url + 'id=' + this.id + '&' + 'event='+event, 1, 1);
swf.preventcache = true;
swf.transparent = true;
swf.addVar('args',this.serialize(args));
swf.draw(this.container);
}
}
}
TFlashIntf.prototype.serialize = function(value, depth) {
depth = depth == undefined ? 0 : depth;
switch (typeof(value)) {
case 'string':    return '<s>' + value.replace(/<\/s>/i, "[/s]") + '</s>';
case 'number':    return '<n>' + value + '</n>';
case 'boolean':   return '<b>' + (value ? 1 : 0) + '</b>';
case 'object':    return this.fromArray(value, depth);
default:          return '<s></s>';
}
}
TFlashIntf.prototype.fromArray = function(list, depth) {
var result = '<a' + depth + '>';
for (var key in list) {
var i = parseInt(key);
if (i == key) {
key = i;
}
result += this.serialize(key,depth+1) + this.serialize(list[key], depth+1);
}
result += '</a' + depth + '>';
return result;
}
var THttp = function () {
this.xhr = null;
this.open = false;
this.error = false;
this.params = [];
this.lastError = '';
};
THttp.inherits(TEventDispatcher);
THttp.timeout = 30;
THttp.MSXML = ["MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
THttp.NULLFunction = null;
THttp.prototype.free = function () {
if (this.open) { this.abort(); }
TEventDispatcher.prototype.free.call(this);
};
THttp.prototype.clear = function() {
this.params = [];
}
THttp.prototype.getParams = function() {
return this.params.join('&');
}
THttp.prototype.addParam = function(name,value) {
this.params.push(name+'='+value);
}
THttp.prototype.addParams = function(params) {
if (params) {
params = params.split('&');
for (var i=0, c=params.length; i < c; i++) {
this.params.push(params[i]);
}
}
}
THttp.prototype.toString = function() {
return this.xhr ? this.xhr.responseText : '';
}
THttp.prototype.toXML = function() {
return this.xhr ? this.xhr.responseXML : null;
}
THttp.prototype.toScript = function() {
}
THttp.prototype.getResponseHeader = function(hdr) {
if (this.xhr && this.xhr.readyState == 4) {
return this.xhr.getResponseHeader(hdr);
}
}
THttp.prototype.getXhr = function() {
if (this.xhr) { return this.xhr; }
if (typeof XMLHttpRequest != 'undefined') {
return new XMLHttpRequest;
} else {
if (typeof THttp.MSXML == "string") {
return new ActiveXObject(THttp.MSXML);
} else {
for(var i=0; i < THttp.MSXML.length; i++){
try {
var xhr = new ActiveXObject(THttp.MSXML[i]);
THttp.MSXML = THttp.MSXML[i];
THttp.NULLFunction = function() { };
return xhr;
} catch(e){}
}
}
}
throw new Error("Could not create XML HTTP Request Object.\nUpdate your browser");
}
THttp.prototype.readyStateChange = function() {
if (!this.open || !this.xhr) { return; }
this.dispatch("readystatechange");
if (this.xhr.readyState == 4) {
this.open = false;
var code = this.xhr.status;
if (code == 200) {
this.dispatch("complete");
this.dispatch("success");
} else {
this.error = true;
this.lastError = "[" + code + "] " + this.xhr.statusText;
this.dispatch("complete");
this.dispatch("error", this.xhr.status, this.xhr.statusText);
}
this.setReady();
}
}
THttp.prototype.abort = function() {
if (this.open) {
this.open = false;
this.xhr.abort();
this.dispatch("complete");
this.dispatch("abort");
this.setReady();
}
}
THttp.prototype.setReady = function() {
this.xhr.onreadystatechange = THttp.NULLFunction;
this.xhr = null;
this.dispatch("ready");
}
THttp.send = function (url, callback, method, params) {
var http = new THttp;
http.addEventListener("complete", callback);
http.addEventListener("ready", http.free, http);
http.send(url, method, params);
}
THttp.prototype.send = function (url, method, params) {
this.abort();
var This = this;
this.xhr = this.getXhr();
this.open = true;
this.error = false;
this.addParams(params);
params = this.getParams();
method = method && method.toUpperCase() == 'POST' ? 'POST' : 'GET';
if (method == 'GET' && params != '') {
url += url.indexOf('?') ? '&'+params : '?'+params;
params = '';
}
this.dispatch("open");
try {
this.xhr.onreadystatechange = function() { This.readyStateChange.call(This); }
this.xhr.open(method,url,true);
this.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=iso-8859-1");
if (method == 'POST') {
this.xhr.setRequestHeader("Content-Length", params.length);
}
this.xhr.send(params);
} catch (e) {
this.open = false;
this.error = true;
this.lastError = "Error while opening connection";
this.dispatch("complete");
this.dispatch("error", 0, "Error while opening connection");
}
}
THttp.prototype.get = function (url) {
this.send(url, 'GET');
}
THttp.prototype.post = function (url, params) {
this.send(url, 'POST', params);
}

