String.prototype.StartWith = function(str) {
    if (str == undefined)
        return false;
    if (str.length > this.length)
        return false;
    if (str == this)
        return true;
    if (str.length == 0 || this.length == 0)
        return false;
    if (this.substring(str, str.length) == str)
        return true;
    else
        return false;
}
String.prototype.EndWith = function(str) {
    if (str == undefined)
        return false;
    if (str.length > this.length)
        return false;
    if (str == this)
        return true;
    if (str.length == 0 || this.length == 0)
        return false;
    if (this.substring(this.length - str.length) == str)
        return true;
    else
        return false;
}
function MM_openBrWindow(theURL, winName, features, w_height, w_width) { //v2.0
    var t = 0, l = 0;
    t = screen.height; l = screen.width;

    t = t - w_height; l = l - w_width;
    t = t / 2; l = l / 2
    //window.open(theURL,winName,features);
    features = features + "top= " + t + "px,height=" + w_height + "px,left=" + l + "px,width=" + w_width + "px";
    window.open(theURL, winName, features);
}
function OpenWinByHtmlControl(theURL, Control_id) {
    var control = document.getElementById(Control_id);
    if (null != control) {
        theURL = theURL + control.value;
        window.open(theURL);
    }
}
function CloseWindow() {
    var ua = navigator.userAgent;
    var IEversion = parseFloat(ua.substring(ua.indexOf("MSIE ") + 5, ua.indexOf(";", ua.indexOf("MSIE "))));
    if (IEversion < 5.5) {
        var str = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">';
        str += '<param name="Command" value="Close"></object>';
        document.body.insertAdjacentHTML("beforeEnd", str);
        if (document.getElementById("noTipClose")) document.getElementById("noTipClose").Click();
    }
    else {
        window.opener = null;
        window.close();
    }
}
function timeout_control(url) {
    if (null != parent) {
        parent.location.assign(url);
    }
    else {
        window.location.assign(url);
    }
}

function assign_main(theUrl, navigation_bar) {
    //	window.parent.frames(0).location.assign('top.aspx?navigation_bar='+navigation_bar);
    window.parent.frames(2).location.assign(theUrl);
}
function assign_self(theUrl, navigation_bar) {
    window.parent.frames(0).location.assign(window.parent.frames(0).location + ";" + navigation_bar);
    window.location.assign(theUrl);
}

