﻿//-----------------------------------------------------------------------------------

	window.bVer=parseInt(navigator.appVersion);
	window.bName=navigator.appName.toLowerCase();
	window.agent=navigator.userAgent.toLowerCase();

	window.browser = {
		version:(agent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
		ie:/msie/.test(agent) && !/opera/.test(agent),
		ie6:/msie 6.0/.test(agent),
		ie7:/msie 7.0/.test(agent),
		ie8:/msie 8.0/.test(agent),
		safari:/webkit/.test(agent),
		opera:/opera/.test(agent),
		mozilla:/mozilla/.test(agent) && !/(compatible|webkit)/.test(agent),
		firefox2:/firefox\/2/.test(agent),
		firefox3:/firefox\/3/.test(agent),
		ns9:/navigator\/9/.test(agent),
		flock:/flock/.test(agent),
		chrome:/chorme/.test(agent)
	};
	window.isIE = browser.ie;
	window.isNS = !browser.ie;
	window.isGecko= !browser.ie;

	if (isIE){
		//bHeight=document.body.clientHeight;
		//bWidth=document.body.clientWidth;
		window.bHeight=window.document.documentElement.clientHeight;
		window.bWidth=window.document.documentElement.clientWidth;
	}

	if (isGecko){
		window.bHeight=window.innerHeight;
		window.bWidth=window.innerWidth;
	}

	window.scrollWidth=getScrollerWidth();

function init(){}

/*
 * Author: Rob Reid
 * CreateDate: 20-Mar-09
 * Description: Little helper function to return details about IE 8 and its various compatibility settings either use as it is
 * or incorporate into a browser object. Remember browser sniffing is not the best way to detect user-settings as spoofing is
 * very common so use with caution.
*/
function IEVersion(){
	//original by http://blog.strictly-software.com/2009/03/detecting-ie-8-compatibility-modes-with.html
	var _n=navigator,_w=window,_d=document;
	var version="NA";
	var na=_n.userAgent;
	var ieDocMode="NA";
	var ie8BrowserMode="NA";
	// Look for msie and make sure its not opera in disguise
	if(/msie/i.test(na) && (!_w.opera)){
		// also check for spoofers by checking known IE objects
		if(_w.attachEvent && _w.ActiveXObject){
			version=na.match(/trident\/4/ig);
			if (version){
				version=8;
			}else{
				// Get version displayed in UA although if its IE 8 running in 7 or compat mode it will appear as 7
				version=(na.match(/trident\/5/ig))?'9':(na.match( /.+ie\s([\d.]+)/i ) || [])[1];
			}
			// Its IE 8 pretending to be IE 7 or in compat mode
			if(parseInt(version)==7){
				// documentMode is only supported in IE 8 so we know if its here its really IE 8
				if(_d.documentMode){
					version = 8; //reset? change if you need to
					// IE in Compat mode will mention Trident in the useragent
					if(/trident\/\d/i.test(na)){
						ie8BrowserMode = "Compat Mode";
					// if it doesn't then its running in IE 7 mode
					}else{
						ie8BrowserMode = "IE 7 Mode";
					}
				}
			}else if(parseInt(version)==8){
				// IE 8 will always have documentMode available
				if(_d.documentMode){ ie8BrowserMode = "IE 8 Mode";}
			}
			// If we are in IE 8 (any mode) or previous versions of IE we check for the documentMode or compatMode for pre 8 versions
			ieDocMode = (_d.documentMode) ? _d.documentMode : (_d.compatMode && _d.compatMode=="CSS1Compat") ? 7 : 5;//default to quirks mode IE5
		}
	}

	return {
		"UserAgent" : na,
		"Version" : version,
		"BrowserMode" : ie8BrowserMode,
		"DocMode": ieDocMode
	}
}

var IEMode=IEVersion();
//alert('UserAgent:'+IEMode.UserAgent+'\nVersion:'+IEMode.Version+'\nBrowserMode:'+IEMode.BrowserMode+'\nie8BrowserMode:'+IEMode.ie8BrowserMode+'\nDocMode:'+IEMode.DocMode);
if (IEMode.Version<8){
	//叫他換瀏覽器
	if (confirm('We suggest you to upgrade more better browser version then you used now!\rClick \'OK\' to visit Microsoft Website.')){
		window.top.location='http://www.microsoft.com/ie';
	}else{
		window.top.location='/commonFiles/blank.asp';
	}
}else{
	if (IEMode.DocMode==7){
		if (confirm('It looks like you have enabled Internet Explorer Compatibility View.\rClick \'OK\' to see how to disable Compatibility View Mode')){
			window.top.location='http://audi.tw/Blog/window/IEMode.asp';
		}else{
			window.top.location='/commonFiles/blank.asp';
		}
	}
}

function googleTrans(str,source,target,container){
	new Ajax({
		url:'https://www.googleapis.com/language/translate/v2?key=AIzaSyBGfGjs6-s55VNpFh0oPCOYN-7Udlg_KDE&source='+source+'&target='+target+'&q='+str,
		method:'get',
		success:function(xmlhttp){
		},
		failure:function(){
		}
	});
}

var __methods={
	version:'0.1',
	intervalOBJ:null,
	agent:navigator.userAgent.toLowerCase(),
	ie:/msie/.test(this.agent) && !/opera/.test(this.agent),
	bWidth:(/msie/.test(this.agent) && !/opera/.test(this.agent))?window.document.documentElement.clientWidth:window.innerWidth,
	bHeight:(/msie/.test(this.agent) && !/opera/.test(this.agent))?window.document.documentElement.clientHeight:window.innerHeight,
	//CSS Setting or Return Property
	width:function(x){
		if (typeof x=='undefined'){
			return parseInt(this.style.width);
		}else{
			this.style.width=(isNaN(x))?x:x+'px';
		}
		return this;
	},

	setwidth:function(x){
		if (typeof x=='undefined'){
			return parseInt(this.style.width);
		}else{
			this.style.width=(isNaN(x))?x:x+'px';
		}
		return this;
	},

	height:function(x){
		if (typeof x=='undefined'){
			return parseInt(this.style.height);
		}else{
			this.style.height=(isNaN(x))?x:x+'px';
		}
		return this;
	},

	setheight:function(x){
		if (typeof x=='undefined'){
			return parseInt(this.style.height);
		}else{
			this.style.height=(isNaN(x))?x:x+'px';
		}
		return this;
	},

	top:function(x){
		if (typeof x=='undefined'){
			return parseInt(this.style.top);
		}else{
			if (this.position()!='absolute' && this.position()!='relative'){
				this.position('absolute');
			}
			this.style.top=isNaN(x)?x:x+'px';
		}
		return this;
	},

	right:function(x){
		x=(typeof x=='undefined')?0:x;
		this.left(this.bWidth-x-this.Width());

		return this;
	},

	left:function(x){
		if (typeof x=='undefined'){
			return parseInt(this.style.left);
		}else{
			if (this.position()!='absolute' && this.position()!='relative'){
				this.position('absolute');
			}
			this.style.left=isNaN(x)?x:x+'px';
		}
		return this;
	},

	topBy:function(x){
		if (typeof x!='undefined'){
			this.position('absolute');
			var currTop=$(this).getOffsetTop();
			this.style.top=currTop+x+'px';
		}
		return this;
	},

	leftBy:function(x){
		if (typeof x!='undefined'){
			this.position('absolute');
			var currLeft=$(this).getOffsetLeft();
			this.style.left=currLeft+x+'px';
		}
		return this;
	},

	color:function(x){
		if (typeof x=='undefined'){
			return this.style.color;
		}else if(x=='hex'){
			if (this.style.color.substring(0,1)=='#'){
				return this.style.color;
			}else{
				var rgb=this.style.color.replace(/\s/g,'');
				rgb=rgb.replace(/rgb\(/g,'');
				rgb=rgb.replace(/\)/g,'');
				return '#'+Dec2Hex(rgb.split(',')[0])+Dec2Hex(rgb.split(',')[1])+Dec2Hex(rgb.split(',')[2]);
			}
		}else{
			this.style.color=x;
		}
		return this;
	},

	backgroundcolor:function(x){
		if (typeof x=='undefined'){
			return this.style.backgroundColor;
		}else if(x=='hex'){
			if (this.style.backgroundColor.substring(0,1)=='#'){
				return this.style.color;
			}else{
				var rgb=this.style.backgroundColor.replace(/\s/g,'');
				rgb=rgb.replace(/rgb\(/g,'');
				rgb=rgb.replace(/\)/g,'');
				return '#'+Dec2Hex(rgb.split(',')[0])+Dec2Hex(rgb.split(',')[1])+Dec2Hex(rgb.split(',')[2]);
			}
		}else{
			this.style.backgroundColor=x;
		}
		return this;
	},

	backgroundColor:function(x){
		if (typeof x=='undefined'){
			return this.style.backgroundColor;
		}else if(x=='hex'){
			if (this.style.backgroundColor.substring(0,1)=='#'){
				return this.style.color;
			}else{
				var rgb=this.style.backgroundColor.replace(/\s/g,'');
				rgb=rgb.replace(/rgb\(/g,'');
				rgb=rgb.replace(/\)/g,'');
				return '#'+Dec2Hex(rgb.split(',')[0])+Dec2Hex(rgb.split(',')[1])+Dec2Hex(rgb.split(',')[2]);
			}
		}else{
			this.style.backgroundColor=x;
		}
		return this;
	},

	background:function(x){
		if (typeof x=='undefined'){
			return this.style.background;
		}else{
			this.style.background=x;
		}
		return this;
	},

	position:function(x){
		if (typeof x=='undefined'){
			return this.style.position;
		}else{
			this.style.position=x;
		}
		return this;
	},

	ZIndex:function(x){
		if (typeof x=='undefined'){
			return this.style.zIndex;
		}else{
			this.style.zIndex=x;
		}
		return this;
	},

	setClass:function(class_Name){
		if(typeof class_Name=='undefined'){
			this.className=class_Name;
		}

		return this;
	},

	getClass:function(){
		return this.className;
	},

	display:function(method){

		if(typeof method=='undefined'){
			return this.style.display;
		}

		if (method=='auto'){
			method=(this.style.display=='inline')?'hide':'show';
		}

		if (method=='show'){method='inline';}
		if (method=='hide'){method='none';}

		if (method=='autob'){
			method=(this.style.display=='none')?'block':'none';
		}

		this.style.display=method;

		return this;
	},

	//Return Property
	Height:function(){
		comment='取得物件含 margin, padding, border 高度';
		var dis=this.style.display;
		var h;
		this.style.display='';
		if (!isNaN(this.offsetHeight)){
			h=this.offsetHeight;
		}else{
			h=this.clientHeight;
		}
		this.style.display=dis;
		return h;
	},

	Width:function(){
		comment='取得物件含 margin, padding, border 寬度';
		var dis=this.style.display;
		var w;
		this.style.display='';
		if (!isNaN(this.offsetWidth)){
			w=this.offsetWidth;
		}else{
			w=this.clientWidth;
		}
		this.style.display=dis;
		return w;

	},

	getOffsetTop:function(){
		comment='取得物件距離視窗左側距離';
		var dis=this.style.display;
		this.style.display='';
		var oDiv=this;
		var oTop=oDiv.offsetTop;
		while (oDiv.offsetParent){
			oDiv=oDiv.offsetParent;
			oTop+=oDiv.offsetTop;
		}
		this.style.display=dis;
		return oTop;
	},

	getOffsetLeft:function(){
		comment='取得物件距離視窗頂端距離';
		var dis=this.style.display;
		this.style.display='';
		var oDiv=this;
		var oLeft=oDiv.offsetLeft;
		while (oDiv.offsetParent){
			oDiv=oDiv.offsetParent;
			oLeft+=oDiv.offsetLeft;
		}
		this.style.display=dis;
		return oLeft;
	},

	getTop:function(x){
		comment='取得物件相對於指定上層物件左側距離';
		if (typeof x!='object'){
			alert('getTop(obj) method:obj must be \'OBJECT\' type');
			return false;
		}
		var dis=this.style.display;
		this.style.display='';
		var oDiv=this;
		var oTop=oDiv.offsetTop;
		while (oDiv.offsetParent!=x){
			oDiv=oDiv.offsetParent;
			oTop+=oDiv.offsetTop;
		}
		this.style.display=dis;
		return oTop;
	},

	getLeft:function(x){
		comment='取得物件相對於指定上層物件頂端距離';
		if (typeof x!='object'){
			alert('getLeft(obj) method:obj must be \'OBJECT\' type');
			return false;
		}
		var dis=this.style.display;
		this.style.display='';
		var oDiv=this;
		var oLeft=oDiv.offsetLeft;
		while (oDiv.offsetParent!=x){
			oDiv=oDiv.offsetParent;
			oLeft+=oDiv.offsetLeft;
		}
		this.style.display=dis;
		return oLeft;
	},

	getCSSValue:function(property){
		return window.getComputedStyle(this,null).getPropertyValue(property);
	},

	getWidthMargin:function(){
		//取得水平方向所有邊界,留白,邊框寬度總和
		var wm=0,temp;
		if (this.currentStyle){
			temp=parseInt(this.currentStyle['borderRightWidth']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['borderLeftWidth']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['marginRight']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['marginLeft']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['paddingRight']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['paddingLeft']);
			wm+=(isNaN(temp))?0:temp;
		}else{
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-right-width'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-left-width'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('margin-right'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('margin-left'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('padding-right'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('padding-left'));
		}

		return wm;
	},

	getHeightMargin:function(){
		//取得垂直方向所有邊界,留白,邊框寬度總和
		var wm=0,temp;
		if (this.currentStyle){
			temp=parseInt(this.currentStyle['borderTopWidth']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['borderBottomWidth']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['marginTop']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['marginBottom']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['paddingTop']);
			wm+=(isNaN(temp))?0:temp;
			temp=parseInt(this.currentStyle['paddingBottom']);
			wm+=(isNaN(temp))?0:temp;
		}else{
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-top-width'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-bottom-width'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('margin-top'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('margin-bottom'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('padding-top'));
			wm+=parseInt(window.getComputedStyle(this,null).getPropertyValue('padding-bottom'));
		}

		return wm;
	},

	shadow:function(x,y,offset,color){
		x=(typeof x=='undefined')?3:x;
		y=(typeof y=='undefined')?3:y;
		offset=(typeof offset=='undefined')?3:offset;
		color=(typeof color=='undefined')?'#333':color;

		if (isIE){
		}

		this.style.BoxShadow=x+'px '+y+'px '+offset+'px '+color;
		this.style.MozBoxShadow=x+'px '+y+'px '+offset+'px '+color;
		this.style.WebkitBoxShadow=x+'px '+y+'px '+offset+'px '+color;

		return this;
	},

	borderRadius:function(radius){
		radius=(typeof radius=='undefined')?5:radius;

		this.style.BorderRadius=radius+'px';
		this.style.MozBorderRadius=radius+'px';
		this.style.WebkitBorderRadius=radius+'px';

		//border-radius-topleft:5px;
		//-moz-border-radius-topleft:5px;
		//-webkit-border-top-left-radius:5px;
		//border-radius-topright:5px;
		//-moz-border-radius-topright:5px;
		//-webkit-border-top-right-radius:5px;

		return this;
	},

	//Methods
	center:function(x){
		//var w=(this.clientWidth)?this.clientWidth:this.offsetWidth;
		//var w=parseInt(this.style.width);
		x=(isNaN(x))?0:x;
		var w=$(this).Width();
		var bWidth=(this.ie)?window.document.documentElement.clientWidth:window.innerWidth;
		this.style.left=((bWidth-w)/2+x)+'px';

		return this;
	},

	middle:function(x){
		//var h=(this.clientHeight)?this.clientHeight:this.offsetHeight;
		//var w=parseInt(this.style.height);
		var distance=(!isNaN(x))?x:0;
		var h=$(this).Height();
		var bHeight=(this.ie)?window.document.documentElement.clientHeight:window.innerHeight;
		this.style.top=((bHeight-h)/2+distance)+'px';

		return this;
	},

	absmiddle:function(x){
		//var h=(this.clientHeight)?this.clientHeight:this.offsetHeight;
		//var w=parseInt(this.style.height);
		var distance=(!isNaN(x))?x:0;
		var h=this.Height();
		var bHeight=(this.ie)?window.document.documentElement.clientHeight:window.innerHeight;
		this.style.top=Math.max((screen.availHeight-h)/2-(screen.availHeight-bHeight)+distance,0)+'px';

		return this;
	},

	moveToTop:function(x){
		var margin=(!isNaN(x))?x:0;
		this.position('absolute');
		this.top(margin);
		return this;
	},

	moveToRight:function(x){
		var margin=(!isNaN(x))?x:0;
		this.left(this.bWidth-this.Width()-margin);
		this.position('absolute');
		return this;
	},

	moveToBottom:function(x){
		var margin=(!isNaN(x))?x:0;
		this.position('absolute');
		this.top(this.bHeight-this.Height()-margin);
		return this;
	},

	moveToLeft:function(x){
		var margin=(!isNaN(x))?x:0;
		this.position('absolute');
		this.left(margin);
		return this;
	},

	show:function(){
		this.style.visibility='visible';

		return this;
	},

	hide:function(){
		this.style.visibility='hidden';

		return this;
	},


	move:function(top,left){
		//this.style.top=top+'px';
		//this.style.left=left+'px';
		this.top(top);
		this.left(left);

		return this;
	},

	moveto:function(top,left){
		//this.style.top=top+'px';
		//this.style.left=left+'px';
		this.top(top);
		this.left(left);

		return this;
	},

	fullscreen:function(){
		var o=this;
		var scrollY = (this.ie)?document.documentElement.scrollTop:self.pageYOffset;
		this.width('100%');
		this.height('100%');
		this.move(scrollY,0);
		return this;
	},

	floatMark:function(scrollSpeed,intervalTime,stopAt){

		this.s=(typeof scrollSpeed=='undefined')?10:scrollSpeed;
		this.iT=(typeof intervalTime=='undefined')?1:intervalTime;
		this.t=(typeof stopAt=='undefined')?this.getOffsetTop():stopAt;
		//var keepAt=(typeof stopAt=='undefined')?0:this.getOffsetTop();

		this.position('absolute');
		this.top(this.t);

		this.keepAt=0;
		this.scrollY=0;
		this.newY=0;
		this.percent=0;

		var o=this;

		clearInterval(this.intervalOBJ);
		this.intervalOBJ=setInterval(function(){
			o.scrollY = (o.ie)?document.documentElement.scrollTop:self.pageYOffset;
			if (o.style.visibility!='hidden'){
				if(o.scrollY != o.keepAt){
					o.percent = 1 * (o.scrollY - o.keepAt) / o.s;
					o.percent=(o.percent>0)?Math.ceil(o.percent):Math.floor(o.percent);

					o.newY=o.top();
					o.newY+=o.percent;
					o.top(o.newY);

					//keepAt+=percent;
					o.keepAt+=o.percent;
				}else{
					clearInterval(o.intervalOBJ);
				}
			}

		},o.iT);

		return this;
	},

	float:function(scrollSpeed,intervalTime,stopAt){

		this.s=(typeof scrollSpeed=='undefined')?10:scrollSpeed;
		this.iT=(typeof intervalTime=='undefined')?1:intervalTime;
		this.t=(typeof stopAt=='undefined')?this.getOffsetTop():stopAt;

		this.position('absolute');
		this.top(this.t);

		this.keepAt=0;
		this.scrollY=0;
		this.newY=0;
		this.percent=0;

		var o=this;

		clearInterval(this.intervalOBJ);
		this.intervalOBJ=setInterval(function(){
			o.scrollY = (o.ie)?document.documentElement.scrollTop:self.pageYOffset;
			if (o.style.visibility!='hidden'){
				if(o.scrollY != o.keepAt){
					o.percent = 1 * (o.scrollY - o.keepAt) / o.s;
					o.percent=(o.percent>0)?Math.ceil(o.percent):Math.floor(o.percent);

					o.newY=o.top();
					o.newY+=o.percent;
					o.top(o.newY);

					//keepAt+=percent;
					o.keepAt+=o.percent;
					//console.trace(o.keepAt);
				}else{
					//clearInterval(o.intervalOBJ);
					//清掉了，就不會動了
					//console.trace('stop');
				}
			}

		},o.iT);

		return this;
	},

	slide:function(startPos,endPos,interval,fade){
		if (typeof startPos=='object'){
			if (startPos==[0,0]){
				this.s=[this.getOffsetTop(),this.getOffsetLeft()];
				this.e=[this.getOffsetTop()+endPos[0],this.getOffsetLeft()+endPos[1]];
			}else{
				this.s=startPos;
				this.e=endPos;
			}

		}else{
			this.s=[this.getOffsetTop(),this.getOffsetLeft()];
			this.e=endPos;
		}

		this.operator=[];
		this.expression=[];
		this.mathOperator=[];
		this.direction=[];

		for (var i=0;i<this.s.length;i++){
			this.operator[i]=(this.s[i]<this.e[i])?'+':'-';
			this.expression[i]=(this.s[i]<this.e[i])?'<':'>';
			this.mathOperator[i]=(this.s[i]<this.e[i])?'Math.min':'Math.max';
		}

		this.style.position='absolute';

		this.direction[0]='top';
		this.direction[1]='left';
		this.style.top=this.s[0]+'px';
		this.style.left=this.s[1]+'px';

		if (typeof interval=='undefined'){
			interval=120;
		}else{
			switch(interval){
				case 'fast':
					interval-=20;
					break;
				case 'faster':
					interval-=40;
					break;
				case 'slow':
					interval+=20;
					break;
				case 'slower':
					interval+=40;
					break;
				default:
					interval=(isNaN)?120:interval;
					break;
			}
		}

		this.stepY=Math.abs(this.s[0]-this.e[0])/interval;
		this.stepX=Math.abs(this.s[1]-this.e[1])/interval;
		this.fade=null;


		if (typeof fade!='undefined'){
			this.style.opacity=(fade=='fadein')?0:1;
			this.opacity=this.style.opacity;
			this.fade=(fade=='fadein')?'fadein':'fadeout';
			this.opaStep=(fade=='fadein')?1/interval:(0-1/interval);
		}


		var o=this;

		this.clearInvterval=true;
		this.clearY=false;
		this.clearX=false;
		clearInterval(this.intervalOBJ);
		//alert(this.s[0]+','+this.e[0]+','+this.opaStep);

		this.intervalOBJ=setInterval(function(){

				o.stepY*=1.05;
				o.stepX*=1.05;

				if (eval('o.s[0]'+o.expression[0]+'o.e[0]')){
					eval('o.s[0]'+o.operator[0]+'=o.stepY');
					eval('o.style.'+o.direction[0]+'='+o.mathOperator[0]+'('+o.e[0]+','+o.s[0]+')+\'px\'');
				}else{
					o.clearY=true;
				}
				if (eval('o.s[1]'+o.expression[1]+'o.e[1]')){
					eval('o.s[1]'+o.operator[1]+'=o.stepX');
					eval('o.style.'+o.direction[1]+'='+o.mathOperator[1]+'('+o.e[1]+','+o.s[1]+')+\'px\'');
				}else{
					o.clearX=true;
				}

				o.opaStep*=1.05;
				o.opacity=parseFloat(o.opacity+o.opaStep);
				o.style.opacity=o.opacity;

				if (o.clearY&&o.clearX){
					clearInterval(o.intervalOBJ);
				}
		},1);

		return this;

	},

	marquee:function(paras){
		if (typeof paras=='undefined'){
			paras={
				type:'smooth',
				direct:'left',
				width:this.Width(),
				height:this.Height(),
				speed:1,
				delay:3,
				step:this.Width()
			}
		}else{
			paras.type=(typeof paras.type=='undefined')?'smooth':paras.type;
			paras.direct=(typeof paras.direct=='undefined')?'left':paras.direct;
			paras.width=(typeof paras.width=='undefined')?this.Width():paras.width;
			paras.height=(typeof paras.height=='undefined')?this.Height():paras.height;
			paras.speed=(typeof paras.speed=='undefined')?1:Math.abs(parseInt(paras.speed));
			paras.delay=(typeof paras.delay=='undefined')?3:Math.abs(parseInt(paras.delay));
			paras.step=(typeof paras.step=='undefined')?this.Width():Math.abs(parseInt(paras.step));
		}

		//alert(paras.direct);
		//alert(paras.width);
		//alert(paras.height);
		var o=this;

		this.height(paras.height);
		this.width(paras.width);
		this.style.position='relative';
		this.style.overflow='hidden';
		this.onmouseover=function(){this.pause();};
		this.onmouseout=function(){this.start();};
		this.motion=false;

		this.marquee_iHTML=this.innerHTML;
		this.innerHTML='';
		this.marquee_iID='marquee_'+new Date().getTime();
		//算一下, marquee 的寬高夠不夠擺滿指定畫面, 不夠的話, 重複
		//先建一個虛的 layer 在很遠的地方

		this.marquee_virtualLayer=document.createElement('div');
		this.marquee_virtualLayer.innerHTML=this.marquee_iHTML;
		document.getElementsByTagName('body')[0].appendChild(this.marquee_virtualLayer);
		this.marquee_virtualLayer.position('absolute');
		this.marquee_virtualLayer.left(-10000);
		this.marquee_virtualLayer.top(-10000);

		//產生兩個 div 放內容, for continous
		this.marquee_iDIVa=document.createElement('div');
		this.marquee_iDIVb=document.createElement('div');
		this.appendChild(this.marquee_iDIVa);
		this.appendChild(this.marquee_iDIVb);
		//

		switch(paras.direct){
			case 'left':
				this.repeat_html_times=Math.ceil(parseInt(paras.width)/this.marquee_virtualLayer.Width());
				for (var i=0;i<this.repeat_html_times;i++){
					this.marquee_iDIVa.innerHTML+=this.marquee_iHTML;
					this.marquee_iDIVb.innerHTML+=this.marquee_iHTML;
				}
				this.marquee_size=this.marquee_virtualLayer.Width()*this.repeat_html_times;
				this.marquee_funs='left';
				this.marquee_op='<';
				this.marquee_iDIVa.left(0);
				this.marquee_iDIVa.height(paras.height);
				this.marquee_iDIVa.width(this.marquee_size);
				this.marquee_iDIVb.left(this.marquee_size);
				this.marquee_iDIVb.height(paras.height);
				this.marquee_iDIVb.width(this.marquee_size);

				paras.step_array=[0,0-paras.step];
				break;
			case 'right':
				this.repeat_html_times=Math.ceil(parseInt(paras.width)/this.marquee_virtualLayer.Width());
				for (var i=0;i<this.repeat_html_times;i++){
					this.marquee_iDIVa.innerHTML+=this.marquee_iHTML;
					this.marquee_iDIVb.innerHTML+=this.marquee_iHTML;
				}
				this.marquee_size=0-this.marquee_virtualLayer.Width()*this.repeat_html_times;
				this.marquee_funs='left';
				this.marquee_op='>';
				this.marquee_iDIVa.left(0);
				this.marquee_iDIVa.height(paras.height);
				this.marquee_iDIVa.width(0-this.marquee_size);
				this.marquee_iDIVb.left(this.marquee_size);
				this.marquee_iDIVb.height(paras.height);
				this.marquee_iDIVb.width(0-this.marquee_size);

				paras.speed=0-paras.speed;
				paras.step_array=[0,paras.step];
				break;
			case 'up':
				this.repeat_html_times=Math.ceil(parseInt(paras.height)/this.marquee_virtualLayer.Height());
				for (var i=0;i<this.repeat_html_times;i++){
					this.marquee_iDIVa.innerHTML+=this.marquee_iHTML;
					this.marquee_iDIVb.innerHTML+=this.marquee_iHTML;
				}
				this.marquee_size=this.marquee_virtualLayer.Height()*this.repeat_html_times;
				this.marquee_funs='top';
				this.marquee_op='<';
				this.marquee_iDIVa.top(0);
				this.marquee_iDIVa.width(paras.width);
				this.marquee_iDIVa.height(this.marquee_size);
				this.marquee_iDIVb.top(this.marquee_size);
				this.marquee_iDIVb.width(paras.width);
				this.marquee_iDIVb.height(this.marquee_size);

				paras.step=0-paras.step;
				paras.step_array=[0-paras.step,0];
				break;
			case 'down':
				this.repeat_html_times=Math.ceil(parseInt(paras.height)/this.marquee_virtualLayer.Height());
				for (var i=0;i<this.repeat_html_times;i++){
					this.marquee_iDIVa.innerHTML+=this.marquee_iHTML;
					this.marquee_iDIVb.innerHTML+=this.marquee_iHTML;
				}
				this.marquee_size=0-this.marquee_virtualLayer.Height()*this.repeat_html_times;
				this.marquee_funs='top';
				this.marquee_op='>';
				this.marquee_iDIVa.top(0);
				this.marquee_iDIVa.width(paras.width);
				this.marquee_iDIVa.height(0-this.marquee_size);
				this.marquee_iDIVb.top(this.marquee_size);
				this.marquee_iDIVb.width(paras.width);
				this.marquee_iDIVb.height(0-this.marquee_size);

				paras.speed=0-paras.speed;
				paras.step_array=[paras.step,0];
				break;
			default:
				this.repeat_html_times=Math.floor(parseInt(paras.width)/this.marquee_virtualLayer.Width());
				for (var i=0;i<this.repeat_html_times;i++){
					this.marquee_iDIVa.innerHTML+=this.marquee_iHTML;
					this.marquee_iDIVb.innerHTML+=this.marquee_iHTML;
				}
				this.marquee_size=this.marquee_virtualLayer.Width()*this.repeat_html_times;
				this.marquee_funs='left';
				this.marquee_op='<';
				this.marquee_iDIVa.left(0);
				this.marquee_iDIVa.height(paras.height);
				this.marquee_iDIVa.width(this.marquee_size);
				this.marquee_iDIVb.left(this.marquee_size);
				this.marquee_iDIVb.height(paras.height);
				this.marquee_iDIVb.width(this.marquee_size);

				paras.step_array=[0,0-paras.step];
				break;
		}

		//this.marquee_iDIV.style.position='absolute';
		this.marquee_iDIVa.style.overflow='hidden';
		this.marquee_iDIVb.style.overflow='hidden';
		this.flow_switch='';

		this.marquee_click=0;
		this.stopControl=setInterval(function(){
			if (paras.type=='sliding'){
				o.marquee_click++;
				if (paras.delay==o.marquee_click){
					o.motion=true;
					o.marquee_click=0;
				}else{
					o.motion=false;
				}
				paras.speed=30;
			}
			if (paras.type=='smooth'){
				o.motion=true;
			}
		},1000);

		this.marquee_interval_str='function(){'+
			'if (o.motion){'+
			'	if (o.marquee_iDIVa.'+o.marquee_funs+'()'+o.marquee_op+'o.marquee_iDIVb.'+o.marquee_funs+'()){'+
			'		o.flow_switch=\'b\';'+
			'	}else{'+
			'		o.flow_switch=\'a\';'+
			'	}'+
			'	if ((o.flow_switch==\'b\')&&(o.marquee_iDIVb.'+o.marquee_funs+'()'+this.marquee_op+'0)){'+
			'			o.marquee_iDIVa.'+o.marquee_funs+'('+o.marquee_size+');'+
			'	}'+
			'	if ((o.flow_switch==\'a\')&&(o.marquee_iDIVa.'+o.marquee_funs+'()'+this.marquee_op+'0)){'+
			'		o.marquee_iDIVb.'+o.marquee_funs+'('+o.marquee_size+');'+
			'	}'+

			'	o.marquee_varoffset=o.marquee_iDIVa.'+o.marquee_funs+'();'+
			'	o.marquee_varoffset-=paras.speed;'+
			'	o.marquee_iDIVa.'+o.marquee_funs+'(o.marquee_varoffset);'+

			'	o.marquee_varoffset=o.marquee_iDIVb.'+o.marquee_funs+'();'+
			'	o.marquee_varoffset-=paras.speed;'+
			'	o.marquee_iDIVb.'+o.marquee_funs+'(o.marquee_varoffset);'+
			'}'+
			''+
		'}';

		eval('this.marquee_interval='+this.marquee_interval_str);

		this.marquee_timeout=setTimeout(function(){
			o.marquee_intervalOBJ=setInterval(o.marquee_interval,1);
		},paras.delay*1000);

		this.pause=function(){
			clearInterval(this.marquee_intervalOBJ);
		};

		this.start=function(){
			this.marquee_intervalOBJ=setInterval(this.marquee_interval,1);
		};

	},

	draggable:function(dragHandler){
		if (typeof dragHandler!='undefined'){
			this.setAttribute('dragHandler',dragHandler);
			$id(dragHandler).setAttribute('draggable','draggable');
			$id(dragHandler).onmouseover=function(){isDraggable(this);return false;};
			$id(dragHandler).onmousedown=function(){startDrag(this);return false;};

			var wintitle=$(dragHandler).innerHTML;
			$(dragHandler).innerHTML='<img style="position:relative;width:15px;height:15px;float:right;cursor:default;" onclick="$id(this.parentNode.getAttribute(\'parentDiv\')).display(\'hide\');" img src="/images/x.png" width="15" height="15" border="0" />'+wintitle+'&nbsp;';

			if ($id(dragHandler).getAttribute('parentDiv')==null){
				$id(dragHandler).setAttribute('parentDiv',this.id);
			}else{
				var dH=$id(dragHandler).getAttribute('parentDiv');
				$id(dragHandler).setAttribute('parentDiv',dH+','+this.id);
			}
		}else{
			this.setAttribute('draggable','draggable');
			this.onmouseover=function(){isDraggable(this);return false;};
			this.onmousedown=function(){startDrag(this);return false;};
		}

		return this;
	},

	drag:function(dragHandler){
		if (typeof dragHandler!='undefined'){
			this.setAttribute('dragHandler',dragHandler);
			$id(dragHandler).setAttribute('draggable','draggable');
			$id(dragHandler).onmouseover=function(){isDraggable(this);return false;};
			$id(dragHandler).onmousedown=function(){startDrag(this);return false;};

			var wintitle=$(dragHandler).innerHTML;
			$(dragHandler).innerHTML='<img style="position:relative;width:15px;height:15px;float:right;cursor:default;" onclick="$id(this.parentNode.getAttribute(\'parentDiv\')).display(\'hide\');" img src="/images/x.png" width="15" height="15" border="0" />'+wintitle+'&nbsp;';

			if ($id(dragHandler).getAttribute('parentDiv')==null){
				$id(dragHandler).setAttribute('parentDiv',this.id);
			}else{
				var dH=$id(dragHandler).getAttribute('parentDiv');
				$id(dragHandler).setAttribute('parentDiv',dH+','+this.id);
			}
		}else{
			this.setAttribute('draggable','draggable');
			this.onmouseover=function(){isDraggable(this);return false;};
			this.onmousedown=function(){startDrag(this);return false;};

		}

		return this;
	},

	dragResize:function(dragHandler){
		if (typeof dragHandler!='undefined'){
			this.setAttribute('dragHandler',dragHandler);
			$id(dragHandler).setAttribute('draggable','draggable');
			$id(dragHandler).onmouseover=function(){isDraggable(this);return false;};
			$id(dragHandler).onmousedown=function(){startDrag(this);return false;};
			if ($id(dragHandler).getAttribute('parentDiv')==null){
				$id(dragHandler).setAttribute('parentDiv',this.id);
			}else{
				var dH=$id(dragHandler).getAttribute('parentDiv');
				$id(dragHandler).setAttribute('parentDiv',dH+','+this.id);
			}
		}else{
			this.setAttribute('draggable','draggable');
			this.onmouseover=function(){isDraggable(this);return false;};
			this.onmousedown=function(){startDrag(this,false);return false;};
		}

		if (this.currentStyle){
			var bt=parseInt(this.currentStyle['borderTopWidth']);
			var br=parseInt(this.currentStyle['borderRightWidth']);
			var bb=parseInt(this.currentStyle['borderBottomWidth']);
			var bl=parseInt(this.currentStyle['borderLeftWidth']);
		}else{
			var bt=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-top-width'));
			var br=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-right-width'));
			var bb=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-bottom-width'));
			var bl=parseInt(window.getComputedStyle(this,null).getPropertyValue('border-left-width'));
		}
		bt=(bt==0)?4:bt;br=(br==0)?4:br;bb=(bb==0)?4:bb;bl=(bl==0)?4:bl;


		////左上角
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='nw-resize';
		//div.style.backgroundColor='#000';
		//$(div).width(bl).height(bt).move(0-bt,0-bl);
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);

		//右下角
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='nw-resize';
		//div.style.backgroundColor='#000';
		//$(div).width(br).height(bb).move(this.height(),this.width());
		//div.onmouseover=function(){this.parentNode.onmousedown=function(){startDrag(this,true);return false;}};
		//div.onmouseout=function(){this.parentNode.onmousedown=function(){startDrag(this,false);return false;}};
		//this.appendChild(div);

		//右上角
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='sw-resize';
		//div.style.backgroundColor='#000';
		//$(div).width(br).height(bt).move(0-bt,this.width());
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);

		//左下角
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='sw-resize';
		//div.style.backgroundColor='#000';
		//$(div).width(bl).height(bb).move(this.height(),0-bl);
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);

		//上
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='n-resize';
		//div.style.backgroundColor='#000';
		//$(div).width('100%').height(bt).move(0-bt,0);
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);

		//下
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='n-resize';
		//div.style.backgroundColor='#000';
		//$(div).width('100%').height(bb).move(this.height(),0);
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);

		//左
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='w-resize';
		//div.style.backgroundColor='#000';
		//$(div).width(bl).height('100%').move(0,0-bl);
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);

		//右
		//var div=document.createElement('div');
		//div.style.position='absolute';
		//div.style.cursor='w-resize';
		//div.style.backgroundColor='#000';
		//$(div).width(br).height('100%').move(0,this.width());
		//div.onmousedown=function(){startDrag(this.parentNode,true);return false;};
		//this.appendChild(div);



		return this;
	},

	fixed:function(){
		var o=this;
		if (o.ie){
			this.floatMark();
		}else{
			this.style.position='fixed';
		}
		this.setAttribute('draggable','fixed');
		this.onmouseover=null;
		this.onmousedown=null;

		return this;
	},

	fixedTop:function(x){
		var distance=(!isNaN(x))?x:0;
		var o=this;
		if (o.ie){
			this.top(document.documentElement.scrollTop);
			this.floatMark(10,1,distance);
		}else{
			this.style.top=distance+'px';
			this.style.position='fixed';
		}
		this.setAttribute('draggable','fixed');
		this.onmouseover=null;
		this.onmousedown=null;

		return this;
	},

	fixedBottom:function(x){
		var distance=(!isNaN(x))?x:0;
		var o=this;
		if (o.ie){
			var bH=document.documentElement.scrollTop;
			this.top(bH-this.Height()-distance);
			this.floatMark(10,1,this.bHeight-this.Height()-distance);
		}else{
			var bH=window.innerHeight;
			var divHeight=o.Height();
			this.top(bH-divHeight-distance);
			this.style.position='fixed';
		}
		this.setAttribute('draggable','fixed');
		this.onmouseover=null;
		this.onmousedown=null;

		return this;
	},

	fadein:function(){
		clearInterval(this.intervalOBJ);
		this.style.opacity=(isNaN(parseFloat(this.style.opacity)))?0:this.style.opacity;
		var o=this;
		var step=0;
		this.intervalOBJ=setInterval(function(){
				if (step<80){
					step+=5;
					o.style.opacity=step/50;
				}else{
					clearInterval(o.intervalOBJ);
				}
		},1);
		return this;
	},

	fadeout:function(){
		clearInterval(this.intervalOBJ);
		this.style.opacity=(isNaN(parseFloat(this.style.opacity)))?1:this.style.opacity;
		var o=this;
		var step=50;
		this.intervalOBJ=setInterval(function(){
				if (step>0){
					step-=5;
					o.style.opacity=step/50;
				}else{
					clearInterval(o.intervalOBJ);
				}
		},1);
		return this;
	},

	test:function(){
		wait();
	}
};


