

function selectMe(id)
{
	input = document.getElementById(id);
	// simulate click to invoke listeners!
	input.click();
//	input.checked = true;
}


/* ##############################################################
All these functions are used for the javascript implementation of the closedended ranking question
##############################################################*/
 
 var alternatives_box = "ranking_box";
/**
	Move an element from the box with all options to the one with those where the ranking was done
*/
function addClosedRanking()
{
	allBox = document.getElementById("all");
	allIdx = allBox.selectedIndex;
	allVal = allBox.options[allIdx].value;
	allText = allBox.options[allIdx].text;				
	
	altBox = document.getElementById(alternatives_box);
	newOpt = new Option((altBox.length+1) + ". " +allText, allVal, false, true);
	altBox[altBox.length] = newOpt;
	
	allBox[allIdx] = null;
	doRenumbering();
}

/**
	move the items back to the box with all items
*/
function removeClosedRanking()
{
	var allBox = document.getElementById(alternatives_box);
	var allIdx = allBox.selectedIndex;
	var allVal = allBox.options[allIdx].value;
	var allText = allBox.options[allIdx].text;				
	
	var altBox = document.getElementById("all");
	var strWithoutNr = removeNumbering(allText);
	var newOpt = new Option(strWithoutNr, allVal, false, true);
	altBox[altBox.length] = newOpt;
	
	allBox[allIdx] = null;
	doRenumbering();
}

function moveUpClosedRanking(reNumber)
{
	var box = document.getElementById(alternatives_box);
	var idx = box.selectedIndex;
	swapOptions(box,idx,idx-1);
	if (reNumber)
	{
		doRenumbering();
	} else
	{
		onlyAssignInputField();
	}
}

function moveDownClosedRanking(reNumber)
{
	var box = document.getElementById(alternatives_box);
	var idx = box.selectedIndex;
	swapOptions(box,idx,idx+1);
	if (reNumber)
	{
		doRenumbering();
	} else
	{
		onlyAssignInputField();
	}
}


function onlyAssignInputField()
{
	var box = document.getElementById(alternatives_box);
	for ( i = 0; i < box.length; i = i + 1)
	{		
		var in_field = document.getElementById("altrank_" + (i+1));
		in_field.value = box[i].value;
	}
}

function doRenumbering()
{
	var box = document.getElementById(alternatives_box);
	for ( i = 0; i < box.length; i = i + 1)
	{
		txtNoNmb = removeNumbering(box[i].text);
		box[i].text = (i+1) + ". " + txtNoNmb;
		in_field = document.getElementById("altrank_" + (i+1));
		in_field.value = box[i].value;
	}
}

/*
	remove the numbering of a string
*/
function removeNumbering(txt)
{
	return txt.substr(txt.indexOf(".")+1);
}

// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}
	

/* ##############################################################
General functions for the filling out area
##############################################################*/

var timeStart;
function loadSteps()
{
	max();
	timeStart = new Date().getTime();
}

/*
Maximize the current browser window
usage: <body onload="javascript:max()">
*/
function max()
{
	w_height=screen.height;
	w_width=screen.width;
	window.moveTo(0,0);
	window.resizeTo(w_width,w_height);
}

/*
open a new window so that the back-button has no effect 
as taken from http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911 
usage: <A HREF="javascript:goNewWin()">Click to go to a new page</A> 
currently not in use
*/
function goNewWin(relUrl) 
{
	window.open(relUrl,'TheNewpop','toolbar=1, location=1,directories=1,status=1,menubar=1, scrollbars=1,resizable=1');
	self.close();

}

/*
This function is called when the page is unloaded
*/
function unloadMe()
{
	//trackMe();
	//history.go(1);
}