var ReplyOnce=0; //在每个问题中是否每个人只能回答一次, 1只回答一,0可以回答多次

$(document).ready(function(){
	inputfocus();
})

function inputfocus(){
	//if ($.browser.msie){
	if (jQuery.browser.msie){	
		$("input[@type='text'], input[@type='password'], textarea").focus(function(){$(this).addClass("iefocus")}).blur(function(){$(this).removeClass("iefocus")});
	}
}

function getCookie(aFolder,aName){
	var sSearch=" "+aFolder+"=";
	var acookie=" "+window.document.cookie+";";
	if(acookie.length>0){
		var iOffset=acookie.indexOf(sSearch);
		if(iOffset!=-1){
			iOffset+=sSearch.length;
			var iEnd=acookie.indexOf(";",iOffset);
			if(iEnd==-1){iEnd=acookie.length;}
			acookie="&"+acookie.substring(iOffset,iEnd)+"&";
			sSearch="&"+aName+"=";
			iOffset=acookie.indexOf(sSearch);
			if(iOffset!=-1){
				iOffset+=sSearch.length;
				iEnd=acookie.indexOf("&",iOffset);
				if(iEnd==-1){iEnd=acookie.length;}
				var s=acookie.substring(iOffset,iEnd);
				if(IsNumeric(s))return s;
			}
		}
	}
	return null;
}


function getUserID(){
	return getCookie("oASK", "UID");
}

function IsLogined(){
  if(getUserID()){return true;}else{return false;}
}

function check_loginform(f){
if(f.name.value==""||f.name.value.length<=0){alert("请输入用户名");f.name.focus();return false;}
if(f.pwd.value==""||f.pwd.value.length<=0){alert("请输入密码");f.pwd.focus();return false;}
if(f.vcode){if(f.vcode.value==""||f.vcode.value.length<=0){alert("请输入验证码");f.vcode.focus();return false;}}
}

function ShowLogin_New(msg,js){
	var surl=weburl + "login.asp";
	if(js)surl=surl+"?js="+escape(js);
	if(msg){msg="用户登陆 ("+msg+")";}else{msg="用户登陆"}
	openWindow(surl,400,180,msg);
}

function ShowLogin(msg,js){
	if(msg){msg="用户登陆 ("+msg+")";}else{msg="用户登陆"}
	var surl="?TB_login=true&TB_vcode=0&height=130&width=320";
	if(js)surl=surl+"&js="+escape(js);
	TB_show(msg, surl, false);
	
}

function openWindow(_sUrl, _sWidth, _sHeight, _sTitle){
	if(!_sUrl)return false;
	if(!_sTitle)_sTitle="oASK系统提示";
	if(_sUrl.indexOf("?")>-1) {_sUrl=_sUrl+"&TB_iframe=true&height="+_sHeight+"&width="+_sWidth}else{_sUrl=_sUrl+"?TB_iframe=true&height="+_sHeight+"&width="+_sWidth}
	try{window.top.TB_show(_sTitle, _sUrl, false);}catch(e){TB_show(_sTitle, _sUrl, false);}
}

function openWindow_Self(_sUrl, _sWidth, _sHeight, _sTitle){
	if(!_sUrl)return false;
	if(!_sTitle)_sTitle="oASK系统提示";//
	if(_sUrl.indexOf("?")>-1) {_sUrl=_sUrl+"&TB_iframe=true&height="+_sHeight+"&width="+_sWidth}else{_sUrl=_sUrl+"?TB_iframe=true&height="+_sHeight+"&width="+_sWidth}
	TB_show(_sTitle, _sUrl, false);
}

function dlg(_sText, _sWidth, _sHeight, _sTitle){
	if(!_sText)return false;
	if(!_sTitle)_sTitle="oASK系统提示";
	var surl="#TB_message?height="+_sHeight+"&width="+_sWidth+"&msgtext="+escape(_sText);
	try{window.top.TB_show(_sTitle, surl, false);}catch(e){TB_show(_sTitle, surl, false);}
}

function closeWindow(){
	try{window.top.dialogBoxClose.click();}catch(e){}
}

function openWindow2(_sUrl, _sWidth, _sHeight, _sTitle){
	if(!getUserID()){
		ShowLogin("登录后您才能执行此操作!");
	}else{
		openWindow(_sUrl, _sWidth, _sHeight, _sTitle);
	}
	return false;
}

function openScript(url, width, height){
	window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=yes,status=yes' );
}

function openScript2(url, width, height){
	window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=no,menubar=no,status=no' );
}

function ReadSMS(id){
	openWindow2(weburl+"sms.asp?act=read&smsid="+id, 610, 450, "站内短信");
}