function __addMethod(elm,obj,overwrite){
	for (var key in obj) {
		//eval(elm+'.'+key+'='+obj[key]);
		if (overwrite){
			elm[key]=obj[key];
		}else{
			if (typeof elm[key]=='undefined'){
				elm[key]=obj[key];
			}
		}
   	}
}


window.$=function (node){
	if (typeof node == 'string'){
		//ref. http://www.vbforums.com/archive/index.php/t-478634.html
		node=document.getElementById(node);
	}

	if(node!=null && !node.test){
		//自訂 property 'test'=true, 如果物件已經存在, 且已繼承屬性方法, 就不再多此一舉
		//IE 不支援對 prototype object 的自訂方法及屬性, 所以只好針對宣告成 document.getElementById 的物件加上自定的方法和屬性
		//這種方式,當頁面中大量使用這些物件語法時, 一個 $(layer) 就要跑一遍, IE 會累死
		//所以測一下是不是已經存在且處理過, 才決定要不要宣告自訂的方法及屬性
		//以下作法可行 8/29 09'
		if (!window.Element) {
			__addMethod(node,__methods,false);
		}
	}

	return node;
};


if (window.Element) {
	__addMethod(Element.prototype,__methods);

}

function $id(node){
	if (typeof node=='string'){
		return document.getElementById(node);
	}
}

