/*
Subj: x object

cPBar   ... ProgressBar | cCRow   ... CurrentRow | cPAjax  ... PageAjax
cBCast  ... BroadCast   | cFld    ... FormField  | cFldChk ... FormCheck
cWin    ... Window

Date: 2008-11-13
*/

var __cCRowBgC = '#d0c0ae';
var __sDel = '删除';
var __selindex = 0;

function cPBar() {
	this._container = '';
	this._msg = _g_PBarSText();
	this._obj = null;
	this._started = false;
	this._inited = false;
}

cPBar.prototype = {
	setext : function(s) {
		this._msg = s;
	},
	start : function() {
		this._initobj();
		if(this._inited) this._act(1);
	},
	stop : function() {
		if(this._started) this._act(2);
	},
	_act : function(a) {
		this._obj.innerHTML = (a==1)?this._msg:'';
		this._started = (a==1)?true:false;
	}
}
cPBar.prototype.setcontainer = setcontainer;
cPBar.prototype._initobj = _initobj;

function cCRow() {
	this._editmode = false;
	this._editid = 0;
	this._orgbkc = '';
	this._obj = null;
}

cCRow.prototype = {
	set : function(p) {
		if(this._editid>0) this._reset();

		this._obj = g('tr_' + p.toString());
		this._orgbkc = this._obj.style.backgroundColor;
		this._obj.style.backgroundColor = __cCRowBgC;
		this._updstatus(1,p);
	},
	clear : function() {
		if(!this._editmode) return;
		this._reset();
		this._updstatus(2,0);
	},
	_reset : function() {
		this._obj = g('tr_' + this._editid.toString());
		this._obj.style.backgroundColor = this._orgbkc;
	},
	_updstatus : function(a,p) {
		this._editmode = (a==1)?true:false;
		this._editid = (a==1)?p:0;
	}
}

function cPAjax(c) {
	this.code = '';
	this.subject = '';
	this.responseText = '';
	this.responseXML = '';
	this.responseType = 0; //0 txt; 1 xml
	this.rdata = null;
	this.started = false;
	this.pb = new cPBar();
	this.cr = new cCRow();

	this._container = c;
	this._obj = null;
	this._inited = false;
}

cPAjax.prototype = {
	setcode : function(tv,ti,c) {
		this.code =
			_g_AjaxFormH(tv + this.subject) + c +
			_g_AjaxFormC(ti) +
			_g_AjaxFormB();
	},
	show : function() {
		this._initobj();
		if(this._inited) {
			this._obj.innerHTML = this.code;
			this.started = true;
		}
	},
	hide : function() {
		if(this.started) {
			this._obj.innerHTML = '';
			this.started = false;
		}
	},
	focus : function(o,s) {
		timeout('xfocus(\'' + o + '\')',s);
	},
	getresponse : function(id,callback,iflag) {
		var ao = ajaxpack.ajaxobj,ft = ajaxpack.filetype;
		var rt = 0,rv = false,r = '',flag = true;

		flag = (id && id != '')?true:false;
		if(iflag && flag){sethtm(id,'<img src="images/loading.gif" width="100" height="9" alt="处理中,请稍候..." />');dispme(id);}

		if (ao.readyState==4) {
			if (ao.status==200||window.location.href.indexOf("http")==-1) {
				rt = (ft=='txt')?0:1;
				if(rt==0) {
					r = ao.responseText;
					if (r=='OK'||r.substr(0,2)=='OK') {
						r = r.substr(((r=='OK')?2:6),r.length);
						rv = true;if(flag) nodispme(id);
					}
					else {
						if(flag){sethtm(id,r);dispme(id);}
						else alert(_g_err() + ':\n\n' + r);
					}
					this.responseText = r;
					this.rdata = r.split('$||$');
				}
				else this.responseXML = ao.responseXML;
				this.responseType = rt;
			}
			if(callback && callback != '') eval(callback);
		}
		return (rv);
	}
}
cPAjax.prototype.setcontainer = setcontainer;
cPAjax.prototype._initobj = _initobj;

function cBCast(i,s,t,c) {
	this.started = false;
	this.purecode = false;

	this._id = i;
	this._msg = s;
	this._livetime = t;
	this._container = c;
	this._obj = null;
	this._timer = null;
	this._cdtimer = null;
	this._inited = false;
}

