var num = 0;
$getId = function(id){
	return document.getElementById(id);
}
function mostra(next) {
	
  	ol  = $getId('olperguntas');
  	lis = ol.getElementsByTagName('li');
  	
	if(next){
		if(num<lis.length-1){
			num++;
		}else{
			getallChecked($getId('x_total').value);
		}
	}else{ 
		if(num>0){
			num--;
		}
	}
  	for(i=0; i<lis.length; i++){
		if(i!=num) {
			lis[i].style.display = 'none';
		}else{
			lis[i].style.display = 'block';
		}
	}
	//alert(num);sa
}
function getCheckedValue(radioObj) {
	if(!radioObj){
		return "x1";
	}
	var radioLength = radioObj.length;
	if(radioLength == undefined){
		if(radioObj.checked){
			return radioObj.value;
		}else{
			return "x2";
		}
	}
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "x3";
}
function xek(str){
	var exp = /x3/;
	if (exp.test(str)){
		testresult = 'Responda a todas as perguntas';
	}else{
		testresult = str;
	}
	return testresult;
}
function getallChecked (max){
	var valores='';
	for(i=0; i<max; i++){
		valores += getCheckedValue(document.forms['perForm'].elements['perg'+i]);
	}
	$getId('x_chave').value = (xek(valores));
	if($getId('x_chave').value != 'Responda a todas as perguntas'){
		document.forms['perForm'].submit();
		//alert($getId('x_chave').value);
	}else{
		alert($getId('x_chave').value);
	}
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}