function $$(node){
	if (typeof node == 'string'){
		node = document.getElementsByTagName(node);
	}

	return node;
}
//********************************************************************************
//String
//

var __str_methods={
	atrim:function(){
		return this.replace(/\s/g,'');
	},

	isEmpty:function(){
		return (this.replace(/\s/g,'')=='')?true:false;
	},

	right:function(n){
		var start=this.length-n;
		return this.substr(start,n);
	},

	left:function(n){
		return this.substr(0,n);
	},

	cs:function(){
		//return this.replace(/[\$&%<>\+,\/:\'\";=\?\\]/g,'');
		return cs(this);
	},

	cn:function(){
		//return this.replace(/[^\d.-]/g,'');
		return cn(this);
	},

	dateAdd:function(interval,number,format){
		//AS VB DateAdd
		number = parseInt(number);
		var date = new Date(this.toString());

		switch(interval){
			case "y": date.setFullYear(date.getFullYear()+number); break;
			case "m": date.setMonth(date.getMonth()+number); break;
			case "d": date.setDate(date.getDate()+number); break;
			case "w": date.setDate(date.getDate()+7*number); break;
			case "h": date.setHours(date.getHour()+number); break;
			case "n": date.setMinutes(date.getMinutes()+number); break;
			case "s": date.setSeconds(date.getSeconds()+number); break;
			case "l": date.setMilliseconds(date.getMilliseconds()+number); break;
		}

		switch(format){
			case 'full':
				break;
			default:
				return date.getFullYear()+'/'+(date.getMonth()+1)+'/'+date.getDate();

		}
	},

	trim:function(){
		return this.replace(/^\s+|\s+$/g, '');

	}


};

