function getEle( theEle ) {
	return document.getElementById(theEle);
}
function colourBG( theTarget, theColour ) {
  sty = document.getElementById(theTarget).style;
  sty.background = '#' + theColour;}
// swap the innerHTML of [target] for [newcontent]
// ** this is where the AJAX shall go...

function swapContent( theTarget, newContent ) {
  ele = document.getElementById(theTarget);
  ele.innerHTML = newContent;
}

// popBox function ... (left, top, w, h, content)
function popBox ( lef, tp, wid, hei, cont ) {
  pb = document.getElementById('popBox');
  // if box is visible, hide it
  // else, show it
  if ( pb.style.display != 'block' ) {
    pb = document.getElementById('popBox');
    pb.style.display='block';
    pb.style.top=tp;
    pb.style.left=lef;
    pb.style.width=wid;
    pb.style.height=hei;
    pb.style.zIndex = 2;
    pb.innerHTML= '<div id="popClose" onClick="popClose();">X</div>' + cont;  } else {
    pb.style.display='none';  }}

function popClose() {
  pb=document.getElementById('popBox');
  pb.style.display='none';
  pb.style.innerHTML='';}
  

var theTarget=null;

function confirmFinal(theID){
	var conf=confirm("Are you SURE?  This cannot be undone!  Be sure you are done making your quiz before you do this!\n\nIf you ARE finished, pick 'OK' to let others take your quiz!");
	if ( conf == true ) {
		document.edtQuiz.confFinalize.value=1;
		document.edtQuiz.submit();
		return true;
	} else {
		document.edtQuiz.confFinalize.value=0;	
		return false;
	}
}

function rateQuiz(QuizID,rating){
	theTarget='_rateQuiz';
	makeRequest("f=rateQuiz&qid="+QuizID+"&r="+rating);
}
function incTaken(QuizID){
	theTarget='_incTaken';
	makeRequest("f=incTaken&qid="+QuizID);	
}

function askQuestion(qid,qsid){
	theTarget=null;
	makeRequest("f=askQuestion&qid="+qid+"&qsid="+qsid);	
}

function makeRequest(url) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance - Sorry, but your brower does not have the appropriate Javascript compatibility');
		return false;
	}

	http_request.onreadystatechange = alertContents; // PHP will return the new <div ...> . . . </div>

	http_request.open('GET', "/io.php?" + url, true);
	http_request.send(null);
}

function alertContents() {
	if ( theTarget==null ){theTarget='contentBox';}
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			result = http_request.responseText;
			swapContent(theTarget, result);
			theTarget=null;
		} else {
			alert('There was a problem with the request.');
		}
	}
}

function do_Tweet( msg ) {
	theTarget="makeTweet";
	msgFriends='';
	msgThem = document.postingOpts.tellFriends.checked;
	swapContent(theTarget,"Tweeting - Please wait!");
	if ( msgThem == true )	msgFriends='&DMF=1';
	makeRequest("f=doTweet&m="+msg +msgFriends);
}

function doLikeQuiz( qID ) {
	theTarget="iLikeQuiz"+qID;
	makeRequest("f=doLike&qid="+qID);
}

function appendOutcome( n ) {
	var t=document.getElementById( 'appOut' + n );
	t.style.display='block';
}

function appendQuestion( n ) {
	var t=document.getElementById( 'appQuest' + n );
	t.style.display='block';
}

