
// ===========================================
//	globals
// ===========================================

var targetID = "";


// ===========================================
//	available for all form functions
// ===========================================

function clearItems(pHidePhTF) {
	var itemContNm = targetID + "_ph";
	var phDivNm = targetID + "_null";
	
	var itemCont = $(itemContNm);
	var phDiv = $(phDivNm);

	for (var i=itemCont.childNodes.length-1; i>=0; i--) {
		if (itemCont.childNodes[i].name == targetID) {
			itemCont.removeChild(itemCont.childNodes[i]);
			break;
		}
	}

	// toggle display of dummy div
	if (pHidePhTF) {
		phDiv.style.display = "none";
	} else {
		phDiv.style.display = "block";
	}

}

function clearItemsBusinessTypes(pHidePhTF) {
	var itemContNm = targetID + "_ph";
	var phDivNm = targetID + "_null";
	
	var itemCont = $(itemContNm);
	var phDiv = $(phDivNm);

	for (var i=itemCont.childNodes.length-1; i>=0; i--) {
		if (itemCont.childNodes[i].id != phDivNm) {
			itemCont.removeChild(itemCont.childNodes[i]);
		}
	}
	clearHiddenItems();

	// toggle display of dummy div
	if (pHidePhTF) {
		phDiv.style.display = "none";
	} else {
		phDiv.style.display = "block";
	}

}

function clearHiddenItems() {
	var itemsInput = document.getElementsByTagName("input");
	var reHiddenField = new RegExp("/hidden_pctr\d{2}/");
	for (var i=0; i<itemsInput.length; i++) {
		if ((itemsInput[i].getAttribute("type") == "hidden") && (reHiddenField.test(itemsInput[i].getAttribute("name")))) {
			itemsInput[i].removeNode(true);
		}
	}
}

function createCont(classNm, text) {
	var cell = document.createElement("div");
	cell.className = classNm;
	
	if (text != null) {
		var textNode = document.createTextNode(text);
		cell.appendChild(textNode);
	}
	
	return cell;
}

function createReqAsterisk() {
	var cell = document.createElement("span");
	cell.className = "required";
	var textNode = document.createTextNode("*");
	cell.appendChild(textNode);
	
	return cell;
}

function createComment(classNm, text) {
	var cell = document.createElement("div");
	cell.className = classNm;
	var textNode = document.createComment(text);
	cell.appendChild(textNode);
	
	return cell;
}

function createRadioListYN(listNm, arrOpts, selYN) {
	var frag = document.createDocumentFragment();
	
	for (i=0; i<arrOpts.length; i++) {
		var elOpt = document.createElement("input");
		elOpt.setAttribute("type", "radio");
		elOpt.setAttribute("name", listNm);
		elOpt.setAttribute("value", arrOpts[i]);
		if (arrOpts[i]==selYN) {
			elOpt.checked = true;
			elOpt.setAttribute("checked", "checked");
		}
		var textNode = document.createTextNode(arrOpts[i] + " ");
		frag.appendChild(elOpt);
		frag.appendChild(textNode);
	}

	return frag;
}

function createHiddenInput(iName, iVal) {
	var elHidden = document.createElement("input");
	var fullFieldName = "hidden_" + iName;
	elHidden.setAttribute("type", "hidden");
	elHidden.setAttribute("name", fullFieldName);
	elHidden.setAttribute("id", fullFieldName);
	elHidden.setAttribute("value", iVal);
	
	return elHidden;
}


// ===========================================
//	city lists
// ===========================================

function getCities(pFieldValue, pTargetPrefix) {
	// set timer; must wait for fn to finish
	callAjaxReady = false;
	// set target as global
	targetID = pTargetPrefix;
	
	// legitimate zip code syntax?
	var reZip = new RegExp("^\\d{5}$");
	if (!reZip.test(pFieldValue)) { // do nothing if ph is visible; revert to ph if true values are already set
		clearItems(false);
		callAjaxReady = true;
		return;
	}

	// start ajax
	var params = 'uZip=' + pFieldValue;
	params += '&targetField=' + pTargetPrefix;
	new Ajax.Request('../ajax/cities.php', {parameters:params, onSuccess:parseXMLCity});
}

