﻿/*
Version:	Joekoe CMS 5.0 for Stage
*/

if(dcs.popup)dcs.popup.init();
$f.MSX="";

$c.setValue("url.login",			$c.getURL("passport")+"login.asp");
$c.setValue("url.logins",			$c.v("url.login")+"?_portal=dtml&_format=map");
$c.setValue("url.user",				$c.getURL("account")+"user.asp");
$c.setValue("url.put",				$c.getURL("account")+"put.asp");
$c.setValue("url.bookmark",			$c.getURL("account")+"bookmark.asp");

$c.setValue("url.comment",			$c.getURL("common")+"comment.asp");
$c.setValue("url.commend",			$c.getURL("common")+"commend.asp");
$c.setValue("url.report",			$c.getURL("common")+"report.asp");
$c.setValue("url.proxy",			$c.getURL("common")+"urlproxy.asp");
$c.setValue("url.xml.dtml",			$c.getURL("common")+"dtml.asp");
$c.setValue("url.xml.agent",			$c.getURL("xml")+"agent.asp");
$c.setValue("url.xml.channel",			$c.getURL("xml")+"channel.asp");

$c.setValue("url.vform.img",			$c.getURL("themes")+"images/common/icon/");
$c.setValue("url.vcode.img",			$c.getURL("common")+"verifycode.asp?channel={$channel}");
$c.setValue("url.vcode.xmls",			$c.getURL("common")+"verifycode.asp?channel={$channel}&portal=dtml&f=map");
$c.setValue("url.tag.hlink",			$c.getURL("common")+"search.asp?channel={$channel}&keyword={$keys.encode}");


$v.unit={};
$v.user={
	"online":"当前在线",
	"offline":"离线了",
	"alert.username":"请输入您的 用户名称 ！",
	"alert.password":"请输入您的 登陆密码 ！",
	"hlink.no":"<font class=\"gray\">------</font>",
	"hlink.no.moderator":"<font class=\"gray\">暂无</font>",
	"":""
};
$v.UserIcons={IM:"email,qq,msn,icq,yahoo,taobao",ATT:"url,home,emoney,money"};


//########################################
//########################################
var app={};
var page=appPage={};

page.doInitHeader=function(t){
	var oBoxBody=$("HeaderBoxBodyContent");
	var oBoxBodyRefill=$("Header-BoxBody-Refill");
	if(oBoxBody && oBoxBodyRefill){
		oBoxBody.html(oBoxBodyRefill.html());
		oBoxBodyRefill.hide();
	}
	else{
		if(oBoxBody) oBoxBody.html("");
	}
	var chn=$b.getURL("channel"),page=$b.getURL("page");
	if(!chn) chn="index";
	if(!$("Header-Menu-"+chn+"-"+page)) page="";
	$o("Header-Menu-"+chn+(page?"-"+page:"")).cssClass("pop");
	if(chn=="support") $o("Header-Menu-"+"about"+(page?"-"+page:"")).cssClass("pop");
}


//########################################
//########################################
var common=appCommon={};

Object.extend(common,{
	toUploadPic:function(s,sWid,sHei,m,t){
		var re="";
		if(!s) s="no_pic.gif";
		var _url=$url.isValid(s)?s:$c.getURL("upload")+s;
		var tmpSize="";
		if(!isn(sWid)&&!isInt(sWid)) sWid=120;
		if(!isn(sHei)&&!isInt(sHei)) sHei=90;
		if(!isn(sWid)) { sWid=sWid*m; tmpSize+=" width=\""+sWid+"\""; }
		if(!isn(sHei)) { sHei=sHei*m; tmpSize+=" height=\""+sHei+"\""; }
		switch(t){
			case 0:		re="<img class=\"pic\" src=\""+_url+"\" "+tmpSize+" />"; break;	// title=\"点击放大\"
			case 1:		re=re="<a href=\""+_url+"\" target=\"_blank\"><img class=\"pic\" src=\""+_url+"\" "+tmpSize+" /></a>"; break;
			default:	re=_url; break;
		}
		return re;
	},
	toUploadPicture:function(s,sWid,sHei,m,o){
		var re="";
		var isPic=false;
		if(s && s.lastIndexOf("no_pic.gif")<0) isPic=true;
		if(isPic) { $o(o).show(); re=this.toUploadPic(s,sWid,sHei,m,0); } else $o(o).hide();
		return re;
	},
	doDataCopy:function(s,msg) { $p.setClipBoardData(iso(s)?$o(s).html():s); if(msg) alert(msg); return false; }
});