//set next ctrl focus when enter keydown event fire
function EnterKeyPress(nextid) {
    var KeyCode = window.event.keyCode;
    if (KeyCode == 13) {
        FocusThisControl(nextid);
    }
}
//set focus by ctrl's ID
function FocusThisControl(ctrlid) {
    //var ctrl = document.getElementById("hfm_floweregg").item(ctrlid);
    var ctrl = document.getElementById(ctrlid);
    if (null == ctrl)
        return;
    if (true == ctrl.disabled)
        return;
    ctrl.focus();
}
//limit text input length
function LimitTextLength(ctrlid, length) {
    //var ctrl = document.getElementById("hfm_floweregg").item(ctrlid);
    var ctrl = document.getElementById(ctrlid);
    if (null == ctrl) return;
    var text = ctrl.value;
    if (text.length <= length)
        return;
    ctrl.value = text.substring(0, length);
}
//check all or not items in DataGrid
function CheckAllGridItem(outckbid, gridid, gridckbid) {
    var Checkboxlist = document.getElementsByTagName("input");
    var selectAll = undefined;
    var checkboxs = Array();
    for (i = 0; i < Checkboxlist.length; i++) {
        if (Checkboxlist[i].type == "checkbox" && Checkboxlist[i].id.StartWith(gridid)) {
            if (Checkboxlist[i].id.EndWith(gridckbid)) {
                checkboxs[checkboxs.length] = Checkboxlist[i];
            }
            else if (Checkboxlist[i].id.EndWith(outckbid)) {
                selectAll = Checkboxlist[i];
            }
        }
    }
    for (i = 0; i < checkboxs.length; i++) {
        checkboxs[i].checked = selectAll.checked;
    }
}
//change check all status by checked status in DataGrid
function CheckOneGridItem(outckbid, gridid, gridckbid) {
    var temp = null;

    temp = document.getElementById(gridid);
    if (null == temp) return;
    var gridlength = temp.rows.length;

    var checkedall = false;
    for (var i = 0; i < 4; i++) {
        temp = document.getElementById(gridid + "_" + "_ctl" + i + "_" + gridckbid);
        if (null == temp) continue;
        checkedall = true; break;
    }

    for (var i = -3; i < gridlength; i++) {
        temp = document.getElementById(gridid + "_" + "_ctl" + (i + 3) + "_" + gridckbid);
        if (null == temp) continue;
        if (temp.checked) continue;
        else {
            checkedall = false;
            break;
        }
    }
    for (var i = 0; i < 4; i++) {
        var name = gridid + ":" + "_ctl" + i + ":" + outckbid
        temp = document.getElementById(name);
        if (null == temp) {
            continue;
        }
        else {
            break;
        }
    }

    if (null == temp) return;
    temp.checked = checkedall;
}
function onKeyPress(aim) {
    var KeyCode = window.event.keyCode;
    if (KeyCode == 13) {
        aim.focus();
    }
}
function refresh_opener(request_full) {
    if (request_full != null) {
        var index_full = -1;
        var str_address_full = window.opener.location.href;
        index_full = str_address_full.indexOf("?");
        if (index_full < 0) {
            window.opener.location.assign(window.opener.location + "?" + request_full);
        }
        else {
            window.opener.location.assign(window.opener.location + "&" + request_full);
        }
    }
    else {
        window.opener.location.assign(window.opener.location);
    }
}
function onKeyPress_dark() {
    var KeyCode = window.event.keyCode;
    if (KeyCode == 13) {
        document.getElementById("btn_DarkQuery").focus();
    }
}
function onKeyPress() {
    var KeyCode = window.event.keyCode;
    if (KeyCode == 13) {
        document.getElementById("btn_search").focus();
    }
}
function OpenOfRefresh() {
    if (null != window.opener) {
        try {
            var openwin = window.opener;
            openwin.location.reload();
        }
        catch (e) {
            return;
        }
    }
}
function ParentOfRefresh() {
    if (null != window.parent) {
        window.parent.location.assign(window.parent.location);
    }
    else
    { }
}
function replace(szMain, szBeforereplace, szAfterreplace) {
    strMain = new String(szMain)
    arrMain = strMain.split(szBeforereplace)
    var szReturn
    szReturn = '';
    for (var i = 0; i < arrMain.length - 1; i++) {
        szReturn = szReturn + arrMain[i] + szAfterreplace;
    }
    return szReturn + arrMain[arrMain.length - 1];
}
function onload_setfocus(txt_id) {
    var focus_txt = document.getElementById(txt_id);
    if (focus_txt != null) {
        focus_txt.focus();
    }
    else {
    }
}
function trim(value) { return value.replace(/(^\s+)|(\s+$)/g, ""); }
function loadtitle(vUrl, vHeight) {
    document.write("<iframe src=" + vUrl + " frameBorder=0 width=100% scrolling=no height=" + vHeight + "></iframe>");
}
//以下是帖子详情页的js
function getsubject() {
    var haha = document.getElementById("HTML_speak_subject");
    if (haha != null)
    { haha.value = "Re:" + document.title; }
}
function quote(announceid, title, username, dtime) {
    var hehe = document.getElementById("HTML_quotebody" + announceid);
    var she = document.getElementById("HTML_speak_subject");
    if (null != hehe) {
        if (null != document.getElementById("HTML_speak_Content")) {
            document.getElementById("HTML_speak_Content").value = "[quote]" + "[B]以下是引用[I]" + username + "[/I]在" + dtime + "的发言：[/B]\n\n" + hehe.value.replace("<table", "").replace(" cellpadding=0 cellspacing=0 border=0 WIDTH=94% bgcolor=#000000", "").replace(" align=center>", "").replace("<tr>", "").replace("<td>", "").replace("<table width=100% cellpadding=5 cellspacing=1 border=0", "").replace("style=\"font-size:13px\">", "").replace("<TR>", "").replace("<TD BGCOLOR=#EFF3F9>", "").replace("</td>", "").replace("</tr>", "").replace("</table>", "").replace("</td>", "").replace("</tr>", "").replace("</table>", "").replace("\n", "") + "[/quote]";
            document.getElementById("announceid").value = announceid;
            document.getElementById("HTML_speak_Content").focus();
        }
    }
    if (she != null)
    { she.value = "Re:" + title; }
}
function reply(announceid, topic) {
    if (announceid == 0) {
        var m_announceid = document.getElementById("HTML_speak_subject");
        if (m_announceid != null)
        { m_announceid.value = "Re:" + topic; }
    }
    else {
        var m_announceid = document.getElementById("announceid");
        if (null != m_announceid)
        { m_announceid.value = announceid; }
        var m_topic = document.getElementById("topic");
        if (null != m_topic)
        { m_topic.value = topic; }
        var hehe = document.getElementById("HTML_speak_subject");
        if (hehe != null)
        { hehe.value = "Re:" + topic; }
    }
}
function flower(money, sign, boardid, announceid) {
    if (confirm("每次表扬要花费" + money + "枚银币，您确定吗?")) {
        document.getElementById("hfm_floweregg").src = "/soufun_forum/post/FlowerEgg.aspx/sign=" + sign + "&good=flower&boardid=" + boardid + "&announceid=" + announceid;
    }
    return;
}
function egg(money, sign, boardid, announceid) {
    if (confirm("每次批评要花费" + money + "枚银币，您确定吗?")) {
        document.getElementById("hfm_floweregg").src = "/soufun_forum/post/FlowerEgg.aspx/sign=" + sign + "&good=egg&boardid=" + boardid + "&announceid=" + announceid;
    }
    return;
}

