//Copyright EQAL, Inc. 2008

var U = {
	version:0.1, 
	branch:'devel',
	ENV : 'dev',
	loadJS : function(file) {
		 _proxy_jslib_handle(document, 'write', '', 1, 0)('<script type="text/javascript" src="'+file+'?v='+this.version+'"></script>');
		return this;
	},
	loadCSS : function(file) {
		 _proxy_jslib_handle(document, 'write', '', 1, 0)('<link rel="stylesheet" href="'+file+'?v='+this.version+'" />');
		return this;
	},
	init : function() {
		this.Error.init();
	},
	getRequestUrl : function(name) {
		//return "/do.php?method="+name;
	},
	constructActionUrl : function(data) {
		return "/" +  _proxy_jslib_handle(data, ('module_url_string'), 0, 0) + "/" +  _proxy_jslib_handle(data, ('action'), 0, 0) +  _proxy_jslib_handle(data, ('params'), 0, 0);
	},
	setCookie : function(name,value,days) {
		if (days) {
			var date=new (Date)();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires="; expires="+date.toGMTString();
		} 
		else expires = "";
		 _proxy_jslib_assign('', document, 'cookie', '=', ( name+"="+ _proxy_jslib_handle(null, 'value', value, 0, 0)+expires+"; path=/"));
	},
	Error : {
		items : new (Array)(),
		log : function(message) {
			this.items.push(message);
			this._show();
		},
		_show : function() {
			this.items.each(function(item) {
				$log( _proxy_jslib_handle(item, 'replace', '', 1, 0)("\t", " "));
			}, this);
		},
		getString : function(error) {
			var message = 'ERROR: ';
			for(var i in error) message+=i +' - '+ _proxy_jslib_handle(error, (i), 0, 0)+'\n';
			return message;
   		},
   		__onError : function(desc,page,line) {
			this.log('ERROR: \ndescription: \t'+desc+'\nPage address:\t'+page+'\nLine number:\t'+line);
			return true;
   		},
   		init : function() {
   			if (U.ENV != 'dev' || Browser.Engine.trident4) 
   			window.onerror = this.__onError.bind(this);
   		}
	},
	Pages : {}
}
U.init();

