
function transferValue(srcObj,destObj){

	var src=document.getElementById(srcObj);
	var dest=document.getElementById(destObj);

	if (src!=null){

		var val=src.innerHTML.replace(/<br>/g,String.fromCharCode(10));		// turn breaks into spaces
		val=val.replace(/{nl} /g,'{nl}');															// get rid of the rogue space that appears on the end

		val=val.replace(/{nl}/g,String.fromCharCode(10));								// turn breaks into spaces

		val=val.replace(/&amp;/g,'&');
		val=val.replace(/&lt;/g,'<');
		val=val.replace(/&gt;/g,'>');

		dest.value=val;
	}else{
		dest.value='';
	}

}

function setThreadID(threadID) {
	var control = document.getElementById('editThreadID');
	control.value = threadID;
}

function setPostID(postID) {
	var control = document.getElementById('postID');
	control.value = postID;
}



//-----------------------------------------------------------------------------------------------------------------------------------------------------------

// Flash Version Detector  v1.2.1
// documentation: http://www.dithered.com/javascript/flash_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
// with VBScript code from Alastair Hamilton (now somewhat modified)


function isDefined(property) {
	return (typeof property != 'undefined');
}

var flashVersion = 0;
function getFlashVersion() {


	// bump this up high!!! otherwise it won't work!!!
	var latestFlashVersion = 20;
	var agent = navigator.userAgent.toLowerCase();

	// NS3 needs flashVersion to be a local variable
	if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {

		flashVersion = 0;
	}

	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') {
			for (var i = latestFlashVersion; i >= 3; i--) {
				if (flashPlugin.description.indexOf(i + '.') != -1) {
					flashVersion = i;
					break;
				}
			}
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
		var doc = '<scr' + 'ipt language="VBScript"\> \n';
		doc += 'On Error Resume Next \n';
		doc += 'Dim obFlash \n';
		doc += 'For k = ' + latestFlashVersion + ' To 3 Step -1 \n';
		doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & k) \n';
		doc += '   If IsObject(obFlash) Then \n';
		doc += '      flashVersion = k \n';
		doc += '      Exit For \n';
		doc += '   End If \n';
		doc += 'Next \n';
		doc += '</scr' + 'ipt\> \n';

		document.write(doc);
	}

	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = flashVersion_DONTKNOW;
	}


	return flashVersion;
}

flashVersion_DONTKNOW = -1;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function FlashInstalled()
{
	result = false;

	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])
	{
		result = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
	}
	else if (document.all && (navigator.appVersion.indexOf("Mac")==-1))
	{
		// IE Windows only -- check for ActiveX control, have to hide code in eval from Netscape (doesn't like try)
		eval ('try {var xObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if (xObj)	result = true; xObj = null;	} catch (e)	{}');
	}

	flashVersion = getFlashVersion();

	if(flashVersion<6){

		result = false;

	}

	return result;
}



