
var RecaptchaOptions = { theme : 'white' };

function joinlist(list) {
	if (!list || list == null) {
		list = '';
	}
	joinPopUp = popUp('/shared/joinlist.php?list='+list);
	if (window.addEventListener) { // W3C standard
		window.addEventListener('load', joinPopUp, false);
	} 
	else if (document.attachEvent) { // Microsoft
		attachEvent('onload', joinPopUp);
	}
}


function h1Fix() {
	//if (document.getElementById('title').offsetHeight > 45) {
		document.getElementById('bodytext').style.marginTop = document.getElementById('title').offsetHeight + 60 + "px";
	//}
}

function findPos(obj) {  //function from http://www.quirksmode.org/js/findpos.html
	if (obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			do {
					curleft += obj.offsetLeft;
					curtop += obj.offsetTop;
				}
			while (obj = obj.offsetParent);
			return [curleft,curtop];
		}
	} else {
		return [0,0];	
	}
}

function pageScroll() {
	hashTop = findPos(document.getElementById(location.hash.substring(1)))[1];
	//alert(hashTop+"\n" + document.documentElement.scrollTop);
	if (location.hash.length > 1 && hashTop < document.documentElement.scrollTop + 106 ) {
		scrollBy(0,-1*(document.getElementById('title').offsetHeight + 106));
	}
}

function waitScroll() {
	scrolldelay = setTimeout(pageScroll,200);
}
if (window.addEventListener) { // W3C standard
	window.addEventListener('hashchange', pageScroll, false);
	window.addEventListener('load', waitScroll, false);
	window.addEventListener('load', h1Fix, false);
} 
else if (document.attachEvent) { // Microsoft
	attachEvent('onhashchange', pageScroll);
	attachEvent('onload', waitScroll);
	attachEvent('onload', h1Fix);
}



function addtag() {
	tag = document.getElementById('newtag').value.replace(/^\s+|\s+$/g, "");
	if (tag != '') {
		newopt = document.createElement('option');
		newopt.value = tag;
		newopt.innerHTML = tag;
		document.getElementById('tags').appendChild(newopt);
		document.getElementById('newtag').value = '';
	}
}



//////////  show/hide functions  ////////////

var sh = new Array();

function showhide(eid) {
	if(sh[eid]) hide(eid);
	else show(eid);
}
	
function hide(eid) {
	document.getElementById("h"+eid).style.display = 'none';
	if (document.getElementById("arrow"+eid)) document.getElementById("arrow"+eid).src= '/media/icons/arrow.gif';
	sh[eid] = 0;
}

function show(eid) {
	document.getElementById("h"+eid).style.display = 'block';
	if (document.getElementById("arrow"+eid)) document.getElementById("arrow"+eid).src= '/media/icons/arrowdown.gif';
	sh[eid] = 1;
}
	
function hideRange(start,end) {
	for(eid = start; eid <= end ; eid++) {
		document.getElementById("h"+eid).style.display = 'none';
		if (document.getElementById("arrow"+eid)) document.getElementById("arrow"+eid).src= '/media/icons/arrow.gif';
		sh[eid] = 0;
	}
}
	
function showRange(start,end) {
	for(eid = start; eid <= end ; eid++) {
		document.getElementById("h"+eid).style.display = 'block';
		if (document.getElementById("arrow"+eid)) document.getElementById("arrow"+eid).src= '/media/icons/arrowdown.gif';
		sh[eid] = 1;
	}
}

function swap(show,hide) {
	document.getElementById(hide).style.display = 'none';
	document.getElementById(show).style.display = 'block';
}


/////////////////////////////////////////////


