var jsCore = {
	version : '2.5',
	
	isFunction : function(obj) {
		return typeof obj=='function';
	},
	
	isObject : function(obj) {
		return typeof obj=='object' && !this.isFunction(obj);
	},
	
	isArray : function(obj) {
		return this.isObject(obj) && obj.constructor==Array;
	},
	
	isString : function(obj) {
		return typeof obj=='string';
	},
	
	getResolution : function(t) {
		if (!t) t = 'w';
		
		if (t == 'w') {
			if (window.innerWidth!=window.undefined) return window.innerWidth; 
			if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
			if (document.body) return document.body.clientWidth;
			return window.undefined;
		} else {
			if (window.innerHeight!=window.undefined) return window.innerHeight;
			if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
			if (document.body) return document.body.clientHeight;
			return window.undefined;
		}
	},
	
	getPosition : function(t) {
		if (!t) t = 't';
		
		var scLeft,scTop;
		if (self.pageYOffset) {
			scLeft = self.pageXOffset;
			scTop = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {
			scLeft = document.documentElement.scrollLeft;
			scTop = document.documentElement.scrollTop;
		} else if (document.body) {
			scLeft = document.body.scrollLeft;
			scTop = document.body.scrollTop;
		}
		
		return (t == 't') ? scTop : scLeft;
	},
	
	setCenter : function(obj,_fixed) {
		try {
			if (!_fixed) _fixed = true;
			obj = $(obj);
			
			var width = obj.offsetWidth;
			var height = obj.offsetHeight;
			
			var fullHeight = this.getResolution('h');
			var fullWidth = this.getResolution('w');
			var scLeft = this.getPosition('l');
			var scTop = this.getPosition('t');
			
			var topMargin = scTop + ((fullHeight - height) / 2);
			if (topMargin < 0) { topMargin = 0; }
			obj.style.top = topMargin + "px";
			obj.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
		}catch(err){
			jsError.where = 'jsCore.setCenter';
			jsError.display(err);
		}
	},
	
	getRandom : function(length) {
		if (!length) length = 10;
		var chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ234567890";
		var pass = '';
		for(x=0; x<length; x++) {
			i = Math.floor(Math.random() * 62);
			pass += chars.charAt(i);
		}
		return pass;
	},
	
	replaceChar : function(html, charCode, string) {
		var RegX = new RegExp(String.fromCharCode(charCode), 'g');
		html = html.replace(RegX, string);
		return html;
	},
	
	htmlEncode : function(value) {
		return !value ? value : String(value).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
	},
	
	money : function(v) {
		if (!v) v = '';
		if (v != '') {
			v = (Math.round((v-0)*100))/100;
			v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
		}
		return v;
	},
	
	hasClass : function(obj,cls) {
		return obj.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
	},
	
	keys : {
		BACKSPACE: 8,
		TAB: 9,
		CLEAR: 12,
		ENTER: 13,
		SHIFT: 16,
		CTRL: 17,
		ALT: 18,
		PAUSE: 19,
		CAPS_LOCK: 20,
		ESCAPE: 27,
		SPACE: 32,
		PAGE_UP: 33,
		PAGE_DOWN: 34,
		END: 35,
		HOME: 36,
		LEFT_ARROW: 37,
		UP_ARROW: 38,
		RIGHT_ARROW: 39,
		DOWN_ARROW: 40,
		INSERT: 45,
		DELETE: 46,
		HELP: 47,
		LEFT_WINDOW: 91,
		RIGHT_WINDOW: 92,
		SELECT: 93,
		NUMPAD_0: 96,
		NUMPAD_1: 97,
		NUMPAD_2: 98,
		NUMPAD_3: 99,
		NUMPAD_4: 100,
		NUMPAD_5: 101,
		NUMPAD_6: 102,
		NUMPAD_7: 103,
		NUMPAD_8: 104,
		NUMPAD_9: 105,
		NUMPAD_MULTIPLY: 106,
		NUMPAD_PLUS: 107,
		NUMPAD_ENTER: 108,
		NUMPAD_MINUS: 109,
		NUMPAD_PERIOD: 110,
		NUMPAD_DIVIDE: 111,
		F1: 112,
		F2: 113,
		F3: 114,
		F4: 115,
		F5: 116,
		F6: 117,
		F7: 118,
		F8: 119,
		F9: 120,
		F10: 121,
		F11: 122,
		F12: 123,
		F13: 124,
		F14: 125,
		F15: 126,
		NUM_LOCK: 144,
		SCROLL_LOCK: 145
	},
	
	makeArray : function(array,splitChar) {
		splitChar = splitChar || ',';
		if (this.isString(array)) {
			array = array.split(new RegExp('\\s*'+splitChar+'\\s*'));
		}
		
		return array;
	},
	
	format : function(str,array,splitChar) {
		array = this.makeArray(array);
		if (this.isArray(array)) {
			for(var i=0; i<array.length; i++) {
				str = str.replace(new RegExp('\\{'+i+'\\}', 'g'), array[i]);
			}
		}
		
		return str;
	}
}



$ = function(obj) {
	var nStyles = {
		'float' : jsInit.browser.isIE ? 'styleFloat' : 'cssFloat'
	};
			
	var inst=jsCore.isObject(obj)?obj:document.getElementById(obj);
	if (inst == null) {
		inst = document.getElementsByName(obj);
		if (inst.length == 0) inst = null;
		if (inst == null) return null;
	}
	if(inst.setStyle){
		return inst;
	}
		
	inst.setStyle = function(style,value) {
		try {
			var errors = '';
			if (jsCore.isArray(style) && jsCore.isArray(value)) {
				for(var i=0; i<style.length,i<value.length; i++) {
					if(this.getStyle(style[i])!=null){
						this.style[(!nStyles[style[i]]) ? style[i] : nStyles[style[i]]]=value[i];
					} else {
						errors+='\nThe style "' + style[i] + '" does not exists.';
					}
				}
			} else if (jsCore.isObject(style)) {
				for(s in style) {
					if(this.getStyle(s)!=null){
						this.style[(!nStyles[s]) ? s : nStyles[s]]=style[s];
					} else {
						errors+='\nThe style "' + style[s] + '" does not exists.';
					}
				}
			} else {
				if(this.getStyle(style)!=null){
					this.style[(!nStyles[style]) ? style : nStyles[style]]=value;
				} else {
					errors='The style "' + style + '" does not exists.';
				}
			}
			if(errors != '') throw(errors);
		}catch(err){
			jsError.where = 'setStyle';
			jsError.display(err);
		}
		return this;
	}
	
	inst.getStyle = function(style) {
		try {
			if (jsCore.isArray(style)) {
				var errors = '';
				var r = new Array();
				for(var i=0; i<style.length; i++){
					r[i]=this.style[(!nStyles[style[i]]) ? style[i] : nStyles[style[i]]];
					if (r[i]=='undefined') errors+='\nThe style "' + style[i] + '" does not exists.';
				}
				if (errors!='') throw(errors);
			} else {
				var r = this.style[(!nStyles[style]) ? style : nStyles[style]];
				if (r=='undefined') throw('The style "' + style + '" does not exists.');
			}
			return r;
		}catch(err){
			jsError.where = 'getStyle';
			jsError.display(err);
			return null;
		}
		
	}
	
	inst.hasStyle = function(style) {
		if (!this.getStyle(style)) {
			return false;
		} else {
			return true;
		}
	}
	
	inst.getParent = function() {
		return (jsInit.browser.isIE) ? $(this.parentElement) : $(this.parentNode);
	}
	
	inst.addEvent = function(evname,func) {
		try {
			if (jsCore.isFunction(func)) {
				if (jsInit.browser.isIE) {
					this.attachEvent('on' + evname, func);
				} else {
					this.addEventListener(evname, func, true);
				}
			}
		} catch(err) {
			jsError.where = 'addEvent';
			jsError.display(err);
		}
		return this;
	}
	
	inst.addClass = function(className) {
		try {
			if (jsCore.isArray(className)) {
				for(var i = 0, len = className.length; i < len; i++) {
					this.addClass(className[i]);
				}
			}else{
				if(className && !this.hasClass(className)){
					this.className = this.className + ' ' + className;
				}
			}
		} catch(err) {
			jsError.where = 'addClass';
			jsError.display(err);
		}
		return this;
	}
	
	inst.hasClass = function(className) {
		try {
			return className && (' '+this.className+' ').indexOf(' '+className+' ') != -1;
		} catch(err) {
			jsError.where = 'hasClass';
			jsError.display(err);
		}
	}
	
	inst.removeClass = function(className) {
		try {
			if (jsCore.isArray(className)) {
				for(var i = 0; i < className.length; i++) {
					this.removeClass(className[i]);
				}
			}else{
				if(jsCore.hasClass(this,className)){
					var re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', "g");
					this.className = this.className.replace(re, ' ');
				}
			}
		} catch(err) {
			jsError.where = 'removeClass';
			jsError.display(err);
		}
		return this;
	}
	
	inst.getLeft = function() {
		var obj = this;
		var curleft = 0;
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				curleft += obj.offsetLeft;
				obj = obj.offsetParent;
			}
		} else if (obj.x) {
			curleft += obj.x;
		}
		
		return curleft;
	}
	
	inst.getTop = function() {
		var obj = this;
		var curtop = 0;
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				curtop += obj.offsetTop;
				obj = obj.offsetParent;
			}
		} else if (this.y) {
			curtop += obj.y;
		}
		
		return curtop;
	}
	
	inst.setPng = function(img_path,type) {
		if (!type) type = 'scale';
		if (jsInit.browser.isIE) {
			this.setStyle('filter','progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=' + 
			type + ' src=' + img_path + ')');
		} else {
			this.setStyle('backgroundImage','url(' + img_path + ')');
		}
		return this;
	}
	
	inst.setFocus = function() {
		if (this.nodeName.toLowerCase() == 'input') {
			if (this.type != 'hidden' && this.getStyle('display') != 'none' && this.getStyle('visibility') != 'hidden') {
				this.focus();
			}
		}
		return this;
	}
	
	inst.setOpacity = function(val) {
		if (jsInit.browser.isIE) {
			this.setStyle('filter','alpha(opacity=' + val + ')');
		} else {
			this.setStyle('opacity',(val/100));
		}
		return this;
	}
	
	inst.hasAttr = function(val) {
		var a = eval("this."+val);
		var r = false;
		if (!a && !jsInit.browser.isIE) {
			r = this.hasAttribute(val);
		} else {
			if (a) {
				r = true;
			}
		}
		
		return r;
	}
	
	inst.getAttr = function(val) {
		var a = eval("this."+val);
		var r = '';
		if (this.hasAttr(val)) {
			if (!a && !jsInit.browser.isIE) {
				r = this.getAttribute(val);
			} else {
				if (a) {
					r = a;
				}
			}
		}
		
		return r;
	}
	
	inst.fx = function() {
		return jsEffects.setObj(this);
	}
	
	return inst;
}


String.prototype.trim = function() {
	var trimRe = /^\s+|\s+$/g;
	return this.replace(trimRe,'');
}

String.prototype.capitalize = function() {
	return this.charAt(0).toUpperCase() + this.substr(1).toLowerCase();
}

String.prototype.ellipsis = function(len) {
	if (!len) len = 0;
	return (this.length > len && len > 0) ? this.substr(0, len) + '...' : this;
}

String.prototype.InnerText = function() {
	var html = this;
	html = html.replace(/<[^>]*>/gi, '');
	html = html.replace(/\n/gi, '') ;
	html = html.replace(/&nbsp;/gi, '');
	html = jsCore.replaceChar(html,10,'');
	html = jsCore.replaceChar(html,13,'');
	html = html.trim(html);
	return html;
}

Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}

if(jsInit.browser.isIE){
	try{
		document.execCommand('BackgroundImageCache', false, true);
	}catch(e){}
}
