/*******************************************************************************
*                                                                              *
*  Author    :  John Serris (a.k.a JB)                                         *
*  Web       :  http://phonophunk.com/                                         *
*  E-mail    :  phonophunk ( at ) gmail ( dot ) ( com )                        *
*  Modified  :  14-MAY-2006                                                    *
*                                                                              *
*  Inspired by Shaun Inman's coding style... :)                                *
*                                                                              *
*  Copyright (c) 1999-2006 John Serris (except noted). All Rights Reserved.    *
*  Use of this code is not permitted without my permission!                    *
*                                                                              *
*******************************************************************************/

var d = document, dE = d.documentElement;
dE.className = "jsPageLoad"; // Nice CSS hook to hide stuff until JS completes
var PP = new Object();
window.defaultStatus = "Phono Phunk - The Groove To Make Yo Booty Move";

/* Onload/unload
*******************************************************************************/

PP = {
	init: function() {
		if (navigator.userAgent.indexOf("Opera") != -1) {
			// alert("Your browser sucks arse!!!!!!");
			// Opera note: This POS browser RANDOMLY refuses to run JavaScript
			// when the page is served as application/xhtml+xml. Thanks for the
			// hours of hair pulling Opera!!! You will now be served text/html.
		}
		if (d.getElementById) {
			extraCSS();
			PP.Widgets.StyleSwitcher.init();
			PP.Widgets.ScrollToTop.init();
			PP.Widgets.PanelToggle.init();
			PP.Widgets.HeaderToggle.init();
			dE.className = "jsPageComplete";
			PP.Forms.CommentForm.init();
			PP.Forms.ContactForm.init();
			PP.Ajax.NewsLists.init();
			PP.Ajax.LinkLists.init();
		}
	},
	end: function() {
		fixIELeaks();
	}
};

window.onload = PP.init;
window.onunload = PP.end;

/* Cookies
*******************************************************************************/

PP.Cookies = {
	set: function(name,val,days) {
		var expires = "";
		if (days) {
			var date = new Date();
			date.setTime(date.getTime() + (days*24*60*60*1000));
			expires = "; expires=" + date.toGMTString();
		}
		d.cookie = name + "=" + val + expires + "; path=/";
	},
	get: function(name) {
		name = name + "=";
		var cs = d.cookie.split("; ");
		for (var i = 0, cv; cv = cs[i]; i++) {
			if (cv.indexOf(name) == 0) {
				return cv.substring(name.length,cv.length);
			}
		}
		return null;
	}
};

/* Widgets
*******************************************************************************/

