/*
	Base, version 1.1
	Copyright 2006, Dean Edwards
	License: http://creativecommons.org/licenses/LGPL/2.1/
*/

/* end Base */
var Base=function(){};Base.prototype={extend:function(c){if(arguments.length>1){var d=this[c];var e=arguments[1];if(typeof e=="function"&&d&&/\bbase\b/.test(e)){var f=e;e=function(){var a=this.base;this.base=d;var b=f.apply(this,arguments);this.base=a;return b};e.method=f;e.ancestor=d}this[c]=e}else if(c){var g=Base.prototype.extend;if(Base._prototyping){var h,i=0,members=["constructor","toString","valueOf"];while(h=members[i++])if(c[h]!=Object.prototype[h]){g.call(this,h,c[h])}}else if(typeof this!="function"){g=this.extend||g}for(h in c)if(!Object.prototype[h]){g.call(this,h,c[h])}}return this},base:Base};Base.extend=function(b,c){var d=Base.prototype.extend;Base._prototyping=true;var e=new this;d.call(e,b);delete Base._prototyping;var constructor=e.constructor;var f=e.constructor=function(){if(!Base._prototyping){if(this._constructing||this.constructor==f){this._constructing=true;constructor.apply(this,arguments);delete this._constructing}else{var a=arguments[0];if(a!=null){(a.extend||d).call(a,e)}return a}}};for(var i in Base)f[i]=this[i];f.ancestor=this;f.base=Base.base;f.prototype=e;f.toString=this.toString;d.call(f,c);if(typeof f.init=="function")f.init();if(typeof f.pageReady=="function"&&Event)Event.pageReady?f.pageReady():Event.onDOMReady.add(f.pageReady,f);return f};Base=Base.extend({constructor:function(){this.extend(arguments[0])}},{ancestor:Object,base:Base,implement:function(a){if(typeof a=="function"){a(this.prototype)}else{this.prototype.extend(a)}return this}});
// Object
Object.extend = Object.merge = function (dest, src, bOverride) {
	dest = dest || {};
	if ( src ) {
		for (var prop in src) {
			if( dest[prop] && bOverride===false );
			else dest[prop] = src[prop];
		}	
	}
	return dest;
};
Object.extract = function(obj,name) {
	var rv = {};
	if (arguments.length ==2) { return obj[name]; }
	for(var i=1,l=arguments.length;i<l; i++) {
		var a = obj[arguments[i]];
		if ( a ) {rv[arguments[i]] = a;}
	}
	return rv;
};
Object.remove = function(obj, name){
	var rv = {};
	if ( arguments.length == 2) {
		var x = obj[name];
		delete obj[name];
		return x;
	}
	for(var i=1,l=arguments.length;i<l; i++) {
		var a = obj[arguments[i]];
		if ( a ) {
			rv[arguments[i]] = a;
			delete obj[arguments[i]];
		}
	}
	return rv;
};
Object.getType = function(obj){
	var t = typeof obj;
	if (obj===null){ t = 'null'; }
	else if (obj && obj.constructor == Array) { t = 'array'; }
	return t;
};
var Fp = Function.prototype;
Fp.bind = function(thisObj) {
	var __method = this, args = Array.from(arguments), obj = args.shift();
	return function() { return __method.apply(obj, args); };
};
Fp.delay = function(ms, thisObj) {
	var args = Array.from(arguments), ms = args.shift();
	return setTimeout(this.bind.apply(this, args),ms);
};

var Aris = Base.extend(null,{
	
	extend: function (obj) {
		return this.base(null,obj);
	},
	_guid: 0,
	
	version: "1.0.0",
	
	guid: function () { 
		return (typeof arguments[0] == 'string' ? arguments[0] + ++this._guid : ++this._guid);
	},
	
	popWin: function (url, name, width, height, center) {
		var win, opt = [];
		if (width || height) {
			height = height || 570;
			width = width || 770;
			opt.push('height='+ height,'width='+ width);
			if (center===false) { 
				opt.push('top=' + ( (screen.width) ? (screen.width-width)/2 : 0 )); 
				opt.push('left=' + ( (screen.height) ? (screen.height-height)/2 : 0 ));
			}
			opt.push('scrollbars=yes','resizable','menubar=1');
		}
		win = window.open(url,name,opt.join(',') );
		if (win) win.focus();
		return win;
	}
});

