// Manifesto: $Id: ajaxdom.js,v 1.70 2009/03/13 00:23:46 spud Exp $
// license: GNU LGPL
// copyright 2001-2008: dada typo and contributors

Function.prototype.bind = function() {
  var __method = this, object = arguments[0];
  return function() {
    return __method.apply(object);
  }
}
String.prototype.trim = function() { 
	return this.replace(/^\s+|\s+$/g, "");
};
function getObjectRef(id,doc) {
	if (!doc) doc = document;
	if (typeof id == "string") {
		var obRef;
		if (document.getElementById) {
			obRef = doc.getElementById(id);
		} else if (document.all) {
			obRef = doc.all[id];
		}
		if (obRef !== null && typeof obRef != "undefined") { return obRef; }
	} else if (typeof id == "object") {
		return id;
	}
	return false;
}
function closeParent(obj) {
	if (obj.parentNode && obj.parentNode.parentNode) {
		obj.parentNode.parentNode.removeChild(obj.parentNode);
	}
	return false;
}
function getNodeValue(obj) {
	var txt = "";
	if (obj.hasChildNodes()) {
		for(var i=0;i<obj.childNodes.length;i++) {
			if (obj.childNodes[i].nodeType == 3) {
				txt += obj.childNodes[i].nodeValue;
			} else if (obj.childNodes[i].nodeType == 1) {
				txt += "<"+obj.childNodes[i].nodeName+">";
				txt += getNodeValue(obj.childNodes[i]);
				txt += "</"+obj.childNodes[i].nodeName+">";
			}
		}
		return txt;
	} else {
		return "";
	}
}
function reID(obj,before,after) {
	var oldid,oldname;
	var beforepat = new RegExp(before,"gi");
	if (oldid = dtDOM.getAttr(obj,"id")) {
		dtDOM.setAttr(obj,"id",oldid.replace(beforepat,after));
		if (oldname = dtDOM.getAttr(obj,"name")) {
			dtDOM.setAttr(obj,"name",oldname.replace(beforepat,after));
		}
	}
	if (obj.hasChildNodes()) {
		for(var i=0;i<obj.childNodes.length;i++) {
			reID(obj.childNodes[i],before,after);
		}
	}
}
function ajaxLog(msg) {
	var http = new AJAXobj(dtDOM.g_url+"rpc_reference.php");
	function nofunction() {
		return false;
	}
	http.method = 'post';
	http.rHandler = nofunction;
	http.dosend("f=log&message="+encodeURIComponent(msg),"text");
	return false;
}
function DOMobj() {
	var ua = navigator.userAgent;
	this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
	this.isMSIE5 = this.isMSIE && (ua.indexOf("MSIE 5") != -1);
	this.isMSIE6 = this.isMSIE && (ua.indexOf("MSIE 6") != -1);
	this.isMSIE7 = this.isMSIE && (ua.indexOf("MSIE 7") != -1);
	this.isGecko = ua.indexOf("Gecko") != -1;
	this.isSafari = ua.indexOf("Safari") != -1;
	this.isMobileSafari = ua.indexOf("iPhone") != -1;
	this.isOpera = ua.indexOf("Opera") != -1;
	this.isMac = ua.indexOf("Mac") != -1;
	this.isNS7 = ua.indexOf("Netscape/7") != -1;
	this.isNS71 = ua.indexOf("Netscape/7.1") != -1;
	this.g_url = "";
	this.sliders = [];
	this.doc = document;
}