function EditSMS(id){
	openWindow2(weburl+"sms.asp?act=edit&smsid="+id, 610, 450, "站内短信");
}

function NewSMS(to){
	var u=weburl+"sms.asp?act=new";
	if(to)u=u+"&touser="+to;
	openWindow2(u, 610, 450, "站内短信");
}

function ShowPerson(id){//by UserID
	if(!getUserID()){
		ShowLogin("登录后您才能查看别人的资料!");
	}else{
		openScript(weburl+"showperson.asp?id="+id+"", 600, 400, "用户信息中心");
	}
}

function ShowPerson2(name){//by UserName
	if(!name)return false;
	if(!getUserID()){
		ShowLogin("登录后您才能查看别人的资料!");
	}else{
		openScript(weburl+"showperson.asp?name="+name+"", 600, 400, "用户信息中心");
	}
}

function ShowIP(IP){
	if(!getUserID()){
		ShowLogin("登录后您才能查看别人的资料!");
	}else{
		openWindow(weburl+"ip.asp?ip="+IP, 400,200, "用户最后登陆的IP地址");
	}
}

function ShowDealBtn(divid,replyerid){
	var UID = getUserID();
	if (jie==0&&UID==senderid && replyerid!=senderid) {
		show_hidden(divid,1);
	}else{
		show_hidden(divid,0);
	}
	return;
}

function ClickDeal(obj,qid,rid){
	if(!getUserID()){
		ShowLogin("登录后您才能选择最佳答案!");
	}else{
		if(confirm('确实要把这个回复选择为最佳答案吗?  ')){
			obj.href = weburl+"modify.asp?act=deal&qid="+qid+"&rid="+rid;
			return true;
		}else{return false;}
	}
}

function ShowAnswerBtn(){
	var UID = getUserID();
	if (UID == senderid || jie == 1) {
		show_hidden("AnswerBtn",0);
	}else{
		show_hidden("AnswerBtn",1);
	}
	return;
}

function ShowModifyReBtn(divid,replyerid){
	var UID = getUserID();
	if (UID == replyerid && jie != 1) {
		show_hidden(divid,1);
	}else{
		show_hidden(divid,0);
	}
	return;
}

function ShowLoginDiv(divid){
	var UID = getUserID();
	if (UID) {
		show_hidden(divid,0);
	}else{
		show_hidden(divid,1);
	}
	return;
}

//idname: 页面元素的ID
//v: 0隐藏，1显示
function show_hidden_new(idname, v)
{
	var oObj = document.getElementById(idname);
	if (!oObj){ return false;}
	if(v==0) {
		oObj.style.display="none";
		return true;
	}else{
		oObj.style.display="";
		return true;
	}
	return false;
}

function show_hidden(idname,v){
	var oObj=$("#"+idname);
	if(!oObj)return false;
	if(v==0){oObj.css({display:"none"});return true;}
	if(v==1){oObj.css({display:""});return true;}
	return false;
}

//更新记录后关闭子窗口并刷新父窗口的JS 
function RefreshParent() {
	if (window.top.dialogBoxClose) window.top.dialogBoxClose.click();
	window.top.location = window.top.location;
}

function IsNumeric(s)
{	
	if(s=="")return false;
	var r,re;
	re = /\d*/i; //\d表示数字,*表示匹配多个数字
	//re = /^\d*$/;
	r = s.match(re);
	return (r==s)?true:false;
}

function regInput(obj, reg, inputStr)
{
	var docSel= document.selection.createRange()
	if(docSel.parentElement().tagName != "INPUT") return false;
	oSel = docSel.duplicate();
	oSel.text = "";
	var srcRange= obj.createTextRange();
	oSel.setEndPoint("StartToStart", srcRange);
	var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length);
	return reg.test(str);
}

function ShowErr(msg, act, aurl){
	var re = /\n/g;
	document.write("<center>"+msg.replace(re,"<br>")+"</center>");
	if(act=="close"){
		try{window.parent.dialogBoxClose.click();}catch(e){}
		if(msg.length>0)alert(msg);
	}else if(act=="refresh"){
		try{window.parent.dialogBoxClose.click();}catch(e){}
		top.location.reload();
	}else if(act=="back"){
		if(msg.length>0)alert(msg);
		history.back();
	}else if(act=="goto" && aurl.length>0){
		if(msg.length>0)alert(msg);
		window.top.location=aurl;
	}else{
		if(msg.length>0)alert(msg);
	}
}