function parseXMLCity(t) {
    var response = t.responseText;
	// function fails without this Try statement
	// xml must be turned into an xml object
	var ajaxResponse = Try.these(
		function() { return new DOMParser().parseFromString(response, 'text/xml'); },
		function() { var xmldom = new ActiveXObject('Microsoft.XMLDOM'); xmldom.loadXML(response); return xmldom; }
	);

	var itemContNm = targetID + "_ph";
	var itemCont = $(itemContNm);
	
	var cities = ajaxResponse.getElementsByTagName("city");
	
	if (!cities.length) { // no valid results
		clearItems(false);
		alert("You have entered an invalid zip code. Please make sure it's correct and try again.");
		return false;
	} else {
		clearItems(true);
		var cityInfo = new Array();
		for (var i=0; i<cities.length; i++) {
			var city = cities[i];
			cityInfo[i] = new Array();
			cityInfo[i][0] = (city.getElementsByTagName("cityName")[0].childNodes.length > 0) ? city.getElementsByTagName("cityName")[0].firstChild.nodeValue : "";
			cityInfo[i][1] = city.getElementsByTagName("sel")[0].firstChild.nodeValue;
		}
	}
	
	var newItem = createCityList(cityInfo);
	itemCont.appendChild(newItem);

	callAjaxReady = true;

}

function createCityList(arrOpts) {
	var elSelect = document.createElement("select");
	elSelect.setAttribute("name", targetID);

	for (i=0; i<arrOpts.length; i++) {
		var elOpt = document.createElement("option");
		elOpt.setAttribute("value", arrOpts[i][0]);
		var textNode = document.createTextNode(arrOpts[i][0]);
		elOpt.appendChild(textNode);
		if (arrOpts[i][1]=="1") {
			elOpt.selected = true;
			elOpt.setAttribute("selected", "selected");
		}
		elSelect.appendChild(elOpt);
	}

	return elSelect;
}


// ===========================================
//	business type select menus
// ===========================================

function getBusinessTypesSelect(pFieldValue, pTargetPrefix) {
	// set timer; must wait for fn to finish
	callAjaxReady = false;
	// set target as global
	targetID = pTargetPrefix;
	
	// legitimate (not null) value?
	if (!pFieldValue) {
		clearItemsBusinessTypes(false);
		callAjaxReady = true;
		return;
	}

	// start ajax
	var params = 'bType=' + pFieldValue + '&formID=' + formID;
	new Ajax.Request('../ajax/business_types_select.php', {parameters:params, onSuccess:parseXMLBusinessTypesSelect});
}