__addMethod(String.prototype,__str_methods,false);
//********************************************************************************
//Array
//
var __array_methods={
	indexOf:function(v,b,s){
		for(var i=+b || 0,l=this.length;i<l;i++){
			if(this[i]===v || s && this[i]==v){
				return i;
			}
		}
		return -1;
	},

	myIndexOf:function(v){
		for (var i=0;i<this.length;i++){
			if (this[i]-v==0){
				return i;
			}
		}
		return -1;
	},

	unique:function(b){
		var a=[],i,l=this.length;
		for(i=0;i<l;i++){
			if(a.indexOf(this[i],0,b)<0){
				a.push(this[i]);
			}
		}
		return a;
	},

	sum:function(){
		var i=this.length,k=0;
		while(i--){
			k+=parseFloat(this[i]);
		}
		return k;
	},

	AND:function(b){
		var a=[],i,l=b.length;
		for (i=0;i<l;i++){
			if (this.indexOf(b[i])!=-1){
				a.push(b[i]);
			}
		}
		return a;
	},

	OR:function(b){
		var a=this.concat(b);
		a.unique();
		return a;
	}
};

__addMethod(Array.prototype,__array_methods,false);


//********************************************************************************
//Window
//
function onloadAttach(funName){
	if (window.addEventListener){
		//Mozilla 事件沒有 on 開頭
		window.addEventListener('load',funName, false);
	}else if (window.attachEvent){
		window.attachEvent('onload',funName);
	}
}
//__addMethod(Window,__array_methods,false);

//********************************************************************************
//Ajax
//
Ajax=function(args){
	this.funName=arguments.callee.name;
	this.createXHR=function(){
		var xmlhttp;
		if (window.XMLHttpRequest){
			xmlhttp = new XMLHttpRequest();
		}else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}

		if (!xmlhttp){
			return false;
		}else{
			return xmlhttp;
		}
	};


	this.getFormValue=function(form){
		var str='',ft,fv;
		for (var i=0;i<form.elements.length;i++){
			fv=form.elements[i];
			if (typeof fv.name!='undefined'){
				ft=fv.type.toLowerCase();

				switch(ft){
					case 'select-one':
						str+=fv.name+'='+escape(fv.value)+'&';
						break;
					case 'radio':
						if (fv.checked){
							str+=fv.name+'='+escape(fv.value)+'&';
						}
						break;
					case 'checkbox':
						if (fv.checked){
							str+=fv.name+'='+escape(fv.value)+'&';
						}
						break;
					case 'text':
						str+=fv.name+'='+escape(fv.value)+'&';
						break;
					case 'password':
						str+=fv.name+'='+escape(fv.value)+'&';
						break;
					case 'hidden':
						str+=fv.name+'='+escape(fv.value)+'&';
						break;
					case 'textarea':
						str+=fv.name+'='+escape(fv.value)+'&';
						break;
					default:
						break;
				}
			}
		}

		return str.split(/\s/).join('')
	};

	if (typeof args.method=='undifined'){args.method='get';}

	this.url=args.url;
	this.method=args.method.toLowerCase();
	this.form=args.form;

	this.xmlhttp=this.createXHR();

	var o=this;

	this.xmlhttp.open(this.method,this.url,true);
	this.xmlhttp.onreadystatechange=function(){
		if (o.xmlhttp.readyState==4){
			if (o.xmlhttp.status == 200) {
				args.success(o.xmlhttp,o.form);
			}else{
				args.failure(o.xmlhttp,o.form);
			}
		}
	};

	if (this.method=='get'){
		this.xmlhttp.send(null);
	};
	if (this.method=='post'){
		this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.xmlhttp.send(this.getFormValue(this.form));
	};

	this.xmlhttp.reportError=function(funName){
		msgBox('<div>AJAX:['+funName+']</div><div>status:'+this.status+'</div>Detail:<p>'+this.responseText+'</p>','50%');
	};

	this.xmlhttp.xmltojson=function(key){
		var xml=this.responseXML.getElementsByTagName(key);
		if (typeof xml!='object'){
			return false;
		}

		var json=[];
		for (var i=0;i<xml.length;i++){
			json.push({});
			for (var k=0;k<xml[i].childNodes.length;k++){
				json[i][xml[i].childNodes[k].tagName]=xml[i].childNodes[k].firstChild.nodeValue;
			}
		}
		return json;
	};

	this.xmlhttp.getTagValue=function(tag){
		var xml=this.responseXML.getElementsByTagName(tag);
		//alert(xml.getElementsByTagName('PLoginID')[0].childNodes[0].nodeValue);
		if (xml.length==0){
			return false;
		}

		if (xml.length==1){
			return xml[0].childNodes[0].nodeValue;
		}

		if (xml.length>1){
			var na=[];
			for (var i=0;i<xml.length;i++){
				na.push(xml[i].childNodes[0].nodeValue);
			}
			return na;
		}

		//return xml.length;
	};


	this.xmlhttp.restoreFormValue=function(form,tag){
		var na=this.getNodeContent(tag);
		for (var i=0;i<na.length;i++){
			if (typeof form[na[i][0]]=='object'){

				fv=form[na[i][0]];

				if (typeof fv.type=='undefined' || fv.type=='undefined' || fv.type==null){
					a='radio-checkbox';
				}else{
					ft=fv.type.toLowerCase();
					a=ft;
				}
				switch(a){
					case 'select-one':
						//alert(fv.name+':'+fv.length+','+na[i][1]);
						for (var k=0;k<fv.length;k++){
							if (fv.options[k].text==na[i][1]){
								fv.selectedIndex=k;
								break;
							}
						}
						//增加值的比對, 計價方式的值和文字不同 6/14 08'
						for (var k=0;k<fv.length;k++){
							if (fv.options[k].value==na[i][1]){
								fv.selectedIndex=k;
								break;
							}
						}
						break;
					case 'checkbox':
						if (na[i][1]){a.checked=true;}
						break;
					//增加 radio 比對 6/14 08'
					case 'radio-checkbox':
						for (var k=0;k<fv.length;k++){
							if (fv[k].value==na[i][1]){
								fv[k].checked=true;
								break;
							}
						}
					default:
						fv.value=unescape(na[i][1]);
						break;
				}
			}
		}
	};


	this.xmlhttp.getNodeContent=function(key,label) {
		var na=[],va=[],l;
		var outstr='';
		var xmldoc=this.responseXML;

		key=(typeof key=='undefined')?this.getNodeName(xmldoc,false):key;

		for (var i=0;i<xmldoc.getElementsByTagName(key).length;i++){
			var xml=xmldoc.getElementsByTagName(key)[i];
			na=this.getNodeName(xml,false);	//必需是唯一值,因為接下來的動作,會依序讀出

			for (var j=0;j<na.length;j++){
				var xmlk=xml.getElementsByTagName(na[j]);
				for (var k=0;k<xmlk.length;k++){
					l=Math.max(va.length,va.length-1);
					if(typeof label!='undefined'){
						if(typeof xmlk[k].getAttribute(label)!=null && typeof xmlk[k].getAttribute(label)!=''){
							va[l]=[xmlk[k].getAttribute(label),xmlk[k].childNodes[0].nodeValue];
						}else{
							va[l]=[na[j],xmlk[k].childNodes[0].nodeValue];
						}
					}else{
						va[l]=[na[j],xmlk[k].childNodes[0].nodeValue];
					}
					outstr+=va[l]+'\n';
				}
			}
		}

		//alert(outstr);
		//xmlToTable(va);

		return va
	};

	this.xmlhttp.getNodeName=function(xmldoc,duplicate){
		var d;
		var na=[];

		d=(typeof duplicate=='undefined')?true:duplicate;

		for (var i=0;i<xmldoc.childNodes.length;i++){
			if (xmldoc.childNodes[i].hasChildNodes()){
				na=na.concat(xmldoc.childNodes[i].tagName);
			}
		}

		na=(d)?na:na.unique();

		return na
	};



};