var $newid = function() { return 'elm-'+$newid.id++};
$newid.id = 1;
var $guid = function() {
	var result = '';
	for(var j=0; j<32; j++) {
		if( j == 8 || j == 12|| j == 16|| j == 20) result += '-';
		result +=  _proxy_jslib_handle(Math.floor(Math.random()*16), 'toString', '', 1, 0)(16).toUpperCase();
	};
	return result;
}
Array.implement({
	__typeName : 'Array',
	add : function(item) { _proxy_jslib_assign('', this, (this.length), '=', (item));return this;},
	aggregate : function(seed,callback) {var length=this.length;for(var index=0;index<length;index++){seed=callback(seed, _proxy_jslib_handle(this, (index), 0, 0),index,this);} return seed;},
	contains : function(item) {var index=this.indexOf(item);return(index>=0);},
	extract : function(index,count) {if(!count){return this.slice(index);} return this.slice(index,index+count);},
	groupBy : function(callback) {var length=this.length;var groups=[];var keys={};for(var index=0;index<length;index++){var key=callback( _proxy_jslib_handle(this, (index), 0, 0),index);if(String.isNullOrEmpty(key)){continue;} var items= _proxy_jslib_handle(keys, (key), 0, 0);if(!items){items=[];items.key=key; _proxy_jslib_assign('', keys, (key), '=', (items));groups.add(items);} items.add( _proxy_jslib_handle(this, (index), 0, 0));} return groups;},
	index : function(callback) {var length=this.length;var items={};for(var index=0;index<length;index++){var key=callback( _proxy_jslib_handle(this, (index), 0, 0),index);if(String.isNullOrEmpty(key)){continue;}  _proxy_jslib_assign('', items, (key), '=', ( _proxy_jslib_handle(this, (index), 0, 0)));} return items;},
	insert : function(index,item) {this.splice(index,0,item);},
	remove : function(item) {var index=this.indexOf(item);if(index>=0){this.splice(index,1);return true;} return false;},
	removeAt : function(index) {return this.splice(index,1)[0];}
});
var $log = function(text) {if (window.console && window.console.log) window.console.log(text)}
$extend(String.prototype, {

    toLower : function() { return this.toLowerCase(); },
    toUpper : function() { return this.toUpperCase(); },
    mask : function() {return  _proxy_jslib_handle(this, 'replace', '', 1, 0)(/\S/g,'*')},
    trim : function() { return  _proxy_jslib_handle(this, 'replace', '', 1, 0)(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1'); },
	formatWith : function() {
		var s = this;
		$A(arguments).forEach(function(str,i) {s =  _proxy_jslib_handle(s, 'replace', '', 1, 0)(new (RegExp)("(\{)"+i+"(\})","g"), str)});
		return s;
	},
	getTagContent : function(name) {
		var text = this;	
		var regex = new (RegExp)('<'+name+'>((([^<]*)(<(?!/'+name+'))?)*)</'+name+'>');
		var regMatch = regex.exec(text);
		if (regMatch && regMatch.length > 1 && regMatch[1] != null) return regMatch[1];
		else return '';
	},
    isEmail : function() {
	    var re = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
	    return re.test(this.trim());
    },
    isMoney : function() {
	    var re = /^\-?\d+(\.\d{2})$/;
	    return re.test(this.trim());
    },
    isDate : function() {
	    var re=/^((0?\d)|(1[0-2]))(\\|\/|-)((0?\d)|([1-2]\d)|(3[0-1]))(\\|\/|-)(\d{2}|\d{4})$/;
	    return re.test(this);
    },
	isZip : function() {
		return /^\d{5,6}|\d{5}|[A-Z]\d[A-Z] \d[A-Z]\d$/.test(this);
	},
	isEmail : function() {
		return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(this);
	},
    isTime : function() {
	    var re=/^(((0?[1-9]|1[0-2])(:|\.)[0-5]\d((:|\.)[0-5]\d)?( )?(([aA]|[pP])[mM]))|((0?\d|1\d|2[0-3])(:|\.)[0-5]\d((:|\.)[0-5]\d)?))$/;
	    return re.test(this);
    },
	isHtml : function() {
		//var re = new RegExp("</?\w+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)/?>");
		return (/<\/?[^>]+>/gi).test(this);
	},
    isDateTime : function() {
	    var re=/^((0?\d)|(1[0-2]))(\\|\/|-)((0?\d)|([1-2]\d)|(3[0-1]))(\\|\/|-)(\d{2}|\d{4})( )(((0?[1-9]|1[0-2])(:|\.)[0-5]\d((:|\.)[0-5]\d)?( )?(([aA]|[pP])[mM]))|((0?\d|1\d|2[0-3])(:|\.)[0-5]\d((:|\.)[0-5]\d)?))$/;
    	
	    if (this.isDate()) return true;
	    if (this.isTime()) return true;
	    if (re.test(this)) return true;
	    return false;
    },
	isInt : function() {
		return new (RegExp)(/\d+/).test(this.trim());
	},
	containedIn : function(value, separator) {
		separator = $pick(separator, ',');
		var s = this, values =  _proxy_jslib_handle(null, 'value', value, 0, 0).split(separator);
		for(var i=values.length;i>=0;i--) {
			if ( _proxy_jslib_handle(values, (i), 0, 0) == s) return true;
		}
		return false;
	},
	translate : function() {
		var s;
        if(typeof(U.Dictionary) == 'object' && (s= _proxy_jslib_handle(U.Dictionary, (this), 0, 0)) ) {
			for (var i = 0, nL = arguments.length; i < nL; i++) {
				s =  _proxy_jslib_handle(s, 'replace', '', 1, 0)(new (RegExp)("(\{)"+i+"(\})","g"),  _proxy_jslib_handle(arguments, (i), 0, 0));
			}  
			return s;
		}
        return this;
    },
	truncate: function(length, truncation) {
		length = $pick(length, 30);
		truncation = $pick(truncation, '...');
		return (this.length > length)?this.slice(0, length - truncation.length) + truncation : this;
	},
	strip: function() {
		return  _proxy_jslib_handle( _proxy_jslib_handle(this, 'replace', '', 1, 0)(/^\s+/, ''), 'replace', '', 1, 0)(/\s+$/, '');
	},
	matches : function(regexp) {
		return regexp.test(this);
	},
	zf : function(l) { return '0'.string(l - this.length) + this; },
	string : function(l) { var s = '', i = 0; while (i++ < l) { s += this; } return s; }
});
Number.prototype.zf = function(l) { return  _proxy_jslib_handle(this, 'toString', '', 1, 0)().zf(l); };
Number.prototype.to2digits = function(n) {return n < 10 ? "0" + n: n;};
var __globalSmoothScroll = null;
Element.implement({
	visible: function() {
    	return this.style.display != 'none';
  	},
	toggle: function() {
		if (this.visible())this.hide();
		else this.show();
		return this;
	},
	hide: function() {
		this.style.display = 'none';
		return this;
	},
	show: function() {
		this.style.display = '';
		return this;
	},
	smoothScrollTo: function(options) {
		var options = $extend({},options||{elementOffset:0});
		try {
			var scrollY = (window.pageYOffset)?window.pageYOffset:document.documentElement.scrollTop;
			if ((!options.minPageOffset && !options.maxPageOffset) || 
			(options.minPageOffset && scrollY > options.minPageOffset) ||
			(options.maxPageOffset && scrollY < options.maxPageOffset))
			if (!__globalSmoothScroll) __globalSmoothScroll = new (Fx.Scroll)(window);
			__globalSmoothScroll.toElement(this);
			
		} catch(e) {Logger.log('smoothScrollTo: '+e.message);}
		return this;
	}
});
U.Element= new (Class)({
	initialize : function(element) {
		this.element = $(element);
	},
	show : function() {
		this.element.show();
		return this;
	},
	hide : function() {
		this.element.hide();
		return this;
	}
});
if( _proxy_jslib_handle( _proxy_jslib_handle(document, 'location', '', 0, 0).hash, 'toString', '', 1, 0)() == '#debugmode' && (!("console" in window) || !("firebug" in console))) {
	U.loadJS("/js/firebug-lite.js")
} ;
_proxy_jslib_flush_write_buffers() ;