﻿function CheckAll(form)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if (e.name != 'chkall')
			e.checked = form.chkall.checked;
	}
}

var bgColor="";
function nudge(objId,i)
{
	return false;
	var obj=document.getElementById(objId);
	if (i<-1)
	{
		obj.bgColor="";
		return;
	}
	if (obj.bgColor=="")
	{
		if (bgColor=="")
			obj.bgColor="#FFCCCC";
		else
			obj.bgColor=bgColor;
	}	
	else
	{
		bgColor=obj.bgColor;
		obj.bgColor="";
	}
	if (--i>0 || obj.bgColor=="")
		setTimeout("nudge(\""+objId+"\","+i+")",500);
}

function GoSearch (kwd,fld)
{
	if (kwd=="站内搜索" || kwd=="") 
		window.alert ("请输入关键词！");
	else if (fld=="s1" || fld=="s2")
		window.location.href='/Search/?skeywords='+encodeURIComponent(kwd);
	else
		window.location.href='/Dict/?Act=LookUp&Word='+encodeURIComponent(kwd);
}

var BMLID=0,BMLPIC=-1,BMDelay;

function BMShow(obj,uid,pic)
{
	clearTimeout(BMDelay);
	var bm=document.getElementById("BoMenu");
	if (bm==null || bm==obj)
		return;
	if (uid!=BMLID || pic!=BMLPIC)
	{
		bm.innerHTML="";
		BMLID=uid;
		loadJs("/MyAccount/MemInf.asp?uid="+uid+"&pic="+pic);
		if (pic!=BMLPIC && pic==0)
			bm.style.backgroundImage="url('/Common/Images/BMBG_LT.PNG')";
		BMLPIC=pic;
	}
	if (pic==1)
	{
		var posl=getAbsLeft(obj)+obj.offsetWidth-getAbsLeft(document.getElementById("Banner"));
		var scrtop=document.documentElement.scrollTop;
		if (scrtop==0 && document.body.scrollTop>0)
			scrtop=document.body.scrollTop;
		var post=getAbsTop(obj)-scrtop-220;
		if (posl<=700 && post>=0)
		{
			bm.style.left=getAbsLeft(obj)+obj.offsetWidth+"px";
			bm.style.top=getAbsTop(obj)-220+"px";
			bm.className="";
			bm.style.backgroundImage="url('/Common/Images/BMBG_Pic_RT.PNG')";
		}
		else if (posl>700 && post>=0)
		{
			bm.style.left=getAbsLeft(obj)-192+"px";
			bm.style.top=getAbsTop(obj)-220+"px";
			bm.className="";
			bm.style.backgroundImage="url('/Common/Images/BMBG_Pic_LT.PNG')";
		}
		else if (posl<=700 && post<0)
		{
			bm.style.left=getAbsLeft(obj)+obj.offsetWidth+"px";
			bm.style.top=getAbsTop(obj)+10+"px"
			bm.className="T";
			bm.style.backgroundImage="url('/Common/Images/BMBG_Pic_RB.PNG')";
		}
		else
		{
			bm.style.left=getAbsLeft(obj)-192+"px";
			bm.style.top=getAbsTop(obj)+10+"px";
			bm.className="T";
			bm.style.backgroundImage="url('/Common/Images/BMBG_Pic_LB.PNG')";
		}
	}
	else
	{
		bm.style.top=getAbsTop(obj)-100+"px";
		bm.style.left=getAbsLeft(obj)-192+"px";
		bm.className="";
	}
	bm.style.display='';
}

function BMHide()
{
	var bm=document.getElementById("BoMenu");
	if (bm!=null)
		bm.style.display='none';
}

function BMHideDelay()
{
	BMDelay=setTimeout("BMHide()",1000);
}

function LMMV(s,itv,index){
	return;
}

function Mv_Ctrl(s,img)
{
	return;
}


function LMMO(img,act)
{
	return;
}

function SendSMsg(Msg,RID,UID,obj)
{
	var SMUI=document.getElementById("SendSMsg");
	var posx=getAbsLeft(obj),posy=getAbsTop(obj);
	var mainx=getAbsLeft(document.getElementById("Banner"));
	if (posx-320-obj.offsetWidth>mainx)
		SMUI.style.left=posx-320+"px";
	else
		SMUI.style.left=posx+obj.offsetWidth+"px";
	SMUI.style.top=posy+"px";
	document.getElementById("formsendmsg").Uid.value=UID;
	document.getElementById("formsendmsg").ID.value=RID;
	document.getElementById("formsendmsg").Txt.value=Msg;
	SMUI.style.display="";
}