var Observer = function() {
	this.fns = [];
	this.locked = false;
};
Observer.prototype = {
	add: function(f,thisObj) {
		if (!f) return;
		if ( !this.fns.some( function (obj) { return obj.fn === f; }) )
			this.fns.push({fn:f, context:thisObj});
	},
	remove: function(fn) {
		this.fns = this.fns.filter( function(el) {
			if ( typeof fn == 'undefined' || (el.fn && el.fn !== fn) ) {
				delete el;
				return false;
			}
			return true;
		});
	},
	fire: function(sender, args) {
		if ( this.locked ) this.fire.delay(this, 10);
		var i = this.fns.length, el;
		if ( i == 0 ) return;
		this.locked = true;
		while(el = this.fns[--i]) {
			if ( el.fn.call(el.context, sender, args) === false ) break;
		}
		this.locked = false;
		return args;
	}
};

var Event = Base.extend(null,{

	all: [],
	onDOMReady: new Observer,
	onPageUnloading: new Observer,
	onPageLoad: new Observer,
	pageReady: false,
	_timer: null,

	_getCacheIndex: function(el, eType, fn) {
		for (var i=0,len=this.all.length; i<len; i++) {
			var li = this.all[i];
			if ( li && li[2] == fn && li[0] == el && li[1] == eType ) return i;
		}
		return -1;
	},
	
	_on: function() {
		var addEvent;
		if (document.addEventListener) {
			addEvent = function(element, type, handler) {
				element.addEventListener(type, handler, false);
			};
		} else if (document.attachEvent) {
			addEvent = function(element, type, handler) {
				element.attachEvent("on" + type, handler);
			};
		} else {
			addEvent = function(){}; // not supported
		}
		return addEvent;
	}(),
	
	_rem: function () {
		var removeEvent;
		if (document.removeEventListener) {
			removeEvent = function(element, type, handler) {
				element.removeEventListener(type, handler, false);
			};
		} else if (document.detachEvent) {
			removeEvent = function(element, type, handler) {
				element.detachEvent("on"+type, handler);
			};
		} else {
			removeEvent = function(){};
		}
		return removeEvent;
	}(),

	_ready: function() {
		if (!this.pageReady) {
			this.pageReady = true;
			this.onDOMReady.fire(this);
			this.onDOMReady.remove();
		}
	},

	
	add: function(el, eType, fn, scope) {
		if ( !el || !fn || !fn.call ) return false;
		
		if ( typeof el == "string" ) { 
			if ( this.pageReady ) { return this.add( document.getElementById(el), eType, fn, scope ); }
			else { this.onDOMReady.add( function() { Event.add(el, eType, fn, scope); } ); return true; } 
		}
		var wFn = (scope) ? this.bind(fn, scope, el) : this.bind(fn,el);
		
		var li = [el,eType,fn,wFn,scope];
		
		this.all.push(li);
		
		this._on(el,eType,wFn);
		
		return true;
		
	}, //end add
	
	bind: function(fn, obj, orig) {
		var __method = fn;
		return function(e) {
			return __method.call(obj,e||window.event,orig);
		};
	},
	
	init: function() {
		// for Mozilla/Opera 9
		if (document.addEventListener) {
		    document.addEventListener("DOMContentLoaded", this.bind(this._ready,this), false);
		}

		// for Internet Explorer (using conditional comments)
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		document.write("<script id=__ie_onload defer src=//:><\/script>");
		var script = document.getElementById("__ie_onload");
		var _this = this;
		script.onreadystatechange = function() {
		    if (this.readyState == "complete") {
		    	_this._ready(); // call the onload handler
		    }
		};
		/*@end @*/

		//for Safari/KTHML based browsers
		if (/KHTML/i.test(navigator.userAgent)) { // sniff
		    this._timer = setInterval(function() {
		        if (/loaded|complete/.test(document.readyState)) {
		           this._ready(); // call the onload handler
	        	}
		    }, 100);
		}		
		
		this.add(window, 'unload', this.unLoad, this);
		this.add(window, 'load', this.load, this);
	},

	load: function() {
		if ( !this.pageReady ) {
			this._ready();
		}	
		this.onPageLoad.fire(this);
	},
	
	preventDefault: function(ev) {
		if ( ev.preventDefault) { ev.preventDefault(); }
		else {ev.returnValue = false;}
	},
	
	remove: function(el,eType,fn,idx) {
		if (!el || !el.nodeName || !fn || !fn.call) return false;

		var cacheItem = null;
		if (typeof idx == "undefined") idx = this._getCacheIndex(el, eType, fn);
		if (idx >= 0) cacheItem = this.all[idx];
		if (!cacheItem) return false;
		
		this._rem(el, eType, cacheItem[3]);

		delete cacheItem[3];
		delete cacheItem[2];
		delete cacheItem;
		return true;
	},

	stopEvent: function(ev) {
		this.stopPropagation(ev);
		this.preventDefault(ev);
	},
	
	stopPropagation: function(ev) {
		if (ev.stopPropagation)
			ev.stopPropagation();
		else
			ev.cancelBubble = true;
	},
	
	unLoad: function(e) {
		this.onPageUnloading.fire(Event);
		this.all.forEach( function(l,idx) {
			this.remove(l[0],l[1],l[2],idx);
		},this);
	}
});