Object.extend(common,{
	doPrint:function(chn){
		w.print();
	},
	doCommend:function(chn,tit,_url){
		var re=$c.v("url.commend");
		if(ise(tit)) tit=$b.get("title");
		if(ise(_url)) _url=$b.url();
		if(chn) re=$url.link(re,"subchannel="+chn);
		if(tit) re=$url.link(re,"title="+$url.toEncode(tit));
		if(_url) re=$url.link(re,"url="+$url.toEncode(_url));
		w.open(re);
	},
	doReport:function(chn,tit,_url){
		var re=$c.v("url.report");
		if(ise(tit)) tit=$b.get("title");
		if(ise(_url)) _url=$b.url();
		if(chn) re=$url.link(re,"subchannel="+chn);
		if(tit) re=$url.link(re,"title="+$url.toEncode(tit));
		if(_url) re=$url.link(re,"url="+$url.toEncode(_url));
		w.open(re);
	},
	doPutAdd:function(chn){
		var re=$c.v("url.put");
		if(chn) re=$url.link(re,"subchannel="+chn);
		w.open(re);
	},
	doBookmarkAdd:function(chn,tit,_url){
		var re=$c.v("url.bookmark");
		var _act="add";
		if(ise(tit)) tit=$b.get("title");
		if(ise(_url)) _url=$b.url();
		if(chn) re=$url.link(re,"subchannel="+chn);
		if(_act) re=$url.link(re,"action="+_act);
		if(tit) re=$url.link(re,"title="+$url.toEncode(tit));
		if(_url) re=$url.link(re,"url="+$url.toEncode(_url));
		w.open(re);
	},
	toTagLink:function(chn,s,urls){
		var re="";
		if(!urls) urls=$c.v("url.tag.hlink");
		if(inp(urls,"</a>")<1) urls="<a href="+urls+">{$keys}</a>";
		urls=rd(urls,"channel",chn);
		s=r(s," ",",");s=r(s,"|",",");
		var _ary=s.split(",");
		for(var i=0;i<_ary.length;i++){if(_ary[i]) re+=rd(rd(urls,"keys",_ary[i]),"keys.encode",$url.toEncode(_ary[i]))+" ";}
		return re.trim();
	}
});


//########################################
//########################################
var chn=appChannel={channel:"",isload:false,treeConfig:new VDCS.utilTree(),_ConfigLoad:null};

chn.set=function(s) { this.channel=s; }
chn.setChannel=function(s) { this.channel=s; }
chn.get=function(t,channel){
	var re="";
	switch(t){
		case "url":	re=$c.url("root")+(channel||this.channel)+"/";break;
		default:	re=this.channel;break;
	}
	return re;
}

chn.addEvent=function(t,s){
	if(!this._ConfigLoad) this._ConfigLoad=new VDCS.Queues();
	switch(t){
		case "config.load":	this._ConfigLoad.add(s); break;
	}
}

chn.loadConfig=function(s){
	if(ise(s))s=this.channel;
	$ajax({onError:function(s,v){alert("调试信息: 装载频道配置["+s+"]错误\n"+v+"");},url:$c.getURL("data")+"cache/channel/"+s+".config.xml",value:"xml",onReady:"appChannel.loadConfigAsync"});
}
chn.loadConfigAsync=function(oXML) { this.treeConfig=$util.toTreeByXML(oXML); if(this.treeConfig.getCount()>0)this.isload=true; if(this._ConfigLoad) this._ConfigLoad.exec(); }
chn.getConfig=function(k) { return this.treeConfig.getItem(k); }
chn.setConfig=function(k,v) { this.treeConfig.addItem(k,v); }

chn.toLinkURL=function(sPage,sItems,tpl) { var s=$c.toReplaceVar(this.getConfig("url."+sPage),obys(sItems)); return (tpl)?rd(tpl,"linkurl",s):s; }


//########################################
//########################################
var user=appUser={id:-1,name:'',ONLINE_MINUTE:60,ONLINE_STATUS:"on",ONLINE_TITLE:$v.user["online"],OFFLINE_STATUS:"off",OFFLINE_TITLE:$v.user["offline"]};

