1///////////////////////////////////////////////////////////////////////////////
2//
3// This code taken from:
4// http://www.aspandjavascript.co.uk/javascript/javascript_api/
5//
6//
7// Conditions of Use (from http://www.aspandjavascript.co.uk/about/conditions.asp)
8//
9// The Begging Bowl
10// ================
11// Though the code on the site is free, building, testing and maintaining dHTML
12// code is a nasty laborious business and takes up a lot of time. If you use
13// code from ASPAndJavaScript.co.uk in a commercial website, or for a paying
14// client or use software from the site in a commercial environment, we politely
15// invite you to consider making a donation of $20 (or whatever you consider
16// appropriate) to help support the site.
17//
18// Donations can be made through PayPal using the button on the left of the page,
19// or "in kind" through our Amazon Wish List (click the link and search for
20// jamesdoz@hotmail.com). Donations go towrds the hosting costs of the site.
21//
22// You can also offer support by visiting our sister site ComputerBookPrices.com
23// and using the price comparison system to find great deals on computer books
24// and manuals.
25//
26//
27// Copyright
28// =========
29// All code available on this site is copyrighted to James Austin (unless
30// otherwise stated) and must retain any copyright messages.
31//
32//
33// Disclaimer
34// ==========
35// All code on the site is available to download for free. No liability is
36// accepted for any loss or damage, financial or otherwise arising from the
37// viewing or use of this web site or any of its contents.
38//
39//
40// Technical Support
41// =================
42// As stated above, we accept no liability for the contents of the site and do
43// not guarantee to offer technical support for it. We do, however, appreciate
44// feedback and always try to answer any questions and queries as thouroughly
45// as time allows.
46//
47// If you have problems using the code or just questions about how it all works,
48// please contact us at jamesdoz@hotmail.com, bug reports can be submitted to
49// the same address
50//
51// Please include as much information as possible with your query, such as
52// operating system, browser etc. Error messages and screenshots (where
53// applicable) are helpful too.
54//
55///////////////////////////////////////////////////////////////////////////////
56
57function sniffBrowsers() {
58	var ns4 = document.layers;
59	var op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) ||(navigator.userAgent.indexOf("Opera/5")!=-1);
60	var op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) ||(navigator.userAgent.indexOf("Opera/6")!=-1);
61	var agt=navigator.userAgent.toLowerCase();
62	var mac = (agt.indexOf("mac")!=-1);
63	var ie = (agt.indexOf("msie") != -1);
64	var mac_ie = mac && ie;
65}
66
67
68function getStyleObject(objectId) {
69    if(document.getElementById && document.getElementById(objectId)) {
70	return document.getElementById(objectId).style;
71    } else if (document.all && document.all(objectId)) {
72	return document.all(objectId).style;
73    } else if (document.layers && document.layers[objectId]) {
74		return getObjNN4(document,objectId);
75    } else {
76	return false;
77    }
78}
79
80function changeObjectVisibility(objectId, newVisibility) {
81    var styleObject = getStyleObject(objectId, document);
82    if(styleObject) {
83	styleObject.visibility = newVisibility;
84	return true;
85    } else {
86	return false;
87    }
88}
89
90function findImage(name, doc) {
91	var i, img;
92	for (i = 0; i < doc.images.length; i++) {
93    	if (doc.images[i].name == name) {
94			return doc.images[i];
95		}
96	}
97	for (i = 0; i < doc.layers.length; i++) {
98    	if ((img = findImage(name, doc.layers[i].document)) != null) {
99			img.container = doc.layers[i];
100			return img;
101    	}
102	}
103	return null;
104}
105
106function getImage(name) {
107	if (document.layers) {
108    	return findImage(name, document);
109	}
110	return null;
111}
112
113function getObjNN4(obj,name)
114{
115	var x = obj.layers;
116	var foundLayer;
117	for (var i=0;i<x.length;i++)
118	{
119		if (x[i].id == name)
120		 	foundLayer = x[i];
121		else if (x[i].layers.length)
122			var tmp = getObjNN4(x[i],name);
123		if (tmp) foundLayer = tmp;
124	}
125	return foundLayer;
126}
127
128function getElementHeight(Elem) {
129	if (ns4) {
130		var elem = getObjNN4(document, Elem);
131		return elem.clip.height;
132	} else {
133		var elem;
134		if(document.getElementById) {
135			var elem = document.getElementById(Elem);
136		} else if (document.all){
137			var elem = document.all[Elem];
138		}
139		if (op5) {
140			xPos = elem.style.pixelHeight;
141		} else {
142			xPos = elem.offsetHeight;
143		}
144		return xPos;
145	}
146}
147
148function getElementWidth(Elem) {
149	if (ns4) {
150		var elem = getObjNN4(document, Elem);
151		return elem.clip.width;
152	} else {
153		var elem;
154		if(document.getElementById) {
155			var elem = document.getElementById(Elem);
156		} else if (document.all){
157			var elem = document.all[Elem];
158		}
159		if (op5) {
160			xPos = elem.style.pixelWidth;
161		} else {
162			xPos = elem.offsetWidth;
163		}
164		return xPos;
165	}
166}
167
168function getElementLeft(Elem) {
169	if (ns4) {
170		var elem = getObjNN4(document, Elem);
171		return elem.pageX;
172	} else {
173		var elem;
174		if(document.getElementById) {
175			var elem = document.getElementById(Elem);
176		} else if (document.all){
177			var elem = document.all[Elem];
178		}
179		xPos = elem.offsetLeft;
180		tempEl = elem.offsetParent;
181  		while (tempEl != null) {
182  			xPos += tempEl.offsetLeft;
183	  		tempEl = tempEl.offsetParent;
184  		}
185		return xPos;
186	}
187}
188
189
190function getElementTop(Elem) {
191	if (ns4) {
192		var elem = getObjNN4(document, Elem);
193		return elem.pageY;
194	} else {
195		if(document.getElementById) {
196			var elem = document.getElementById(Elem);
197		} else if (document.all) {
198			var elem = document.all[Elem];
199		}
200		yPos = elem.offsetTop;
201		tempEl = elem.offsetParent;
202		while (tempEl != null) {
203  			yPos += tempEl.offsetTop;
204	  		tempEl = tempEl.offsetParent;
205  		}
206		return yPos;
207	}
208}
209
210
211function getImageLeft(myImage) {
212	var x, obj;
213	if (document.layers) {
214		var img = getImage(myImage);
215    	if (img.container != null)
216			return img.container.pageX + img.x;
217		else
218			return img.x;
219  	} else {
220		return getElementLeft(myImage);
221	}
222	return -1;
223}
224
225function getImageTop(myImage) {
226	var y, obj;
227	if (document.layers) {
228		var img = getImage(myImage);
229		if (img.container != null)
230			return img.container.pageY + img.y;
231		else
232			return img.y;
233	} else {
234		return getElementTop(myImage);
235	}
236	return -1;
237}
238
239function getImageWidth(myImage) {
240	var x, obj;
241	if (document.layers) {
242		var img = getImage(myImage);
243		return img.width;
244	} else {
245		return getElementWidth(myImage);
246	}
247	return -1;
248}
249
250function getImageHeight(myImage) {
251	var y, obj;
252	if (document.layers) {
253		var img = getImage(myImage);
254		return img.height;
255	} else {
256		return getElementHeight(myImage);
257	}
258	return -1;
259}
260
261function moveXY(myObject, x, y) {
262	obj = getStyleObject(myObject)
263	if (ns4) {
264		obj.top = y;
265 		obj.left = x;
266	} else {
267		if (op5) {
268			obj.pixelTop = y;
269 			obj.pixelLeft = x;
270		} else {
271			obj.top = y + 'px';
272 			obj.left = x + 'px';
273		}
274	}
275}
276
277function changeClass(Elem, myClass) {
278	var elem;
279	if(document.getElementById) {
280		var elem = document.getElementById(Elem);
281	} else if (document.all){
282		var elem = document.all[Elem];
283	}
284	elem.className = myClass;
285}
286
287function changeImage(target, source) {
288	var imageObj;
289
290	if (ns4) {
291		imageObj = getImage(target);
292		if (imageObj) imageObj.src = eval(source).src;
293	} else {
294		imageObj = eval('document.images.' + target);
295		if (imageObj) imageObj.src = eval(source).src;
296	}
297}
298
299function changeBGColour(myObject, colour) {
300	if (ns4) {
301		var obj = getObjNN4(document, myObject);
302		obj.bgColor=colour;
303	} else {
304		var obj = getStyleObject(myObject);
305		if (op5) {
306			obj.background = colour;
307		} else {
308			obj.backgroundColor = colour;
309		}
310	}
311}
312