function parseXMLBusinessTypesSelect(t) {
    var response = t.responseText;
	// function fails without this Try statement
	// xml must be turned into an xml object
	var ajaxResponse = Try.these(
		function() { return new DOMParser().parseFromString(response, 'text/xml'); },
		function() { var xmldom = new ActiveXObject('Microsoft.XMLDOM'); xmldom.loadXML(response); return xmldom; }
	);

	var vList = ajaxResponse.getElementsByTagName("vlist");
	var items = ajaxResponse.getElementsByTagName("dept");
	
	if (!items.length) { // no valid results
		clearItemsBusinessTypes(false);
		alert("No valid results exist for this business type. Please select another.");
		return false;
	}
	
	clearItemsBusinessTypes(true);
	var itemCont = $(targetID + "_ph");
	
	var deptName, deptAbbr, deptValue = "";
	var vListArr = new Array();

	for (var i=0; i<vList.length; i++) {
		vlItem = vList[i];
		var vlValueSet = vlItem.getElementsByTagName("vlValue");
		vListArr[i] = new Array();
		for (var j=0; j<vlValueSet.length; j++) {
			vListArr[i][j] = vlValueSet[j].firstChild.nodeValue;
		}
	}
	
	var item = null;
	for (var i=0; i<items.length; i++) {
		item = items[i];
		deptName = (item.getElementsByTagName("deptName")[0].childNodes.length > 0) ? item.getElementsByTagName("deptName")[0].firstChild.nodeValue : "";
		deptAbbr = (item.getElementsByTagName("deptAbbr")[0].childNodes.length > 0) ? item.getElementsByTagName("deptAbbr")[0].firstChild.nodeValue : "";
		deptValue = (item.getElementsByTagName("deptValue")[0].childNodes.length > 0) ? item.getElementsByTagName("deptValue")[0].firstChild.nodeValue : "";
		
		var newItem = createCont('fItem', null);
		
		// create label
		var cellLabel = createCont('fQues', deptName);
		var cellReq = createReqAsterisk();
		cellLabel.appendChild(cellReq);
		newItem.appendChild(cellLabel);
		
		// create select menu
		var cellDD = createCont('fField', null);
		var setDD = createDD(deptAbbr, vListArr[0], deptValue); // [0] because we only have one value list in there
		cellDD.appendChild(setDD);
		newItem.appendChild(cellDD);
		
		var cellClear = createComment('clear', 'for IE');
		newItem.appendChild(cellClear);
		
		itemCont.appendChild(newItem);
		
		// create associated hidden field to communicate plain-English name of fields
		var hiddenField = createHiddenInput(deptAbbr, deptName);
		itemCont.appendChild(hiddenField);
	}
	
	callAjaxReady = true;

}

function createDD(textAbbr, arrOpts, textValue) {
	var elSelect = document.createElement("select");
	elSelect.setAttribute("name", textAbbr);
	elSelect.setAttribute("id", textAbbr);

	for (i=0; i<arrOpts.length; i++) {
		var elOpt = document.createElement("option");
		elOpt.setAttribute("value", arrOpts[i]);
		var textNode = document.createTextNode(arrOpts[i]);
		elOpt.appendChild(textNode);
		if (arrOpts[i] == textValue) {
			elOpt.selected = true;
			elOpt.setAttribute("selected", "selected");
		}
		elSelect.appendChild(elOpt);
	}

	return elSelect;
}


// ===========================================
//	business type input fields
// ===========================================

function getBusinessTypesInput(pFieldValue, pTargetPrefix) {
	// set timer; must wait for fn to finish
	callAjaxReady = false;
	// set target as global
	targetID = pTargetPrefix;
	
	// legitimate (not null) value?
	if (!pFieldValue) {
		clearItemsBusinessTypes(false);
		callAjaxReady = true;
		return;
	}

	// start ajax
	var params = 'bType=' + pFieldValue + '&formID=' + formID;
	new Ajax.Request('../ajax/business_types_input.php', {parameters:params, onSuccess:parseXMLBusinessTypesInput});
}

