var FilterHelper = function () { var hideObj = $("#hiddencount"); var cookieValue = ""; var oldHideSchValue = ""; var oldHideSclassValue = ""; var ifSchChange = false; var ifSclassChange = false; var ifCountryChange = false; var _FilterHelper = function () { this.init(); }; _FilterHelper.prototype = { initValue: function () { this.hashCountry = new Hash(); this.hashSclass = new Hash(); this.hashSch = new Hash(); this.hashLetgoal = new Hash(); this.hashTotalgoal = new Hash(); this.matchType = 0; this.matchStateKind = 0; this.oddsLevel = -1; this.needChangeSchNum = 0; this.selCondition = ""; }, init: function () { this.initValue(); var str = getCookie("FilterHelper"); if (!str) return; var arr = unescape(str).split("^"); for (var i = 0; i < arr.length; i++) { var value = arr[i]; switch (i) { case 0: this.matchType = value; break; case 1: this.matchStateKind = value; break; case 2: convertHash(this.hashCountry, value); break; case 3: convertHash(this.hashSclass, value); break; case 4: convertHash(this.hashSch, value); break; case 5: this.selCondition = value; break; } } }, initHtml: function (ifSortByTime) { var _this = this; function tempFuc() { _this.updateAllSch(true, true, true); showMatchType(_this.matchType); $(".rbl [name=selectType][value=" + _this.matchStateKind + "]").attr("checked", true); for (var i = 0; i < 3; i++) { var obj = $("#MatchType" + i); if (_this.matchType == i) obj.addClass("radio_on"); else obj.removeClass("radio_on"); } } if (!ifSortByTime) { this.seledCondition = null; } else { _this.initSeledCondition(); } tempFuc(); }, initSeledCondition: function () { var temp = null; if (this.selCondition !== "" && this.conditionHash) { temp = new Hash(); $.each(this.conditionHash.get(this.selCondition), function (i, v) { temp.put(v.id, true); }); } this.seledCondition = temp; }, linkData: function () { var schHash = this.schs = new Hash(); var sclassHash = this.sclass = new Hash(); var countryHash = this.country = new Hash(); this.letGoal = new Hash(); this.totalGoal = new Hash(); var thisObj = this; $(A).each(function (i, v) { var schObj = getObject(i, v, v[0], schHash); thisObj.putGoalByID(v[0], v[25], v[33]); var sclassIndex = v[1]; var countryIndex = v[31]; var sclassValue = B[sclassIndex]; var countryValue = C[countryIndex]; var countryObj; if (typeof countryValue != "undefined") { countryObj = getObject(countryIndex, countryValue, countryValue[0], countryHash); oneToMore(schObj, countryObj, "country", "schs"); } if (typeof sclassValue != "undefined") { var sclassObj = getObject(sclassIndex, sclassValue, sclassIndex, sclassHash); oneToMore(schObj, sclassObj, "sclass", "schs"); if (typeof countryValue != "undefined") oneToMore(sclassObj, countryObj, "country", "sclass"); } }); }, getCookiesValue: function () { var arr = new Array(); arr.push(this.matchType); arr.push(this.matchStateKind); arr.push(getHash(this.hashCountry)); arr.push(getHash(this.hashSclass)); arr.push(getHash(this.hashSch)); arr.push(this.selCondition); return arr.join("^"); }, save: function () { docCookies.setItem("FilterHelper", this.getCookiesValue()); }, ifShowSchByID: function (schID, ifOnOwn) { var hash = this.schs; if (!hash.contains(schID)) return false; return this.ifShowSch(hash.get(schID), ifOnOwn); }, ifShowSch: function (obj, ifOnOwn) { if (obj.ifChange) { var value = obj.value; value[25] = getGoal(value[25]); value[33] = getGoal(value[33]); obj.ifShowOther = ifByMatchTypeForSch(obj.id, this.matchType) && ifByState(value, this.matchStateKind) && ifOddsLevel(value, this.oddsLevel) && ifFromHash(this.hashLetgoal, value[25]) && ifFromHash(this.hashTotalgoal, value[33]); obj.ifShowNotCondition = obj.ifShowOther && ifFromHash(this.hashSch, obj.id); obj.ifShow = obj.ifShowNotCondition && ifFromHash(this.seledCondition, obj.id, true); obj.ifChange = false; } if (typeof ifOnOwn == "undefined") ifOnOwn = false; return obj.ifShow && (ifOnOwn || (this.ifShowCountry(obj.country, true) && this.ifShowSclass(obj.sclass, true))); }, ifShowArray: function (arr, fuc) { var reBool = false; for (var i = 0; i < arr.length; i++) { if (reBool = reBool || fuc.call(this, arr[i], true)) break; } return reBool; }, ifShowSclassByIndex: function (index, ifOnOwn) { var hash = this.sclass; if (!hash.contains(index)) return false; return this.ifShowSclass(hash.get(index), ifOnOwn); }, ifShowSclass: function (obj, ifOnOwn) { if (obj.ifChange) { obj.ifShowOther = ifByMatchTypeForSclass(obj.value, this.matchType); obj.ifShow = obj.ifShowOther && ifFromHash(this.hashSclass, obj.id); obj.ifChange = false; } if (typeof ifOnOwn == "undefined") ifOnOwn = false; return obj.ifShow && (ifOnOwn || (this.ifShowCountry(obj.country, true) && this.ifShowArray(obj.schs, this.ifShowSch))); }, ifShowSclassCheck:function(obj) { return this.ifShowCountry(obj.country, true) && obj.ifShowOther && this.ifShowArray(obj.schs, function (obj) { return obj.ifShowOther; }); }, ifShowCountryById: function (countryID, ifOnOwn) { var hash = this.country; if (!hash.contains(countryID)) return false; return this.ifShowCountry(hash.get(countryID), ifOnOwn); }, ifShowCountry: function (obj, ifOnOwn) { if (obj.ifChange) { obj.ifShow = ifFromHash(this.hashCountry, obj.id); obj.ifChange = false; } if (typeof ifOnOwn == "undefined") ifOnOwn = false; return obj.ifShow && (ifOnOwn || (this.ifShowArray(obj.sclass, this.ifShowSclass) && this.ifShowArray(obj.schs, this.ifShowSch))); }, ifFromHash: function (hash, key) { return ifFromHash(hash, key); }, putGoalByID: function (schID, letGoal, totalGoal) { var hash = this.schs; if (!hash.contains(schID)) return false; var schObj = hash.get(schID); letGoal = getGoal(letGoal); var ifChangeLet = false, ifChangeTotal = false; if (letGoal !== schObj.letGoal) { schObj.letGoal = letGoal; ifChangeLet = this.putGoal(hash.get(schID), 0); } totalGoal = getGoal(totalGoal); if (totalGoal !== schObj.totalGoal) { schObj.totalGoal = totalGoal; ifChangeTotal = this.putGoal(hash.get(schID), 1); } return ifChangeLet || ifChangeTotal; }, putGoal: function (schObj, oddsKind) { var hashGoal = oddsKind == 0 ? this.letGoal : this.totalGoal; var goalName = oddsKind == 0 ? "letGoal" : "totalGoal"; var schsHash; var goalValue = getGoal(schObj[goalName]); if (hashGoal.contains(goalValue)) schsHash = hashGoal.get(goalValue); else { schsHash = new Hash(); hashGoal.put(goalValue, schsHash); } schsHash.put(schObj.id, schObj); var goalObj = schObj[goalName + "Obj"]; if (goalObj !== schsHash) { if (typeof goalObj !== "undefined") goalObj.remove(schObj.id); if (typeof schObj.sclass != "undefined") schObj.sclass.ifChange = true; if (typeof schObj.country != "undefined") schObj.country.ifChange = true; schObj[goalName + "Obj"] = schsHash; schObj.ifChange = true return true; } return false; }, updateAllSch: function (ifSchChange, ifSclassChange, ifCountryChange) { if (typeof ifSchChange != "boolean") ifSchChange = false; if (typeof ifSclassChange != "boolean") ifSclassChange = false; if (typeof ifCountryChange != "boolean") ifCountryChange = false; var thisObj = this; this.country.each(function (v, k) { v.ifChange = ifCountryChange; v.sclass.each(function (v, k) { v.ifChange = ifSclassChange; v.schs.each(function (v, k) { v.ifChange = ifSchChange; thisObj.showSch(v); }); thisObj.showSclass(v); }); thisObj.showCountry(v); }); }, updateSch: function (id, ifShow) { ifShow = (typeof ifShow != "undefined" && ifShow === true); var v = this.schs.get(id); if (typeof (v) == "undefined") return; v.ifChange = ifShow != v.ifShow; if (v.ifChange) { this.hashSch.put(id, ifShow); if (this.showSch(v)) { this.showSclass(v.sclass) && this.showCountry(v.country); } this.save(); } }, updateSclass: function (id, ifShow) { ifShow = (typeof ifShow != "undefined" && ifShow === true); var v = this.sclass.get(id); if (typeof (v) == "undefined") return; var thisObj = this; this.hashSclass.put(id, ifShow); v.ifChange = ifShow != v.ifShow; $(v.schs).each(function (i, value) { //if (ifShow && !ifFromHash(thisObj.hashSch, value.id)) { // value.ifChange = true; // thisObj.hashSch.put(value.id, ifShow); //} thisObj.showSch(value); }); this.showSclass(v); this.showCountry(v.country); this.save(); }, updateCountry: function (id, ifShow) { ifShow = (typeof ifShow != "undefined" && ifShow === true); var v = this.country.get(id); if (typeof (v) == "undefined") return false; v.ifChange = ifShow != v.ifShow; this.hashCountry.put(id, ifShow); var thisObj = this; $(v.schs).each(function (i, value) { //if (ifShow && !ifFromHash(thisObj.hashSch, value.id)) { // value.ifChange = true; // thisObj.hashSch.put(value.id, ifShow); //} thisObj.showSch(value); }); $(v.sclass).each(function (i, value) { //if (ifShow && !ifFromHash(thisObj.hashSclass, value.id)) { // value.ifChange = true; // thisObj.hashSclass.put(value.id, ifShow); //} thisObj.showSclass(value); }); this.showCountry(v, true); this.save(); }, getGoalValue: function (goal) { return getGoal(goal); }, updateGoal: function (goal, oddsKind, ifShow) { ifShow = (typeof ifShow != "undefined" && ifShow === true); var goal = getGoal(goal); var hiddenHash = oddsKind == 0 ? this.hashLetgoal : this.hashTotalgoal; if (hiddenHash.contains(goal) ? (hiddenHash.get(goal) == ifShow) : ifShow) return false; hiddenHash.put(goal, ifShow); var hashGoal = oddsKind == 0 ? this.letGoal : this.totalGoal; if (!hashGoal.contains(goal)) return false; var hashObj = hashGoal.get(goal); var thisObj = this; var sclassHash = new Hash(); var countryHash = new Hash(); hashObj.each(function (v, k) { v.ifChange = true; if (thisObj.showSch(v, true)) { if (!sclassHash.contains(v.sclass.id)) sclassHash.put(v.sclass.id, v.sclass); if (!countryHash.contains(v.country.id)) countryHash.put(v.country.id, v.country); } }); sclassHash.each(function (v, k) { v.ifChange = true; thisObj.showSclass(v); }); countryHash.each(function (v, k) { v.ifChange = true; thisObj.showCountry(v); }); }, updateLetgoal: function (goal, ifShow) { this.updateGoal(goal, 0, ifShow); }, updateTotalgoal: function (goal, ifShow) { this.updateGoal(goal, 1, ifShow); }, updateOddsLevel: function (n) { if (typeof n != "undefined" && this.oddsLevel != n) { this.oddsLevel = n; this.updateAllSch(true); } }, updateStateKind: function (n) { if (typeof n != "undefined" && this.matchStateKind != n) { this.matchStateKind = n; this.updateAllSch(true); this.save(); } }, getConfition:function(callback) { var thisObj = this; this.conditionHash = new Hash(); $.ajax({ type: "GET", url: "/data/condition.js", dataType: "text", cache: false, success: function (data) { var arr1 = data.split('!'); for (var i = 0; i < arr1.length; i++) { var arr2 = arr1[i].split('^'); for (var j = 0; j < arr2.length; j++) { var arr3 = arr2[j].split(','); var arrV = new Hash(); for (var k = 0; k < arr3.length; k++) { var sid = arr3[k]; if (sid !== '' && thisObj.schs.contains(sid)) arrV.put(sid, thisObj.schs.get(sid)); } thisObj.conditionHash.put(i + "_" + j, arrV.values()); } } if (typeof callback == "function") callback(); } }); }, updateCondition: function (n) { if (typeof n != "undefined" && this.selCondition != n) { this.selCondition = n; this.initSeledCondition(); this.updateAllSch(true); this.save(); } }, updateMatchType: function (n) { if (typeof n != "undefined" && this.matchType != n) { $("#MatchType" + this.matchType).removeClass("radio_on"); showMatchType(n); var oldType = this.matchType; this.matchType = n; var thisObj = this; this.updateAllSch(oldType == 2 || n == 2, oldType == 1 || n == 1);//oldType != 1 && n != 1 this.save(); } }, showCountry: function (id) { var newIfShow = false; if (typeof id === "object") { newIfShow = this.ifShowCountry(id); id = id.id; } else newIfShow = this.ifShowCountryById(id); var checkObj = $("#countryList #checkboxcountry_" + id); if (checkObj.is(':checked') != newIfShow) { if (newIfShow) checkObj.attr("checked", "true"); else checkObj.removeAttr("checked"); return true; } return false; }, showSclass: function (index) { var sclassObj; if (typeof index === "object") { sclassObj = index; index = sclassObj.index; } else sclassObj = this.sclass.get(index); if (typeof sclassObj === "undefined") return false; var newIfShow = this.ifShowSclass(sclassObj); var checkObj = $("#checkboxleague_" + index); var ifDif = false; if (checkObj.is(':checked') != newIfShow) { if (newIfShow) checkObj.attr("checked", "true"); else checkObj.removeAttr("checked"); ifDif = true; } var ifShowCheck = newIfShow || this.ifShowSclassCheck(sclassObj); var fuc = ifShowCheck ? $.prototype.show : $.prototype.hide; var liObj = checkObj.parents("li"); if (liObj.is(":visible") != ifShowCheck) { fuc.call(liObj); ifDif = true; } if (orderby === "league") { var trObj = $(".Leaguestitle#tr_" + index); if (trObj.is(":visible") !== ifShowCheck) { fuc.call(trObj); ifDif = true; } var cObj = $("#collapse" + index); if (cObj.is(":visible") !== newIfShow) { var otherObj = $("#expand" + index); setTimeout(function () { if (newIfShow) { cObj.show(); otherObj.hide(); } else { cObj.hide(); otherObj.show(); } }, 100); ifDif = true; } } return ifDif; }, showSch: function (schID) { var newIfShow = false; var thisObj = this; if (typeof schID === "object") { newIfShow = thisObj.ifShowSch(schID); schID = schID.id; } else newIfShow = thisObj.ifShowSchByID(schID); var schTr = $("#tr1_" + schID); if (schTr.length == 0) return false; var ifShow = schTr.is(":visible"); if (typeof schTr.attr("ifshow") == "undefined") ifShow = schTr.is(":visible"); else ifShow = schTr.attr("ifshow") === "1"; if (newIfShow != ifShow) { schTr.attr("ifshow", newIfShow ? 1 : 0); var schObj = thisObj.schs.get(schID); var schValue = schObj.value; var doms = $("#tr1_" + schID + (schValue[27] + schValue[32] != "" ? ",#tr2_" + schID : "") + (typeof( flashScheduleIDs) != "undefined"&& flashScheduleIDs != "" && parseInt(flashScheduleIDs) == schID && flashData.scheduleList.items.length > 0 ? ",#tr3_" + schID : "")); setTimeout(function () { var count = parseInt(hideObj.html()); if (newIfShow) { doms.show(); count--; } else { doms.hide(); count++; } hideObj.html(count); thisObj.needChangeSchNum--; changeTxtAdLocation(); }, 100); thisObj.needChangeSchNum++; return true; } return false; } } function getGoal(goal) { if (typeof (goal) === "number") return goal; return parseFloat(goal); } function ifFromHash(hash, key, mustHas) { if (typeof mustHas === "undefined") mustHas = false; if (hash == null) return true; var ifContain = hash.contains(key); if (mustHas) return ifContain; return !ifContain || hash.get(key); } function convertHash(hash, value) { if (value == "") return; var arr = value.split("_"); $(arr).each(function (i, v) { hash.put(v, false); }); } function oneToMore(oneObj, moreObj, oneName, moreArrName) { if (typeof oneObj[oneName] != "undefined") return; oneObj[oneName] = moreObj; var arr = moreObj[moreArrName]; if (typeof arr == "undefined") arr = moreObj[moreArrName] = new Array(); arr.push(oneObj); } function getObject(i, v, key, hash) { var id = arguments.length > 5 ? arguments[5] : key; if (hash.contains(key)) return hash.get(key); var obj = new Object(); obj.id = id; obj.value = v; obj.index = i; obj.ifShow = true;// !hashShow.contains(id) || hashShow.get(id); obj.ifChange = true; hash.put(key, obj); return obj; } function getHash(hash) { var arr = new Array(); hash.each(function (value, key) { if (!value) arr.push(key); }); return arr.join("_"); } function ifByState(schValue, kind) { schValue[12] = parseInt(schValue[12]); switch (parseInt(kind)) { case 1: return parseInt(schValue[12]) > 0; case 2: return schValue[12] == "-1"; case 3: return schValue[12] == "0"; case 4: return (/^true$/i).test(schValue[24]); } return true; } function ifOddsLevel(schValue, level) { schValue[30] = parseInt(schValue[30]); switch (parseInt(level)) { case 0: return schValue[30] > 0; case 1: return schValue[30] == 1 || schValue[30] == 3; case 2: return schValue[30] == 2 || schValue[30] == 3; case 3: return jcIdList.indexOf(schValue[0]) > -1; } return true; } function ifByMatchTypeForSch(id, mType) { if (typeof (idList) !== "undefined") switch (parseInt(mType)) { case 2: return idList.indexOf(id) > -1; } return true; } function ifByMatchTypeForSclass(sclassValue, mType) { switch (parseInt(mType)) { case 1: return sclassValue[5] != 0; } return true; } function showMatchType(n) { $("#MatchType" + n).addClass("radio_on"); if (n == 0) $("#btn_all").hide(); else $("#btn_all").show(); } return _FilterHelper }();