var basepath = "http://www.faculdadedocerrado.com.br/";

//Function to open pop up window
function openWin(theURL,winName,features) {
  	window.open(theURL,winName,features);
}

/* Excluir Cadastro */
function excluirCadastro(form,destino){
	
	if (confirm("Tem certeza que deseja excluir este registro?")) {
	
		document.getElementById(form).setAttribute("target","_self");
		document.getElementById(form).setAttribute("action",destino);
		document.getElementById(form).submit();
	
	}
}

// Conta caracteres
function FormataCount(form,num) {
	text = form.mensagem.value;
	falta = (num-parseInt(text.length));
	if(falta<0) falta = 0;
	form.Count.value = falta;
	if(text.length>num && !msg) {
		alert('A mensagem não deve ter mais de '+ num +' caracteres!');
		msg = true;
	}
	else if(falta!=0) msg = false;
}

// Checa se um campo está vazio
function emBranco(str) {
	tamanho = str.length;
    contador = 0;
    for (x=0; x<tamanho; x++) {
    	if (str.substring(x,x+1) == " ") { ++contador;}
    }
  return ((contador == tamanho) || (str == ""));
}

function checaForm(frm,campo,desc) {
	campo = document.forms[frm].elements[campo];
	
	if (emBranco(campo.value)) { 
		alert(desc);
		campo.focus();
		return false;
		}	
	}

function votarEnquete(enquete) {

	var indice;
	var escolheu;
	var resposta;
	
	escolheu = false;
	
	for (indice=0; indice < document.getElementsByName("r").length; indice++) {
		if (document.getElementsByName("r")[indice].checked) {
			resposta = document.getElementsByName("r")[indice].value;
			escolheu = true;
		}
	}
	
	if (escolheu) {
		window.open('votarenquete.asp?c=' + enquete + '&r=' + resposta, 'janEnquete', 'toolbar=no,location=no,scrollbars=auto,width=370,height=330,resizable=no,left=60,top=90');
	}
	else {
		alert('Escolha uma resposta antes de votar!');
	}
}

function resultadoEnquete(enquete) {
	window.open('votarenquete.asp?c=' + enquete, 'janEnquete', 'toolbar=no,location=no,scrollbars=auto,width=370,height=330,resizable=no,left=60,top=90');
}

/* Submeter Formulário*/
function enviaFormulario(form,destino){
	
	if (confirm("Tem certeza que deseja excluir os registros selecionados?")) {
	
		document.getElementById(form).setAttribute("target","_self");
		document.getElementById(form).setAttribute("action",destino);
		document.getElementById(form).submit();
	
	}
}