document.write('<script type="text/javascript" src="../dwr/interface/Friend.js"></script>');
document.write('<script type="text/javascript" src="../dwr/interface/Mail.js"></script>');
document.write('<script type="text/javascript" src="../dwr/interface/Item.js"></script>');
document.write('<script type="text/javascript" src="../dwr/interface/Account.js"></script>');
document.write('<script type="text/javascript" src="../dwr/interface/Subject.js"></script>');
document.write('<script type="text/javascript" src="../dwr/engine.js"></script>');
document.write('<script type="text/javascript" src="../dwr/util.js"></script>');
accnum=0;
ussid="";
function jiangquan(tt){
	//document.getElementById("job1").src="item.jsp?id="+tt;
	alert("Not Open");
}
function jifen(tt){
	alert("Not Open");
}
function setting(){
	var id=QueryString("id");
	document.getElementById("job1").src="setting.jsp?id="+id;
}
function friend(){
	var id=QueryString("id");
	document.getElementById("job1").src="friend.jsp?id="+id;
}
function QueryString(qs)
{
      var s = location.href;
      s = s.replace("?","?&").split("&");
      var re = "";
      for(i=1;i<s.length;i++)
      if(s[i].indexOf(qs+"=")==0)
      re = s[i].replace(qs+"=","");
      return re;
}
function deleteFirend(id){
	if(confirm("Are you sure to delete?")){
		Friend.deleteFriend(id,delCallBack);
	}
}
function delCallBack(tt){
	if(tt){
			alert("Success");
			id=QueryString("id");
			window.location="friend.jsp?id="+id;
		}else{
			alert("Error.");
		}
}
function deleteMiraFriend(id){
	if(confirm("Are you sure to delete?")){
		Friend.deleteFriend(id,function(tt){
			if(tt){
				alert("Success");
				id=QueryString("userid");
				window.location="mypage?type=2&userid="+id;
			}else{
				alert("Error.");
			}
		});
	}
}
function MyPage(){
	var id=QueryString("id");
	document.getElementById("job1").src="user1.jsp?id="+id;
}
function appendFriend(userid){
	name=document.getElementById("txtName").value;
	if(name!=""){
		Friend.checkFirendName(name,userid,appFCallBack);
	}else{
		alert("Name can't be blank.");
	}
}
function appendFriendfromShow(name,id){
	if(name!="" && id!=""){
		ussid=id;
		Friend.checkFirendName(name,id,appFFShowBack);
	}else{
		alert("Login first.");
	}
}
function appFFShowBack(bool){
	if(bool!="true"){
		if(bool=="name"){
			alert("The name does not exist.");
			return;
		}else if(bool=="in"){
			alert("The user is already in your friend list.");
			return;
		}else if(bool=="same"){
			alert("Can not add yourself into friend list.");
		}else{
			alert("Error.");
		}
	}else{
		alert("Success!");
		window.location="user.jsp?id="+ussid+"&pp=3";
	}
}
function appFCallBack(bool){
	if(bool!="true"){
		if(bool=="name"){
			alert("The account does not exist.");
			return;
		}else if(bool=="in"){
			alert("The user is already in your friend list.");
			return;
		}else if(bool=="same"){
			alert("Can not add yourself into friend list.");
		}else{
			alert("Error.");
		}
	}else{
		alert("Success!");
		id=QueryString("id");
		window.location="friend.jsp?id="+id;
	}
}

function jieshou(tt){
	id=QueryString("id");
	Mail.updateJieShou(id,tt,jieshouBack);
}
function jieshouBack(tt){
	if(tt){
		alert("Success.");
		window.location.reload();
	}else{
		alert("Error.");
	}
}

