function directUrl(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "nill";
  else
    return results[1];
}

var section = directUrl('type');
var questionValue;
var questionTag;
var xmlhttp;
var xmlDoc;

function loadXMLDoc(theFile) {
  xmlhttp=null;
  if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } 
  else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

  if (xmlhttp!=null) {
    xmlhttp.onreadystatechange=loaded;
    xmlhttp.open("GET",theFile,true);
    xmlhttp.send(null);
  } else { alert('Sorry, your browser can\'t handle this script'); return; }
}

function checkReadyState(obj) {
  if(obj.readyState == 4) {
    if(obj.status == 200) { return true; }
    else { alert("Problem retrieving XML data"); }
  }
}

function loaded() {	
  if(checkReadyState(xmlhttp)) {
    xmlDoc=xmlhttp.responseXML.documentElement;
			showTags(questionTag,'quiz');
  }
}

function showTags(theTag,thePlace) {
  function getTag(tag) { 
    var tmp='';
    xx=x[i].getElementsByTagName(tag);
	
    try { tmp=xx[0].firstChild.data; } 
    catch(er) { tmp=''; }    
    return(tmp); 
  }

	var xx; var x; var txt;
	x = xmlDoc.getElementsByTagName(theTag);
	questionValue = x[0].getAttribute("id");
	questionArray = x[0].getElementsByTagName('item');
	quizSectionTitle = x[0].getAttribute("description");

		txt='<p>' + quizSectionTitle + '</p>';

			for (i=0; i<questionArray.length; i++) { 
				question=questionArray[i].getAttribute("name");
				questionId=questionArray[i].getAttribute("id");
				hasImage=questionArray[i].getAttribute("asset");
				if(hasImage == null){
					txt+='<a class="quizLinks" id="' + questionId + '" onClick="setQuestionTag(this.id);">' + question + '</a>';
				}
				else if(hasImage != null){
					txt+='<a id="' + questionId + '" onClick="setQuestionTag(this.id);"><img src="' + hasImage + '" border="0" /></a>';
				}
			}

  document.getElementById(thePlace).innerHTML=txt;
}

function setQuestionTag(data){
	this.questionTag = data;
	$("#quiz").SlideOutLeft(500);
	window.setTimeout(function() {showTags(questionTag,'quiz');}, 400);
	$("#quiz").SlideInRight(500);
}

window.onload=function(){
	this.questionTag = 'questionOne';
	loadXMLDoc("xml/jobData.xml");
}