var captchaURL = '';

function updateCaptcha() {
  var oldImg = document.getElementById('imgcaptcha');
  if (oldImg) {   
    if (captchaURL == '') {
      captchaURL = oldImg.src;
    }
    var d = new Date();
    oldImg.src = captchaURL + '?d=' + d.getMilliseconds();
    oldImg.id = 'imgcaptcha';
  }
}

function displayBoxMsg(msg) {
  var boxErro = document.getElementById('erroAssinatura');
  var listMsg = document.getElementById('listMsg');
  if (boxErro) {
    boxErro.style.display="block";
    listMsg.style.display="block";
    boxErro.innerHTML = "<p>"+msg+"</p>";		
  }
}

function submitSurveyForm(url) {
	var isIt = "";
	var how_big = document.surveyForm1.optionsSelected.length;
	for (i=0; i<how_big; i++) {
		if (document.surveyForm1.optionsSelected[i].checked) {
			isIt = isIt + document.surveyForm1.optionsSelected[i].value;
		}
	}

	if (isIt) {
		if (document.surveyForm1.strCAPTCHA && document.surveyForm1.strCAPTCHA.value == '') {
			displayBoxMsg('Por favor, digite os caracteres de confirmação.');
			return
		} else {
			updateCaptcha();
			var boxErro = document.getElementById('erroAssinatura');
			var listMsg = document.getElementById('listMsg');
			if (boxErro && listMsg) {
				boxErro.style.display="none";
				listMsg.style.display="none";
			}
			document.surveyForm1.action = url+'&se='+isIt;
			document.surveyForm1.submit();
		}
	} else {
		displayBoxMsg('Atenção! Selecione uma opção de enquete e verifique se o nome foi digitado corretamente.');
		return 
	}
}