function check_send() {
	if (document.getElementById("formsendmsg")==null)
		return;
	if (document.getElementById("formsendmsg").Uid.value=="") {
		window.alert("请填写收件人！");
		nudge("SM_Rec",4);
		return false;
	}
	nudge("SM_Rec",-2);
	if (document.getElementById("formsendmsg").Txt.value=="") {
		window.alert("请写消息内容！");
		nudge("SM_Body",4);
		return false;
	}
	nudge("SM_Body",-2);
	document.getElementById("formsendmsg").Sub.disabled=1;
	return true;
}

function mMenu()
{
	mItems=document.getElementById("mMItems");
	for (i=0; i<mItems.childNodes.length; i++)
	{
		mItem=mItems.childNodes[i];
		mItem.onmouseover=function() {this.className+="MO";}
		mItem.onmouseout=function() {this.className="";}
	}
}

function mButton()
{
	mItems=document.getElementById("sButton");
	mItems.onmouseover=function() {this.className+="MO";}
	mItems.onmouseout=function() {this.className="";}
	mItems=document.getElementById("sPlaces");
	for (i=0; i<mItems.childNodes.length; i++)	
	{
		mItem=mItems.childNodes[i];
		mItem.onclick=function() {GoSearch(document.getElementById("Sform").Skeywords.value,this.id);}
	}

}

function getAbsLeft( ob )
{
	if(!ob)
		return null;
	var mendingOb = ob;
	var mendingLeft = mendingOb .offsetLeft;
	while (mendingOb != null && mendingOb .offsetParent != null && mendingOb .offsetParent.tagName != "BODY")
	{
		mendingLeft += mendingOb .offsetParent.offsetLeft;
		mendingOb = mendingOb .offsetParent;
	}
	return mendingLeft ;
}

function getAbsTop( ob )
{
	if(!ob)
		return null;
	var mendingOb = ob;
	var mendingTop = mendingOb .offsetTop;
	while (mendingOb != null && mendingOb .offsetParent != null && mendingOb .offsetParent.tagName != "BODY")
	{
		mendingTop += mendingOb .offsetParent.offsetTop;
		mendingOb = mendingOb .offsetParent;
	}
	return mendingTop ;
}

function loadJs(file)
{
	var scriptTag = document.getElementById("loadScript");
	var head = document.getElementsByTagName('head').item(0);
	if(scriptTag)
		head.removeChild(scriptTag);
	script = document.createElement("script");
	script.src = ""+file;
	script.type = "text/javascript";
	script.id = "loadScript";
	head.appendChild(script);
}

var maxEdit=-1;
var qEditBackup,qEditOprBackup;
function qEdit(c,id)
{
	var AnsField=document.getElementById("Ans"+c);
	if (AnsField==null)
		return;
	var AnsOpr=document.getElementById("AnsOpr"+c);
	if (AnsOpr==null)
		return;
	qECancel();
	var txt;
	txt=httpreq("/QnA/Edit.asp?action=req&id="+id,"GET","");
/*
	if (AnsField.innerText==null)
		txt="　　"+AnsField.textContent.replace(/　　/g,"\n");
	else
		txt=AnsField.innerText;
	//window.alert(txt.replace("  ",""));
	txt=txt.replace("　　\n","");
	txt=txt.replace(/　　/g,"");
	txt=txt.replace("（内容为空）","");
	txt=txt.replace(/\ \[CR\]/g,"");
*/
	qEditBackup=AnsField.innerHTML;
	qEditOprBackup=AnsOpr.innerHTML;
	AnsField.innerHTML="<form id=\"formedit"+c+"\" method=\"post\" action=\"Edit.asp?ID="+id+"\"><textarea name=\"Txt\" rows=\"8\" class=\"full90\">"+txt+"</textarea></form>";
	AnsOpr.innerHTML="<a href=\"javascript:qEditSave("+c+");\"><span class=\"Expired\">保存更改</span></a>　<a href=\"javascript:qECancel();\"><span class=\"Expired\">取消</span></a></b>";
	if (c>maxEdit)
		maxEdit=c;

}

function qECancel()
{
	for (var i=0;i<=maxEdit;i++)
		if (document.getElementById("formedit"+i)!=null)
		{
			document.getElementById("Ans"+i).innerHTML=qEditBackup;
			document.getElementById("AnsOpr"+i).innerHTML=qEditOprBackup;
		}
	maxEdit=-1;	
}

function qEditSave(id)
{
	var AnsForm=document.getElementById("formedit"+id);
	if (AnsForm==null)
		return;
	if (window.confirm("确认要保存更改吗？"))
		AnsForm.submit();
}
function zht()
{	
	if (window.location.href.substr(6,5)=="/zht.")
		window.location.href=window.location.href.replace("/zht.","/www.");
	else if (window.location.href.substr(6,5)=="/www.")
		window.location.href=window.location.href.replace("/www.","/zht.");
	else if (window.location.href.substr(6,17)=="/hk.boliance.net/")
		window.location.href=window.location.href.replace("/hk.boliance.net/","/zht.studyinhk.net/");
	else	
		return true;
	return false;
}