//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function quizvalidate(){

	var s;
	var n=-1;
	var lastone;
	var totals=Array();
	var shouldBes=Array();
	var problemQues=Array();
	var isProblem='';
	var realVal;

	var thisName='';
	var radios=Array();
	var radiosChecked=Array();

	for (i=0;i<document.mainform.elements.length ; i++){

		if (typeof(document.mainform.elements[i].name)!='undefined'){

			// constant sum
			if (document.mainform.elements[i].name.substr(0,4)=='ans_'){
				s=document.mainform.elements[i].name.split('_');

				if (typeof(document.mainform.elements["sum_" + s[1]])!='undefined'){

					if (document.mainform.elements["sum_" + s[1]].value>0){
						if (lastone!=s[1]){
							if (i>0){
								n++;
							}
							totals[n]=0;
							shouldBes[n]=document.mainform.elements["sum_" + s[1]].value;
						}
						lastone=s[1];
						// hack to throw it out if a negative number is used
						realVal=document.mainform.elements[i].value.replace(/^\s*|\s*$/g,"")*1;
						if (realVal<0){
							realVal=1000000;
						}
						totals[n]=totals[n]*1+realVal;
					}
				}
			}else if (document.mainform.elements[i].name.substr(0,3)=='ans'){

				if (thisName!=document.mainform.elements[i].name){
					n++;
					radiosChecked[n]=0;
				}
				if (document.mainform.elements[i].checked==true){
					radiosChecked[n]=1;

				}

				thisName=document.mainform.elements[i].name;
			}
		}
	}

	n=0;
	for (i=0;i<totals.length ; i++){
		if (shouldBes[i]!=totals[i]){
			isProblem='y';
			problemQues[n]=i+1;
			n++;

		}
	}

	var notAllChecked='';
	var str='';
	for (i=0;i<radiosChecked.length ; i++){
		if (radiosChecked[i]!=1){
			notAllChecked='y';
			str=str + " " + (i+1);
		}
	}


	if (isProblem=='y'){
		alert("Sorry - your answers don't all add up correctly... Question(s) " + problemQues.join(', '));
		return(false);

	}else if(notAllChecked=='y'){
		alert("Sorry - you need to answer all the questions. You need to tick Question(s) " + str);
		return(false);
	}else{
		return(true);
		//document.forms.mainform.submit();
	}


}


function today() {
	var months=new Array(13);
	months[1]="January";
	months[2]="February";
	months[3]="March";
	months[4]="April";
	months[5]="May";
	months[6]="June";
	months[7]="July";
	months[8]="August";
	months[9]="September";
	months[10]="October";
	months[11]="November";
	months[12]="December";
	var time=new Date();
	var lmonth=months[time.getMonth() + 1];
	var date=time.getDate();
	var year=time.getYear();
	if (year < 2000)
	year = year + 1900;
	document.write("" + lmonth + " ");
	document.write(date + ", " + year + "");
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function flip(divName){
	var obj=document.getElementById(divName);

	if (obj.style.display=='none')	{
		obj.style.display='block';
	}else{
		obj.style.display='none';
	}
}



// buttons float at side of screen
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function floatBtn(divName){
	var obj=document.getElementById(divName);
	if (obj!=null){
		obj.style.top=document.body.scrollTop+15;
	}
}



//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function showDiv(divName){
	var obj=document.getElementById(divName);
	obj.style.visibility='visible';
}

// turns on all the hidden edit buttons.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function switchAllButtons(){


	for (i=0;i<document.images.length; i++){
		if (document.images[i].id.length>0){
			obj=document.getElementById(document.images[i].id);
			if (obj.style.display=='none')	{
				obj.style.display='block';
				document.cookie="btnsOn'=y'";
			}else{
				obj.style.display='none';
				document.cookie="btnsOn'=n'";
			}
		}
	}
}

// opens all quizadmin divs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function openAllQuizDivs(){

	var divs=document.getElementsByTagName("div");



	for (var i=0; i<divs.length;i++ ){

		if (divs[i].id.charAt(0)=='s'){
			divs[i].style.display='block';
		}
	}

}




//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
function keyCap() { //v1.0
	if (navigator.appName != 'Netscape') {
		if (window.event.keyCode == 13){
			loginform.submit();
		}
	}
}