DOMobj.prototype.getAttr = function(obj,prop) {
	if (!obj) { return false; }
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	// if this is a text node, skip it
	if (obj.nodeType != 1) { return ""; }
	if (prop == "class" && this.isMSIE) {
		prop = "className";
	}
	if (obj[prop]) {
		if (obj.nodeName == "FORM") {
			return obj.getAttribute(prop)
		}
		return obj[prop];
	} else {
		if (this.isMSIE) {
			return obj.getAttribute(prop);
		} else {
			if (obj.hasAttribute(prop)) {
				return obj.getAttribute(prop);
			} else {
				return "";
			}
		}
	}
	return "";
}
DOMobj.prototype.setAttr = function(obj,prop,val) {
	if (!obj) { return false; }
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	if (typeof prop == "object") {
		for (var n in prop) {
			val = prop[n];
			if (n == "class" && this.isMSIE) {
				n = "className";
			}
			// shortcut to prevent value/defaultValue distinction
			if (n == "value") {
				obj.value = val;
			} else {
				obj.setAttribute(n,val);
			}
		}
	} else {
		if (prop == "class" && this.isMSIE) {
			prop = "className";
		}
		// shortcut to prevent value/defaultValue distinction
		if (prop == "value") {
			obj.value = val;
		} else {
			obj.setAttribute(prop,val,0);
		}
	}
}
DOMobj.prototype.removeAttr = function(obj,prop) {
	if (!obj) { return false; }
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	if (prop == "class" && this.isMSIE) {
		prop = "className";
	}
	return obj.removeAttribute(prop);
}
DOMobj.prototype.getWindowHeight = function() {
	if (window.innerHeight) {
		this.windowHeight = window.innerHeight;
	} else {
		this.windowHeight = this.doc.body.parentNode.clientHeight;
	}
	return this.windowHeight;
}
DOMobj.prototype.cursorX = function(evt) {
	if (evt.clientX) { return evt.clientX; }
	return false;
}
DOMobj.prototype.cursorY = function(evt) {
	if (evt.clientY) { return evt.clientY; }
	return false;
}
DOMobj.prototype.scrollX = function() {
	if (this.doc.window.scrollX) { return this.doc.window.scrollX; }
	var db = this.doc.body, dbp = this.doc.body.parentNode;
	if (db && db.scrollTop) {
		return db.scrollTop;
	} else if (dbp && dbp.scrollTop) {
		return dbp.scrollTop;
	}
	return false;
}
DOMobj.prototype.scrollY = function() {
	if (this.doc.window.scrollY) { return this.doc.window.scrollY; }
	var db = this.doc.body, dbp = this.doc.body.parentNode;
	if (db && db.scrollTop) {
		return db.scrollTop;
	} else if (dbp && dbp.scrollTop) {
		return dbp.scrollTop;
	}
	return false;
}
DOMobj.prototype.pageX = function(evt) {
	if (evt.pageX) { return evt.pageX; }
	var dd = this.doc.documentElement, db = this.doc.body;
	if (dd && dd.scrollLeft) {
		return evt.clientX + dd.scrollLeft;
	} else if (db) {
		return evt.clientX + db.scrollLeft;
	}
	return evt.clientX;
}
DOMobj.prototype.pageY = function(evt) {
	if (evt.pageY) { return evt.pageY; }
	var dd = this.doc.documentElement, db = this.doc.body;
	if (dd && dd.scrollTop) {
		return evt.clientY + dd.scrollTop;
	} else if (db) {
		return evt.clientY + db.scrollTop;
	}
	return evt.clientY;
}
DOMobj.prototype.getOffsetLeft = function(obj) {
	var x = obj.offsetLeft;
	var parent = obj.offsetParent;
	while (parent) {
		x += parent.offsetLeft;
		parent = parent.offsetParent;
	}
	return x;
}
DOMobj.prototype.getOffsetTop = function(obj) {
	var y = obj.offsetTop;
	var parent = obj.offsetParent;
	while (parent) {
		y += parent.offsetTop;
		parent = parent.offsetParent;
	}
	return y;
}
DOMobj.prototype.setHandler = function(obj,h,f) {
	if (this.isMSIE) {
		obj[h] = new Function(f);
	} else {
		dtDOM.setAttr(obj,h,f);
	}
};
DOMobj.prototype.addEvent = function(obj,ev,func) {
	if (this.isMSIE) {
		obj.attachEvent("on"+ev,func);
	} else {
		obj.addEventListener(ev,func,false);
	}
};
DOMobj.prototype.removeEvent = function(obj,ev,func) {
	if (this.isMSIE) {
		obj.detachEvent("on"+ev,func);
	} else {
		obj.removeEventListener(ev,func,false);
	}
};
DOMobj.prototype.getStyle = function(obj,prop) {
	if (!obj) { return false; }
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	var value = null;
	if (prop == "opacity" && obj.filters) {
		value = 1;
		try {
			value = obj.filters.item("DXImageTransform.Microsoft.Alpha").opacity/100;
		} catch(e) {
			try {
				value = obj.filters.item("alpha").opacity/100;
			} catch(e) {
				value = 1.0;
			}
		}
	} else if (prop == "height" || prop == "width") {
		if (obj.style[prop]) {
			value = obj.style[prop];
		} else if (obj.currentStyle && obj.currentStyle[prop]) {
			value = obj.currentStyle[prop];
		}
		if (value == "auto") {
			if (prop == "height") {
				value = obj.offsetHeight;
			} else {
				value = obj.offsetWidth;
			}
		}
	} else if (obj.style[prop]) {
		value = obj.style[prop];
	} else if (obj.currentStyle && obj.currentStyle[prop]) {
		value = obj.currentStyle[prop];
	} else if (document.defaultView && document.defaultView.getComputedStyle) {
		var thecss = document.defaultView.getComputedStyle(obj,null);
		if (thecss !== null) {
			value = thecss.getPropertyValue(prop);
		}
	}
	return value;
};
DOMobj.prototype.getHeight = function(obj) {
	if (!obj) { return false; }
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	var value = null;
	if (obj.style["height"]) {
		value = obj.style["height"];
	} else if (obj.currentStyle && obj.currentStyle["height"]) {
		value = obj.currentStyle["height"];
	} else if (document.defaultView && document.defaultView.getComputedStyle) {
		var thecss = document.defaultView.getComputedStyle(obj,null);
		if (thecss !== null) {
			value = thecss.getPropertyValue("height");
		}
	}
	if (value == "auto" || value == "null") {
		value = obj.offsetHeight;
	}
	// hack to fix IE miscalculation in case of equal-length columns hack
	if (value > 32000) {
		value = parseInt(value) - 32727;
	}
	return value;
};
DOMobj.prototype.getWidth = function(obj) {
	if (!obj) { return false; }
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	var value = null;
	if (obj.style["width"]) {
		value = obj.style["width"];
	} else if (obj.currentStyle && obj.currentStyle["width"]) {
		value = obj.currentStyle["width"];
	} else if (document.defaultView && document.defaultView.getComputedStyle) {
		var thecss = document.defaultView.getComputedStyle(obj,null);
		if (thecss !== null) {
			value = thecss.getPropertyValue("width");
		}
	}
	if (value == "auto" || value == "null") {
		value = obj.offsetWidth;
	}
	return value;
};
DOMobj.prototype.setStyle = function(obj,prop,value) {
	if (!obj) { return false; }
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	try {
		if (typeof prop == "object") {
			for (var n in prop) {
				switch(n) {
					case "opacity":
						if (obj.filters) {
							obj.style.filter = "alpha(opacity="+prop[n]*100+")";
							if (!obj.currentStyle.hasLayout) obj.style.zoom = 1;
						} else {
							obj.style.opacity = prop[n];
							obj.style["-moz-opacity"] = prop[n];
							obj.style["-khtml-opacity"] = prop[n];
						}
						break;
					case "float":
						if (dtDOM.isMSIE) {
							obj.style["styleFloat"] = prop[n];
						} else {
							obj.style["cssFloat"] = prop[n];
						}
						break;
					default:
						obj.style[n] = prop[n];
				}
			}
		} else {
			switch(prop) {
				case "opacity":
					if (obj.filters) {
						obj.style.filter = "alpha(opacity="+value*100+")";
						if (!obj.currentStyle.hasLayout) obj.style.zoom = 1;
					} else {
						obj.style.opacity = value;
						obj.style["-moz-opacity"] = value;
						obj.style["-khtml-opacity"] = value;
					}
					break;
				case "float":
					if (dtDOM.isMSIE) {
						obj.style["styleFloat"] = value;
					} else {
						obj.style["cssFloat"] = value;
					}
					break;
				default:
					obj.style[prop] = value;
			}
		}
	}
	catch(e) {
		//alert("Object "+obj+" could not set "+prop+" to "+value);
	}
};
DOMobj.prototype.removeStyle = function(obj,prop) {
	if (obj.style.removeProperty) {
		obj.style.removeProperty(prop);
	} else {
		obj.style[prop] = "";
	}
};
DOMobj.prototype.hasClass = function(obj,value) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	var cclass = this.getAttr(obj,"class");
	if (cclass == value) { return true; }
	if (cclass) {
		var loc = cclass.indexOf(value);
		if (loc == -1) return false;
		// match only full strings, not substrings
		var space = cclass.indexOf(" ");
		if (space == -1) return false;
		if (space > loc && cclass.substring(loc,space) != value) return false;
		// might need another check for triplet names (more than one space)
		return true;
	}
	return false;
};
DOMobj.prototype.addClass = function(obj,value) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	var cclass = this.getAttr(obj,"class");
	if (cclass === null || cclass == "") {
		this.setAttr(obj,"class",value);
		return;
	}
	if (cclass == value) { return; }
	if (cclass.indexOf(value) == -1) {
		this.setAttr(obj,"class",cclass+" "+value);
	}
};
DOMobj.prototype.removeClass = function(obj,value) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	var cclass = dtDOM.getAttr(obj,"class");
	var cpos = cclass.indexOf(value);
	if (cpos == -1) {
		return;
	} else if (cpos == 0) {
		if (cclass.length == value.length) {
			dtDOM.setAttr(obj,"class",cclass.replace(value,""));
		} else {
			dtDOM.setAttr(obj,"class",cclass.replace(value+" ",""));
		}
	} else {
		dtDOM.setAttr(obj,"class",cclass.replace(" "+value,""));
	}
};
DOMobj.prototype.toggleClass = function(obj,class1,class2) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	var eclass = this.getAttr(obj,"class");
	if (eclass == class1) {
		this.setAttr(obj,"class",class2);
	} else if (eclass == class2) {
		this.setAttr(obj,"class",class1);
	}
};
DOMobj.prototype.swapClass = function(obj,class1,class2) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	var eclass = this.getAttr(obj,"class");
	if (eclass != "") {
		this.setAttr(obj,"class",eclass.replace(class1,class2));
	}
};
DOMobj.prototype.getEventTarget = function(e) {
	if (e.srcElement) {
		return e.srcElement;
	} else if (e.target) {
		return e.target;
	}
	return null;
}
DOMobj.prototype.showHide = function(obj,force) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	if (!obj) return false;
	var disp = dtDOM.getStyle(obj,"display");
	if (this.isSafari && disp === null) {
		disp = "";
		if (dtDOM.hasClass(obj,"hidden")) dtDOM.removeClass(obj,"hidden");
	}
	if (force) {
		if (this.isMSIE) {
			if (obj.nodeName == "TR" && force == "table-row") {
				force = "block";
			} else if (obj.nodeName == "TBODY" && force == "table-row-group") {
				force = "block";
			}
		}
		obj.style.display = force;
	} else if (disp != "none" && disp != "") {
		obj.style.display = "none";
	} else {
		switch(obj.nodeName) {
			case "TABLE":
				if (this.isMSIE) {
					obj.style.display = "block";
				} else {
					obj.style.display = "table";
				}
				break;
			case "TBODY":
				if (this.isMSIE) {
					obj.style.display = "block";
				} else {
					obj.style.display = "table-row-group";
				}
				break;
			case "TR":
				if (this.isMSIE) {
					obj.style.display = "block";
				} else {
					obj.style.display = "table-row";
				}
				break;
			case "LI":
				if (this.isMSIE) {
					obj.style.display = "block";
				} else {
					obj.style.display = "list-item";
				}
				break;
			case "A":
			case "SPAN":
			case "IMG":
			case "INPUT":
				obj.style.display = "inline";
				break;
			default:
				obj.style.display = "block";
		}
	}
	return false;
};
DOMobj.prototype.dropShowHide = function(elem,obj,force) {
	dtDOM.showHide(obj,force);
	var disp = dtDOM.getStyle(obj,"display");
	var src = dtDOM.getAttr(elem,"src");
	if (disp == 'none') {
		dtDOM.setAttr(elem,"src",src.replace('undrop','drop'));
	} else {
		dtDOM.setAttr(elem,"src",src.replace('drop','undrop'));
	}
}
DOMobj.prototype.zoomImage = function(e,url) {
	var z;
	var evt = e ? e : window.event;
	if (dtDOM.isMSIE) {
		win_h = document.body.parentNode.clientHeight;
		win_w = document.body.parentNode.clientWidth;
	} else {
		win_h = window.innerHeight;
		win_w = window.innerWidth;
	}
	max_h = win_h - 150;
	max_w = win_w - 200;
	z = blackout();
	var zinner = dtDOM.buildElement("DIV","zoomDiv");
	var zimg = dtDOM.buildElement("IMG","zoomImage",{ "src": url , "alt": "Full-Size Image" });
	// get the height of the new element
	h = dtDOM.getHeight(zimg);
	w = dtDOM.getWidth(zimg);
	if (h <= max_h && w <= max_w) {
		final_h = h;
		final_w = w;
	} else {
		if (h > max_h) {
			final_h = max_h;
			// reduce width by same proportion
			w = w * (max_h/h);
		} else {
			final_h = h;
		}
		if (w > max_w) {
			final_w = max_w;
			final_h = final_h * (max_w/w);
		} else {
			final_w = w;
		}
	}
	dtDOM.setStyle(zinner,"backgroundColor","#ffffff");
	dtDOM.setStyle(zinner,"height",(final_h+50)+"px");
	dtDOM.setStyle(zinner,"width",(final_w+20)+"px");
	dtDOM.setStyle(zinner,"textAlign","center");
	dtDOM.setStyle(zinner,"verticalAlign","middle");
	dtDOM.setStyle(zinner,"margin", "20px auto");
	dtDOM.setStyle(zimg,{"margin":"10px","maxHeight":final_h+"px","maxWidth":final_w+"px"});
	zinner.appendChild(zimg);
	var zcloser = dtDOM.buildElement("DIV");
	dtDOM.setStyle(zcloser,{"color":"#000000","fontSize":"12px","textAlign":"left"});
	var closeimg = dtDOM.buildElement("IMG","closeImage",{ "src": "/images/default/icons/closebox.gif" , "alt": "Close", "height": "12px", "width": "12px" });
	dtDOM.setStyle(closeimg,{"margin": "0 6px 0 10px"});
	zcloser.appendChild(closeimg);
	zcloser.appendChild(document.createTextNode('CLOSE'));
	zinner.appendChild(zcloser);
	z.appendChild(zinner);
	if (evt.returnValue) {
		evt.returnValue = false;
	} else if (evt.preventDefault) {
		evt.preventDefault();
	} else {
		return false;
	}
}
DOMobj.prototype.showThumb = function(e,src) {
	var target = dtDOM.getEventTarget(e);
	var newimg = dtDOM.buildElement("IMG","thumbpop",{"src": src, "alt": src});
	dtDOM.setStyle(newimg,{"position": "absolute", "bottom": "20px", "left": "20px", "zIndex": 100});
	dtDOM.setStyle(target.parentNode,"position","relative");
	target.parentNode.appendChild(newimg);
}
DOMobj.prototype.hideThumb = function() {
	var obj;
	if (obj = getObjectRef("thumbpop")) {
		obj.parentNode.removeChild(obj);
	}
}
DOMobj.prototype.slide = function(obj,step,intvl) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	dtDOM.setStyle(obj,"overflow","hidden");
	dtDOM.slideobj = obj;
	dtDOM.slideobj.step = step;
	dtDOM.slideobj.interval = intvl;
	var disp = dtDOM.getStyle(obj,"display");
	if (!disp || disp == "none") {
		this.setStyle(obj,"visibility","hidden");
		this.showHide(obj);
		var h = dtDOM.getHeight(dtDOM.slideobj);
		dtDOM.setStyle(dtDOM.slideobj,"height",0);
		this.setStyle(obj,"visibility","visible");
		dtDOM.slideobj.h = parseInt(h);
		// double step if this is a huge slide
		if (dtDOM.slideobj.h > step * 10) { dtDOM.slideobj.step += step; }
		slideInt = setInterval("dtDOM.doSlideIn()",dtDOM.slideobj.interval);
	} else {
		var h = dtDOM.getHeight(dtDOM.slideobj);
		dtDOM.slideobj.h = parseInt(h);
		// double step if this is a huge slide
		if (dtDOM.slideobj.h > step * 10) { dtDOM.slideobj.step += step; }
		slideInt = setInterval("dtDOM.doSlideOut()",dtDOM.slideobj.interval);
	}
	//console.log("Starting height is "+dtDOM.slideobj.h+"px");
}
DOMobj.prototype.doSlideIn = function() {
	if (dtDOM.slideobj) {
		var h = parseInt(dtDOM.getHeight(dtDOM.slideobj));
		//console.log(dtDOM.slideobj.id+" height is "+h+"px slidingIn");
		if (h < dtDOM.slideobj.h) {
			if (h + dtDOM.slideobj.step > dtDOM.slideobj.h) {
				dtDOM.setStyle(dtDOM.slideobj,"height",dtDOM.slideobj.h+"px");
				clearInterval(slideInt);
				dtDOM.slideobj = null;
			} else {
				dtDOM.setStyle(dtDOM.slideobj,"height",h+dtDOM.slideobj.step+"px");
			}
		} else {
			clearInterval(slideInt);
			dtDOM.slideobj = null;
		}
	}
}
DOMobj.prototype.doSlideOut = function() {
	if (dtDOM.slideobj) {
		var h = parseInt(dtDOM.getHeight(dtDOM.slideobj));
		//console.log(dtDOM.slideobj.id+" height is "+h+"px slidingOut");
		if (h > 0) {
			if (h - dtDOM.slideobj.step <= 0) {
				this.showHide(dtDOM.slideobj);
				dtDOM.setStyle(dtDOM.slideobj,"height",dtDOM.slideobj.h+"px");
				clearInterval(slideInt);
				dtDOM.slideobj = null;
			} else {
				dtDOM.setStyle(dtDOM.slideobj,"height",h-dtDOM.slideobj.step+"px");
			}
		} else {
			clearInterval(slideInt);
			dtDOM.slideobj = null;
		}
	}
		
}
DOMobj.prototype.makeEditable = function(basename,type,id,func) {
	params = false;
	if (arguments.length > 4) params = arguments[4];
	var oldobj = getObjectRef(basename);
	switch(type) {
		case 'input':
			var input = dtDOM.buildElement("INPUT","input_"+basename,{"type":"text","name":"input_"+basename,"size":40});
			if (params) dtDOM.setAttr(input,params);
			dtDOM.setHandler(input,"onblur","return "+func+"('"+basename+"',"+id+");");
			dtDOM.showHide(oldobj);
			dtDOM.setAttr(input,"value",oldobj.innerHTML);
			oldobj.parentNode.insertBefore(input,oldobj);
			var fader = new Fader();
			fader.fade(input,"in",50);
			input.select();
			if (!dtDOM.isMobileSafari) input.focus();
			break;
		case 'textarea':
			var input = dtDOM.buildElement("TEXTAREA","input_"+basename,{"type":"text","name":"input_"+basename,"cols":40});
			if (params) dtDOM.setAttr(input,params);
			dtDOM.setStyle(input,"display","none");
			dtDOM.setHandler(input,"onblur","return "+func+"('"+basename+"',"+id+");");
			// loop through all childNodes of oldobj, and put them in input node
			for(var i=0;i<oldobj.childNodes.length;i++) {
				if (oldobj.childNodes[i].nodeName != "BR") {
					input.appendChild(oldobj.childNodes[i]);
				}
			}
			//input.appendChild(document.createTextNode(contents));
			dtDOM.showHide(oldobj);
			oldobj.parentNode.insertBefore(input,oldobj);
			var fader = new Fader();
			fader.fade(input,"in",50);
			if (!dtDOM.isMobileSafari) input.focus();
			break;
	}
}
DOMobj.prototype.unEditable = function(basename) {
	var oldobj = getObjectRef(basename);
	var inputobj = getObjectRef("input_"+basename);
	if (inputobj) {
		dtDOM.setHandler(inputobj,"onblur","");
		inputobj.parentNode.removeChild(inputobj);
	}
	dtDOM.showHide(oldobj);
}
DOMobj.prototype.selectNode = function(win,elem) {
	if (this.isMSIE) {
	} else {
		var sel = window.getSelection();
		var rng = window.document.createRange();
		rng.selectNode(elem);
		sel.addRange(rng);
	}
	return false;
};
DOMobj.prototype.getParentArray = function(node) {
	var pArr = new Array();
	do {
		pArr.push(node);
	} while ((node = node.parentNode) !== null && node.nodeType == 1 && node.nodeName != "HTML");
	return pArr;
};
DOMobj.prototype.seekParentElement = function(node,elem) {
	if (typeof elem == "undefined") {
		if (node.nodeType == 1) { return node; }
		while ((node = node.parentNode) !== null && node.nodeType != 1) { }
		return node;
	} else if (node === null) {
		return null;
	} else if (node.nodeType == 1 && node.nodeName == elem) {
		return node;
	}
	while (node = node.parentNode) {
		if (node.nodeType == 1 && node.nodeName == elem) {
			return node;
		} else if (node.nodeName == "BODY") {
			return null;
		}
	}
	return null;
};
DOMobj.prototype.seekChildElement = function(node,elem) {
	if (node.hasChildNodes()) {
		for(var i=0;i<node.childNodes.length;i++) {
			if (node.childNodes[i].nodeName == elem) {
				return node.childNodes[i];
			} else if (node.childNodes[i].hasChildNodes()) {
				var r = this.seekChildElement(node.childNodes[i],elem);
				if (r !== null) {
					return r;
				}
			}
		}
	}
	return null;
};
DOMobj.prototype.getElementsByClass = function(node,c) {
	if (typeof node == "string") { node = getObjectRef(node,this.doc); }
	var arr = new Array();
	if (node && node.hasChildNodes()) {
		for(var i=0;i<node.childNodes.length;i++) {
			var cNode = node.childNodes[i];
			if (cNode.nodeType == 1) {
				if (dtDOM.hasClass(cNode,c)) {
					arr.push(cNode);
				}
				if (cNode.hasChildNodes()) {
					var subarr = this.getElementsByClass(cNode,c);
					arr = arr.concat(subarr);
				}
			}
		}
	}
	return arr;
}
DOMobj.prototype.getParentByClass = function(node,c) {
	if (typeof node == "string") { node = getObjectRef(node,this.doc); }
	while (node = node.parentNode) {
		if (node.nodeType == 1 && dtDOM.hasClass(node,c)) {
			return node;
		} else if (node.nodeName == "BODY") {
			return null;
		}
	}
	return null;
}
DOMobj.prototype.br = function() {
	return this.buildElement("BR",false,false);
}
DOMobj.prototype.buildElement = function(type,id,attrs) {
	if (arguments.length == 4) {
		var elem = arguments[3].createElement(type);
	} else {
		var elem = this.doc.createElement(type);
	}
	if (typeof id != "undefined" && id != "" && id != false) { this.setAttr(elem,"id",id); }
	if (attrs) {
		for(var i in attrs) {
			this.setAttr(elem,i,attrs[i]);
		}
	}
	return elem;
};
DOMobj.prototype.buildTH = function(arr) {
	var tr,th;
	tr = this.buildElement("TR");
	for(var i=0;i<arr.length;i++) {
		th = this.buildElement("TH");
		th.appendChild(document.createTextNode(arr[i]));
		tr.appendChild(th);
	}
	return tr;
}
DOMobj.prototype.buildInputElement = function(type,name,id,value,arr) {
	if (typeof id == "undefined" || id == false || id == "") id = name;
	var elem = this.buildElement("INPUT",id, { "type": type, "name": name, "value": value });
	if (arr) {
		for (var n in arr) {
			this.setAttr(elem,n,arr[n]);
		}
	}
	return elem;
};
DOMobj.prototype.buildRadioElement = function(type,name,id,value,arr) {
	if (typeof id == "undefined" || id == false || id == "") { id = name; }
	if (this.isMSIE) {
		var elem = null;
		try {
			if (arr.checked == "checked") {
				elem = document.createElement('<input type="'+type+'" name="'+name+'" checked="checked">');
			} else {
				elem = document.createElement('<input type="'+type+'" name="'+name+'">');
			}
		} catch (e) {
			elem = document.createElement(type);
			elem.setAttribute("name",name);
		}
	} else {
		return this.buildInputElement(type,name,id,value,arr);
	}
	elem.setAttribute("id",id);
	elem.setAttribute("value",value);
	if (arr) {
		for (var n in arr) {
			this.setAttr(elem,n,arr[n]);
		}
	}
	return elem;
};
DOMobj.prototype.buildLinkElement = function(href,inside,arr) {
	var elem = this.buildElement("A",false, { "href": href });
	if (arr) {
		for (var n in arr) {
			this.setAttr(elem,n,arr[n]);
		}
	}
	if (typeof inside == "object") {
		elem.appendChild(inside);
	} else {
		elem.appendChild(document.createTextNode(inside));
	}
	return elem;
};
DOMobj.prototype.setSelectByValue = function(obj,value) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	for(var i=0;i<obj.options.length;i++) {
		if (obj.options[i].value == value) {
			obj.selectedIndex = i;
			break;
		}
	}
}
DOMobj.prototype.getInputValue = function(obj) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	return obj.value;
}
DOMobj.prototype.getIsChecked = function(obj) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	return obj.checked;
}
DOMobj.prototype.getSelectedOption = function(obj) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	return obj.options[obj.selectedIndex].value;
}
DOMobj.prototype.getSelectedOptionText = function(obj) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	return obj.options[obj.selectedIndex].text;
}
DOMobj.prototype.getCheckedOption = function(obj) {
	if (typeof obj == "string") { obj = getObjectRef(obj,this.doc); }
	for(var i=0;i<obj.length;i++) {
		if (obj[i].checked) return obj[i].value;
	}
	return false;
}
DOMobj.prototype.addOnload = function(f) {
	if (typeof window.onload != 'function') {
		window.onload = f;
	} else {
		var oldonload = window.onload;
		dtDOM.addEvent(window,"load", function() {
			if (oldonload) oldonload();
			f();
		});
	}
}
function toggleProgbar() {
	var progbar = getObjectRef("progbar");
	if (progbar.style.display == "block" || arguments[0] == 'off') {
		progbar.style.display = "none";
	} else {
		progbar.style.display = "block";
	}
}
function get_XMLHttpReq() {
	if (dtDOM.isMSIE) {
		try {
			httpObj = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			httpObj = new ActiveXObject("Microsoft.XMLHTTP");
		}
	} else {
		httpObj = new XMLHttpRequest();
	}
	return httpObj;
}
function AJAXobj(baseurl) {
	this.obj = new get_XMLHttpReq();
	this.baseurl = baseurl;
	this.method = "get";
	this.args = ""
	this.reqHeader = new Array();
	this.rHandler = false;
	this.responsetext = "";
	this.responseXML = "";
	this.responseCount = 0;
	this.response = null;
	this.error = "";
	this.fielddelim = ";";
	this.linedelim = "|";
	this.timeoutID = false;
	this.showError = true;
	this.showProgress = true;
}
AJAXobj.prototype.dosend = function(args,rtype) {
	if (this.showProgress) toggleProgbar();
	this.args = args;
	this.error = "";
	switch (rtype) {
		case 'boolean':
			this.obj.onreadystatechange = this.booleanResponse.bind(this);
			break;
		case 'text':
			this.obj.onreadystatechange = this.textResponse.bind(this);
			break;
		case 'array':
			this.obj.onreadystatechange = this.arrayResponse.bind(this);
			break;
		case 'xml':
			this.obj.overrideMimeType('text/xml');
			this.obj.onreadystatechange = this.XMLResponse.bind(this);
			break;
		case 'object':
			this.obj.onreadystatechange = this.JSONResponse.bind(this);
			break;
	}
	if (this.method == "get") {
		this.obj.open("get",this.baseurl+"?"+args);
		this.obj.send(null);
	} else {
		this.obj.open("post",this.baseurl);
		if (this.reqHeader.length) {
			this.obj.setRequestHeader(this.reqHeader[0],this.reqHeader[1]);
		} else {
			this.obj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		}
		this.obj.send(args);
	}
}
AJAXobj.prototype.giveUp = function() {
	clearTimeout(this.timeoutID);
	this.obj.readyState = 4;
	this.timeout = false;
	this.error = "The script timed out during execution";
	if (this.showError) showSheet(this.error,"ajax");
	this.rHandler();
}
AJAXobj.prototype.textResponse = function() {
	if (this.obj.readyState == 4) {
		if (this.showProgress) toggleProgbar();
		if (this.obj.status == 200) {
			this.response = this.obj.responseText.trim();
		} else {
			this.error = "This script has failed to successfully contact the server.";
			if (this.showError) showSheet(this.error,"ajax");
		}
		this.rHandler();
	}
}
AJAXobj.prototype.arrayResponse = function() {
	if (this.obj.readyState == 4) {
		// clear the giveUp() call
		if (this.timeoutID) clearTimeout(this.timeoutID);
		if (this.showProgress) toggleProgbar();
		if (this.obj.status == 200) {
			this.responsetext = this.obj.responseText;
			if (this.responsetext.indexOf(this.linedelim) != -1) {
				this.response = new Array();
				var linearr = this.responsetext.split(this.linedelim);
				this.responseCount = 0;
				for(i=0;i<linearr.length;i++) {
					if (linearr[i] != "") {
						var fieldarr = linearr[i].split(this.fielddelim);
						this.response[this.response.length] = fieldarr;
						this.responseCount++;
					}
				}
			} else if (this.responsetext != 0) {
				this.error = this.responsetext;
				if (this.showError) showSheet(this.error,"ajax");
			}
		} else {
			this.error = "This script has failed to successfully contact the server.";
			if (this.showError) showSheet(this.error,"ajax");
		}
		this.rHandler();
	} else if (this.timeoutID == false) {
		this.timeoutID = setTimeout(this.giveUp,3000);
	}
}
AJAXobj.prototype.booleanResponse = function() {
	if (this.obj.readyState == 4) {
		if (this.showProgress) toggleProgbar();
		if (this.obj.status == 200) {
			if (parseInt(this.obj.responseText) == NaN) {
				this.error = this.obj.responseText;
				if (this.showError) showSheet(this.error,"ajax");
			} else {
				this.response = parseInt(this.obj.responseText);
			}
		} else {
			this.error = "This script has failed to successfully contact the server.";
			if (this.showError) showSheet(this.error,"ajax");
		}
		this.rHandler();
	}
}
AJAXobj.prototype.XMLResponse = function() {
	if (this.obj.readyState == 4) {
		// clear the giveUp() call
		if (this.timeoutID) clearTimeout(this.timeoutID);
		if (this.showProgress) toggleProgbar();
		if (this.obj.status == 200) {
			if (this.obj.responseXML.firstChild.nodeName == "error") {
				this.error = getNodeValue(this.obj.responseXML.firstChild,"msg");
				if (this.showError) showSheet(this.error,"ajax");
			} else {
				this.response = this.obj.responseXML;
			}
		} else {
			this.error = "This script has failed to successfully contact the server.";
			if (this.showError) showSheet(this.error,"ajax");
		}
		this.rHandler();
	} else if (this.timeoutID == false) {
		this.timeoutID = setTimeout(this.giveUp,3000);
	}
}
AJAXobj.prototype.JSONResponse = function() {
	if (this.obj.readyState == 4) {
		if (this.showProgress) toggleProgbar();
		if (this.obj.status == 200) {
			if (this.obj.responseText == "") {
				this.error = "The request returned an empty object";
				if (this.showError) showSheet(this.error,"ajax");
			} else {
				theObject = eval("(" + this.obj.responseText + ")");
				this.response = theObject;
			}
		} else {
			this.error = "This script has failed to successfully contact the server.";
			if (this.showError) showSheet(this.error,"ajax");
		}
		this.rHandler();
	}
}
// take a menu object, an Ajax response array, and populates the menu
AJAXobj.prototype.populateMenu = function(menu,showblank) {
	if (typeof menu == "string") { menu = getObjectRef(menu,dtDOM.doc); }
	menu.options.length = 0;
	try { dtDOM.removeAttr(menu,"disabled"); } catch(e) {}
	if (typeof showblank == "object") {
		menu.options[0] = new Option(showblank[0],showblank[1]);
	}
	if (this.responseCount) {
		for(var i=0;i<this.responseCount;i++) {
			var optarr = this.response[i];
			var opt = new Option(optarr[0],optarr[1]);
			menu.options[menu.options.length] = opt;
		}
	}
}
// takes a menu name, an Ajax response array, and returns a new DOM menu object
AJAXobj.prototype.buildMenu = function(mname,showblank) {
	var menu = dtDOM.buildElement("SELECT",mname,{ "name" : mname });
	if (typeof showblank == "object") {
		menu.options[0] = new Option(showblank[0],showblank[1]);
	}
	if (this.responseCount) {
		for(var i=0;i<this.responseCount;i++) {
			var optarr = this.response[i];
			var opt = new Option(optarr[0],optarr[1]);
			menu.options[menu.options.length] = opt;
		}
	}
	return menu;
}
function Fader() {
	return true;
}
Fader.prototype.fade = function(obj,inout,interval) {
	if (typeof obj == "string") { obj = getObjectRef(obj,dtDOM.doc); }
	if (inout == "in") {
		dtDOM.setAttr(obj,"fading",1);
		if (dtDOM.getStyle(obj,"display") == "none") {
			dtDOM.setStyle(obj,"opacity",0);
			dtDOM.showHide(obj);
		}
		var fadeInID = setInterval(doFadeIn,interval);
		//console.log('fadeInID for '+obj.id+' is '+fadeInID);
	} else {
		var fadeOutID = setInterval(doFadeOut,interval);
		//console.log('fadeOutID for '+obj.id+' is '+fadeOutID);
	}
	function doFadeIn() {
		var opac = dtDOM.getStyle(obj,"opacity");
		if (parseFloat(opac) < 1) {
			dtDOM.setStyle(obj,"opacity",parseFloat(opac) + .2);
		} else {
			clearInterval(fadeInID);
			//console.log('Clearing fadeInID '+fadeInID);
		}
	}
	function doFadeOut() {
		var opac = dtDOM.getStyle(obj,"opacity");
		if (parseFloat(opac) > 0) {
			dtDOM.setStyle(obj,"opacity",parseFloat(opac) - .2);
		} else {
			//console.log('Clearing fadeOutID '+fadeOutID);
			clearInterval(fadeOutID);
			dtDOM.showHide(obj);
			dtDOM.setStyle(obj,"opacity",1.0);
			dtDOM.removeAttr(obj,"fading");
		}
	}
}
function SlideObj() {
	this.index = dtDOM.sliders.length;
	dtDOM.sliders[this.index] = this;
	this.obj = null;
	this.step = 10;
	this.interval = 10;
	this.h = 0;
	this.w = 0;
	this.wrapped = false; // a reference to the wrapped object
}
SlideObj.prototype.wrap = function(obj,disp) {
	if (!disp || disp == "none") {
		// make it invisible so we can unhide it and get its height
		dtDOM.setStyle(obj,"visibility","hidden");
		dtDOM.showHide(obj);
		var height = dtDOM.getHeight(obj);
		// now hide it again
		dtDOM.setStyle(obj,"visibility","visible");
		dtDOM.showHide(obj);
	}
	var inside = obj.cloneNode(obj,true);
	var wrapper = dtDOM.buildElement("DIV","tmp_wrapper",false);
	dtDOM.setStyle(wrapper,"height",height);
	dtDOM.setStyle(wrapper,"display",disp);
	dtDOM.showHide(inside);
	wrapper.appendChild(inside);
	obj.parentNode.replaceChild(wrapper,obj);
	obj = getObjectRef("tmp_wrapper");
	this.wrapped = inside;
	return obj;
}
SlideObj.prototype.unwrap = function(obj) {
	this.obj.parentNode.replaceChild(this.wrapped,this.obj);
}
SlideObj.prototype.slide = function(obj,step,intvl) {
	if (typeof obj == "string") { obj = getObjectRef(obj,dtDOM.doc); }
	var disp = dtDOM.getStyle(obj,"display");
	if (obj.nodeName == "TABLE") {
		var newobj = this.wrap(obj,disp);
		this.obj = newobj;
	} else {
		this.obj = obj;
	}
	dtDOM.setStyle(this.obj,"overflow","hidden");
	this.step = step;
	this.interval = intvl;
	if (!disp || disp == "none") {
		dtDOM.setStyle(this.obj,"visibility","hidden");
		dtDOM.showHide(this.obj);
		var h = dtDOM.getHeight(this.obj);
		dtDOM.setStyle(this.obj,"height",0);
		dtDOM.setStyle(this.obj,"visibility","visible");
		this.h = parseInt(h);
		// double step if this is a huge slide
		if (this.h > step * 10) { this.step += step; }
		slideInt = setInterval("dtDOM.sliders["+this.index+"].doSlideIn()",this.interval);
	} else {
		var h = dtDOM.getHeight(this.obj);
		this.h = parseInt(h);
		// double step if this is a huge slide
		if (this.h > step * 10) { this.step += step; }
		slideInt = setInterval("dtDOM.sliders["+this.index+"].doSlideOut()",this.interval);
	}
	//console.log("Starting height is "+this.h+"px");
}
SlideObj.prototype.doSlideIn = function() {
	if (this.obj) {
		var h = parseInt(dtDOM.getHeight(this.obj));
		//console.log(this.obj.id+" height is "+h+"px slidingIn");
		if (h < this.h) {
			if (h + this.step > this.h) {
				dtDOM.setStyle(this.obj,"height",this.h+"px");
				clearInterval(slideInt);
				if (this.wrapped) {
					this.unwrap()
				}
				dtDOM.sliders.splice(this.index,1);
				this.obj = null;
			} else {
				dtDOM.setStyle(this.obj,"height",h+this.step+"px");
			}
		} else {
			clearInterval(slideInt);
			if (this.wrapped) {
				this.unwrap()
			}
			dtDOM.sliders.splice(this.index,1);
			this.obj = null;
		}
	}
}
SlideObj.prototype.doSlideOut = function() {
	if (this.obj) {
		var h = parseInt(dtDOM.getHeight(this.obj));
		//console.log(this.obj.id+" height is "+h+"px slidingOut");
		if (h > 0) {
			if (h - this.step <= 0) {
				dtDOM.showHide(this.obj);
				dtDOM.setStyle(this.obj,"height",this.h+"px");
				clearInterval(slideInt);
				if (this.wrapped) {
					this.unwrap()
				}
				dtDOM.sliders.splice(this.index,1);
				this.obj = null;
			} else {
				dtDOM.setStyle(this.obj,"height",h-this.step+"px");
			}
		} else {
			clearInterval(slideInt);
			if (this.wrapped) {
				this.unwrap();
			}
			dtDOM.sliders.splice(this.index,1);
			this.obj = null;
		}
	}
		
}
function sndUserCheck(username) {
	if (username != "") {
		function useralert() {
			var userfield = getObjectRef("form_newusername");
			if (uhttp.error != "") {
				showSheet(uhttp.error,"ajax");
			} else if (uhttp.response) {
				showSheet("That username is already in use by a registered account. Please choose a different username.","form validation");
			}
		}
		uhttp = new AJAXobj(dtDOM.g_url+"rpc_reference.php");
		uhttp.rHandler = useralert;
		uhttp.dosend("f=name&str="+username,"boolean");
	}
	return false;
}
function sndArbitraryUserCheck(fieldobj,username,menu) {
	if (username != "") {
		function arbitraryuseralert() {
			if (uhttp.error != "") {
				showSheet(uhttp.error,"ajax");
			} else if (uhttp.response) {
				showSheet("That username is already in use by a registered account. Please choose a different username.","form validation");
			} else {
				menuobj.selectedIndex = 0;
			}
		}
		var menuobj = getObjectRef(menu);
		uhttp = new AJAXobj(dtDOM.g_url+"rpc_reference.php");
		uhttp.rHandler = arbitraryuseralert;
		uhttp.dosend("f=name&str="+username,"boolean");
	}
	return false;
}
dtDOM = new DOMobj();
dtDOM.g_url = js_g_url;

