/*---------------
	划蛇效果的实现
-----------------*/
function SubShowClass(ID,eventType,defaultID,openClassName,closeClassName){
	this.version="1.0";this.author="mengjia";this.parentObj=SubShowClass.$(ID);if(this.parentObj==null){throw new Error("SubShowClass(ID)参数错误:ID 对像存在!")};if(!SubShowClass.childs){SubShowClass.childs=[]};this.ID=SubShowClass.childs.length;SubShowClass.childs.push(this);this.lock=false;this.label=[];this.defaultID=defaultID==null?0:defaultID;this.selectedIndex=this.defaultID;this.openClassName=openClassName==null?"selected":openClassName;this.closeClassName=closeClassName==null?"":closeClassName;this.mouseIn=false;var mouseInFunc=Function("SubShowClass.childs["+this.ID+"].mouseIn = true"),mouseOutFunc=Function("SubShowClass.childs["+this.ID+"].mouseIn = false");if(this.parentObj.attachEvent){this.parentObj.attachEvent("onmouseover",mouseInFunc)}else{this.parentObj.addEventListener("mouseover",mouseInFunc,false)};if(this.parentObj.attachEvent){this.parentObj.attachEvent("onmouseout",mouseOutFunc)}else{this.parentObj.addEventListener("mouseout",mouseOutFunc,false)};if(typeof(eventType)!="string"){eventType="onmousedown"};eventType=eventType.toLowerCase();switch(eventType){case "onmouseover":this.eventType="mouseover";break;case "onmouseout":this.eventType="mouseout";break;case "onclick":this.eventType="click";break;case "onmouseup":this.eventType="mouseup";break;default:this.eventType="mousedown"};this.addLabel=function(labelID,contID,parentBg,springEvent,blurEvent){if(SubShowClass.$(labelID)==null){throw new Error("addLabel(labelID)参数错误:labelID 对像存在!")};var TempID=this.label.length;if(parentBg==""){parentBg=null};this.label.push([labelID,contID,parentBg,springEvent,blurEvent]);var tempFunc=Function('SubShowClass.childs['+this.ID+'].select('+TempID+')');if(SubShowClass.$(labelID).attachEvent){SubShowClass.$(labelID).attachEvent("on"+this.eventType,tempFunc)}else{SubShowClass.$(labelID).addEventListener(this.eventType,tempFunc,false)};if(TempID==this.defaultID){SubShowClass.$(labelID).className=this.openClassName;if(SubShowClass.$(contID)){SubShowClass.$(contID).style.display=""};if(parentBg!=null){this.parentObj.style.background=parentBg};if(springEvent!=null){eval(springEvent)}}else{SubShowClass.$(labelID).className=this.closeClassName;if(SubShowClass.$(contID)){SubShowClass.$(contID).style.display="none"}};if(SubShowClass.$(contID)){if(SubShowClass.$(contID).attachEvent){SubShowClass.$(contID).attachEvent("onmouseover",mouseInFunc)}else{SubShowClass.$(contID).addEventListener("mouseover",mouseInFunc,false)};if(SubShowClass.$(contID).attachEvent){SubShowClass.$(contID).attachEvent("onmouseout",mouseOutFunc)}else{SubShowClass.$(contID).addEventListener("mouseout",mouseOutFunc,false)}}};this.select=function(num,force){if(typeof(num)!="number"){throw new Error("select(num)参数错误:num 不是 number 类型!")};if(force!=true&&this.selectedIndex==num){return};var i;for(i=0;i<this.label.length;i++){if(i==num){SubShowClass.$(this.label[i][0]).className=this.openClassName;if(SubShowClass.$(this.label[i][1])){SubShowClass.$(this.label[i][1]).style.display=""};if(this.label[i][2]!=null){this.parentObj.style.background=this.label[i][2]};if(this.label[i][3]!=null){eval(this.label[i][3])}}else if(this.selectedIndex==i||force==true){SubShowClass.$(this.label[i][0]).className=this.closeClassName;if(SubShowClass.$(this.label[i][1])){SubShowClass.$(this.label[i][1]).style.display="none"};if(this.label[i][4]!=null){eval(this.label[i][4])}}};this.selectedIndex=num};this.random=function(){if(arguments.length!=this.label.length){throw new Error("random()参数错误:参数数量与标签数量不符!")};var sum=0,i;for(i=0;i<arguments.length;i++){sum+=arguments[i]};var randomNum=Math.random(),percent=0;for(i=0;i<arguments.length;i++){percent+=arguments[i]/sum;if(randomNum<percent){this.select(i);break}}};this.autoPlay=false;var autoPlayTimeObj=null;this.spaceTime=5000;this.play=function(spTime){if(typeof(spTime)=="number"){this.spaceTime=spTime};clearInterval(autoPlayTimeObj);autoPlayTimeObj=setInterval("SubShowClass.childs["+this.ID+"].nextLabel()",this.spaceTime);this.autoPlay=true};this.nextLabel=function(){if(this.autoPlay==false||this.mouseIn==true){return};var index=this.selectedIndex;index++;if(index>=this.label.length){index=0};this.select(index)};this.stop=function(){clearInterval(autoPlayTimeObj);this.autoPlay=false}};SubShowClass.$=function(objName){if(document.getElementById){return eval('document.getElementById("'+objName+'")')}else{return eval('document.all.'+objName)}
	}

