﻿String.prototype.trim = function() { //清除两边空格
	return this.replace( /(^\s*)|(\s*$)/g , "");
}
String.prototype.ltrim = function() { //清除左边空格
	return this.replace( /(^\s*)/g, "" );
}
String.prototype.rtrim = function() { //清除右边空格
	 return this.replace( /(\s*$)/g, "" );
}
String.prototype.lsubstr = function( len ) { //截取左边字符
	return this.substr( 0, len );
}
String.prototype.rsubstr = function( len ) { //截取右边字符
	return this.substr( this.length - len, this.length );
}
String.prototype.lwipe = function( len ) { //擦除左边字符
	return this.substr( len, this.length );
}
String.prototype.rwipe = function( len ) { //擦除右边字符
	return this.substr( 0, this.length - len );
}
String.prototype.replaceAll = function( oldString, newString ) { //全部替换
	return this.replace(new RegExp( oldString, "gm" ), newString);
}
String.prototype.isString = true; //检测是否字符串
String.prototype.getById = function() { //根据ID获取控件对象
	return $id( this );
}
String.prototype.getByName = function() { //根据TagName获取控件对象
	return $tag( this );
}
String.prototype.getByTagName = function() { //根据Name获取控件对象
	return $name( this );
}
String.prototype.isBound = function( min, max ) { //根据Name获取控件对象
	return isBound( this.length, min, max );
}
Array.prototype.toString = function( splitString ) { //数组转换字符串
	tmpstr = '';
	for ( var i = 0; i < this.length; i++ ) {
		if ( i + 1 < this.length ) {
			tmpstr += this[i] + splitString;
		} else {
			tmpstr += this[i];
		}
	}
	return tmpstr;
}
Array.prototype.append = function( value ) { //尾部添加值
	this[this.length] = value;
}
Array.prototype.unite = function( ary ) { //与单个数组合并
	if ( !isArray(ary) )return this;
	tmpary = this;
	for ( var i = 0; i < ary.length; i++ ) {
		tmpary[tmpary.length] = ary[i];
	}
	return tmpary;
}
Array.prototype.isArray = true; //检测是否数组