function restoreFormValue(form,xml,tag){
	var na=getNodeContent(xml,tag);
	for (var i=0;i<na.length;i++){
		//eval('fv=form.'+na[i][0]);

		//alert(na[i][0]+':'+typeof fv);
			//document.form1['memo'].value+=na[i][0];
			//document.form1['memo'].value+='='+fv.name+'\n';
		if (typeof form[na[i][0]]=='object'){

			fv=form[na[i][0]];

			if (typeof fv.type=='undefined' || fv.type=='undefined' || fv.type==null){
				a='radio-checkbox';
			}else{
				ft=fv.type.toLowerCase();
				a=ft;
			}

			switch(a){
				case 'select-one':
					//alert(fv.name+':'+fv.length+','+na[i][1]);
					for (var k=0;k<fv.length;k++){
						if (fv.options[k].text==na[i][1]){
							fv.selectedIndex=k;
							break;
						}
					}
					//增加值的比對, 計價方式的值和文字不同 6/14 08'
					for (var k=0;k<fv.length;k++){
						if (fv.options[k].value==na[i][1]){
							fv.selectedIndex=k;
							break;
						}
					}
					break;
				case 'checkbox':
					if (na[i][1]){a.checked=true;}
					break;
				//增加 radio 比對 6/14 08'
				case 'radio-checkbox':
					for (var k=0;k<fv.length;k++){
						if (fv[k].value==na[i][1]){
							fv[k].checked=true;
							break;
						}
					}
				default:
					fv.value=unescape(na[i][1]);
					break;
			}
		}
	}
}

function getNodeContent(xmldoc,key,label) {
	var na=[],va=[],l;
	var outstr='';

	key=(typeof key=='undefined')?this.getNodeName(xmldoc,false):key;

	for (var i=0;i<xmldoc.getElementsByTagName(key).length;i++){
		var xml=xmldoc.getElementsByTagName(key)[i];
		na=this.getNodeName(xml,false);	//必需是唯一值,因為接下來的動作,會依序讀出

		for (var j=0;j<na.length;j++){
			var xmlk=xml.getElementsByTagName(na[j]);
			for (var k=0;k<xmlk.length;k++){
				l=Math.max(va.length,va.length-1);
				if(typeof label!='undefined'){
					if(typeof xmlk[k].getAttribute(label)!=null && typeof xmlk[k].getAttribute(label)!=''){
						va[l]=[xmlk[k].getAttribute(label),xmlk[k].childNodes[0].nodeValue];
					}else{
						va[l]=[na[j],xmlk[k].childNodes[0].nodeValue];
					}
				}else{
					va[l]=[na[j],xmlk[k].childNodes[0].nodeValue];
				}
				outstr+=va[l]+'\n';
			}
		}
	}

	//alert(outstr);
	//xmlToTable(va);

	return va
}


function getNodeName(xmldoc,duplicate){
	var d;
	var na=[];

	d=(typeof duplicate=='undefined')?true:duplicate;

	for (var i=0;i<xmldoc.childNodes.length;i++){
		if (xmldoc.childNodes[i].hasChildNodes()){
			na=na.concat(xmldoc.childNodes[i].tagName);
		}
	}

	na=(d)?na:na.unique();

	return na
}
//********************************************************************************
//Document
//
if (document.getElementsByClassName=='undefined'){
	Document.prototype.getElementsByClassName = function(){
	var tTagName ="*";
	if(arguments.length > 1){
		tTagName = arguments[1];
	}
	if(arguments.length > 2){
		var pObj = arguments[2]
	}
	else{
		var pObj = document;
	}
	var objArr = pObj.getElementsByTagName(tTagName);
	var tRObj = new Array();
	for(var i=0; i<objArr.length; i++){
		if(objArr[i].className == arguments[0]){
			tRObj.push(objArr[i]);
		}
	}
	return tRObj;
	}
}

//********************************************************************************
//Date
//

Date.prototype.dateAdd=function(interval,number){
	//AS VB DateAdd
	number = parseInt(number);
	var date = this;

	switch(interval){
		case "y": date.setFullYear(date.getFullYear()+number); break;
		case "m": date.setMonth(date.getMonth()+number); break;
		case "d": date.setDate(date.getDate()+number); break;
		case "w": date.setDate(date.getDate()+7*number); break;
		case "h": date.setHours(date.getHour()+number); break;
		case "n": date.setMinutes(date.getMinutes()+number); break;
		case "s": date.setSeconds(date.getSeconds()+number); break;
		case "l": date.setMilliseconds(date.getMilliseconds()+number); break;
	}
	return date.toString();
};
//********************************************************************************
//Modal Dialog
//

showModalWindow=function(filename,winTitle,width,height){
	if (!$('_mask')){
		var mask=document.createElement('div');
		mask.id='_mask';
		mask.display('show');
		document.getElementsByTagName('body')[0].appendChild(mask);
	}else{
		$('_mask').display('show');
	}

	if (!$('_activeWin')){
		var activeWin=document.createElement('div');
		activeWin.id='_activeWin';

		var awTitle=document.createElement('div');
		awTitle.className='awTitle';
		awTitle.innerHTML='<img style="position:relative;width:15px;height:15px;float:right;cursor:default;" onclick="clearMask();document.getElementsByTagName(\'body\')[0].removeChild($(\'_activeWin\'));" img src="/images/x.png" alt="Close" title="Close Window" width="15" height="15" border="0" />'+winTitle+'&nbsp;';
		activeWin.appendChild(awTitle);

		var awContent=document.createElement('div');
		awContent.className='awContent';
		activeWin.appendChild(awContent);

		var w=(typeof width!='number')?bWidth*0.5:width;
		var h=(typeof height!='number')?bHeight*0.7:height;

		document.getElementsByTagName('body')[0].appendChild(activeWin);
		activeWin.className='modal';
		activeWin.width(w).height(h).center().middle();
		awContent.height(activeWin.height()-awTitle.Height()-awContent.getHeightMargin());

		//*******************************************************

		new Ajax({
			url:filename,
			method:'get',
			success:function(xmlhttp){
				var fileext=filename.split('.')[filename.split('.').length-1];
				switch (fileext){
					case 'json':
						awContent.innerHTML=eval(xmlhttp.responseText).html;
						eval(eval(xmlhttp.responseText).js);
						break;
					case 'js':
						eval(xmlhttp.responseText);
						break;
					default:
						awContent.innerHTML=xmlhttp.responseText;
						break;
				}
				return true;

			},
			failure:function(xmlhttp){
				return false;
			}

		});
	}
}

//********************************************************************************
//Alert
//

function Alert_keydown(e){
	e=(!e)?window.event:e;
}

function Alert_mousedown(e){
	e=(!e)?window.event:e;
}

Alert=function(msg,winTitle,width,height){
	if (!$('_mask')){
		var mask=document.createElement('div');
		mask.id='_mask';
		mask.display('show');
		document.getElementsByTagName('body')[0].appendChild(mask);
	}else{
		$('_mask').display('show');
	}

	if ($('_activeMsgBox')){
		document.getElementsByTagName('body')[0].removeChild($('_activeMsgBox'))
	}

	var activeWin=document.createElement('div');
	activeWin.id='_activeWin';
	document.getElementsByTagName('body')[0].appendChild(activeWin);

	var awTitle=document.createElement('div');
	awTitle.className='awTitle';
	if (typeof winTitle=='undefined' || winTitle==''){
		//awTitle.display('none');
		winTitle='Alert'
	}
	awTitle.innerHTML='<img style="position:relative;width:15px;height:15px;float:right;cursor:default;" onclick="clearMask();document.getElementsByTagName(\'body\')[0].removeChild($(\'_activeWin\'));" img src="/images/x.png" alt="Close" title="Close Window" width="15" height="15" border="0" />'+winTitle+'&nbsp;';

	activeWin.appendChild(awTitle);

	var awContent=document.createElement('div');
	awContent.className='awContent';
	activeWin.appendChild(awContent);

	var w=(typeof width=='undefined')?bWidth*0.3:width;
	var h=(typeof height=='undefined')?bHeight*0.3:height;

	w=(typeof w!='number')?w:Math.min(w,bWidth-20);
	h=(typeof h!='number')?h:Math.min(h,bHeight-20);

	activeWin.className='modal';
	activeWin.width(w).height(h).center().middle();
	awContent.height(activeWin.height()-awTitle.Height()-awContent.getHeightMargin());
	awContent.innerHTML=msg;

	//改色
	//activeWin.style.border='#000 6px solid';
	//awTitle.style.color='#FFF';
	//awTitle.style.backgroundColor='#000';


	//awContent.innerHTML+='<div><button>OK</button></div>';
};


//********************************************************************************
//msgBox
//

msgBox=function(msg,autohide,position){
	if ($('_activeMsgBox')){
		document.getElementsByTagName('body')[0].removeChild($('_activeMsgBox'))
	}

	var activeWin=document.createElement('div');
	activeWin.id='_activeMsgBox';
	document.getElementsByTagName('body')[0].appendChild(activeWin);

	var awContent=document.createElement('div');
	//awContent.className='awContent';
	awContent.innerHTML=msg;

	activeWin.className='modal';
	activeWin.style.opacity=0;
	activeWin.style.border=0;
	activeWin.style.color='#FFF';
	activeWin.style.backgroundColor='#000';
	activeWin.style.padding='6px';
	activeWin.style.zIndex='20000';
	addNewStyle('#_activeMsgBox a {color:#FFF;text-decoration:underline;}');
	//
	activeWin.style.background='linear-gradient(top,#4B4B4B,#000)';
	activeWin.style.background='-webkit-linear-gradient(top,#4B4B4B,#000)';
	activeWin.style.background='-moz-linear-gradient(top,#4B4B4B,#000)';
	activeWin.style.background='-ms-linear-gradient(top,#4B4B4B,#000)';
	activeWin.style.background='-o-linear-gradient(top,#4B4B4B,#000)';

	activeWin.appendChild(awContent);
	if (typeof position=='object'){
		activeWin.width(bWidth*0.3).moveto(position.y,position.x);
	}else{
		activeWin.width(bWidth*0.3).center().moveToBottom(12);
	}

	 autohide=(typeof autohide=='undefined')?true:autohide;


	setTimeout("$('_activeMsgBox').fadein()",1);

	if (autohide){
		setTimeout("$('_activeMsgBox').fadeout()",4000);
		setTimeout("document.getElementsByTagName('body')[0].removeChild($('_activeMsgBox'))",5000);
	}else{
		awContent.onclick=function(){document.getElementsByTagName('body')[0].removeChild($('_activeMsgBox'));};
	}
};

//********************************************************************************
//popup window
//
closePop=function(){
	if (!$('_mask')){
		//window.parent.$('_mask').display('hide');
		window.parent.clearMask();
		window.parent.document.getElementsByTagName('body')[0].removeChild($('_activeWin'));
	}else{
		//$('_mask').display('hide');
		clearMask();
		document.getElementsByTagName('body')[0].removeChild($('_activeWin'));
	}
}

popup=function(url,winName,width,height){
	if (!$('_mask')){
		var mask=document.createElement('div');
		mask.id='_mask';
		mask.display('show');
		document.getElementsByTagName('body')[0].appendChild(mask);
	}else{
		$('_mask').display('show');
	}

	if ($('_activeWin')){
		document.getElementsByTagName('body')[0].removeChild($('_activeWin'))
	}

	var activeWin=document.createElement('div');
	activeWin.id='_activeWin';

	var awTitle=document.createElement('div');
	awTitle.className='awTitle';
	var winTitle='';
	awTitle.innerHTML='<img style="position:relative;width:15px;height:15px;float:right;cursor:default;" onclick="clearMask();document.getElementsByTagName(\'body\')[0].removeChild($(\'_activeWin\'));" img src="/images/x.png" alt="Close" title="Close Window" width="15" height="15" border="0" />'+winTitle+'&nbsp;';

	activeWin.appendChild(awTitle);

	var awContent=document.createElement('div');
	awContent.className='awContent';
	activeWin.appendChild(awContent);

	var w=(typeof width=='undefined')?bWidth*0.3:width;
	var h=(typeof height=='undefined')?bHeight*0.3:height;

	w=(typeof w!='number')?w:Math.min(w,bWidth-20);
	h=(typeof h!='number')?h:Math.min(h,bHeight-20);

	document.getElementsByTagName('body')[0].appendChild(activeWin);
	activeWin.className='modal';
	activeWin.style.opacity=0;
	activeWin.width(w).height(h).center().middle().fixed();
	awContent.height(activeWin.height()-awTitle.Height()-awContent.getHeightMargin());
	awContent.innerHTML='<iframe name="'+winName+'" src="'+url+'" width="100%" height="100%" frameborder="0"border="0"></iframe>';
	activeWin.fadein();
	//awContent.innerHTML+='<div><button>OK</button></div>';
};



