/**********************************************************\
 * 常用正则表达式的定义
 *---------------------------------------------------------
 * 
\**********************************************************/
var	Require	= /.+/;
var	Email	= /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
var	Phone	= /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/;
var	Mobile	= /^((\(\d{2,3}\))|(\d{3}\-))?1\d{10}$/;
var	Url		= /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
var	Currency= /^\d+(\.\d+)?$/;
var	Number	= /^\d+$/;
var	Zip		= /^[1-9]\d{5}$/;
var	QQ		= /^[1-9]\d{4,8}$/;
var	Integer	= /^[-\+]?\d+$/;
var	Double	= /^[-\+]?\d+(\.\d+)?$/;
var	English	= /^[A-Za-z]+$/;
var	Chinese	= /^[\u0391-\uFFE5]+$/;
var RealName= /^[\u0391-\uFFE5]{2,10}$/;
var	Username= /^\w{5,16}$/;
var	Password= /^\w{5,16}$/;
var	UnSafe	= /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/;

/**********************************************************\
 * 将字符串以UTF-8字符集编码
 *---------------------------------------------------------
 * 
\**********************************************************/
function URLEncode(val){
	return encodeURIComponent(encodeURIComponent(val));
}

/**********************************************************\
 * URL处理, 获取URL中的参数
 *---------------------------------------------------------
 * e.g.
 * var	jsr	= new JSRequest("https://sq.qidian.com/wwww/ShowClub.aspx?id=23432&f=567");
 * 
 * alert("path:    "+myurl.Path);
 * alert("pathandQuery:    "+myurl.PathAndQuery);
 * alert("queryString:    "+myurl.QueryString);
 * alert("id="+myurl.getParameter("id")); //获取查询参数的值
 * alert("f="+myurl.getParameter("f"));
\**********************************************************/
function JSRequest(_url){
    this.url	= document.URL;
    if(_url){
        this.url	= _url;
	}

    this.reg	= new RegExp("(http|https|ftp)://([-a-z0-9_.]+)(/[-a-z0-9_.!/@&=\+,.~%\$\?]*)","gmi");
    this.reg.test(this.url);

    this.HostName=RegExp.$2; //域名
    this.Protocal=RegExp.$1; //url协议
    this.PathAndQuery=RegExp.$3; //路径和查询参数
    this.Path=this.url.indexOf('?')>0?RegExp.$3.substring(0,RegExp.$3.indexOf('?')):RegExp.$3; //路径
    this.QueryString=this.url.indexOf('?')>0?RegExp.$3.substring(RegExp.$3.indexOf('?')+1):''; //查询参数
}
//获取Url的查询参数值
JSRequest.prototype.getParameter = function (name){
	if(/\?(.+)$/.test(this.url)){
		var ta=RegExp.$1;
		var r = new RegExp(name+"=([^&]+)","gmi");
		if(r.test(ta)){
			return unescape(RegExp.$1);
		}else{
			return '';
		}
	}else{
		return '';
	}
}

/**********************************************************\
 * 动态载入js文件
 *---------------------------------------------------------
 * 载入的js将出现在body的最下部
 * 
\**********************************************************/
function loadJS(js_url){
	var	oScript	= document.createElement('script');
	oScript.setAttribute('type', 'text/javascript');
	oScript.setAttribute('src', js_url);
	if(document.getElementById('_load_js') === null){
		var	oDiv	= document.createElement('div');
		oDiv.setAttribute('id', '_load_js');
		oDiv.setAttribute('style', 'display: none;');
		document.body.appendChild(oDiv);
	}
	var	container	= document.getElementById('_load_js');
	container.appendChild(oScript);
}

