﻿cj = {
	 version : '1.0'
	,modify : '2009/04/17'

	,files : {}
	,elm : []

	,init : function(set){
		var t = this,  na = navigator, ua = na.userAgent, src, ss;
		t.d = document;
		t.w = window;
		t.b = t.d.documentElement || t.d.body;

		t.isOpera = t.w.opera && opera.buildNumber;
		t.isWebKit = /WebKit/.test(ua);
		t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName);
		t.isIE6 = t.isIE && /MSIE [56]/.test(ua);
		t.isIE7 = t.isIE && /MSIE [7]/.test(ua);
		t.isGecko = !t.isWebKit && /Gecko/.test(ua);
		t.isMac = ua.indexOf('Mac') != -1;
		t.isAir = /adobeair/i.test(ua);

		ss = document.getElementsByTagName('script');
		for(var i=0, l=ss.length; i<l; i++){
			src = ss[i].src;
			if(src && /cj\.js/.test(src)){
				t.base = src.substring(0, src.lastIndexOf('/')) + '/';
				break;
			}
		}
		if(set&&set.require){
			t.util.each(set.require.split(','), function(s){
				if(t.files[s]) return;
				t.files[s] = true;
				s = t.base + s + '.js';
				t.util.loadJs(s);
			});
		}
		t.util.loadCss(t.base + 'res/cj.css');
		t.vp = t.util.getVP();
		if(t.isIE6) cj.evt.add(cj.w,'load',t.util.fixPng);
	}
    ,evt : {
		 guid : 1
		,add : function (elm, type, handler){
			if(elm.addEventListener){
				elm.addEventListener(type, handler, false);
			}else if (elm.attachEvent){
				elm.attachEvent('on' + type, handler);
			}else{
				if (!handler.$$guid){
					handler.$$guid = this.guid++;
				}
				if (!elm.events){
					elm.events = {};
				}
				var handlers = elm.events[type];
				if (!handlers){
					handlers = elm.events[type] = {};
					if(elm['on' + type]){
						handlers[0] = elme['on' + type];
					}
				}
				handlers[handler.$$guid] = handler;
				elm['on' + type] = this.handleEvent;
			}
			return handler;
		}
		,remove : function(elm, type, handler){
			if (elm.removeEventListener){
				elm.removeEventListener(type, handler, false);
			}else{
				if (elm.events && elm.events[type]){
					delete elm.events[type][handler.$$guid];
				}
			}
		}
		,cancel : function(e){
			e.cancelBubble = true;
			if(e.stopPropagation){
				e.stopPropagation();
			}
		}
	}
	,util : {
		is : function(o, type){
			return (typeof o == type);
		}
		,getMousePos : function(ev){
			return (ev.pageX && ev.x) ? {'x':ev.pageX, 'y':ev.pageY} : {'x':ev.clientX+this.getScrollPos().x, 'y':ev.clientY+this.getScrollPos().y}
		}
		,getScrollPos : function(){
			return {
				x : document.documentElement.scrollLeft || document.body.scrollLeft
				,y : document.documentElement.scrollTop || document.body.scrollTop
			}
		}
		,getWindowSize : function(){
			var b = cj.d.documentElement || cj.d.body;
			return { w:b.scrollWidth, h:b.scrollHeight}
		}
		,getSize : function(n) {
			var t = this, w, h;
			w = n.style.width;
			h = n.style.height;
			if (w.indexOf('px') === -1) w = 0;
			if (h.indexOf('px') === -1) h = 0;
			return {
				w : parseInt(w) || n.offsetWidth || n.clientWidth,
				h : parseInt(h) || n.offsetHeight || n.clientHeight
			};
		}
		,getScrollWidth : function(){
			var
				c = cj.util.addElm(cj.d.body, {tag:'div', cssText:'position:absolute;top:-1000px;left:-1000px;width:50px;height:50px;overflow:hidden'}),
				n = cj.util.addElm(c, {tag:'div', cssText:'width:100%;height:60px;'}),
				w1, w2
			;
			w1 = n.offsetWidth;
			c.style.overflow = 'auto';
			w2 = n.offsetWidth;
			cj.d.body.removeChild(c);
			return Math.max(21,w1-w2);
		}
		,getVP : function(){
			return {
				 x : cj.w.pageXOffset || cj.b.scrollLeft
				,y : cj.w.pageYOffset || cj.b.scrollTop
				,w : cj.w.innerWidth || cj.b.clientWidth
				,h : cj.w.innerHeight || cj.b.clientHeight
				,ws : {w:cj.b.scrollWidth, h:cj.b.scrollHeight}
				,sp : {
					x:cj.w.pageXOffset || cj.b.scrollLeft
					,y:cj.w.pageYOffset || cj.b.scrollTop
				}
			}
		}
		,getElmSize : function(n){
			return {
				w : n.clientWidth
				,h : n.clientHeight
			}
		}
		,getPos : function(n){
			var x = y = 0;
	   		while(n){
	   			if(n.style.left) return{x:parseInt(n.style.left)||0, y:parseInt(n.style.top)||0}
	   			if(n.style.left){
	   				x += parseInt(n.style.left)||0;
	   				y += parseInt(n.style.top)||0;
	   				break;
	   			}else{
	   				x += n.offsetLeft;
		   			y += n.offsetTop;
		   		}
	   			n = n.offsetParent;
	   		}
	   		return {x:x,y:y};
	   	}
	   	,getElmPos : function(n){
			var x = y = 0;
	   		while(n){
	   			x += n.offsetLeft;
		   		y += n.offsetTop;
	   			n = n.offsetParent;
	   		}
	   		return {x:x,y:y};
	   	}
		,getAbsPos : function(n){
			return { x:parseInt(n.style.left)||0, y:parseInt(n.style.top)||0}
	   	}
	   	,getStyle : function(n, s){
			if (n.currentStyle){
				return n.currentStyle[s];
			}else if (cj.w.getComputedStyle){
				return cj.d.defaultView.getComputedStyle(n,null).getPropertyValue(s);
			}
			return x;
	   	}
	   	,setStyle : function(n, set){
	   		var s = n.style;
	   		for(var k in set){
	   			v = set[k];
	   			switch(k){
	   				case 'opacity':
	   					this.setOpacity(n, v);
	   				break;
	   				case 'zIndex':
	   					s.zIndex = v;
	   				break;
	   				default :
	   					if(cj.util.is(v, 'number') || /^[\-0-9\.]+$/.test(v)) v += 'px';
	   					s[k] = v;
	   				break;
	   			}
			}
	   	}
		,fix_ieflash : function() {
			var objects = document.getElementsByTagName('object');
			for (var i=0;i<objects.length;i++)
				objects[i].outerHTML = objects[i].outerHTML;
		}
		,loadJs : function(s){
		   	var h = document.getElementsByTagName('head')[0];
		   	o = this.addElm(h, [{tag : 'script', attrib : 'type:text/javascript;src:'+s}]);
		}
		,loadCss : function(u){
			var u = u || ''
			var h = document.getElementsByTagName('head')[0]
			this.each(u.split(','), function(u){
				if(cj.files[u]) return;
				cj.files[u] = true;
				cj.util.addElm(h, {tag:'link',attrib:'rel:stylesheet;type:text/css;href:'+u});
			});
		}
		,addElm : function(p, set){
			var i, o, t = this;
			if(t.is(set,'string') || !set.length){
				o = p.appendChild(this.createElm(set));
			}else{
				o = p.appendChild(t.createElm(set[0]));
				for(var i=1, l=set.length; i<l; i++){
					t.addElm(o, set[i]);
				}
			}
			return o;
		}
		,createElm : function(set){
			var o, a , s, d = document, t = this;
			o = t.is(set, 'string')
				? d.createTextNode(set)
				: d.createElement(set.tag);
			if(set.id){
				o.id = set.id;
				cj.elm[set.id] = o;
			}
			if(set.cssText) o.style.cssText = set.cssText;
			if(set['class']){
				o.className = set['class'];
			}
			if(set.innerHTML) o.innerHTML = set.innerHTML;
			if(set.style) t.setStyle(o, set.style);
			if(set.attrib){
				cj.util.each(set.attrib.split(';'), function(s){
					if(s.indexOf(':') != -1){
						n = s.indexOf(':');
						k = s.substr(0, n).replace(/\s+/g);
						v = s.substr(n+1, s.length);
						o.setAttribute(k, v)
					}
				});
			}
			return o;
		}
		,removeChild : function(n){
			try{
				if(n.firstChild){
					while(n.firstChild){
						if(n.firstChild.firstChild) this.removeChild(n.firstChild);
						else n.removeChild(n.firstChild);
					}
				}
				n.parentNode.removeChild(n);
			}catch(e){}
		}
		,setOpacity : function(o, v){
			if(!o){
				alert('setOpacity : o is nto defined');
				return;
			}
			if(v<0.1){
				o.style.display = 'none';
				return;
			}
			if(typeof o.style.opacity != 'undefined'){
				o.style.opacity = (v == 1) ? 0.9999999 : v;
			}else if (typeof o.style.MozOpacity != 'undefined'){
				o.style.MozOpacity = (v == 1) ? 0.9999999 : v;
			}else if (typeof o.style.KhtmlOpacity != 'undefined'){
				o.style.KhtmlOpacity = v;
			}else{
				o.style.filter = 'alpha(opacity=' + Math.floor(v*100) + ')';
			}
		}
		,each : function(o, cb, s){
			if(!o) return 0;
			var s = s || o;
			if(typeof(o.length) != 'undefined'){
				for(var i=0, l=o.length; i<l; i++){
					if(cb.call(s, o[i], i, o) === false) return 0;
				}
			}else{
				for (var i in o){
					if(o.hasOwnProperty(i)){
						if(cb.call(s, o[i], i, o) === false){
							return 0;
						}
					}
				}
			}
			return 1;
		}
		,ieMask : function (n){
			var t = this, s = n.style, ieMask;
			ieMask = t.addElm(cj.d.body, {tag:'iframe','class':'cjIEMask',attrib:'frameBorder:0,src:javascript:""'});
			cj.util.setStyle(ieMask, {
				width :  cj.util.getElmSize(n).w
				,height : cj.util.getElmSize(n).h
				,left : s.left
				,top : s.top
				,zIndex : s.zIndex-1
				,opacity : 0
			});
			n.ieMask = ieMask;
		}
		,winMask : function(n){
			n.showMask = function(){
				//cj.util.setStyle(cj.b, {overflow:'hidden'});
				var t = this, s = t.style||{}, vp = cj.util.getVP();
				if(!cj.mask) cj.mask = cj.util.addElm(cj.d.body, {tag: 'div', 'class':'cjIEMask'});
				if(!s.zIndex) s.zIndex = 1000;
				cj.util.setStyle(cj.mask, {
					 width :  Math.max(vp.w,vp.ws.w)
					,height : Math.max(vp.h,vp.ws.h)
					,left : 0
					,top : 0
					,opacity : 0.1
					,visibility : 'visible'
					,zIndex : s.zIndex-1
				});
				cj.fade.fps = 20;
				cj.fade.start(cj.mask, 0.2, 0.1, 0.6);
			}
			n.hideMask = function(){
				if(!cj.mask) return;
				//cj.util.setStyle(cj.b, {overflow:'hidden'});
				cj.util.setStyle(cj.mask, {visibility : 'hidden', left:-10000, top:-10000});
				//cj.d.body.removeChild(cj.mask);
				//cj.mask = null;
			}
		}
		,disableSelect : function(){
			if(!cj.d.onselectstart) cj.d.onselectstart = function(){return false};
			if(!cj.d.onmousedown) cj.d.onmousedown = function(){ return false};
		}
		,enableSelect : function(){
			if(cj.d.onselectstart) cj.d.onselectstart = null;
			if(cj.d.onmousedown) cj.d.onmousedown = null;
		}
		,countDown : {
			init : function(){
				var t = this;
				t.n = cj.d.getElementById('cjCountDown');
				if(!t.n) return;
				t.n.sec = t.n.getAttribute('sec');
				t.start();
			}
			,start : function(){
				var t = this;
				t.n.sec = Math.max(1, t.n.sec);
				t.n.innerHTML = t.n.sec;
				t.n.sec --;
				setTimeout(function(){cj.util.countDown.start();}, 1000);
			}
		}
		,getElementsByIds : function(ids, debug){
			var n = {}, f = ids.split(',');
			for(i=0; i<f.length; i++){
				if(!(n[f[i]]=cj.d.getElementById(f[i]))){
					if(debug) alert(f[i]+'not found!');
					return null;
				}
			}
			n.toString = function(){return ids};
			return n;
		}
		,fixPng : function(){
			if(!cj.isIE6) return;
			var n = cj.d.getElementsByTagName('*')
				,ip=/\.png/i
				,al="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
				,blank = 'images/spacer.gif';
			cj.util.each(n, function(el){
				var es=el.style
					,elc=el.currentStyle
					,elb=elc.backgroundImage;
				if(el.src&&el.src.match(ip)&&!es.filter){
					es.height=el.height;
					es.width=el.width;
					es.filter=al+el.src+"',sizingMethod='crop')";
					el.src=blank;
				}else{
					if(elb.match(ip)){
						var path=elb.split('"')
							,rep=(elc.backgroundRepeat=='no-repeat')?'crop':'scale'
							,elkids=el.getElementsByTagName('*')
							,j=elkids.length;
						es.filter=al+path[1]+"',sizingMethod='"+rep+"')";
						es.height=el.clientHeight+'px';
						es.backgroundImage='none';
						if(j!=0){
							if(elc.position!="absolute")es.position='static';
							while(j-->0)
								if(!elkids[j].style.position)elkids[j].style.position="relative";
						}
					}
				}
			});
		}
		,releaseSelection : function(){
			if(cj.d.selection && cj.d.selection.empty) cj.d.selection.empty();
			if(cj.w.getSelection){
				var s = cj.w.getSelection();
				if(s.removeAllRanges) s.removeAllRanges();
			}
		}
	}
	,ajax : {
		// {URL:, onComplete:, cb:}
		open : function(set){
			var t = this, req = this.getReq();
			if (!req) return;
			if(!set.disableLoadding){
				var p = cj.loadding.newPlayer();
				p.timer = setTimeout(function(){
					p.stop();
					alert('連線逾時，系統暫時無法回應您的要求。\n請重新整理網頁後，再試一次。');
				},10*1000);
				p.play();
			}
			if(set.onStart)	set.onStart();
			method = (set.postData) ? 'POST' : 'GET';
			req.open(method, set.URL, true);
			req.setRequestHeader('User-Agent', 'XMLHTTP');
			if (set.postData) req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			req.onreadystatechange = function(){
				if(cj.isIE6){
					try{
						if(typeof req.responseText == 'string'){
							setTimeout(function(){
								if(set.onComplete) set.onComplete(req);
								if(set.cb) set.cb(req);
							}, 100);
							req.onreadystateChange = function(){};
							if(!set.disableLoadding){
								p.stop();
								clearTimeout(p.timer);
							}
						}
					}catch(e){alert('Connection timeout, please try again');}
				}else if(this.readyState === 4 || typeof this.readyState == 'undefined'){
					setTimeout(function(){
						if(set.onComplete) set.onComplete(req);
						if(set.cb) set.cb(req);
					}, 100);
					req.onreadystateChange = function(){};
					if(!set.disableLoadding){
						p.stop();
						clearTimeout(p.timer);
					}
				}
			}
			if (req.readyState == 4) return;
			req.send(set.postData);
		}
		,getReq : function(){
			var req = null;
			var factories = [
				function() { return new XMLHttpRequest()}
				,function(){ return new ActiveXObject('Msxml2.XMLHTTP')}
				,function(){ return new ActiveXObject('Msxml3.XMLHTTP')}
				,function(){ return new ActiveXObject('Microsoft.XMLHTTP')}
			];
			for (var i=0; i<factories.length; i++){
				try{
					req = factories[i]();
				}catch(e){ continue;}
				break;
			}
			return req;
		}
	}
	,drag : function(n, ev){
		var ev = ev || cj.w.event;
		var t = this, b = cj.d.documentElement || t.d.body, ws, vp, mdp, np, ns, tag, min_dx, max_dx;
		vp = t.util.getVP();
		vp.w -= 2;
		vp.h -= 2;
		ws = t.util.getSize(b);
		ws.w = Math.max(vp.w, ws.w);
		ws.h = Math.max(vp.h, ws.h);
		mdp = t.util.getMousePos(ev);
		np = t.util.getElmPos(n);
		ns = t.util.getSize(n);

		tag = (t.isIE6) ? 'iframe' : 'div';
		min_dx = vp.x - np.x;
		max_dx = vp.x + vp.w - np.x - ns.w;

		if(!t.bodyMask) t.bodyMask = cj.util.addElm(t.d.body, {tag:tag, 'class':'cjBodyMask',style:{opacity:0.5}});
		t.util.setStyle(t.bodyMask, {width:vp.w+'px', height:vp.h+'px', zIndex:parseInt(n.style.zIndex)-100, display:'block'});

		if(!n.cp) n.cp = cj.util.addElm(t.d.body, {tag:tag, 'class':'cjMoveMask', style:{opacity:0.5}});
		t.util.setStyle(n.cp, {width:n.style.width, height:n.style.height, left:n.style.left, top:n.style.top, zIndex:parseInt(n.style.zIndex)+1, display:'block'});

		t.util.disableSelect();
		mu = t.evt.add(cj.d, 'mouseup', function(){
			t.util.enableSelect();
			t.evt.remove(cj.d, 'mouseup', mu);
			t.evt.remove(cj.d, 'mousemove', mm);
			t.util.setStyle(n, {width:n.cp.style.width, height:n.cp.style.height, left:n.cp.style.left, top:n.cp.style.top});
			n.cp.style.display = 'none';
			n.blur();
			t.bodyMask.focus();
			t.bodyMask.style.display = 'none';
			b.style.overflow = 'auto';
			t.evt.cancel(ev);
			cj.util.releaseSelection();
		});
		mm = t.evt.add(t.d, 'mousemove', function(ev){
			var dx = dy = 0;
			var ev = ev || cj.w.event;
			var mmp = cj.util.getMousePos(ev);

			dx = mmp.x - mdp.x;
			dy = mmp.y - mdp.y;
			dx = Math.max(dx, vp.x - np.x);
			dx = Math.min(dx, vp.x + vp.w - np.x - ns.w);
			dy = Math.max(dy, vp.y - np.y);
			dy = Math.min(dy, vp.y + vp.h - np.y - ns.h);

			if(dx + dy != 0){
				n.cp.style.left = np.x + dx + 'px';
				n.cp.style.top = np.y + dy + 'px';
			}
			t.evt.cancel(ev);
		});
		t.evt.cancel(ev);
	}
	,fade : {
		fps : 10,
		start : function(n, time, start, end){
			var t = this;
			n.steps = (end - start) / (time * t.fps) ;
			n.timer = null;
			t.dofade(n, start, end);
		}
		,dofade : function (n, current, end){
			var t = this, dir
			dir = (n.steps > 0);
			current += n.steps;
			cj.util.setOpacity(n, current);

			if (dir ^ (current - end > 0)){
				n.timer = setTimeout(function(){ cj.fade.dofade(n, current, end)}, 1000/t.fps);
			}else{
				clearTimeout(n.timer);
				n.timer = null;
			}
		}
	}
	,popMsg : {
		div : null,
		move : 10,
		timer : null,
		holdTime : 3 * 1000,
		init : function(msg, pos, size, holdTime){
			var t = this;
			t.size = size || {w:100, h:20}
			if(holdTime) t.holdTime = holdTime * 1000;
			t.clear();
			t.div = cj.util.addElm(cj.d.body, {tag:'div', 'class':'cjPopMsg', innerHTML:msg, style:{left:pos.x,top:pos.y} });
			this.show();
		}
		,show : function(step){
			var t = this, w, h;
			step = step || 1;
			if(t.div.offsetWidth < t.size.w){
				w = Math.abs((t.size.w/t.move)*step);
				h = Math.abs((t.size.h/t.move)*step);
				cj.util.setStyle(t.div, {width:w,height:h});
				t.timer = setTimeout( function(){ cj.popMsg.show(++step) }, 1 );
			}else{
				t.timer = setTimeout( function(){cj.popMsg.clear()}, t.holdTime);
			}
		}
		,clear : function(){
			if (this.div){
				clearTimeout(this.timer);
				this.timer = null;
				cj.d.body.removeChild(this.div);
				this.div = null;
			}
		}
	}
	,form : {
		chk : function(f, fields){
			if(!f)	return false;
			if(typeof f.lang == 'undefined' || !f.lang){
				alert('lang not set');
				return false;
			}
			var lang = f.lang.value;

			for (var i=0; i<fields.length; i++){
				var a = fields[i].split(',');
				var obj = f[a[0]];
				if(!obj){
					alert(a[0] + ' not set');
					return false;
				}
				var type = a[1];
				if(!type){
					alert(a[1] + ' not set');
					return false;
				}
				var title = obj.getAttribute('title');
				if(!title){
					alert(a[0] + ' title not set');
					return false;
				}
				var pos = cj.util.getElmPos(obj);
				var size = {w:100,h:30}
				//pos.x +=  obj.offsetWidth - size.w;
				pos.x +=  obj.offsetWidth;
				var t = 3;
				switch (type){
					case 'num':
						obj.value = cj.form.trim(obj.value);
						if( !cj.form.isNumber(obj.value)){
							obj.focus();
							cj.popMsg.init(title + cj.form.msg.not_number[lang], pos, size, t);
							return false;
						}
					case 'text':
						if(obj.value== ''){
							obj.focus();
							cj.popMsg.init(title + cj.form.msg.not_null[lang], pos, size, t);
							return false;
						}
					break;
					case 'date':
						if(!cj.form.isDate(obj.value)){
							obj.focus();
							cj.popMsg.init(title + cj.form.msg.not_null[lang], pos, size, t);
							return false;
						}
					break;
					case 'email':
						if(!cj.form.isEmail(obj.value)){
							obj.focus();
							cj.popMsg.init(cj.form.msg.valid[lang] + title, pos, size, t);
							return false;
						}
					break;
					case 'account':
						if(!cj.form.isAccount(obj.value)){
							obj.focus();
							cj.popMsg.init(cj.form.msg.valid[lang] + title, pos, size, t);
							return false;
						}
					break;
					case 'password':
						if(!cj.form.isPasswd(obj.value)){
							obj.focus();
							cj.popMsg.init(cj.form.msg.valid[lang] + title, pos, size, t);
							return false;
						}
						if(obj.getAttribute('confirm')){
							var passwd2 = f[obj.getAttribute('confirm')];
							if(passwd2){
								if(obj.value != passwd2.value){
									passwd2.focus();
									cj.popMsg.init(cj.form.msg.valid[lang] + passwd2.getAttribute('title'), pos, size, t);
									return false;
								}
							}
						}
					break;
					case 'checkbox':
						if(!obj.checked){
							obj.focus();
							cj.popMsg.init(obj.getAttribute('title'),pos, size, t);
							return false;
						}
					break;
					case 'creditCard':
						var cardname = document.getElementById(obj.getAttribute('cardName'));
						if (!cardname){
							alert('Attribute : cardName not set');
							return false;
						}
						if(!cj.form.checkCreditCard.check(cardname.value, obj.value)){
							obj.focus();
							cj.popMsg.init(cj.form.msg.valid[lang] + title, pos, size, t);
							return false;
						}
					break;
					case 'sid':
						if(!cj.form.isSid(obj.value)){
							obj.focus();
							cj.popMsg.init(cj.form.msg.valid[lang] + title, pos, size, t);
							return false;
						}
					break;
				}
			}
			return true;
		},
		isEmail : function(elm){
			return /^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i.test(elm);
		},
		isAccount : function(s){
			if(/[^a-z^A-Z^0-9^\.]/.test(s)) return false;
			return /[a-zA-Z0-9\.]{6,30}/.test(s)
		},
		isPasswd : function(s){
			return /.{6,30}/.test(s);
		},
		isNumber : function(obj){
			var exp = /^\d+\.?\d*$/;
			return (exp.exec(obj));
		},
		isSid : function(id){
			code = [10,11,12,13,14,15,16,17,34,18,19,20,21,22,35,23,24,25,26,27,28,29, 0,30,31, 0];
			id = id.toLowerCase();
			if (id.length != 10) return false;
			re = /[a-z]/
			if( !id.charAt(0).match(re) ) return false;
			re = /[0-9]/
			for (i=1; i<10; i++){
				if ( !id.charAt(i).match(re) ){
					return false;
				}
			}
			id0 = code[id.charAt(0).charCodeAt(0)-97];
			if (!id0) return false;
			return !((10-id.charAt(9)-(Math.floor(id0/10) +(id0%10)*9 + id.charAt(1)*8 + id.charAt(2)*7 + id.charAt(3)*6 + id.charAt(4)*5 + id.charAt(5)*4 + id.charAt(6)*3 + id.charAt(7)*2 + id.charAt(8)*1)%10)%10);
		},
		trim : function(obj){
			return obj.replace(/\s/g, '');
		},
		msg : {
			not_null : {
				tw	: ' 必填 ',
				en		: ' is required! '
			},
			valid : {
				tw	: ' 請輸入有效的 ',
				en		: ' Please specify valid '
			},
			day : {
				tw	: '日期',
				en		: 'Date'
			},
			not_number : {
				tw	: ' 不是數字',
				en		: ' is not number'
			}
		},
		isDate : function(d){
			return(/\d{4}[\/-]\d{2}[[\/-]\d{2}/.text(d));
		}
	}
	,updateUid : function(uid){
		var time = 20 * 60 * 1000;
		cj.uid = uid||'null';
		postData = 'a=updateUid&uid='+uid;
		cj.ajax.open({URL:'ajax', postData:postData, disableLoadding:1, cb:function(req){
			try{
				r = eval(req.responseText);
				if(!r.uid) return;
				cj.uid = r.uid;
				setTimeout(function(){cj.updateUid(r.uid)}, time);
			}catch(e){}
		}});
	}
}
cj.flashObj = {
	init : function (set){
		this.src       = set.src;
		this.width     = set.w;
		this.height    = set.h;
		this.version   = '7,0,14,0';
		this.id        = null;
		this.flashVars = null;
		this.params = set.params.split(',') || [];
		return this;
	},
	setVersion : function(v){
		this.version = v;
	},
	setId : function(id){
		this.id = id;
	},
	setBgcolor : function(bgc){
		this.bgcolor = bgc;
	},
	setFlashvars : function(fv){
		this.flashVars = fv;
	},
	toString : function(){
	    var flashTag = new String();
	    if (cj.isIE){
	        flashTag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
	        if (this.id != null) flashTag += 'id="'+this.id+'" ';
	        flashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.version+'" ';
	        flashTag += 'width="'+this.width+'" ';
	        flashTag += 'height="'+this.height+'" />';
	        flashTag += '<param name="movie" value="'+this.src+'" />';
	        flashTag += '<param name="quality" value="high" />';
	        flashTag += '<param name="wmode" value="transparent" />';
	        for(var i=0; i<this.params.length/2; i++) flashTag += '<param name="' + this.params[i*2] + '" value="' + this.params[i*2+1] + '" />';
	        if (this.flashVars != null) flashTag += '<param name="flashvars" value="'+this.flashVars+'" />';
	        flashTag += '</object>';
	    }else{
	    	allowfullscreen="true"
	        flashTag += '<embed src="'+this.src+'" ';
	        if (this.id != null) flashTag += 'name="'+this.id+'" ';
	        flashTag += 'quality="high" wmode="transparent" ';
	        flashTag += 'width="'+this.width+'" ';
	        flashTag += 'height="'+this.height+'" ';
	        flashTag += 'type="application/x-shockwave-flash" ';
	        for(var i=0; i<this.params.length/2; i++) flashTag += this.params[i*2] + '="' + this.params[i*2+1] + '" ';
	        if (this.flashVars != null) flashTag += 'flashvars="'+this.flashVars+'" ';
	        flashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
	        flashTag += '</embed>';
	    }
	    return flashTag;
	},
	write : function(set){
		if(set) this.init(set);
    	cj.d.write(this.toString());
    }
}
Function.prototype.clone = function() {
    var fct = this;
    var clone = function() {
        return fct.apply(this, arguments);
    };
    clone.prototype = fct.prototype;
    for (property in fct) {
        if (fct.hasOwnProperty(property) && property !== 'prototype') {
            clone[property] = fct[property];
        }
    }
    return clone;
};
function html_entity_decode (string, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: john (http://www.jd-tech.net)
    // +      input by: ger
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: marc andreu
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Ratheous
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Nick Kolosov (http://sammy.ru)
    // +   bugfixed by: Fox
    // -    depends on: get_html_translation_table
    // *     example 1: html_entity_decode('Kevin &amp; van Zonneveld');
    // *     returns 1: 'Kevin & van Zonneveld'
    // *     example 2: html_entity_decode('&amp;lt;');
    // *     returns 2: '&lt;'

    var hash_map = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();

    if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }

    // fix &amp; problem
    // http://phpjs.org/functions/get_html_translation_table:416#comment_97660
    delete(hash_map['&']);
    hash_map['&'] = '&amp;';

    for (symbol in hash_map) {
        entity = hash_map[symbol];
        tmp_str = tmp_str.split(entity).join(symbol);
    }
    tmp_str = tmp_str.split('&#039;').join("'");

    return tmp_str;
}
function get_html_translation_table (table, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // +   bugfixed by: Alex
    // +   bugfixed by: Marco
    // +   bugfixed by: madipta
    // +   improved by: KELAN
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Frank Forte
    // +   bugfixed by: T.Wild
    // +      input by: Ratheous
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js, meaning the constants are not
    // %          note: real constants, but strings instead. Integers are also supported if someone
    // %          note: chooses to create the constants themselves.
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}

    var entities = {}, hash_map = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};

    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';

    useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';

    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
        throw new Error("Table: "+useTable+' not supported');
        // return false;
    }

    entities['38'] = '&amp;';
    if (useTable === 'HTML_ENTITIES') {
        entities['160'] = '&nbsp;';
        entities['161'] = '&iexcl;';
        entities['162'] = '&cent;';
        entities['163'] = '&pound;';
        entities['164'] = '&curren;';
        entities['165'] = '&yen;';
        entities['166'] = '&brvbar;';
        entities['167'] = '&sect;';
        entities['168'] = '&uml;';
        entities['169'] = '&copy;';
        entities['170'] = '&ordf;';
        entities['171'] = '&laquo;';
        entities['172'] = '&not;';
        entities['173'] = '&shy;';
        entities['174'] = '&reg;';
        entities['175'] = '&macr;';
        entities['176'] = '&deg;';
        entities['177'] = '&plusmn;';
        entities['178'] = '&sup2;';
        entities['179'] = '&sup3;';
        entities['180'] = '&acute;';
        entities['181'] = '&micro;';
        entities['182'] = '&para;';
        entities['183'] = '&middot;';
        entities['184'] = '&cedil;';
        entities['185'] = '&sup1;';
        entities['186'] = '&ordm;';
        entities['187'] = '&raquo;';
        entities['188'] = '&frac14;';
        entities['189'] = '&frac12;';
        entities['190'] = '&frac34;';
        entities['191'] = '&iquest;';
        entities['192'] = '&Agrave;';
        entities['193'] = '&Aacute;';
        entities['194'] = '&Acirc;';
        entities['195'] = '&Atilde;';
        entities['196'] = '&Auml;';
        entities['197'] = '&Aring;';
        entities['198'] = '&AElig;';
        entities['199'] = '&Ccedil;';
        entities['200'] = '&Egrave;';
        entities['201'] = '&Eacute;';
        entities['202'] = '&Ecirc;';
        entities['203'] = '&Euml;';
        entities['204'] = '&Igrave;';
        entities['205'] = '&Iacute;';
        entities['206'] = '&Icirc;';
        entities['207'] = '&Iuml;';
        entities['208'] = '&ETH;';
        entities['209'] = '&Ntilde;';
        entities['210'] = '&Ograve;';
        entities['211'] = '&Oacute;';
        entities['212'] = '&Ocirc;';
        entities['213'] = '&Otilde;';
        entities['214'] = '&Ouml;';
        entities['215'] = '&times;';
        entities['216'] = '&Oslash;';
        entities['217'] = '&Ugrave;';
        entities['218'] = '&Uacute;';
        entities['219'] = '&Ucirc;';
        entities['220'] = '&Uuml;';
        entities['221'] = '&Yacute;';
        entities['222'] = '&THORN;';
        entities['223'] = '&szlig;';
        entities['224'] = '&agrave;';
        entities['225'] = '&aacute;';
        entities['226'] = '&acirc;';
        entities['227'] = '&atilde;';
        entities['228'] = '&auml;';
        entities['229'] = '&aring;';
        entities['230'] = '&aelig;';
        entities['231'] = '&ccedil;';
        entities['232'] = '&egrave;';
        entities['233'] = '&eacute;';
        entities['234'] = '&ecirc;';
        entities['235'] = '&euml;';
        entities['236'] = '&igrave;';
        entities['237'] = '&iacute;';
        entities['238'] = '&icirc;';
        entities['239'] = '&iuml;';
        entities['240'] = '&eth;';
        entities['241'] = '&ntilde;';
        entities['242'] = '&ograve;';
        entities['243'] = '&oacute;';
        entities['244'] = '&ocirc;';
        entities['245'] = '&otilde;';
        entities['246'] = '&ouml;';
        entities['247'] = '&divide;';
        entities['248'] = '&oslash;';
        entities['249'] = '&ugrave;';
        entities['250'] = '&uacute;';
        entities['251'] = '&ucirc;';
        entities['252'] = '&uuml;';
        entities['253'] = '&yacute;';
        entities['254'] = '&thorn;';
        entities['255'] = '&yuml;';
    }

    if (useQuoteStyle !== 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
    if (useQuoteStyle === 'ENT_QUOTES') {
        entities['39'] = '&#39;';
    }
    entities['60'] = '&lt;';
    entities['62'] = '&gt;';


    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal);
        hash_map[symbol] = entities[decimal];
    }

    return hash_map;
}