var DOM = {

	addClass: function(o, c1) {
		if(!this.hasClass(o, c1)) {
			o.className += o.className ?' ' + c1 : c1;
		}
	},

	hasClass: function(o, c1) {
		return new RegExp('\\b'+c1+'\\b').test(o.className)
	},

	clear: function(el) {
		while(el && el.hasChildNodes()) {
			el.removeChild(el.firstChild);
		}
	},

	create: function(elName, attr) {
		if (BOM.is('ie') && attr) {
			var el = [elName];
			['name','type'].forEach(function(val) {
				if (attr[val]){ el.push(val+'="'+attr[val]+'"'); delete attr[val]; }
			});
			if ( el.length > 1 ){ elName = '<'+el.join(' ')+'>'; }
		}
		var el = document.createElement(elName);
		if ( attr ) {
			var children = Object.remove(attr, 'children');
			forEach(attr, function(val, a) {
				if (a=='style'){ DOM.setStyle(el,val); }
				else{el[a] = val;}
			});
			if (typeof children =='string') children = [children];
			if ( children ) Array.from(children).forEach(function(c) {
				if ( typeof c == 'string' ) { el.appendChild(document.createTextNode(c)); }
				else if ( c.nodeType == 3 ) { el.appendChild(document.createTextNode(c.nodeValue)); }
				else if ( c.nodeType == 1 ) { el.appendChild(c); }
				else { el.appendChild( DOM.create(c.tag, c.attr) ); }
			});
		}
		return el;
	},

	get: function(el) {
		if (typeof el == 'string')
			el = document.getElementById(el);
		return el;
	},
	
	getElementsByTagName: function(root, tag) {
		var node = root||document;
		tag = tag || '*';
		var els = node.getElementsByTagName(tag);
		if( !els.length && (tag == '*' && node.all) ) els = node.all;
		return els;
	},
	
	getElementsByClass: function (searchClass,node,tag) {
		var cEls = [];
		var els = this.getElementsByTagName(node, tag);
		var elsLen = els.length;
		var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
		for (var i=0,j=0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) { cEls[j++] = els[i]; }
		}
		return cEls;
	},
	
	getStyle: function() {
		if (document.defaultView && document.defaultView.getComputedStyle) {
			return function(o,prop) {
				if (!o) return;
				prop = prop == 'float' ? 'cssFloat' : prop;
				var s = document.defaultView.getComputedStyle(o,'');
				return o.style[prop] || s ? s[prop] : null;
			};
		}
		else if (document.all) {
			return  function(o, prop) {
				if (!o) return;
				prop = prop == 'float' ? 'styleFloat' : prop;
				
				if ( prop == 'opacity' && window.ActiveXObject) {
					var val = 100;
                    try { // will error if no DXImageTransform
                        val = o.filters['DXImageTransform.Microsoft.Alpha'].opacity;
                    } catch(e) {
                        try { // make sure its in the document
                            val = o.filters('alpha').opacity;
                        } catch(e) { }
                    }
                    return val / 100;
				}
				else {
					return o.style[prop] || o.currentStyle[prop];
				}
			};
		}
		else {
			return function(o, prop) { if(!o) return; return o.style[prop] };
		}
	}(),
	
	removeClass: function(o, c1) {
		var rep = o.className.match(' '+c1) ? ' ' + c1 : c1;
		o.className=o.className.replace(rep,'');
	},
	
	setOpacity: function() {
		if (window.ActiveXObject) {
			return function(o, val) {
				o.style.filter = "alpha(opacity:"+val*100+")";
				if (!o.hasLayout) o.style.zoom = 1; 
			}
		}
		else {
			return function(o,val) {
				o.style.opacity = val<1 ? val : .999;
			};
		}
	}(),
	
	setStyle: function(el, style, val) {
		if ( !el ) return;
		if (arguments.length ==3 && val)
			style == "opacity" ?  DOM.setOpacity(el, val) :  el.style[style] = val;
		else {
			for( var s in style) {
				var val = style[s];
				if( typeof val != 'undefined') 
					s == "opacity" ? DOM.setOpacity(el, style[s]) :  el.style[s] = val;
			}
		}
	},

	swapClass: function(o,c1,c2) {
		o.className=!this.hasClass(o,c1) ? o.className.replace(c2,c1) : o.className.replace(c1,c2);
	},
	
	getPos: function(tEl, asArray) {
		var el = DOM.get(tEl);
		var pos = { top: 0, left: 0 };
		do {
			pos.top += el.offsetTop;
			pos.left += el.offsetLeft;
		} while( el = el.offsetParent );
		return asArray? [pos.top, pos.left] : pos;
	},
	
	getDim: function(tEl,asArray) {
		var tEl = DOM.get(tEl);
		var dim = {};
		dim.width = tEl.offsetWidth;
		dim.height = tEl.offsetHeight;
		return asArray ? [dim.width,dim.height] : dim;
	},
	
	getLayout: function(el) { return Object.extend( this.getPos(el), this.getDim(el) ); }
	
};
if ( window.Ext && Ext.query ) {
	DOM.match = Ext.query;
	DOM.matchOne = Ext.DomQuery.selectNode;
}

