﻿if(typeof cj == "undefined") cj = {};
cj.evt = {
	guid : 1,
	add : function (element, type, handler)
	{
		if(element.addEventListener){
			element.addEventListener(type, handler, false);
		}else if (element.attachEvent)
		{
			element.attachEvent("on" + type, handler);
		}else{
			if (!handler.$$guid)
			{
				handler.$$guid = this.guid++;
			}
			if (!element.events)
			{
				element.events = {};
			}
			var handlers = element.events[type];
			if (!handlers)
			{
				handlers = element.events[type] = {};
				if(element["on" + type]){
					handlers[0] = element["on" + type];
				}
			}
			handlers[handler.$$guid] = handler;
			element["on" + type] = this.handleEvent;
		}
	},
	remove : function(element, type, handler)
	{
		if (element.removeEventListener)
		{
			element.removeEventListener(type, handler, false);
		}else
		{
			if (element.events && element.events[type])
			{
				delete element.events[type][handler.$$guid];
			}
		}
	}
}
cj.util = {
	getMousePos : function(ev){
		var ev = ev ? ev : window.event;
		return (ev.pageX && ev.x) ? {"x":ev.pageX, "y":ev.pageY} : {"x":ev.clientX+this.getScrollPos().left, "y":ev.clientY+this.getScrollPos().top}
	},
	getScrollPos : function(){
		var top = left = 0;
		top = document.documentElement.scrollTop || document.body.scrollTop;
		left = document.documentElement.scrollLeft || document.body.scrollLeft;
		return {"top" : top, "left" : left}
	},
	getWindowSize : function(){
		var width = height = 0;
		width = document.documentElement.clientWidth || document.body.clientWidth;
		height = document.documentElement.clientHeight || document.body.clientHeight;
		return {"width" : width, "height" : height}
	},
   	getElementPos : function(elm){
   		var top = left = 0;
   		while(elm != null){
   			top += elm.offsetTop;
   			left += elm.offsetLeft;
   			elm = elm.offsetParent;
   		}
   		return {"top" : top, "left" : left}
   	},
   	getPos : function(elm){
   		var top = left = 0;
   		while(elm != null){
   			try{
   				if(elm.style.position=='absolute'){
   					break;
   				}
   			}catch(ev){}
	   		top += elm.offsetTop;
	   		left += elm.offsetLeft;
   			elm = elm.offsetParent;
   		}
   		return {"top" : top, "left" : left} ;
   	},
   	showAttrib : function (obj, type){
   		var html = "<ul>";
		for(var i in obj){
			html += "<li>" + i + "=" + obj[i] + "</li>";
		}
		html += "</ul>";
		
		switch (type){
			default :
				var c = document.createElement("div");
				c.style.cssText = "position:absolute; border:1px solid #eeeeff; width:640px; height:480px; background:whitesmoke;";
				document.body.appendChild(c);
				c.style.top = this.getScrollPos().top + 50 + "px";
				
				var bar = document.createElement("div");
				bar.style.cssText = "width:100%; height:20px; border:1px solid #cccccc; background:#666666; color:whitesmoke; cursor:pointer; text-align:center;";
				bar.innerHTML = "Close";
				bar.onclick = function(){
					document.body.removeChild(this.offsetParent);
					return false;
				}
				c.appendChild(bar);
				
				var main = document.createElement("div");
				main.style.cssText = "width:100%; height:460px; overflow:auto;";
					main.innerHTML = html;
				c.appendChild(main);
				return false;
			break;
			
			case "text" :
				return html;
			break;
		}				
	},
	loadJs : function(src){
		var js = document.createElement("script");
		js.src = src;
		js.type = "text/javascript";
		document.getElementsByTagName("head")[0].appendChild(js);
	},
	fix_ieflash : function() {
		var objects = document.getElementsByTagName("object"); 
		for (var i=0;i<objects.length;i++)
			objects[i].outerHTML = objects[i].outerHTML;
	},
	popMsg : {
		div : null,
		move : 10,
		timer : null,
		holdTime : 3 * 1000,
		init : function(msg, pos, size, holdTime){
			if (typeof(holdTime)!="undefined"){
				this.holdTime = holdTime * 1000;
			}
			this.clear();
			this.size = size;
			this.div = document.createElement("div");
			this.div.className = "popMsg";
			this.div.innerHTML = msg;
			document.body.appendChild(this.div);
			this.div.style.left = pos.left + "px";
			this.div.style.top = pos.top + "px";
			this.show(1);
		},
		show : function(step){
			if(this.div.offsetWidth < this.size.width){
				this.div.style.width = Math.abs((this.size.width/this.move)*step) + "px";
				this.div.style.height = Math.abs((this.size.height/this.move)*step) + "px";
				this.timer = setTimeout( function(){ cj.util.popMsg.show(++step) }, 1 );
			}else{
				this.timer = setTimeout( function(){cj.util.popMsg.clear()}, this.holdTime);
			}
		},
		clear : function(){
			if (this.div){
				clearTimeout(this.timer);
				this.timer = null;
				document.body.removeChild(this.div);
				this.div = null;
			}
		}
	}
}