function $( key ) { // 快捷函数,默认$id
	return $id( key );
}
function $id( id ) { //通过ID获取对象
	if ( window.document.getElementById ){
		var $id = function( id ) { return window.document.getElementById( id ); }
		return $id( id );
	}
	if ( window.document.all ){
		var $id = function( id ) { return window.document.all[ id ]; }
		return $id( id );
	}
	if ( window.document.layers[ id ] ){
		var $id = function( id ) { return window.document.layers[ id ]; }
		return $id(id);
	}
	alert( "Error: Lack of access to HTML object, upgrade your browser to IE6 or later!" );
	var $id = function( id ){ return null; }
	return null;
}
function $name( name ) { //通过Name获取对象
	if ( window.document.getElementsByName ) {
		var $name = function( name ){
			var tmpobj = window.document.getElementsByName[name];
			return tmpobj.length == 1 ? tmpobj[0] : tmpobj;
		}
		return $name(name);
	}
	alert( "Error: Lack of access to HTML object By Name, upgrade your browser to IE6 or later!" );
	var $name = function( name ) { return null; }
	return $name(name);
}
function $tag( tag ) { //通过TagName获取对象
	if ( window.document.getElementsByTagName ) {
		var $tag = function( tag ){
			var tmpobj = window.document.getElementsByTagName[tag];
			return tmpobj.length == 1 ? tmpobj[0] : tmpobj;
		}
		return $tag(tag);
	}
	alert("Error: Lack of access to HTML object By Tag, upgrade your browser to IE6 or later!");
	$tag = function( tag ) { return null; }
	return $tag(tag);
}
function isNum( value ) { //检测是否为数字
	return !isNaN( value ) ? true : false;
}
function isNull( o ) { //检测是否为无效对象
	return o == null || o == 'undefined' ? true : false;
}
function isEmpty( value ) { //检测是否为空
	return isNull( value ) || value == '' || value.length == 0 ? true : false;
}
function isArray( value ) { //检测是否数组
	return isNull( value ) ? false : value.isArray;
}
function isString( value ) { //检测是否字符串
	return value.isString;
}
function isBound( value, min, max ) { //检测数字范围 (如需检测长度，直接赋入长度)
	return value > min && value < max ? true : false;
}
function swfWrite( URL, width, height ) { //页面输出flash
	document.write(swfGetCode( URL, width, height ));
}
function swfGetCode( URL, width, height ) { //生成flash代码
	var tmpstr = isEmpty(swf_id) ? '' : "id=\"" + swf_id + "\"";
	var tmpstr2 = "";
	tmpstr = "<object " + tmpstr + " classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"" + swf_codebase + "\" width=\"" + width + "\" height=\"" + height + "\">\n<param name=\"movie\" value=\"" + URL + "\" />\n<param name=\"quality\" value=\"" + swf_quality + "\" />\n";
	params = isArray(swf_params) ? swf_params.unite( swf_globalparams ) : swf_globalparams;
	for ( var i = 0; i < params.length; i += 2 ) {
  		tmpstr2 += "<param name=\"" + params[i] + "\" value=\"" + params[i+1] + "\" />\n";
	}
	tmpstr += tmpstr2 + "<embed src=\"" + URL+ "\" quality=\"" + swf_quality + "\" pluginspage=\"" + swf_pluginspage + "\" type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\"></embed></object>";
	swfInit();
	return tmpstr;
}
function swfInit() { //初始化flash局部变量
	swf_params = Array(), swf_id = null, swf_quality = "hign";
}
function swfVersion() { //检测flash版本
	var tmp = navigator.plugins;
	if ( !tmp || tmp.length == 0 ) {
		for ( var i = 12; i > 5; i-- ) {
			try {
				var tmp = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash." + i.toString() );
				return i.toString() + ".0";
			} catch( e ) { continue; }
		}
		return null;
	} else {
		for ( var i = 0; i < tmp.length; i++ ) {
			if ( tmp[i].name.indexOf("Shockwave Flash") == -1 ) continue;
			return tmp[i].description.substr(16, 3);
		}
		return null;
	}
}
function selectedValue( o ) { //获取select选中的值
	return o.options[o.selectedIndex].value;
}
function selectedHtml( o ) { //获取select选中的HTML代码
	return o.options[o.selectedIndex].innerHTML;
}
function selectedAll( o ) { //select全选
	for ( var i = 0; i < o.options.length; i++ ) { o.options[i].selected = true; }
}
function selectedReverse( o ) { //select反选
	for ( var i = 0; i < o.options.length; i++ ) { o.options[i].selected = !o.options[i].selected; }
}
function appendOptions( o, value, html ) { //批量添加option元素
	for ( var i = 0; i < value.length; i++ ) {
		tmpobj = window.document.createElement('OPTION');
		tmpobj.value = value[i];
		tmpobj.innerHTML = html[i];
		o.appendChild( tmpobj );
	}
}
function checkedValue( o ) { //获取checkbox集合选中的值
	tmpary = Array();
	for ( var i = 0; i < o.length; i++ ) {
		if ( o[i].checked ) tmpary[tmpary.length] = o[i].value;
	}
	return tmpary;
}
function checkedObject( o ) { //获取checkbox集合选中的对象
	tmpary = Array();
	for ( var i = 0; i < o.length; i++ ) {
		if ( o[i].checked ) tmpary[tmpary.length] = o[i];
	}
	return tmpary;
}
function checkedAll( o ) { //checkbox全选
	for ( var i = 0; i < o.options.length; i++ ) {
		o.options[i].checked = true;
	}
}
function checkedReverse( o ) { //checkbox反选
	for ( var i = 0; i < o.length; i++ ) {
		o.checked = o.checked ? false : true;
	}	
}
function imgZoom( o, maxWidth ) { //图片缩略
	var a = new Image();
	a.src = o.src;
	if( a.width > maxWidth * 4 ){
		o.style.width = maxWidth;
	} else if( a.width >= maxWidth ){
		o.style.width = Math.round( a.width * Math.floor( 4 * maxWidth / a.width ) / 4 );
	}
	return false;
}
function write( txt ) { //页面输出
	document.write( txt );
}
function randomNum( min, max ) { //随即数字
	return Math.round( Math.random() * 100 );
}
function getOs( key, count ) { //获取浏览器的版本
	tmpstr = window.navigator.userAgent.toLowerCase().trim();
	key = key.toLowerCase().trim();
	if ( tmpstr.indexOf(key) > -1 ) {
	    return tmpstr.substr(  tmpstr.indexOf(key) + key.length + 1, count );
	}
	return null;
}
function jump( URL ) { //跳转页面
	o = isEmpty(jump_method) ? window : jump_method;
	switch( URL ) {
		case 'back':
			o.history.back(-1);
			break;
		case 'reload':
			o.location.reload();
			break;
		default:
			o.location.href = URL;
			break;
	}
	jump_method = window;
}
function wclose() { //关闭窗体
	window.open( '', '_parent', '');
	window.close();
}
function isCookiesEnable() { //检测是否支持cookies
	if( navigator.cookiesEnabled ) {
		isCookiesEnable = function() { return true; }
		return true;
	} else {
		document.cookie = "testcookie=yes;";
		if( document.cookie.indexOf("testcookie=yes") > -1 ) {
			document.cookie = "";
			var isCookiesEnable = function() { return true; }
			return true;
		}
		var isCookiesEnable = function() { return false; }
		alert('Your browser does not support cookies!');
		return false;
	}
}
function setCookie( key, value ) { // 设置Cookies
	if ( !cookies ) {
		var setCookie = function() { return false; }
		return false;
	}
    var exp  = new Date();
    exp.setTime(exp.getTime() + 9999999 * 1000);
    document.cookie = key + "="+ escape (value) + ";expires=" + exp.toGMTString() + ";";
}
function getCookieValue( key ) { // 获取Cookies的值
	if ( !cookies ) {
		var getCookieValue = function() { return null; }
		return null;
	}
	var tmpstr, rege = new RegExp( "(^| )" + key + "=([^;]*)(;|$)" );
	return tmpstr = document.cookie.match(reg) ? unescape( tmpstr[2] ) : null;
}
function checkExtend( URL, extend ) { //检测文件格式
	for ( var i = 0; i < URL.length; i++ ) {
		fileExtend = URL[i].split('.').lastValue().toLowerCase();
		for ( var n = 0; n < extend.length; n++ ) {
			if ( fileExtend != extend[n].toLowerCase() ) return false;
		}
	}
	return true;
}
function getUrlParam( key ) { // 获取网址上的参数(区分大小写)
	key = key.toLowerCase();
	if ( window.location.href.toString().indexOf('?') == -1 ) return null;
	tmparams = window.location.href.toString().split('?').lastValue().split('&');
	tmparamsValue = Array();
	for ( var i = 0; i < tmparams.length; i++ ) {
		tmpary = tmparams[i].split('=');
		if ( tmpary[0] == key ) tmparamsValue.append( tmpary[1] );
	}
	return tmparamsValue;
}
function incJs( URL ) { //载入js文件
	document.write( "<script type=\"text/javascript\" src=\"" + URL + "\"></" + "script>" );
}
function getClipBoard( text ) { //获取剪切板信息
	if ( window.clipboardData ) {
		getClipBoard = function( text ) {
			method = clipboard_method ? clipboard_method : 'text';
			clipboard_method = null;
			return window.clipboardData.getData( method, text );
		}
		return getClipBoard( text );
	} else {
		getClipBoard = function() { return false; }
		return false;
	}
}
function setClipBoard( text ) { //复制字符串到剪切板
	if ( window.clipboardData ) {
		setClipBoard = function( text ) {
			method = clipboard_method ? clipboard_method : 'text';
			clipboard_method = null;
			window.clipboardData.clearData();
			window.clipboardData.setData( method, txt );
			return true;
		}
		return setClipBoard( text );
	} else {
		setClipBoard = function() { return false; }
		return false;
	}  
}
function $xmlHttp() { //创建返回xmlHttp对象
	if ( window.XMLHttpRequest ) {
		$xmlHttp = function() { return new XMLHttpRequest(); }
		return $xmlHttp();
	}
	if ( window.ActiveXObject ) {
		try {
			var tmpobj = new ActiveXObject("Msxml2.XMLHTTP");
			var $xmlHttp = function() { return new ActiveXObject("Msxml2.XMLHTTP"); }
			return $xmlHttp();
		} catch(e) {
			try {
				var tmpobj = new ActiveXObject("Microsoft.XMLHTTP");
				var $xmlHttp = function() { return new ActiveXObject("Microsoft.XMLHTTP"); }
			} catch(e) {

			}
			return $xmlHttp();
		}
	}
	alert( "Error: Initialization \"XMLHttp\" Object Is Aborted" );
	var $xmlHttp = function() { return null; }
	return $xmlHttp();
}
function getXmlRequest( o, url, parm, method, asynchronism, charset, callback ) { //获取请求
	o.open( method, url, asynchronism );
	o.onreadystatechange = callback;
	o.setRequestHeader( "If-Modified-Since", "0" );
	o.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
	o.setRequestHeader( "Content-Type", charset );
	o.send(null);
}
function setXmlRunfunc( o, load, err, main ) { //设置xml运行的函数
	if ( !o ) return;
	if ( o.readyState == 4 ) {
		if ( o.status == 200 ) {
			return main;
		} else { return err; }
	} else { return load; }
}

var swf_globalparams = Array(); //flash全局通用参数
var swf_params = Array(); //flash参数变量
var swf_id = null; //flash的ID
var swf_quality = "hign"; //flash播放品质
var swf_codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"; //flash安装插件地址
var swf_pluginspage = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"; //flash安装插件地址
var jump_method = window; //跳转对象
var clipboard_method = null; //剪切板的方法
var ie, firefox, opera; //浏览器变量
var cookies; //是否支持cookies
var swf; //是否支持flash
var isframe = window.top.location != window.self.location; //判断是否本页被frame引用

//初始化浏览器版本变量
ie = getOs( "msie", 3 );
firefox = getOs( "firefox", 8 );
opera = getOs( "opera", 4 );
cookies = isCookiesEnable(); //初始化浏览器是否支持cookies
swf = swfVersion(); //初始化浏览器是否支持flash