//********************************************************************************
//console
//
window.console=(function(){
	if ($('__consoleWin__')){
		document.getElementsByTagName('body')[0].removeChild($('__consoleWin__'))
	}

	var activeWin=document.createElement('div');
	activeWin.id='__consoleWin__';

	var awTitle=document.createElement('div');
	awTitle.innerHTML='\
		<div style="text-align:right;">\
		<button style="font-size:80%;padding:1px;" onclick="this.blur();$(\'__consoleBody__\').innerHTML=\'\';">Clear</button>\
		<button style="font-size:80%;padding:1px;" onclick="this.blur();clearMask();document.getElementsByTagName(\'body\')[0].removeChild($(\'__consoleWin__\'));">X</button>\
		</div>\
		';
	activeWin.appendChild(awTitle);

	var awContent=document.createElement('div');
	awContent.id='__consoleBody__';
	awContent.style.overflowY='auto';
	awContent.style.padding='0px';
	awContent.height(bHeight*0.2);

	activeWin.style.border=0;
	activeWin.style.color='#FFF';
	activeWin.style.backgroundColor='#000';
	activeWin.style.padding='0px';
	activeWin.style.position='absolute';

	activeWin.appendChild(awContent);

	//-trace
	function trace(msg){
		var body=document.getElementsByTagName('body')[0];
		body.appendChild(activeWin);
		activeWin.style.padding=(body.style.padding)?body.style.padding:activeWin.style.padding;
		activeWin.style.margin=body.style.margin;
		activeWin.width('100%').left(0).fixedBottom();
		awContent.innerHTML+='<div>'+msg+'</div>';
	};

	//-info
	function info(){
	}

	//-agent
	var agent=navigator.userAgent.toLowerCase();

	return ({
		trace	:trace,
		info	:info,
		agent	:agent
	});
})();

window.cconsole={
	trace:function(msg){
		alert(msg);
	}
}
//********************************************************************************
//
//
function clearMask(){
	if ($('_mask')){
		document.getElementsByTagName('body')[0].removeChild($('_mask'));
	}
}

function createMask(){
	//For WEB ERP only
	if (!$('_mask')){
		var mask=document.createElement('div');
		mask.id='_mask';

		mask.style.width='100%';
		mask.style.height='100%';
		mask.style.backgroundColor='#FFF';
		mask.style.opacity='0.7';
		mask.style.display='inline';
		mask.style.left='0px';
		mask.style.top='0px';
		mask.style.position='fixed';
		mask.style.filter='alpha(opacity=70)';
		mask.ondblclick=function(){clearMask();};

		//mask.innerHTML='<div style="width:50%;height:50%;margin:20% auto;text-align:center;"><img src="/images/gfx/ajax-loader.gif" alt="loading" title="loading" /></div>';
		//mask.innerHTML='<div id="op">...Loading...</div>';

		var op=document.createElement('div');
		op.id='op';
		op.style.fontFamily='Verdana';
		op.innerHTML='...Loading...';
		op.style.color='#333';
		op.style.fontSize='11px';
		op.style.fontWeight='bold';
		op.style.position='absolute';
		op.style.textAlign='center';
		op.style.width='200px';
		op.style.border='#000 0px solid';

		mask.appendChild(op);
		document.getElementsByTagName('body')[0].appendChild(mask);

		circleLoading(12,bHeight/2,bWidth/2,parseInt(Math.min(bWidth,bHeight)/8));
		$('op').center().middle();

	}else{
		$('_mask').display('show');
	}
}

Circle=function(id,y,x,opacity){
	this.obj=document.getElementById(id);
	this.id=id;
	this.x=x;
	this.y=y;
	this.opacity=opacity;
	this.counter=0;
	this.spot=12;

	var o=this;

	clearInterval(this.intervalOBJ);
	this.animate=function(I,circle,pos){
		o.spot=circle;
		setInterval(function(){
			//o.obj.style.top=pos[(I+o.counter)%o.spot][0]+'px';
			//o.obj.style.left=pos[(I+o.counter)%o.spot][1]+'px';
			o.obj.style.opacity=((I+o.counter)%o.spot)/o.spot;

			o.counter++;
		},1000/this.spot);
	}
}

circleLoading=function(n,centerY,centerX,radius){

	this.pageCenter={y:centerY,x:centerX};
	this.radius=radius;
	this.circle=n;
	this.pos=[];
	this.preheadChar='A'+Math.round(Math.random()*10000)+'_';

	for (var i=0;i<this.circle;i++){
		var y,x,opacity,imgw=16,imgh=16;;
		y=this.pageCenter.y+radius*Math.sin(2*i*Math.PI/this.circle)-imgh/2;
		x=this.pageCenter.x+radius*Math.cos(2*i*Math.PI/this.circle)-imgw/2;
		opacity=(i+1)/this.circle;
		this.pos.push([y,x]);

		var div=document.createElement('div');
		div.id=this.preheadChar+i;
		//div.className='circle';
		div.style.width='16px';
		div.style.height='16px';
		div.style.backgroundColor='#333';
		div.style.borderRadius='8px';
		div.style.MozBorderRadius='8px';
		div.style.WebkitBorderRadius='8px';

		div.innerHTML='<!--//-->';
		div.style.position='absolute';
		div.style.top=y+'px';
		div.style.left=x+'px';
		div.style.opacity=opacity;

		document.getElementById('_mask').appendChild(div);
	}
	for (var i=0;i<this.circle;i++){
		new Circle(this.preheadChar+i,this.pos[i][0],this.pos[i][1],1/(i+1)).animate(i,this.circle,this.pos);
	}
}

function getScrollerWidth() {
	var scr = null;
	var inn = null;
	var wNoScroll = 0;
	var wScroll = 0;

	// Outer scrolling div
	scr = document.createElement('div');
	scr.style.position = 'absolute';
	scr.style.top = '-1000px';
	scr.style.left = '-1000px';
	scr.style.width = '100px';
	scr.style.height = '50px';
	scr.padding='0px';
	scr.margin='0px';
	// Start with no scrollbar
	scr.style.overflow = 'hidden';

	// Inner content div
	inn = document.createElement('div');
	inn.style.width = '100%';
	inn.style.height = '200px';
	inn.padding='0px';
	inn.margin='0px';

	// Put the inner div in the scrolling div
	scr.appendChild(inn);
	// Append the scrolling div to the doc
	document.getElementsByTagName('html')[0].appendChild(scr);

	// Width of the inner div sans scrollbar
	wNoScroll = inn.offsetWidth;
	// Add the scrollbar
	scr.style.overflow = 'auto';
	// Width of the inner div width scrollbar
	wScroll = inn.offsetWidth;

	// Remove the scrolling div from the doc
	document.getElementsByTagName('html')[0].removeChild(document.getElementsByTagName('html')[0].lastChild);

	// Pixel width of the scroller
	return (wNoScroll - wScroll);
}



function autoExpand(textarea){
	//create div
	if (!$('div_'+textarea.name)){
		var cDiv=document.createElement('div');
		cDiv.id='div_'+textarea.name;
		cDiv.style.width=$(textarea).Width()+'px';
		cDiv.style.border='#000 1px solid';
		cDiv.style.position='absolute';
		cDiv.style.top='-3000px';
		cDiv.style.left='-3000px';
		document.getElementsByTagName('body')[0].appendChild(cDiv);

		var iText=document.createElement('input');
		iText.type='text';
		iText.id='text_'+textarea.name;
		iText.style.position='absolute';
		iText.style.top='-3000px';
		iText.style.left='-3000px';
		document.getElementsByTagName('body')[0].appendChild(iText);
	}

	//
	var div=$('div_'+textarea.name);
	var obj=$(textarea);
	$('text_'+textarea.name).style.lineHeight='1.3em';
	var minHeight=$('text_'+textarea.name).Height();

	obj.style.overflow='hidden';
	div.style.fontSize='80%';
	div.innerHTML=obj.value.replace(/\n/g,'<br/>');
	if (div.Height()>minHeight){
		obj.height(div.Height()+minHeight);
		//scrollBy(0,obj.scrollHeight);
	}else{
		obj.height(minHeight);
	}
}

function addNewStyle(newStyle) {
	var styleElm = document.getElementById('__styles_js__');
	if (!styleElm) {
		styleElm=document.createElement('style');
		styleElm.type='text/css';
		styleElm.id='__styles_js__';
		document.getElementsByTagName('head')[0].appendChild(styleElm);
	}
	styleElm.appendChild(document.createTextNode(newStyle));
}