var favon=0,favavg=0;
function add2Fav(id,r,t) {
	loadJs("/MyAccount/Add2Fav.asp?id="+id+"&t="+t+"&r="+r);
}
function setFav_5(id,r) {
	for (var i=1;i<=r;i++)
		if (i<=favavg && r>favavg)
			document.getElementById("fav"+id+"_"+i).src="/Common/Images/fav_rate.gif";
		else
			document.getElementById("fav"+id+"_"+i).src="/Common/Images/fav_add.gif";
	for (var i=5;i>r;i--)
		if (i>favavg)
			document.getElementById("fav"+id+"_"+i).src="/Common/Images/fav_non.gif";
		else
			document.getElementById("fav"+id+"_"+i).src="/Common/Images/fav_rate.gif";
	var myfav=""
	if (r==0)
		myfav="请点击星星进行评级";
	else
		myfav="您的评级："+r+" 颗星";
	if (favon==0)
		setFavMsg(myfav+"，平均评级："+favavg+" 颗星。");
}
function setFav(id,r) {
	if (r>0)
		document.getElementById("fav"+id+"_3").src="/Common/Images/fav_add.gif";
	else
		document.getElementById("fav"+id+"_3").src="/Common/Images/fav_non.gif";
}
function setFavMsg(msg) {
	if (document.getElementById("favMsg")!=null)
		document.getElementById("favMsg").innerHTML=msg;
}
function setAvg(id,r) {
	if (favavg<0)
		return;
	favavg=r;
	//setFav(id,0);
}
function favIn (id,r) {
	setFav(id,r);
	/*switch(r)
	{
	case 1: setFavMsg("基本没帮助，就给一颗星。"); break;
	case 2: setFavMsg("帮助不很大，只给两颗星。"); break;
	case 3: setFavMsg("有一些帮助，能给三颗星。"); break;
	case 4: setFavMsg("比较有帮助，我给四颗星。"); break;
	case 5: setFavMsg("非常有帮助，得给五颗星。"); break;
	}*/
	favon++;
}
function favOut (id,r) {
	favon--;
	if (favon==0)
		setFav(id,document.getElementById("fav"+id).value);
}
var curTab=new Array();
function Tab(a,b) {
	if (curTab[a]==null)
		curTab[a]=1;
	document.getElementById("th"+a+"_"+curTab[a]).className="";
	document.getElementById("t"+a+"_"+curTab[a]).className="TabHid";
	document.getElementById("th"+a+"_"+b).className="Tab";
	document.getElementById("t"+a+"_"+b).className="Tab";
	curTab[a]=b;
}
function setFont(s) {
	if (s==1)
	{
		if (document.getElementById("Article")!=null)
			document.getElementById("Article").id="article_middle";
		else if (document.getElementById("article_large")!=null)
			document.getElementById("article_large").id="article_middle";
	}
	else if (s==2)
	{
		if (document.getElementById("Article")!=null)
			document.getElementById("Article").id="article_large";
		else if (document.getElementById("article_middle")!=null)
			document.getElementById("article_middle").id="article_large";
	}
	else
	{
		if (document.getElementById("article_middle")!=null)
			document.getElementById("article_middle").id="Article";
		else if (document.getElementById("article_large")!=null)
			document.getElementById("article_large").id="Article";
	}
}
function playCaptcha(lang) {
	document.getElementById("playAudio").innerHTML = "<object type=\"application/x-shockwave-flash\" data=\"/ChkCode/play.swf?f=/ChkCode/voice.asp&r="+lang+"\" width=\"0\" height=\"0\"><param name=\"movie\" value=\"/ChkCode/play.swf?f=/ChkCode/voice.asp&r="+lang+"\" /></object>";

}
function DictLookup(obj) {
	if (obj.innerHTML!="")
		window.open("/Dict/?Act=LookUp&Word="+obj.innerHTML);
}

function Redirect(turl)
{
	if (turl.toLowerCase().indexOf(".studyinhk.net/",0)>0 && turl.toLowerCase().indexOf(".studyinhk.net/",0)<12 || turl.toLowerCase().indexOf(".boliance.net/",0)>0 && turl.toLowerCase().indexOf(".boliance.net/",0)<12)
		return true;
	else
	{
		window.open(turl);//window.location.href="/Home/Redirect.asp?ref="+encodeURIComponent(document.location)+"&url="+encodeURIComponent(turl);
		return false;
	}
		
}
function share(url)
{
	window.open(url);
}