// 新表扬/批评
function newflower(money, sign, boardid, announceid, tid) {
    if (confirm("每次表扬要花费" + money + "枚银币，您确定吗?")) {
        document.getElementById("hfm_floweregg").src = "/soufun_forum/post/FlowerEgg.aspx/sign=" + sign + "&good=Flower&boardid=" + boardid + "&announceid=" + announceid + "&tid=" + tid;
    }
    return;
}
function newegg(money, sign, boardid, announceid, tid) {
    if (confirm("每次批评要花费" + money + "枚银币，您确定吗?")) {
        document.getElementById("hfm_floweregg").src = "/soufun_forum/post/FlowerEgg.aspx/sign=" + sign + "&good=Egg&boardid=" + boardid + "&announceid=" + announceid + "&tid=" + tid;
    }
    return;
}
// 新表扬/批评

function delete_post(httphead, a_id, sign, bid, isfu, action, direct, a_mid, tid, m_listid) {
    var message
    if (a_mid == "") {
        a_mid = a_id;
    }
    var url = httphead + '/soufun_forum/post/frm_announce_move.aspx/sign=' + sign + '&announceid=' + a_id + '&bid=' + bid + '&isfu=' + isfu + '&action=' + action + '&masterid=' + a_mid + '&tid=' + tid + '&listid=' + m_listid;
    switch (action) {
        case 0: //
            var url = httphead + '/soufun_forum/post/frm_postTransfer.aspx?sign=' + sign + '&announceid=' + a_id + '&bid=' + bid + '&tid=' + tid;
            message = '你确认要移动这个帖子吗?';
            if (confirm(message)) {
                MM_openBrWindow(url, "move", "", 120, 300);
            }
            return;
            break;
        case 1: //
            if (direct == '固顶') {
                message = '你确认要把这个帖子固顶吗?';
            }
            else {
                action = 2;
                message = '你确认要取消这个帖子的固顶吗?';
            }
            break;
        case 3: //
            message = '你确认要删除这个帖子吗?\r\n(提醒:如果你删除的是一个主帖，那么他下面所有的跟帖也会被删除)';
            break;
        case 4: //
            if (direct == '精华') {
                message = '你确认要标记这个帖子为精华帖吗?';
                MM_openBrWindow(url, "选择一个精华区分类", "", 300, 400);
                return;
                break;
            }
            else {
                action = 5;
                message = '你确认要取消这个帖子精华吗?';
            }
            break;
        case 5: //
            if (direct == '加锁') {
                action = 6;
                message = '你确认要给这个帖子加锁吗?加锁需要花费1枚银币！';
                break;
            }
            else {
                action = 7;
                message = '你确认要给这个帖子解锁吗?解锁需要花费1枚银币！';
            }
            break;
    }
    var url = httphead + '/soufun_forum/post/frm_announce_move.aspx/sign=' + sign + '&announceid=' + a_id + '&bid=' + bid + '&isfu=' + isfu + '&action=' + action + '&masterid=' + a_mid + '&tid=' + tid + '&listid=' + m_listid;
    if (confirm(message)) {
        document.getElementById("hfm_master").src = url;
    }
    else
    { return false; }
}

function getExpDate(days, hours, minutes) {
    var expDate = new Date();
    if (typeof (days) == "number" && typeof (hours) == "number" && typeof (hours) == "number") {
        expDate.setDate(expDate.getDate() + parseInt(days));
        expDate.setHours(expDate.getHours() + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
        return expDate.toGMTString();
    }
}

//utility function called by getCookie()
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

// primary function to retrieve cookie by name
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return;
}

// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

// remove the cookie by setting ancient expiration date
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function CheckAll(ckbAllId, ckbSingleName) {
    var ckbAll = document.getElementById(ckbAllId);
    if (ckbAll == null)
        return;

    var ckbSingle = document.getElementsByName(ckbSingleName);
    for (var i = 0; i < ckbSingle.length; i++) {
        if (ckbSingle[i] != null) {
            ckbSingle[i].checked = ckbAll.checked;
        }
    }
}
function CheckSingle(ckbAllId, ckbSingleName) {
    var ckbAll = document.getElementById(ckbAllId);
    if (ckbAll == null)
        return;

    var isAll = true;
    var ckbSingle = document.getElementsByName(ckbSingleName);
    for (var i = 0; i < ckbSingle.length; i++) {
        if (ckbSingle[i].checked == false) {
            isAll = false;
            break;
        }
    }

    ckbAll.checked = isAll;
}
function DeletePost(sbmId) {
    var sbm = document.getElementById(sbmId);
    if (sbm != null) {
        sbm.disabled = true;
    }
    if (confirm("你确认要删除这些帖子吗?\r\n(提醒:如果你删除一个主帖，那么他下面所有的跟帖也会被删除)")) {
        return true;
    }
    else {
        if (sbm != null) {
            sbm.disabled = false;
        }

        return false;
    }
}
//kejet系统发布flash广告页面
function insertFlash(elm, url, w, h, id) {
    if (!document.getElementById(elm)) return;
    var str = '';
    str += '<embed width="' + w + '" height="' + h + '" src="' + url + '" quality="autohigh" wmode="opaque" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" id=' + id + '></embed>';
    document.getElementById(elm).innerHTML = str;
}

function formCtrlEnt(f, event) {
    var e;
    if (event)
        e = event;
    else
        e = window.event;
    if (f && f.getAttribute("submited") == "true") {
        return;
    }
    if (e.ctrlKey && e.keyCode == 13) {
        f.setAttribute("submited", "true");
        f.submit();
    }
}
function changecss(theClass, element, value) {
    var cssRules;
    if (document.all) {
        cssRules = 'rules';
    }
    else if (document.getElementById) {
        cssRules = 'cssRules';
    }
    for (var S = 0; S < document.styleSheets.length; S++) {
        try {
            for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
                if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
                    document.styleSheets[S][cssRules][R].style[element] = value;
                }
            }
        } catch (e) { }
    }
}
////for checkall or not ie and ffx 
function selectITAll(formid) {
    var testform = document.getElementById(formid);
    var action = "selectAll";
    var isfirst = true;
    for (var i = 0; i < testform.elements.length; i++) {
        if (testform.elements[i].type == "checkbox") {
            e = testform.elements[i];
            if (isfirst) {
                if (e.checked)
                { action = "No"; }
                else {
                    action = "selectAll";
                }
                isfirst = false;
            }

            e.checked = (action == "selectAll") ? 1 : (!e.checked);

        }

    }

}


function getPageSize() {

    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
    } else if (document.body.scrollHeight > document.body.offsetHeight) {
        xScroll = document.body.scrollWidth;
    } else {
        xScroll = document.body.offsetWidth;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
    }

    if (xScroll < windowWidth) {
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }
    return pageWidth;
}

function quotenew(sign, bid, tid, masterid, announceid, title, username, userid, dtime) {
    var hehe = document.getElementById("HTML_quotebody" + announceid);
    var she = document.getElementById("HTML_speak_subject");

    if (null != hehe) {
        if (null != document.getElementById("HTML_speak_Content")) {
            document.getElementById("HTML_speak_Content").value = "[QUOTE]引用：[URL=http://www.soufun.com/space/" + userid + "/]" + username;
            document.getElementById("HTML_speak_Content").value += "[/URL] 在" + dtime + "写道：【[URL=http://";
            document.getElementById("HTML_speak_Content").value += bbs_domain + "/" + sign + "~" + bid + "~" + tid + "/" + masterid + "_" + announceid;
            document.getElementById("HTML_speak_Content").value += ".htm]原帖[/URL]】\n" + hehe.value + "[/QUOTE]";
            document.getElementById("announceid").value = announceid;
            document.getElementById("HTML_speak_Content").focus();
        }
    }
    if (she != null) {
        she.value = "Re:" + title;
    }
}
function fnAddFav(title, url) {
    if (document.all)
        window.external.AddFavorite(url, title);
    else if (window.sidebar)
        window.sidebar.addPanel(title, url, "")
}

