/*----------------------------------------------------------------------------
Events (coded for Mozilla compatibility)
----------------------------------------------------------------------------*/
function addEvent(oObject, sEventName, fnHandler) {
	if (oObject) {
		if (oObject.addEventListener) oObject.addEventListener(sEventName, fnHandler, false);
		else if (oObject.attachEvent) oObject.attachEvent("on" + sEventName, fnHandler);
	}
}
function removeEvent(oObject, sEventName, fnHandler) {
	if (oObject) {
		if (oObject.removeEventListener) oObject.removeEventListener(sEventName, fnHandler, false);
		else if (oObject.detachEvent) oObject.detachEvent("on" + sEventName, fnHandler);
	}
}
function fireHTMLEvent(oObject,sEventName) {
	if (oObject.addEventListener) {
		var oEvent = document.createEvent("HTMLEvents");
        oEvent.initEvent(sEventName,true,true);
        oObject.dispatchEvent(oEvent);
	} else if (oObject.attachEvent) {
            oObject.fireEvent("on" + sEventName);
      }
}

 
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode){
		switch (where){
			case 'beforeBegin':	return this.parentNode.insertBefore(parsedNode,this)
				break;
			case 'afterBegin':	return this.insertBefore(parsedNode,this.firstChild);
				break;
			case 'beforeEnd':	return this.appendChild(parsedNode);
				break;
			case 'afterEnd':
				if (this.nextSibling) return this.parentNode.insertBefore(parsedNode,this.nextSibling);
				else return this.parentNode.appendChild(parsedNode);
				break;
		}
	}
}

addEvent(window,"load",onLoadActions_MozDOMFunctions)
function onLoadActions_MozDOMFunctions() {
	var aTables = document.getElementsByTagName("TABLE");
	if((aTables.length > 0) && (typeof aTables[0].moveRow == "undefined")){
		Node.prototype.moveRow = function(){
			if(this && this.nodeName.match(/^(table|t(body|head|foot))$/i)){
				try {
					srcIndex = (!arguments[0] && arguments[0] != 0?-1:arguments[0]);
					destIndex = (!arguments[1] && arguments[1] != 0?-1:arguments[1]);

					// Makes sure the row exists and then makes sure the insertable row isn't greater then the length
					if(!this.rows[srcIndex] || destIndex > this.rows.length){
						var err = new Error();
						throw err;
					}

					// This is just so that it gets put in the right place.
					if(destIndex > srcIndex) destIndex = destIndex+1;
					else if(srcIndex > destIndex) srcIndex = srcIndex+1;

					var oNewRow = this.insertRow(destIndex);

					//transfer styles, etc.  Tried using cloneNode and insertBefore, but apparently Firefox doesn't have insertBefore
					oNewRow.innerHTML = this.rows[srcIndex].innerHTML;
					oNewRow.className = this.rows[srcIndex].className;
					oNewRow.style.backgroundColor = this.rows[srcIndex].style.backgroundColor;
					oNewRow.setAttribute("keyID",this.rows[srcIndex].getAttribute("keyID"));
					
					this.deleteRow(srcIndex);
				} catch(err) {
					throwConsoleError("FF MozCompatibility Script",err);
				}
			}
		}
	    
	}
}