function cse() {
	var sFormDiv = document.getElementById("searchForm");
	var leftScDiv = document.getElementById("searchControl");

	this.leftControl = new GSearchControl();
	this.searchForm = new GSearchForm(true, sFormDiv);

	// bind clear and submit functions
	this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);
	this.searchForm.setOnClearCallback(this, cse.prototype.onClear);

	// set up for small result sets
	this.leftControl.setResultSetSize(GSearch.SMALL_RESULTSET);
	this.leftControl.setLinkTarget(GSearch.LINK_TARGET_SELF);

	var searcher;
	var options;

	searcher = new GwebSearch();
	options = new GsearcherOptions();
	searcher.setSiteRestriction("014101120621721815484:vxq8ewdyhqa");
	options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
	this.leftControl.addSearcher(searcher, options);

	var drawOptions = new GdrawOptions();
	drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);

	this.leftControl.draw(leftScDiv, drawOptions);
}

cse.prototype.onSubmit = function(form) {
	var q = form.input.value;
	if (q && q!= "") {
		this.leftControl.execute(q);
		document.getElementById('grey-outS').style.display = 'block';
		document.getElementById('searchResults').style.display='block';
	}
	return false;
}

cse.prototype.onClear = function(form) {
	this.leftControl.clearAllResults();
	form.input.value = "";
	return false;
}

function OnLoad() {
	new cse();
}

GSearch.setOnLoadCallback(OnLoad);
  
 ////////////////////////////////////////////////////////////////////
 
function ajax(dest,docEl) { 
	try {
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP");
	} 
	catch (e) {}
	if (typeof(docEl) == "string") {
		targetElement = document.getElementById(docEl);	
	} else { 
		targetElement = docEl;
	}
	xmlhttp.onreadystatechange = function () {
		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
			targetElement.innerHTML = xmlhttp.responseText;
			var scripts = targetElement.getElementsByTagName('script');
			for (var i=0; i < scripts.length; i++) {
				script = scripts[i].innerHTML;
				if (window.ActiveXObject) {
					//window.execScript(script); //IE
					(window.eval || eval)(script, null);
				} else {
					eval(script); //real browsers
				}
			}
		}
	}
	xmlhttp.open("GET", dest);
	xmlhttp.send(null);
}

function ajax1(dest,docEl) { 
	try {
		xmlhttp1 = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("MSXML2.XMLHTTP.2.0");
	} 
	catch (e) {}
	if (typeof(docEl) == "string") {
		targetElement = document.getElementById(docEl);	
	} else { 
		targetElement = docEl;
	}
	xmlhttp1.onreadystatechange = function () {
		if ((xmlhttp1.readyState == 4) && (xmlhttp1.status == 200)) {
			targetElement.innerHTML = xmlhttp1.responseText;
			var scripts = targetElement.getElementsByTagName('script');
			for (var i=0; i < scripts.length; i++) {
				script = scripts[i].innerHTML;
				if (window.ActiveXObject) {
					window.execScript(script); //IE
				} else {
					eval(script); //real browsers
				}
			}
		}
	}
	xmlhttp1.open("GET", dest);
	xmlhttp1.send(null);
}
	