cj.drag = {
	draging : false,
	offsetX : 0,
	offsetY : 0,
	dragObj : null,
	start : function(ev){
		var ev = ev || window.event;
		var tgt = ev.target || ev.srcElement;
		if(typeof tgt.attrib != "undefined" && tgt.attrib == "dragable"){
			cj.drag.dragObj = tgt;
			cj.drag.draging = false;
			cj.drag.offsetY = (cj.util.getMousePos(ev)).y - tgt.offsetTop;
			cj.drag.offsetX = (cj.util.getMousePos(ev)).x - tgt.offsetLeft;
			cj.evt.add(document, "mousemove", cj.drag.drag);
			cj.evt.add(document, "mouseup", cj.drag.end);
		}
		return false;
	},
	drag : function(ev){
		if (!cj.drag.dragObj){
			return false;
		}
		cj.drag.dragObj.style.top = (cj.util.getMousePos(ev)).y - cj.drag.offsetY + "px";
		cj.drag.dragObj.style.left = (cj.util.getMousePos(ev)).x - cj.drag.offsetX + "px";
		if(typeof cj.drag.dragObj.mask != "undefined" && cj.drag.dragObj.mask){
			cj.drag.dragObj.mask.style.top = cj.drag.dragObj.style.top;
			cj.drag.dragObj.mask.style.left = cj.drag.dragObj.style.left;
		}
		cj.drag.draging = true;
		return false;
	},
	end : function(ev){
		if (!cj.drag.dragObj){
			return;
		}
		cj.drag.dragObj = null;
		cj.drag.draging = false;
		cj.evt.remove(document, "mousemove", cj.drag.drag);
		cj.evt.remove(document, "mouseup", cj.drag.end);
		return false;
	}
}