function shoAcc(){
	//mask.style.visibility='visible';
	document.getElementById("mask").style.visibility='visible';
	document.getElementById("selFriend").style.display="none";
}
function cancelAcc(){
	document.getElementById("mask").style.visibility='hidden';
	document.getElementById("selFriend").style.display="";
}
function checkAccNum(vv,num,name,id,itemid){
	inputvalue=document.getElementById("addI"+itemid).value;
	if(parseInt(num)<parseInt(inputvalue)){
		alert("You don't have as much item as inputted.");
		return;
	}
	if(inputvalue==""){
		return;
	}
	if(accnum>2){
		alert("Maximum 3 Attachments.");
		document.getElementById("mask").style.visibility='hidden';
		document.getElementById("selFriend").style.display="";
		return;
	}
	if(document.getElementById("showAcc").innerHTML!=""){
		document.getElementById("showAcc").innerHTML=document.getElementById("showAcc").innerHTML+"   "+"["+name+" : "+inputvalue+"]";
		document.getElementById("accID").value=document.getElementById("accID").value+"|"+"0 I "+id+" "+inputvalue;
	}else{
		document.getElementById("showAcc").innerHTML="["+name+" : "+inputvalue+"]";
		document.getElementById("accID").value="0 I "+id+" "+inputvalue;
	}
	vv.style.visibility="hidden";
	document.getElementById("mask").style.visibility='hidden';
	document.getElementById("selFriend").style.display="";
	accnum++;
}
function addGold(gg){
	gold=document.getElementById("txtGold").value;
	if(gg<gold){
		alert("You don't have as much gold as inputted.");
		document.getElementById("txtGold").value="";
		return;
	}
	if(gold!=""){
		if(document.getElementById("showAcc").innerHTML!=""){
		document.getElementById("showAcc").innerHTML=document.getElementById("showAcc").innerHTML+"  [Gold : "+gold+"]";
		document.getElementById("accID").value=document.getElementById("accID").value+"|"+"0 G "+gold;
	}else{
		document.getElementById("showAcc").innerHTML="[Gold : "+gold+"]";
		document.getElementById("accID").value="0 G "+gold;
	}
	}else{
		alert("Gold can't be blank.");
	}
	document.getElementById("btnGold").style.visibility="hidden";
	document.getElementById("mask").style.visibility='hidden';
	document.getElementById("selFriend").style.display="";
}
function sendMail(){
	window.onbeforeunload=null;
	if(document.getElementById("txtTitle").value==""){
		alert("Subject can't be blank.");
		return;
	}
	if(document.getElementById("txtContent").value==""){
		alert("Content can't be blank.");
		return;
	}
	
	if(document.getElementById("txtName").value==""){
		alert("Name can't be blank.");
		return;
	}
	var context=document.getElementById("txtContent").value;
	if(context.length>1000 || context.length<4){
		alert("Content length should be between 5 to 1000 characters.");
		return;
	}
	ff=document.getElementById("form1");
	ff.submit();
}
function changeName(){
	document.getElementById("txtName").value=document.getElementById("selFriend").value;
}
function delsendMail(id){
	if(confirm("Are you sure to delete?")){
		Mail.delSendMail(id,delSendBack);
	}
}
function delSendBack(tt){
	if(tt){
		window.location.reload();
	}else{
		alert("Error.");
	}
}
function delMial(id){
	if(confirm("Are you sure to delete?")){
		Mail.delMail(id,delSendBack);
	}
}

function delMail(id, returnUrl){
	if(confirm("Are you sure to delete?")){
		Mail.delMail(id,delSendBack);
		
		location.replace(returnUrl);
	}
}