/**********************************************************\
 * 以下是一组关于table的javascript函数
 *---------------------------------------------------------
 * blinkTable(tid) 
 *     表格特效,当鼠标移动到表格的某一行时,该行将高亮显示,当鼠标移出时,
 *     颜色恢复为原来的白色 
 *     tid 为表格的id, 效果只针对目标表格中的tbody部分
 * markPosition(row, col, value)
 *     用于存放表格中某个单元格数据的对象
 * markMax(DataSet, oColor, oColumns)
 *     用于标出表格中各列的最大值,该函数只针对tbody区域的数据
 *     DataSet ---- 表格的id
 *     oColor ----- 用于标记的颜色
 *     oColumns --- 欲标记的列的序号,列的序号从 0 开始
 * markMin(DataSet, oColor, oColumns)
 *     用于标出表格中各列的最小值,该函数只针对tbody区域的数据
 *     DataSet ---- 表格的id
 *     oColor ----- 用于标记的颜色
 *     oColumns --- 欲标记的列的序号,列的序号从 0 开始
 *
\**********************************************************/
function blinkTable(tid){
	var	oDataSet= document.getElementById(tid);
	var	oBody	= oDataSet.getElementsByTagName("tbody")[0];
	var	oTds	= oBody.getElementsByTagName("tr");
	for(var i=0; i<oTds.length; i++){
		oTds[i].onmouseover	= function(){
			this.style.backgroundColor	= "#eec";
		};
		oTds[i].onmouseout	= function(){
			this.style.backgroundColor	= "#fff";
		};
	}
}

function markPosition(row, col, value){
	this.row	= row;
	this.col	= col;
	this.value	= value;
}

function markMax(DataSet, oColor, oColumns){
	var	oDataSet= document.getElementById(DataSet);
	var	oMaxs	= new Array(oColumns.length);
	for(var i=0; i<oColumns.length; i++){
		oMaxs[i]	= new markPosition(
			0, 
			oColumns[i], 
			parseFloat(oDataSet.tBodies[0].rows[0].cells[oColumns[i]].childNodes[0].nodeValue)
		);
	}

	for(var i=0; i<oDataSet.tBodies[0].rows.length; i++){
		for(var j=0; j<oColumns.length; j++){
			var	tmp	= parseFloat(oDataSet.tBodies[0].rows[i].cells[oColumns[j]].childNodes[0].nodeValue);
			if(oMaxs[j].value < tmp){
				oMaxs[j].value	= tmp;
				oMaxs[j].row	= i;
				oMaxs[j].col	= oColumns[j];
			}
		}
	}

	for(var i=0; i<oMaxs.length; i++){
		oDataSet.tBodies[0].rows[oMaxs[i].row].cells[oMaxs[i].col].style.color			= oColor;
		oDataSet.tBodies[0].rows[oMaxs[i].row].cells[oMaxs[i].col].style.backgroundColor= "#eec";
		oDataSet.tBodies[0].rows[oMaxs[i].row].cells[oMaxs[i].col].style.fontWeight		= "bold";
	}
}

function markMin(DataSet, oColor, oColumns){
	var	oDataSet= document.getElementById(DataSet);
	var	oMins	= new Array(oColumns.length);
	for(var i=0; i<oColumns.length; i++){
		oMins[i]	= new markPosition(
			0, 
			oColumns[i], 
			parseFloat(oDataSet.tBodies[0].rows[0].cells[oColumns[i]].childNodes[0].nodeValue)
		);
	}

	for(var i=0; i<oDataSet.tBodies[0].rows.length; i++){
		for(var j=0; j<oColumns.length; j++){
			var	tmp	= parseFloat(oDataSet.tBodies[0].rows[i].cells[oColumns[j]].childNodes[0].nodeValue);
			if(oMins[j].value > tmp){
				oMins[j].value	= tmp;
				oMins[j].row	= i;
				oMins[j].col	= oColumns[j];
			}
		}
	}

	for(var i=0; i<oMins.length; i++){
		oDataSet.tBodies[0].rows[oMins[i].row].cells[oMins[i].col].style.color			= oColor;
		oDataSet.tBodies[0].rows[oMins[i].row].cells[oMins[i].col].style.backgroundColor= "#eec";
		oDataSet.tBodies[0].rows[oMins[i].row].cells[oMins[i].col].style.fontWeight		= "bold";
	}
}

/**********************************************************\
 * 闪烁的文本框
 *---------------------------------------------------------
 * 使文本框在鼠标进入和移出时分别显示不同的颜色
 * 
\**********************************************************/
function BLINK_BORDER(cMouseOver, cMouseOut){
	var	objs	= document.getElementsByTagName("input");
	for(var i=0; i<objs.length; i++){
		if(objs[i].type=="text" || objs[i].type=="password"){
			objs[i].style.border	= "1px solid "+cMouseOut;
			objs[i].style.width	= 160;
			objs[i].onmouseover	= function(){
				this.style.border	= "1px solid "+cMouseOver;
			};
			objs[i].onmouseout	= function(){
				this.style.border	= "1px solid "+cMouseOut;
			};
		}
	}
}

