function trim(campo){
  var retValue = campo;
  var ch 	   = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { 
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   }
   return retValue;
}

function auto_tab(campo1,campo2,qtd) {
	var val = campo1.value;
		if (val.length == qtd) {
			campo2.focus();
		}	
}


function valida_form(){
	var form, qtd, vazios, i;
	//setar vars
	form   = document.forms['form1'];	//pegar o nome do form a verificar
	qtd    = form.length;						//quantidade de elementos do form
	vazios = Array();						//array de id's de elementos vazios
	
	//verificar textfields vazio
	for (i = 0 ; i < qtd ; i++){
		
		if (form[i].type == 'text'){
			if ((form[i].value == "") && (form[i].alt == "#")){
				vazios.push(form[i].id);
			}
		}
		
		if (form[i].type == 'password'){
			if ((form[i].value == "") && (form[i].alt == "#")){
				vazios.push(form[i].id);
			}
		}
		
		//verificar selects vazio
		if ( (form[i].type == "select-one") && (form[i].value == "") ){
			vazios.push(form[i].id);
		}
		
		//verificar textarea vazio
		if ((form[i].type == "textarea") && (form[i].value == "")){
			vazios.push(form[i].id);
		}
	}
	
	//notificar ou enviar
	if (vazios.length == 0){
		form.submit();
	}else{
		marcarObrigatorios(vazios);
		alert("Alguns campos obrigatorios estao vazios.");
	}	
}

function Voltar(){
  document.location.href="../menu.php";
}

function redir(url){
  document.location.href = url;
}

// verifica o numero de checkboxs checados
function numeroChecados() {
	var aux = 0;
	for (i = 0; i < document.forms[0].length; i++) {
		if (document.forms[0].elements[i].type == 'checkbox' && document.forms[0].elements[i].id != 'dbListCheckAll_1') {
			if (document.forms[0].elements[i].checked) {
				aux += 1;
			}
		}
	}
	return aux;
}

function proximo(e, campo){
	if (e.keyCode == 13){ 
		campo.focus(); 
	}
}