PP.Widgets = {

	// CSS Style Switcher
	StyleSwitcher: {
		init: function() {
			var self = this;
			var ss = d.getElementById("styleswitcher");
			var buttons = ss.getElementsByTagName("a");
			var queryVar = 'style';

			for (var i = 0, btn; btn = buttons[i]; i++) {
				btn.onclick = function() {
					this.blur();
					self.setActive(this.search.substring(queryVar.length+2));
					return false;
				};
			}
		},
		setActive: function(title) {
			var found = 0;
			var slinks = d.getElementsByTagName("link");

			for (var i = 0, slink; l = slinks[i]; i++) {
				if (l.getAttribute("rel").indexOf("style") != -1
				&& l.getAttribute("title")) {
					l.disabled = true;
					if (l.getAttribute("title") == title) {
						l.disabled = false;
						found = 1;
					}
				}
			}

			if (found == 0) {
				var title = this.getPreferred();
				if (title) {
					this.setActive(title);
				}
			}
			this.save();
		},
		getActive: function() {
			var slinks = d.getElementsByTagName("link");

			for (var i = 0, l; l = slinks[i]; i++) {
				if (l.getAttribute("rel").indexOf("style") != -1
				&& l.getAttribute("title") && !l.disabled) {
					return l.getAttribute("title");
				}
			}
			return null;
		},
		getPreferred: function() {
			var slinks = d.getElementsByTagName("link");

			for (var i = 0, l; l = slinks[i]; i++) {
				if (l.getAttribute("rel").indexOf("style") != -1
				&& l.getAttribute("rel").indexOf("alt") == -1
				&& l.getAttribute("title")) {
					return l.getAttribute("title");
				}
			}
			return null;
		},
		load: function() {
			if (d.getElementById) {
				var cookie = PP.Cookies.get("phonophunkstyle");
				var title = cookie || this.getPreferred();
				this.setActive(title);
			}
		},
		save: function() {
			if (d.getElementById) {
				var title = this.getActive();
				PP.Cookies.set("phonophunkstyle", title, 365);
			}
		}
	},

	// Toggle Side Panels
	PanelToggle: {
		pOff: "panel-hidden",
		pOn: "panel-visible",
		persistState: [
			"styleswitcher",
			"search",
			"archives",
			"tools"
		],
		currentState: [],
		init: function() {
			var self = this;

			for (var i = 0, pEl; pEl = this.persistState[i]; i++) {
				var el = d.getElementById(pEl);
				if (el) {
					var h = el.getElementsByTagName("h2")[0];
					el.className = this.pOn;
					h.title = "Toggle this panel";
					h.onclick = function() {
						var p = this.parentNode;
						if (p.className == self.pOn) {
							p.className = self.pOff;
							self.currentState[p.id] = 0;
						} else {
							p.className = self.pOn;
							self.currentState[p.id] = 1;
						}
						self.save();
					};

					if (typeof el.onselectstart != "undefined") {
						el.onselectstart = function() {
							return false;
						};
					}
				}
			}
			this.load();
		},
		load: function() {
			if (d.getElementById) {
				var cookie = PP.Cookies.get("phonophunkpanels");
				if ((cookie != null) && (cookie.length > 0)) {
					var pnlArr = cookie.split(",");
					for (var i = 0, pEl; pEl = this.persistState[i]; i++) {
						var el = d.getElementById(pEl);
						if (el) {
							if (pnlArr[i] == 1) {
								el.className = this.pOn;
								this.currentState[el.id] = 1;
							} else {
								el.className = this.pOff;
								this.currentState[el.id] = 0;
							}
						}
					}
				}
			}
		},
		save: function() {
			if (d.getElementById) {
				var cookie = PP.Cookies.get("phonophunkpanels");
				var undefined;
				if ((cookie != null) && (cookie.length > 0)) {
					var oldArr = cookie.split(",");
				}
				var pnlArr = new Array();
				var pnlCounter = 0;

				for (var i = 0, pEl; pEl = this.persistState[i]; i++) {
					var el = d.getElementById(pEl);
					if (this.currentState[pEl] != undefined) {
						pnlArr[pnlCounter] = this.currentState[pEl];
					} else {
						if (oldArr) {
							pnlArr[pnlCounter] = oldArr[pnlCounter];
						} else {
							pnlArr[pnlCounter] = 1;
						}
					}
					pnlCounter++;
				}
				PP.Cookies.set("phonophunkpanels", pnlArr, 365);
			}
		}
	},

	// Resize Textareas with Animation
	textAreaResizer: {
		running: false,
		timer: null,
		interval: 40,
		tween: 2,
		size: 100,
		minHeight: 40,
		init: function(label, el) {
			if (d.getElementById && d.createElement) {
				var self = this;
				var label = d.getElementById(label);
				var rInc = d.createElement("a");
				var rDec = d.createElement("a");

				rInc.href = "";
				rDec.href = "";
				rInc.title = "Increase the size of the text area";
				rDec.title = "Decrease the size of the text area";
				rInc.className = "resize-inc";
				rDec.className = "resize-dec";
				rInc.onclick = function() {
					self.resize(el,"inc");
					this.blur();
					return false;
				};
				rDec.onclick = function() {
					self.resize(el,"dec");
					this.blur();
					return false;
				};

				label.appendChild(d.createTextNode(" | "));
				rInc.appendChild(d.createTextNode("Increase Text Area"));
				label.appendChild(rInc);

				label.appendChild(d.createTextNode(" | "));
				rDec.appendChild(d.createTextNode("Decrease Text Area"));
				label.appendChild(rDec);
			}
		},
		resize: function(el, val) {
			var self = this;
			clearInterval(this.timer);
			this.running = false;
			this.timer = null;
			val = (val == "inc") ? this.size : 0-this.size;
			var el = d.getElementById(el);
			var height = el.offsetHeight;
			height = (parseInt(height,10) + parseInt(val,10));
			if (height < this.minHeight) {
				height = this.minHeight;
			}
			this.animate(el.id, height);
		},
		animate: function(elId, newHeight) {
			var h = d.getElementById(elId);
			if (this.running) {
				var c = parseInt(h.offsetHeight,10);

				if (c < newHeight) {
					var fHeight = Math.ceil(c+((newHeight-c)/this.tween));

					if (fHeight >= (newHeight-1)) {
						h.style.height = newHeight + "px";
						clearInterval(this.timer);
						this.running = false;
						this.timer = null;
						this.focus(h);
					} else {
						h.style.height = fHeight + "px";
					}
				} else if (c > newHeight) {
					var fHeight = Math.floor(c-((c-newHeight)/this.tween));
					if (fHeight <= (newHeight+1)) {
						h.style.height = newHeight + "px";
						clearInterval(this.timer);
						this.running = false;
						this.timer = null;
						this.focus(h);
					} else {
						h.style.height = fHeight + "px";
					}
				}
			} else {
				this.running = true;
				this.timer = setInterval("PP.Widgets.textAreaResizer.animate('" + elId + "'," + newHeight + ")",this.interval);
			}
		},
		focus: function(el) {
			if (el.createTextRange) {
				var oRange = el.createTextRange();
				oRange.collapse(false);
				oRange.select();
			} else {
				el.focus();
			}
		}
	},

	// Header Image Toggle with Animation
	HeaderToggle: {
		header: null,
		header2: null,
		tab: null,
		running: false,
		timer: null,
		interval: 50,
		tween: 2,
		init: function() {
			var self = this;
			this.header = d.getElementById("head-banner");
			this.header2 = d.getElementById("access-helper");
			var hParent = d.getElementById("head-section");
			this.tab = d.createElement("span");
			this.tab.id = "htab";
			this.tab.title = "Toggle Image";
			hParent.appendChild(this.tab);
			this.tab.onclick = function() {
				if (!self.header.state) {
					self.header.state = 1;
				}
				if (self.header.state == 190) {
					self.header2.className = "";
				}
				if (self.running) {
					return false;
					self.running = false;
					self.timer = null;
					clearInterval(self.timer);
				}
				self.animate();
			}
		},
		animate: function() {
			if (this.running) {
				var c = this.header.offsetHeight;
				if (this.header.state == 1) {
					var fHeight = c/this.tween;
					if (fHeight < 1) {
						this.header.style.height = 0 + "px";
						clearInterval(this.timer);
						this.running = false;
						this.timer = null;
						this.header.state = 190;
						this.header2.className = "up";
						this.tab.className = "up";
					} else {
						this.header.style.height = fHeight + "px";
					}
				} else {
					var fHeight = c*this.tween;
					if (fHeight >= 190) {
						this.header.style.height = 190 + "px";
						clearInterval(this.timer);
						this.running = false;
						this.timer = null;
						this.header.state = 1;
						this.header2.className = "";
						this.tab.className = "";
					} else {
						this.header.style.height = fHeight + "px";
					}
				}
			} else {
				if (this.header.offsetHeight == 0) {
					this.header.style.height = 1 + "px";
				}
				this.running = true;
				this.timer = setInterval("PP.Widgets.HeaderToggle.animate()",this.interval);
			}
		}
	},

	// Scroll To Top Of Page
	ScrollToTop: {
		button: null,
		x: null,
		y: null,
		timer: null,
		interval: 25,
		init: function() {
			var self = this;
			this.button = d.getElementById("backtotop").getElementsByTagName("a")[0];
			this.button.onclick = function() {
				clearTimeout(self.timer);
				this.blur();
				self.animate();
				return false;
			}
		},
		animate: function() {
			// Modified version of http://web-graphics.com/mtarchive/001659.php
			var x1 = x2 = x3 = 0;
			var y1 = y2 = y3 = 0;

			if (dE) {
				x1 = dE.scrollLeft || 0;
				y1 = dE.scrollTop || 0;
			}
			if (d.body) {
				x2 = d.body.scrollLeft || 0;
				y2 = d.body.scrollTop || 0;
			}

			x3 = window.scrollX || 0;
			y3 = window.scrollY || 0;

			var x = Math.max(x1, Math.max(x2, x3));
			var y = Math.max(y1, Math.max(y2, y3));

			window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

			if (x > 0 || y > 0) {
				this.timer = window.setTimeout("PP.Widgets.ScrollToTop.animate()",this.interval);
			} else {
				clearTimeout(this.timer);
			}
		}
	}
};