cBCast.prototype = {
	setcontent : function(s,t) {
		this._msg = (!this.purecode)?_g_BCastText(s):s;
		if(t>0) this._livetime = t;
	},
	start : function() {
		this._initobj();
		if(this._inited&&this._livetime>0) {
			this._obj.innerHTML = this._msg;
			this._obj.style.display = '';
			this._timer = timeout(this._id + '.stop()',this._livetime*1000);
			if(!this.purecode) this._docdown();
			this.started = true;
		}
	},
	stop : function() {
		clearTimeout(this._timer);
		if(this._cdtimer) clearTimeout(this._cdtimer);
		this._obj.style.display = 'none';
	},
	_docdown : function() {
		if(this._livetime==0) {
			clearTimeout(this._cdtimer);
			return;
		}
		g('_bc_cdown').innerHTML = (this._livetime --).toString();
		this._cdtimer = timeout(this._id + '._docdown()',1000);
	}
}
cBCast.prototype.setcontainer = setcontainer;
cBCast.prototype._initobj = _initobj;

function cFld(i,d,u,t,z) {
	this.id = i;
	this.desc = d;
	this.type = t; //0 text,1 radio,2 option,3 checkbox
	this.value = u;
	this.isEmpty = !((/\S/).test(u));
	this.isZero = (typeof(z)!='undefined'&&z==1&&(isNaN(parseInt(u))||parseInt(u)<=0));
}

function cFldChk() {
	this.firstid = '';

	this._items = 0;
	this._item = new Array();
}

cFldChk.prototype = {
	add : function(fld) {
		this._item[this._items] = fld;
		this._items ++;
	},
	check : function() {
		var fld = null,nv = true,msg = '',id = '';
		var vv = 0,tp = 0,i = 0,j = 0,k = 1;
		j = this._items;

		if(j==0) return true;
		for(i=0; i<j; i++) {
			fld = this._item[i];
			tp = fld.type;
			id = fld.id;
			vv = fld.value;
			nv = (
				(tp==0)?(fld.isEmpty||fld.isZero):(
				(tp==1)?vv==-999:(
				(tp==2)?(vv==-999||vv==0):vv=='')));
			if(nv) {
				if(k==1) this.firstid = id;
				msg += k.toString() + '. ' + fld.desc + (fld.isZero?_get_NotZeroDesc():'') + '\n';
				k ++;
			}
		}
		this._initobj();

		nv = (k>1)?true:false;
		if(nv) {
			alert(_g_NotNullDesc(msg));
			fld = g(this.firstid);
			if(fld) fld.focus();
		}
		return (!nv);
	},
	_initobj : function() {
		this._item = new Array();
		this._items = 0;
	}
}

function cWin(c) {
	this.code = '';
	this.started = false;

	this._container = c;
	this._handle = '';
	this._width = 300;
	this._title = '';
	this._precode = '';
	this._cmdid = 0;
	this._obj = null;
	this._inited = false;
}

cWin.prototype = {
	setcode : function(s) {
		this.code = _g_WinCode(
			this._width,
			this._title,
			this._cmdid,
			s
		);
	},
	setall : function(w,t,a) {
		this._width = w;
		this._title = t;
		this._cmdid = a;
	},
	setwidth : function(w) {
		this._width = w;
	},
	setitle : function(t) {
		this._title = t;
	},
	setcmdid : function(a) {
		this._cmdid = a;
	},
	show : function() {
		this._initobj();
		if(this._inited) {
			if(this._handle!='') {
				toggledisp(this._handle);
			}
			this._precode = this._obj.innerHTML;
			this._obj.innerHTML = this.code;
			this.started = true;
		}
	},
	hide : function(s) {
		if(this.started) {
			if(this._handle!='') {
				toggledisp(this._handle);
			}
			this._obj.innerHTML = (typeof(s)!='undefined'?s:this._precode);
			this.started = false;
		}
	},
	focus : function(o,s) {
		timeout('xfocus(\'' + o + '\')',s);
	},
	setcontainer : function(c,h) {
		if(this.started) {
			alert(_g_AjaxNotDoneDesc());
			return false;
		}
		this._container = c;
		this._handle = h;
		this._inited = false;
		return true;
	}
}
cWin.prototype._initobj = _initobj;

/*-- obj prototype f --*/
function setcontainer(c) {
	this._container = c;
	this._inited = false;
}

function _initobj() {
	if(!this._inited) {
		this._obj = g(this._container);
		this._inited = (this._obj)?true:false;
	}
}

/*-- obj instance --*/
var p = new cPAjax('lbsp01');
var w = new cWin('');
var b = new cBCast('b','',10,'lbc');
var v = new cFldChk();

