// click on a label = bold text

function maxlen(that, dest)
{
	var id = document.getElementById(dest)
	if(id == 'undefined' || id == null)
		return

	var maxch = 255 - that.value.length
	if (maxch < 0)
		id.value = "!!!";
	else
		id.value = maxch
}

function increase_clicks()
{
	var id = document.getElementById('clicks')
	if(id == 'undefined' || id == null)
		return
		
	var val = parseInt(id.value)
	
	id.value = val + 1
}

function label_click(evnt)
{
	var t = evnt.target ? evnt.target : evnt.srcElement;
	var el = t
	
	// set all other answers to normal
	
	while(el.parentNode || el.parentElement)
	{
		el = el.parentNode? el.parentNode : el.parentElement
		
		if(el.className == 'answer')
		{
			var list = el.getElementsByTagName('label')
			var len = list.length
			
			for(j = 0; j < len; j++)
				list[j].style.fontWeight = 'normal'

			break;
		}
	}
	
	t.style.fontWeight = 'bold'

	//increase_clicks()
}

// setup

function init()
{
	var labels = document.getElementsByTagName('label')
	var len = labels.length

	var ff = navigator.userAgent.indexOf('Firefox') != -1
	
	for(i = 0; i < len; i++)
	{
		labels[i].onclick = function() {label_click(event)}

		// firefox fix

		if(ff && labels[i].setAttribute)
			labels[i].setAttribute('onclick', 'label_click(event)')
	}
	
	var checkboxes = document.getElementsByTagName('input')
	len = checkboxes.length
	
	for(i = 0; i < len; i++)
	{
		if(checkboxes[i].type == 'radio')
		{
			checkboxes[i].onclick = function() {increase_clicks()}
			
			if(ff && checkboxes[i].setAttribute)
				checkboxes[i].setAttribute('onclick', 'increase_clicks()')		
		}
	}
	
	var id = document.getElementById('focus')
	if(id == 'undefined' || id == null) return
	if(id.focus) id.focus()
}

onload = init