/*-----------------------------------------
	fun:  滑舌效果
	para：Id所获得div的id号，tagName 标签名称
	author：shiying 2008-12-10
--------------------------------------------*/
function ontags(Id,tagName){
	if(Id==1){
		document.getElementById(tagName+"_1").className="xuanzhong";
		document.getElementById(tagName+"_2").className="weixuan";
		document.getElementById(tagName+"_con_"+1).style.display="";
		document.getElementById(tagName+"_con_"+2).style.display="none";
		
		document.getElementById(tagName+"_more_"+1).style.display="";
		document.getElementById(tagName+"_more_"+2).style.display="none";



	}else{
		document.getElementById(tagName+"_2").className="xuanzhong";
		document.getElementById(tagName+"_1").className="weixuan";

		document.getElementById(tagName+"_con_"+2).style.display="";
	    document.getElementById(tagName+"_con_"+1).style.display="none";
		
		document.getElementById(tagName+"_more_"+2).style.display="";
		document.getElementById(tagName+"_more_"+1).style.display="none";



	}
}
//滑舌效果
function showSubCatalog(obj,subName,tagName,num,moreInfo){
	if(typeof($(tagName+'More')) == 'object') $(tagName+'More').innerHTML = (typeof(moreInfo) != 'undefined')?moreInfo:'';
	for(i=1;i<=num;i++){
		if(obj == tagName+i){
			if(typeof($(obj)) == 'object') {
				$(obj).className='xuanzhong';
				$(subName+i).style.display="";
			}
		}else{
			if(typeof($(tagName+i)) == 'object') {
				$(tagName+i).className='weixuan';
				$(subName+i).style.display="none";
			}
		}
	}
}
/*-----------------------------------------
	计算两个整数的排列
	para：TLen,SLen 两个整数
	author： fangzhen 08.9.19
--------------------------------------------*/
function PaiLie(TLen,SLen) {
   var maxs = 1;
   var mins = 1;
   if(TLen <= 0) return 0;
   if(TLen<SLen) return 0;

   for(var i=TLen-SLen+1; i<TLen+1; i++) {
       maxs = maxs*i;
   }
   for(var i=1; i<SLen+1; i++) {
       mins = mins*i;
   }
   return maxs/mins;  
}
/*--------------------------------------------
	功能：用ajax方法提交数据
	author：fangzhen 08.10.20
--------------------------------------------*/
var XMLHttpObj=null;
function newXMLHttpRequest() { 
	var xmlreq = false; 
	if (window.XMLHttpRequest) { 
		xmlreq = new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		try { 
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP"); 
		} catch (e1) { 
			try { 
				xmlreq = new ActiveXObject("Microsoft.XMLHTTP"); 
			} catch (e2) { 

			} 

		} 

	}
	return xmlreq; 
}