/**************************************************************************************
Rich Editor
**************************************************************************************/
//var editor=createEditor(this.iframeID);
editorA=function(aID){

	var editor;
	addNewStyle('#HTMLEditor img {border:#DDD 1px solid;}');
	addNewStyle('#HTMLEditor img:hover {box-shadow:0px 0px 3px #666;-moz-box-shadow:0px 0px 3px #666;-webkit-box-shadow:0px 0px 3px #666;}');
	addNewStyle('#HTMLEditor .seperator {margin:0 6px;border-left:#999 1px solid;border-right:#FFF 1px solid;}');

	addNewStyle('#HTMLEditor_color_picker {position:absolute;width:219px;height:167px;padding:3px;border:#666 1px solid;background-color:#FFF;visibility:hidden;box-shadow:3px 3px 3px #666;-moz-box-shadow:3px 3px 3px #666;-webkit-box-shadow:3px 3px 3px #666;}');
	addNewStyle('#HTMLEditor_color_picker .head {margin-bottom:2px;}');
	addNewStyle('#HTMLEditor_color_picker .colorBlock {width:72px;float:left;border-left:#333 1px solid;border-top:#333 1px solid;}');
	addNewStyle('#HTMLEditor_color_picker .color {width:11px;height:11px;float:left;border-right:#333 1px solid;border-bottom:#333 1px solid;}');

	this.id=aID;
	this.width='100%';
	this.height='300px';
	this.border='#666 1px solid';
	this.margin='0';
	this.padding='2px';
	this.imagepath='/editorA/images/';
	this.active=true;
	this.iframeID='_editorA_'+new Date().getTime();

	var o=this;

	this.init=function(){
		var obj=document.getElementById(this.id);
		this.innerHTML=obj.innerHTML;

		obj.style.padding='0';
		obj.style.margin='0';
		obj.style.borderWidth='0px';
		obj.style.width='100%';
		obj.style.height='100%';
		obj.style.visibility='visible';

		var div=document.createElement('div');
		div.id='HTMLEditor';
		div.style.padding='2px';
		div.style.margin='2px 2px 0px 2px';
		div.style.borderColor='#666';
		div.style.borderWidth='1px';
		div.style.borderStyle='solid';
		div.style.borderBottomWidth='0px';
		div.style.backgroundColor='#EEE';
		if (this.width!='100%'){
			div.style.width=this.width;
		}

		//heading
		var tag_select=document.createElement('select');
		tag_select.onchange=function(){editor.execCommand('FormatBlock',false,this.value);_clearSelection(editor);};

		for (var i=0;i<i18N.heading.length;i++){
			var op=document.createElement('option');
			op.appendChild(document.createTextNode(i18N.heading[i].text));
			op.value=i18N.heading[i].value;
			tag_select.appendChild(op);
		}
		div.appendChild(tag_select);

		//font
		var tag_select=document.createElement('select');
		tag_select.onchange=function(){editor.execCommand('FontSize',false,this.value);_clearSelection(editor);};

		for (var i=0;i<i18N.font.length;i++){
			var op=document.createElement('option');
			op.appendChild(document.createTextNode(i18N.font[i].text));
			op.value=i18N.font[i].value;
			tag_select.appendChild(op);
		}
		div.appendChild(tag_select);

		//bold
		var img=document.createElement('img');
		img.src=this.imagepath+'ed_format_bold.png';
		img.width='18';img.height='18';img.alt='Bold';img.title='Bold';img.align='absmiddle';
		img.onclick=function(){editor.execCommand('Bold',false,null);_clearSelection(editor);};
		div.appendChild(img);

		//italic
		var img=document.createElement('img');
		img.src=this.imagepath+'ed_format_italic.png';
		img.width='18';img.height='18';img.alt='Italic';img.title='Italic';img.align='absmiddle';
		img.onclick=function(){editor.execCommand('Italic',false,null);_clearSelection(editor);};
		div.appendChild(img);

		//underline
		var img=document.createElement('img');
		img.src=this.imagepath+'ed_format_underline.png';
		img.width='18';img.height='18';img.alt='Underline';img.title='Underline';img.align='absmiddle';
		img.onclick=function(){editor.execCommand('Underline',false,null);_clearSelection(editor);};
		div.appendChild(img);

		//seperator
		var span=document.createElement('span');
		span.className='seperator';
		div.appendChild(span);

		//fg color
		var img=document.createElement('img');
		img.src=this.imagepath+'ed_color_fg.png';
		img.width='18';img.height='18';img.alt='ForeColor';img.title='ForeColor';img.align='absmiddle';
		img.onclick=function(){_display_palette(document.getElementById('HTMLEditor_color_picker'),this,editor);};
		div.appendChild(img);

		//seperator
		var span=document.createElement('span');
		span.className='seperator';
		div.appendChild(span);


		//order list
		var img=document.createElement('img');
		img.src=this.imagepath+'ed_list_num.png';
		img.width='18';img.height='18';img.alt='Order List';img.title='Order List';img.align='absmiddle';
		img.onclick=function(){editor.execCommand('InsertOrderedList',false,null);_clearSelection(editor);};
		div.appendChild(img);

		//unorder list
		var img=document.createElement('img');
		img.src=this.imagepath+'ed_list_bullet.png';
		img.width='18';img.height='18';img.alt='Bullet List';img.title='Bullet List';img.align='absmiddle';
		img.onclick=function(){editor.execCommand('InsertUnorderedList',false,null);_clearSelection(editor);};
		div.appendChild(img);

		//seperator
		var span=document.createElement('span');
		span.className='seperator';
		div.appendChild(span);

		//source
		var img=document.createElement('img');
		img.src=this.imagepath+'ed_html.png';
		img.width='18';img.height='18';img.alt='HTML Source';img.title='HTML Source';img.align='absmiddle';
		img.onclick=function(){if (editor.designMode=='on'){editor.designMode='off';document.getElementById(aID).value=editor.body.innerHTML;document.getElementById(aID).show();document.getElementById(this.iframeID).style.visibility='hidden';}else{editor.designMode='on';editor.body.innerHTML=document.getElementById(aID).value;document.getElementById(aID).style.visibility='hidden';document.getElementById(this.iframeID).style.visibility='visible';}};
		div.appendChild(img);


		var div1=document.createElement('div');
		div1.style.height=this.height;
		div1.style.padding='2px';
		div1.style.margin='0px 2px 2px 2px';
		div1.style.borderColor='#666';
		div1.style.borderWidth='1px';
		div1.style.borderStyle='solid';
		if (this.width!='100%'){
			div1.style.width=this.width;
		}

		var div2=document.createElement('div');
		div2.id='HTMLEditor_color_picker';

		var tag_iframe=document.createElement('iframe');
		tag_iframe.id=this.iframeID;
		tag_iframe.name=this.iframeID;
		tag_iframe.border='0';
		tag_iframe.frameBorder='0';
		tag_iframe.marginWidth='0';
		tag_iframe.marginHeight='0';
		tag_iframe.style.margin='0';
		tag_iframe.style.padding='0';
		tag_iframe.style.width='100%';
		tag_iframe.style.height='100%';
		tag_iframe.style.position='relative';
		tag_iframe.style.top='-'+this.height;
		tag_iframe.style.visibility='visible';
		tag_iframe.style.backgroundColor='#FFF';

		obj.parentNode.insertBefore(div,obj);
		obj.parentNode.insertBefore(div1,obj);

		div1.appendChild(obj.parentNode.removeChild(obj));
		div1.appendChild(tag_iframe);
		div1.appendChild(div2);
		/**********************************
		<div>
		</div>
		<div1>
			obj
				<textarea id="doc" name="doc" style="margin:0px;border:#000 0px none;width:50%;height:100%;visibility:hidden;"><%=thisTrans_doc%></textarea>
			iframe
				<iframe id="
			div2
		</div1>
		**********************************/

		this.editor=this.createEditor(this.iframeID);

		//Notice here
		this.body=this.editor.body;
		this.designMode=this.editor.designMode;
		//obj.innerHTML=o.innerHTML;


	}

	this.createEditor=function(reID){

		//return window.frames[reID].document;
		//
		//由 Mozilla 來的資料 https://developer.mozilla.org/en/Rich-Text_Editing_in_Mozilla#Executing_Commands
		//if contentDocument exists, W3C compliant (Mozilla)
		if (document.getElementById(reID).contentDocument){
			editor=document.getElementById(reID).contentDocument;
			editor.open();
			editor.write('');
			editor.close();
			editor.designMode='on';
			editor.addEventListener("keyup", this.setTextarea, false);
			editor.addEventListener("blur", this.setTextarea, false);
		}else{
			// IE
			editor=document.frames[reID].document;
			editor.open();
			editor.write('');
			editor.close();
			editor.designMode='on';
			editor.body.attachEvent("onkeyup", this.setTextarea);
			editor.body.attachEvent("onblur", this.setTextarea);
		}

		//textarea init value
		editor.body.innerHTML=document.getElementById(this.id).value;

		return editor;
	};

	this.callBack=function(e){
	}

	this.setTextarea=function(){
		if (editor.designMode=='on'){
			document.getElementById(o.id).value=editor.body.innerHTML;
		}
		if (editor.designMode=='off'){
			editor.body.innerHTML=document.getElementById(o.id).value;
		}
		o.callBack();
	};

	this.setContent=function(c){
		editor.body.innerHTML=c;
		document.getElementById(o.id).value=c;
	};

	this.setHTML=function(){
		document.getElementById(o.id).value=editor.body.innerHTML;
	};

}

function _clearSelection(editor){
	editor.getSelection().removeAllRanges();
}