user.isLoginCheck=function(frm){
	var err=new VDCS.Error();
	var tmpMessage="";
	frm=frm||"frm_login";
	if($f.getValue(frm+".username")==""){ err.addItem($v.user["alert.username"]); $f.focus(frm+".username"); }
	else if($f.getValue(frm+".password")==""){ err.addItem($v.user["alert.password"]); $f.focus(frm+".password"); }
	err.doPop();
	return err.isCheck();
}

user.doMessageCheck=function(n){
	if(n<1) return false;
	put("<bgsound src=\""+$c.getURL("themes")+"account/images/message/new.mp3\" />");
	if($("user_message_new")) $("user_message_new").style.display="";
	if($("user_message_new_num")) $("user_message_new_num").innerText=n;
}

user.toURL=function(id,name,mode){
	var re="";
	re=$c.v("url.user");
	if(id) re=$url.link(re,"userid="+id);
	if(name) re=$url.link(re,"username="+$url.toEncode(name));
	if(mode) re=$url.link(re,"mode="+mode);
	return re;
}

user.toLinkURL=function(id,name,ps,_target){	//,sMod,sTarget,sTit,sTxt
	if(ps){if(!iso(ps))ps={mode:ps};}else ps={};
	if(_target)ps.target=true;
	var re="",_url,_text=ps.txt||name;
	if(id>0){
		_url=this.toURL(id,name,ps.mode);
		re=$url.hlink(_url,_text,ps);
	}
	else{
		if(name.length>0){
			var ary=name.split(",");
			for(var i=0;i<ary.length;i++){
				_url=this.toURL(0,ary[i],ps.mode);
				_text=ary[i];
				if(re.length>0) re+=" "+$url.hlink(_url,_text,ps);
				else re=$url.hlink(_url,_text,ps);
			}
		}
		else{
			re=(ps.mode=="moderator")?re=$v.user["hlink.no.moderator"]:$v.user["hlink.no"];
		}
	}
	return re;
}

user.toGroupPower=function(s){
	var re="";
	return re;
}

user.loadFace=function(o,s,w,h) { o=$(o); if(o){o.src=this.toFaceURL(s); o.width=w; o.height=h;} }
user.toFaceURL=function(s) { var re="";if(s){if(s.substring(0,1)=="$"){re=$c.getURL("upload")+"user.face/"+s.substring(1);}else if(s.substring(0,1)=="#"){re=$c.getURL("upload")+"face/"+s.substring(1);}else{re=s;}};return re; }
user.toFace=function(s,w,h) { return "<img class=\"user-face\" src=\""+this.toFaceURL(s)+"\" width=\""+w+"\" width=\""+h+"\" />"; }

user.toIcon=function(s) {
	var re="";
	if(!iso(s))s=[s," "];
	if(s[0]=="qq"&&s[1]=="0"){s[1]="";}else if(s[0]=="url"&&s[1]=="http://"){s[1]="";}
	if((s[0]&&s[1])){
		var imgsrc="";
		if(s[0].indexOf(".")>-1){imgsrc=s[0];}
		else if(inPart("sex,sex0,sex1,sex2",s[0])>0){imgsrc=$c.getURL("themes")+"images/user/icon_sex"+(s[0]=="sex1"?"_male":(s[0]=="sex2"?"_female":""))+".gif";}
		else if(inPart($v.UserIcons.IM,s[0])>0){imgsrc=$c.getURL("images")+"common/im/"+s[0]+".gif";}
		else if(inPart($v.UserIcons.ATT,s[0])>0){imgsrc=$c.getURL("themes")+"images/common/icon/"+s[0]+".gif";}
		else{imgsrc=$c.getURL("themes")+"images/user/icon/"+s[0]+".gif";}
		re="<img class=\"icon\" src=\""+imgsrc+"\""+((s[1]&&s[1]!=" ")?" title=\""+s[1]+"\"":"")+" />";
		switch(s[0]){
			case "url":re="<a href=\""+s[1]+"\" target=\"_blank\">"+re+"</a>";break;
			case "email":re="<a href=\"mailto:"+s[1]+"\">"+re+"</a>";break;
		}
	}
	return re;
}
user.toIcons=function(o,s) { if(!s)s=" ";var re="",v; if(isa(o)){for(var a=0;a<o.length;a++){v=this.toIcon(o[a]);if(v&&s&&a<(o.length-1))v+=s;re+=v;}} return re; }