function ReturnFunction() {
	if(XMLHttpObj.readyState==4) {
	// 成功接收了服务器响应
	  if (XMLHttpObj.status==200) {
	  } else { 
	   // 有HTTP问题发生 
			alert("HTTP error: "+XMLHttpObj.status); 
	  } 
	}
}
/*-----------------------------------------
	利用tp自带的ajax功能，实现广告点击的统计
	para：adName 广告名称 url统计处理页面
	author： fangzhen 08.9.19
--------------------------------------------*/
function tj_adv(adId,adName,url,refer){
	if(adId != "") {
		var URL=url+"/common/index.php/Common/mark_adv/ad_id/"+adId+"/ad_name/"+adName+"/url_from/"+refer;
		var Parm=null;
		XMLHttpObj=newXMLHttpRequest(); 
		XMLHttpObj.onreadystatechange=ReturnFunction;
		XMLHttpObj.open("POST",URL,true);
		XMLHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
		XMLHttpObj.send(Parm);
	}
}
/*--------------------------------
	重新加载验证码
	para：url 验证码地址
	author：fangzhen 08.10.23
----------------------------------*/
function verifyRest(url) {
	if(url != "") {
		var timenow = new Date().getTime();
		$("verifyImg").src = url+"/"+timenow;
	}	
}

/*---------------------------------
	检测字符长度，一个汉字算两个字符
	para：str
	author：fangzhen 08.11.3
----------------------------------*/
function mb_strlen(str) {
	var len = 0;
	for(var i = 0; i < str.length; i++) {
		len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ?  2 : 1;
	}
	return len;
}

String.prototype.trim= function(){  
    // 用正则表达式将前后空格  
    // 用空字符串替代。  
    return this.replace(/(^\s*)|(\s*$)/g, "");  
}

//检测邮件地址

function validEmail(item) {
	var etext;
	var elen;
	var i;
	var aa;
	etext=item;
	elen=etext.length;
	if (elen<5) return true;
	i= etext.indexOf("@",0);
	if (i==0 || i==-1 || i==elen-1) {
		return true;
	} else {
		if (etext.indexOf("@",i+1)!=-1) return true;
	}
	
	if (etext.indexOf("..",i+1)!=-1) return true;
	i=etext.indexOf(".",0);
	if (i==0 || i==-1 || etext.charAt(elen-1)=='.') return true;
	if ( etext.charAt(0)=='-' ||  etext.charAt(elen-1)=='-') return true;
	if ( etext.charAt(0)=='_' ||  etext.charAt(elen-1)=='_') return true;
	
	for (i=0;i<=elen-1;i++){ 
		aa=etext.charAt(i)
	  	if (!((aa=='.') || (aa=='@') || (aa=='-') ||(aa=='_') || (aa>='0' && aa<='9') || (aa>='a' && aa<='z') || (aa>='A' && aa<='Z'))) return true;
	
	}
	return false;

}

/*----------------------------
	去掉错误提示
	para: divId 层标签名 msg 提示信息
	author：fangzhen 08.11.6
------------------------------*/
function clearInfo(divId,msg) {
	$(divId).innerHTML = msg;
}

function checkNum(str){
	var strSource ="0123456789.";
	var ch;
	var i;
	var temp;  
	for (i=0;i<=(str.length-1);i++) {  
		ch = str.charAt(i);
		temp = strSource.indexOf(ch);
		if (temp==-1){
			return 0;
		}
	}
	if (strSource.indexOf(ch)==-1){
		return 0;
	} else {
		return 1;
	} 
}
/*--------------------------------------------------
	格式化浮点型数据
	para：srcStr 要格式的浮点型数据 nAfterDot小数点位数
	fangzhen 08.11.12
---------------------------------------------------*/
function formatNumber(srcStr,nAfterDot){
　　var srcStr,nAfterDot;
　　var resultStr,nTen;
　　srcStr = ""+srcStr+"";
　　strLen = srcStr.length;
　　dotPos = srcStr.indexOf(".",0);
　　if (dotPos == -1){
　　　　resultStr = srcStr+".";
　　　　for (i=0;i<nAfterDot;i++){
　　　　　　resultStr = resultStr+"0";
　　　　}
　　　　return resultStr;
　　}
　　else{
　　　　if ((strLen - dotPos - 1) >= nAfterDot){
　　　　　　nAfter = dotPos + nAfterDot + 1;
　　　　　　nTen =1;
　　　　　　for(j=0;j<nAfterDot;j++){
　　　　　　　　nTen = nTen*10;
　　　　　　}
　　　　　　resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen;
　　　　　　return resultStr;
　　　　}
　　　　else{
　　　　　　resultStr = srcStr;
　　　　　　for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++){
　　　　　　　　resultStr = resultStr+"0";
　　　　　　}
　　　　　　return resultStr;
　　　　}
　　}
}