// Do the styleswitch ASAP.
PP.Widgets.StyleSwitcher.load();

/* Forms
*******************************************************************************/

PP.Forms = {

	// Contact Form
	ContactForm: {
		fName: "contactform",
		init: function() {
			var s = this;
			this.f = d.forms[this.fName];
			if (!this.f) { return; }

			this.email = d.getElementById("senderemail");
			this.msg = d.getElementById("sendermessage");
			this.f.onsubmit = function() {
				return s.validate();
			};
			PP.Widgets.textAreaResizer.init("resizer", "sendermessage");
			PP.Forms.Skin.init(this.f);
		},
		validate: function() {
			if (PP.Forms.Validation.empty(this.email.value)) {
				//this.email.className = "formerror";
				alert ("Hey buddy... How am I suppose to reply to you?");
				this.email.focus();
				return false;
			}
			if (PP.Forms.Validation.empty(this.msg.value)) {
				//this.msg.className = "formerror";
				alert ("Hey buddy... Wouldn't it make more sense to type in a message first?");
				this.msg.focus();
				return false;
			}
		}
	},

	// Comment Form
	CommentForm: {
		fName: "commentform",
		init: function() {
			var self = this;
			this.f = d.forms[this.fName];
			if (!this.f) { return; }

			this.comment = d.getElementById("comment");
			this.preview = d.getElementById("previewform");
			this.commentlist = d.getElementById("commentlist");

			if (this.preview) {
				this.initPrev();
			} else {
				this.f.style.display = "block";
			}

			PP.Widgets.textAreaResizer.init("resizer", "comment");
			PP.Forms.Skin.init(this.f);

			this.f.onsubmit = function() {
				return self.validate();
			};
		},
		initPrev: function() {
			var self = this;
			this.preview.style.display = "block";
			if (this.commentlist) {
				this.commentlist.className = "mini";
			}

			fPreview = this.preview.getElementsByTagName("fieldset")[0];
			fEdit = this.f.getElementsByTagName("fieldset")[0];

			this.f.style.display = "none";
			this.togglePreview = d.getElementById("previewcomment");
			this.toggleEdit = d.getElementById("editcomment");
			this.toggleEdit.className = "off";
			this.togglePreview.onclick = function() {
				self.f.style.display = "none";
				self.preview.style.display = "block";
				self.toggleEdit.className = "off";
				this.className = "";
				this.blur();
				return false;
			};
			this.toggleEdit.onclick = function() {
				self.preview.style.display = "none";
				self.f.style.display = "block";
				self.togglePreview.className = "off";
				this.className = "";
				this.blur();
				return false;
			};
		},
		validate: function() {
			if (PP.Forms.Validation.empty(this.comment.value)) {
				this.comment.className = "formerror";
				alert ("Hey buddy... Wouldn't it make more sense to type in a comment first?");
				this.comment.focus();
				return false;
			}
		}
	},

	// Validation
	Validation: {
		empty: function(v) {
			var x = /^\s*$/;
			return x.test(v);
		}
	},
	Skin: {
		init: function(frm) {
			var inputs = frm.getElementsByTagName("input");
			var textareas = frm.getElementsByTagName("textarea");
			var formEls = new Array();

			for (var i = 0, el; el = inputs[i]; i++) {
				if (el.type == "text") {
					formEls[formEls.length] = el;
				}
			}

			for (var i = 0, el; el = textareas[i]; i++) {
				formEls[formEls.length] = el;
			}

			for (var i = 0, el; el = formEls[i]; i++) {
				var b0 = d.createElement("span");
				var b1 = d.createElement("span");
				var b2 = d.createElement("span");
				var b3 = d.createElement("span");
				var d0 = d.createElement("span");
				var d1 = d.createElement("span");
				var d2 = d.createElement("span");
				var d3 = d.createElement("span");
				b0.className = "jsTxt";
				b0.appendChild(b1);
				b1.appendChild(b2);
				b2.appendChild(b3);
				b3.appendChild(d0);
				d0.appendChild(d1);
				d1.appendChild(d2);
				d2.appendChild(d3);
				el.parentNode.insertBefore(b0, el);
				d3.appendChild(el);
				el.parent = b0;
				el.onfocus = function() {
					this.parent.className = "jsTxt focus";
				};
				el.onblur = function() {
					this.parent.className = "jsTxt";
				};
			}
		}
	}
};

