6 var mresultPreCache = 200;
7 //var idsCookie = new cookieObject("ids", 1, "/", COOKIE_IDS);
9 var idsCookie = new HTTP.Cookies();
12 attachEvt("common", "unload", mresultUnload);
13 attachEvt("common", "run", mresultDoSearch);
14 attachEvt("result", "idsReceived", mresultSetRecords);
15 attachEvt("result", "idsReceived", mresultCollectRecords);
18 function mresultUnload() { removeChildren(table); table = null;}
20 function mresultDoSearch() {
22 if(getOffset() == 0) {
23 swapCanvas($('loading_alt'));
24 searchTimer = new Timer('searchTimer',$('loading_alt_span'));
28 table = G.ui.result.main_table;
30 while( table.parentNode.rows.length <= (getDisplayCount() + 1) ) /* add an extra row so IE and safari won't complain */
31 table.appendChild(G.ui.result.row_template.cloneNode(true));
33 if(getOffset() == 0 || getHitCount() == null ) {
34 if( getAdvTerm() && !getTerm() ) mresultCollectAdvIds(1);
35 else mresultCollectIds(FETCH_MRIDS_FULL);
38 if( getAdvTerm() && !getTerm()) mresultCollectAdvIds();
39 else mresultCollectIds(FETCH_MRIDS);
44 function mresultGetCount() {
45 var form = (getForm() == "all") ? null : getForm();
46 var req = new Request(FETCH_MRCOUNT,
47 getStype(), getTerm(), getLocation(), getDepth(), form );
48 req.callback(mresultHandleCount);
52 function mresultHandleCount(r) {
53 HITCOUNT = parseInt(r.getResultObject());
54 alert('mresultHandleCount()');
55 runEvt('result', 'hitCountReceived');
60 /* performs the actual search */
61 function mresultCollectIds(method) {
63 if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) {
64 //alert('cached: ' + idsCookie.read(COOKIE_IDS));
65 var c = JSON2js(idsCookie.read(COOKIE_IDS));
66 if(c) { records = c[0]; ranks = c[1]; }
69 if( getOffset() != 0 &&
70 records[getOffset()] != null &&
71 records[resultFinalPageIndex()] != null) {
72 //alert('we have cookies... offset : ' + getOffset() );
73 runEvt('result', 'hitCountReceived');
74 mresultCollectRecords();
78 var form = (getForm() == "all") ? null : getForm();
79 var req = new Request(method, getStype(), getTerm(),
80 getLocation(), getDepth(), mresultPreCache, getOffset(), form );
81 req.callback(mresultHandleMRIds);
87 function mresultCollectAdvIds() {
89 if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) {
90 var c = JSON2js(idsCookie.read(COOKIE_IDS));
91 if(c) { records = c[0]; ranks = c[1]; }
94 if( getOffset() != 0 &&
95 records[getOffset()] != null &&
96 records[resultFinalPageIndex()] != null) {
97 runEvt('result', 'hitCountReceived');
98 mresultCollectRecords();
102 var form = (getForm() == "all") ? null : getForm();
103 var req = new Request(FETCH_ADV_MRIDS,
104 JSON2js(getAdvTerm()), getLocation(), form, mresultPreCache );
105 req.callback(mresultHandleMRIds);
112 function mresultHandleMRIds(r) {
113 var res = r.getResultObject();
115 if(res.count != null) {
116 if( getOffset() == 0 ) HITCOUNT = res.count;
117 runEvt('result', 'hitCountReceived');
119 runEvt('result', 'idsReceived', res.ids);
122 function mresultSetRecords(idstruct) {
123 if(!idstruct) return;
126 for( var x = o; x < idstruct.length + o; x++ ) {
127 if( idstruct[x-o] != null ) {
128 var r = parseInt(idstruct[x - o][0]);
129 var ra = parseFloat(idstruct[x - o][1]);
130 var or = parseInt(idstruct[x - o][2]);
131 if(!isNull(r) && !isNaN(r)) records[x] = r;
132 if(!isNull(ra) && !isNaN(ra)) ranks[x] = ra;
133 if(!isNull(or) && !isNaN(or)) onlyrecord[x] = or;
137 if(getOffset() == 0) {
138 idsCookie.remove(COOKIE_IDS);
139 idsCookie.write(COOKIE_IDS, js2JSON([ records, ranks ]), '+1d' );
140 //alert('Set cookies: ' + idsCookie.read(COOKIE_IDS) + ' : ' + idsCookie.read(COOKIE_IDS).length );
143 TOPRANK = ranks[getOffset()];
146 function mresultCollectRecords() {
147 if(getHitCount() > 0 ) runEvt("result", "preCollectRecords");
149 for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
150 if(isNull(records[x])) break;
151 if(isNaN(records[x])) continue;
152 var req = new Request(FETCH_MRMODS, records[x]);
153 req.request.userdata = i++;
154 req.callback(mresultHandleMods);
159 function mresultHandleMods(r) {
160 var rec = r.getResultObject();
161 var pagePosition = r.userdata;
162 runEvt('result', 'recordReceived', rec, pagePosition, true);
163 resultCollectCopyCounts(rec, pagePosition, FETCH_MR_COPY_COUNTS);