function _display_palette(obj,btn,editor){

	if(obj.hasChildNodes()){
		obj.removeChild(obj.firstChild);
	}

	var div=document.createElement('div');

	var _ca=['000000','333333','666666','999999','CCCCCC','FFFFFF','FF0000','00FF00','0000FF','FFFF00','00FFFF','FF00FF'];
	var block=document.createElement('div');
	block.className='head';
	for (var i=0;i<_ca.length;i++){
		var color=document.createElement('div');
		color.className='color';
		color.style.backgroundColor='#'+_ca[i];
		color.title='#'+_ca[i];
		color.onclick=function(){editor.execCommand('ForeColor',false,this.style.backgroundColor);_clearSelection(editor);this.parentNode.parentNode.parentNode.hide();this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);};
		block.appendChild(color);
	}

	var color=document.createElement('div');
	color.innerHTML='<img src="'+this.imagepath+'ed_none_color.png" width="17" height="17" />';
	color.className='color';
	color.style.width='72px';
	color.style.height='19px';
	color.style.textAlign='right';
	color.style.borderWidth='0px';
	color.onclick=function(){editor.execCommand('ForeColor',false,this.style.backgroundColor);_clearSelection(editor);this.parentNode.parentNode.parentNode.hide();this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);};
	block.appendChild(color);

	div.appendChild(block);



	var ca=['00','33','66','99','CC','FF'];

	for (var i=0;i<ca.length;i++){
		var block=document.createElement('div');
		block.className='colorBlock';
		for (var j=0;j<ca.length;j++){
			for (var k=0;k<ca.length;k++){
				var color=document.createElement('div');
				color.className='color';
				color.style.backgroundColor='#'+ca[i]+ca[k]+ca[j];
				color.title='#'+ca[i]+ca[k]+ca[j];
				color.onclick=function(){editor.execCommand('ForeColor',false,this.style.backgroundColor);this.parentNode.parentNode.parentNode.hide();this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);};
				block.appendChild(color);
			}
		}
		div.appendChild(block);
	}

	obj.appendChild(div);
	obj.move(btn.getOffsetTop()+btn.Height(),btn.getOffsetLeft());
	obj.show();
}
/**************************************************************************************
tableForm 語法:(tableForm.js)

new tableForm(表格ID,插入的儲存格內容樣板陣列,表格樣式,是否可以新增列).init(表頭內容陣列)

表格ID:<table> 標籤以 id 定義
插入的儲存格內容樣板陣列:多維陣列, 元素為 object , 詳見下列說明
表頭內容陣列:一維陣列, 元素為 object , 詳見下列說明

expample:

	new tableForm('tbl1',
		[
		[{td cell 1},{td cell 2},.... ],  <-- row1
		[{td cell 1},{td cell 2},.... ],  <-- row2
		[{td cell 1},{td cell 2},.... ]   <-- row3
		]).init(
			[{td head 1},{td cell 2},....etc]
		);

	陣列中的元素為 object, 格式為:

		{
		'cellstyle':'儲存格樣式,像是 width, height, background 等等...',
		'cellhtml':'儲存格文內容,像是 <h1>title</h1>,主要可以寫成表單內容'
		}

	實例:
		new tableForm('tbl',[
			[
			{'cellstyle':'background-color:#000','cellhtml':'<input type="text" id="vote[#]" name="vote[#]" style="width:100%;">'}
			如果再加一項,操作插入時,就會一次插入兩列,分別顯示內容
			]
		]).init([
			{
			'cellstyle':'background-color:#FFC;',
			'cellhtml':'投票內容候選項目'
			}
		]);
*************************************************************************************************/
tableForm=function(tableID,cells,classStyle,insert){
	this.id=tableID;
	this.cells=cells;
	this.lineNumber=0;		//顯示行號
	this.rows=this.cells.length;	//每次插入的列數
	//this.funcButton=1;		//0=功能表同列,1=功能表新列

	this.rowPointer=[];		//列號儲存陣列
	this.rowIndex=0;
	this.activeRow=0;		//active row bumber
	this.table=document.getElementById(this.id);

	if (typeof insert=='undefined'){this.insert=true}else{this.insert=insert};

	//調整樣式
	this.table.className+=classStyle;


	//***************************************************************************
	var o=this;

	this.init=function(headArray){
		//rowPointer
		var input=document.createElement('input');
		input.type='hidden';
		input.name=o.id+'.tf_rowPointer';
		input.id=o.id+'.tf_rowPointer';
		input.value='1';
		o.table.parentNode.appendChild(input);

		//insert table head
		var headtr=o.table.insertRow(0);
		headtr.className='tbltitle';
		if (o.lineNumber==1){
			headtr.insertCell(0).innerHTML='#';
		}

		for (var i=0;i<headArray.length;i++){
			var cell=headtr.insertCell(i+o.lineNumber);
			cell.innerHTML=headArray[i].cellhtml;
			cell.setAttribute('style',headArray[i].cellstyle);
		}

	}

	this.addRow=this.table.addRow=function(n){

		if (o.insert || o.rowPointer.length<1){
			o.rowIndex++;
			if (typeof n=='undefined'){
				//.............................v 這裡減一把功能表永遠釘在最末列
				//var row=(o.table.rows.length-1+(o.rows-1))/o.rows;
				//..........................v 不減一把功能表永遠釘在上方
				var row=(o.table.rows.length+(o.rows-1))/o.rows;
				o.rowPointer.push(o.rowIndex);
			}else{
				//..........................................v 功能表在最末列
				var row=o.rowPointer.myIndexOf(o.activeRow)+1;
				//............................................v 功能表在第二列
				//var row=o.rowPointer.myIndexOf(o.activeRow)+2;
				var indexShift=0;
				//---------------------------
				//把 Pointer 插入到正確位置
				//var nIndex1=o.rowPointer.myIndexOf(n)+indexShift;
				var nIndex1=o.rowPointer.myIndexOf(o.activeRow)+indexShift;
				var a1=o.rowPointer.slice(0,nIndex1);
				var a2=o.rowPointer.slice(nIndex1);

				a2.unshift(o.rowIndex);
				o.rowPointer=a1.concat(a2);
			}

			for (var k=0;k<o.cells.length;k++){

				var tr=o.table.insertRow(o.rows*row-(o.rows-k-1));

				tr.setAttribute('_elm',o.rowIndex);
				tr.onclick=function(){o.activeRow=this.getAttribute('_elm');};
				o.activeRow=o.rowIndex;

				if (o.lineNumber==1){
					tr.insertCell(0).innerHTML=o.rowIndex;
				}

				for (var i=0;i<o.cells[k].length;i++){
					var cell=tr.insertCell(i+o.lineNumber);
					cell.innerHTML=o.cells[k][i].cellhtml.replace(/\[#\]/ig,o.rowIndex);
					cell.setAttribute('style',o.cells[k][i].cellstyle);
				}
			}

			if ($(o.id+'.tf_rowPointer')){
				$(o.id+'.tf_rowPointer').value=o.rowPointer;
			}
			//delete when complete
			//$('rowIndex').innerHTML=o.rowIndex;
			//$('rowPointer').innerHTML=o.rowPointer;
			//$('activeRow').innerHTML=o.activeRow;
			//$('instance').innerHTML=o.id;

		}

	}

	this.delRow=this.table.delRow=function(){
		if (o.rowPointer.length>1){
			var sIndex=o.rowPointer.myIndexOf(o.activeRow);

			for (var i=0;i<o.rows;i++){
				o.table.deleteRow(o.rows*sIndex+1);
			}

			o.rowPointer.splice(sIndex,1);
			o.activeRow=o.rowPointer[0];			//
		}

		$(o.id+'.tf_rowPointer').value=o.rowPointer;
		//delete when complete
		//$('rowIndex').innerHTML=o.rowIndex;
		//$('rowPointer').innerHTML=o.rowPointer;
		//$('activeRow').innerHTML=o.activeRow;
		//$('instance').innerHTML=o.id;

	}


	document.onkeydown=function(e){
		var key = (!e) ? event.keyCode : e.keyCode;
		var ckey = (!e) ? event.ctrlKey : e.ctrlKey;
		switch(key){
			case 18:	//alt
				break;
			case 27:	//esc
				break;
			case 13:
				break;
			case 37:	//left
				break;
			case 38:	//up
				break;
			case 39:	//right
				break;
			case 40:	//down
				break;
			default:
				if (key>=112 && key <=123){  //112-123:F1-F12
					break;
				}else if (ckey){
					break;
				}else{
					break;
				}
				break;
		}
	}

	this.addRow();
}

//********************************************************************************
// Form Validation
//
function cs(obj){
	re=/[\$&%<>\+\/:\'\"=\?\\]/g;
	if (re.test(obj.value)){
		obj.value=obj.value.replace(/[\$&%<>\+,\/:\'\";=\?\\]/g,'');
	}
}

function checkString(obj){
	cs(obj);
}

function checkNum(obj){
	cn(obj);
}

function cn(obj,rule){
	//'1':只能輸入純數字
	//'1.':只能輸入數字加小數點
	//'1 ':只能輸入數字及 ()-和空格
	switch (rule){
		case '1':
			obj.value=obj.value.replace(/[^\d]/g,'');
			while(isNaN(obj.value)){
				obj.value=obj.value.substring(0,obj.value.length-1);
			}
			break;
		case '1.':
			obj.value=obj.value.replace(/[^\d.]/g,'');
			while(isNaN(obj.value)){
				obj.value=obj.value.substring(0,obj.value.length-1);
			}
			break;
		case '1 ':
			obj.value=obj.value.replace(/[^\d-()\s]/g,'');
			break;
		default:
			var max_value=obj.getAttribute('max');
			var min_value=obj.getAttribute('min');

			obj.value=obj.value.replace(/[^\d\.]/g,'');

			//while(isNaN(obj.value)){
			//	obj.value=obj.value.substring(0,obj.value.length-1);
			//}

			//if (obj.value==''){obj.value='0';}else{obj.value/=1;}
			//obj.value/=1;

			if (max_value!=null && !isNaN(max_value)){
				if (obj.value-max_value>0){
					obj.value=max_value;
				}
			}

			if (min_value!=null && !isNaN(min_value)){
				if (obj.value-min_value<0){
					obj.value=min_value;
				}
			}

			break;
	}

}

function formAdjust(){
	//必需搭配 js-calendar
	var obj=document.getElementsByTagName('input');
	for (var i=0;i<obj.length;i++){
		if ((obj[i].getAttribute('type')!=null && obj[i].getAttribute('type')!='undefined') && obj[i].getAttribute('type').toLowerCase()=='date'){
			Calendar.setup({
				inputField	:obj[i].name,	// 日期欄位的 ID，不是 name 喔
				ifFormat	:'%Y/%m/%d',	// 需要的日期格式
				showsTime	:true,		// 除日期外，要不要顯示幾點幾分
				button		:obj[i].name,	// 用來呼叫日曆功能的...可能是按鈕的 ID，不是 name 喔
				singleClick	:true,		// 啟動日曆功能，是按一下還按兩下
				step		:1		// 上一年及下一年的清單中，年份的間隔
			});
		}
		if ((obj[i].getAttribute('type')!=null && obj[i].getAttribute('type')!='undefined') && obj[i].getAttribute('type').toLowerCase()=='number'){
			obj[i].value=(obj[i].value=='')?'0':obj[i].value;
			obj[i].setAttribute('autocomplete','off');
			//是否有預設值
			obj[i].value=parseFloat(obj[i].value);
			var v_max=parseFloat(obj[i].getAttribute('max'));
			var v_min=parseFloat(obj[i].getAttribute('min'));
			obj[i].value=(obj[i].value-v_max>0)?v_max:obj[i].value;
			obj[i].value=(obj[i].value-v_min<0)?v_min:obj[i].value;
			if (window.addEventListener){
				//正常，加 handler 在原 event 之後，就簡單用下列方法
				obj[i].addEventListener('keyup',function(){cn(this);}, false);
				obj[i].addEventListener('focus',function(){this.select();}, false);

				//如果要把新加入的 handler 放到 event 最前面，簡單用下列方法, 重點是 apply() 的使用，如此，IE 照樣可以用 this
				//var keyupHandler=(obj[i].onkeyup)?obj[i].onkeyup:function(){};
				//var focusHandler=(obj[i].onfocus)?obj[i].onfocus:function(){};
				//obj[i].onkeyup=function(){cn(this);keyupHandler.apply(this.arguments);}
				//obj[i].onfocus=function(){this.select();focusHandler.apply(this.arguments);}
			}else if (window.attachEvent){
				//attachEvent 不能使用參數 this (在 IE 中, 這裡使用 this 代表 window),改用 event.srcElement 替代
				obj[i].attachEvent('onkeyup',function(){cn(event.srcElement);});
				obj[i].attachEvent('onfocus',function(){event.srcElement.select();});

				//var keyupHandler=(obj[i].onkeyup)?obj[i].onkeyup:function(){};
				//var focusHandler=(obj[i].onfocus)?obj[i].onfocus:function(){};
				//obj[i].onkeyup=function(){cn(this);keyupHandler.apply(this.arguments);}
				//obj[i].onfocus=function(){this.select();focusHandler.apply(this.arguments);}
			}
		}
	}
}

function t(){}
//********************************************************************************
//
function openWindow(strURL,winName,winWidth,winHeight){

	var objWindow,blnlongcall=false;
	var winHeightBrowserShell=0;

	//center window
	var screenMarginL=0;
	var screenMarginTop=0;

	winWidth=(winWidth<=1)?screen.width*winWidth:winWidth;
	winHeight=(winHeight<=1)?screen.height*winHeight:winHeight;

	if(winWidth>0 && winHeight>0){
		screenMarginL=(screen.width - winWidth)/2;
		screenMarginTop=(screen.height - winHeight - winHeightBrowserShell)/2;
	}

	if(blnlongcall==true){
		window.open(strURL,winName,'width='+winWidth+',height='+winHeight+',left=' + screenMarginL + ',top=' + screenMarginTop + ',toolbar=no,location=no,directories=no,status=no,menubar=no,titlebar=no,scrollbars=no,resizable=yes,copyhistory=no');
	}else{
		objWindow=window.open(strURL,winName,'scrollbars,resizable,width='+winWidth+',height='+winHeight+',left=' + screenMarginL + ',top=' + screenMarginTop);
	}
}

function clearLinkDot() {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("a")[i]); i++) {
		if(a.getAttribute("onFocus")==null) {
			a.setAttribute("onFocus","this.blur();");
		}else{
			a.setAttribute("onFocus",a.getAttribute("onFocus")+";this.blur();");
		}
		a.setAttribute("hideFocus","hidefocus");

		if (a.getAttribute("href") && a.getAttribute("rel") == "external"){
			a.target = "_blank";
		}
	}



	for(i=0; (a = document.getElementsByTagName("input")[i]); i++) {
		if (a.type=='button' || a.type=='submit' || a.type=='reset'){
			if(a.getAttribute("onFocus")==null) {
				a.setAttribute("onFocus","this.blur();");
			}else{
				a.setAttribute("onFocus",a.getAttribute("onFocus")+";this.blur();");
			}
			a.setAttribute("hideFocus","hidefocus");
		}
	}
}

function wait(x){
	if (typeof x!='undefined')
		alert(x);
	else
		alert('wait');
}

function x_fileExist(file){
	new Ajax({
		url:file+'?ts='+new Date().getTime(),
		method:'get',
		success:function(xmlhttp){
			return true;
		},
		failure:function(xmlhttp){
			return false;
		}
	});
}


function fileExist(filename){
	var xmlhttp;
	if (window.XMLHttpRequest){
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	//var url='/Performance/paData/2011新年期許/zoe.yang/(F表)行政.xml?ts='+new Date().getTime();
	var url=filename+'?ts='+new Date().getTime();
	try{
		xmlhttp.open('HEAD',url,false);
		xmlhttp.send(null);
		return (xmlhttp.status == 200)?true:false;
	}catch(err){
		return false;
	}
}

function activeCSS(css){
	var a, obj=document.getElementsByTagName('link'),cIndex=0;
	for (var i=0;i<obj.length;i++){
		a=obj[i];
		if (a.getAttribute('rel').toLowerCase()=='alternate stylesheet'){
			a.disabled=true;
			if (a.getAttribute('title')=='skinstyle_'+css){
					cIndex=i;

					var cookiesDays=30;
					var expireDate = new Date()
					var expstring=expireDate.setDate(expireDate.getDate()+parseInt(cookiesDays));
					document.cookie = 'skin_Name='+css+'; expires='+expireDate.toGMTString()+'; path=/';
			}
		}
	}
	obj[cIndex].disabled=false;

	return false;
}
//**************************************************************************************
//
//
function OPENACME(aUrl,ahight,awidth){
	var sUrl
	var sFeature = 'dialogHeight:'+ahight+'px;dialogWidth:'+awidth+'px;status:no;toobar=no;location=no;'
	if (aUrl.indexOf('?') != -1){
		sUrl = aUrl +'&pRndNo='+Math.random()
	}
	else{
		sUrl = aUrl +'?pRndNo='+Math.random()
	}
	var ss=window.showModalDialog(sUrl,window,sFeature);
	return ss;
}



function ckForm(form,exclude){
	//exclude is array
	var errField=[];
	exclude=(typeof exclude=='undefined')?[]:exclude;
	for (var i=0;i<form.length;i++){
		var fv=form[i];
		var ft=form[i].type;
		var a=form[i].name;

		if (exclude.indexOf(a)==-1){
			//*******************************************
			//check Type (HTML5)
			//	number:
			//	date:
			//	required:
			switch(ft){
				case 'select-one':	//不可以是第一項
					fv.style.border='';
					if (fv.selectedIndex==0){
						errField.push([i,fv.name]);
					}
					break;
				case 'text':
					fv.style.border='';
					if (fv.value.isEmpty()){
						errField.push([i,fv.name]);
					}
					break;
				case 'radio':
					fv.style.border='';
					var elm_checked=false;
					for (var k=0;k<form[fv.name].length;k++){
						elm_checked=elm_checked || form[fv.name][k].checked;
					}

					if (!elm_checked){
						errField.push([i,fv.name]);
					}
					break;
				default:
					break;
			}
		}
	}


	if (errField.length==0){
		form.submit();
	}else{
		for (var i=0;i<errField.length;i++){
				//form[errField[i]].parentNode.style.border='#F00 1px solid';
				//form[errField[i]].parentNode.style.backgroundColor='#0FF';
				form[errField[i][0]].style.border='#F00 1px solid';
		}
		//alert(errField);
		return false;
		//msgBox('Error!<br/>Please correct the fields with red border');
	}
}

function opWin(url){
	$('floater').center().middle().display('show');
	window.frames['opFrame'].location=url;
}


//**************************************************************************************
//
//
onloadAttach(formAdjust);



//***********************************************************
//PosterMIS only
//
function dF(s){
	var s1=unescape(s.substr(0,s.length-1)); var t='';
	for(i=0;i<s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length-1,1));
		document.write(unescape(t));
}

function centerDiv(layer){
	var w=$(layer).width();
	$(layer).left((bWidth-w)/2);
}

function changeDays(mIndex,daySelect){
	var MonthDay=new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	if (daySelect.length!=MonthDay[mIndex]){
		daySelect.length=MonthDay[mIndex];
		for (var i=1;i<=MonthDay[mIndex];i++){
			daySelect.options[i-1].text=i;
			daySelect.options[i-1].value=i;
		}
	}
}

function noempty(form){
	var obj=form.elements;
	for (var i=0;i<obj.length;i++){
		if (obj[i].getAttribute('required')==''){
			obj[i].value=obj[i].value.replace(/[\s]/g,'');
			if (obj[i].value.length==0){
				obj[i].style.border='#F00 1px solid';
				obj[i].focus();
				obj[i].select();
				break;
			}
		}
	}
}

function showFloat(url,display){
	window.open(url,'INSIDE_CHILD_FRAME');
	$('floater').center().middle().display('show').fixed();
}

function closeFloat(){
	window.open('about:blank','INSIDE_CHILD_FRAME');
	$('floater').display('hide');
}
//*********************************************************
//
//

function Dec2Hex(dec){
    var hexChars = "0123456789ABCDEF";
    var a=dec%16;
    var b=(dec-a)/16;
    var hex=""+hexChars.charAt(b)+hexChars.charAt(a);
    return hex;
}

function Hex2Dec(hex) {
    return parseInt(hex,16);
}

