PageSourceSearch

https://secure.accountsupport.com/secure/BL_AJAX.js

js accountsupport.com collected 2026-10-03 22:10:15 UTC 12,884 bytes, 452 lines download raw bytes

1/*
2
3Generic AJAX HTML library. Contains a few generalized functions to get a URL with XMLHTTPRequest and show it in a DIV
4
5See Wiki for more information
6*/
7
8/*
9
10OpenDIV( divname )
11
12This function will make a div visible. It is only one way! If you want open and close then see below. Takes the id of a div
13
14*/
15function OpenDIV( divname ) {
16
17    if (document.getElementById) { // DOM3 = IE5, NS6
18        if (document.getElementById(divname).style.display == "none"){
19            document.getElementById(divname).style.display = 'block';
20        }
21    } else {
22        if (document.layers) {
23            if (document.divname.display == "none"){
24                document.divname.display = 'block';
25            }
26        } else {
27            if (document.all.divname.style.visibility == "none"){
28                document.all.divname.style.display = 'block';
29            }
30        }
31    }
32}
33
34
35/*
36
37CloseDIV( divname )
38
39This function will make a div invisible. It is only one way! If you want open and close then see below. Takes the id of a div
40
41*/
42function CloseDIV( divname ) {
43
44    if (document.getElementById) { // DOM3 = IE5, NS6
45        if (document.getElementById(divname).style.display != "none"){
46            document.getElementById(divname).style.display = 'none';
47        }
48    } else {
49        if (document.layers) {
50            if (document.divname.display != "none"){
51                document.divname.display = 'none';
52            }
53        } else {
54            if (document.all.divname.style.visibility != "none"){
55                document.all.divname.style.display = 'none';
56            }
57        }
58    }
59}
60
61/* 
62
63OpenCloseDIV( id )
64
65This function takes an id. The function will look for a div named (id)_block and change the visibility of it. In addition to the _block div it will also try to switch images for (id)_img image tag. It will do a plus sign when (id)_block is not visible and minus when it is
66
67*/
68function OpenCloseDIV(id,img_path,table,image_open,image_close,custom_path) {
69    var divname = id + "_block";
70    var imgname = id + "_img";
71
72    var newimg
73
74    // make this useful to tables as well
75    var type = 'block';
76    if ( table == 1 ) { type = 'table'; }
77
78    if (document.getElementById) { // DOM3 = IE5, NS6
79      if ( type == 'block' ){
80        if (document.getElementById(divname).style.display == "none"){
81            document.getElementById(divname).style.display = "block";
82            newimg = 'minus'
83        } else {
84            document.getElementById(divname).style.display = 'none';
85            newimg = 'plus' 
86        }
87      } else {
88        if (document.getElementById(divname).style.display == 'none'){
89            document.getElementById(divname).style.display = '';
90            newimg = 'minus'
91        } else {
92            document.getElementById(divname).style.display = 'none';
93            newimg = 'plus'
94        }
95
96      }
97    } else {
98        if (document.layers) {
99            if (document.divname.display == "none"){
100                document.divname.display = "block";
101                newimg = 'minus'
102            } else {
103                document.divname.display = 'none';
104                newimg = 'plus' 
105            }
106        } else {
107            if (document.all.divname.style.visibility == "none"){
108                document.all.divname.style.display = "block";
109                newimg = 'minus'
110            } else {
111                document.all.divname.style.display = 'none';
112                newimg = 'plus' 
113            }
114        }
115    }
116
117    if ( document.images[imgname] ) {
118	    var Imgs = new Object;
119
120        if ( img_path ) {
121          Imgs.minus = img_path+"arrow_down.gif";
122          Imgs.plus = img_path+"arrow_right.gif";
123        } 
124        else if ( custom_path ) {
125          Imgs.minus = custom_path+image_close;
126          Imgs.plus  = custom_path+image_open;
127        }
128        else if ( image_open ) {
129          Imgs.minus = "https://secure.bizland.com/images"+image_close;
130          Imgs.plus  = "https://secure.bizland.com/images"+image_open;
131        }
132        else {
133      	  Imgs.minus = "https://secure.bizland.com/images/greenarrow.gif";
134          Imgs.plus = "https://secure.bizland.com/images/redarrow.gif";
135        }
136
137      switchimg(imgname,Imgs[ newimg ]);
138    }
139    
140}
141
142/*
143
144getAJAXHTML( name , url , extras , append , noblink , showprogress , sucfunc , errfunc )
145
146This is the main function for making an AJAX request. It takes several options:
147
148name 		- the name of the div to change with the request
149
150url 		- optional URL of the script to call. This allows you to use a script other than the one the javascript is called from.
151
152extras 		- If you are calling back to the script that has the javascript in it , then you can just pass the parameters for the GET request. The script will prepend http://machine/script? to the extras.
153
154append          - Append to the div instead of overwriting
155
156noblink		- Turns off the 'Getting Data' blinking tag.
157
158showprogress    - If true it will write to the div as it loads ( doesn't work in IE )
159
160sucfunc         - A function to run on success. req object is passed in
161
162errfunc         - A function to run on error. req object is passed in
163
164
165You need to send a div and you need url or extras
166
167*/
168/*
169 * Same-document AJAX (no explicit url): build URL with pathname + existing search + extras.
170 * - Merges with & when a query string exists (never ?…?…) so Mason sees update= webusage/inodeusage.
171 * - Uses GET + _=timestamp so responses are not cached (old IE issue) and typical WAFs allow GET
172 *   where POST to the same path returned 403; POST + default body also tripped SQLi rules (1=1).
173 */
174function blAjaxMergeSamePageQuery( extras ) {
175	var path = window.location.pathname;
176	var search = window.location.search;
177	var bust = '_=' + new Date().getTime();
178	var tail = extras ? ( extras + '&' + bust ) : bust;
179	if ( search && search.length > 1 ) {
180		return path + search + '&' + tail;
181	}
182	return path + '?' + tail;
183}
184
185function getAJAXHTML( name , url , extras, append, noblink , showprogress , sucfunc , errfunc ) {
186   var samePageGet = false;
187   if ( ! url ) {
188	url = blAjaxMergeSamePageQuery( extras );
189	samePageGet = true;
190   }
191
192   if (noblink != 1){
193   	changeDiv( name ,'<img src="/images/indicator.gif">') 
194   }
195   var request = new makeReq( url , name, append , showprogress , sucfunc , errfunc )
196
197   if ( samePageGet ) {
198	request.doGet( true );
199   } else {
200	request.doPost(null);
201   }
202}
203
204/*
205
206postAJAXHTML( name , url , formid, append , noblink , showprogress , sucfunc , errfunc )
207
208POST version of getAJAXHTML.  Rather than an optional list of 'extra' params to send
209in the query string, requires the id of a form on the page to read parameters from.
210Sends values of all non-blank inputs from the given form, except for unchecked radios
211and checkboxes.
212
213*/
214function postAJAXHTML( name, url, form, append, noblink, showprogress, sucfunc, errfunc ) {
215	if ( ! url ) {
216		url = window.location;
217	}
218
219	var eForm = document.getElementById( form );
220	var aInputs = eForm.getElementsByTagName( "input" );
221
222	var aParams = new Array();
223
224	// gather list of form params to send with post
225	for ( var i = 0; i < aInputs.length; i++ ) {
226		var eI = aInputs[i];
227
228		if ((( eI.type == 'checkbox' ) || ( eI.type == 'radio' )) && ( ! eI.checked )) {
229			continue;
230		}
231
232		if ( eI.value ) {
233			aParams.push( eI.name + '=' + eI.value );
234		}
235	}
236
237	var request = new makeReq( url , name, append , showprogress , sucfunc , errfunc );
238	var postBody = aParams.join( '&' );
239	request.doPost( aParams.join( '&' ) );
240
241	if ( noblink != 1 ) {
242		changeDiv( name, '<img src="/images/indicator.gif">' ) ;
243	}
244}
245
246
247
248/*
249
250changeDiv( divname, contents )
251
252Internal function to change the contents of a div.
253
254*/
255function changeDiv(divname,contents, append) {
256
257    var obj;
258    if (document.getElementById) { // DOM3 = IE5, NS6
259        //document.getElementById(divname).innerHTML = contents;
260    	obj = document.getElementById(divname);
261    } else if (document.layers) {
262        //document.divname.innerHTML = contents;
263    	obj = document.divname;
264    } else {
265        //document.all.divname = contents;
266    	obj = document.all.divname;
267    }
268   
269    // need to check if session expired, so it doesn't
270    // return the login page in a div...
271    if ( contents.match('<title>BizLand Login</title>') ) {
272      contents = 'Your session expired. Please log in.';
273    } 
274
275
276    if (append == 1){
277    	obj.innerHTML += contents ;
278    } else {
279	    obj.innerHTML = contents;
280    }
281}
282
283/*
284makeReq( url , name , append , showprogress , sucfunc , errfunc )
285
286Internal function that creates and executes the XMLRequest. Takes a URL and the name of the div to send the contents to. Other options:
287
288append 		- Append to the div instead of overwriting
289showprogress	- If true it will write to the div as it loads ( doesn't work in IE )
290sucfunc		- A function to run on success. req object is passed in
291errfunc		- A function to run on error. req object is passed in
292
293*/
294function makeReq( url , name, append , showprogress , sucfunc , errfunc ) {
295
296    var req = init();
297    req.onreadystatechange = processRequest;
298        
299    function init() {
300      if (window.XMLHttpRequest) {
301        return new XMLHttpRequest();
302      } else if (window.ActiveXObject) {
303        return new ActiveXObject("Microsoft.XMLHTTP");
304      }
305    }
306
307    function processRequest () {
308      if (req.readyState == 3 && window.XMLHttpRequest && showprogress ) {
309        processReqReal( req.responseText , name, append );
310      }
311      if (req.readyState == 4 ) {
312        if (req.status == 200) {
313          processReqReal( req.responseText , name, append );
314	  if ( sucfunc ) {
315            sucfunc(req)
316          }
317        } else {
318	  processReqReal( 'ERROR', name , append );
319	  if ( errfunc ) {
320	    errfunc(req)
321	  }
322	}
323      }
324    }
325
326    this.doGet = function( noCache ) {
327      req.open("GET", url, true);
328      if ( noCache ) {
329	try {
330	  req.setRequestHeader( 'Cache-Control', 'no-cache' );
331	  req.setRequestHeader( 'Pragma', 'no-cache' );
332	} catch ( e ) {}
333      }
334      req.send(null);
335    }
336    
337    this.doPost = function(body) {
338      req.open("POST", url, true);
339      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
340      
341	// Avoid "1=1" default: treated as SQLi by many WAFs (403 on fragment refresh, etc.).
342	if ( body == null || body === '' ) {
343		body = '_ajax=1';
344	}
345      
346      req.send(body);
347    }
348
349}
350
351/* 
352
353processReqReal( HTML , divname )
354
355Internal function to take HTML from the request and pass it to changeDiv
356
357*/
358function processReqReal( HTML , divname, append )
359{
360	changeDiv(divname,HTML, append)
361}
362
363/*
364switchimg( image_name , imgsrc )
365
366Internal function to change a specific image src
367
368*/
369function switchimg( image_name , imgsrc){
370    if (document.images){
371        document.images[image_name].src = imgsrc;
372    }
373}
374
375
376/* this is an external image switch function
377
378*/
379function ImgForceClose( id, img_path ) {
380
381    var divname = id + "_block";
382    var imgname = id + "_img";
383
384    if ( document.images[imgname] ) {
385      var Imgs = new Object;
386
387        if ( img_path ) {
388          Imgs.minus = img_path+"arrow_down.gif";
389          Imgs.plus = img_path+"arrow_right.gif";
390        }
391        else {
392          Imgs.minus = "https://secure.bizland.com/images/greenarrow.gif";
393          Imgs.plus = "https://secure.bizland.com/images/redarrow.gif";
394        }
395
396      switchimg(imgname,Imgs[ 'plus' ]);
397    }
398
399}
400
401/* two tab switcher */
402function SwitchTabColor ( tab, category, color1, color2 ) {
403
404  if ( document.getElementById ) {
405
406    var clicked_tab = document.getElementById( tab+'_'+category );
407    var other_tab;
408
409    /* get clicked tab and the other tab */
410    if      ( tab == 'tab_link1' ) { other_tab = document.getElementById( 'tab_link2_'+category ); }
411    else if ( tab == 'tab_link2' ) { other_tab = document.getElementById( 'tab_link1_'+category ); }
412    else                           {                                                               }
413
414    /* make the clicked tab darker color and the other tab lighter */
415    if ( clicked_tab.style.backgroundColor == color1 ) {
416      if ( clicked_tab ) {
417        clicked_tab.style.backgroundColor = color2;
418      }
419      if ( other_tab ) {
420        other_tab.style.backgroundColor = color2;
421      }
422    }
423    else if ( clicked_tab.style.backgroundColor == color2 ) {
424      if ( clicked_tab ) {
425        clicked_tab.style.backgroundColor = color1;
426      }
427      if ( other_tab ) {
428        other_tab.style.backgroundColor = color2;
429      }
430    }
431    else {}
432
433  }
434
435}
436
437function getAJAXObj( url ) {
438	var xhttp;
439
440        if ( window.XMLHttpRequest ) {
441	        xhttp = new XMLHttpRequest();
442	} else if ( window.ActiveXObject ) {
443                xhttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
444        } else {
445                return;
446        }
447
448        xhttp.open( 'GET', url, true );
449        xhttp.send( null );
450
451       return xhttp;
452}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.