function parseXMLBusinessTypesInput(t) {
    var response = t.responseText;
	// function fails without this Try statement
	// xml must be turned into an xml object
	var ajaxResponse = Try.these(
		function() { return new DOMParser().parseFromString(response, 'text/xml'); },
		function() { var xmldom = new ActiveXObject('Microsoft.XMLDOM'); xmldom.loadXML(response); return xmldom; }
	);

	var vList = ajaxResponse.getElementsByTagName("vlist");
	var items = ajaxResponse.getElementsByTagName("dept");
	
	if (!items.length) { // no valid results
		clearItemsBusinessTypes(false);
		alert("No valid results exist for this business type. Please select another.");
		return false;
	}
	
	clearItemsBusinessTypes(true);
	var itemCont = $(targetID + "_ph");
	
	var deptName, deptAbbr, deptValueYN, deptValueDesc = "";
	var vListArr = new Array();

	for (var i=0; i<vList.length; i++) {
		vlItem = vList[i];
		var vlValueSet = vlItem.getElementsByTagName("vlValue");
		vListArr[i] = new Array();
		for (var j=0; j<vlValueSet.length; j++) {
			vListArr[i][j] = vlValueSet[j].firstChild.nodeValue;
		}
	}
	
	var item = null;
	for (var i=0; i<items.length; i++) {
		item = items[i];
		deptName = (item.getElementsByTagName("deptName")[0].childNodes.length > 0) ? item.getElementsByTagName("deptName")[0].firstChild.nodeValue : "";
		deptAbbr = (item.getElementsByTagName("deptAbbr")[0].childNodes.length > 0) ? item.getElementsByTagName("deptAbbr")[0].firstChild.nodeValue : "";
		deptValueYN = (item.getElementsByTagName("deptValueYN")[0].childNodes.length > 0) ? item.getElementsByTagName("deptValueYN")[0].firstChild.nodeValue : null;
		deptValueDesc = (item.getElementsByTagName("deptValueDesc")[0].childNodes.length > 0) ? item.getElementsByTagName("deptValueDesc")[0].firstChild.nodeValue : "";
		
		var newItem = createCont('fItem', null);
		
		// create label
		var cellLabel = createCont('fQues', deptName);
		var cellReq = createReqAsterisk();
		cellLabel.appendChild(cellReq);
		newItem.appendChild(cellLabel);
		
		// create YN radio buttons
		var cellRadio = createCont('fField', null);
		var setRadio = createRadioListYN(deptAbbr+'_yn', vListArr[0], deptValueYN);
		cellRadio.appendChild(setRadio);
		newItem.appendChild(cellRadio);

		// create textarea fields
		var cellTextarea = createCont('fField', null);
		var setTextarea = createTextareaBusinessTypesInput(deptAbbr+'_desc', deptValueDesc);
		cellTextarea.appendChild(setTextarea);
		newItem.appendChild(cellTextarea);

		var cellClear = createComment('clear', 'for IE');
		newItem.appendChild(cellClear);
		
		itemCont.appendChild(newItem);
		
		// create associated hidden field to communicate plain-English name of fields
		var hiddenField = createHiddenInput(deptAbbr, deptName);
		itemCont.appendChild(hiddenField);
	}
	
	callAjaxReady = true;

}

function createTextareaBusinessTypesInput(listNm, selVal) {
	var cell = document.createElement("textarea");
	cell.setAttribute("name", listNm);
	cell.setAttribute("id", listNm);
	cell.setAttribute("cols", "55");
	cell.setAttribute("rows", "2");
	
	var textNode = document.createTextNode(selVal);
	cell.appendChild(textNode);
	
	return cell;
}


// ===========================================
//	photo upload
// ===========================================

function enableSubmit(pSubmitBtn) {
	var sBtn = $(pSubmitBtn);
	var onclickAttr = "document." + formID + ".submit();";
	sBtn.setAttribute("onclick", onclickAttr);
}

function alertSubmitDisabled() {
	alert("You don't have enough information filled out to submit this form. Please double-check the fields.");
}

var busPhotoUploadCount = 1;

function attachNewPhoto() {
	if (busPhotoUploadCount < 5) {
		// create widget
		busPhotoUploadCount++;
		var elWidget = document.createElement("input");
		var fullFieldName = "photo_upload" + busPhotoUploadCount;
		elWidget.setAttribute("type", "file");
		elWidget.setAttribute("name", fullFieldName);
		elWidget.setAttribute("onclick", "enableSubmit('photoSubmit');");
		
		// create clearing div
		var cellClear = createComment('clear', 'for IE');
		
		// attach both
		var cont = $('fileWidgetCont');
		cont.appendChild(elWidget);
		cont.appendChild(cellClear);
	}
}

function submitNoPhotos(pHiddenField) {
	pHiddenField.value = 1;
	pHiddenField.parentNode.submit();
}


// ===========================================
//	timed ajax executions
// ===========================================

