function openImage(img, path){
	try{if(newWin.closed==false) newWin.close();}catch(e){}
	if (path == "" || path == undefined) path = "";
	w=200;
	h=120;
	var left = Math.floor((screen.width-w)/2);
	var top = Math.floor((screen.height-h)/2);
	var setting="location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no,width="+w+",height="+h+",top="+top+",left="+left;
	newWin=window.open(path + "openimg.php?img="+img, 'popUp', setting);
	newWin.focus();
}

function openPopup(file, w, h){
	try{if(newWin.closed==false) newWin.close();}catch(e){}
	var left = Math.floor((screen.width-w)/2);
	var top = Math.floor((screen.height-h)/2);
	var setting="location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no,width="+w+",height="+h+",top="+top+",left="+left;
	newWin=window.open(file, 'popUp', setting);
	newWin.focus();
}

function xId(id){return document.getElementById(id)}


function $(id) {
	return document.getElementById(id);
}

function $T(tag) {
	return document.getElementsByTagName(tag);
}

Function.prototype.$B = function() {
	if (arguments.length < 2 && Util.isUndefined(arguments[0])) return this;
	var __method = this, args = Util.toArray(arguments), object = args.shift();
	return function() {
		return __method.apply(object, args.concat(Util.toArray(arguments)));
	}
}

Function.prototype.$BE=function() {
	var __method = this,args = Util.toArray(arguments), object = args.shift();
	return function(event) {
		return __method.apply(object,[event||window.event].concat(args));
	}
}

Function.prototype.$C = function() {
	if (!arguments.length) return this;
	var __method = this, args = Util.toArray(arguments);
	return function() {
		return __method.apply(this, args.concat(Util.toArray(arguments)));
	}
}


