function cancelEdit(label) {
	var alertMessage = 'This will cause you to lose any edits you have made. Click OK to continue, or Cancel to return to editing.';

	if(confirm(alertMessage)) {
		toggleEditQuestion(false);
		//possibly reset the text in the editanswer field to the current Answer's text here...
		if(undefined!=label) {
			gotoName(label);
		}
	}
}

function toggleEditQuestion(firstShow) {
	//ResizeTextArea('answereditarea');//resizes the textarea to fit the prepoulated content

	$('viewanswer').toggle();
	$('editanswer').toggle();

	$('currentAnswerAuthor').toggle();
	$('futureAnswerAuthor').toggle();

	if(firstShow) {
		answerdiv = document.getElementById('answereditarea');
		edCanvas=answerdiv;
	}
}

function getElement( whichLayer) {
	var elem;
  if( document.getElementById ) // this is the way the standards work
	elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
	  elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
	elem = document.layers[whichLayer];
  return elem;
}

function ResizeTextArea(whichLayer)
{
	txtBox = getElement(whichLayer);

	nCols = txtBox.cols;
	sVal = txtBox.value;
	nVal = sVal.length;
	nRowCnt = 1;

	for (i=0;i<nVal;i++) { 
		if (sVal.charAt(i).charCodeAt(0) == 13 || sVal.charAt(i) == "\n") { 
			nRowCnt +=1; 
		}
	}

	if (nRowCnt < (nVal / nCols)) { nRowCnt = 1 + (nVal / nCols); }
	nRowCnt = nRowCnt +3;

	//limit the text area to a maximum size
	if(nRowCnt > 35) {
		nRowCnt = 45;
	}

	//make sure the textarea is a minimum size
	if(nRowCnt < 30) {
		nRowCnt = 25;
	}
	txtBox.rows = nRowCnt + 3; // a little extra space for editing...
} 

function disableAnswerButton() {
	//disable button to prevent multiple form submits
	var answerForm = getElement('editanswerform');
	answerForm.answerbutton.disabled=true;
	answerForm.submit();
}

function ratingBox_highlight(state, which, where) {
	var whereToChange = getElement(where);
	if (state=="over") {
		whereToChange.style.backgroundPosition = which=="left" ? "0px -21px": "0px -42px";
	} else {
		whereToChange.style.backgroundPosition="0px 0px";
	}
}

function alert_fail(msg) {
	alert(msg);
	return false;
}