﻿function switchdiv(mainGroupsName, subGroupsName, showIndex, mainShowStyle, mainHiddenStyle) {
    var mainele = document.getElementsByName(mainGroupsName);
    var subele = document.getElementsByName(subGroupsName);
    for (i = 0; i < mainele.length; i++) {
        //bindStyle(mainele[i],mainHiddenStyle);
        mainele[i].className = mainHiddenStyle;
        bindStyle(subele[i], { "visibility": "hidden", "display": "none" });
    }
    if (isNumber(showIndex)) {
        //bindStyle(mainele[showIndex-1],mainShowStyle);
        mainele[showIndex - 1].className = mainShowStyle;
        bindStyle(subele[showIndex - 1], { "visibility": "", "display": "" });
    }
    else {
        //bindStyle(showIndex,mainShowStyle);
        showIndex.className = mainShowStyle;
        bindStyle(showIndex, { "visibility": "", "display": "" });
    }
}
var getSkinPath = function() {
    if (getCookie("skintype") == "")
        return "http://img2.soufun.com/bbs/v3/images/";
    else
        return "http://img2.soufun.com/bbs/v3/skin/" + getCookie("skintype") + "/images/";
}
function openDiv(itemname, status, imgid, closesrc, opensrc) {
    if (($$(itemname, "open") != "true" && status == "") || status == "1") {
        bindStyle($(itemname), { "visibility": "", "display": "" });
        $$(itemname, "open", "true");
        if ($(imgid)) {
            $(imgid).className = "img_treelist_an05";
        }
        return;
    }
    if (($$(itemname, "open") == "true" && status == "") || status == "2") {
        bindStyle($(itemname), { "visibility": "hidden", "display": "none" });
        $$(itemname, "open", "false");
        if ($(imgid)) {
            $(imgid).className = "img_treelist_an03";
        }
        return;
    }
}
function isNumber(oNum) {
    if (!oNum) return false;
    var strP = /^\d+(\.\d+)?$/;
    if (!strP.test(oNum)) return false;
    try {
        if (parseFloat(oNum) != oNum) return false;
    }
    catch (ex) {
        return false;
    }
    return true;
}
function beginShowUserList(sign) {
    if (!$("showuserList")) return;
    if ($$("showuserList", "loaded") != "true") {
        var nocache = new Date().getTime();
        AJAXCALL("/soufun_forum/OwnerForum/BBS_OnlineUser.aspx/sign=" + sign + "&nocache=" + nocache, endShowUserList, { isCache: "false" });
    }
}
function endShowUserList(doc) {
    var data = eval("(" + doc + ")");
    var usercount = 0;
    if ($("showuserlist_all")) $("showuserlist_all").innerHTML = data.allcount.toString();
    if ($("showuserlist_reg")) $("showuserlist_reg").innerHTML = data.regcount.toString();
    if ($("showuserlist_guest")) $("showuserlist_guest").innerHTML = data.guestcount.toString();
    if (data.ManagerList.length > 1 && $("showuserList_manager")) {
        $("showuserList_manager").innerHTML = "";
        $("showuserList_manager").innerHTML = "<ul><li><div class=\"s3\"><img src='http://img1n.soufun.com/bbs/2005_06/24/1119589442369.gif' height='20' /></div></li>";
        var showuserList_managerinnerHTML = "";
        for (i = 0; i < data.ManagerList.length; i++) {
            if (data.ManagerList[i] && data.ManagerList[i].imgsrc)
                showuserList_managerinnerHTML += "<li><div class=\"s1\"><img src=\"" + data.ManagerList[i].imgsrc + "\" /></div><div class=\"s2\"><a href=\"" + data.ManagerList[i].url + "\" title=\"点击进入该用户家庭空间\" target=\"_blank\">" + data.ManagerList[i].username + "</a></div><div class=clear></div></li>";
        }

        $("showuserList_manager").innerHTML += showuserList_managerinnerHTML + "</ul>";
    }
    if (data.UserList.length > 1 && $("showuserList_user")) {
        $("showuserList_user").innerHTML = "";
        var showuserList_userinnerHTML = new Array();
        for (i = 0; i < data.UserList.length; i++) {
            if (data.UserList[i] && data.UserList[i].imgsrc) {
                if (data.UserList[i].ismaster == "0") {

                    for (var p = 0; p < data.UserBlockList.length; p++) {

                        if (data.UserBlockList[p].username == data.UserList[i].username) {
                            break;
                        }
                    }

                    if (p == data.UserBlockList.length) {
                        usercount = usercount + 1;
                        showuserList_userinnerHTML.push("<li><div class=\"s1\"><img src=\"" + data.UserList[i].imgsrc + "\" /></div><div class=\"s2\"><a href=\"" + data.UserList[i].url + "\"  title=\"点击进入该用户家庭空间\" target=\"_blank\">" + data.UserList[i].username + "</a></div><div class=clear></div></li>")
                    }
                }
                else {
                    usercount = usercount + 1;
                    showuserList_userinnerHTML.push("<li><div class=\"s1\"><img src=\"" + data.UserList[i].imgsrc + "\" /></div><div class=\"s2\"><a href=\"" + data.UserList[i].url + "\"  title=\"点击进入该用户家庭空间\" target=\"_blank\"><span style=\"color:#ff6600;\">" + data.UserList[i].username + "</span></a></div><div class=clear></div></li>");
                }
            }
        }
        $("showuserList_user").innerHTML = "<ul>"+showuserList_userinnerHTML.join("")+"</ul>";
    }
    if (data.showUser == "1") $$("showuserList", "loaded", "true");
}
function initUserOnlineList(open, sign) {
    var first = false;
    if (open == undefined || open == null || open == "") {
        open = getCookie("viewUser");
    }
    if (sign != undefined && sign != null)
    { $$("showuserList", "sign", sign); }
    else
    { sign = $$("showuserList", "sign"); }
    if (open == "2") {
        bindStyle($("showuserList"), { "visibility": "hidden" }); bindStyle($("showuserList"), { "display": "none" });
        $$("showuserlist_chanagebutton", "innerHTML", "[查看在线用户]");
    }
    else if (open == "1") {
        bindStyle($("showuserList"), { "visibility": "" }); bindStyle($("showuserList"), { "display": "" });
        $$("showuserlist_chanagebutton", "innerHTML", "[隐藏在线用户]");
        $$("showuserList", "open", "true");
    }
    else {
        open = "1";
    }
    setCookie("viewUser", open, getExpDate(30, 0, 0), "/", "soufun.com");
    beginShowUserList(sign);
}
function changeUserList(a) {
    if ($$("showuserList", "open") != "true") {
        $$("showuserList", "open", "true");
        initUserOnlineList("1");
    }
    else {
        $$("showuserList", "open", "false");
        initUserOnlineList("2");
    }
}
function changeSkin(skintype) {
    var csshref = "";
    if (skintype == "")
        csshref = "http://img2.soufun.com/bbs/v3.5/style/css.css";
    else
        csshref = "http://img2.soufun.com/bbs/v3.5/style/css" + skintype + ".css";
    if (document.getElementById("linkcsshref").getAttribute("href") != csshref) {
        document.getElementById("linkcsshref").setAttribute("href", csshref);
        //changeSubList(skintype);
        setCookie("skintype", skintype, getExpDate(30, 0, 0), "/", "soufun.com");
    }
    if (skintype == "") skintype = 0;
    var divs = document.getElementsByName("changedivs");
    for (i = 0; i < divs.length; i++) {
        if (i == (3 - skintype))//<a href="#"><img src="<%=CommLayer.C.ImgDomain%>images/blue.gif" alt="" /></a>
            divs[i].innerHTML = "<a href='#'><img src='http://img2.soufun.com/bbs/v3.5/images/blue.gif'/></a>";
        else
            divs[i].innerHTML = "<a href='#'></a>";
    }
}
function changeSubList(skintype) {
    var imgpath = "";
    if (skintype == "")
        imgpath = "http://img2.soufun.com/bbs/v3.5/images/";
    else
        imgpath = "http://img2.soufun.com/bbs/v3.5/images/";
    var imgs = document.getElementsByName("sublistl");
    for (i = 0; i < imgs.length; i++) {
        if (imgs[i].src.indexOf("button_r2_c2.jpg") > -1)
            imghref = imgpath + "button_r2_c2.jpg";
        else
            imghref = imgpath + "button_r2_c6.jpg";
        var tempimg = new Image();
        tempimg.src = imghref;
        imgs[i].src = tempimg.src;
    }
    imgs = document.getElementsByName("sublistr");
    for (i = 0; i < imgs.length; i++) {
        if (imgs[i].src.indexOf("button_r2_c5.jpg") > -1)
            imghref = imgpath + "button_r2_c5.jpg";
        else
            imghref = imgpath + "button_r2_c7.jpg";
        var tempimg = new Image();
        tempimg.src = imghref;
        imgs[i].src = tempimg.src;
    }
}
function loadThreadFollow(b_id,a_id,t_id,sign,top,list_tid,good){

	var targetImg =document.getElementById("followImg"+"_"+top+"_"+ a_id);
	var targetDiv =document.getElementById("follow" +"_"+top+"_"+ a_id);
	
	if (targetImg.src.indexOf("nofollow")!=-1){return false;}
	if ("object"==typeof(targetImg)){
		if (targetDiv.style.display!='block'){
			targetDiv.style.display="block";
			//targetImg.src="http://img2s.soufun.com/bbs/image/bbs/minus.gif";
			targetImg.src="http://img2.soufun.com/bbs/v3/images/minus.gif";
			if (targetImg.getAttribute("loaded")=="no"){
				//$("hiddenframe").location.replace("/soufun_forum/frm_loadtree1.aspx?boardid="+b_id+"&id="+a_id+"&tid="+t_id+"&sign="+ sign +"&top="+top+"&listTid="+list_tid+"&good="+good);
				$("hiddenframe").src = "/soufun_forum/frm_loadtree1.aspx?boardid="+b_id+"&id="+a_id+"&tid="+t_id+"&sign="+ sign +"&top="+top+"&listTid="+list_tid+"&good="+good;
			}
		}else{
			targetDiv.style.display="none";
			//targetImg.src="http://img2s.soufun.com/bbs/image/bbs/plus.gif";
			targetImg.src="http://img2.soufun.com/bbs/v3/images/plus.gif";
		}
	}
}
function loadThreadFollowMatched(b_id,a_id,rsign){
	var targetImg =eval("followImg" + a_id);
	var targetDiv =eval("follow" + a_id);
	if (targetImg.src.indexOf("nofollow")!=-1){return false;}
	if ("object"==typeof(targetImg)){
		if (targetDiv.style.display!='block'){
			targetDiv.style.display="block";
			//targetImg.src="http://img2s.soufun.com/bbs/image/bbs/minus.gif";
			targetImg.src="http://img2.soufun.com/bbs/v3/images/minus.gif";
			if (targetImg.getAttribute("loaded")=="no"){
				//$("hiddenframe").location.replace("/soufun_forum/frm_loadtree_matched.aspx?boardid="+b_id+"&id="+a_id+"&top=0&rsign="+rsign);
				$("hiddenframe").src = "/soufun_forum/frm_loadtree_matched.aspx?boardid="+b_id+"&id="+a_id+"&top=0&rsign="+rsign;
			}
		}else{
			targetDiv.style.display="none";
			//targetImg.src="http://img2s.soufun.com/bbs/image/bbs/plus.gif";
			targetImg.src="http://img2.soufun.com/bbs/v3/images/plus.gif";
		}
	}	
}
function loadThreadFollowtop(b_id,a_id){
	var targetImg =eval("TfollowImg" + a_id);
	var targetDiv =eval("Tfollow" + a_id);
	if (targetImg.src.indexOf("nofollow")!=-1){return false;}
	if ("object"==typeof(targetImg)){
		if (targetDiv.style.display!='block'){
			targetDiv.style.display="block";
			//targetImg.src="http://img2s.soufun.com/bbs/image/bbs/minus.gif";
			targetImg.src="http://img2.soufun.com/bbs/v3/images/minus.gif";
			if (targetImg.getAttribute("loaded")=="no"){
				//$("hiddenframe").location.replace("/soufun_forum/frm_loadtree1.aspx?boardid="+b_id+"&id="+a_id+"&top=1");
				$("hiddenframe").src = "/soufun_forum/frm_loadtree1.aspx?boardid="+b_id+"&id="+a_id+"&top=1";
			}
		}else{
			targetDiv.style.display="none";
			//targetImg.src="http://img2s.soufun.com/bbs/image/bbs/plus.gif";
			targetImg.src="http://img2.soufun.com/bbs/v3/images/plus.gif";
		}
	}
}
function resumeTree(rootid) {
    loadThreadFollow(rootid);
}
String.prototype.getBytes = function() {
    var cArr = this.match(/[^\x00-\xff]/ig);
    return this.length + (cArr == null ? 0 : cArr.length);
}
function showSendList(t) {
    if (browser.IE) {
        if (t.parentNode.parentNode.parentNode.childNodes.length > 4) {
            i = 4;
            fixed = false;
        }
        else {
            i = 3;
            fixed = true;
        }
        t.parentNode.parentNode.parentNode.childNodes[i].childNodes[0].style.visibility = 'visible';
        if (fixed) {
            t.parentNode.parentNode.parentNode.childNodes[i].childNodes[0].childNodes[0].style.right = "160px";
        }
    }
    else {
        if (t.parentNode.parentNode.parentNode.childNodes.length > 9) {
            i = 9; fixed = false;
        }
        else {
            i = 7; fixed = true;
        }
        t.parentNode.parentNode.parentNode.childNodes[i].childNodes[1].style.visibility = 'visible';
        if (fixed) {
            t.parentNode.parentNode.parentNode.childNodes[i].childNodes[1].childNodes[1].style.right = "160px";
        }
    }
}
function hiddenSendList(t) {
    if (browser.IE) {
        if (t.parentNode.parentNode.parentNode.childNodes.length > 4) {
            i = 4;
        }
        else {
            i = 3;
        }
        t.parentNode.parentNode.parentNode.childNodes[i].childNodes[0].style.visibility = 'hidden';
    }
    else {
        if (t.parentNode.parentNode.parentNode.childNodes.length > 9) {
            i = 9;
        }
        else {
            i = 7;
        }
        t.parentNode.parentNode.parentNode.childNodes[i].childNodes[1].style.visibility = 'hidden';
    }
}
function showWelcomeBox(idname, userid, username, userlevel) {
    if (getCookie("showWelcome") == "0") {
        return;
    }
    setCookie("showWelcome", "0", getExpDate(1, 0, 0), "/", "soufun.com");
    var start = $(idname).innerHTML.indexOf("<" + "!--");
    var end = $(idname).innerHTML.indexOf("--" + ">", start);
    if (start == -1 || end == -1) {
       return;
    }
    start += 4;
    var arglist = $(idname).innerHTML.substring(start, end);
    var article = 0, userallintegral = 0;
    var r = /.*(article)\:\{(\d+)\}.*/;
    var mc = arglist.match(r);
    if (mc == null || mc.length != 3)
        return;
    else
        article = mc[2];
    r = /.*(userallintegral)\:\{(\d+)\}.*/;
    mc = arglist.match(r);
    if (mc == null || mc.length != 3) {
        return;
    }
    else {
        userallintegral = mc[2];
    }
    var over = 0, per = 0;
    if (userallintegral < 1000) {
        over = getWelcomeNext(userallintegral, 1000);
        per = Math.ceil(userallintegral / 1000 * 100);
    }
    else if (userallintegral < 3000)
    { over = getWelcomeNext(userallintegral, 3000); per = Math.ceil(userallintegral / 3000 * 100); }
    else if (userallintegral < 9000)
    { over = getWelcomeNext(userallintegral, 9000); per = Math.ceil(userallintegral / 9000 * 100); }
    else if (userallintegral < 15000)
    { over = getWelcomeNext(userallintegral, 15000); per = Math.ceil(userallintegral / 15000 * 100); }
    else if (userallintegral < 22000)
    { over = getWelcomeNext(userallintegral, 22000); per = Math.ceil(userallintegral / 22000 * 100); }
    else if (userallintegral < 30000)
    { over = getWelcomeNext(userallintegral, 30000); per = Math.ceil(userallintegral / 30000 * 100); }
    else if (userallintegral < 40000)
    { over = getWelcomeNext(userallintegral, 40000); per = Math.ceil(userallintegral / 40000 * 100); }
    else if (userallintegral < 60000)
    { over = getWelcomeNext(userallintegral, 60000); per = Math.ceil(userallintegral / 60000 * 100); }
    else if (userallintegral < 100000)
    { over = getWelcomeNext(userallintegral, 100000); per = Math.ceil(userallintegral / 100000 * 100); }
    else if (userallintegral < 200000)
    { over = getWelcomeNext(userallintegral, 200000); per = Math.ceil(userallintegral / 200000 * 100); }
    else if (userallintegral < 300000)
    { over = getWelcomeNext(userallintegral, 300000); per = Math.ceil(userallintegral / 300000 * 100); }
    else if (userallintegral < 600000)
    { over = getWelcomeNext(userallintegral, 600000); per = Math.ceil(userallintegral / 600000 * 100); }
    else if (userallintegral < 900000)
    { over = getWelcomeNext(userallintegral, 900000); per = Math.ceil(userallintegral / 900000 * 100); }
    else if (userallintegral >= 900000)
    { over = -1; per = 100; }

    var now, datestr = "";
    now = new Date();
    if (document.all)
        datestr += now.getYear() + "年";                         // 获取年份。
    else
        datestr += (1900 + now.getYear()) + "年";
    datestr += (now.getMonth() + 1) + "月";            // 获取月份。
    datestr += now.getDate() + "日";                   // 获取日。
    datestr += " 星期";
    switch (now.getDay()) {
        case 1: datestr += "一"; break;
        case 2: datestr += "二"; break;
        case 3: datestr += "三"; break;
        case 4: datestr += "四"; break;
        case 5: datestr += "五"; break;
        case 6: datestr += "六"; break;
        case 7: datestr += "日"; break;
    }
    re = /.*<BR>\&nbsp\;(<img src='http\:\/\/[a-z0-9]+\.soufun\.com\/bbs\/image\/bbs\/level\d+\.gif'>)<BR>\&nbsp\;.*/i;
    mc = $(idname).innerHTML.match(re);
    var imgstr = "";
    if (mc != null) {
        imgstr = mc[1];
    }

    var hour = new Date().getHours() + 1,welcomestr = "";
    if (hour >= 5 && hour < 11)
        welcomestr = "上午好";
    else if (hour >= 11 && hour < 14)
        welcomestr = "中午好";
    else if (hour >= 14 && hour < 18)
        welcomestr = "下午好";
    else
        welcomestr = "晚上好";

    var weatherstr = "";
    //加天气预报
    if ($("weather_" + userid)) {weatherstr = $("weather_" + userid).innerHTML;}

    var output = $("welcomebox").innerHTML;
    output = output.replace(/\$datestr\$/, datestr);
    output = output.replace(/\$userurl\$/, "http://www.soufun.com/space/" + userid + "/");
    output = output.replace(/\$username\$/, username);
    output = output.replace(/\$levelstr\$/, userlevel);
    output = output.replace(/\$imgstr\$/, imgstr);
    output = output.replace(/\$over\$/, over);
    output = output.replace(/\$per\$/, per);
    output = output.replace(/\$weather\$/, weatherstr);
    output = output.replace(/\$welcomestr\$/, welcomestr);
    var perstr = "";
    var lastpre = 10;
    for (i = 0; i < Math.ceil(per / 10); i++) {
        perstr += "<div class='s6'> </div>"; lastpre--;
    }
    for (i = 0; i < lastpre; i++) {
        perstr += "<div class='s7'> </div>";
    }

    output = output.replace(/\$perstr\$/, perstr);
    $("welcomebox").innerHTML = output;
    $("welcomebox").style.visibility = "visible";
    $("welcomebox").style.display = "inline";
    if (window.innerWidth)
        $("welcomebox").style.left = ((window.innerWidth - $("welcomebox").offsetWidth) / 2) + "px";
    else
        $("welcomebox").style.left = ((document.body.clientWidth - $("welcomebox").offsetWidth) / 2) + "px";
    setTimeout("checkWelcomeTime()", 1000);
}
function checkWelcomeTime() {
    if ($("welcomebox_sec").innerHTML == 1) {
        $("welcomebox").style.visibility = "hidden";
        $("welcomebox").style.display = "none"
    }
    else {
        $("welcomebox_sec").innerHTML--;
        setTimeout("checkWelcomeTime()", 1000);
    }
}
function getWelcomeNext(nowCount, nextCount) {
    return Math.ceil((nextCount - nowCount) / 10);
}