﻿function HandleClsSysInfo(){$("SysInfo").innerHTML = "";}
function handleDialog(url,cid,uid){if(cid){$('listid').value=cid;};if(uid){$('agenuid').value=uid;};$('SetupDialog').style.display='';$('dialogframe').src=url;}
function AjaxMenuShow(objh,mod){var obj=AjaxMenuInit();var posX = findPosX(objh)-70;var posY = findPosY(objh) + objh.offsetHeight;getPosX(obj,posX);getPosY(obj,posY);var option={parameters:"?action=menuShow&rm="+Math.random()+"&op="+mod,method:"get",onSuccess:function(transport){$("AjaxMenuContent").innerHTML = transport.responseText;ClipShow("AjaxMenu");},onFailure:function(transport){}};var request = new Ajax.Request(AjaxUrl, option);};
function MenuOut(){}
function MenuClose(){ClipHide('AjaxMenu');}
function MenuOver(){if (MenuTimer){clearTimeout(MenuTimer);}}
function ClipShow(objid,nw,nh){var showObj = $(objid);if (nw==null) {nw = 0;nh = 0;};var sw = Math.min( (showObj.offsetWidth) , (nw+15) );var sh = Math.min( (showObj.offsetHeight) , (nh+15) );showObj.style.clip = "rect(0px " + sw + "px " + sh + "px 0px)";if (showObj.style.display=="none") {showObj.style.display = "";};if ((sw!=(showObj.offsetWidth))||(sh!=(showObj.offsetHeight))) {setTimeout("ClipShow(\"" + objid + "\"," + sw + "," + sh + ")",20);};};
function ClipHide(objid,nw) {var showObj = $(objid);if(showObj!=null){if (nw==null) {nw = 0;};var sw = Math.min( (showObj.offsetWidth) , (nw+15) );showObj.style.clip = "rect(0px " + showObj.offsetWidth + "px " + showObj.offsetHeight + "px " + sw + "px)";if (sw!=showObj.offsetWidth) {setTimeout("ClipHide(\"" + objid + "\"," + sw + ")",20);} else {showObj.style.display = "none";};}}
var MenuTimer = null;function AjaxMenuInit() {var obj = $("AjaxMenu");if (!obj) {obj = document.createElement("DIV");obj.id = "AjaxMenu";obj.onmouseover = MenuOver;obj.onmouseout = MenuOut;obj.style.display = "none";objc = document.createElement("DIV");objc.id = "AjaxMenuContent";obji = document.createElement("IMG");obji.src = "images/close.gif";obji.className = "close";obji.onclick = MenuClose;obj.appendChild(obji);obj.appendChild(objc);document.getElementsByTagName("BODY")[0].appendChild(obj);};return obj;}
var AjaxUrl = "ajax.aspx";var UserId = 0;var ChatName="点评天下";
function atoi(s){var r = parseInt(s);return isNaN(r) ? 0 : r;}
function magicLocus(x1, x2){x1=atoi(x1);x2=atoi(x2);if ((Math.abs(x1-x2))<2){return x2;}else{return parseInt((x1+x2)/2);}}
String.prototype.Trim=function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
function isNotNull(s){return ((s!=null)&&(s.Trim()!=""));}
function HtmlEncode(str){if (str==null){return "";}else{return str.replace(/\"/g,"%22").replace(/\'/g,"%27").replace(/&/g,"&amp;").replace(/\"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/ /g,"&nbsp;");}}
function HtmlDecode(str){if (str==null){return "";}else{return str.replace(/%22/g,"\"").replace(/%27/g,"'").replace(/&nbsp;/g," ").replace(/&gt;/g,">").replace(/&lt;/g,"<").replace(/&quot;/g,"\"").replace(/&amp;/g,"&");}}
function getXByZoneId(zoneId){if (zoneId%801==0){return Math.floor((zoneId/801)-401);}else{return Math.floor((zoneId/801)-400);}}
function getYByZoneId(zoneId){if (zoneId%801==0){return 400;}else{return Math.floor((zoneId%801)-401);}}
function getXyByZoneId(zoneId){return ("(" + getXByZoneId(zoneId) + "|" + getYByZoneId(zoneId) + ")");}
function map50(zoneId,ally,people){if ($("tb")){if (zoneId>0){$("tb").innerHTML = getMapDesc((getXByZoneId(zoneId)+25),(getYByZoneId(zoneId)+25),ally,people);}else{$("tb").innerHTML = getMapDesc();}}}
function map5(zoneId,ally,people){if ($("tb")){if (zoneId>0){$("tb").innerHTML = getMapDesc((getXByZoneId(zoneId)),(getYByZoneId(zoneId)),ally,people);}else{$("tb").innerHTML = getMapDesc();}}}
var summe;var max123;var max4;var haendler;var carry;var df;
var quest={'anmstep':false};
function qst_getstep(){var step;if(quest.anmstep===false){step={'step':{},'source':{},'current':{},'target':{'width':448,'height':482,'top':-1},'fps':50,'n':10,'i':0,'anm':{}};step.target['left']='-502';}else{step=quest.anmstep;};step.anm=$('anm');for(var pg in step.target){step.source[pg]=Number(step.anm.style[pg].substr(0,step.anm.style[pg].length-2));step.current[pg]=step.source[pg];step.step[pg]=Math.round((step.target[pg]-step.source[pg])/step.n);};step.timeout=1000/step.fps;return step;};
function qst_handle(){quest.cstep=qst_getstep();window.setTimeout('qst_setstep()',quest.cstep.timeout);if(quest.anmstep===false){ajax_call("faqoper",{"oper":"task"});};};
function qst_setstep(){$("ce").style.display="none";step=quest.cstep;step.i++;if(step.i==2){step.anm.style.visibility='visible';};for(var pg in step.target){step.current[pg]+=step.step[pg];step.anm.style[pg]=step.current[pg]+'px';};if(step.i<step.n){window.setTimeout('qst_setstep()',step.timeout);}else{step.anm.style.visibility='hidden';quest.cstep=false;if(quest.anmstep===false){$("ce").style.display="block";step.current=step.target;step.target=step.source;step.source=step.current;for(var pg in step.target){step.anm.style[pg]=step.current[pg]+'px';};step.i=0;quest.anmstep=step;}else{$("ce").style.display="none";quest.anmstep=false;}}};
var qst_tim;
function qst_timer(){
    window.clearInterval(qst_tim);
    qst_tim = window.setInterval("qst_timer_step()",1000);
};
function qst_timer_step(){
    var st= $("qst_timer");
    if(st){
        st = st.innerHTML;
        if(st>0){
            $("qst_timer").innerHTML = (st-1);
        }else{
            window.clearInterval(qst_tim);
            frm_submit("testoper",document.faq_frm);
        }
    }
    else{
        window.clearInterval(qst_tim);
    }
}
function helper(){$('qge').style.display = ($('qge').style.display=="inline"?"none":"inline");setCookie("showHelper",($('qge').style.display=="inline"?"1":"0"),7);};
function getTopEvent(title,date,type,point) {
	var retHtml = "";
	if (title) {
		retHtml += "<table class='f8 map_infobox_grey' cellspacing='1' cellpadding='2'>\n";
		retHtml += "	<tr>\n";
		retHtml += "		<td class='c b' colspan='2' align='center'>" + title + "</td>\n";
		retHtml += "	</tr>\n";
		retHtml += "	<tr>\n";
		retHtml += "		<td width='45%' class='c s7'>时间:</td>\n";
		retHtml += "		<td class='c s7'>" + date + "</td>\n";
		retHtml += "	</tr>\n";
		retHtml += "	<tr>\n";
		retHtml += "		<td class='c s7'>" + ((type==1)?"总米数":"抢得资源") + ":</td>\n";
		retHtml += "		<td class='c s7'>" + point + "</td>\n";
		retHtml += "	</tr>\n";
		retHtml += "</table>\n";
	}else{retHtml += getMapDesc();}	
	if ($("tb")){$("tb").innerHTML = retHtml;}
}

function buySomething(pa){
    var option={
        parameters:"?action=buy&p="+pa+"&rm="+Math.random(),
        method:"get",
        onSuccess:function(transport){
            ClipHide("AjaxMenu");
            if(transport.responseText==""){
                getContent("lmid2","building&gid=37&t=2");
            }else{
                showAlert(transport.responseText);
            }
        },
        onFailure:function(transport){
            ClipHide("AjaxMenu");
            showAlert("购买失败，请稍候再试");
        }
    };
    var request = new Ajax.Request(AjaxUrl, option);
}

function getMapDesc(xId,yId,ally,people) {
	var retHtml = "";
	if (xId!=null) {
		retHtml += "<table class='f8 map_infobox_grey' cellspacing='1' cellpadding='2'>\n";
		retHtml += "	<tr>\n";
		retHtml += "		<td class='c b' colspan='2' align='center'>(" + xId + "|" + yId + ")</td>\n";
		retHtml += "	</tr>\n";
		retHtml += "	<tr>\n";
		retHtml += "		<td width='45%' class='c s7'>区域人口:</td>\n";
		retHtml += "		<td class='c s7'>" + people + "</td>\n";
		retHtml += "	</tr>\n";
		retHtml += "	<tr>\n";
		retHtml += "		<td class='c s7'>最强联盟:</td>\n";
		retHtml += "		<td class='c s7'>" + ((ally)?ally:"-") + "</td>\n";
		retHtml += "	</tr>\n";
		retHtml += "</table>\n";
	}else{
		retHtml += "<table class='f8 map_infobox_grey' cellspacing='1' cellpadding='2'>\n";
		retHtml += "	<tr>\n";
		retHtml += "		<td class='c b' colspan='2' align='center'>详情:</td>\n";
		retHtml += "	</tr>\n";
		retHtml += "	<tr>\n";
		retHtml += "		<td width='45%' class='c s7'>区域人口:</td>\n";
		retHtml += "		<td class='c s7'>0</td>\n";
		retHtml += "	</tr>\n";
		retHtml += "	<tr>\n";
		retHtml += "		<td class='c s7'>最强联盟:</td>\n";
		retHtml += "		<td class='c s7'>-</td>\n";
		retHtml += "	</tr>\n";
		retHtml += "</table>\n";
	}
	return retHtml;
}

function map1(typeId, xId, yId) {
	if (typeId==0) {
		map('','','','',xId,yId);
	}else{
		x_y(xId, yId);
		
		var retHtml = "";
		var tempHtml = "";
		switch (typeId) {
			case 1: {tempHtml += "<img src=\"" + ImgPath + "img/un/r/4.gif\" />+50%";break;}
			case 2: {tempHtml += "<img src=\"" + ImgPath + "img/un/r/1.gif\" />+50%";break;}
			case 3: {tempHtml += "<img src=\"" + ImgPath + "img/un/r/3.gif\" />+50%";break;}
			case 4: {tempHtml += "<img src=\"" + ImgPath + "img/un/r/2.gif\" />+50%";break;}
			case 5: {tempHtml += "<img src=\"" + ImgPath + "img/un/r/2.gif\" />+25% <img src=\"" + ImgPath + "img/un/r/4.gif\" />+25%";break;}
			case 6: {tempHtml += "<img src=\"" + ImgPath + "img/un/r/3.gif\" />+25% <img src=\"" + ImgPath + "img/un/r/4.gif\" />+25%";break;}
			case 7: {tempHtml += "<img src=\"" + ImgPath + "img/un/r/1.gif\" />+25% <img src=\"" + ImgPath + "img/un/r/4.gif\" />+25%";break;}
			case 8: {tempHtml += "<img src=\"" + ImgPath + "img/un/r/1.gif\" />+25%";break;}
			case 9: {tempHtml += "<img src=\"" + ImgPath + "img/un/r/3.gif\" />+25%";break;}
			case 10: {tempHtml += "<img src=\"" + ImgPath + "img/un/r/2.gif\" />+25%";break;}
			case 11: {tempHtml += "<img src=\"" + ImgPath + "img/un/r/4.gif\" />+25%";break;}
			case 22: {tempHtml += "1<img src=\"" + ImgPath + "img/un/r/1.gif\" /> 1<img src=\"" + ImgPath + "img/un/r/2.gif\" /> 1<img src=\"" + ImgPath + "img/un/r/3.gif\" /> 15<img src=\"" + ImgPath + "img/un/r/4.gif\" />";break;}
			case 23: {tempHtml += "3<img src=\"" + ImgPath + "img/un/r/1.gif\" /> 3<img src=\"" + ImgPath + "img/un/r/2.gif\" /> 3<img src=\"" + ImgPath + "img/un/r/3.gif\" /> 9<img src=\"" + ImgPath + "img/un/r/4.gif\" />";break;}
			case 24: {tempHtml += "5<img src=\"" + ImgPath + "img/un/r/1.gif\" /> 3<img src=\"" + ImgPath + "img/un/r/2.gif\" /> 4<img src=\"" + ImgPath + "img/un/r/3.gif\" /> 6<img src=\"" + ImgPath + "img/un/r/4.gif\" />";break;}
			case 28: {tempHtml += "4<img src=\"" + ImgPath + "img/un/r/1.gif\" /> 4<img src=\"" + ImgPath + "img/un/r/2.gif\" /> 4<img src=\"" + ImgPath + "img/un/r/3.gif\" /> 6<img src=\"" + ImgPath + "img/un/r/4.gif\" />";break;}
			case 29: {tempHtml += "3<img src=\"" + ImgPath + "img/un/r/1.gif\" /> 4<img src=\"" + ImgPath + "img/un/r/2.gif\" /> 5<img src=\"" + ImgPath + "img/un/r/3.gif\" /> 6<img src=\"" + ImgPath + "img/un/r/4.gif\" />";break;}
			case 30: {tempHtml += "4<img src=\"" + ImgPath + "img/un/r/1.gif\" /> 5<img src=\"" + ImgPath + "img/un/r/2.gif\" /> 3<img src=\"" + ImgPath + "img/un/r/3.gif\" /> 6<img src=\"" + ImgPath + "img/un/r/4.gif\" />";break;}
			default: {break;}
		}
		
		if (tempHtml) {
			retHtml += "					<TABLE class=\"f8 map_infobox_grey\" cellSpacing=\"1\" cellPadding=\"2\">\n";
			retHtml += "						<TR><TD class=\"c b\" align=\"center\" colSpan=\"2\"></A><//A>详情:</TD></TR>\n";
			retHtml += "						<TR><TD class=\"c s7\" width=\"45%\">玩家:</TD><TD class=\"c s7\">-</TD></TR>\n";
			retHtml += "						<TR><TD class=\"c s7\">居民:</TD><TD class=\"c s7\">-</TD></TR>\n";
			retHtml += "						<TR><TD class=\"c s7\">联盟:</TD><TD class=\"c s7\">-</TD></TR>\n";
			retHtml += "						<TR><TD class=\"\" align=\"center\" colspan=\"2\">" + tempHtml + "</TD></TR>\n";
			retHtml += "					</TABLE>\n";
		} else {
			retHtml += "					<TABLE class=\"f8 map_infobox_grey\" cellSpacing=\"1\" cellPadding=\"2\">\n";
			retHtml += "						<TR><TD class=\"c b\" align=\"center\" colSpan=\"2\"></A><//A>详情:</TD></TR>\n";
			retHtml += "						<TR><TD class=\"c s7\" width=\"45%\">玩家:</TD><TD class=\"c s7\">-</TD></TR>\n";
			retHtml += "						<TR><TD class=\"c s7\">居民:</TD><TD class=\"c s7\">-</TD></TR>\n";
			retHtml += "						<TR><TD class=\"c s7\">联盟:</TD><TD class=\"c s7\">-</TD></TR>\n";
			retHtml += "					</TABLE>\n";
		}
		if ($("tb")) {$("tb").innerHTML = retHtml;}
	}
}
function SubmitConfirm(memo) {if (confirm(memo)==true) {return true;} else {return false;}}
var indexString = null;
function indexChange() {
	var ddObj1 = $("ddLeft");
	var ddObj2 = $("ddRight");
	if ((ddObj1)&&(ddObj2)) {
		indexString = "";
		for (var i=0; i<ddObj1.childNodes.length; i++) {
			if (i>0) {
				indexString += ";";
			}
			indexString += ddObj1.childNodes[i].id.replace("ap_","");
			indexString += ",";
			indexString += (ddObj1.childNodes[i].hasClassName("hide"))?"1":"0";
		}
		indexString += "|";
		for (var i=0; i<ddObj2.childNodes.length; i++) {
			if (i>0) {
				indexString += ";";
			}
			indexString += ddObj2.childNodes[i].id.replace("ap_","");
			indexString += ",";
			indexString += (ddObj2.childNodes[i].hasClassName("hide"))?"1":"0";
		}
		showDdTop("<span id=\"ddTop_AS_Info\"></span><input id=\"ddTop_AS_Submit\" type=\"image\" value=\"保存修改\" src=\"" + ImgPath + "img/cn/b/s1.gif\" onclick=\"indexUpdate();\" />");
		
	} else {
		indexString = null;
	}
}
function indexUpdate() {
	if (indexString) {
		$("ddTop_AS_Submit").disable = true;
		var option={
			parameters:"?action=chat&op=apsave&is=" + indexString + "&rd=" + Math.random(),
			method:"get",
			onSuccess:function(transport){
				showAlert("保存成功。",500);
			},
			onFailure:function(transport){ }
		}
		var request=new Ajax.Request(AjaxUrl, option)
		hideDdTop();
		indexString = null;
	}
}
function showDdTop(s) {var obj = $("ddTop");if (obj) {obj.innerHTML = s;obj.style.display = "";}}
function hideDdTop(){var obj = $("ddTop");if(obj){obj.innerHTML = "";obj.style.display = "none";}}
function getCookie(c_name){if (document.cookie.length>0){c_start=document.cookie.indexOf(c_name + "=");if (c_start!=-1){c_start=c_start + c_name.length+1;c_end=document.cookie.indexOf(";",c_start);if (c_end==-1) c_end=document.cookie.length;var _result = document.cookie.substring(c_start,c_end);return decodeURIComponent(_result);}}return null;}
function setCookie(c_name,value,expiredays){value = encodeURIComponent(value);var exdate=new Date();exdate.setTime(exdate.getTime()+(expiredays*24*3600*1000));document.cookie=c_name+ "=" +value+";path=/"+((expiredays==null)?"":";expires="+exdate.toGMTString());}
var showGuide=(getCookie("showGuide")==null?0:getCookie("showGuide"));
function shiftGuide(){if(showGuide==null||showGuide==0){showGuide = 1;setCookie("showGuide",1,300);}else{showGuide = 0;setCookie("showGuide",0,300);}}
var taskTimeout = null;
var taskJson=[{ "ty":9, "fi":"0", "fn":"系统", "ti":"0", "tn":"所有人", "cl":"0", "msg":"欢迎进入副本任务聊天室。","st":(new Date()) }];
function taskSend() {
	var Messenger = $("taskMsgInput").value;
	
	if (Messenger) {
		var option={
			parameters:"?action=task&op=send&ct=0&ti=0&msg=" + encodeURIComponent(Messenger) + "&rd=" + Math.random(),
			method:"get",
			onSuccess:function(transport){
				$("taskMsgInput").value = "";
				$("taskMsgInput").focus();
			},
			onFailure:function(transport){ }
		}
		var request=new Ajax.Request(AjaxUrl, option);
	}else{
		$("taskMsgInput").focus();
	}
};
function getTaskHint() {
	var prm = "";
	if (taskTimeout==null) {
		prm = "?action=task&op=get&ga=1&rd=" + Math.random();
	} else {
		prm = "?action=task&op=get&rd=" + Math.random();
	}
	var option={
		parameters:prm,
		method:"get",
		onSuccess:function(json){
			taskTimeout = setTimeout(getTaskHint,1000);
			if (taskJson.length>0) {
				taskView();
			}
			taskJson = eval("(" + json.responseText + ")");
			taskView();
		},
		onFailure:function(json){
			taskTimeout = setTimeout(getTaskHint,1000);
		}
	}
	var request=new Ajax.Request(AjaxUrl, option)
}

function taskView() {
	if (taskJson) {
		while(taskJson.length>0) {
			var objChat = taskJson.shift();
            if (objChat){
                var sHtml = "";
                switch (objChat.ty){
                    case 0 :sHtml += "<a href=\"sim_spieler.aspx?uid="+objChat.fi+"\">" + objChat.fn + "</a>说：";sHtml += "<span class=\"ChatColor_" + objChat.cl + "\">" + objChat.msg + "</span>";break;
                    case 9 :sHtml += "<span>【系统】" + HtmlDecode(objChat.msg) + "</span>";break;
                    case 10:sHtml += "<span>【消息】" + HtmlDecode(objChat.msg) + "</span>";break;
                    case 12:if(SubmitConfirm(objChat.fn)==true){eval(HtmlDecode(objChat.msg));}break;
                    case 13:eval(HtmlDecode(objChat.msg));break;
                    default:sHtml += "<span>【帮助】" + HtmlDecode(objChat.msg) + "</span>";break;
                }
                if(sHtml!=""){
                    taskListAdd(sHtml, objChat.ty);
                }
            }
		}
	}	
}

function taskListAdd(sHtml, sClass) {
	var objUl = $("taskList");
	if (objUl) {
		var objLi = document.createElement("LI");
		if (sClass) {
			objLi.className = "ChatBg_" + sClass;
		}
		objLi.innerHTML = sHtml;
		objUl.appendChild(objLi);
		objUl.scrollTop = objUl.scrollHeight; 
			
		if (objUl.childNodes.length > 50) {
			objUl.removeChild(objUl.childNodes[0]);
		}
	}	
}
var hintTimeout = null;var hintJson=[{ "ty":9, "fi":"0", "fn":"系统", "ti":"0", "tn":"所有人", "cl":"0", "msg":"欢迎进入"+ChatName+"。","st":(new Date()) }];
function questionSend() {
	var Messenger = $("questionMsgInput").value;
	if (Messenger) {
		var option={
			parameters:"?action=hint&op=send&ct=0&ti=0&msg=" + encodeURIComponent(Messenger) + "&rd=" + Math.random(),
			method:"get",
			onSuccess:function(json){
				$("questionMsgInput").value = "";
				$("questionMsgInput").focus();
			},
			onFailure:function(json){}
		};
		var request=new Ajax.Request(AjaxUrl, option)
	}else{
		$("questionMsgInput").focus();
	}
}

function getSystemHint() {
	var prm = "";
	if (hintTimeout==null) {
		prm = "?action=hint&op=get&ga=1&rd=" + Math.random();
	} else {
		prm = "?action=hint&op=get&rd=" + Math.random();
	}
	var option={
		parameters:prm,
		method:"get",
		onSuccess:function(json){
			hintTimeout = setTimeout(getSystemHint,3000);
			if (hintJson.length>0) {
				hintView();
			}
			hintJson = eval("(" + json.responseText + ")");
			hintView();
		},
		onFailure:function(json){
			hintTimeout = setTimeout(getSystemHint,3000);
		}
	}
	var request=new Ajax.Request(AjaxUrl, option)
}
function hintView(){
    if (hintJson){
        while(hintJson.length>0){
            var objChat = hintJson.shift();
            if (objChat){
                var sHtml = "";
                switch (objChat.ty){
                    case 0 :sHtml += "<a href=#getContent(\"lmid2\",\"spieler&uid=" + objChat.fi + "\");>" + objChat.fn + "</a>说：";sHtml += "<span class=\"ChatColor_" + objChat.cl + "\">" + objChat.msg + "</span>";break;
                    case 9 :sHtml += "<span>【系统】" + HtmlDecode(objChat.msg) + "</span>";break;
                    case 10:sHtml += "<span>【消息】" + HtmlDecode(objChat.msg) + "</span>";break;
                    case 12:if(SubmitConfirm(objChat.fn)==true){eval(HtmlDecode(objChat.msg));}break;
                    case 13:eval(HtmlDecode(objChat.msg));break;
                    default:sHtml += "<span>【帮助】" + HtmlDecode(objChat.msg) + "</span>";break;
                }
                if(sHtml!=""){hintListAdd(sHtml, objChat.ty);}
            }
        }
    }
}
function hintListAdd(sHtml, sClass) {
	var objUl = $("hintList");
	if (objUl) {
		var objLi = document.createElement("LI");
		if (sClass) {
			objLi.className = "ChatBg_" + sClass;
		}
		objLi.innerHTML = sHtml;
		objUl.appendChild(objLi);
		objUl.scrollTop = objUl.scrollHeight; 
			
		if (objUl.childNodes.length > 50) {
			objUl.removeChild(objUl.childNodes[0]);
		}
	}	
}
var ChatTimeout = null;
var ChatJson=[{ "ty":9, "fi":"0", "fn":"系统", "ti":"0", "tn":"所有人", "cl":"0", "msg":"欢迎来到WEBATTLE联盟聊天室。","st":(new Date()) }]
function ChatSend() {
	var ToUserId = $("ChatSelectUser").value;
	var Color = $("ChatColor").value;
	var ChatType = ($("ChatType").value=="公") ? 0 : 1;
	var Messenger = $("ChatMsgInput").value;
	
	if (Messenger) {
		var option={
			parameters:"?action=chat&op=send&ct=" + ChatType + "&cl=" + Color + "&ti=" + ToUserId + "&msg=" + encodeURIComponent(Messenger) + "&rd=" + Math.random(),
			method:"get",
			onSuccess:function(transport){
				$("ChatMsgInput").value = "";
				$("ChatMsgInput").focus();
			},
			onFailure:function(transport){ }
		}
		var request=new Ajax.Request(AjaxUrl, option)
	}else{
		$("ChatMsgInput").focus();
	}
}

function getChatJson() {
	var prm = "";
	if (ChatTimeout==null) {
		prm = "?action=chat&op=get&ga=1&rd=" + Math.random();
	} else {
		prm = "?action=chat&op=get&rd=" + Math.random();
	}
	var option={
		parameters:prm,
		method:"get",
		onSuccess:function(json){
			ChatTimeout = setTimeout(getChatJson,1000);
			if (ChatJson.length>0) {
				ChatView();
			}
			ChatJson = eval("(" + json.responseText + ")");
			ChatView();
		},
		onFailure:function(json){
			ChatTimeout = setTimeout(getChatJson,1000);
		}
	}
	var request=new Ajax.Request(AjaxUrl, option)
}

function ChatView() {
	if (ChatJson) {
		while(ChatJson.length>0) {
			var objChat = ChatJson.shift();
			if (objChat) {
				var sHtml = "";
				switch (objChat.ty) {
					case 1:
						if (objChat.fi==objChat.ti) {
							sHtml += "你对自己说：";
							sHtml += "<span class=\"ChatColor_" + objChat.cl + "\">" + objChat.msg + "</span>";
						} else {
							sHtml += "<a href=\"javascript:;\" onclick=\"ChatSelectUser(" + objChat.fi + ",'" + objChat.fn + "')\">" + objChat.fn + "</a>对你说：";
							sHtml += "<span class=\"ChatColor_" + objChat.cl + "\">" + objChat.msg + "</span>";
						}
						break;
					case 2:
						if (objChat.fi==objChat.ti) {
							sHtml += "你小声的对自己说：";
							sHtml += "<span class=\"ChatColor_" + objChat.cl + "\">" + objChat.msg + "</span>";
						} else {
							sHtml += "<a href=\"javascript:;\" onclick=\"ChatSelectUser(" + objChat.fi + ",'" + objChat.fn + "')\">" + objChat.fn + "</a>悄悄地对你说：";
							sHtml += "<span class=\"ChatColor_" + objChat.cl + "\">" + objChat.msg + "</span>";
						}
						break;
					case 3:
						sHtml += "你对<a href=\"javascript:;\" onclick=\"ChatSelectUser(" + objChat.ti + ",'" + objChat.tn + "')\">" + objChat.tn + "</a>说：";
						sHtml += "<span class=\"ChatColor_" + objChat.cl + "\">" + objChat.msg + "</span>";
						break;
					case 4:
						sHtml += "你悄悄地对<a href=\"javascript:;\" onclick=\"ChatSelectUser(" + objChat.ti + ",'" + objChat.tn + "')\">" + objChat.tn + "</a>说：";
						sHtml += "<span class=\"ChatColor_" + objChat.cl + "\">" + objChat.msg + "</span>";
						break;
					case 5:
						sHtml += "<span class=\"ChatColor_0\"><a href=\"javascript:;\" onclick=\"ChatSelectUser(" + objChat.fi + ",'" + objChat.fn + "')\">" + objChat.fn + "</a>对<a href=\"javascript:;\" onclick=\"ChatSelectUser(" + objChat.ti + ",'" + objChat.tn + "')\">" + objChat.tn + "</a>说：";
						sHtml += "消息被您屏蔽。</span>";
						break;
					case 9:
						sHtml += "<span class=\"ChatColor_" + objChat.cl + "\">【系统消息】" + objChat.msg + "</span>";
						break;
					default:
						sHtml += "<a href=\"javascript:;\" onclick=\"ChatSelectUser(" + objChat.fi + ",'" + objChat.fn + "')\">" + objChat.fn + "</a>对<a href=\"javascript:;\" onclick=\"ChatSelectUser(" + objChat.ti + ",'" + objChat.tn + "')\">" + objChat.tn + "</a>说：";
						sHtml += "<span class=\"ChatColor_" + objChat.cl + "\">" + objChat.msg + "</span>";
						break;
				
				}
                if(sHtml!=""){
    				ChatListAdd(sHtml, objChat.ty);
                }
			}
		}
	}	
}

function ChatListAdd(sHtml, sClass) {
	var objUl = $("ChatList");
	if (objUl) {
		var objLi = document.createElement("LI");
		if (sClass) {
			objLi.className = "ChatBg_" + sClass;
		}
		objLi.innerHTML = sHtml;
		objUl.appendChild(objLi);
		objUl.scrollTop = objUl.scrollHeight; 
			
		if (objUl.childNodes.length > 50) {
			objUl.removeChild(objUl.childNodes[0]);
		}
	}	
}

function ChatSelectUser(ui, un) {
	var objSel = $("ChatSelectUser");
	if (objSel) {
		$("ChatMsgInput").focus();
		for (var i=0; i<objSel.options.length; i++) {
			if (objSel.options[i].value==ui) {
				objSel.options[i].selected = true;
				return "";
			}
		}
		var objOpt = document.createElement("OPTION");
		objSel.options.add(objOpt);
		objOpt.text = un;
		objOpt.value = ui;
		objOpt.selected = true;
	}
}
function ChatBlockUser(){var ui = $("ChatSelectUser").value;if(ui==0){ChatListAdd("<span class=\"c\">【系统消息】您选择的用户无效。</span>");}else{var option={parameters:"?action=chat&op=block&ui=" + ui + "&rd=" + Math.random(),method:"get"};var request=new Ajax.Request(AjaxUrl, option);}}
function ChatSwitchPrivate(obj) {if (obj.value=="私") {obj.value = "公";obj.src = "images/chat_public.gif";obj.title = "现在处于公聊状态，点击切换至私聊。";}else{obj.value = "私";obj.src = "images/chat_private.gif";obj.title = "现在处于私聊状态，点击切换至公聊。";}}
function ChatBoxHide() {if ($("ChatOperation").style.display=="") {$("ChatOperation").style.display = "none";$("ChatSend").style.display = "none";} else {$("ChatOperation").style.display = "";$("ChatSend").style.display = "";}}
function ChatRoomClear() {var objUl = $("ChatList");if (objUl) {objUl.innerHTML = "";}}
function StartUp(id) {
    UserId = id;
    if ($("ChatRoom")) {getChatJson();}
    if (($("ddLeft"))&&($("ddRight"))) {ddStart();}
    if ($("hintRoom")) {getSystemHint();}
    if ($("taskRoom")) {getTaskHint();}
    start();LinkShow();GuideOpen();
}
function ddStart() {Sortable.create("ddLeft",{tag:"div",dropOnEmpty:true,handle:"ddHandle",containment:["ddLeft","ddRight"],constraint:false,onUpdate:indexChange});Sortable.create("ddRight",{tag:"div",dropOnEmpty:true,handle:"ddHandle",containment:["ddLeft","ddRight"],constraint:false,onUpdate:indexChange});}
function ddHide(apId) {var apObj = $("ap_"+apId);if (apObj) {if (apObj.hasClassName("hide")) {apObj.removeClassName("hide");}else{apObj.addClassName("hide");}indexChange();}}
function ddClose(apId) {var apObj = $("ap_"+apId);if (apObj) {apObj.parentNode.removeChild(apObj);indexChange();}}
function ddAdd(){var option={parameters:"?action=chat&op=apadd&rd=" + Math.random(),method:"get",onSuccess:function(transport){if (transport.responseText=="0") {showAlert("您现在没有可供添加的模块",1000);} else {showDdTop(transport.responseText);}},onFailure:function(transport){}};var request=new Ajax.Request(AjaxUrl, option);}
function EquipStart(){
    Droppables.drops = [];
    var obj1 = $("herosim");
    if (obj1){
        var objD = obj1.getElementsByTagName("DIV");
        for(var i=0; i<objD.length; i++){
            Droppables.add(
                objD[i],
                {
                    hoverclass:"eba",
                    onDrop:function(element,dropon) { 
                        EquipSwitch(element, dropon);
                    }
                }
            );
            objD[i].ondblclick=function(){
                EquipStrip(this);
            }
        }
        var objE = obj1.getElementsByTagName("IMG");
        for (var i=0; i<objE.length; i++){
            new Draggable(objE[i], {revert:true})
        }
    }
    var obj2 = $("equipbox");
    if (obj2) {
        var objI = obj2.getElementsByTagName("IMG");
        for (var i=0; i<objI.length; i++) {
            new Draggable(objI[i], {revert:true})
        }
    }
    var obj3 = $("equipmarket88");
    if (obj3){
        Droppables.add(
            obj3, 
            { 
                hoverclass:"equipmarketaa", 
                onDrop:function(element,dropon) {if (SubmitConfirm("你确认要将该宝物卖给电脑商人？")) { EquipSwitch(element, dropon); }}
            }
        )
    }
    var obj4 = $("equipmarket99");
    if (obj4){
        Droppables.add(
            obj4, 
            { 
                hoverclass:"equipmarketba", 
                onDrop:function(element,dropon) {if (SubmitConfirm("你确认要卖出该宝物？")) { EquipSwitch(element, dropon); } }
            }
        )
    }
};
function Str2Int(s) {var re = /[1-9]\d*/i;return atoi(s.match(re));}
var _EquipE, _EquipD;
function EquipSwitch(objE, objD) {
	_EquipE = objE;
	_EquipD = objD;
	var prm = "?action=equip&op=equipswitch&sc="+$('sc_state').value+"&ei=" + Str2Int(objE.id) + "&es=" + Str2Int(objD.id) + "&rd=" + Math.random();
	var option={
		parameters:prm,
		method:"get",
		onSuccess:function(transport){
			if (transport.responseText=="0") {
				if ((_EquipD)&&(_EquipE)) {EquipTakeoff(_EquipD);_EquipD.appendChild(_EquipE);}
			}else{
				switch (transport.responseText) {
					case "1":{showAlert("装备位置不合适。",2000);break;}
					case "-1":{showAlert("参数有误。");break;}
					case "2":{showAlert("操作失败。");break;}
					default:{EquipTakeoff(_EquipD);_EquipD.appendChild(_EquipE);_EquipD.removeChild(_EquipE);showAlert(transport.responseText);break;}
				}
			}
			_EquipD = null;
			_EquipE = null;
			EquipGetHeroState();
		},
		onFailure:function(transport){
            TipClose();
			alert("超时错误，请稍候再试。");
			_EquipD = null;
			_EquipE = null;
		}
	}
	var request=new Ajax.Request(AjaxUrl, option)
}

function EquipStrip(obj) {
	var objE = obj.getElementsByTagName("IMG");
	var objD = $("equipbox");
	if ((objD)&&(objE.length>0)) {EquipSwitch(objE[0], objD);}
}

function EquipTakeoff(obj) {
	TipClose();
	if ((obj)&&(obj.id!="equipbox")&&(obj.id!="equipmarket99")&&(obj.id!="equipmarket88")) {
		var objI = obj.getElementsByTagName("IMG");
		if (objI.length>0) {
			var objE = $("equipbox");
			for (var i=0; i<objI.length; i++) {
				objE.appendChild(objI[i]);
			}
		}
	}
}

function EquipGetHeroState() {
	var objHs = $("herostate");
	if (objHs) {
		var prm = "?action=equip&op=herostate&sc="+$('sc_state').value+"&rd=" + Math.random();
		var option={
			parameters:prm,
			method:"get",
			onSuccess:function(transport){
				$("herostate").innerHTML = transport.responseText;
			},
			onFailure:function(transport){
				$("herostate").innerHTML = "";
			}
		}
		var request=new Ajax.Request(AjaxUrl, option);
		objHs.innerHTML = "Loading...";
	}
}
function AvatarSelect(id) {var obj = $("avatardemo");if (obj) {obj.src = "images/avatar/avatar_u" + id + ".gif"}}
function LinkHandle() {
	var g1 = document.getElementsByTagName("H1");
	var d = "";
	if (g1.length>0) {
		if (g1[0].textContent) {
			d = HtmlEncode(g1[0].textContent);
		}else{
			d = HtmlEncode(g1[0].innerText);
		}
	}
	var n = prompt("请输入链接名称。如：兵营",d);
	if (!isNotNull(n)) return;
	var re = /[^\/]*$/;
	var g = window.location.toString().match(re);
	var l = prompt("请输入链接地址。",g);
	if (!isNotNull(l)) return;
	LinkAdd(n,l);
}

function LinkAdd(n,l) {
	var g = getCookie("CustomLink_" + UserId);
	if (g) {
		var g1 = g.split("$$$");
		g = "";
		for (var i=0; i<g1.length; i++) {
			if ((g1[i])&&(g1[i].split("|||").length==2)) {
				if (g) {
					g += "$$$";
				}
				g += g1[i];
			}
		}
	}
	if (g) {g += "$$$" + n + "|||" + l;}else{g = n + "|||" + l;}
	setCookie(("CustomLink_" + UserId), g, 300);
	LinkShow();
}

function LinkDelete(ob){
    if (SubmitConfirm("是否删除这个链接？")) {
        var delId;
	    if(ob==null||ob.id==null){
    		delId = Str2Int(this.id);
	    }
	    else{
    		delId = Str2Int(ob.id);
	    }
		var g = getCookie("CustomLink_" + UserId);
		var g1 = g.split("$$$");
		g = "";
		for (var i=0; i<g1.length; i++) {
			if ((i!=delId)&&(g1[i])&&(g1[i].split("|||").length==2)) {
				if (g) {
					g += "$$$";
				}
				g += g1[i];
			}
		}
		setCookie(("CustomLink_" + UserId), g, 300);
		LinkShow();
	}
}

function LinkShow() {
	var obj = $("CustomLink");
	if (obj) {
		obj.innerHTML = "";
		var g = getCookie("CustomLink_" + UserId);
		if (isNotNull(g)) {
		    var g1 = g.split("$$$");
		    for (var i=0; i<g1.length; i++) {
		        var g2 = g1[i].split("|||");
		        if (g2.length==2) {
	                var tmpA = document.createElement("A");
	                tmpA.innerHTML = g2[0];tmpA.href = g2[1];
	                var tmpB = document.createElement("IMG");
	                tmpB.src = "images/del.gif";
	                tmpB.id = "cldid_" + i;
	                tmpB.onclick = LinkDelete;
	                var tmpD = document.createElement("DIV");
	                tmpD.className = "CustomLink";
	                tmpD.appendChild(tmpA);
	                tmpD.appendChild(tmpB);
	                obj.appendChild(tmpD);
		        }
		    }
		}
	}
}

function cardShow(s,tp){
    if(tp){
        TipOut();
        LightBoxOpen("<div style=\"width:440px; height:569px; background:#000 url("+s+") no-repeat 0 0; position:relative;\"><div id=\"merry_content\" style=\"padding:45px; font-size:16px; line-height:180%;\"></div><div style=\"position:absolute; bottom:40px; width:100%; text-align:center;\"><a href=\"javascript:;\" onclick=\"LightBoxClose();\"><img src=\"images/GuideClose.gif\" /></a></div></div>");
        getDepart("merry_content","cardMgr&tp="+tp);
    }else{
        LightBoxOpen("<div style=\"width:440px; height:569px; background:#000 url("+s+") no-repeat 0 0; position:relative;\"><div id=\"merry_content\" style=\"padding:45px; font-size:16px; line-height:180%;\"></div><div style=\"position:absolute; bottom:40px; width:100%; text-align:center;\"><a href=\"javascript:;\" onclick=\"LightBoxClose();\"><img src=\"images/GuideClose.gif\" /></a></div></div>");
        getDepart("merry_content","cardMgr&tp=0");
    }
};
function GuideOpen() {
	var obj = $("GuideSpan");
	if ((obj)&&(isNotNull(obj.innerHTML))) {
		LightBoxOpen("<div class=\"Guide\"><div class=\"Content\">" + obj.innerHTML + "</div><div class=\"Close\"><a href=\"javascript:;\" onclick=\"LightBoxClose();\"><img src=\"images/GuideClose.gif\" /></a></div></div>");
	}
	showGuide=(getCookie("showGuide")==null?0:getCookie("showGuide"));
	var hasShowGuide=(getCookie("hasShowGuide")==null?0:getCookie("hasShowGuide"));
	if((showGuide==null||showGuide==0)&&hasShowGuide==0){
		c=$("ce");
		if(c!=null){
			var aF="<div class=\"popup3\"><iframe frameborder=\"0\" id=\"Frame\" src=\"manual.aspx?s=1&typ=6\" width=\"412\" height=\"440\" border=\"0\"></iframe><div style=\"position:absolute; top:7px; left:320px;\"><input type=\"checkbox\" CHECKED id=\"newUserGuide\" name=\"newUserGuide\" align=\"bottom\" onClick=\"javascript:shiftGuide();\"><span>登录时显示</span></div></div><a href=\"#\" onClick=\"Close()\"><img src=\"" + ImgPath + "img/un/a/x.gif\" border=\"1\" class=\"popup4\" alt=\"Close\"></a>";
			c.innerHTML=aF;
			setCookie("hasShowGuide",1,1);
		}
	}
}
function CopyToClipBoard() {var clipBoardContent='';try{if (arguments[0]){clipBoardContent = arguments[0];};window.clipboardData.setData("Text",clipBoardContent);showAlert("已经拷贝到剪贴板.",1000);}catch(error){alert(error,"系统错误");}}
function AvatarDemoUpdate() {
	var ssize = $("AvatarDemoSize");
	var scode = $("AvatarDemoCode");
	if ((ssize)&&(scode)) {
		var re = /\/[^\/]*$/;
		var hostUrl = document.location.toString();
		hostUrl = hostUrl.replace(re,"");

	
		var picUrl = "";
		var aUrl = hostUrl + "/welcome" + UserId + ".do";
		switch (ssize.value) {
			case "1":picUrl = hostUrl + "/avatar/" + UserId + ".jpg";break;
			case "2":picUrl = hostUrl + "/avatar/f" + UserId + ".jpg";break;
		}
		if ($("AvatarDemoImg")) {$("AvatarDemoImg").src = picUrl;}
		if ($("AvatarDemoUrl")) {$("AvatarDemoUrl").innerHTML = "图片:" + picUrl + "<br />链接(QQ群发):" + aUrl;}
		if ($("AvatarDemoTextArea")) {
			switch (scode.value) {
				case "1":$("AvatarDemoTextArea").value = "<a href=\"" + aUrl + "\"><img src=\"" + picUrl + "\" /></a>";break;
				case "2":$("AvatarDemoTextArea").value = "[url=" + aUrl + "][img]" + picUrl + "[/img][/url]";break;
			}
		}
	}
}
function AvatarDemoCopy(){var obj = $("AvatarDemoTextArea");if (obj) {CopyToClipBoard(obj.value);}}
function showAlert(alertMessenger,timeout) {var obj = $("tb_alert");if (!obj) {obj = document.createElement("DIV");obj.id = "tb_alert";document.getElementsByTagName("BODY")[0].appendChild(obj);};if (obj) {obj.innerHTML = alertMessenger;obj.style.display = "";setAbsCenter(obj);alertOpacity = 100;changeOpacity("tb_alert",alertOpacity);if(typeof timeout=="undefined"){var timeout = 200;};setTimeout("clearAlert()",timeout);}}
function clearAlert(){alertOpacity = alertOpacity - 5;if (alertOpacity > 4) {changeOpacity("tb_alert",alertOpacity);setTimeout("clearAlert()",30);} else {alertOpacity = 0;$("tb_alert").style.display = "none";}}
function showLoading(){var obj = $("tb_loading");if (obj) {obj.style.width = "205px";obj.style.height = "56px";obj.style.top = (atoi(getScrollTop()) + atoi(getWinHeight()) - 58) + "px";var retHtml = "";retHtml += "<span style=\"width:32px; height:32px; float:left; position:absolute; left: 11px; top: 13px;\"><img src=\"/images/loadingModule.gif\" width=\"32\" height=\"32\" /></span>";retHtml += "<div style=\" width: 152px; height: 34px; position:absolute; left: 50px; top: 21px; font-size:14px;\">载入中，请稍候……</div>\n";obj.innerHTML = retHtml;obj.style.display = "";}};
function hideLoading(){if ($("tb_loading")) {$("tb_loading").style.display = "none";}};
function execHtmlScript(text){
    var scripts = text.match(/\<script[^>]*\>[\s\S]*?\<\/script\>/ig);
    if(scripts&&scripts.length>0){
        for(var i=0;;i++){
            if(scripts[i]){
                eval(scripts[i].replace(/\<script[^>]*\>/ig,"").replace(/\<\/script\>/ig,""));
            }
            else{
                break;
            }
        }
    }
};
function getDepartHtml(cId,param){contain = $(cId);if(contain){contain.innerHTML = param;}};
function getDepart(cId,param){
    var option={
        parameters:"?action="+param+"&rm="+Math.random(),
        method:"get",
        onSuccess:function(transport){
            MenuClose();
            contain = $(cId);
            if(contain){
                contain.innerHTML = transport.responseText;
            }
        },
        onFailure:function(transport){MenuClose();}
    };
    var request = new Ajax.Request(AjaxUrl, option);
};
function rfSC(){
    var option={
        parameters:"?action=simcityList&rm="+Math.random(),
        method:"get",
        onSuccess:function(transport){
            contain = $("simcityList");
            if(contain){
                contain.innerHTML = transport.responseText;
                sAT();
            }
        },
        onFailure:function(transport){}
    };
    var request = new Ajax.Request(AjaxUrl, option);
};
function setRes(param){contain = $("lres0");if(contain){contain.innerHTML = param;sRT();}};
function quickBuild(h,c){if($("lbau2")){getContent("lmid2","dorf2&d="+h+"&a=1&c="+c);}else if($("lbau1")){getContent("lmid2","dorf1&d="+h+"&a=1&c="+c);}};
function CAL(obj){$("d_build").href="dorf1.aspx#getContent('lmid2','building&gid="+$('b_gid').value+"&a=18816&abriss="+obj.value+"');";};
function setAuto(e,s){if($('u_auto')){if(e){$('u_auto').innerHTML="<A href=dorf1.aspx#getContent('lmid2','plus&id=3');>电脑托管中</A><br/>&nbsp;&nbsp;&nbsp;<SPAN class='activetimer'>" + s + "</SPAN> <br/>";}else{$('u_auto').innerHTML = "";}sAT();}};
function train(g,u,z,a,c){
    var str = "";for(var i=1;i<=10;i++){str+="&t"+i+"="+($("train_"+i)?$("train_"+i).value:0);}
    getContent("lmid2","building&gid="+g+"&id=" + u + "&z=" + z + "&a=" + a + "&c=" + c + str);
}
function sendRes(g,u,a,c,k){
    var str = "";for(var i=1;i<=4;i++){str+="&r"+i+"="+($("r"+i)?$("r"+i).value:0);}
    getContent("lmid2","building&gid="+g+"&id=" + u + "&a=" + a + "&sz=" + c + "&kid=" + k + str);
}
function preSendRes(g,u){
    var str = "";for(var i=1;i<=4;i++){str+="&r"+i+"="+($("r"+i)?$("r"+i).value:0);}
    getContent("lmid2","building&gid="+g+"&id=" + u + str + "&x="+$("sim_x").value+"&y="+$("sim_y").value+"&dname="+HtmlEncode($("dname").value));
}
function historyInit(){
    window.dhtmlHistory.create({toJSON: function(o){return JSON.stringify(o);},fromJSON: function(s){return JSON.parse(s);}});
    if (document.all){ 
        window.attachEvent("onload",hisInit)//对于IE 
    } 
    else{ 
        window.addEventListener("load",hisInit,false);//对于FireFox 
    }  
};
function hisInit(){
    try{
        dhtmlHistory.initialize();
        dhtmlHistory.addListener(historyChangeEvent);
        var loc = document.location.href.split("#");
        if(loc[1]&&loc[1]!=""){
            hisUrl = loc[1];
            var exec = HtmlDecode(loc[1]);
            if(exec!=""){eval(exec);}
        }else if(document.location.href.indexOf("dorf1.aspx")!=-1&&document.location.href.indexOf("sim_")==-1){
            getContent("lmid2","dorf1");
        }
    }catch(e){}
};
var hisUrl = "",logger=false;
var historyChangeEvent = function(newLocation, historyData) {
    if(newLocation!=""){
        try{
            if(newLocation!=hisUrl){
                hisUrl = newLocation;
                eval(HtmlDecode(newLocation));
            }
        }catch(e){}
    }
};
var jxNum=0;
function getContent(cId,param){
    var od = jxNum;
    showLoading();
    try{if(logger==true){var loc = document.location.href.split("#");if(loc[1]){dhtmlHistory.add(loc[1],false);}};logger=true;}catch(e){hideLoading();}
    var option={
        parameters:"?action=content&op="+param+"&rm="+Math.random(),
        method:"get",
        onSuccess:function(transport){
            pause=false;
            hideLoading();TipClose();MenuClose();closeLightbox();
            if(od==jxNum){
                jxNum++;
                contain = $(cId);
                if(contain){
                    contain.innerHTML = transport.responseText;
                    sET($(cId));
                    execHtmlScript(transport.responseText);
                };
            };
        },
        onFailure:function(transport){hideLoading();TipClose();MenuClose();pause=false;}
    };
    var request = new Ajax.Request(AjaxUrl, option);
};
function TaskHint(){LightBoxClose();getJs("op=taskHint");}
function TaskDesc(){LightBoxClose();getJs("op=taskDesc");}
function publishReport(s,t){getJs("op=pr&s="+s+"&t="+t);}
function getJs(p){
	var option={
		parameters:"?action=getJs&" + p + "&rd=" + Math.random(),
		method:"get",
		onSuccess:function(transport){
		    eval(transport.responseText);
		},
		onFailure:function(transport){ }
	}
	var request=new Ajax.Request(AjaxUrl, option);
};
function usercard(){
	var option={
		parameters:"?action=usercard&cn="+$("vip_card").value+"&rd=" + Math.random(),
		method:"get",
		onSuccess:function(transport){
		    $("vip_card").value = "";
		    showAlert(transport.responseText);
		},
		onFailure:function(transport){ 
		    showAlert("验证失败，请稍后再试");
		}
	}
	var request=new Ajax.Request(AjaxUrl, option);
};

//RES
var overall;
function calculateRes() {
	resObj=document.getElementsByName("m2");
	overall=0;
	for (i=0; i<resObj.length; i++) {
		var tmp="";
		for (j=0; j<resObj[i].value.length; j++)
			if ((resObj[i].value.charAt(j)>="0") && (resObj[i].value.charAt(j)<="9")) tmp=tmp+resObj[i].value.charAt(j);
		resObj[i].value=tmp;
		if (tmp=="") tmp="0";
		newRes=Math.round(parseInt(tmp)*summe/100);
		if (((i<3) && (newRes<=max123)) || ((i==3) && (newRes<=max4)))
			newHTML=newRes;
		else
			newHTML="<span style='color:#FF4000'>"+newRes+"</span>";
		$("new"+i).innerHTML=newHTML;
		overall+=parseInt(tmp);
	};
	$("overall").innerHTML=overall+"%";
};
function getValueStr(obj) {
    var str='';
	for (i=0; i<obj.length; i++) {
        if(str!='')str+=','; 
        str += obj[i].value==''?'0':obj[i].value;
    };
    return str;
};
function normalize() {
	calculateRes();
	resObj=document.getElementsByName("m2");
	for (i=0; i<resObj.length; i++) {
		tmp=parseInt(resObj[i].value);
		tmp=tmp*(100/overall);
		resObj[i].value=Math.round(tmp);
	};
	calculateRes();
};
function calculateRest() {
	resObj=document.getElementsByName("m2[]");
	overall=0;
	for (i=0; i<resObj.length; i++) {
		var tmp="";
		for (j=0; j<resObj[i].value.length; j++){
			if ((resObj[i].value.charAt(j)>="0") && (resObj[i].value.charAt(j)<="9")) 
			    tmp=tmp+resObj[i].value.charAt(j);
		}
		if (tmp=="") {
			tmp="0";
			newRes=0;
			resObj[i].value="";
		} else {
			newRes=parseInt(tmp);
			if ((i<3) && (newRes>max123)) newRes=max123;
			if ((i==3) && (newRes>max4)) newRes=max4;
			resObj[i].value=newRes;
		};
		dif=newRes-parseInt($("org"+i).innerHTML);
		newHTML=dif;
		if (dif>0) newHTML="+"+dif;
		$("diff"+i).innerHTML=newHTML;
		overall+=newRes;
	};
	$("newsum").innerHTML=overall;
	rest=parseInt($("org4").innerHTML)-overall;
	$("remain").innerHTML=rest;
	testSum();
};
function fillup(nr) {
	resObj=document.getElementsByName("m2[]");
	if (nr<3) {
		resObj[nr].value=max123;
	} else {
		resObj[nr].value=max4;
	};
	calculateRest();
};
function portionOut() {
	restRes=parseInt($("remain").innerHTML);
	rest=restRes;
	resObj=document.getElementsByName("m2[]");
	nullCount=0;
	notNullCount=0;
	for (j=0; j<resObj.length; j++) {
		if ((restRes>0) && (resObj[j].value=="")) nullCount++;
		if ((restRes<0) && (resObj[j].value!="")) notNullCount++;
	};
	nullCount2=0;
	if (restRes>0) {
		if (nullCount==0) {
			for (i=0; i<resObj.length; i++) {
				free=max123-parseInt(resObj[i].value);
				resObj[i].value=(parseInt(resObj[i].value)+Math.round(rest/(4-i)));
				rest=rest-Math.min(free,Math.round(rest/(4-i)));
				if ((i<3) && (parseInt(resObj[i].value)<max123)) nullCount2++;
			};
		} else {
			for (i=0; i<resObj.length; i++) {
				if (resObj[i].value=="") {
					resObj[i].value=Math.round(rest/nullCount);
					rest=rest-Math.round(rest/nullCount);
					nullCount--;
				};
				if ((i<3) && (parseInt(resObj[i].value)<max123)) nullCount2++;
			};
		};
	} else {
		for (j=0; j<resObj.length; j++) {
			if (parseInt(resObj[j].value)>0) {
				resObj[j].value=(parseInt(resObj[j].value)+Math.round(rest/notNullCount));
				rest=rest-Math.round(rest/notNullCount);
				notNullCount--;
			};
		};
	};
	calculateRest();
	if (rest>0) {
		if (max123>max4) {
			for (j=0; j<3; j++) {
				if (parseInt(resObj[j].value)<max123) {
					resObj[j].value=(parseInt(resObj[j].value)+Math.round(rest/nullCount2));
					rest=rest-Math.round(rest/nullCount2);
					nullCount2--;
				};
			};
		} else {
			resObj[3].value=(parseInt(resObj[j].value)+rest);
		};
	};
	calculateRest();
};
function testSum() {
	if ($("remain").innerHTML!=0) {
		$("submitText").innerHTML="<a href='javascript:portionOut();'>（1/2）分配资源</a>";
		$("submitButton").style.display="none";
	} else {
		$("submitText").innerHTML="";
		$("submitButton").style.display="block";
	};
};

var roomId=1;var timeSwitchTab = null;function clearSwitchTab() {clearTimeout(timeSwitchTab);};
function handleSwitchTab(objid,o) {clearTimeout(timeSwitchTab);timeSwitchTab = setTimeout("switchTab(\"" + objid + "\"," + o + ")",100);}
function switchTab(objid,o) {var tobj,cobj;for (var i=1; i<=3; i++) {tobj = $(objid + "_" + i);if ((tobj)) {if (i==o) {roomId=i;tobj.className = "active";}else {tobj.className = "";}}}};
function showNotice(htm) {var retHtml = "";retHtml += "<span class=\"close\" onclick=\"closeLightbox();\">X</span>\n";retHtml += "<div style=\"padding:20px; line-height:160%; width:400px; \" class=\"f12td\">\n";retHtml += htm;retHtml += "</div>\n";openLightbox(retHtml);}
function closeM(id) {var obj = $(id);if (obj&&obj.style.display!="none"){obj.style.display = "none";var aDivs = document.body.getElementsByTagName("select");for(var i=0;i<aDivs.length;i++){aDivs[i].style.display = "";}}};
function openM(id,htm){var aDivs = document.body.getElementsByTagName("select");for(var i=0;i<aDivs.length;i++){aDivs[i].style.display = "none";};var obj = $(id);if (obj) { obj.innerHTML = htm;obj.style.display = "";}};
function openOverlay(){var objOverlay = $("tb_overlay");if(!objOverlay){objOverlay = document.createElement("DIV");objOverlay.id = "tb_overlay";objOverlay.style.display = "none";document.getElementsByTagName("BODY")[0].appendChild(objOverlay);};objOverlay.style.width = getWinWidth() + "px";objOverlay.style.height = Math.max(getWinHeight(),getPageHeight()) + "px";objOverlay.style.display = "";};
function openLightbox(htm) {openOverlay();var objLightbox = $("tb_lightbox");if(!objLightbox){objLightbox = document.createElement("DIV");objLightbox.id = "tb_lightbox";objLightbox.style.display = "none";document.getElementsByTagName("BODY")[0].appendChild(objLightbox);};openM("tb_lightbox",htm);setAbsCenter(objLightbox);};
function closeLightbox() {closeM("tb_lightbox");if($("tb_overlay")){$("tb_overlay").style.display = "none";}};
function frm_radioField(obj,name,dt){
    var es = obj.getElementsByTagName("input");
    for(var i=0;i<es.length;i++){
        if(es[i].type!="radio"||!es[i].checked||es[i].name!=name){continue;};
        eval("dt."+es[i].name.replace(/a2b_/ig,"")+"='"+es[i].value+"'");
    }
};
function frm_submit(action,obj){
    var req={};
    var ary=new Array();
    if(obj){
        var es = obj.getElementsByTagName("select");
        for(var i=0;i<es.length;i++){
            if(es[i].value==""){continue;};
            eval("req."+es[i].id.replace(/a2b_/ig,"")+"='"+es[i].value+"'");
        };
        var es = obj.getElementsByTagName("input");
        for(var i=0;i<es.length;i++){
            switch(es[i].type){
                case "radio":
                    if(es[i].value==""){continue;};
                    frm_radioField(obj,es[i].name,req);
                    break;
                default:
                    if(es[i].name=="array"){
                        ary.push({'id':es[i].id,'value':es[i].value});
                    }
                    else{
                        if(es[i].value==""){continue;};
                        eval("req."+es[i].id.replace(/a2b_/ig,"")+"='"+es[i].value+"'");
                        break;
                    }
            }
        };
        if(ary.length>0){
            var anm=ary[0].id.replace(/a2b_/ig,"").substring(0,1);
            eval("req."+anm+"=[]");
            for(var i=0;i<ary.length;i++){
                var loc = ary[i].id.replace(/a2b_/ig,"").match(/\d+/)[0];
                eval("req."+anm+"["+loc+"-1]=\""+ary[i].value+"\"");
            }
        }
        ajax_call(action,req);
    };
};