var BOM = function(){
	var ua = navigator.userAgent.toLowerCase();
	this.xpath = !!(document.evaluate);
	if (window.ActiveXObject) { this.ie = this[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true; }
	else if (document.childNodes && !document.all && !navigator.taintEnabled){ this.khtml = this.webkit = this[this.xpath ? 'webkit420' : 'webkit419'] = true; }
	else if (document.getBoxObjectFor !== null){ this.gecko = true; }
	this.mac = /mac/.test(ua);
	this.winCE = /windows ce/.test(ua);
	this.opera = /opera/.test(ua);
	return this;
}();

BOM.is = function() {
	return [].every.call(arguments, function(condition) {
			return this[condition] === true;
	},this);
};

Object.serialize = function(obj, s1, s2) {
	s1 = s1 || ':';
	s2 = s2 || ',';
	var rv = [];
	forEach(obj, function(val,name) {
		rv.push(name+s1+val);
	});
	return rv.join(s2);
};

var IConfigurable = Base.extend({
	config: null,
	setConfig: function(config) {
		if (!this.config ) this.config = {};
		forEach(config,function(opt,name) {
			this.config[name] = opt;
		},this);
		return this.config;
	}
});


Object.merge(Array.prototype,{
	//javascript 1.6 array functions forEach, every, some, filter
	forEach: function(fn,context) {
		for(var i=0,len=this.length;i < len; i++) {
			if(i in this)
				fn.call(context, this[i], i, this );
		}
	},

	filter: function(fn,context) {
		var rv = [];
		for (var i=0,len=this.length;i < len; i++) {
			if (i in this){
				if ( fn.call(context,this[i],i,this) )
					rv.push( this[i] );
			}
		}
		return rv;
	},

	every: function(fn,context) {
		var rv = true;
		for (var i=0,len=this.length;i < len; i++) {
			
			if (i in this && !fn.call(context,this[i],i,this) )
				return false;
		}
		return true;
	},

	some: function(fn,context) {
		for (var i=0,len=this.length;i < len; i++) {
			
			if( i in this && fn.call(context,this[i],i,this) )
				return true;
		}
		return false;
	},

	map: function(fn,context) {
		var len = this.length;
		var rv = new Array(len);
		for (var i=0; i < len; i++) {
			if(i in this)
				rv[i] = fn.call(context,this[i],i,this);
		}
		return rv;
	},

	indexOf: function(obj,start) {
		var len = this.length;
		var i = start || 0;
		if (i < 0) i += len;
		for (;start < len; i++) {
			if (i in this && this[i]===obj) 
				return i;
		}
		return -1;
	}
},false);

Array.from = function(iterable) {
	var rv = [];
	if ( !iterable ) return rv;
	if ( typeof iterable == 'string' ) return [iterable];
	
	for(var i=0,len=iterable.length; i < len; i++)
		if ( i in iterable ) rv.push(iterable[i]);
	return rv;
};

var iArray = {};
// array-like enumeration
if (!Array.forEach) { // mozilla already supports this
    Array.forEach = function(object, fn, context) {
        for (var i=0,len=object.length; i < len; i++) {
			if ( i in object ) fn.call(context, object[i], i, object);
        }
    };
}
iArray.forEach = Array.forEach;

// generic enumeration
Function.prototype.forEach = function(object, fn, context) {
    for (var key in object) {
        if (typeof this.prototype[key] == "undefined") {
            if( key in object) fn.call(context, object[key], key, object);
        }
    }
};

// globally resolve forEach enumeration
var forEach = function(object, fn, context) {
    if (object) {
        var resolve = Object; // default
        if (object instanceof Function) {
            // functions have a "length" property
            resolve = Function;
        } else if (object.forEach instanceof Function) {
            // the object implements a custom forEach method so use that
            object.forEach(fn, context);
            return;
        } else if (typeof object.length == "number") {
            // the object is array-like
            resolve = iArray;
        }
        resolve.forEach(object, fn, context);
    }
};

String.prototype.normalize = function(){
	return this.replace(/\s+/g, " ");
};
 
 DOM.addClass(document.documentElement, 'hasScript');