/* Ajax-ified Parts and Utilities
*******************************************************************************/

PP.Ajax = {

	// Util to load XML into a HTML element
	innerXML: function(container, xml) {
		if (typeof DOMParser == "undefined") {
			container.innerHTML = xml;
		} else {
			// Use DOMParser to replicate innerHTML behaviour
			// for documents served as application/xhtml+xml
			var oldXML = document.createRange();
			var frag = '<div xmlns="http://www.w3.org/1999/xhtml">' + xml + "</div>";
			var tree = (new DOMParser()).parseFromString(frag, "text/xml");
			var newXML = document.createDocumentFragment();
			var children = tree.documentElement.childNodes;
			for (var i = 0, child; child = children[i]; i++) {
				newXML.appendChild(d.importNode(child, true));
			}
			if (container.hasChildNodes()) {
				oldXML.setStart(container,0);
				oldXML.setEnd(container,container.childNodes.length);
				oldXML.deleteContents();
			}
			container.appendChild(newXML);
		}

	},

	// Links lists on links page
	LinkLists: {
		ajax: null,
		init: function() {
			if (!d.getElementById("hdlinks")) { return; }
			if (location.search) { return; }
			var self = this;
			this.ajax = XHConn();
			if (this.ajax) {
				var lists = d.getElementById("content").getElementsByTagName("ul");
				for (var i = 0, l; l = lists[i]; i++) {
					l.className = "treeView";
					var alinks = l.getElementsByTagName("a");
					for (var j = 0, al; al = alinks[j]; j++) {
						al.onclick = function() {
							if (this.linkLoaded == true) {
								this.parentNode.className =
									(this.parentNode.className == "expand")
									? ''
									: "expand";
							} else {
								self.getLinks(this);
							}
							return false;
						}
					}
				}
			}
		},
		getLinks: function(alink) {
			var self = this;
			var response = function (oXML) {
				var tempDiv = d.createElement("div");
				PP.Ajax.innerXML(tempDiv, oXML.responseText);
				var ulParent = alink.parentNode.parentNode;
				var lis = ulParent.childNodes;

				for (var i = 0, l; l = lis[i]; i++) {
					if (l.tagName && l.tagName.toLowerCase() == "li") {
						l.appendChild(tempDiv.getElementsByTagName("ul")[0]);
						l.firstChild.linkLoaded = true;
					}
				}
				alink.parentNode.className = "expand";
				tempDiv = null;
			};
			alink.parentNode.className = "loading";
			this.ajax.connect(alink.search.substring(5) + ".php", "GET",
				alink.search.substring(1) + "&ajax=1", response);
		}
	},

	// Recent News and Quick Phunk lists on news page
	NewsLists: {
		rn: null,
		qp: null,
		currentPageNews: 1,
		currentPageQuick: 1,
		counters: null,
		init: function() {
			var self = this;
			this.rn = d.getElementById("recent-news");
			this.qp = d.getElementById("quick-phunk");
			if (this.qp && this.rn) {
				var ajax = XHConn();
				if (ajax) {
					var outCount = function (oXML) {
						eval("self.counters = " + oXML.responseText);
						self.addPager(self.rn);
						self.addPager(self.qp);
					};
					ajax.connect("/news/ajax-results.php", "GET",
						"func=counter", outCount);
				}
			}
		},
		pageResults: function(pageNum, func) {
			var self = this;
			var outNews = function(oXML) {
				self.response(oXML, "news");
			};

			var outQuick = function(oXML) {
				self.response(oXML, "quick");
			};
			if (pageNum < 1) {
				pageNum = 1;
			}
			if (func == 'news') {
				if (pageNum > this.counters["news"]["count"]) {
					pageNum = this.counters["news"]["count"];
				}
				var ajax1 = XHConn();
				ajax1.connect("/news/ajax-results.php", "GET", "func=" +
					func + "&pageNum=" + pageNum, outNews);
				this.currentPageNews = pageNum;
			} else if (func == 'quick') {
				if (pageNum > this.counters["quick"]["count"]) {
					pageNum = this.counters["quick"]["count"];
				}
				var ajax2 = XHConn();
				ajax2.connect("/news/ajax-results.php", "GET",
					"func=" + func + "&pageNum=" + pageNum, outQuick);
				this.currentPageQuick = pageNum;
			}
		},
		response: function(ajaxObj, parent) {
			//alert(ajaxObj.onreadystatechange);
			//alert(ajaxObj.readyState);
			//alert(ajaxObj.responseText);
			//alert(ajaxObj.responseXML);
			//alert(ajaxObj.status);
			//alert(ajaxObj.statusText);

			var newroot;

			if (parent == "news") {
				newroot = this.rn;
				cPage = this.currentPageNews;
				lPage = this.counters["news"]["count"];
			}

			if (parent == "quick") {
				newroot = this.qp;
				cPage = this.currentPageQuick;
				lPage = this.counters["quick"]["count"];
			}

			var pager = cPage + " of " + lPage;

			var ajaxStr = ajaxObj.responseText;
			var navList = newroot.getElementsByTagName("ul")[0]
			var link1 = navList.getElementsByTagName("li")[3];
			var link2 = navList.getElementsByTagName("li")[4];
			var counter = navList.getElementsByTagName("li")[2];
			var container = newroot.getElementsByTagName("dl")[0];

			if (cPage == lPage) {
				link1.getElementsByTagName("a")[0].clickable = false;
				link1.className = "fpPrev off";
			} else {
				link1.getElementsByTagName("a")[0].clickable = true;
				link1.className = "fpPrev";
			}
			if (cPage == 1) {
				link2.getElementsByTagName("a")[0].clickable = false;
				link2.className = "fpNext off";
			} else {
				link2.getElementsByTagName("a")[0].clickable = true;
				link2.className = "fpNext";
			}

			counter.className = "fpCounter";
			counter.firstChild.nodeValue = pager;

			PP.Ajax.innerXML(container, ajaxStr);
		},
		addPager: function(panel) {
			var self = this;
			var liCounter = d.createElement("li");
			var liNav = panel.getElementsByTagName("ul")[0];
			var liPrev = d.createElement("li");
			var liNext = d.createElement("li");
			var Prev = d.createElement("a");
			var Next = d.createElement("a");

			liCounter.className = "fpCounter";
			if (panel == this.rn) {
				var total = this.counters["news"]["count"];
			} else {
				var total = this.counters["quick"]["count"];
			}
			liCounter.appendChild(d.createTextNode("1 of "+total));
			Prev.href = "";
			Next.href = "";
			Prev.title = "Older";
			Next.title = "Newer";
			liPrev.className = "fpPrev";
			liNext.className = "fpNext off";
			Prev.clickable = true;
			Next.clickable = false;
			Prev.onclick = function() {
				this.blur();
				if (this.clickable) {
					Prev.clickable = false;
					Next.clickable = false;
					liPrev.className = "fpPrev off";
					liNext.className = "fpNext off";
					if (panel == self.rn) {
						self.pageResults(self.currentPageNews+1, "news", self.rn);
					} else {
						self.pageResults(self.currentPageQuick+1, "quick", self.qp);
					}
					liCounter.firstChild.nodeValue = "Loading...";
					liCounter.className = "fpCounterLoading";
				}
				return false;
			};
			Next.onclick = function() {
				this.blur();
				if (this.clickable) {
					Prev.clickable = false;
					Next.clickable = false;
					liPrev.className = "fpPrev off";
					liNext.className = "fpNext off";
					if (panel == self.rn) {
						self.pageResults(self.currentPageNews-1, "news", self.rn);
					} else {
						self.pageResults(self.currentPageQuick-1, "quick", self.qp);
					}
					liCounter.firstChild.nodeValue = "Loading...";
					liCounter.className = "fpCounterLoading";
				}
				return false;
			};
			Prev.appendChild(d.createTextNode("Older"));
			liPrev.appendChild(Prev);
			Next.appendChild(d.createTextNode("Newer"));
			liNext.appendChild(Next);
			liNav.appendChild(liCounter);
			liNav.appendChild(liPrev);
			liNav.appendChild(liNext);
		}
	}
};

