/***********************************************
* Random Content Order script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function randomizeContent(classname){
	return;
	var contents=randomizeContent.collectElementbyClass(classname)
	contents.text.sort(function() {return 0.5 - Math.random();})
	for (var i=0; i<contents.ref.length; i++){
		contents.ref[i].innerHTML=contents.text[i]
		contents.ref[i].style.visibility="visible"
	}
}

randomizeContent.collectElementbyClass=function(classname){ //return two arrays containing elements with specified classname, plus their innerHTML content
var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i") //regular expression to screen for classname within element
var contentobj=new Object()
contentobj.ref=new Array() //array containing references to the participating contents
contentobj.text=new Array() //array containing participating contents' contents (innerHTML property)
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (var i=0; i<alltags.length; i++){
if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1){
contentobj.ref[contentobj.ref.length]=alltags[i]
contentobj.text[contentobj.text.length]=alltags[i].innerHTML
}
}
return contentobj
}

function randomizeSelect(inSelect,inmode){
	// ### DC 20090509 CHANGED FOR NEW USE FOR RANKING AND SINGLE CHOICE DROP-DOWN - PASSES ACTUAL VALUE OF QHASROTATION
	inmode=inmode-1;
	// INMODE NOW=1 IF STICKY BOTTOM
	var lastitem;
	inSelect=document.getElementById(inSelect);
	var selContents=new Array();
	var count=inSelect.length
	if(isNaN(inmode)){inmode=0}
	if(inmode==1){
		//SAVE ORIGINAL LAST ITEM
		lastitem=inSelect.options[count-1].text + '¬'+ inSelect.options[count-1].value;
	}
	// PUT DROP DOWN OPTIONS INTO ARRAY
	for(i=1;i<count-inmode;i++){
		selContents[i]=inSelect.options[i].text + '¬'+ inSelect.options[i].value;
	}
	// RANDOM SORT OPTIONS
	selContents.sort(function() {return 0.5 - Math.random();})
	// TRUNCATE DROP DOWN TO FIRST OPTION ONLY WHICH IS 'PLEASE SELECT AN ANSWER'
	inSelect.length=1;
	// REBUILD DROP DOWN
	for (i=0;i<(count-(1+inmode));i++){
		var optionName = new Option(selContents[i].split('¬')[0], selContents[i].split('¬')[1])
		var length = inSelect.length;
		inSelect.options[length] = optionName;
	}
	// IF STICKY BOTTOM THEN ADD IN ORIGINAL LAST ITEM
	if(inmode==1){
		var optionName = new Option(lastitem.split('¬')[0], lastitem.split('¬')[1])
		var length = inSelect.length;
		inSelect.options[length] = optionName;
	}
}

function randomizeRanking(inSelect){
	inSelect=document.getElementById(inSelect);
	var selContents=new Array();
	var count=inSelect.length
	//DON'T MOVE INSTRUCTION ITEM AT TOP
	for(i=1;i<count;i++){
		selContents[i]=inSelect.options[i].text + '¬'+ inSelect.options[i].value;
	}
	selContents.sort(function() {return 0.5 - Math.random();})
	inSelect.length=1;
	for (i=0;i<count-1;i++){
		var optionName = new Option(selContents[i].split('¬')[0], selContents[i].split('¬')[1])
		var length = inSelect.length;
		inSelect.options[length] = optionName;
	}
}

function rotateAll(){
	//return;
	var alltags=document.getElementsByTagName("*")
	var fb=document.getElementById('feedback');
	limit=alltags.length;
	var inside=false;
	for (var i=0; i<limit; i++){
		if (alltags[i].className=='start'){
			// START
			inside=true;
			var contentobj=new Object()
			contentobj.ref=new Array() //array containing references to the participating contents
			contentobj.text=new Array() //array containing participating contents' contents (innerHTML property)
		}
		if (alltags[i].className=='end'){
			// STOP ADDING ELEMENTS TO contentobj AND SORT AND REDRAW
			inside=false;
			contentobj.text.sort(function() {return 0.5 - Math.random();})
			for (var j=0; j<contentobj.ref.length; j++){
				contentobj.ref[j].innerHTML=contentobj.text[j]
			}
			contentobj=null;
		}
		if (inside==true && alltags[i].className!='start' && alltags[i].className.search('group')>-1){
			//WE HAVE A VALID ELEMENT TO BE ADDED TO contentobj
			contentobj.ref[contentobj.ref.length]=alltags[i]
			contentobj.text[contentobj.text.length]=alltags[i].innerHTML;
			//fb.innerHTML=fb.innerHTML + '<br />['+ i + '] '+ alltags[i].innerHTML;
		}
	}
}