function _chk_fmFld(vf,t) {
	var _vr = null,_fc = vf.length,_os = 0;
	var _vi = 0,_vz = 0,_vs = 0,_vo = '',_vd = '',_vt = '',_vv = '',_tv = '';

	for(_vi=0; _vi<_fc; _vi++) {
		_vr = vf[_vi].split('.'); //tp.id.desc.ischk.isnotzero.isnum.optionset
		if(_vr.length>0) {
			_vt = parseInt(_vr[0]);
			_vo = _vr[1];
			_vd = _vr[2];

			_vz = (_vr.length>=5?parseInt(_vr[4]):0);
			_vs = (_vr.length>=6?parseInt(_vr[5]):0);
			_os = (_vr.length>=7?parseInt(_vr[6]):0);

			switch(_vt) {
				case 0:
					_vv = getvalueS(_vo);
					_vv = (_vs==0?_vv:_vv.replace(/\D/g,''));
					break;
				case 1:
					_vv = getRadioValue(_vo);
					break;
				case 2:
					_vv = getOptionValue(_vo);
					break;
				case 3:
					if(!_os&1)
						_vv = getCheckboxValue(_vo);
					else
						_vv = getCheckboxValueEx(_vo);
					break;
			}
			if(parseInt(_vr[3])==1) v.add(new cFld(_vo,_vd,_vv,_vt,_vz));
		}
		if(t==1) _tv += '$|' + getchar(_vi+66) + '|$' + escape(_vv);
	}

	if(!v.check()) return (((t==1)?'':false));
	return (((t==1)?_tv:true));
}

function _g_url() {
	return ((!gHasNC)?gfN:(gfN + '?t=' + _navcat.toString()));
}

function _g_ok() {
	return ('操作成功！');
}

function _g_err() {
	return ('出错');
}

function _g_fail() {
	return ('操作失败，出错信息：\n\n');
}

function _g_cfont(c,s) {
	return ('<font color="' + c + '">' + s + '</font>');
}

function _g_bscfont(c,s) {
	return (_g_cfont(c,'<strike><b>' + s + '</b></strike>'));
}

function _g_ConfirmT(o,s) {
	return (((o=='')?s:'操作对象：' + o + '\n\n\n' + s));
}

function _g_NotNullDesc(s) {
	return ('以下内容不能为空：\n\n' + s + '\n请填写完整，谢谢！');
}

function _get_NotZeroDesc() {
	return ('，该项内容须为数字且大于0');
}

function _g_AjaxNotDoneDesc() {
	return ('请先完成或取消上一个编辑操作，谢谢！');
}

function _g_PBarSText() {
	return ('<br /><img src="images/loading.gif" /> 操作进行中，请稍候...');
}

function _g_BCastText(s) {
	var c = '<div class="infob infob_T">&nbsp;提示信息 <span id="_bc_cdown"></span></div><div class="infob infob_C">' + s + '</div>';
	return (c);
}

function _g_LockDesc() {
	return (_g_actDesc('锁定'));
}

function _g_LockResultT(s) {
	return (_g_ResultT(s,'锁定'));
}

function _g_LockResultS() {
	return (_g_cfont('red','LOCKED'));
}

function _g_UnlockDesc() {
	return ('是否要【解除锁定】对该' + p.subject + '的锁定？');
}

function _g_DelDesc() {
	return (_g_actDesc(__sDel));
}

function _g_DelResultT(s) {
	return (_g_ResultT(s,__sDel));
}

function _g_DelResultS() {
	return (_g_cfont('red','DELETED'));
}

function _g_ActResultS(s) {
	return (_g_cfont('red',s));
}

function _g_ResultT(s,t) {
	var c = _g_cfont('black','<strike><b>' + s + '</b></strike>') + '&nbsp;(' + _g_cfont('red','已' + t) + ')';
	return (c);
}

function _g_AjaxPostStr() {
	return ('ajax=1&a=' + gCID.toString() + '&t=' + _navcatS + '&gp=' + _navcpS + '&li=' + _li.toString() + '&ln=' + _ln + '&aid=' + msg);
}

function _g_AFResult(a,s) {
	var c = '操作 ' + ((a==5)?'新建':'编辑') + p.subject + _g_ResultBC(s,'');
	return (c);
}

function _g_ResultBC(s,x) {
	if(typeof(x)=='undefined') x = '';
	var c = '【<span id="#mf_bold" class="cred">' + s + '</span>】' + x + '完成！<br /><br /><br />刷新后即可看到最新的数据～<br /><br />［<a href="javascript:rp()">点击这里刷新当前页面</a>］';
	return (c);
}

