// JavaScript Document
/*
取得文本对象.
*/
function $(id){return document.getElementById(id);};

var System={};
/*
创建对象Class
*/
var Class={
		create:function(){
			return function(){
				this.init.apply(this,arguments);
			};
	}
};
/*
util
*/
System.util={
	/*
	写入文档.
	*/
	dw : function(str){
		document.write(str);
	},
	/*
	写入javascript
	*/
	dwScript : function(o/*{charset:,url:,innerText:,defer:,}*/){
		if(typeof(o)!='object')throw new Error('loadscript error');
		o.id=o.id?'id="'+o.id+'" ':'';
		o.url=o.url?'scr="'+o.url+'" ':'';
		o.defer=o.defer?'defer="true" ':'';
		o.charset=o.charset?'charset="'+o.charset+'" ':'charset="utf-8" ';
		if(o.url!=''){
			this.dw('<script '+o.id+o.url+o.charset+o.defer+'><\/script>');
		}else if(o.innerText){
			this.dw('<script '+o.id+o.charset+o.defer+'>'+o.innerText+'<\/script>');
		}else{
			throw new Error('no script content or url specified');
		}
	},
	/*
	添加js
	*/
	loadScript : function (url, callback, encode){  
		var script = document.createElement('script');
		script.type = 'text/javascript';
		if (encode) {
			script.charset = encode;
		}
		if (callback) {
			script.onload = script.onreadystatechange = function(){
				if (script.readyState && script.readyState != 'loaded' &&
				script.readyState != 'complete') {
					return;
				}
				script.onreadystatechange = script.onload = null;
				callback();
			};
		}
		script.src = url;
		document.getElementsByTagName('head')[0].appendChild(script);  
	},
	/*
	写入swf.
	*/
	dwSwf : function(wr,url,width,height,sId,sMode,sScript,vars/*{name:,value}*/){
		var sWidth=width?'width="'+width+'"':'';
		var sHeight=height?'height="'+height+'"':'';
		var IEsId=sId?'id="'+sId+'IE" name="'+sId+'IE"':'';
		var NIEsId=sId?'id="'+sId+'NIE" name="'+sId+'NIE"':'';
		var flashArr=[];
	
		var IEpara='';
		var NIEpara='';
		if(sScript){
				IEpara+='<param name="allowScriptAccess" value="always" />'
				NIEpara+=' allowScriptAccess="always" ';
		}
		if(sMode){
				IEpara+='<param name="wmode" value="transparent" />'
				NIEpara+=' wmode="transparent" ';
		}
		if(vars){
			for(var key in vars){
				flashArr.push(key.name+'='+key.value);
			}
			var FlashVars=flashArr.join('&');
		   IEpara='<param name="FlashVars" value="'+FlashVars+'"/>';
		   NIEpara+=' FlashVars="'+FlashVars+'" ';
		}
			var documentHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" '+IEsId+' '+sWidth+'  '+sHeight+' ><param name="movie" value="'+url+'" /><param name="menu" value="false" /><param name="quality" value="high" />'+IEpara+'<embed src="'+url+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" menu="false"  '+NIEsId+' '+NIEpara+' '+sWidth+' '+sHeight+' ></embed></object>';
			if(wr)return documentHTML;
			else this.dw(documentHTML);
	},
	/*
	写入css样式
	*/
	dwCSS : function(o){
		o.id = o.id || "";
		if (o.url){
			this.dw('<link id="' + o.id + '" rel="stylesheet" type="text/css" href="' + o.url + '" />');
		}
		else if (o.styles){
			this.dw('<style id="' + o.id + '" >' + o.styles + '<\/style>');
		}
	},

	/*
	尝试程序.
	*/
	TryThis:function(){
		var returnValue;
			for(var i=0;i<arguments.length;i+=1){
				var objHttp=arguments[i];
				try{
					returnValue=objHttp();
					break;
				}catch(e){
				}
			}
		
		return objHttp;
	},
	/*
	取得cookie 值.
	*/
	getCookie : function (name) {
		var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
		if (arr != null) {
			return unescape(arr[2]);
		}
		return null;
	},
	/*
	创建cookie.
	*/
	setCookie : function (sName,sValue,objHours,sPath,sDomain,bSecure){
		var sCookie = sName + "=" + encodeURIComponent(sValue);
		if (objHours) {
			var date = new Date();
			var ms = objHours * 3600 * 1000;
			date.setTime(date.getTime() + ms);
			sCookie += ";expires=" + date.toGMTString();
		}
		if (sPath) {
			sCookie += ";path=" + sPath;
		}
		if (sDomain) {
			sCookie += ";domain=" + sDomain;
		}
		if (bSecure) {
			sCookie += ";secure";
		}
		document.cookie=sCookie;
	},
	/*
	创建RegExp对象.
	*/
	getRegExp:function(strRegExp){
		return new RegExp(strRegExp);
	},
	getHTMLText:function(str){
		str=str.replace(/\</g,'&lt;');
		str=str.replace(/\>/g,'&gt;');
		str=str.replace(/\n/g,'<br />');
		str=str.replace(/\s/g,'&nbsp;');
		str=str.replace(/\<br&nbsp;\/\>/g,'<br />');
		str=encodeURIComponent(str);
		return str;
	}
};
/*
浏览器.
*/
System.App={
	/*
	浏览器userAgent.
	*/
	ua : navigator.userAgent.toLowerCase(),
	/*
	浏览器是否为MSIE.
	*/
	IE : /msie/.test(navigator.userAgent.toLowerCase()),
	/*
	浏览器是否为gecko.
	*/
	MOZ : /gecko/.test(navigator.userAgent.toLowerCase()),
	/*
	浏览器是否为opera.
	*/
	OPERA : /opera/.test(navigator.userAgent.toLowerCase()),
	/*
	浏览器是否为safari.
	*/
	SAFARI : /safari/.test(navigator.userAgent.toLowerCase())
};
/*
样式
*/
System.style={
	/*
	对象样式设定.
	*/
	setStyle:function(elm,styles,value){
		if(!elm)return;
		if(styles=='float'){
			if(System.App.IE)styles='styleFloat';
			else styles='cssFloat';
		}
		if(styles=='opacity'){
			if(System.App.IE){
				elm.style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity='+(value*100)+')';
			}
		}
		elm.style[styles]=value;
	},
	/*
	对象样式取得.
	*/
	getStyle:function(elm,styles){
		if(!elm)return;
		if(styles=='float'){
			if(System.App.IE)styles='styleFloat';
			else styles='cssFloat';                                      
		}
		if(styles=='opacity'&&System.App.IE){
			var str = elm.style.filter;
			if(str=='')return '';
			str=str.match(/opacity\=\d+/ig);
			if(str.length>0){
				str=str[0].replace(/opacity\=(\d+)/ig,'$1');
				str=parseInt(str);
				return str/100;
			}else return '';
		}
		return elm.style[styles];
	},
	/*
	设定样式集.
	*/
	setStyleList : function(elm,o){
		if(!elm)return;
		if(typeof(o)!='object')return;
		for(var key in o){
			if(o[key].style&&o[key].value)this.setStyle(elm,o[key].style,o[key].value);
		}
	},
	/*
	得到样式集.
	*/
	getStyleList : function(elm,styles){
		var o=styles;
		if(!o)return;
		var returnValue=[];
		for(var key in o){
			returnValue.push('{style:'+o[key]+',value:'+elm.style[o[key]]+'}');
		}
		return returnValue.join(',');
	}
};
/*
event
*/
System.Events={
	/*
	创建event监听.
	*/
	addEvent :	function (elm, handler, evType, useCapture) {
			if (typeof useCapture == 'undefined') {
				useCapture = false;
			}
			if (typeof evType == 'undefined') {
				evType = 'click';
			}
			if (elm.addEventListener) {
				elm.addEventListener(evType, handler, useCapture);
				return true;
			}
			else if (elm.attachEvent) {
				var r = elm.attachEvent('on' + evType, handler);
				return true;
			}
			else {
				elm['on' + evType] = handler;
			}
	},
	/*
	取消event监听.
	*/
	removeEvent : function  (oElement, fHandler, sName) {
			if (typeof fHandler != "function") {
				return;
			}
			if (oElement.addEventListener) {
				oElement.removeEventListener(sName, fHandler, false);
			}
			else if (oElement.attachEvent) {
				oElement.detachEvent("on" + sName, fHandler);
			}
			else fHandler[sName] = null;
	},
	/*
	取得 event 对象.
	*/
	getEvent : function(){
		var ie=System.App.IE;
		if(ie)return window.event;
		var o=arguments.callee.caller;
		var e;
		var n=0;
		while(o!=null&&n<40){
			e=o.arguments[0];
			try{
				if(e&&(e.constructor==Event||e.constructor==MouseEvent))return e;
			}catch(e){}
			n++;
			o=o.caller;
		}
		
		return e;
	},
	/*
	event 返回值.
	*/
	stopEvent : function(){
			var ev=this.getEvent();
			try{
				ev.cancelBubble=true;
				ev.returnValue=false;
			}catch(e){
				try{
					ev.preventDefault();
					ev.stopPropagation();
				}catch(e){}
			}
	}
};
/*
ajax
*/
System.Ajax={
	/*
	创建ajax对象.
	*/
	xmlHttp : function(){
			var xml=System.util.TryThis(function(){return new XMLHttpRequest();},function(){return new ActiveXObject('Microsoft.XMLHTTP');},function(){return new ActiveXObject('MSXML.XMLHTTP');},function(){return new ActiveXObject('Microsoft.XMLHTTP');},function(){return new ActiveXObject('Msxml2.XMLHTTP.7.0');}, function(){return new ActiveXObject('Msxml2.XMLHTTP.6.0');},function(){return new ActiveXObject('Msxml2.XMLHTTP.5.0');},function(){return new ActiveXObject('Msxml2.XMLHTTP.4.0');},function(){return new ActiveXObject('MSXML2.XMLHTTP.3.0');}, function(){return new ActiveXObject('MSXML2.XMLHTTP');})||false;
			return xml();
	}
};
function GM_xmlHttp(obj){
	var xml=System.Ajax.xmlHttp();
	xml.onreadystatechange=function(){
			if(xml.readyState==4){
				if(xml.status==200){
					if(typeof(obj.onload)=='function'){
						obj.onload.apply(this,[xml]);
						
					}
				}
			}
		}
	if(obj.method=='post'){
		xml.open('post',obj.url,true);
		xml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xml.send(obj.send);
	}else{
		xml.open('get',obj.url,true);
		xml.send(obj.send);
	}
}
/*
String
*/
String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g,'');};
String.prototype.contains=function(A){return this.indexOf(A)>-1};
String.prototype.equals=function(A){return this.toLowerCase()==A.toLowerCase();};
String.prototype.startsWith=function(A){return A==this.substr(0,A.length);};
String.prototype.endsWith=function(A){if(A.length>this.length)return false;else return this.substr(this.length-A.length)==A;};
String.prototype.istartsWith=function(A){return A.toLowerCase()==this.toLowerCase().substr(0,A.length);};
String.prototype.iendsWith=function(A){if(A.length>this.length)return false;else return this.substr(this.length-A.length).toLowerCase()==A.toLowerCase();};
/*
Array
*/
Array.prototype.remove=function(from,to){var arr=this;var rest = this.slice((to || from) + 1 || this.length);from=from < 0 ? this.length + from : from;to=arr.length-rest.length-from;arr=arr.slice(from,to+from);this.length =from;this.push.apply(this, rest);return arr;};
Array.prototype.removeByObjectProperty=function(property,value){var arr=[];for(var i=0;i<this.length;i++){if(this[i][property]==value)arr.push(i);}for(var i=0;i<arr.length;i++){arr[i]=this.remove(arr[i]);} return arr;};