user.isOnLine=function(s){if(!isInt(s))s=$time.toNumber(s);return !(($time.toNumber($time.getNow())-s)>this.ONLINE_MINUTE*60);}
user.toOnLineStatus=function(s){return this.isOnLine(s)?this.ONLINE_STATUS:this.OFFLINE_STATUS;}
user.toOnLineTitle=function(s){return this.isOnLine(s)?this.ONLINE_TITLE:this.OFFLINE_TITLE;}
user.toOnLineIcon=function(s){var _is=this.isOnLine(s);var _status=_is?this.ONLINE_STATUS:this.OFFLINE_STATUS;var _title=_is?this.ONLINE_TITLE:this.OFFLINE_TITLE;return "<img class=\"icon\" src=\""+$c.getURL("themes")+"images/user/icon/line_"+_status+".gif\" title=\""+_title+"\" />";}

//########################################
user.group={tableData:null};

user.group.bind=function(o,ps){ $xbind.bind(o,{res:"url:"+$c.getURL("data")+"cache/channel/user.group.xml",func:"user.group.toValue",param1:ps["id"],param2:ps["type"]}); }

user.group.toValue=function(map,id,t){
	var re="";
	var tableData=map?map.getItemTable("item"):null;
	if(tableData){
		tableData.doItemBegin();
		for(var i=1;i<=tableData.getRow();i++){
			if(id==tableData.getItemValue("id")){
				switch(t){
					case "icon":re="<img class=\"icon\" src=\""+$c.getURL("themes")+"images/user/group/icon_"+tableData.getItemValue("key")+".gif\" />";break;
					case "style":re=rd(tableData.getItemValue(t),"name",tableData.getItemValue("name"));break;
					default:re=tableData.getItemValue(t);break;
				}
			}
			tableData.doItemMove();
		}
	}
	return re;
}

//########################################
user.honor={tableData:null};

user.honor.bind=function(o,ps){ var _othis=this;$xbind.bind(o,{res:"url:"+$c.getURL("data")+"cache/channel/user.honor.xml",func:function(map,s){return _othis.toHTML(map,s)},param1:ps["v"]}); }

user.honor.toHTML=function(map,s){
	var re="";
	var tableData=map?map.getItemTable("item"):null;
	if(tableData){
		tableData.doItemBegin();
		for(var i=1;i<=tableData.getRow();i++){
			if(inPart(s,tableData.getItemValue("value"))>0) re+=tableData.getItemValue("img");
			tableData.doItemMove();
		}
	}
	return re;
}

//########################################
user.rank={NUM_BASE:4,NUM_RADIX:5,NUM_MAX:80,IMG_PATH:$c.getURL("images")+"user/rank/"};

user.rank.toTimeString=function(n) { return $time.toMinuteString(n); }

user.rank.toUpgradeInfo=function(n,ol) { return $time.toMinuteString((Math.pow(n+1,2)+(n+1))*5*60-ol); }

user.rank.toIcon=function(n){
	if(!isInt(n)||n<1) return "";
	if(n>this.NUM_MAX) n=this.NUM_MAX;
	var _sun=toMathAC(n,Math.pow(this.NUM_BASE,2));
	var _num=toMathMOD(n,Math.pow(this.NUM_BASE,2));
	var _moon=toMathAC(_num,this.NUM_BASE);
	var _star=toMathMOD(_num,this.NUM_BASE);
	var re="",i;
	for(i=0;i<_sun;i++){re+="<img class=\"icon\" src=\""+this.IMG_PATH+"sun.gif\" title=\"Rank: "+n+"\" />";}
	for(i=0;i<_moon;i++){re+="<img class=\"icon\" src=\""+this.IMG_PATH+"moon.gif\" title=\"Rank: "+n+"\" />";}
	for(i=0;i<_star;i++){re+="<img class=\"icon\" src=\""+this.IMG_PATH+"star.gif\" title=\"Rank: "+n+"\" />";}
	return re;
}

function toMathAC(a,b){return Math.floor(Math.abs(a/b));}
function toMathMOD(a,b){return a-Math.floor(Math.abs(a/b))*b;}