function ajaxPost(dest,form,url0,docEl0) { //form can be passed an element id or an element
	if (!url0 || !url0 == null) url0 = '';
	if (!docEl0 || !docEl0 == null) docEl0 = '';
	if (typeof(form) == "string") {
		form = document.getElementById(form);	
	}
	inputs = form.getElementsByTagName('input');
	var params = "";
	for ( var i = 0; i < inputs.length; i++ ) {
		if ( i != 0 ) {
			params += '&';
		}
		if (inputs[i].type == 'checkbox') {
			if (inputs[i].checked) {
				params +=inputs[i].name + '=on';
			}
		} else if (inputs[i].type == 'radio') {
			if (inputs[i].checked) {
				params +=inputs[i].name + '=' + inputs[i].value;
			}
		} else {
			params += inputs[i].name + '=' + encodeURIComponent(inputs[i].value);
		}
	}
	inputs = form.getElementsByTagName('textarea');
	for ( var i = 0; i < inputs.length; i++ ) {
		params += '&' + inputs[i].name + '=' + encodeURIComponent(inputs[i].value);
	}
	inputs = form.getElementsByTagName('select');
	for ( var i = 0; i < inputs.length; i++ ) {
		params += '&' + inputs[i].name + '=' + encodeURIComponent(inputs[i].options[inputs[i].selectedIndex].value);
	}
	try {
		xmlhttp2 = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch (e) {}
	xmlhttp2.open("POST", dest, true);
	xmlhttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp2.setRequestHeader("Content-length", params.length);
	xmlhttp2.setRequestHeader("Connection", "close");
	xmlhttp2.send(params);
	xmlhttp2.onreadystatechange = function() {
		if(xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
			if ((url0 != "") && (docEl0 != "")) {
				ajax(url0,docEl0);
			}
		}
	}
}

function ajaxPostRefresh(dest,form,docEl) { //form can be passed an element id or an element
	if (!docEl || !docEl == null) docEl = '';
	if (typeof(form) == "string") {
		form = document.getElementById(form);	
	}
	inputs = form.getElementsByTagName('input');
	var params = "";
	for ( var i = 0; i < inputs.length; i++ ) {
		if ( i != 0 ) {
			params += '&';
		}
		if (inputs[i].type == 'checkbox') {
			if (inputs[i].checked) {
				params +=inputs[i].name + '=on';
			}
		} else if (inputs[i].type == 'radio') {
			if (inputs[i].checked) {
				params +=inputs[i].name + '=' + inputs[i].value;
			}
		} else {
			params += inputs[i].name + '=' + encodeURIComponent(inputs[i].value);
		}
	}
	inputs = form.getElementsByTagName('textarea');
	for ( var i = 0; i < inputs.length; i++ ) {
		params += '&' + inputs[i].name + '=' + encodeURIComponent(inputs[i].value);
	}
	inputs = form.getElementsByTagName('select');
	for ( var i = 0; i < inputs.length; i++ ) {
		params += '&' + inputs[i].name + '=' + encodeURIComponent(inputs[i].options[inputs[i].selectedIndex].value);
	}
	try {
		xmlhttp3 = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch (e) {}
	if (typeof(docEl) == "string") {
		targetElement = document.getElementById(docEl);	
	} else { 
		targetElement = docEl;
	}
	xmlhttp3.open("POST", dest, true);
	xmlhttp3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp3.setRequestHeader("Content-length", params.length);
	xmlhttp3.setRequestHeader("Connection", "close");
	xmlhttp3.onreadystatechange = function() {
		if ((xmlhttp3.readyState == 4) && (xmlhttp3.status == 200)) {
			targetElement.innerHTML = xmlhttp3.responseText;
			var scripts = targetElement.getElementsByTagName('script');
			for (var i=0; i < scripts.length; i++) {
				script = scripts[i].innerHTML;
				if (window.ActiveXObject) {
					window.execScript(script); //IE
				} else {
					eval(script); //real browsers
				}
			}
		}
	}
	xmlhttp3.send(params);
}




function ajaxDirectPost(dest,params,url0,docEl0) { 
	try {
		xmlhttp2 = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch (e) {}
	xmlhttp2.open("POST", dest, true);
	xmlhttp2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp2.setRequestHeader("Content-length", params.length);
	xmlhttp2.setRequestHeader("Connection", "close");
	xmlhttp2.send(params);
	xmlhttp2.onreadystatechange = function() {
		if(xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
			if ( (url0 != "") && (docEl0 != "") ) {
				ajax(url0,docEl0);
			}
		}
	}
}


//////////////////////////////////////////////////

function rmClearX() {
	allTds = document.getElementsByTagName("td");
	for(var i=0; i < allTds.length; i++) {
		if (allTds[i].className.match("gsc-clear-button")) {
			allTds[i].parentNode.removeChild(allTds[i]);
		}
	}
}

function closePopUp(delay) {
	if (!delay) {
		delay = 0;
	}
	if (document.getElementById('popupdiv')) {
		document.getElementById('popupdiv').style.display = 'none';
		document.getElementById('popupdiv').innerHTML = '<p class="head2" style="text-align:center">Loading<br /><img src="/media/icons/loading.gif" alt="..."/></p>'; 
		setTimeout("document.getElementById('greyout').style.display = 'none';",delay);
	}
}

function popUp(el) {
	document.getElementById('greyout').style.display = 'block';
	document.getElementById('popupdiv').style.display = 'block';
	document.getElementById('popupdiv').style.top = 100 + (document.documentElement.scrollTop || document.body.scrollTop) + 'px';
	ajax(el,'popupdiv');
}

/////////////////////////////////////////////////////

function checkbg(input,img) {
	if (input.value == "") {
		input.style.backgroundImage = "url('/forum/images/"+img+"')";
	} else {
		input.style.backgroundImage = "";
	}
}

function hlbg(el,color) {
	el.style.backgroundColor = color;
}

function forminit(form,postUrl,ackUrl,ackEl,cke_hack) {
	var theform = document.getElementById(form);
	setexpands(theform);
	setlimits(theform);
	theform.onsubmit = function () {
		if (cke_hack) {
			document.getElementById('content').value = CKEDITOR.instances.content.getData();
		}		
		if(button = document.getElementById('submitbtn')) {
			button.style.display = 'none';
		}
		var inputs = this.getElementsByTagName("input");
		for(var i=0; i < inputs.length; i++) {
			if (inputs[i].className.match("requiredcheck") && inputs[i].getAttribute("vis") != "false") {
				if (!inputs[i].checked) {
					alert("Please complete all fields/questions before sumbitting.");
					inputs[i].focus();
					if (inputs[i].type == "file") {
						inputs[i].parentNode.style.backgroundColor = "#e0e0ff";
					}
					restore();
					return false;
				}
			}
		}

		var inputs = this.getElementsByTagName("input");
		for(var i=0; i < inputs.length; i++) {
			if (inputs[i].className.match("required") && inputs[i].getAttribute("vis") != "false") {
				if (inputs[i].value.length == 0) {
					alert("Please complete all fields/questions before sumbitting.");
					inputs[i].focus();
					if (inputs[i].type == "file") {
						inputs[i].parentNode.style.backgroundColor = "#e0e0ff";
					}
					restore();
					return false;
				}
			}
		}

		var inputs = this.getElementsByTagName("textarea");
		for (var i=0; i < inputs.length; i++) {
			if (inputs[i].className.match("required") && inputs[i].getAttribute("vis") != "false") {
				if (inputs[i].value.length == 0) {
					alert("Please complete all fields/questions before sumbitting.");
					inputs[i].focus();
					restore();
					return false;
				}
			}
		}

		var inputs = this.getElementsByTagName("select");
		for (var i=0; i < inputs.length; i++) {
			if (inputs[i].className.match("required") && inputs[i].getAttribute("vis") != "false") {
				if (inputs[i].options[inputs[i].selectedIndex].className.match("default") || !inputs[i].selectedIndex) {
					alert("Please complete all fields/questions before sumbitting.");
					inputs[i].focus();
					restore();
					return false;
				}
			}
		}

		var divs = this.getElementsByTagName("div");
		for (var i=0; i < divs.length; i++) {
			if (divs[i].className.match("required") && divs[i].getAttribute("vis") != "false") {
				var inputslength = 0;
				var divinputs = divs[i].getElementsByTagName("textarea");
				for (var j=0; j < divinputs.length; j++) {
					if (divinputs[j].checked) {
						inputslength += divinputs[j].value.length;
					}
				}
				var divinputs = divs[i].getElementsByTagName("input");
				for (var j=0; j < divinputs.length; j++) {
					if (divinputs[j].checked) {
						inputslength += divinputs[j].value.length;
					}
				}
				if (inputslength == 0) {
					alert("Please complete all fields/questions before sumbitting.");
					divinputs[0].focus();
					restore();
					return false;
				}
			}
		}
		
		//iframes for each 'ajax' file upload must, on success, include an object with id 'status' and content === 'uploaded'
		var iframes = this.getElementsByTagName("iframe");  
		for(var i=0; i < iframes.length; i++) {
			if (iframes[i].className.match("required") && iframes[i].getAttribute("vis") != "false") {
				if (iframes[i].contentDocument) {
					if (!iframes[i].contentDocument.getElementById('status') || iframes[i].contentDocument.getElementById('status').innerHTML != 'uploaded') { //real web browsers
						alert ("File upload failed or is still in progress.  Please check your file upload and submit again.");
						restore();
						return false;
					}
				} else {
					if (!iframes[i].Document.getElementById('status') || iframes[i].Document.getElementById('status').innerHTML != 'uploaded') { //IE
						alert ("File upload failed or is still in progress.  Please check your file upload and submit again.");
						restore();
						return false;
					}
				}
			}
		}
		
		//clear hidden fields to only submit those intended
		var divs = this.getElementsByTagName("div");
		for (var i=0; i < divs.length; i++) {
			if (divs[i].style.display == "none") {
				hiddeninputs = divs[i].getElementsByTagName("input");
				for (var j=0; j < hiddeninputs.length; j++) {
					hiddeninputs[j].value = "";
				}
				hiddeninputs = divs[i].getElementsByTagName("textarea");
				for (var j=0; j < hiddeninputs.length; j++) {
					hiddeninputs[j].value = "";
				}
			}
		}
		if(ackUrl != null) {
			ajaxPost(postUrl,this,ackUrl,ackEl);
			return false;
		} else if(ackEl != null) {
			ajaxPostRefresh(postUrl,this,ackEl);
			return false;
		} //else submit form using action set by form
	}
}

function restore() {
	if(button = document.getElementById('submitbtn')) {
		button.style.display = 'inline';
	}
	return false;
}

function limit(){
	allowed = "";
	phone = "()-+. 0123456789ext";
	alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	alphanumplus = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
	number = "0123456789";
	time = ":0123456789";
	usd = "$0123456789.,";
	if (this.getAttribute("limit") == "phone") {
		allowed = phone;
	} else if (this.getAttribute("limit") == "alphanum") {
		allowed = alphanum;
	} else if (this.getAttribute("limit") == "alpha_-num") {
		allowed = alphanumplus;
	} else if (this.getAttribute("limit") == "number") {
		allowed = number;
	} else if (this.getAttribute("limit") == "time") {
		allowed = time;
	} else if (this.getAttribute("limit") == "usd") {
		allowed = usd;
	}
	if (allowed != "") {
		var value = "";
		for (i=0; i < this.value.length; i++) {
			chara = this.value.charAt(i);
			if (allowed.indexOf(chara,0) != -1) {
				value += chara;
			}
		}
		this.value = value;
	}
	if (this.value == "" && this.getAttribute('date')) {
		this.style.backgroundImage = "url('/forum/images/"+this.getAttribute('date')+".png')";
	} else {
		this.style.backgroundImage = "";
	}
}



function setlimits(theform) {
	inputlist = theform.getElementsByTagName("input");
	for (var i=0; i < inputlist.length; i++) {
		if (inputlist[i].getAttribute("limit")) {
			inputlist[i].onkeyup = limit;
		}
	}
}


function highlight() {
	if (this.getAttribute("date")) {
		dateformat = this.getAttribute("date");
		this.style.backgroundImage = "url('/forum/images/"+dateformat+".png')";
	}
	this.style.backgroundColor = "#e0e0ff";
	this.style.backgroundPosition = "right";
	this.style.backgroundRepeat = "no-repeat";
}


function nolight() {
	this.style.backgroundColor = "";
	this.style.backgroundImage = "";
}

function setexpands(theform) {
	inputlist = theform.getElementsByTagName("input");
	for (var i=0; i < inputlist.length; i++) {
		inputlist[i].onfocus = highlight;
		inputlist[i].onblur = nolight;
		if (inputlist[i].getAttribute("expand") == "true") {
			inputlist[i].onchange = expandcall;
			inputlist[i].onkeyup = expandcall;
		}
	}
	inputlist = theform.getElementsByTagName("textarea");
	for (var i=0; i < inputlist.length; i++) {
		inputlist[i].onfocus = highlight;
		inputlist[i].onblur = nolight;
		if (inputlist[i].getAttribute("expand") == "true") {
			inputlist[i].onchange = expandcall;
			inputlist[i].onkeyup = expandcall;
		}
	}
	inputlist = theform.getElementsByTagName("select");
	for (var i=0; i < inputlist.length; i++) {
		inputlist[i].onfocus = highlight;
		inputlist[i].onblur = nolight;
		if (inputlist[i].getAttribute("expand") == "true") {
			inputlist[i].onchange = expandcall;
			inputlist[i].onkeyup = expandcall;
		}
	}
	divlist = theform.getElementsByTagName("div");
	for (var i=0; i < divlist.length; i++) {
		if ((divlist[i].getAttribute("expand") == "true") || (divlist[i].getAttribute("expand") == "flip")) {
			divinputs = divlist[i].getElementsByTagName("input");
			for (var j=0; j < divinputs.length; j++) {
				divinputs[j].onclick = expandset;
			}
			divinputs = divlist[i].getElementsByTagName("select");
			for (var j=0; j < divinputs.length; j++) {
				divinputs[j].onclick = expandset;
			}
			divinputs = divlist[i].getElementsByTagName("textarea");
			for (var j=0; j < divinputs.length; j++) {
				divinputs[j].onclick = expandset;
			}
		}
	}
}

function expandcall() {
	expand(this);
}

function expand(el) {
	if ((el.value.length > 0 && !el.checked && el.tagName.toLowerCase()!='select') || el.checked || (el.tagName.toLowerCase()=='select' && el.options[el.selectedIndex].value==el.getAttribute('expandtarget')) ) {
		expandnames = el.getAttribute("expandnames");
		var children = expandnames.split(","); 
		for (var i=0; i < children.length; i++) {
			var kid = document.getElementById(children[i]);
			kid.style.display = 'inline';
			grandkids = kid.getElementsByTagName("input");
			for (var j=0; j < grandkids.length; j++) {
				grandkids[j].setAttribute("vis", "true");
			}
			grandkids = kid.getElementsByTagName("textarea");
			for (var j=0; j < grandkids.length; j++) {
				grandkids[j].setAttribute("vis", "true");
			}
			grandkids = kid.getElementsByTagName("select");
			for (var j=0; j < grandkids.length; j++) {
				grandkids[j].setAttribute("vis", "true");
			}
			grandkids = kid.getElementsByTagName("iframe");
			for (var j=0; j < grandkids.length; j++) {
				grandkids[j].setAttribute("vis", "true");
			}
		}
	}
	if (el.value.length == 0 || ((el.type == "radio" || el.type == "checkbox") && !el.checked) || (el.tagName.toLowerCase()=='select' && el.options[el.selectedIndex].value!=el.getAttribute('expandtarget')) ) {
		expandnames = el.getAttribute("expandnames");
		var children = expandnames.split(","); 
		for (var i=0; i < children.length; i++) {
			var kid = document.getElementById(children[i]);
			kid.style.display = 'none';
			grandkids = kid.getElementsByTagName("input");
			for (var j=0; j < grandkids.length; j++) {
				grandkids[j].setAttribute("vis", "false");
			}
			grandkids = kid.getElementsByTagName("textarea");
			for (var j=0; j < grandkids.length; j++) {
				grandkids[j].setAttribute("vis", "false");
			}
			grandkids = kid.getElementsByTagName("select");
			for (var j=0; j < grandkids.length; j++) {
				grandkids[j].setAttribute("vis", "false");
			}
			grandkids = kid.getElementsByTagName("iframe");
			for (var j=0; j < grandkids.length; j++) {
				grandkids[j].setAttribute("vis", "false");
			}
		}
	}
}

function expandset() {
	if (this.parentNode.getAttribute("expand") == "flip") {
		choices = this.parentNode.getElementsByTagName("input");
		if (this.checked) {
			swapval = false;
		} else {
			swapval = true;
		}
		for (i=0; i < choices.length; i++) {
			if (choices[i] != this) {
				choices[i].checked = swapval;
			}
		}
	}
	setinputs = this.parentNode.getElementsByTagName("input");
	for (i=0; i < setinputs.length; i++) {
		if (setinputs[i].getAttribute("expandnames")) {
			expand(setinputs[i]);
		}
	}
	setinputs = this.parentNode.getElementsByTagName("textarea");
	for (i=0; i < setinputs.length; i++) {
		if (setinputs[i].getAttribute("expandnames")) {
			expand(setinputs[i]);
		}
	}
}

function ajaxAppend(loc,next,docEl,rowName) {
	var nextRowDiv = rowName + next;
	if (document.getElementById(nextRowDiv) && document.getElementById(nextRowDiv) != null) {
		return false;
	}
	try {
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch (e) {}
	targetEl = document.getElementById(docEl);
	xmlhttp.onreadystatechange = function () {
		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
			var newlines = document.createElement('div');
			newlines.innerHTML = xmlhttp.responseText;
			targetEl.appendChild(newlines);
		}
	}
	var dest = loc + "?q=" + next;
	xmlhttp.open("GET", dest);
	xmlhttp.send(null);
}

function upload(elem,userid,large,path) {
	if (!large || large == null) {
		large = "";
	}
	if (!path || path == null) {
		path = "upload.php";
	}
	filefield = elem.name;
	var parent = elem.parentNode;
	var parentname = parent.tagName;
	while( parentname != "FORM" && parentname != "BODY" ) {
		var parent = parent.parentNode;
		var parentname = parent.tagName;
	}
	if (parentname == "BODY") {
		return false;
	}
	form = document.getElementById(parent.id);
	form.target = filefield+'iframe';
	form.setAttribute('enctype',"multipart/form-data");
	form.setAttribute('action',path+"?filefield="+filefield+"&user="+userid+"&large="+large);
	form.setAttribute('method',"post");
	form.submit();
}

function comparepw(pwconfid,pwid) {
	el = document.getElementById(pwconfid);
	pw = document.getElementById(pwid);
	if ( el.value == pw.value ) {
		el.style.color='#000';
	} else {
		el.style.color='#f00';
	}
}

function madePublic(pageid) {
	publicspan = document.getElementById('public'+pageid);
	privatespan = document.getElementById('private'+pageid);
	privatespan.style.display = 'none';
	publicspan.style.display = 'inline';
}

function madePrivate(pageid) {
	publicspan = document.getElementById('public'+pageid);
	privatespan = document.getElementById('private'+pageid);
	publicspan.style.display = 'none';
	privatespan.style.display = 'inline';
}
	
function deletedRow(pageid) {
	deadrow = document.getElementById('pagerow'+pageid);
	deadrow.parentNode.removeChild(deadrow);
}

function deletedCell(pageid,table,col) {
	ajax1('profileline.php?table='+table+'&col='+col+'&pageid='+pageid,'pagecell'+pageid);
}

function editRow(pageid,newcontent,table,row,span) {
	edittr = document.getElementById('pagerow'+pageid);
	edittd = edittr.insertCell(0); 		//doesn't replace anything, so the row now has one extra cell (added to beginning)
	for (i=0; i < span; i++) {			//remove all the old cells
		edittr.deleteCell(-1);
	}
	edittd.colSpan = ""+span;
	edittd.className = 'editline';
	edittd.innerHTML = newcontent;
	forminit('formrow'+pageid,'/forum/post.php','profileline.php?table='+table+'&row='+row+'&pageid='+pageid,'ajaxactiondiv');
}

function editCell(pageid,newcontent,table,col,nodel) {
	edittd = document.getElementById('pagecell'+pageid);
	edittd.innerHTML = newcontent;
	forminit('formrow'+pageid,'/forum/post.php','profileline.php?table='+table+'&col='+col+'&pageid='+pageid+'&nodel='+nodel,'pagecell'+pageid);
}

function editPair(pageid,newcontent,target) {
	editdiv = document.getElementById('pair'+pageid);
	editdiv.innerHTML = newcontent;
	forminit('formrow'+pageid,'/forum/post.php',target,'pair'+pageid);
}

function newRow(pageid,newcontent,table,span) {
	tbodyid = table + "table";
	tbody = document.getElementById(tbodyid);
	newtr = tbody.insertRow(-1);
	newtr.id = 'pagerow' + pageid;
	newtd = newtr.insertCell(0);
	newtd.colSpan = ""+span;
	newtd.className = 'editline';
	newtd.innerHTML = newcontent;
	forminit('formrow'+pageid,'/forum/post.php','profileline.php?table='+table+'&row=NEW&pageid='+pageid,'ajaxactiondiv');
	document.getElementById(table+'table').parentNode.style.display = 'block';
}

function moveHtoRow(pageid) {
	//delete all td elements currently in row
	tr = document.getElementById('pagerow'+pageid);
	oldrowtds = tr.getElementsByTagName('td');
	for (i=0; i < oldrowtds.length; i++) {
		tr.deleteCell(i);
	}
	//for each h6 element in ajaxactiondiv, create a new td at the end of tr, and copy h6.innerHTML to it
	hloc = document.getElementById('ajaxactiondiv');
	hs = hloc.getElementsByTagName('h6');
	for (i=0; i < hs.length; i++) {
		newtd = tr.insertCell(i);
		newtd.innerHTML = hs[i].innerHTML;
		if (i == hs.length-1) newtd.className = 'endopts';
	}
}


function toggleBox(input,table) {
	col = input.name;
	if (input.checked) {
		value = 'on';
	} else {
		value = '';
	}
	ajax1('/forum/post.php?table='+table+'&col='+col+'&value='+value,'ajaxactiondiv');
}

function qtoggle(a,b) {
	aEl = document.getElementById(a);
	bEl = document.getElementById(b);
	if (aEl.style.display == 'none') {
		aEl.style.display = 'inline';
		bEl.style.display = 'none';
	} else {
		aEl.style.display = 'none';
		bEl.style.display = 'inline';	
	}
}

function getBoxValues(formid,table,col) {
	var form = document.getElementById(formid);
	inputs = form.getElementsByTagName('input');
	var params = 'table='+table+'&col='+col+'&';
	for ( var i = 0; i < inputs.length; i++ ) {
		if (inputs[i].type == 'checkbox' && inputs[i].checked) {
			params +=inputs[i].name + '=on&';
		}
	}
	ajax1('/forum/post.php?'+params,'ajaxactiondiv');
}

function toggleSL() {
	trs = document.getElementsByTagName('tr');	
	for ( var i = 0; i < trs.length; i++ ) {
		if (trs[i].className.match("nosl")) {
			if (trs[i].style.display == 'table-row') {
				trs[i].style.display = 'none';
			} else {
				trs[i].style.display = 'table-row';
			}
		}
	}
}

function compareselects(s1,s2) {
	s1 = document.getElementById(s1);
	s2 = document.getElementById(s2);
	opt1 = s1.options[s1.selectedIndex].value;
	opt2 = s2.options[s2.selectedIndex].value;
	if (opt1.length > 0 && opt2.length > 0 && opt1 == opt2) {
		s2.options[0].selected = 'selected';
		s2.focus();
		alert("Your first and second selections must be different.  Please choose a different second selection, in case your first is not available.");
	}
}