function _g_AjaxFormH(t) {
	var c = '<table width="600px" border="0" cellpadding="2" cellspacing="0" class="tcinfo ajaxtb" style="background-color:white"><tr><td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="list"><tr><td colspan="2" class="titles">' + t +'</td></tr>';
	return (c);
}

function _g_AjaxFormC(a) {
	var c = '<tr class="hs"><td class="bd br" colspan="2">　　　<input type="button" value=" 确定 " onclick="act(' + a.toString() + ')" id="se_o_btnok" class="buttnc" accesskey="S" />&nbsp;<input type="button" value=" 取消 " class="buttnc" accesskey="R" onclick="act(21)" /><span id="lbi"></span></td></tr>';
	return (c);
}

function _g_AjaxFormB() {
	return ('</table></td></tr></table>');
}

function _g_WinCode(w,t,a,s) {
	var c = '<div class="clsbox cb_T" style="width:' + w.toString() + 'px"> <div class="fll">' + t + '</div><div class="flr"><img src="images/w_cl1.gif" title="关闭" class="hand" onclick="w.hide();" />&nbsp;</div></div><div class="clsbox cb_C cblack" style="width:' + (w-2).toString() + 'px;line-height:200%">' + s + '&nbsp;<input type="button" value=" 确定 " onclick="cwin_do(' + a.toString() + ')" class="buttnc">&nbsp;<input type="button" value=" 取消 " class="buttnc" onclick="cwin_reset(' + a.toString() + ')"></div>';
	return (c);
}

function _g_actDesc(t) {
	return ('是否要【' + t + '】该' + p.subject + '？');
}

function se_keyp_return(t,e) {
	if(chksubmit(e)) se_form(t);
}

function chksubmit(e) {
	if(!e) e = window.event;
	var k = getkeycode(e);
	if(k==13) {
		cancelevt(e);
		return true;
	}
	return false;
}

function se_form(t,a2) {
	var obj = null,aa = '$|A|$',i = 0,cc = '',kk = '',ss = '',vv = '';
	var acmd = new Array('c','t','o');

	for(i=66; i<69; i++) {
		if(i==66&&(!gHasNC)) {
			i = 67;
			ss = 'a0$$';
		}
		cc = getchar(i);
		obj = g('s' + acmd[i-66] + 'p');
		vv = obj.options[obj.options.selectedIndex].value;
//		aa += ((i==68)?vv:escape(vv)) + '$|' + cc + '|$';
		aa += vv + '$|' + cc + '|$';
		ss += obj.options[obj.options.selectedIndex].id.toString() + '$$';
	}

	kk = g('skp').value.toString();
	aa += kk;
	ss += escape(kk);

	if (trim(kk)=='')
		gourl(_g_url());
	else {
		i = 3;
		if(arguments.length==2) i = arguments[1];
		se_sf(i,aa,ss);
	}
}

function se_sf(a,b,c) {
	var f = document.form1;

	f.a.value = a;
//	f.gp.value = 1;
	f.aid.value = b;
	f.seobj.value = c;
	f.submit();
}

function dispresult(s) {
	p.hide();
	b.setcontent(s,10,'');
	b.start();
}

function strikecf(c,s) {
	return (_g_cfont(c,'<strike>' + s + '</strike>'));
}

function ec(s) {
	return (encodeURIComponent(s));
}

function dispnote() {
	toggledispX('se_o_note');
	jumpto('se_o_note');
}

function dosearch(){
	var sServerName = getOptionText('sel_o_ServerID');
	var iServerType = getOptionValueI('sel_o_ServerID');
	var sServerType = '';
	if(iServerType == 1 ) {
		var indx = sServerName.lastIndexOf('-');
		sServerType = sServerName.substr(indx + 1,sServerName.length);
		sServerName = sServerName.substr(0,indx - 1).replace(/ /g,'-');
	}
	sServerName = sServerName.replace(/ /g,'-');
	var sgameName = getOptionText('sel_o_GameID').replace(/ /g,'-');
	gourl('/gold/'+ sgameName +'/' + sServerName  + (sServerType!=''? '/'+(sServerType):'') + '.html');
}

function getServers(index){
	var gameid = getOptionValueI('sel_o_GameID');
	if(gameid <= 0) {return true;}
	var ps = "GameID=" + gameid;
	__selindex = index;
	lock('sel_o_Search');
	ajaxpack.postAjaxRequest("/s/serverList.asp",ps,showServerList,'txt');
}

function showServerList(){
	if(p.getresponse('','unlock("sel_o_Search");')) {
		changeOption('sel_o_ServerID',p.rdata);
		setOptionValue('sel_o_ServerID',__selindex);
		unlock("sel_o_Search");
	}
}