/*--------------------------------
	div显示内容 背景网页内容被屏蔽
	para：tipStr 显示内容
	fangzhen 08.17
	#dhtipscontent {width:400px;height:300px;background:white;border:2px solid #ddd;z-index:102;padding:2px;}
	#dhtipsdiv {background:#000;-moz-opacity:0.6;opacity:0.6;filter:alpha(opacity=60);z-index:101;border:none;}
	#dhtipsiframe {-moz-opacity:0;opacity:0;filter:alpha(opacity=0);z-index:100;border:none;}
	.tipsdiv {height:160px;overflow:auto;line-height:150%; border:1px solid #FF9900}
	.closediv {height:20px;text-align:right; padding-right:5px; padding-top:5px}
	.closebtn {position:relative;top:0px;right:0px;border:1px solid buttonshadow;}
---------------------------------*/
function showtips(tipStr){
	var pagesize = TB_getPageSize();
	if(document.getElementById("dhtipsiframe")==null){
		var iframe = document.createElement("IFRAME");
		iframe.id = "dhtipsiframe";
		iframe.style.position = "absolute";
		iframe.style.left = 0;
		iframe.style.top = 0;
		iframe.style.width = (document.body.scrollWidth>document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
		iframe.style.height = (document.body.scrollHeight>document.body.offsetHeight)?document.body.scrollHeight+20:document.body.offsetHeight;
		
		var div = document.createElement("DIV");
		div.id = "dhtipsdiv";
		div.style.position = "absolute";
		div.style.left = 0;
		div.style.top = 0;
		div.style.width = (document.body.scrollWidth>document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
		div.style.height = (document.body.scrollHeight>document.body.offsetHeight)?document.body.scrollHeight+20:document.body.offsetHeight;
		div.oncontextmenu = function(){return false}
		div.onselectstart = function(){return false}
		
		var div2 = document.createElement("DIV");
		div2.id = "dhtipscontent";
		div2.style.position = "absolute";
		div2.style.left = pagesize[0]/2-150+document.body.scrollLeft;
		//div2.style.top = pagesize[1]/2-150+document.body.scrollTop;
		div2.style.top = document.documentElement.scrollTop + document.documentElement.clientHeight/2 - 150 + "px";
		div2.innerHTML = "<div class=\"tipsdiv\">"+tipStr+"</div><div class=\"closediv\"><input type=\"button\" class=\"closebtn\" value=\"关闭\" onclick=\"document.body.style.overflow='auto';document.getElementById('dhtipsiframe').style.display='none';document.getElementById('dhtipsdiv').style.display='none';document.getElementById('dhtipscontent').style.display='none';\" /></div>";
		div2.oncontextmenu = function(){return false}
		
		document.body.appendChild(iframe);
		document.body.appendChild(div);
		document.body.appendChild(div2);
	}else{
		document.getElementById("dhtipsiframe").style.display = "block";
		document.getElementById("dhtipsdiv").style.display = "block";
		document.getElementById("dhtipscontent").style.display = "block";
		document.getElementById("dhtipscontent").innerHTML = "<div class=\"tipsdiv\">"+tipStr+"</div><div class=\"closediv\"><input type=\"button\" class=\"closebtn\" value=\"关闭\" onclick=\"document.body.style.overflow='auto';document.getElementById('dhtipsiframe').style.display='none';document.getElementById('dhtipsdiv').style.display='none';document.getElementById('dhtipscontent').style.display='none';\" /></div>";
		document.getElementById("dhtipscontent").style.left = pagesize[0]/2-150+document.body.scrollLeft;
		document.getElementById("dhtipscontent").style.top = document.documentElement.scrollTop + document.documentElement.clientHeight/2 - 150 + "px";
	}
	var l = document.body.scrollLeft;
	var t = document.body.scrollTop;
	document.body.style.overflow = "hidden";
	document.body.scrollLeft = l;
	document.body.scrollTop = t;
}

/*-----------------------
	功能：验证交易密码
	author:fangzhen 08.11.21
------------------------*/
function checkTradePwd() {
	ThinkAjax.showTip = false;
	ThinkAjax.sendForm(parent.document.tradePwdForm,'http://www.52cp.cn/common/index.php/Index/check_trade_pwd/',completeTradePwd);	
}
function completeTradePwd(divId,status,info) {
	
	if(status == 1) {
		parent.$(divId).innerHTML = "交易密码验证通过";
		$('tradePassword').value = info;
		setTimeout('hiddenTradePwdCheck()',10);
	} else {
		parent.$(divId).innerHTML = info+"<br><input type='password' name='trade_pwd' id='trade_pwd' style='width:120px;height:18px;' />&nbsp;&nbsp;<input type='button' name='Submit' value='确认' onClick='checkTradePwd()' />";
	}
}
function hiddenTradePwdCheck () {
	document.body.style.overflow='auto';
	parent.$('dhtipsiframe').style.display='none';
	parent.$('dhtipsdiv').style.display='none';
	parent.$('dhtipscontent').style.display='none';
}

/*------------------------------------------------------------
	该函数实现期号选择后的跳转
	para: issue 期号 lottType 彩种（如 fc3d 表示福彩3D） url 跳转路径
	author： fangzhen 08.9.19
---------------------------------------------------------------*/
function searchIssue(issue,lottType,url){
	if(issue != ""){
		document.location.href = url+"/"+lottType+"/"+issue;
	}
}

/*------------------------------------------------------------
	判断字符串全由汉字组成
	author：fangzhen 09.3.23
------------------------------------------------------------*/
function checkHz(str) { 
	var s; 
	var ts; 
	var tscode;
	var hzNum = 0; 
	for (i=0;i<str.length;i++){ 
		tscode=str.charCodeAt(i); 
		if ((tscode<19968)||(tscode>40959)){
		  return 0;
		} else {
		  hzNum ++;
		}
	}
	if(hzNum == str.length) {
		return 1;
	} else {
		return 0;
	}
}

function TB_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
}
/*------------------------------
	登录验证
	athor：fangzhen 09.8.9
--------------------------------*/
function checkLog(){
	if($F('username') == "") {
		alert("请输入您的用户名.");
		$('username').focus();
		return false;
	}
	if($F('password') == "") {
		alert("请输入您的用户密码.");
		$('password').focus();
		return false;
	}
	if($F('verify') == "") {
		alert("请输入验证码.");
		$('verify').focus();
		return false;
	}
	return true;
}

/*---------------------------
	清空input数据
	athor：fangzhen 09.8.9
---------------------------*/
function clearInput(inputId) {
	$(inputId).value = "";
}
/*--------------------
	隐藏显示层
	author：fangzhen 09.9.7
---------------------*/
function openSort(obj,tagName,num){
	if(typeof($(obj)) == 'object') {
		for(i=1;i<=num;i++){
			if(obj == tagName+i){
				$(obj).style.display = '';
			}else{
				$(tagName+i).style.display = 'none';
			}
		}
	}
}
/*------------------------------------------------------------
	该函数实现期号选择后的跳转
	para: issue 期号 lottType 彩种（如 fc3d 表示福彩3D） url 跳转路径
	author： fangzhen 08.9.19
---------------------------------------------------------------*/
function searchIssue2(issue,url){
	if(issue != ""){
		document.location.href = url+"/"+issue;
	}
}