var callAjaxReady = true; // set at particular times in each ajax process
var callAjaxInterval = null; // id for setInterval
var callAjaxFnsBusSurvey = new Array(
	"getBusinessTypesInput(fname.bus_type[fname.bus_type.selectedIndex].value, 'items_rev');",
	"getCities(fname.addr_zip.value, 'addr_city');"
);
var callAjaxFnsBuyerReg = new Array(
	"getBusinessTypesSelect(fname.bus_type[fname.bus_type.selectedIndex].value, 'items_rev');",
	"getCities(fname.h_addr_zip.value, 'h_addr_city');",
	"getCities(fname.w_addr_zip.value, 'w_addr_city');"
);
var callAjaxFnsManageProfile = new Array(
	"getBusinessTypesSelect(fname.bus_type[fname.bus_type.selectedIndex].value, 'items_rev');",
	"getCities(fname.h_addr_zip.value, 'h_addr_city');",
	"getCities(fname.w_addr_zip.value, 'w_addr_city');"
);
var callAjaxFnsOwnerReg = new Array(
	"getCities(fname.h_addr_zip1.value, 'h_addr_city1');",
	"getCities(fname.w_addr_zip1.value, 'w_addr_city1');",
	"getCities(fname.h_addr_zip2.value, 'h_addr_city2');",
	"getCities(fname.w_addr_zip2.value, 'w_addr_city2');",
	"getCities(fname.h_addr_zip3.value, 'h_addr_city3');",
	"getCities(fname.w_addr_zip3.value, 'w_addr_city3');",
	"getCities(fname.bus_addr_zip.value, 'bus_addr_city');"
);
var callAjaxFnsPos = 0; // pointer for array of fns to call

function callAjaxBusSurvey() {
	callAjaxInterval = setInterval("callAjaxFnBusSurvey()", 200); // check ajax progress every 200ms
}
function callAjaxBuyerReg() {
	callAjaxInterval = setInterval("callAjaxFnBuyerReg()", 200); // check ajax progress every 200ms
}
function callAjaxManageProfile() {
	callAjaxInterval = setInterval("callAjaxFnManageProfile()", 200); // check ajax progress every 200ms
}
function callAjaxOwnerReg() {
	callAjaxInterval = setInterval("callAjaxFnOwnerReg()", 200); // check ajax progress every 200ms
}

function callAjaxFnBusSurvey() {
	var fname = $(formID);
	if (callAjaxReady) { // if another ajax process is not in progress
		eval(callAjaxFnsBusSurvey[callAjaxFnsPos]); // evaluate the function and execute it
		callAjaxFnsPos++; // advance the pointer
		if (callAjaxFnsPos == callAjaxFnsBusSurvey.length) {
			clearInterval(callAjaxInterval); // clearInterval if all fns have been executed
			// reset pointer
			callAjaxReady = true;
			callAjaxFnsPos = 0;
		}
	}
}

function callAjaxFnBuyerReg() {
	var fname = $(formID);
	if (callAjaxReady) { // if another ajax process is not in progress
		eval(callAjaxFnsBuyerReg[callAjaxFnsPos]); // evaluate the function and execute it
		callAjaxFnsPos++; // advance the pointer
		if (callAjaxFnsPos == callAjaxFnsBuyerReg.length) {
			clearInterval(callAjaxInterval); // clearInterval if all fns have been executed
			// reset pointer
			callAjaxReady = true;
			callAjaxFnsPos = 0;
		}
	}
}

function callAjaxFnManageProfile() {
	var fname = $(formID);
	if (callAjaxReady) { // if another ajax process is not in progress
		eval(callAjaxFnsManageProfile[callAjaxFnsPos]); // evaluate the function and execute it
		callAjaxFnsPos++; // advance the pointer
		if (callAjaxFnsPos == callAjaxFnsManageProfile.length) {
			clearInterval(callAjaxInterval); // clearInterval if all fns have been executed
			// reset pointer
			callAjaxReady = true;
			callAjaxFnsPos = 0;
		}
	}
}

