/**动画参数============================================================*/
/**网站动画效果总开关*/
var doAnimation=($.cookie('doAnimation')==null?((document.all)?false:true):($.cookie('doAnimation')=="true"?true:false));
/**日期框集合*/
var dateList=new Array();
/**向下展开框集合*/
var accordionList=new Array();
/**弹窗集合*/
var dialogList=new Array();
/** 大部分日期框的动画 */
var dateAnimation = "clip";
/** 大部分向下展开框的动画 */
var accordionAnimation = "slide";
/**大部分弹窗出现效果*/
var showDialogAnimation=null;
/**大部分弹窗关闭效果*/
var hideDialogAnimation="blind";
/**会员注册页动画----------------------------------*/
/**头像选择横条展开效果*/
var photoOpenAnimation="fold";
/**被选中的头像收回效果*/
var photoSelectedCloseAnimation="transfer";
/**其他头像收回效果*/
var photoOtherCloseAnimation="scale";
/**相框中的头像消失效果*/
var photoHideAnimation="scale";
/**头像出现在像框中的效果*/
var photoShowAnimation="shake";
/**论坛帖子动画----------------------------------*/
/**评分成功出现的勾的动画*/
var scoreSuccessAnimation="clip";
/**回复支持成功出现的勾的动画*/
var commentTopSuccessAnimation="clip";
/**发帖头像选中动画*/
var bbsPhotoSelectedAnimation="transfer";
/**颜色参数==============================================*/
/**论坛部分----------------------------------*/
/**论坛帖子整体颜色*/
var bbs_article_color="#294A7D";
/**论坛其它页面整体颜色*/
var bbs_other_color="#37577C";
/**鼠标经过项变色(版块项,和帖子项)*/
var bbs_other_hoverItem_color="#D1D9F4";
/**栏目交错颜色(单双)*/
var bbs_other_itemColor1="#F3F3F3";
var bbs_other_itemColor2="white";
/**按钮经过反色(例:支持选项)*/
var bbs_button_hover="#8FBF5C";
/**管理员部分-------------------------------*/
var admin_button_hover="#8FBF5C";
var admin_button_color="#37577C";
/**一般页面部分*/
var common_normalColor="#4A79FF";
var common_currentColor="#225D9F";
/**首页部分*/
/**首页标题颜色*/
var mainTitleColor="#EBF1F7";
/**首页标题选中颜色*/
var mainTitleHoverColor="white";
/**IE6重复加载背景*/
try{
	document.execCommand("BackgroundImageCache", false, true); 
}catch(e){}
/**判断是否为IE6*/
var isIE = (document.all) ? true : false;
var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6);
/** 文本框输入限制 */
$.fn.textCheck = function(type) {
	/**type参数
	 * num纯数字
	 * phone数字+"-"
	 * lop 用户名或密码 (a-zA-Z0-9)
	 * email 电子邮箱(a-zA-Z0-9_@.)
	 * noSH 禁用空格和标签
	 * */
	if(type!="noSH")
	$(this).css("ime-mode", "disabled");
	this.bind("keypress", function(e) {
		/** 兼容火狐 IE */
		var code = (e.keyCode ? e.keyCode : e.which);
		/** 火狐下不能使用退格键 */
		if (!$.browser.msie && (e.keyCode == 0x8)) {
			return;
		}
		if (type == "num") {
			return code >= 48 && code <= 57;
		}else if (type == "phone") {
			return (code >= 48 && code <= 57)||code==45;
		}else if (type == "lop") {
			return (code >= 48 && code <= 57)||(code>=97&&code<=122)||(code>=65&&code<=90);
		}else if (type == "email") {
			return (code >= 48 && code <= 57)||(code>=97&&code<=122)||(code>=65&&code<=90)||code==46||code==64||code==95;
		}else if(type=="noSH"){
			return code!=32&&code!=60&&code!=62&&code!=38;
		}
	});
	this.bind("blur", function() {
		if (type=="num"&&!/^[\d]+$/.test(this.value)) {
			this.value = "";
		}else if (type=="phone"&&!/^[\d-]+$/.test(this.value)) {
			this.value = "";
		}else if (type=="lop"&&!/^[a-zA-Z0-9]+$/.test(this.value)) {
			this.value = "";
		}else if (type=="email"&&!/^[a-zA-Z0-9_\\.\\@]+$/.test(this.value)) {
			this.value = "";
		}else if (type=="noSH"&&(this.value.indexOf(" ")!=-1||this.value.indexOf("<")!=-1||this.value.indexOf(">")!=-1||this.value.indexOf("&")!=-1)) {
			this.value = "";
		}
	});
	this.bind("paste", function() {
		var s = clipboardData.getData('text');
		if (type=="num"&&/^[\d]+$/.test(s))
			return s;
		else if (type=="phone"&&/^[\d-]+$/.test(s))
			return s;
		else if (type=="lop"&&/^[a-zA-Z0-9]+$/.test(s))
			return s;
		else if (type=="email"&&/^[a-zA-Z0-9_\\.\\@]+$/.test(s))
			return s;
		else if (type=="noSH"&&s.indexOf(" ")==-1&&s.indexOf("<")==-1&&s.indexOf(">")==-1&&s.indexOf("&")==-1)
			return s;
		return false;
	});
	this.bind("dragenter", function() {
		return false;
	});
};
/**格式化时间*/
Date.prototype.format = function(format){       
	var o = {        
			"M+" : this.getMonth()+1, //month        
			"d+" : this.getDate(),    //day        
			"H+" : this.getHours(),   //hour       
			"m+" : this.getMinutes(), //minute        
			"s+" : this.getSeconds(), //second        
			"q+" : Math.floor((this.getMonth()+3)/3),  //quarter        
			"S" : this.getMilliseconds() //millisecond        
			}        
	if(/(y+)/.test(format)){
		format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
	}
	for(var k in o)if(new RegExp("("+ k +")").test(format)){
		format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] :("00"+ o[k]).substr((""+ o[k]).length));
	}
	return format;    
}
/**字节数转KBMBGB显示格式*/
function fileSizeFormat(size){
	size=parseInt(size);
	var type;
	var toSize;
	if(size<1024){
		toSize=size+"";
		type="字节";
	}else if(size<1048576){
		toSize=(size/1024)+"";
		type="KB";
	}else if(size<1073741824){
		toSize=(size/1048576)+"";
		type="MB";
	}else if(size<1099511627776){
		toSize=(size/1073741824)+"";
		type="GB";
	}else{
		toSize=(size/1099511627776)+"";
		type="TB";
	}
	if(toSize.indexOf(".0")==toSize.length-2){
		toSize=toSize.substring(0,toSize.length-2);
	}else if(toSize.indexOf(".")>=0){
		var s=toSize.split(".");
		if(s[1].length>2){
			toSize=s[0]+"."+s[1].substring(0,2);
		}
	}
	return toSize+type;
}
/**超过长度的字符显示省略号*/
function checkStrLength(str,max){
	str=str+"";
	var tempStr="";
	var allLength=0;
	for (var i=0;i<str.length;i++){
		var s=str.charAt(i);
		allLength+=getLength(s);
		if(allLength>=max){
			tempStr+="..";
			break;
		}
		tempStr+=s;
	}
	return tempStr;
}
function checkStrLengthMiddle(str,max){
	str=str+"";
	var tempStr1="";
	var tempStr2="";
	var allLength=0;
	while(str!=""){
		var s1=str.charAt(0);
		allLength+=getLength(s1);
		if(allLength>=max){
			tempStr1+="...";
			break;
		}
		tempStr1+=s1;
		if(str.length==1){
			break;
		}
		var s2=str.charAt(str.length-1);
		allLength+=getLength(s2);
		if(allLength>=max){
			tempStr1+="...";
			break;
		}
		tempStr2=s2+tempStr2;
		str=str.substring(1,str.length-1);
	}
	return tempStr1+tempStr2;
}
/**重新初始化网站动画*/
function baseReInitAnimation(){
	for(i=0;i<dateList.length;i++){
		$(dateList[i]).datepicker("option","showAnim",doAnimation?dateAnimation:null);
	}
	for(i=0;i<accordionList.length;i++){
		$(accordionList[i]).accordion("option","animated",doAnimation?accordionAnimation:null);
	}
	for(i=0;i<dialogList.length;i++){
		$(dialogList[i]).dialog("option","show",doAnimation?showDialogAnimation:null);
		$(dialogList[i]).dialog("option","hide",doAnimation?hideDialogAnimation:null);
	}
}
/**重新初始化网站按钮*/
function reInitStyleButton(){
	var styleButton=$(".styleButton");
	styleButton.hover(
		function(){
			$(this).removeClass("ui-state-default").removeClass("ui-state-active").addClass("ui-state-hover");
		},function(){
			$(this).removeClass("ui-state-hover").removeClass("ui-state-active").addClass("ui-state-default"); 
		}
	);
	styleButton.mousedown(function(){
		$(this).removeClass("ui-state-default").removeClass("ui-state-hover").addClass("ui-state-active"); 
	});
	styleButton.mouseup(function(){
		$(this).removeClass("ui-state-default").removeClass("ui-state-active").addClass("ui-state-hover"); 
	});
}
/**判断会员状态*/
function checkUserState(state){
	if(state=="unExist"){
		exitUserView();
		return "您的帐号不存在，或者已被管理员删除。";
	}else if(state=="unLogin"){
		exitUserView();
		return "可能由于您长时间未操作本页面，已自动退出登陆，请重新登陆。";
	}else if(state=="disable"){
		exitUserView();
		return "对不起，您的帐号已被封停！如有疑问请与管理员联系。";
	}else if(state=="unActivation"){
		return "对不起，您的帐号未激活！请前往注册邮箱激活帐号。如需重新发送注册邮件，请登陆个人中心。";
	}else{
		/**返回空代表会员状态正常*/
		return null;
	}
}
/**取地址栏参数*/
function getParameter(queryStringName){
	var returnValue="";
	var URLString=new String(document.location);
	URLString=URLString.toLowerCase();
	var serachLocation=-1;
	var queryStringLength=queryStringName.length; 
	do { 
		serachLocation=URLString.indexOf(queryStringName+"/="); 
		if (serachLocation!=-1) {
			if ((URLString.charAt(serachLocation-1)=='?') || (URLString.charAt(serachLocation-1)=='&')) {
				URLString=URLString.substr(serachLocation);
				break; 
			} URLString=URLString.substr(serachLocation+queryStringLength+1); 
		}  
	} while (serachLocation!=-1) 
	if (serachLocation!=-1) { 
		var seperatorLocation=URLString.indexOf("&"); 
		if (seperatorLocation==-1) { 
			returnValue=URLString.substr(queryStringLength+1); 
		} else { 
			returnValue=URLString.substring(queryStringLength+1,seperatorLocation); 
		}  
	} 
	return returnValue;
}
/**删除左右两端的空格*/
function trim(str){ 
    return str.replace(/(^\s*)|(\s*$)/g, "");
}
/**删除左边的空格*/
function ltrim(str){
    return str.replace(/(^\s*)/g,"");
}
/**删除右边的空格*/
function rtrim(str){
    return str.replace(/(\s*$)/g,"");
}
/**替换所有*/
function replaceAll(str,oldStr,newStr){
	while(str.indexOf(oldStr)!=-1){
		str=str.replace(oldStr,newStr);
	}
	return str;
}
/**判断HTML里是否有可见内容*/
function isHtmlNull(html){
	html=replaceAll(html.toLowerCase(),"&nbsp;", "");
	html=trim(replaceAll(html,"<br />", ""));
	html=trim(replaceAll(html,"<br/>", ""));
	html=trim(replaceAll(html,"<br>", ""));
	if(html==""){
		return true;
	}else{
		return false;
	}
}
/**获得验证码相关-----------------------------------*/
var b_checkCode;
var b_checkCodeKey;
var b_codeImg;
var b_codeWait;
var b_checkCodeDiv;
var b_checkCodeTip;
var b_checkForm;
var checkCodeValue="";
var checkCodeDate="";
var isLoadCode=false;
var isError=false;
/**设置验证码只能输入字母和数字*/
function initCheckCode(checkCode,checkCodeKey,codeImg,codeWait,checkCodeDiv,checkCodeTip,checkForm){
	b_checkCode=checkCode;
	b_checkCodeKey=checkCodeKey;
	b_codeImg=codeImg;
	b_codeWait=codeWait;
	b_checkCodeDiv=checkCodeDiv;
	b_checkCodeTip=checkCodeTip;
	b_checkForm=checkForm;
	b_checkCode.textCheck("lop");
	b_checkCode.focus(function (){
		if(checkCodeDate==""){
			getCheckCodeImg();
		}
		if(!isError){
			b_checkCodeTip.removeClass();
			b_checkCodeTip.addClass("onFocus");
			b_checkCodeTip.html("不区分大小写，如果看不清，点击图片换一张。");
		}
	});
	/**在验证码回车直接提交表单*/
	b_checkCode.keypress(function(e){
		if((e.keyCode ? e.keyCode : e.which)==13){
			b_checkForm.submit();
		}
	});
	b_checkCode.blur(function(){
		if(isError){
			return;
		}
		var str=$(this).val();
		b_checkCodeTip.removeClass();
		if(str.length<4){
			b_checkCodeTip.addClass("onError");
			b_checkCodeTip.html("必须输入4位验证码才能发帖！");
		}else if($.md5(str.toLowerCase())!=checkCodeValue) {
			b_checkCodeTip.addClass("onError");
			b_checkCodeTip.html("验证码输入错误！");
		}else{
			b_checkCodeTip.addClass("onCorrect");
			b_checkCodeTip.html("验证码输入正确。");
		}
	});
	b_checkCodeDiv.click(function(){
		getCheckCodeImg();
	})
	b_codeImg.error(function(){
		b_codeWait.hide();
		b_checkCodeTip.removeClass();
		b_checkCodeTip.addClass("onError");
		b_checkCodeTip.html("验证码获取失败，点击<a onclick='getCheckCodeImg()' class='bbs_fontColor'>重新获取</a>。");
		isError=true;
		isLoadCode=false;
		alert("验证码加载失败！");
	});
	b_codeImg.load(function(){
		if($(this).attr("src").indexOf("onError.gif")==-1){
			getCheckCode();
		}
	});
}
/**获得验证码图片*/
function getCheckCodeImg(){
	if(!isLoadCode){
		if(isError){
			b_checkCodeTip.removeClass();
			b_checkCodeTip.addClass("onFocus");
			b_checkCodeTip.html("不区分大小写，如果看不清，点击图片换一张。");
			isError=false;
		}
		isLoadCode=true;
		var timeNow = new Date().getTime(); 
		b_codeImg.attr("src","/checkCode/"+timeNow+"/"+checkCodeDate+".jpg");
		checkCodeDate=timeNow;
		b_codeWait.show();
		b_codeImg.hide();
	}
}
/**获得验证码的值*/
function getCheckCode(){
	$.ajax({"type":"POST","url":"/checkCode/"+checkCodeDate+".html","cache" :false,"data":null,"success":function(data,status){
		isLoadCode=false;
		b_codeWait.hide();
		if(data==null||data==""){
			b_checkCodeTip.removeClass();
			b_checkCodeTip.addClass("onError");
			b_checkCodeTip.html("验证码获取失败，点击<a onclick='getCheckCodeImg()' class='bbs_fontColor'>重新获取</a>。");
			isError=true;
			alert("验证码加载失败！");
		}else{
			b_codeImg.show();
			checkCodeValue=data;
			b_checkCodeTip.removeClass();
			b_checkCodeTip.addClass("onFocus");
			b_checkCodeTip.html("不区分大小写，如果看不清，点击图片换一张。");
			b_checkCodeKey.val(checkCodeDate);
		}
		},"error":function(){
			isLoadCode=false;
			b_codeWait.hide();
			b_checkCodeTip.removeClass();
			b_checkCodeTip.addClass("onError");
			b_checkCodeTip.html("验证码获取失败，点击<a onclick='getCheckCodeImg()' class='bbs_fontColor'>重新获取</a>。");
			isError=true;
			alert("连接服务器错误，验证码加载失败！");
		}
	});
}
/**编辑器相关*/
var bbsEditorCss="body,td,font{font:14px Tahoma,sans-serif,宋体;}" +
				 "a{text-decoration:none;color:#3E63B9;}a:hover{text-decoration:underline;}" +
				 "img{border:0px}";