function TEST_BOX(tid, reg){
	var	oBox		= document.getElementById(tid);
	this.status		= false;
	oBox.onblur		= fun;
	oBox.onkeyup	= fun;
	oBox.onkeydown	= fun;
	
	function fun(){
		this.status	= false;
		if(reg.length){
			for(var i=0; i<reg.length; i++){
				if(reg[i].test(this.value)){
					this.status	= true;
					break;
				}
			}
		}else{
			this.status	= reg.test(this.value);
		}
		this.style.backgroundColor	= this.status ? "#fff" : "#fee";
	}
}

//检查身份证号
function IDCARD_BOX(tid){
	var	oBox	= document.getElementById(tid);
	var	msg		= true;
	this.status	= false;
	
	oBox.onblur		= fun;
	oBox.onkeyup	= fun;
	oBox.onkeydown	= fun;
	
	function fun(){
		var	idc	= null;
		try{
			idc	= new IDCard(oBox.value);
		}catch(e){}
		this.status	= idc!=null;
		this.style.backgroundColor	= this.status ? "#fff" : "#fee";
	}
}

/**********************************************************************\
 * __☆★| 锁屏功能 |★☆__
 *---------------------------------------------------------------------
 * 说明:
 *      当要执行摸个操作时先调用 lock() 方法, 束时时在调用 unlock() 方法.
 *      LOCK_IMGAGE_URL 为loading图片的位置,可根据实际情况更改
 * 作者: Alex Zhao
 * 时间: 2008-11-13 14:51
\**********************************************************************/
var	LOCK_IMGAGE_URL	= "http://cash.forugame.com/charge/images/clz.gif";

function lock(){
	var	oImg	= document.createElement("img");
	oImg.setAttribute("src", LOCK_IMGAGE_URL);
	oImg.setAttribute("id", "_close");

	var	oInfo	= document.createElement("div");
	oInfo.setAttribute("id", "_lock_info_div");
	oInfo.setAttribute("style", "border: 0px solid #369; width:100px; height:100px; background:transparent; z-index:1000; position:absolute; display:none;");
	oInfo.style.display = "block";
	oInfo.style.position = "absolute";
	oInfo.style.top = "50%";
	oInfo.style.left = "50%";
	oInfo.style.marginTop = "-75px";
	oInfo.style.marginLeft = "-50px";

	var	oWall = document.createElement("div");
	
	oWall.setAttribute("id","_lock_wall_div");
	oWall.style.background = "#000";
	oWall.style.width = "100%";
	oWall.style.height = "100%";
	/* 如果是IE6将采取其他方式处理高度 */
	if(navigator.appVersion.search("MSIE 6.0")>=0){
		oWall.style.height = "1050px";
	}
	oWall.style.position = "absolute";
	oWall.style.top = "0";
	oWall.style.left = "0";
	oWall.style.zIndex = "500";
	oWall.style.opacity = "0.61";
	oWall.style.filter = "Alpha(opacity=61)";

	oInfo.appendChild(oImg);

	document.body.appendChild(oInfo);

	document.body.appendChild(oWall);
	
	document.body.style.overflow = "hidden";
}

function unlock(){
	document.body.removeChild(document.getElementById('_lock_info_div'));
	document.body.removeChild(document.getElementById('_lock_wall_div'));
	document.body.style.overflow = "auto";
}
//-- 锁屏功能结束 ---------------------------------------------------------


/**********************************************************\
 * 复制
 *---------------------------------------------------------
 * 添加指定的文字到剪贴板中
 * 
\**********************************************************/
function copyToClipboard(txt) {
     if(window.clipboardData) {
             window.clipboardData.clearData();
             window.clipboardData.setData("Text", txt);
     } else if(navigator.userAgent.indexOf("Opera") != -1) {
          window.location = txt;
     } else if (window.netscape) {
          try {
               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
          } catch (e) {
               alert("你使用的FF浏览器,复制功能被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signed.applets.codebase_principal_support'设置为'true'");
          }
          var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
          if (!clip)
               return;
          var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
          if (!trans)
               return;
          trans.addDataFlavor('text/unicode');
          var str = new Object();
          var len = new Object();
          var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
          var copytext = txt;
          str.data = copytext;
          trans.setTransferData("text/unicode",str,copytext.length*2);
          var clipid = Components.interfaces.nsIClipboard;
          if (!clip)
               return false;
          clip.setData(trans,null,clipid.kGlobalClipboard);
     }
}