function clearSendMessage(){
	if(confirm("Are you sure to clear all the text?")){
		document.getElementById("txtTitle").value='';
		document.getElementById("txtContent").value="";
		document.getElementById("txtName").value="";
		document.getElementById("selFriend").options[0].selected=true;
	}
}
function delAttach(){
	if(confirm("Are you sure to delete all the attachment?")){
		document.getElementById("accID").value="";
		document.getElementById("showAcc").innerHTML="";
	}
}
function deleteItem(id){
	if(confirm("Are you sure to delete?")){
		Item.deleteItem(id,delSendBack);
	}
}
function upBack(tt){
	if(tt){
		parent.location.reload();
	}else{
		alert("Error.");
	}
}
function upHead(id){
	pic=document.getElementById("head").src;
	realpic=pic.substr(pic.indexOf("images"),pic.length);
	if(id!="" && realpic!=""){
		Account.updatePhoto(id,realpic,upBack);
	}
}
function upBanner(id){
	pic=document.getElementById("banner").src;
	realpic=pic.substr(pic.indexOf("images"),pic.length);
	if(id!="" && realpic!=""){
		Account.updateBanner(id,realpic,upBack);
	}
}
function reportMessag(id,messid){
	if(confirm("Are you sure to report?")){
		Mail.ReportMail(id,messid,reportBack);
	}
}
function reportBack(bool){
	if(bool){
		if (window.showModalDialog!=null)//IE
		{
			alert("Success");
			window.close();//firefox No zhichi
		}
		else
		{
			alert("Success");
			top.close();//IE and FireFox OK
		}
	}else{
		alert("Error.");
	}
}
function flashImg(){
	var timenow = new Date().getTime();
	document.getElementById("Vcode").src="../verifyCode.jsp?d="+timenow;
}
function getServer(vv){
	var first = document.getElementById("selServer");
	if(vv=="Talisman Online"){
		first.options.length=1;
		var option = new Option("Light in Darkness","Light in Darkness"); 
		first.options.add(option); 
		var option = new Option("Sky around Water","Sky around Water"); 
		first.options.add(option); 
		var option = new Option("Earth and Seas","Earth and Seas"); 
		first.options.add(option); 
		var option = new Option("Sun and Moon","Sun and Moon"); 
		first.options.add(option); 
		var option = new Option("All Stars","All Stars"); 
		first.options.add(option);
		var option = new Option("Giant Tree","Giant Tree"); 
		first.options.add(option);
	}else if(vv=="Project of Planets"){
		first.options.length=1;
		var option = new Option("Atom Storm","Atom Storm"); 
		first.options.add(option); 
	}else{
		 first.options.length=1;
	}
}
function getGame(){
	var first = document.getElementById("selGame");  
	var option = new Option("Talisman Online","Talisman Online"); 
	first.options.add(option); 
	var option1 = new Option("Project of Planets","Project of Planets"); 
	first.options.add(option1); 
}
function showReport(id,messid){
	if (window.showModalDialog!=null)//IE
   	{
		window.showModalDialog("../report.jsp?id="+id+"&messid="+messid,"","dialogWidth:370px;dialogHeight:250px;status:no;help:no;scrolling=no;scrollbars=no");
		return;
   }
   else
   {
		this.returnAction=function(strResult){
		window.open("../report.jsp?id="+id+"&messid="+messid,"","width=370,height=250,menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes");
		return;
		}
	}
}
function chargenHead(){
	vv=document.getElementById("fileHead").value;
	Account.judgeWidthHeight(vv,140,150,function(callback){
		if(callback){
			//document.getElementById("form1").submit(); 
		}else{
			alert("Picture size is too big.  It should be 140(w)*150(h)."); 
            document.getElementById("form1").reset(); 
            return; 
		}
	});
}
function getactivepoint(id,comlevel){
if(id!="" && comlevel!=0){
	Account.checkActivePoint(id,comlevel,function(back){
		if(back>0){
			ff=back/10;
			document.getElementById("txtPP").value=ff;
			document.getElementById("txtPoint").value=ff*10;
		}
	});
}
}

//²»½ÓÊÕPM
function updatePM(subjectid){
	if(confirm("Are you sure not to receive system mail?")){
		Subject.updatePM(subjectid,function(bb){
			if(bb){
				alert("Setting succeeded!  You won't get system pm after this thread is replied by others.");
			}
		});
	}
}