/**延迟加载CSS和JS文件*/
lazyLoadJC=function(obj){
	var loadSuccessCnt=0;
	var head=document.getElementsByTagName("head")[0];
	doLoadJC=function(){
		if(obj.files.length>loadSuccessCnt){
			var file=obj.files[loadSuccessCnt];
			var nameExt=file.substring(file.lastIndexOf(".")+1).toLowerCase();
			if(nameExt==="js"){
				var script=document.createElement("script");
				script.src=file;
				script.type="text/javascript";
				 if (!/*@cc_on!@*/0){
					 script.onload=function(){
						this.onload=null;
						loadJCSuccess();
					 };
				 }else{
					 script.onreadystatechange=function(){
						if(!this.readyState||this.readyState==="loaded"||this.readyState==="complete"){
							this.onreadystatechange=null;
							loadJCSuccess();
						}
					 };
				 }
				script.onerror=obj.error;
				head.appendChild(script);
			}else if(nameExt==="css"){
				var css = document.createElement('link');
				css.href = file;
				css.rel = "stylesheet";
				css.type="text/css";
				css.onerror=obj.error;
				head.appendChild(css);
				listenCssLoad(css);
			}
		}
	}
	doLoadJC();
	/**加载完成,调用的方法*/
	loadJCSuccess=function(){
		loadSuccessCnt++;
		if(loadSuccessCnt===obj.files.length){
			obj.success();
		}else{
			doLoadJC();
		}
	}
	/**设置一个定时器判断是否加载成功*/
	function listenCssLoad(css){
		var sheet, cssRules; 
		if("sheet" in css){/**FF/CM/OP*/
	        sheet="sheet";
	        cssRules="cssRules"; 
		}else{/**IE*/ 
	        sheet="styleSheet";
	        cssRules="rules";
		}
		var startDate=new Date().getTime();
		var doListenCssLoad=setInterval(function(){
			/**设置超时30秒则视为加载失败*/
			if(new Date().getTime()-startDate>=30000){
				clearInterval(doListenCssLoad);
				obj.error();
			}
			try{
                if (css[sheet]&&css[sheet][cssRules].length){
					clearInterval(doListenCssLoad);
					loadJCSuccess();
                }
	        }catch(e){
	        }
		},20);
	}
}
/**判断字符串真实长度*/
function getLength(str) {
	var totallength=0;   
	for (var i=0;i<str.length;i++){
		var intCode=str.charCodeAt(i);
		if(intCode==77||intCode==87){
			totallength=totallength+1.5;/**W和M*/
		}else if(intCode==109||intCode==119){
			totallength=totallength+1.3;/**w和m*/
		}else if(intCode==105||intCode==108){
			totallength=totallength+0.7;/**i和l*/
		}else if (intCode>=0&&intCode<=128) {
			totallength=totallength+1; /**非中文单个字符长度加*/
		}else {
			totallength=totallength+1.9;/**中文字符长度则加*/
		}
	} 
	return totallength;
}