function callAjaxFnOwnerReg() {
	var fname = $(formID);
	if (callAjaxReady) { // if another ajax process is not in progress
		eval(callAjaxFnsOwnerReg[callAjaxFnsPos]); // evaluate the function and execute it
		callAjaxFnsPos++; // advance the pointer
		if (callAjaxFnsPos == callAjaxFnsOwnerReg.length) {
			clearInterval(callAjaxInterval); // clearInterval if all fns have been executed
			// reset pointer
			callAjaxReady = true;
			callAjaxFnsPos = 0;
		}
	}
}







/*



var tnRollover = {
	'a.tn' : function(element){
		element.onmouseover = function(){
			var theMsg = document.getElementById("tnMsg");
			theMsg.className = "tnMsgOver";
			theMsg.firstChild.nodeValue = ":: " + this.title + " ::";
		},
		element.onmouseout = function(){
			var theMsg = document.getElementById("tnMsg");
			theMsg.className = "tnMsgOff";
			theMsg.firstChild.nodeValue = "~ select a project from the gallery below ~";
		},
		element.onclick = function(){
			var cID = parseInt(this.id.substr(this.className.length)); // className is "tn"; id is "tn8" (for example)
			swapClient(cID);
		}
	}
};

var sendEmail = {
	'a.email' : function(element){
		element.onclick = function(){
			var eFormCont = document.getElementById("sendEmail");
			clearEmailFields();
			setEmailMsg(0);
			new Effect.Appear(eFormCont, { duration: 1.0 });
		}
	},
	'input.send' : function(element){
		element.onclick = function(){
			disableEmailBtns(true);
			var theForm = document.getElementById("sendEmailForm");
			if (!validate(theForm)) {
				disableEmailBtns(false);
				var eFormCont = document.getElementById("sendEmail");
				setEmailMsg(3);
				new Effect.Shake(eFormCont, { duration: 1.0 });
			} else {
				// concatenate form values
				var theElements = theForm.getElementsByTagName('input');
				var theMsgElement = theForm.getElementsByTagName('textarea');
				var params = '';
				for (i=0; i<theElements.length; i++) {
					if (theElements[i].type=='text') {
						params += theElements[i].name + '=' + theElements[i].value + '&';
					}
				}
				params += theMsgElement[0].name + '=' + theMsgElement[0].value;
				//params = params.substring(0,params.length-1);
				//alert(params);
	
				new Ajax.Request('ajax/send_email.php', {method:'post', parameters:params, onSuccess:sEmailSuccess, onFailure:sEmailErr});
				//sEmailSuccess(true);
			}
		}
	},
	'input.cancel' : function(element){
		element.onclick = function(){
			var eFormCont = document.getElementById("sendEmail");
			new Effect.Fade(eFormCont, { duration: 0.7 });
			clearEmailFields();
			setEmailMsg(0);
		}
	}
};

function clearEmailFields() {
	var eForm = document.getElementById("sendEmailForm");
	eForm.eName.value = "";
	eForm.eEmail.value = "";
	eForm.eSubject.value = "";
	eForm.eMsg.value = "";
}

function setEmailMsg(pMsgNumber) {
	var msgs = new Array(
		'all fields are required',
		'Thanks! Your message has been sent.',
		'Sorry, message not sent. Please try again.',
		'Please fill out all fields correctly.'
	);
	var eFormMsg = document.getElementById("sendEmailMsg");
	eFormMsg.firstChild.nodeValue = msgs[pMsgNumber];
}

function disableEmailBtns(pTF) {
	var eFormSend = document.getElementById("eSubmit");
	var eFormCancel = document.getElementById("eCancel");
	eFormSend.disabled = pTF;
	eFormCancel.disabled = pTF;
}

var fadeDelayInt = null;

function fadeDelay() {
	var eFormCont = document.getElementById("sendEmail");
	new Effect.Fade(eFormCont, { duration: 0.7 });
	clearTimeout(fadeDelayInt);
}

var sEmailSuccess = function(t) {
	setEmailMsg(1);
	clearEmailFields();
	disableEmailBtns(false);
	fadeDelayInt = setTimeout(fadeDelay, 700);
}

var sEmailErr = function(t) {
	setEmailMsg(2);
	clearEmailFields();
	disableEmailBtns(false);
}


function clearItems(pDiv) {
	var itemCont = document.getElementById(pDiv);
	for (var i=itemCont.childNodes.length-1; i>=0; i--) {
		itemCont.removeChild(itemCont.childNodes[i]);
	}
}

function swapClient(pSelClientID) {
	if (pSelClientID == curClient) { return; }
	var params = 'cID=' + pSelClientID;
	selClient = pSelClientID;
	new Ajax.Request('ajax/load_clients.php', {parameters:params, onSuccess:swapClientInfo, onFailure:swapClientErr});
}

var swapClientInfo = function(t) {

    var response = t.responseText;
	// function fails without this Try statement
	// xml must be turned into an xml object
	var ajaxResponse = Try.these(
		function() { return new DOMParser().parseFromString(response, 'text/xml'); },
		function() { var xmldom = new ActiveXObject('Microsoft.XMLDOM'); xmldom.loadXML(response); return xmldom; }
	);
	var clientInfo = ajaxResponse.getElementsByTagName("client");
	
	var cName = $('clientName');
	var cLoc = $('clientLoc');
	var cAbstract = $('clientAbstract');
	var cURL = $('clientURL');
	
	// abstract may include line breaks
	// must be done here, after xml comes in
	var clientAbstractArr = clientInfo[0].getElementsByTagName("cAbstract")[0];
	clearItems('clientAbstract');

	var clientAbstractNode;
	for (var i=0; i<clientAbstractArr.childNodes.length; i++) {
		if (clientAbstractArr.childNodes[i].nodeType == 3) { // text node
			var linesArr = clientAbstractArr.childNodes[i].nodeValue.split('\n');
			if (linesArr.length > 1) {
				var lineText, lineBR;
				for (var j=0; j<linesArr.length; j++) {
					lineText = document.createTextNode(linesArr[j]);
					lineBR = document.createElement("br");
					cAbstract.appendChild(lineText);
					if (j<(linesArr.length - 1)) cAbstract.appendChild(lineBR);
				}
				
			} else {
				clientAbstractNode = document.createTextNode(clientAbstractArr.childNodes[i].nodeValue);
				cAbstract.appendChild(clientAbstractNode);
			}

		} else if (clientAbstractArr.childNodes[i].nodeType == 1) { // element node
			clientAbstractNode = document.createElement(clientAbstractArr.childNodes[i].nodeName);
			// attach attributes
			for (var j=0; j<clientAbstractArr.childNodes[i].attributes.length; j++) {
				clientAbstractNode.setAttribute(clientAbstractArr.childNodes[i].attributes[j].nodeName, clientAbstractArr.childNodes[i].attributes[j].nodeValue);
			}
			// attach anchor text
			var aText = document.createTextNode(clientAbstractArr.childNodes[i].firstChild.nodeValue);
			clientAbstractNode.appendChild(aText);
			cAbstract.appendChild(clientAbstractNode);

		}
	}

	// change others
	// at present, no risk of line breaks
	cName.firstChild.nodeValue = clientInfo[0].getElementsByTagName("cName")[0].firstChild.nodeValue;
	cLoc.firstChild.nodeValue = unescape(clientInfo[0].getElementsByTagName("cLoc")[0].firstChild.nodeValue);
	cURL.href = clientInfo[0].getElementsByTagName("cURL")[0].firstChild.nodeValue;
	
	swapClientImgs();

}

function swapClientImgs() {
	new Effect.Appear('client' + selClient, { duration: 1.0 });
	new Effect.Fade('client' + curClient, { duration: 1.5 });
	curClient = selClient;
}

var swapClientErr = function(t) {
    // switch back
    selClient = curClient;
    alert('Error ' + t.status + ' -- ' + t.statusText);
}
*/