function check_replyform(aform){

	//桀骜不羁添加编辑器
	if(edittype==1)
	{
	  sdcData = aform.ScienceWordEditor.GetZipSDCFileBase64();   //转换为base64位码
	  aform.co.value = sdcData;
	}
	//桀骜不羁添加编辑器
	if(!aform.co.value)
		{alert("回答内容不能为空！"); return false; }
	else if(aform.co.value.length>40000)
		{alert("回答内容的长度不能超过40000字"); return false; }
	else
		return true;
}

function ShowIMG(imgsrc,maxw,maxh){
try{
	var img=new Image;
	img.src=imgsrc;
	var w=img.width;
	var h=img.height;
	img=null;
	var r=parseInt(w)/parseInt(h);
	if(!maxw)maxw=500;
	if(!maxh)maxh=800;
	if(w>maxw){w=maxw;h=maxw/r;}
	if(h>maxh){h=maxh;w=maxh*r;}
	if(w<1)w=100;if(h<1)h=100;
	document.write("<a href='"+imgsrc+"' target='_blank'><img width="+w+" height="+h+" src='"+imgsrc+"' /></a>");
}catch(e){document.write("<a href='"+imgsrc+"' target='_blank'><img src='"+imgsrc+"' /></a>");}
}

function resizeme(aimg,maxw,maxh){
try{
	var img=new Image;
	img.src=aimg.src;
	var w=img.width;
	var h=img.height;
	img=null;
	var r=parseInt(w)/parseInt(h);
	if(!maxw)maxw=500;
	if(!maxh)maxh=800;
	if(w>maxw){w=maxw;h=maxw/r;}
	if(h>maxh){h=maxh;w=maxh*r;}
	if(w<1)w=100;if(h<1)h=100;
	$(aimg).css("width",w);
	$(aimg).css("height",h);
}catch(e){}
}

function showit(id){$("#"+id).css({display:""});}
function hideit(id){$("#"+id).css({display:"none"});}
String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");}

function hideifblank(id){var s=$("#"+id).text();if(!s || s.trim()=="")hideit(id);}

function ShowEmot(p)
{
	var Emots='01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|';
	Emots=Emots.split("|");
	var ps=12;
	var pc;
	var ec=Emots.length-1;
	if(ec%ps==0)
	{
		pc=(ec)/ps
	}else{
		pc=Math.floor((ec)/ps)+1
	}
	p=parseInt(p);
	if (p<=pc){
	var istr;
	var s='&nbsp;';
	var ep=weburl+'img/emot/em';
	if (p!=1 && pc>1)
	{s+='<img style="cursor: pointer;" onClick="ShowEmot('+(p-1)+');" src="'+weburl+'img/'+'Previous.gif" width="14" height="14" title="上一页">&nbsp;';}
	for(i=(p-1)*ps;i<(p-1)*ps+ps;i++)
	{
		if (i==ec){break}
		if (i<9)
			{istr='em0'+(i+1)}
			else
			{istr='em'+(i+1)}
		s+='<img title="'+istr+'" style="cursor: pointer;" onClick=putEmot("'+istr+'"); src="'+ep+Emots[i]+'.gif">&nbsp;';
	}
	if (p!=pc)
	{s+='<img style="cursor: pointer;" onClick="ShowEmot('+(p+1)+');" src="'+weburl+'img/'+'Next.gif" width="14" height="14" title="下一页">&nbsp;';}
	s+='分页：<b>'+p+'</b>/<b>'+pc+'</b>，共<b>'+(ec)+'</b>个';
	s+="<select id=emotpage onchange=\"ShowEmot(this.value);\">";
	for (i=1; i<=pc;i++ )
	{
		s+="<option value=\""+i+"\">"+i;
	}
	s+="<\/select>";
	var o=document.getElementById("emot");
	o.innerHTML=s;
	document.getElementById('emotpage').options[p-1].selected=true;
	}
}

function putEmot(thenNo)
{
	var ToAdd = '['+thenNo+']';
	hd.co.value=hd.co.value+ToAdd;
}

function reset_vcd(){try{var obj=document.getElementById("oask_vcdimg");obj.src=obj.src;}catch(e){}}

function SearchBar(keyword){document.write("<form method='get' action='"+weburl+"search.asp' target='_top'><table><tr><td nowrap='nowrap' valign='middle' align='left' height='32'><img src='"+weburl+"img/search.gif' border='0' align='middle' /><input type='text' name='q' id='q' size='25' maxlength='255' value='"+keyword+"' /> <input onclick=\"this.form.action='"+weburl+"search.asp';\" type='Submit' class='btn1' value='站内搜索' /> <input onclick=\"this.form.action='"+weburl+"ask.asp';\" type='Submit' class='btn1' value='我要提问' /></td></tr></table></form>");}


