var flList = {
    "jlyy1": {
        "name": "应用",
        "val": {
            1 : "推荐应用",
            2 : "最新应用",
            3 : "最热门top50"
        }
    },
    "jlyy2": {
        "name": "类别",
        "val": {
            0 : "不限",
            1 : "在线应用",
            2 : "盒子应用"
        }
    },
    "hslx": {
        "name": "登录",
        "val": {
            0 : "不限",
            1 : "应用",
            3 : "登录"
        }
    },
    "yyxz": {
        "name": "性质",
        "val": {
            0 : "不限",
            1 : "免费",
            2 : "收费",
            3 : "开源",
            4 : "收费开源"
        }
    },
    "yys": {
        "name": "运营商",
        "val": {
            0 : "不限",
            1 : "ii23",
            2 : "扣扣",
            3 : "新浪"
        },
        "sub": "fl1"
    },
    "fl1": {
        "name": "分类",
        "parent": "yys",
        "val": {
            0 : "不限",
            1 : {
                "name": "玫瑰小镇",
                "parent": "2"
            },
            2 : {
                "name": "Q宠大乐斗",
                "parent": "2"
            },
            3 : {
                "name": "签到",
                "parent": "1"
            },
            4 : {
                "name": "新浪微博",
                "parent": "3"
            },
            5 : {
                "name": "QQ空间",
                "parent": "2"
            },
            6 : {
                "name": "微博",
                "parent": "2"
            },
            7 : {
                "name": "QQ农场",
                "parent": "2"
            },
            8 : {
                "name": "QQ牧场",
                "parent": "2"
            },
            9 : {
                "name": "QQ餐厅",
                "parent": "2"
            },
            10 : {
                "name": "宝宝乐园",
                "parent": "2"
            },
            11 : {
                "name": "蓝钻贵族",
                "parent": "2"
            },
            12 : {
                "name": "QQ游戏",
                "parent": "2"
            },
            13 : {
                "name": "微信",
                "parent": "2"
            }
        }
    },
    "lx": {
        "name": "类型",
        "val": {
            0 : "不限",
            1 : "开通",
            2 : "活动",
            3 : "每月",
            4 : "日常",
            5 : "其它"
        }
    },
    "yxq": {
        "name": "有效性",
        "val": {
            0 : "不限",
            1 : "有效",
            2 : "过期应用"
        }
    }
};
var resRet = "";
var resSql = "";
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "")
}
var gs_searchurl = location.search;
gs_searchurl = gs_searchurl.replace(new RegExp("%26", "gmi"), "&");
if (typeof(isJLAPPBOX) == "undefined") isJLAPPBOX = false;
if (typeof(isJLAPPBOXIndex) == "undefined") isJLAPPBOXIndex = false;
if (typeof(isJLUP) == "undefined") isJLUP = false;
if (typeof(getUrlParam) != "undefined") {
    if (getUrlParam(gs_searchurl, "up") != "") {
        isJLUP = true
    }
    if (getUrlParam(gs_searchurl, "type") != "") {
        isJLAPPBOX = true
    }
    if (getUrlParam(gs_searchurl, "fromjlbox") != "") {
        isJLAPPBOXIndex = true
    }
}
function getRetStr(typename, id) {
    var tmp = "&" + typename + "=" + id;
    if (resRet != "") resRet = "&" + resRet
    if (resRet.indexOf("&" + typename + "=") >= 0) {
        var reg = new RegExp("&" + typename + "=(\\d+)", "gmi");
        resRet = resRet.replace(reg, tmp)
    } else {
        resRet += tmp
    }
    resRet += "&";
    if (id == 0) {
        resRet = resRet.replace(new RegExp(tmp, "gmi"), "")
    }
    if (resRet.substr(0, 1) == '&') {
        resRet = resRet.substr(1, resRet.length)
    }
    if (resRet.substr(resRet.length - 1, 1) == '&') resRet = resRet.substr(0, resRet.length - 1);
    resSql = resRet;
    resSql = resSql.replace(new RegExp("&", "gmi"), " and ")
}
function removeAllSelect() {
    for (var i in flList) {
        var typename = i;
        var val = flList[i].val;
        for (var j in val) {
            if (!document.getElementById(typename + '_' + j)) continue;
            document.getElementById(typename + '_' + j).removeAttribute("class");
            document.getElementById(typename + '_' + j).className = ""
        }
    }
    resRet = "";
    resSql = ""
}
function selectByStr(str) {
    removeAllSelect();
    var lst_tmp = str.split('&');
    for (obj in lst_tmp) {
        var typename = lst_tmp[obj].split('=')[0];
        var id = lst_tmp[obj].split('=')[1];
        flClick(typename, id)
    }
}
function flClick(typename, id) {
    if (typename == "username" || typename == "q") {
        document.getElementById("searchType").value = typename;
        document.getElementById("q").value = id;
        return
    }
    if (!document.getElementById(typename + '_' + id)) return;
    if (isJLUP) {
        document.getElementById('up_div').style.display = '';
        if (typename == "yyxz") {
            document.getElementById('sfky').style.display = 'none';
            if (id == "2" || id == "4") {
                document.getElementById('sffs_div').style.display = '';
                if (id == "4") document.getElementById('sfky').style.display = ''
            } else {
                document.getElementById('sffs_div').style.display = 'none'
            }
        }
    }
    if (flList[typename].sub) {
        if (id == 0) {
            document.getElementById(flList[typename].sub).innerHTML = '';
            document.getElementById(flList[typename].sub).style.display = "none"
        } else {
            document.getElementById(flList[typename].sub).innerHTML = getSubList(typename, id);
            document.getElementById(flList[typename].sub).style.display = "block"
        }
        getRetStr(flList[typename].sub, 0)
    }
    var val = flList[typename].val;
    for (var j in val) {
        if (document.getElementById(typename + '_' + j)) {
            document.getElementById(typename + '_' + j).removeAttribute("class");
            document.getElementById(typename + '_' + j).className = ""
        }
    }
    document.getElementById(typename + '_' + id).setAttribute = ("class", "flSelect");
    document.getElementById(typename + '_' + id).className = "flSelect";
    getRetStr(typename, id)
}
function getFlNameById(typename, id) {
    var val = flList[typename].val;
    if (val) {
        for (var j in val) {
            if (j == id) {
                var name = "";
                if (typeof(val[j]) == "object") {
                    name = val[j]["name"]
                } else {
                    name = val[j]
                }
                return name
            }
        }
    }
}
function getSubList(typename, parent) {
    var id = flList[typename].sub;
    var obj = flList[flList[typename].sub];
    var val = obj.val;
    var tmpHtml = "";
    tmpHtml = obj.name + "：";
    for (var j in val) {
        if ((j != 0) && (val[j]["parent"] != parent)) continue;
        var name = "";
        if (typeof(val[j]) == "object") {
            name = val[j]["name"]
        } else {
            name = val[j]
        }
        tmpHtml += "<a id='" + id + "_" + j + "' href='javascript:void(0);' onclick=\"flClick('" + id + "','" + j + "')\">" + name + "</a>&nbsp;"
    }
    return tmpHtml
}
var flHtml = "<ul>";
for (var i in flList) {
    if ((isJLAPPBOX) && i.indexOf("jlyy") >= 0) continue;
    if ((isJLUP) && i == "yxq") continue;
    if ((isJLUP) && i == "hslx") continue;
    if (flList[i].parent) {
        flHtml += "<li id='" + i + "' style='display:none'>";
        flHtml += flList[i].name + "：";
        flHtml += "</li>";
        continue
    }
    flHtml += "<li id='" + i + "'>";
    flHtml += flList[i].name + "：";
    var val = flList[i].val;
    for (var j in val) {
        flHtml += "<a id='" + i + "_" + j + "' href='javascript:void(0);' onclick=\"flClick('" + i + "','" + j + "')\">" + val[j] + "</a>&nbsp;"
    }
    flHtml += "</li>"
}
flHtml += "</ul>";
document.getElementById('jlfl').innerHTML = flHtml;
function search() {
    ls_tmp = resRet;
    var ls_searchWord = "q";
    if (document.getElementById('searchType')) ls_searchWord = document.getElementById('searchType').value;
    document.getElementById('q').value = document.getElementById('q').value.trim();
    if (document.getElementById('q').value.trim() != "") {
        if (ls_tmp != "") ls_tmp = ls_tmp + "&" + ls_searchWord + "=" + (document.getElementById('q').value);
        else ls_tmp = ls_searchWord + "=" + (document.getElementById('q').value)
    }
    if (document.getElementById('sfyc')) {
        if (document.getElementById('sfyc').checked) {
            if (ls_tmp != "") ls_tmp = ls_tmp + "&sfyc=1";
            else ls_tmp = "sfyc=1"
        } else {}
    }
    if (document.getElementById('sfxz')) {
        if (document.getElementById('sfxz').checked) {
            if (ls_tmp != "") ls_tmp = ls_tmp + "&sfxz=1";
            else ls_tmp = "sfxz=1"
        } else {}
    }
    if (isJLAPPBOX) {
        external("search", ls_tmp)
    } else {
        jlweb.queryByStr(ls_tmp)
    }
}
function getQueryStr() {
    if (!isJLUP) return resRet;
    var oForm = document.sffs_form;
    var aParams = new Array();
    for (var i = 0; i < oForm.elements.length; i++) {
        var sParam = "";
        if (oForm.elements[i].type == "checkbox") {
            if (oForm.elements[i].checked) {
                sParam = (oForm.elements[i].name);
                sParam += "=";
                sParam += (oForm.elements[i].value)
            }
        } else if (oForm.elements[i].type == "radio") {
            if (oForm.elements[i].checked) {
                sParam = (oForm.elements[i].name);
                sParam += "=";
                sParam += (oForm.elements[i].value)
            }
        } else {
            sParam = (oForm.elements[i].name);
            sParam += "=";
            sParam += (oForm.elements[i].value)
        }
        if (sParam != "") aParams.push(sParam)
    }
    var resultstr = resRet;
    if (resultstr != "") resultstr += "&";
    return resultstr + aParams.join("&")
}
function initJG(obj) {
    if (obj.appid) {
        if (obj.code != 0) return;
        document.getElementById('jg_t').value = obj.jg_t;
        document.getElementById('jg_z').value = obj.jg_z;
        document.getElementById('jg_y').value = obj.jg_y;
        document.getElementById('jg_j').value = obj.jg_j;
        document.getElementById('jg_bn').value = obj.jg_bn;
        document.getElementById('jg_n').value = obj.jg_n;
        document.getElementById('jg_yj').value = obj.jg_yj;
        document.getElementById('ibjc').value = obj.ibjc;
        document.getElementById('sfksy').checked = (obj.sfksy == 1 ? true: false);
        document.getElementById('ksysj').value = obj.ksysj;
        document.getElementById('bdfs').value = obj.bdfs;
        document.getElementById('slzjyb').value = obj.slzjyb;
        document.getElementById('fdj').value = obj.fdj;
        try {
            document.getElementById('up_sfyc').checked = (obj.sfyc == 1 ? true: false)
        } catch(e) {}
        getRadioBoxValue('sffs', obj.sffs);
        changeBySFKSY();
        changeBySFFS(obj.sffs);
        changeBDFS(obj.bdfs)
    }
}
function getRadioBoxValue(radioName, radiovalue) {
    var obj = document.getElementsByName(radioName);
    for (i = 0; i < obj.length; i++) {
        if (obj[i].value == radiovalue) {
            obj[i].checked = true
        }
    }
    return true
}
function changeBySFFS(as_sffs) {
    if (as_sffs == 1) {
        document.getElementById('ibjcs_id').style.display = 'none'
    } else if (as_sffs == 2) {
        document.getElementById('ibjcs_id').style.display = ''
    } else if (as_sffs == 3) {
        document.getElementById('ibjcs_id').style.display = ''
    }
}
function changeBDFS(as_bdfs) {
    if (as_bdfs == 2) {
        document.getElementById('slzjyb_div').style.display = '';
        document.getElementById('jg_yj_div').style.display = 'none'
    } else {
        document.getElementById('slzjyb_div').style.display = 'none';
        document.getElementById('jg_yj_div').style.display = ''
    }
}
function changeBySFKSY() {
    if (document.getElementById('sfksy').checked) {
        document.getElementById('ksysj_id').style.display = ''
    } else {
        document.getElementById('ksysj_id').style.display = 'none'
    }
}
if (gs_searchurl.indexOf("?") != -1) {
    if (isJLAPPBOX || isJLAPPBOXIndex) {
        flClick("yxq", 1)
    } else {
        var str = gs_searchurl.substr(1);
        selectByStr(str)
    }
} else {
    flClick("hslx", 1);
    flClick("yxq", 1)
}
if (isJLUP) {
    document.getElementById('search').style.display = "none"
}
if (!isJLAPPBOX) {
    if ((typeof(discuz_uid) != 'undefined' && discuz_uid != '' && discuz_uid != '0') && (typeof(isjlappzz) != 'undefined' && isjlappzz == "1")) {
        document.getElementById('sfyc_div').style.display = ""
    }
}