//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function checkPasswords(){

	if (document.register.emailAddress.value!=document.register.emailAddress2.value){
		alert("Sorry - your email addresses appear not to match");
	}else{
		document.register.submit();
	}
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function handleKeyDown(e){

	if (document.register.checkKey.value==1){

		document.register.checkKey.value='';
		if(!e)	var e = window.event;

		if (e.keyCode == 17){
			alert('Coping and pasting has been disabled for this field');
		}

	}
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
function confirmLink(theLink, msg)
{
	// Confirmation is not required in the configuration file
	// or browser is Opera (crappy js implementation)
	if (typeof(window.opera) != 'undefined') {
		return true;
	}

	var is_confirmed = confirm( msg);


	return is_confirmed;
} // end of the 'confirmLink()' function

// for tree
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function showMenu( divNum,minusGif, plusGif ){

	if (getIdProperty( "s" + divNum, "display") != "block" )
	{
		setIdProperty("s" + divNum, "display", "block");
		document.images["i" + divNum].src = minusGif;
		document.cookie="s_" + divNum + '=y';
	}
	else
	{
		setIdProperty("s" + divNum, "display", "none");
		document.images["i" + divNum].src = plusGif;
		document.cookie="s_" + divNum + "=''; expires=Sun, 09-Nov-97 01:00:00";

	}
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function getIdProperty( id, property ){

	var styleObject = document.getElementById( id );
	if (styleObject != null){
		styleObject = styleObject.style;
		if (styleObject[property]) {
			return styleObject[ property ];
		}
	}
	styleObject = getStyleBySelector( "#" + id );
	return (styleObject != null) ?
	styleObject[property] :
	null;

}


//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function setIdProperty( id, property, value ){

	var styleObject = document.getElementById( id );
	if (styleObject != null){
		styleObject = styleObject.style;
		styleObject[ property ] = value;
	}


}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
function popupwindow(url_name,w,h,t,l){

	viewer=window.open(" ","remotewin","scrollbars=0, resizable=0,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
	viewer.location.href=url_name;
	if(viewer.opener==null)viewer.opener=window;
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function flipTick(stem){
	for (i=0;i<document.mainform.elements.length;i++ ){
		if (typeof(document.mainform.elements[i].name)!='undefined'){
			if (document.mainform.elements[i].name.substr(0,stem.length)==stem){
				if (document.mainform.elements[i].checked==true){
					document.mainform.elements[i].checked=false;
				}else{
					document.mainform.elements[i].checked=true;
				}
			}
		}
	}
}


// proper replace function
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function replaceAll( str, from, to ) {
	var idx = str.indexOf( from );

	while ( idx > -1 ) {
		str = str.replace( from, to );
		idx = str.indexOf( from );
	}

	return str;
}





// ajax stuff - based on Richard's code.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------

function xhtmlresultcallback(responseArray,resultParams) {
	//alert(responseArray['errstring']);

	ctlip=document.getElementById(resultParams['inputFieldId']);
	if(responseArray['result']=='OK') {
		ctlip.style.color='green';
	} else {
		ctlip.style.color='red';

		outnode=document.getElementById(resultParams['resultSpaceId']);

		offset=responseArray['errbyte'];
		outnode.innerHTML=responseArray['report']+'<p style="line-height: 1.8">'+responseArray['errstring']+" <a href=\"javascript:highlightError('htmltemplate','"+offset+"')\" style=\"background-color: #cccccc; padding: 3px; \">Highlight failure location</a><br /> 	Last/matching opened tag was <b>&quot;&lt;"+responseArray['lastopen']+"..&gt;&quot;</b> <a href=\"javascript:highlightError('htmltemplate','"+responseArray['lastopenoffset']+"')\"  style=\"background-color: #cccccc; padding: 2px; \">Hightlight matching tag</a></p><p><b>NOTE on highlight feature</b>: highlighting alone will not move the textbox view. To find the highlight, hold down SHIFT, and press right-arrow one or more times.</p><p><a href=\"javascript:auto_html_to_xhtml('" + resultParams['inputFieldId']  + "'); ajaxValidateSingleInput( '"+ resultParams['inputFieldId']  + "','" + resultParams['resultSpaceId']  + "','lib/ajax/xmlcheck.php?fieldName="+resultParams['inputFieldId']+"','xhtmlresultcallback')\"  style=\"background-color: #cccccc; padding: 2px; \">Attempt Automatic Fix</a> (may not change simple templates)</p>";
	}
}


//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function highlightError(ctl,offset) {
	selectRange(ctlip,offset-1,offset);
	ctlip.focus();
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function selectRange(ctl,from,to) {
	if( ctl.setSelectionRange ) {
		ctl.setSelectionRange(from,to);
	}
	else if( ctl.createTextRange ) {
		range = ctl.createTextRange();
		range.collapse(true);
		range.moveEnd('character',to);
		range.moveStart('character',from);
		range.select();
	}
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function auto_html_to_xhtml(ctlid) {

	ctl=document.getElementById(ctlid);
	xhtml=ctl.value;

	xhtml=xhtml.replace(/<br\s*>/g,'<br />'); //this to fix ZDE highlight bug: '
	xhtml=xhtml.replace(/\n\s*\n/g,"\n");
	xhtml=xhtml.replace(/(<img\s[^>]+[" ])>/g,"$1 />");
	xhtml=xhtml.replace(/(<meta\s[^>]+[" ])>/g,"$1 />");
	xhtml=xhtml.replace(/(<input\s[^>]+[" ])>/g,"$1 />");
	ctl.value=xhtml;
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function xmlhttpPost(ajaxURL, queryString, resultFunc, resultParams) {

	var xmlHttpReq = false;


	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
		//	xmlHttpReq.overrideMimeType('text/xml');
	}
	// IE
	else if (window.ActiveXObject) {
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlHttpReq.open('POST', ajaxURL, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.onreadystatechange = function() {
		if (xmlHttpReq.readyState == 4) {
			eval(resultFunc + '(xmlHttpReq.responseText, resultParams );');
		}
	}
	xmlHttpReq.send(queryString);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function ajaxValidateSingleInput(inputFieldId,resultSpaceId,ajaxURL,extraResponseHandler) {
	// alert('VSA');

	inputField=document.getElementById(inputFieldId);
	queryString=(inputField.name+'='+escape(inputField.value));

	resultParams= new Array();
	resultParams['inputFieldId']=inputFieldId;
	resultParams['resultSpaceId']=resultSpaceId;
	resultParams['ajaxURL']=ajaxURL;
	resultParams['extraResponseHandler']=extraResponseHandler;

	xmlhttpPost(ajaxURL,queryString,'ajaxValidateSingleInputResponse',resultParams);

}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function ajaxValidateSingleInputResponse(rawResponse,resultParams) {
	var outstr='';
	// alert(rawResponse);
	//document.write(rawResponse);
	responseArray= new Array();
	responseLines=rawResponse.split("\n");
	numResponseLines=responseLines.length;
	for(i=0;i<numResponseLines;i++) {
		responseParts=responseLines[i].split("|");
		responseArray[responseParts[0]]=responseParts[1];
	}

	if(resultParams['resultSpaceId'].length) {
		resultSpace=document.getElementById(resultParams['resultSpaceId']);
		resultSpace.innerHTML=outstr+responseArray['report'];
	}
	if(resultParams['extraResponseHandler']) {
		eval(resultParams['extraResponseHandler'] + '(responseArray,resultParams);');
	}
}









//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function ajaxShowProcessList(resultSpaceId,ajaxURL){


	resultParams= new Array();
	resultParams['resultSpaceId']=resultSpaceId;
	resultParams['ajaxURL']=ajaxURL;

	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
		xmlHttpReq.overrideMimeType('text/xml');
	}
	// IE
	else if (window.ActiveXObject) {
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlHttpReq.open('POST', ajaxURL, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.onreadystatechange = function() {
		if (xmlHttpReq.readyState == 4) {
			eval('stringToDiv(xmlHttpReq.responseText, resultParams );');
		}
	}
	xmlHttpReq.send('');	// we're not actually sending any params atm

	setTimeout("ajaxShowProcessList('" + resultSpaceId + "', '" + ajaxURL+  "')",1000);

}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function stringToDiv(str,resultParams) {
	outnode=document.getElementById(resultParams['resultSpaceId']);
	outnode.innerHTML=str;
}


//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function ajaxGeneric(resultSpaceId,ajaxURL){

	resultParams= new Array();
	resultParams['resultSpaceId']=resultSpaceId;
	resultParams['ajaxURL']=ajaxURL;

	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
		xmlHttpReq.overrideMimeType('text/xml');
	}
	// IE
	else if (window.ActiveXObject) {
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlHttpReq.open('POST', ajaxURL, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.onreadystatechange = function() {
		if (xmlHttpReq.readyState == 4) {
			eval('stringToDiv(xmlHttpReq.responseText, resultParams );');
		}
	}
	xmlHttpReq.send('');

}

function autoswitchflashview(flashVersion,htmlVersion) {
	cookieflashview='auto';
	cookiedata=unescape(document.cookie);
	cookies=cookiedata.split(';');
	for(i=0;i<cookies.length;i++) {
		//alert(cookies[i]);
		cookies[i]=cookies[i].replace(/^\s+|\s+$/g,'');
		cparts=cookies[i].split('=');
		if(cparts[0] == 'flashview') {
			//alert('-'+cparts[0]+':'+cparts[1]+'-');
			cookieflashview=cparts[1];
			//alert(cookies[i]);
		}
	}

	if (FlashInstalled() && !(cookieflashview=='html')){
		var vf=document.getElementById(flashVersion);
		vf.style.display='block';

		var hf=document.getElementById(htmlVersion);
		hf.style.display='none';
		setflashswitchclasses('flash');
	} else {
		setflashswitchclasses('html');
	}
}

/*
function switchflview(flashVersion,htmlVersion) {
var vf=document.getElementById(flashVersion);
var vh=document.getElementById(htmlVersion);
if(vf.style.display=='none') {
vf.style.display='block';
vh.style.display='none';
document.cookie="flashview=flash";
} else {
vh.style.display='block';
vf.style.display='none';
document.cookie="flashview=html";
}


}*/

//Set flash view of known div's
function setflview(flashVersion,htmlVersion,version) {
	var vf=document.getElementById(flashVersion);
	var vh=document.getElementById(htmlVersion);
	//alert ('SFV:'+version);
	if(version=='flash') {
		if(vf && vh) {
			vf.style.display='block';
			vh.style.display='none';
		}
		document.cookie="flashview=flash";
	} else {
		if(vf && vh) {
			vh.style.display='block';
			vf.style.display='none';
		}
		document.cookie="flashview=html";

	}

}

/** just set the classes of the LHS switch */
function setflashswitchclasses(which){ //flashVersion,htmlVersion) {
	//var vf=document.getElementById(flashVersion);
	//var vh=document.getElementById(htmlVersion);

	// don't call this in the template!

	var sf=document.getElementById('switcherFlash');
	var sh=document.getElementById('switcherHTML');
	if(which=='html' && sf!=null && sh!=null) {
		sf.className='switcherFlash';
		sh.className='switcherHTMLActive';
	} else if(which=='flash' && sf!=null && sh!=null) {
		sf.className='switcherFlashActive';
		sh.className='switcherHTML';
	}
}

function settoflash() {
	setflview('flashVersion','htmlVersion','flash');
	setflview('SBflashVersion','SBhtmlVersion','flash');
	setflashswitchclasses('flash');
}


function settohtml() {
	setflview('flashVersion','htmlVersion','html');
	setflview('SBflashVersion','SBhtmlVersion','htmlsettoflash');
	setflashswitchclasses('html');
}

// this is for theforum - the message box needs an id as well as a name for mozilla
function tagSelection(type,bx) {

	var agt=navigator.userAgent.toLowerCase();

	var tArea=document.getElementById(bx);


	var is_nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
	&& (agt.indexOf('compatible') == -1)));
	var is_ie   = (agt.indexOf("msie") != -1);
	var is_opera = (agt.indexOf("opera") != -1);

	if (is_nav){

		var start_selection = tArea.selectionStart;
		var end_selection = tArea.selectionEnd;
	}else{

		var theSelection= document.selection;

		var rng = theSelection.createRange();

		var start_selection=tArea.value.indexOf(rng.text);

		var end_selection=tArea.value.indexOf(rng.text)+rng.text.length;

	}

	if (end_selection>start_selection){
		tArea.value=tArea.value.substring(0,start_selection) + "[" + type + "]" + tArea.value.substring(start_selection,end_selection) + "[/" + type + "]" +  tArea.value.substring(end_selection,tArea.value.length) ;
	}
}

function addlikemind360(source) {
	sourcesel=document.getElementById(source);
	//alert(sourcese1.value);
	indata=sourcesel.value.split(':');

	i=0; done=0;
	while(!done) {
		if(fnameip=document.getElementById('forename'+i)) {
			lmnumip=document.getElementById('likemindnum'+i);
			fnamespan=document.getElementById('sforename'+i)
			snamespan=document.getElementById('ssurname'+i);
			//	mailspan=document.getElementById('semail'+i);
			if(lmnumip.value==indata[0]) {
				done=1; // already there!
			} else if(!fnameip.value) {

				snameip=document.getElementById('surname'+i);
				mailspan=document.getElementById('mailspan'+i);
				removebuttonspan = document.getElementById('removebutton'+i);
				lmnumip.value=indata[0];
				fnameip.value=indata[1];
				fnamespan.innerHTML=indata[1];
				snameip.value=indata[2];
				snamespan.innerHTML=indata[2];
				mailspan.innerHTML='[Like Mind]';
				removebuttonspan.innerHTML = '<input type="button" style="width:100%;text-align:center" class="inviteSubmit" onclick="javascript:dellikemind360('+i+')" value="Delete" />'
				// + '{<a href="javascript:editlikemind360('+i+')">EDIT</a>}';
				//Can't edit LMs!
				done=1;
			}
		} else {
			done=1;
		}

		i++;
		//	if(i>9) done=1;
	}

}

function dellikemind360(which) {
	if(fnameip=document.getElementById('forename'+which)) {
		fnamespan=document.getElementById('sforename'+which)
		fnamespan.innerHTML='';
		snamespan=document.getElementById('ssurname'+which);
		snamespan.innerHTML='';
		smailspan=document.getElementById('semail'+which);
		smailspan.innerHTML='';
		editbuttonspan = document.getElementById('editbutton'+which);
		removebuttonspan = document.getElementById('removebutton'+which);
		removebuttonspan.innerHTML = '';
		editbuttonspan.innerHTML = '';
		fnameip.value='';
		snameip=document.getElementById('surname'+which);
		snameip.value='';
		emailip=document.getElementById('email'+which);
		emailip.value='';
		mailspan=document.getElementById('mailspan'+which);
		lmnumip=document.getElementById('likemindnum'+which);
		lmnumip.value=0;
		mailspan.innerHTML='';
	}
}

function editlikemind360(which) {
	forenameip=document.getElementById('forename');
	surnameip=document.getElementById('surname');
	fnameip=document.getElementById('forename'+which);
	snameip=document.getElementById('surname'+which);
	emailip=document.getElementById('email');
	mymailip=document.getElementById('email'+which);
	forenameip.value=fnameip.value;
	surnameip.value=snameip.value;
	emailip.value=mymailip.value;

	dellikemind360(which);
}

function searchOptions(selectControl, id) {
	for(i in selectControl.options) {
		if(selectControl.options[i].value == id) {

			return i;
		}
	}
	return 0;
}

function editlikemind360Preview(id,control) {
	likemind = document.getElementById('likemindnum'+id);
	emailCell = document.getElementById('emailCell'+id);
	if(likemind) {
		forenameCell = document.getElementById('forenameCell'+id);
		likemind = document.getElementById('likemindnum'+id);
		likemindID = likemind.value;

		forenameCell.innerHTML = likemindsSelector;
		newSelector = forenameCell.firstChild;
		newSelector.selectedIndex = searchOptions(newSelector,likemindID);
		control.value = 'Save';

		controlfunction = control.onclick;
		control.onclick = function() {
			name = newSelector.options[newSelector.selectedIndex].text;
			likemind.value = newSelector.options[newSelector.selectedIndex].value;
			forenameCell.innerHTML = name;
			control.value = 'Edit';
			control.onclick = controlfunction;
		};

	} else {
		forenameCell = document.getElementById('forenameCell'+id);
		surnameCell = document.getElementById('surnameCell'+id);
		emailCell = document.getElementById('emailCell'+id);

		de = document.getElementById('debug');
		forename = document.getElementById('forename'+id);
		forenameWidth = forename.parentNode.clientWidth - 6;
		surname = document.getElementById('surname'+id);
		surnameWidth = surname.parentNode.clientWidth - 6;
		email = document.getElementById('email'+id);
		emailWidth = email.parentNode.clientWidth - 6;


		forenameCell.innerHTML = '<input class="quizInput" style="width:' + forenameWidth + 'px" type="text" name="editForname'+ id + '" id="editForname'+ id + '" value="' + forename.value + '"/>';
		surnameCell.innerHTML = '<input class="quizInput" style="width:' + surnameWidth + 'px" type="text" name="editSurname'+ id + '" id="editSurname'+ id + '" value="' + surname.value + '"/>';
		emailCell.innerHTML = '<input class="quizInput" style="width:' + emailWidth + 'px" type="text" width="100%" name="editEmail'+ id + '" id="editEmail'+ id + '" value="' + email.value + '"/>';
		control.value = 'Save';

		controlfunction = control.onclick;
		control.onclick = function() {
			editForename = document.getElementById('editForname'+id);
			editSurname = document.getElementById('editSurname'+id);
			editEmail = document.getElementById('editEmail'+id);
			forename.value = editForename.value;
			surname.value = editSurname.value;
			email.value = editEmail.value;
			forenameCell.innerHTML = forename.value;
			surnameCell.innerHTML = surname.value
			emailCell.innerHTML = email.value;
			control.value = 'Edit';
			control.onclick = controlfunction;
		};
	}
}

function dellikemind360Preview(id, control) {
	control.parentNode.parentNode.parentNode.removeChild(control.parentNode.parentNode);
}


function addemail360(forenameid,surnameid,emailid) {

	forenameip=document.getElementById(forenameid);
	surnameip=document.getElementById(surnameid);
	emailip=document.getElementById(emailid);
	//	alert(sourcesel.value);
	//indata=sourcesel.value.split(':');

	if(forenameip.value=='Forename' || surnameip.value=='Surname' || emailip.value=='email') {
		return;

	}

	i=0; done=0;
	while(!done) {
		if(fnameip=document.getElementById('forename'+i)) {
			//	lmnumip=document.getElementById('likemindnum'+i);
			snameip=document.getElementById('surname'+i);
			mailip=document.getElementById('email'+i);
			fnamespan=document.getElementById('sforename'+i);
			editbuttonspan = document.getElementById('editbutton'+i);
			removebuttonspan = document.getElementById('removebutton'+i);
			snamespan=document.getElementById('ssurname'+i);
			mailspan=document.getElementById('semail'+i);
			if(mailip.value==emailip.value || (fnameip.value==forenameip.value && snameip.value==surnameip.value)) {
				done=1; // already there!
			} else if(!fnameip.value) {


				//mailspan=document.getElementById('mailspan'+i);
				mailip.value=emailip.value;
				mailspan.innerHTML=emailip.value;
				editbuttonspan.innerHTML= '<input type="button" class="inviteSubmit" onclick="editlikemind360('+i+')" value="Edit"/>';
				removebuttonspan.innerHTML= '<input type="button" class="inviteSubmit" style="width:100%;text-align:center" onclick="dellikemind360('+i+')" value="Delete" />';
				fnameip.value=forenameip.value;
				fnamespan.innerHTML=forenameip.value;
				snameip.value=surnameip.value;
				snamespan.innerHTML=surnameip.value;
				//	mailspan.innerHTML='[Email]
				done=1;
			}
		} else {
			done=1;
		}

		i++;
		//	if(i>9) done=1;
	}

	forenameip.value='Forename';
	surnameip.value='Surname';
	emailip.value='email';
	emailip.style.color='black';
}

function checkPairedEmailFields(inputFieldId,secondInputFieldId,resultSpaceId) {
	inputField=document.getElementById(inputFieldId);
	secondInputField=document.getElementById(secondInputFieldId);
	resultSpace=document.getElementById(resultSpaceId);

	if(inputField.value.length && secondInputField.value.length) {
		if (inputField.value != secondInputField.value) {
			resultSpace.innerHTML='Email fields don\'t match';
		} else {
			resultSpace.innerHTML='';
			ajaxValidateEmailField(inputFieldId,resultSpaceId);
		}
	} else {
		resultSpace.InnerHTML='';
	}
}

function checkPairedPasswordFields(inputFieldId,secondInputFieldId,resultSpaceId) {
	inputField=document.getElementById(inputFieldId);
	secondInputField=document.getElementById(secondInputFieldId);
	resultSpace=document.getElementById(resultSpaceId);

	if(inputField.value.length && secondInputField.value.length) {
		if (inputField.value != secondInputField.value) {
			resultSpace.innerHTML='Password fields don\'t match';
		} else {
			resultSpace.innerHTML='';
			//	ajaxValidateEmailField(inputFieldId,resultSpaceId);
		}
	} else {
		resultSpace.InnerHTML='';
	}
}


function ajaxValidateEmailField(inputFieldId,resultSpaceId) {
	//alert(inputFieldId);
	inputField=document.getElementById(inputFieldId);
	queryString=('address='+escape(inputField.value));

	resultParams= new Array();
	resultParams['inputFieldId']=inputFieldId;
	resultParams['resultSpaceId']=resultSpaceId;
	//	resultParams['ajaxURL']=ajaxURL;

	xmlhttpPost('lib/ajax/validateEmail.php', queryString, 'ajaxValidateEmailFieldResponse', resultParams);
}

function ajaxValidateEmailFieldResponse(rawResponse,resultParams) {
	var outstr='';
	// alert(rawResponse);
	//document.write(rawResponse);
	inputFieldId=resultParams['inputFieldId'];
	resultSpaceId=resultParams['resultSpaceId'];
	//			alert('IFI:'+inputFieldId+'\'');
	inputField=document.getElementById(inputFieldId);
	resultSpace=document.getElementById(resultSpaceId);

	responseArray= new Array();
	responseLines=rawResponse.split("\n");
	numResponseLines=responseLines.length;
	for(i=0;i<numResponseLines;i++) {
		responseParts=responseLines[i].split("|");
		responseArray[responseParts[0]]=responseParts[1];
	}
	if(inputField.value==responseArray['email']) {
		//		alert('match');
		if(responseArray['result']=='OK') {
			inputField.style.color='green';
		} else {
			inputField.style.color='red';
		}
		if(resultSpace) {
			resultSpace.innerHTML=responseArray['report'];
		}
	} else {
		//		alert(responseArray['email']);
		inputField.style.color='black';
		if(resultSpace) {
			resultSpace.innerHTML='';
		}
	}
}

function checkclearquiz(page,id) {
	if(confirm("Clear all personal and friends' responses?")) {
		dl='index.php?pageID='+page+'&id='+id+'&delete=y';
		//		alert(dl);
		document.location=dl;
	}
}

function grabpagetoinput(url,ipid) {

	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
		//		xmlHttpReq.overrideMimeType('text/xml');
	}
	// IE
	else if (window.ActiveXObject) {
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlHttpReq.open('GET', url, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.onreadystatechange = function() {
		if (xmlHttpReq.readyState == 4) {
			ip=document.getElementById('rawhtml');
			xs=xmlHttpReq.responseText;//.replace(/"/g,'&quot;');
			ip.value=xs;

			//alert(xs);
		}
	}
	xmlHttpReq.send('');

}

function checkhelpform() {
	problemurlip=document.getElementById('problemurl');
	rawhtmlip=document.getElementById('rawhtml');
	if(problemurlip.value.length && !rawhtmlip.value.length) {
		return(confirm('Examining problem page - hit OK to submit'));
	}
	return(true);
}