/* Utils
*******************************************************************************/

// Load some extra CSS for gecko

function extraCSS() {
	if (d.getElementById && d.createAttribute) {
		var eHead = d.getElementsByTagName("head")[0];
		var eLink = d.createElement("link");

		eLink.type = "text/css";
		eLink.media = "screen, projection";
		eLink.href = "/c/adv-moz-100.css";
		eLink.rel = "stylesheet";
		eHead.appendChild(eLink);
	}
}

// Fix some IE memory leaks. Modified version of
// http://youngpup.net/2005/0221010713

function fixIELeaks() {
	if (d.all && window.attachEvent) {
		var elProps = [
			"data", "onmouseover", "onmouseout",
			"onmousedown", "onmouseup", "ondblclick",
			"onclick", "onselectstart", "oncontextmenu"
		];
		var all = d.all;
		for (var i = 0, el; el = all[i]; i++) {
			for (var j = 0, elProp; elProp = elProps[j]; j++) {
				el[elProp] = null;
			}
		}
	}
}

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/

function XHConn() {
	var xmlhttp, bComplete = false;
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	catch (e) { try { xmlhttp = new XMLHttpRequest(); }
	catch (e) { xmlhttp = false; }}}
	if (!xmlhttp) return null;
	this.connect = function(sURL, sMethod, sVars, fnDone) {
		if (!xmlhttp) return false;
		bComplete = false;
		sMethod = sMethod.toUpperCase();

		try {
			if (sMethod == "GET") {
				xmlhttp.open(sMethod, sURL+"?"+sVars, true);
				sVars = "";
			} else {
				xmlhttp.open(sMethod, sURL, true);
				xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
				xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			}
			xmlhttp.onreadystatechange = function(){
				if (xmlhttp.readyState == 4 && !bComplete) {
					bComplete = true;
					fnDone(xmlhttp);
				}
			};
			xmlhttp.send(sVars);
		} catch(z) {
			return false;
		}
		return true;
	};
	return this;
}