function AskTools(){
	var s;
	s="<div id='AskTools'>";
	if(getUserID()==senderid){
		s=s+"<a class='btn_5' style='width:101px;' href='#' onClick=\"return openWindow2('"+weburl+"attach/up.asp?qid="+qid+"&rid=0','550','350','问题附件')\" title='上传附件文档、屏幕截图或演示动画，将会使问题或解答更清晰易懂'>上传/更换附件</a>&nbsp;";
		s=s+"<a class='btn_4' style='width:72px;' href='#' onClick=\"return openWindow2('"+weburl+"modify.asp?act=bu&qid="+qid+"',500,220,'问题补充')\" title='可以对您的提问补充细节，以得到更准确的答案'>问题补充</a>&nbsp;";
		s=s+"<a class='btn_4' style='width:72px;' href='#' onClick=\"return openWindow2('"+weburl+"modify.asp?act=tg&qid="+qid+"',400,160,'提高悬赏')\" title='提高悬赏分，以提高问题的关注度'>提高悬赏</a>&nbsp;";
		s=s+"<a class='btn_5' style='width:101px;' href='#' onClick=\"return openWindow2('"+weburl+"modify.asp?act=wu&qid="+qid+"',440,140,'无满意答案')\" title='没有满意的回答，还可直接结束提问，关闭问题'>无满意答案</a>";
	}else{
		s=s+"<a class='btn_4' style='width:72px;' href='#ireply'>我来回答</a>";
	}
	s=s+"</div>";
	document.write(s);
}


function AdminTools(cid){
	if(!cid)return;
	if(IsLogined()==false)return;
	try{if(!MasterC)return;}catch(e){return;}
	if(MasterC.indexOf(","+cid+",")>-1){
		document.write("<div id='AdminTools'><a class='btn_5' style='width:101px; float:right' href='#' onClick=\"this.href='"+weburl+"answerit.asp?qid="+qid+"'\">管理此问题</a></div>");
	}
}
function AnswerTools(rid, ruid){
	if(getUserID()==ruid){
		var s;
		s="<div id='AnswerTools'>";
		s=s+"<a class='btn_4' style='width:72px;' href='#' onClick=\"return openWindow2('"+weburl+"modify.asp?act=mr&qid="+qid+"&rid="+rid+"', '500', '350', '修改答复')\">修改答复</a>&nbsp;";
		s=s+"<a class='btn_5' style='width:101px;' href='#' onClick=\"return openWindow2('"+weburl+"attach/up.asp?qid="+qid+"&rid="+rid+"','550','350','回答附件')\" title='上传附件文档、屏幕截图或演示动画，将会使您的解答更清晰易懂'>上传/更换附件</a>";
		s=s+"</div>";
		document.write(s);
	}
}

function DealTools(rid, ruid){
	var s;
	if(getUserID()==senderid&&senderid!=ruid){
		document.write("<a href='#' class='btn_4' style='width:72px;' id='deal' onClick='return ClickDeal(this,"+qid+","+rid+")'>采纳</a>");
	}
}

function CanReply(){
	var v=1;
	try{
		if(pubr!=1){
			if(!myname){v=0;}else{
				if(master.indexOf(","+myname+",")<0){v=0;}
			}
		}
	}catch(e){}
	show_hidden("ireply",v);
}

function ShowIReplyDiv(){
	var v=1;
	try{if(pubr==1 || isMaster==1){v=1;}else{v=0;}}catch(e){}
	if(ReplyOnce==1){try{var uid=getUserID();if(uid){if(rus.indexOf(","+uid+",")>-1)v=0;}}catch(e){}}
	show_hidden("ireply",v);
}

function Ping(atype,rid){
	if(!getUserID()){
		ShowLogin("登录后您才能做出评价!");
	}else{
		var s;
		if(atype==1){s='做出好评';}else{s='做出坏评';}
		openWindow2(weburl+"modify.asp?act=pj&type="+atype+"&qid="+qid+"&rid="+rid, '400', '150', s);
	}
}

function AddPinglun(divid,ping,isSender){
	try{
		var n;
		if(ping){
			if(isSender==1){
				$("#pinglun").html("提问人的评论："+ping+"<hr class='hr_p'>"+$("#pinglun").html());
				return;
			}else{
				$("#pinglun").html($("#pinglun").html()+ping+"<hr class='hr_p'>");
			}
		}
		n=$("#"+divid).text().valueOf();
		n++;
		$("#"+divid).text(n.toString());
	}catch(e){}
}


//桀骜不羁新增函数
function changetype()
{
  if(edittype==0)
  {
      document.EditTypes.EditModes.value="1";
  }
  else
  {
	  document.EditTypes.EditModes.value="0";
  }
  EditTypes.submit();
}


//桀骜不羁新增函数