cj.form = {
	chk : function(id, fields){
		var f = document.getElementById(id);
		if(!f)	return false;
		f.onsubmit = function(){
			if(typeof this.lang == "undefined" || !this.lang){
				alert("lang not set");
				return false;
			}
			var lang = this.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] + " doesn't exist");
					return false;
				}
				var type = a[1];
				var title = obj.getAttribute("title");
				if(!title){
					alert(a[0] + " title not set");
					return false;
				}
				var pos = cj.util.getElementPos(obj);
				pos.left +=  50;
				switch (type){
					case "num":
						obj.value = cj.form.trim(obj.value);
						//obj.value = obj.value.replace(/^[0]{2,}/, 0);
						//obj.value = obj.value.replace(/[0]+$/, '');
						//obj.value = obj.value.replace(/^[0](\d+)/, '$1');
						if( !cj.form.isNumber(obj.value)){
							obj.focus();
							cj.util.popMsg.init(title + cj.form.msg.not_number[lang], pos, {"width":200, "height":20});
							return false;
						}
					case "text":
						if( obj.value == "" ){
							obj.focus();
							cj.util.popMsg.init(title + cj.form.msg.not_null[lang], pos, {"width":200, "height":20});
							return false;
						}
					break;
					case "email":
						if(!cj.form.isEmail(obj.value)){
							obj.focus();
							cj.util.popMsg.init(cj.form.msg.valid[lang] + title, pos, {"width":200, "height":20});
							return false;
						}
					break;
					case "account":
						if(!cj.form.isAccount(obj.value)){
							obj.focus();
							cj.util.popMsg.init(cj.form.msg.valid[lang] + title, pos, {"width":200, "height":20});
							return false;
						}
					break;
					case "password":
						if(!cj.form.isPasswd(obj.value)){
							obj.focus();
							cj.util.popMsg.init(cj.form.msg.valid[lang] + title, pos, {"width":200, "height":20});
							return false;
						}
						var passwd2 = f[obj.getAttribute("confirm")];
						if(obj.value != passwd2.value){
							passwd2.focus();
							cj.util.popMsg.init(cj.form.msg.valid[lang] + passwd2.getAttribute("title"), pos, {"width":200, "height":20});
							return false;
						}
					break;
					case "checkbox":
						if(!obj.checked){
							obj.focus();
							cj.util.popMsg.init(obj.getAttribute("title"), pos, {"width":200, "height":20});
							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.util.popMsg.init(cj.form.msg.valid[lang] + title, pos, {"width":200, "height":20});
							return false;
						}
					break;
					case "sid":
						if(!cj.form.isSid(obj.value)){
							obj.focus();
							cj.util.popMsg.init(cj.form.msg.valid[lang] + title, pos, {"width":200, "height":20});
							return false;
						}
					break;
				}
			}
			return true;
		}
	},
	isEmail : function(elm){
		re = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
		return elm.match(re)
	},
	isAccount : function(obj){
		if (obj.length <4){
			return false;
		}
		var exp = /^[a-zA-Z]/;
		if(!exp.exec(obj)){
			return false;
		}
		return true;
	},
	isPasswd : function(obj){
		if (obj.length <4){
			return false
		}
		var exp = /['"]/;
		if(exp.exec(obj)){
			return false;
		}
		return true;
	},
	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, '');
	}
}
cj.form.msg = {
	not_null : {
		zh_tw	: " 必填 ",
		en		: " is required! "
	},
	valid : {
		zh_tw	: " 請輸入有效的 ",
		en		: " Please specify valid "
	},
	day : {
		zh_tw	: "日期",
		en		: "Date"
	},
	not_number : {
		zh_tw	: " 不是數字",
		en		: " is not number"
	}
}
cj.calendar = {
	init : function(yid, mid, did, aid){
		var a = document.getElementById(aid);
		if(!a)	return;
		a.y = document.getElementById(yid);
		a.m = document.getElementById(mid);
		a.d = document.getElementById(did);
		if(!a.y || !a.m || !a.d)	return;
		
		//select onchange --hide
		cj.evt.add(a.y, "change", function(){a.hide()});
		cj.evt.add(a.m, "change", function(){a.hide()});
		cj.evt.add(a.d, "change", function(){a.hide()});
		
		a.closeH = 13;
		a.bolder = 2;
		a.boxW = 30;
		a.boxH = 25;
		
		a.draw = cj.calendar.draw;
		a.drawBox = cj.calendar.drawBox;
		a.show = cj.calendar.show;
		a.hide = cj.calendar.hide;
		a.lastMonth = cj.calendar.lastMonth;
		a.nextMonth = cj.calendar.nextMonth;
		a.drawCaption = cj.calendar.drawCaption;
		a.setDate = cj.calendar.setDate;
		a.setH = cj.calendar.setH;
		a.setTheDay = cj.calendar.setTheDay;
		
		cj.evt.add(a, "click", function(){a.show()});
		a.style.cursor = "pointer";
		
		a.win = document.createElement("div");
		a.win.id = "calendar";
		var width = 7*a.boxW + 2*a.bolder + 6;
		a.win.style.width = width + "px";
		a.win.style.top = (cj.util.getElementPos(a)).top + a.offsetHeight + 5 + "px";
		a.win.style.left = (cj.util.getElementPos(a)).left + a.offsetWidth - width +  "px";
		
		//drag
		a.win.attrib = "dragable";
		cj.evt.add(a.win, "mousedown", cj.drag.start);
		
		if(document.attachEvent){
			a.win.mask = document.createElement("iframe");
			a.win.mask.style.cssText = "position:absolute; display:none; border:0px;";
			a.win.mask.style.width = a.win.style.width;
			a.win.mask.style.top = a.win.style.top;
			a.win.mask.style.left = a.win.style.left;
			document.body.appendChild(a.win.mask);
		}
		
		//close
		a.closer = document.createElement("div");
		a.closer.parent = a;
		a.closer.id = "calCloser";
		a.closer.style.top = 1 + "px";
		a.closer.style.right = 1 + "px";
		cj.evt.add(a.closer, "click", function(evt){
			var evt = evt || window.event;
			tgt = evt.target || evt.srcElement;
			tgt.parent.hide();
			});
		a.win.appendChild(a.closer);
		
		//last
		a.last = a.drawBox('calLast', 0, 0, 1, 1, "&#60;&#60");
		a.last.parent = a;
		a.last.style.cursor = "pointer";
		a.last.onclick = a.lastMonth;
		a.win.appendChild(a.last);
		
		//caption
		a.caption = a.drawBox('calCaption', 0, 1, 5, 1, "");
		a.win.appendChild(a.caption);
		document.body.appendChild(a.win);
		
		//next
		a.next = a.drawBox('calNext', 0, 6, 1, 1, "&#62;&#62");
		a.next.parent = a;
		a.next.style.cursor = "pointer";
		a.next.onclick = a.nextMonth;
		a.win.appendChild(a.next);
		
		//nav
		a.nav = new Array();
		var days = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
		for (var i=0; i<days.length; i++){
			a.nav[i] = a.drawBox("calNav", 1, i, 1, 1, days[i]);
			a.win.appendChild(a.nav[i]);
		}
		document.body.appendChild(a.win);
	},
	draw : function(){
		this.setTheDay();
		this.drawCaption();
		this.setH();
		
		if (typeof this.box != "undefined"){
			for(var i=0; i<this.box.length; i++){
			//for(var i in this.box){
				this.win.removeChild(this.box[i]);
			}
			this.box = null;
		}
		this.box = new Array();
		for (var i=0; i<7*this.rows; i++){
			id = (i%7==0 || i%7==6) ? "calweekend" : "";
			var day = (i - this.firstWeekDay) + 1;
			if (day < 1 || day > this.monthDay)
				day = "";
			this.box[i] = this.drawBox(id, Math.floor(i/7)+2, (i%7), 1, 1, day);
			this.box[i].parent = this;
			if (day){
				this.box[i].style.cursor = "pointer";
				this.box[i].onclick = this.setDate;
			}
			if (day == this.d.value)
					this.box[i].id = "caltheday";
			this.win.appendChild(this.box[i]);
		}
	},
	setTheDay : function(){
		this.monthDay = cj.calendar.solarDays(this.y.value, this.m.value);
		this.firstWeekDay = (new Date(this.y.value + "/" + this.m.value + "/1")).getDay(); 
	},
	setH : function(){
		this.rows =  Math.ceil((this.monthDay + this.firstWeekDay)/7);
		this.win.style.height = 2*this.bolder + this.closeH + (this.rows+2)*(this.boxH+1) + "px";
		if(typeof this.win.mask != "undefined"){
			this.win.mask.style.height = this.win.style.height;
		}
	},
	drawCaption : function(){
		this.caption.innerHTML = this.y.value + "-" + this.m.value;
	},
	show : function(){
		if(typeof this.win.mask != "undefined"){
			this.win.mask.style.display = "block";
		}
		this.win.style.display = "block";
		this.draw();
		return false;
	},
	hide : function(){
		if(typeof this.win.mask != "undefined")
			this.win.mask.style.display = "none";
		this.win.style.display = "none";
	},
	setDate : function(){
		this.parent.d.selectedIndex = this.innerHTML - 1;
		this.parent.hide();
		if(typeof this.parent.d.onchange == "function")
			this.parent.d.onchange();
	},
	lastMonth : function(ev){
		if (this.parent.y.selectedIndex == 0 && this.parent.m.selectedIndex == 0)	return;
		if (this.parent.m.selectedIndex == 0){
			this.parent.y.selectedIndex --;
			this.parent.m.selectedIndex = 11;
		}else{
			this.parent.m.selectedIndex --;
		}
		this.parent.monthDay = cj.calendar.solarDays(this.parent.y.value, this.parent.m.value);
		this.parent.firstWeekDay = (new Date(this.parent.y.value + "/" + this.parent.m.value + "/1")).getDay(); 
		this.parent.draw();
	},
	nextMonth : function(){
		if (this.parent.y.selectedIndex >= this.parent.y.options.length && this.parent.m.selectedIndex >= this.parent.m.options.length){
			return false;
		}
		if (this.parent.m.selectedIndex == 11){
			this.parent.y.selectedIndex++;
			this.parent.m.selectedIndex = 0;
		}else{
			this.parent.m.selectedIndex++;
		}
		this.parent.monthDay = cj.calendar.solarDays(this.parent.y.value, this.parent.m.value);
		this.parent.firstWeekDay = (new Date(this.parent.y.value + "/" + this.parent.m.value + "/1")).getDay(); 
		this.parent.draw();
	},
	drawBox : function (id, t, l, w, h, htm){
		var obj = document.createElement("div");
		obj.id = id;
		obj.style.top = this.bolder + this.closeH + t*(this.boxH+1) + "px";
		
		obj.style.left = this.bolder + l*(this.boxW+1) + "px";
		obj.style.width = w * (this.boxW+1) - 1 + "px";
		obj.style.height = h * (this.boxH+1) -1 + "px";
		obj.innerHTML = htm;
		return obj;
	},
	solarDays : function (y,m){
		var solarMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		if( m == 2){
			return (( y%4 == 0) && (y%100 !=0) || (y%400 == 0)) ? 29 : 28;
		}else{
			return solarMonth[m-1];
		}
	}
}
cj.classSelt = {
	mc : {},
	sc : {},
	list : function(mc, sc){
		if (!mc.tgt){
			alert('mc.tgt not set');
			return;
		}
		if (!sc.tgt){
			alert('sc.tgt not set');
			return;
		}
		this.mc = mc;
		this.sc = sc;
		this.makeMc();
		this.makeSc();
	},
	modForm : function(mc, sc){
		if (!mc.tgt){
			alert('mc.tgt not set');
			return;
		}
		if (!sc.tgt){
			alert('sc.tgt not set');
			return;
		}
		this.mc = mc;
		this.sc = sc;
		this.makeMc();
		this.makeSc();
		this.mc.tgt.onchange = function(){
			cj.classSelt.makeSc();
		}
	},
	makeMc : function(){
		this.clear(this.mc.tgt);
		for(var i=0; i<this.mc.items.length; i++){
			this.mc.tgt.options[i] = new Option(this.mc.items[i].title, this.mc.items[i].id);
			if (this.mc.items[i].id == this.mc.selected){
				this.mc.tgt.selectedIndex = i;
			}
		}
	},
	makeSc : function(){
		this.clear(this.sc.tgt);
		items = this.sc.items;
		var j=0;
		for(var i=0; i<items.length; i++){
			if (this.mc.tgt.value == items[i].mcid){
				this.sc.tgt.options[j] = new Option(items[i].title, items[i].id);
				if (items[i].id == this.sc.selected){
					this.sc.tgt.selectedIndex = j;
				}
				j++;
			}
		}
	},
	clear : function(so, start){
		start = (typeof start == "undefined") ? 0 : start;
		while(so.options[start]){
			so.options[start] = null;
		}
	}
}
cj.flashObj = {
	init : function (src, width, height){
		this.src       = src;
		this.width     = width;
		this.height    = height;
		this.version   = '7,0,14,0';
		this.id        = null;
		this.bgcolor   = 'ffffff';
		this.flashVars = null;
		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 ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
	    var flashTag = new String();
	    if (ie)
	    {
	        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="bgcolor" value="#'+this.bgcolor+'"/>';
	        if (this.flashVars != null)
	        {
	            flashTag += '<param name="flashvars" value="'+this.flashVars+'"/>';
	        }
	        flashTag += '</object>';
	    }
	    else
	    {
	        flashTag += '<embed src="'+this.src+'" ';
	        flashTag += 'quality="high" '; 
	        flashTag += 'bgcolor="#'+this.bgcolor+'" ';
	        flashTag += 'width="'+this.width+'" ';
	        flashTag += 'height="'+this.height+'" ';
	        flashTag += 'type="application/x-shockwave-flash" ';
	        if (this.flashVars != null)
	        {
	            flashTag += 'flashvars="'+this.flashVars+'" ';
	        }
	        if (this.id != null)
	        {
	            flashTag += 'name="'+this.id+'" ';
	        }
	        flashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
	        flashTag += '</embed>';
	    }
	    return flashTag;
	},
	write : function(doc){
    	doc.write(this.toString());
    }
}
cj.xmlHttp = {
	req : false,
	init : function(){
		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{
				this.req = factories[i]();
			}
			catch(e){
				continue;
			}
			break;
		}
		return (this.req) ? true : false;
	},
	sendRequest : function(URL, callback, postData){
		this.init();
		if (!this.req) return;
		method = (postData) ? "POST" : "GET";
		this.req.open(method, URL, true);
		this.req.setRequestHeader('User-Agent', 'XMLHTTP');
		if (postData){
			this.req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		}
		this.req.onreadystatechange = function(){
			if (cj.xmlHttp.req.readyState != 4) return;
			if (cj.xmlHttp.req.status != 200 && cj.xmlHttp.req.status != 304){
				alert('HTTP error ' + cj.xmlHttp.req.status);
				return;
			}
			callback(cj.xmlHttp.req);
		}
		if (this.req.readyState == 4) return;
		this.req.send(postData);
	}
}
cj.roller = {
	ar : 0.99,
	init : function(boxid, itemcontainerid, rollerSet){
		var box = document.getElementById(boxid);
		if (!box){
			return;
		}
		var items = document.getElementById(itemcontainerid);
		if(!items)	return;
		box.items = items.getElementsByTagName('table');
		if(!box.items || !box.items.length){
			return;
		}
		box.index = 0;
		box.timer = null;
		rollerSet.showNum = Math.min(box.items.length, rollerSet.showNum);
		box.rollerSet = rollerSet;
		box.doRoll = (box.items.length > box.rollerSet.showNum);
		
		var div = document.createElement("div");
		div.style.cssText = "position:absolute; top:0px; left:0px; visibility:visible";
		box.divs = [];
		for (var i=0; i<=rollerSet.showNum; i++){
			box.divs[i] = div.cloneNode(true);
			/*
			box.divs[i].onmouseover = function(){
				this.style.border = "1px solid #ccf";
			}
			box.divs[i].onmouseout = function(){
				this.style.border = "0px";
			}
			*/
			box.appendChild(box.divs[i]);
		}
		this.roll(box);
		if(box.doRoll){
			box.onmouseover = function(){
				clearTimeout(box.timer);
			}
			box.onmouseout = function(evt){
				var evt = evt || window.event;
				var related = evt.relatedTarget || evt.toElement;
				var contains = false;
				while(related){
					if(related == this){
						contains = true;
						break;
					}
					related =  related.offsetParent;
				}
				if(!contains){
					box.timer = cj.roller.rollNext(box, cj.roller.ar);
				}
			}
		}
	},
	roll : function(obj){
		for(var i=0; i<=obj.rollerSet.showNum; i++){
			while(obj.divs[i].childNodes[0])
				obj.divs[i].removeChild(obj.divs[i].childNodes[0]);
			obj.divs[i].appendChild(obj.items[(obj.index+i)%obj.items.length].cloneNode(true));
			if (i){
				if (obj.rollerSet.dir == "horizontal"){
					obj.divs[i].style.left = obj.divs[i-1].offsetLeft + obj.divs[i-1].offsetWidth + obj.rollerSet.gap + "px";
				}else{
					obj.divs[i].style.top = obj.divs[i-1].offsetTop + obj.divs[i-1].offsetHeight + obj.rollerSet.gap + "px";
				}
			}else{
				obj.divs[i].style.top = obj.divs[i].style.left = 0 + "px";
			}
			if (i == obj.rollerSet.showNum){
				obj.divs[i].style.visibility = "hidden";
			}
		}
		if(obj.doRoll){
			obj.index  = (obj.index == obj.items.length -1) ? 0 : obj.index +1;
			obj.timer = setTimeout(function(){cj.roller.rollNext(obj, cj.roller.ar)}, obj.rollerSet.holdtime);
		}
	},
	rollNext : function(obj, ar){
		if (obj.rollerSet.dir == "horizontal"){
			var delta = Math.floor(Math.max(0, obj.divs[1].offsetLeft * ar));
			var move = obj.divs[1].offsetLeft - delta;
		}else{
			var delta = Math.floor(Math.max(0, obj.divs[1].offsetTop * ar));
			var move = obj.divs[1].offsetTop - delta;
		}
		for(var i=0; i<=obj.rollerSet.showNum; i++){
			obj.divs[i].style.visibility = "visible";
			if (obj.rollerSet.dir == "horizontal"){
				obj.divs[i].style.left = obj.divs[i].offsetLeft - move + "px";
			}else{
				obj.divs[i].style.top = obj.divs[i].offsetTop - move + "px";
			}
		}
		if(!delta){
			this.roll(obj);
		}else{
			obj.timer = setTimeout(function(){cj.roller.rollNext(obj, ar*cj.roller.ar)}, obj.rollerSet.rolltime);
		}
	}
}
cj.simpleMenu = {
	timer : null,
	menus : [],
	items : [],
	openObj : null,
	ar : 0.99,
	init: function(menu, item, dir){
		var mm, sm;
		for (var i=0; i<menu.length; i++){
			mm = document.getElementById(menu[i]);
			sm = document.getElementById(item[i]);
			if (mm&&sm){
				mm.index = this.menus.length;
				this.menus[mm.index] = mm;
				this.items[mm.index] = mm;
				mm.sm = sm;
				mm.onmouseover = function(){ cj.simpleMenu.show(this.index)};
				mm.onmouseout = function(){ cj.simpleMenu.hide(this.index)};
				
				mm.div = document.createElement("div");
				mm.div.style.cssText = "position:absolute; display:none; z-index: 1000;";
				/*
				mm.div.style.top = cj.util.getElementPos(mm).top + "px";
				mm.div.style.left = cj.util.getElementPos(mm).left + mm.offsetWidth - 3 + "px";
				*/
				mm.div.style.width = sm.offsetWidth + "px";
				sm.style.top = "0px";
				sm.style.left = "0px";
				mm.appendChild(mm.div);
				mm.div.appendChild(sm);
			}
		}
	},
	setPos : function(index){
		var mm = this.menus[index];
		var sm = this.menus[index];
		var wt = cj.util.getScrollPos().top + cj.util.getWindowSize().height;
		var wl = cj.util.getScrollPos().left + cj.util.getWindowSize().width;
			
		var pos = cj.util.getPos(mm);
		var h = (sm.getElementsByTagName('table')[0]).offsetHeight;
		pos.top = Math.min(pos.top, wt - h);
		pos.left = Math.min(pos.left + mm.offsetWidth - 3, wl - sm.offsetWidth);
		mm.div.style.top = pos.top + "px";
		mm.div.style.left = pos.left + "px";
	},
	show : function(index){
		if(this.openObj){
			this.openObj.div.style.display = 'none';
		}
		clearTimeout(this.timer);
		this.openObj = this.items[index];
		if(this.openObj){
			this.openObj.div.style.display = 'block';
			this.setPos(index);
		}
	},
	hide : function(index){
		var obj = this.items[index].div;
		if(obj) this.timer = setTimeout(function(){obj.style.display = 'none'}, 600);
	}
}
Array.prototype.in_array = function ( obj ) {
	var len = this.length;
	for ( var x = 0 ; x <= len ; x++ ) {
		if ( this[x] == obj ) return true;
	}
	return false;
}