var Util = {
	IE: (window.attachEvent && !window.opera),
	Opera: window.opera,
	WebKit: (navigator.userAgent.indexOf('AppleWebKit/') > -1),
	Gecko: (navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1),
	popup: null,

	toArray: function(v) {
		if (!v) return [];
		var len = v.length || 0, results = new Array(len);
		while (len--) results[len] = v[len];
		return results;
	},
	$: function(id) {
		return document.getElementById(id);
	},


	/********** ARRAY **********/
	inArray: function(arr, elem) {
		for (var i = 0, n = arr.length; i < n; i++) {
			if (arr[i] == elem) return true;
		}
		return false;
	},

	/********** EVENT **********/
	addEvent: function(obj, eventName, handler) {
		if (obj.attachEvent) {
			obj['e' + eventName + handler] = handler;
			obj[eventName + handler] = function(){obj['e' + eventName + handler]( window.event );}
			obj.attachEvent('on' + eventName, obj[eventName + handler]);
		} else {
			obj.addEventListener(eventName, handler, false);
		}
	},
	fireEvent: function(element, eventName) {
		if (element == document && document.createEvent && !element.dispatchEvent) element = document.documentElement;
		var event;
		if (document.createEvent) {
			event = document.createEvent('HTMLEvents');
			event.initEvent(eventName, true, true);
			element.dispatchEvent(event);
		} else {
			event = document.createEventObject();
			element.fireEvent('on' + eventName, event);
		}
	},
	removeEvent: function(obj, eventName, handler) {
		if (obj.detachEvent) {
			obj.detachEvent('on' + eventName, obj[eventName + handler]);
			obj[eventName + handler] = null;
		} else {
			obj.removeEventListener(eventName, handler, false);
		}
	},
	targetElement: function(e) {
		var targ;
		if (e.target) {
			targ = e.target;
		} else if (e.srcElement) {
			targ = e.srcElement;
		}
		if (targ.nodeType == 3) targ = targ.parentNode;
		return targ;
	},
	isLeftClick: function(event) {
		if (Util.IE) {
			return event.button == 1;
		} else if (Util.WebKit) {
			return event.which == 1 && !event.metaKey;
		} else {
			return event.which ? (event.which === 1) : (event.button === 0);
		}
	},




	/********** ELEMENT **********/
	createElement: function(tag, attr, txt) {
		var obj = document.createElement(tag);
		if (attr != null && attr != undefined && attr != '') {
			for (var i in attr) {
				obj[i] = attr[i];
			}
		}
		if (txt != null && txt != undefined && txt != '') {
			obj.innerHTML = txt;
		}
		obj.observe = function(eventName, handler) {
			Util.addEvent(this, eventName, handler);
		}
		obj.setStyle = function(css) {
			for (var i in css) {
				if (i == 'float' || i == 'cssFloat' || i == 'styleFloat') {
					this.style[(obj.style.styleFloat == undefined) ? 'cssFloat' : 'styleFloat'] = css[i];
				} else if (i == 'opacity') {
					this.setOpacity(css[i]);
				} else {
					this.style[i] = css[i];
				}
			}
		}
		obj.setOpacity = function(value) {
			if (Util.IE) {
				var filter = this.style.filter;
				var noAlpha = filter.replace(/alpha\([^\)]*\)/gi,'');
				if (value == 1 || value == '') {
					this.style.filter = noAlpha ? noAlpha : '';
				} else {
					this.style.filter = noAlpha + 'alpha(opacity=' + (value * 100) + ')';
				}
			} else {
				this.style.opacity = (value == 1 || value === '') ? '' : (value < 0) ? 0 : value;
			}
		}
		obj.visible = function() {
			return (this.style.display == 'none') ? false : true;
		}
		obj.show = function() {
			this.style.display = '';
		}
		obj.hide = function() {
			this.style.display = 'none';
		}
		return obj;
	},

	positionedOffset: function(element) {
		var valueT = 0;
		var valueL = 0;
		do {
			valueT += element.offsetTop || 0;
			valueL += element.offsetLeft || 0;
			element = element.offsetParent;
		} while (element);
		return {left: valueL, top: valueT};
	},


	/********** NUMBER **********/
	roundValue: function roundVal(v, n) {
		var v = parseFloat(v);
		if (isNaN(v)) return 0;
		if (!Util.isNumber(n)) n = 2;
		var p = 10 ^ n;
		return Math.round(v * p) / p;
	},


	/********** MESSAGES **********/
	showMSG: function(value) {
		if (Util.isArray(value)) {
			value = value.join("\n");
		}
		alert(value);
	},


	/********** VALIDATOR **********/
	isArray: function(object) {
		return object != null && typeof object == "object" && "splice" in object && "join" in object;
	},

	isFunction: function(object) {
		return typeof object == "function";
	},

	isString: function(object) {
		return typeof object == "string";
	},

	isNumber: function(object) {
		return typeof object == "number";
	},

	isUndefined: function(object) {
		return typeof object == "undefined";
	},

	isEmail: function(val) {
		var filter=/^([a-zA-Z0-9_\-])+([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z]{2,4})$/;
		return filter.test(val);
	},
	
	isEmpty: function(val) {
		return (val == '' || val == null || val == undefined || (Util.isArray(val) && val.length == 0));
	},

	isAlphanumeric: function(val) {
		var filter=/^[_\.\-a-zA-Z0-9]{2,20}$/;
		return filter.test(val);
	},


	/********** IMAGE **********/
	getExt: function(fName) {
		var tmp = fName.substring(fName.lastIndexOf('.') + 1, fName.length);
		return tmp.toLowerCase();
	},
	openImage: function(path) {
		if (Util.$("x__IMAGEVIEW__LOCKWIN__x") == null) {
			var lockWin = Util.createElement('div', {id: "x__IMAGEVIEW__LOCKWIN__x"});
			lockWin.setStyle({left: '0px', top: '0px', width: '100%', height: '100%',  position: 'fixed', zIndex: 9999, display: "none", backgroundColor:"#999999", opacity: "0.5"});
			lockWin.onclick = function() {
				Util.$("x__IMAGEVIEW__LOCKWIN__x").hide();
				Util.$("x__IMAGEVIEW__IMAGE__x").hide();
			}
			document.body.appendChild(lockWin);
			var img = Util.createElement('img', {src: "", id: "x__IMAGEVIEW__IMAGE__x", alt: "", title: "", border: "0"});
			img.setStyle({left: '50%', top: '45%', position: 'fixed', zIndex: 9999, display: "none", backgroundColor: "#ffffff", border: "1px solid #666666"});
			img.onclick = function() {
				Util.$("x__IMAGEVIEW__LOCKWIN__x").hide();
				Util.$("x__IMAGEVIEW__IMAGE__x").hide();
			}
			document.body.appendChild(img);
		} else {
			var lockWin = Util.$("x__IMAGEVIEW__LOCKWIN__x");
			var img = Util.$("x__IMAGEVIEW__IMAGE__x");
		}
		lockWin.show();
		//img.src = "../images/loading.gif";
		//img.setStyle({width: "35px", height: "35px", margin: "-40px 0px 0px -40px", padding: "45px"});
		//img.show();
		var oImg = new Image();
		oImg.onload = function(obj, path) {
			obj.hide();
			obj.width = this.width;
			obj.height = this.height;
			obj.setStyle({padding: "0px"});
			obj.src = path;
			obj.setStyle({width: this.width + "px", height: this.height + "px", margin: '-' + (this.height / 2) + 'px 0px 0px -' + (this.width / 2) + 'px'});
			obj.show();
		}.$C(img, path);
		oImg.src = path;
	},



	/********** POPUP **********/
	openPopup: function(file, w, h){
		try{
			if(Util.popup == false) Util.popup.close();
		} catch(e) {}
		var x = Math.floor((screen.width - w) / 2);
		var y = Math.floor((screen.height - h) / 2);
		var setting="location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no,width=" + w + ",height=" + h + ",top=" + y + ",left=" + x;
		Util.popup = window.open(file, 'PopUp', setting);
		Util.popup.focus();
	},



	/********** SWF **********/
	getSWF: function(fileName, w, h, bgColor, flashVars) {
		if (bgColor == "") bgColor = "#FFFFFF";
		var str = '<object width="' + w + '" height="' + h + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">';
		if (flashVars != "") str += '<param name="flashVars" value="' + flashVars + '">';
		str += '<param name="movie" value="' + fileName + '">';
		if (bgColor == "transparent") {
			str += '<param name="wmode" value="transparent">';
		} else {
			str += '<param name="bgcolor" value="' + bgColor + '">';
		}
		str += '<param name="allowScriptAccess" value="sameDomain">';
		str += '<param name="quality" value="high">';
		str += '<param name="scale" value="exactfit">';
		str += '<param name="id" value="index">';
		str += '<param name="align" value="">';
		str += '<param name="hspace" value="0">';
		str += '<param name="vspace" value="0">';
		str += '<param name="menu" value="false">';
		str += '<embed src="'+fileName+'" ';
		if (flashVars != "") str += 'flashVars="' + flashVars + '" ';
		str += 'width="' + w + '" height="' + h + '" ';
		if (bgColor == "transparent") {
			str += 'wmode="transparent" ';
		} else {
			str += 'bgcolor="'+bgColor+'" ';
		}
		str += 'quality="high" menu="false" allowScriptAccess="sameDomain" type="application\/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
		str += '<\/object>';
		return str;
	}
}



var Tooltip = {
	tooltip: null,
	mOver: false,
	show: function(val, ev) {
		if (this.tooltip == null) {
			this.tooltip = Util.createElement('div', {className: 'tooltip'});
			this.tooltip.setStyle({position: 'absolute', visibility: 'hidden', left: '0px', top: '0px'});
			this.tooltip.observe('mouseover', function() {Tooltip.mOver = true});
			this.tooltip.observe('mouseout', function() {Tooltip.mOver = false});
			document.body.appendChild(this.tooltip);
		}
		this.tooltip.innerHTML = unescape(val);
		var w = this.tooltip.offsetWidth;
		this.tooltip.setStyle({left: (ev.clientX - w) + 'px', top: (ev.clientY + 4) + 'px'});
		this.tooltip.setStyle({visibility: 'visible'});
	},
	hide: function() {
		if (this.tooltip != null) {
			this.tooltip.setStyle({visibility: 'hidden'});
			this.mOver = false;
		}
	}
}

