/*
*
*
*/
function jumpMenu(id,linkURL,extra) {
	if(id != -1) {
		window.location.href = ''+linkURL+'?'+extra+'='+id+'';
	}
}
function validarFormulario(formulario){
	var erros = "Erros Encontrados:\n\n";
	
	for(var i = 0; i < formulario.elements.length; i++){
		
		if(formulario.elements[i].type == "text" || formulario.elements[i].type == "textarea" || formulario.elements[i].type == "password"){
			
			if(formulario.elements[i].alt == "*" && formulario.elements[i].value == ""){
				erros += "* Campo "+formulario.elements[i].id+" não preenchido!\n";
			}
			if(formulario.elements[i].title == "*" && formulario.elements[i].value == ""){
				erros += "* Campo "+formulario.elements[i].id+" não preenchido!\n";
			}
			
		}else if(formulario.elements[i].type == "select-one"){
			
			var index = formulario.elements[i].selectedIndex;
							
			if(formulario.elements[i].title == "*" && formulario.elements[i].options[index].value == "0"){
				erros += "* Campo "+formulario.elements[i].id+" não selecionado!\n";
			}
			
		}			
	}
	if(erros != "Erros Encontrados:\n\n"){
		alert(erros);
		return false;
	}else{
		return true;
	}
}
/*******************************************************/
/* Funcao para validar um CPF no formato 999.999.999-99
/******************************************************/
function validarCpf(pcpf){
	campo = pcpf;
	pcpf = pcpf.value;
	
	pcpf = pcpf.toString().replace( ".", "" );
	pcpf = pcpf.toString().replace( ".", "" );
	pcpf = pcpf.toString().replace( ".", "" );
	pcpf = pcpf.toString().replace( "-", "" );
	
	if (pcpf.length == 0) {return false;}
	if (pcpf.length != 11) {sim=false}
	else {sim=true}

	if (sim )  // valida o primeiro digito
	{
	for (i=0;((i<=(pcpf.length-1))&& sim); i++)
	{
	 val = pcpf.charAt(i)
	 if

 ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")

 &&    (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {sim=false}
	 }

	 if (sim)
	{
	soma = 0
	for (i=0;i<=8;i++)
	{
	 val = eval(pcpf.charAt(i))
	 soma = soma + (val*(i+1))
	}

	resto = soma % 11
	if (resto>9) dig = resto -10
	else  dig = resto
	if (dig != eval(pcpf.charAt(9))) { sim=false }
	 else   // valida o segundo digito
	{

	 soma = 0
	for (i=0;i<=7;i++)
	 {
	 val = eval(pcpf.charAt(i+1))
		soma = soma + (val*(i+1))
	}

	 soma = soma + (dig * 9)
	resto = soma % 11
	 if (resto>9) dig = resto -10
	 else  dig = resto
	 if (dig != eval(pcpf.charAt(10))) { sim = false }
	else sim = true
	 }
	 }
	}

	if (sim) { 
		//alert("Valor Valido de CPF") ;
		return true;
	}else{
		alert("Erro Encontrado:\n\n* CPF Inválido!");
		campo.focus();
		return false;
	}
}
/*
*
*
*/
function checkTag(TAG,ID,OBG) {
		
		var x = document.getElementsByTagName(TAG);
		
		if(OBG != "") {
				document.getElementById(OBG).className = "HIDDEN";
		} else {
				for (var i = 0;i < x.length; i++) {
						if((x[i].id == ID) && (x[i].className == "HIDDEN")) {
							document.getElementById(ID).className = "VISIBLE";
							//alert(document.getElementById(x[i].id).className+" PRIMEIRO");
						}
						if((x[i].id != ID) && (x[i].className == "VISIBLE")) {
							document.getElementById(x[i].id).className = "VISIBLE";
							//alert(document.getElementById(x[i].id).className+" SEGUNDO");
						}	
				}
		}
		//alert(document.getElementById(ID).style.visibility);
		
}

function exibeThumbs() {
	//var class = document.getElementById("tempThumbs");
	
	//if(class.className == "tempHidden") {
		 //class.className = "tempVisible";
	//} else {
		 //class.className = "tempHidden";
	//}
	alert("OK");
	
}
/*
* insertData();
* Função para definir uma data para finalização da cotação
*/
function insertData(ID) {
	
	if(confirm("Deseja copiar essa cotação?!")) {
		var dataFim = prompt("Digite a data final para o prazo da cotação. Ex.: 00/00/0000")
		window.location.href="copy.php?id_compra="+ID+"&dataFim="+dataFim+"";
	}
	
}
/*
* confirmActionAjax(mensagem);
* Função para exibir uma mensagem e executar um comando
*/
function confirmActionAjax(mensagem) {
	
			if(confirm(mensagem)) {
				xajax_armazenarCompra(xajax.getFormValues('formulario'));
			}
			
}
/*
*
*/
function mudaCor(elem) {
 //document.getElementById(elem).bgColor = "#8EAEBF";
 alert(elem);
}
/*
*
*/
function selecionaRadio(VALOR) {
	
 var x = 0;
 var y = 0;
 var z = 0;
	
 inputs = document.getElementsByTagName('input');  
   for (i=0;i<inputs.length;i++){  
     if (inputs[i].type == "radio"){  
        if (inputs[i].checked) {
						
						// Achou o Check					
						if(inputs[i].value != VALOR) {
							 inputs[i].checked = false;
						} else {
							
						}
						
				 }    
      }  
   }
	
}
/*
* sizeSite(ID);
* Função para redimensionar o site de acordo com a resolução
* Exemplo
*  <body onload="sizeSite('tabela_principal');">
*/
function sizeSite(ID) {

	var largura;

	if(screen.width >= "1024"){
		largura = 940;
	} else if(screen.width == "800") {
		largura = 779;
	}

	document.getElementById(ID).width = largura;
	
	//alert(document.getElementById(ID).width);
	
}



/*
* checkDiv(ID);
* Função para exibir apenas uma unica TAG (DIV,SPAN)
* Exemplo
* 	<select onChange="checkDiv('span','DIV',this.value);">...
*/
function checkDiv(TAG,ID,OBG) {
		
		var x = document.getElementsByTagName(TAG);

		if(OBG != "") {
			
				document.getElementById(OBG).style.display = "block";
			
		} else {

				for (var i = 0;i < x.length; i++) {
						
						if((x[i].id == ID) && (x[i].style.display == "none")) {
							document.getElementById(ID).style.display = "block";
						}
									
						if((x[i].id != ID) && (x[i].style.display == "block")) {
							document.getElementById(x[i].id).style.display = "none";
						}
								
				}
							
		}
		
}

/*
* openClose(ID);
* Função para exibir e esconder uma div
* onclick="openClose(1);"
*/
function openClose(ID) {
	var ESTILO = document.getElementById(ID);
	
	if(ESTILO.className == "INV") {
		 ESTILO.className = "EXB";
	} else {
		 ESTILO.className = "INV";
	}
}
/*
* questionClear(MSG,CAMPO)
* Função para perguntar e limpar campos escolhidos
*/
function questionClear(MSG,CAMPO) {
	
		if(MSG != "") {
			
			if(confirm(MSG)) {
				document.getElementById(CAMPO).value = "";
			}
		
		}
	
}
/*
*
*/
function paginar(local){
	window.location = local;
}
/*
* sum(x)
* Função para calcular um array estatico
*/
sum = function(o){
    for(var s = 0, i = o.length; i; s += o[--i]);
    return s;
};
/*
* getElem(form);
* Função para pegar o numero de elementos a ser calculado!!
*/
function getElem(form) {
		
		var numElement = eval(document.getElementById(form).length);
		var objForm    = document.getElementById(form);
		var i;
		var x = 0;

		for (i = 0; i <= numElement - 1; i++) {
			if ((objForm.elements[i].type == 'hidden') && (objForm.elements[i].name != 'id_fornecedor') && (objForm.elements[i].name != 'nElem') && (objForm.elements[i].name != 'id_compra')) {	
				x++;
			}
		}
		
		document.getElementById("nElem").value = x;
}
/*
function transforma()
{
    var palavras = document.getElementById("teste").value.split(",");
    var words = [];
    
    for (var a = 0; a < palavras.length; a++)
    {
        words.push(palavras[a]);
    }
    return words;
}
*/
/*
* checkField(pos);
* Função para desabilitar campos dinamicamente atravez de CheckBox
* onchange="checkField(this.value);"
*/
function checkField(pos) {
	
	var check = document.getElementById("checkPD_"+pos).checked; 
	
	if(check == true) {
		document.getElementById("valorPD_"+pos).disabled   = true;
		document.getElementById("valorPD_"+pos).value      = "0,00";
		document.getElementById("totalPD_"+pos).innerHTML  = "0,00";
		document.getElementById("vtotalPD_"+pos).value     = "0,00";
	} else {
		document.getElementById("valorPD_"+pos).disabled   = false;
		document.getElementById("valorPD_"+pos).value      = "";
		document.getElementById("totalPD_"+pos).innerHTML  = "0,00";
		document.getElementById("vtotalPD_"+pos).value     = "";
	}
	
}
/*
* currencyFormat(fld, milSep, decSep, e)
* Função para formatar o campo com valores de moedas
* onKeyPress="return currencyFormat(this, '.', ',' ,event)"
*/
function currencyFormat(fld, milSep, decSep, e) {
	var sep        = 0;
	var key        = '';
	var i = j      = 0;
	var len = len2 = 0;
	var strCheck   = '0123456789';
	var aux = aux2 = '';
	var whichCode  = (window.Event) ? e.which : e.keyCode;
	
	/*
	* 9  = TAB
	* 13 = Enter
	* 8  = BackSpace
	* 37 = setinha para esquerda
	* 39 = setinha para direita
	* 46 = Delete
	*/

	if ((whichCode == 13) || (whichCode == 8) || (whichCode == 9)) {
		return true;  // Enter ou BackSpace
	}
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) {
		return false;  // Not a valid key
	}
	len = fld.value.length;
	for(i = 0; i < len; i++) {
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)){
			 break;
		}
	}
	
	aux = '';
	for(; i < len; i++) {
		if (strCheck.indexOf(fld.value.charAt(i))!=-1){
			aux += fld.value.charAt(i);
		}
	}
	aux += key;
			
	len = aux.length;
	if (len == 0) {
		fld.value = '';
	} else if (len == 1) {
		fld.value = '0'+ decSep + '0' + aux;
	} else if (len == 2) {
		fld.value = '0'+ decSep + aux;
	} else if (len > 2) {
		aux2 = '';

		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--) {
			fld.value += aux2.charAt(i);
		}
		
		fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}
/*
* tecla();
* Função para capturar a tecla
*/
function tecla (field, event, campo) {
		
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		var listRef = document.getElementById("listRef");
		var x       = document.getElementsByTagName("li");
		var i;
		
		if (keyCode == 13) {
			
		/*if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
					if (field == field.form.elements[i]) {
						break;
						i = (i + 1) % field.form.elements.length;
						field.form.elements[i].focus();
						return false;
					}	else {
						return true;
					}
			}
	 }*/
	 
	 if (campo == "CODPESQUISA") {
	 	
		for(i = 0; i < x.length; i++) {
			 if(x[i].className == "selected") {
				 	document.getElementById("CODPESQUISA").value = x[i].innerHTML;
			 		xajax_consultaRef(xajax.getFormValues('formulario'));
					break;
			 }
		 }
		 
	 }
	 
	 if (campo == "DESCRICAO") {
	 	
		for(i = 0; i < x.length; i++) {
			 if(x[i].className == "selected") {
				 	document.getElementById("DESCRICAO").value = x[i].innerHTML;
			 		xajax_consultaDesc(xajax.getFormValues('formulario'));
					break;
			 }
		 }
		 
	 }
		
		//listRef.style.display = "none";
		return false;
	 }
	 
	 if (keyCode == 9) {
		 
		 
		 if (campo == "CODPESQUISA") {
	 	
				for(i = 0; i < x.length; i++) {
			 		if(x[i].className == "selected") {
				 		document.getElementById("CODPESQUISA").value = x[i].innerHTML;
			 			xajax_consultaRef(xajax.getFormValues('formulario'));
						break;
			 		}
		 		}
		 
	 	 }
		 
		 if (campo == "DESCRICAO") {
	 	
				for(i = 0; i < x.length; i++) {
			 		if(x[i].className == "selected") {
				 		document.getElementById("DESCRICAO").value = x[i].innerHTML;
			 			xajax_consultaDesc(xajax.getFormValues('formulario'));
						break;
			 		}
		 		}
		 
	 	 }
		 
		 
		//listRef.style.display = "none";
		return true;
	 
	 }
	
}

/*
* primeiro_campo(form);
* Função pra deixar o primeiro campo de um form em foco
*/
function primeiro_campo(TAG) {
	
	var numForm    = document.getElementsByTagName("form");
	var i;
	
	if(numForm.length != 0) {
	
		var numElement = eval(document.getElementById(TAG).length);
	
		for (i = 0; i < numElement; i++) {
			if (document.getElementById(TAG).elements[i].type == 'text') {
					document.getElementById(TAG).elements[i].focus();
					break;
			}
		}
	}
	

}
/*
* checkForm(form);
* Função pra verificar os campos de um form basta atribuir a propriedade title="<nome do campo>" ao campo do form
*/
function checkForm(form) {
	var numElement = eval(document.getElementById(form).length);
	var i;
	var Obj = document.getElementById(form);
	var erro = "";
	
	for (i = 0; i < numElement; i++) {
		// VALOR DO SELECT
		var index = Obj.elements[i].selectedIndex;
		
		// CAMPO DE TEXTO
		if ((Obj.elements[i].type == "text") && (Obj.elements[i].title != "") && (Obj.elements[i].value == "")) {
			erro += "- O Campo "+Obj.elements[i].title+".\n";
			Obj.elements[i].focus();
			break;
		}
		
		// CAMPO DE SELECT
		if ((Obj.elements[i].type == "select-one") && (Obj.elements[i].title != "") && (Obj.elements[i].options[index].index == 0)) {
			erro += "- O Campo "+Obj.elements[i].title+" deve ser selecionado um item.\n";
			Obj.elements[i].focus();
			break;
		}
		
		// CAMPO PASSWORD
		if ((Obj.elements[i].type == "password") && (Obj.elements[i].title != "") && (Obj.elements[i].value == "")) {
			erro += "- O Campo "+Obj.elements[i].title+".\n";
			Obj.elements[i].focus();
			break;
		}
		
	}
	
	if (erro != "") {
		alert("Por Favor verifique o Campo:\n\n"+erro);
		return false;
	} else {
		return true;
	}
}
/*
* messageAlert(mensagem,location,janela,tamanho);
* Função exibir uma mensagem personalizada e Redirecionar
*/
function messageAlert(mensagem,location,janela,tamanho) {
	
	switch(tamanho) {
		case "MAX" : size = "width=1024, height=724"; break;
		case "MED" : size = "width=800, height=600"; break;
		case "MIN" : size = "width=640, height=480"; break;
		default : break;
	}
	
	if ((mensagem != "") && (janela != "")) {
	
		if(confirm(''+mensagem+'')) {
			window.open(''+location+'','Janela','fullscreen=yes, scrollbars=yes, '+size+'');
		}
		
	} else if(mensagem != "") {
		
		if(confirm(''+mensagem+'')) {
			window.location.href = ''+location+'';
		}
		
	} else {
			if(janela == "") {
				window.location.href = ''+location+'';
			} else {
				window.open(''+location+'','Janela','fullscreen=yes, scrollbars=yes, '+size+'');
			}
	}
	
}
/*
* clearField(campo);
* Função exibir para limpar um campo especifico
*/
function clearField(campo) {
	if (document.getElementById(campo).value != '') {
			document.getElementById(campo).value = '';
			document.getElementById(campo).focus();
	} else {
			document.getElementById(campo).focus();
	}
}
/*
* ViewHidden_div(idLink,idDiv,Force);
* idLink -> ID DA TAG QUE CONTEM O EVENTO
* idDiv  -> ID DA DIV QUE RECEBE O EVENTO
* Force  -> FORÇA O FECHAMENTO DA DIV
* Tag1   -> O TEXTO QUE SERÁ EXIBIDO
* Tag2   -> O TEXTO QUE SERÁ EXIBIDO
* idRes  -> CASO SEJA DINAMICO O RESULTADO OBTIDO
* Função exibir ou esconder uma DIV
* Exemplo Estático
* <a href="#" id="linkTAF" onclick="ViewHidden_div('linkTAF','addTAF','','[ADD TAREFA]','[FECHAR]','')">[ADD TAREFA]</a>
* Exemplo Dinâmico
* <a href=\"#\" id=\"linkTAF".$rows["id_item"]."\" onclick=\"ViewHidden_div('linkTAF','addTAF','','[ADD TAREFA]','[FECHAR]','".$rows["id_item"]."')\">[ADD TAREFA]</a>";
*/
function ViewHidden_div(idLink,idDiv,Force,Tag1,Tag2,idRes) {
	if (idRes != "") {
		
		if (document.getElementById(idLink+idRes).innerHTML == ''+Tag1+'') {
				document.getElementById(idLink+idRes).innerHTML = ''+Tag2+'';
				document.getElementById(idDiv).style.display = 'block';
		} else {
				document.getElementById(idLink+idRes).innerHTML = ''+Tag1+''
				document.getElementById(idDiv).style.display = 'none';	
		}
		// Caso Extra
		if (Force != '') {
				document.getElementById(idLink+idRes).innerHTML = ''+Tag1+'';
				document.getElementById(idDiv).style.display = 'none';
		}
		
	} else {
		
		if (document.getElementById(idLink).innerHTML == ''+Tag1+'') {
				document.getElementById(idLink).innerHTML = ''+Tag2+'';
				document.getElementById(idDiv).style.display = 'block';
		} else {
				document.getElementById(idLink).innerHTML = ''+Tag1+''
				document.getElementById(idDiv).style.display = 'none';
		}
		// Caso Extra
		if (Force != '') {
				document.getElementById(idLink).innerHTML = ''+Tag1+'';
				document.getElementById(idDiv).style.display = 'none';
		}
		
	}
}
/*
* checkPassword(campo1, campo2);
* Função para verificar se um campo é identido do outro
*/
function checkPassword(ID1, ID2) {
	var valor1 = document.getElementById(ID1).value;
	var valor2 = document.getElementById(ID2).value;
	
	if (valor1 != valor2) {
		alert("A senha digitada não confere!!");
		document.getElementById(ID2).focus;
		return false;
	} else {
		return true;
	}
	
}
/*************************************************************/
/* Funcao txtBoxFormat(objForm, strField, sMask, evtKeyPress)
/* 		descricao: formata um campo de acordo com a mascara informada.
/*		uso: <input type="text" name="data" onKeyPress="txtBoxFormat(formulario, 'data', '99/99/9999', event);">
/**************************************************************/
function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	
	if(document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode;
	} else if(document.layers) { // Nestcape
		nTecla = evtKeyPress.which;
	} else {
		nTecla = evtKeyPress.which;
		if (nTecla == 8) {
				return true;
		}
	}
	
	sValue = objForm[strField].value;
	// Limpa todos os caracteres de formatação que
	// já estiverem no campo.
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( " ", "" );
	sValue = sValue.toString().replace( " ", "" );
	fldLen = sValue.length;
	mskLen = sMask.length;
	
	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;
	
	while (i <= mskLen) {
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ":") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
		
		if (bolMask) {
			sCod += sMask.charAt(i);
			mskLen++;
		} else {
			sCod += sValue.charAt(nCount);
			nCount++;
		}
		i++;
	}
	
	objForm[strField].value = sCod;
	if (nTecla != 8) { // backspace
		if (sMask.charAt(i-1) == "9") { // apenas números...
		return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
	else { // qualquer caracter...
		return true;
	}
	} else {
		return true;
	}
}
/*
* checkEmail(email)
* Função para verificar se o e-mail é valido
* EX.: checkEmail(this.value);
*/
function checkEmail(email) {
  var CharValido = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  var erro 		 = "";
  var valido     = true;
  var i;
  
  for (i=0; i < email.length; i++) {
    var letras = email.charAt(i).toLowerCase();
    if (CharValido.indexOf(letras) != -1)
      continue;
      valido = false;
      break;
  }
  
  if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
   	erro += "Não foi encontrado o caracter @ e-mail.\n";
  } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
    erro += "Não foi encontrado o nome do servidor no e-mail.\n";
  } else if (email.indexOf("@") == email.length) {
	erro += ("@2");
  } else if (!valido) {
    erro += "Existe caracteres inválidos no e-mail.\n";
  }
  
  if (erro != "") {
    alert("Por Favor verifique os seguintes erro no campo e-mail:\n\n"+erro);
  } else {
    return true
  }
  
}
/*
* addItem(Pai,Filho)
* Função para enviar itens de um LIST PAI para o LIST FILHO
* onclick="addItem('listA','listB[]');"
*/
function addItem(Pai,Filho) {

	var i;
	var exist     = 0;
	var itemAdd   = document.createElement("option");
	var listPai   = document.getElementById(Pai);
	var listFilho = document.getElementById(Filho);

 	// Faz o Laço e pega o item selecionado
	for(i = 0; i < listPai.options.length; i++) {
		
		if(listPai.options[i].selected) {
				
				// Verificando se existe o item seleciona na lista filho
				for(x = 0; x < listFilho.options.length; x++) {
				
					 if(listPai.options[i].text == listFilho.options[x].text) {
					 			exist++;
					 }
				
				}
				
				if(exist == 0) { 
					listFilho.options.add(itemAdd);
					itemAdd.text  = listPai.options[i].text;
					itemAdd.value = listPai.options[i].value; 
					listPai.remove(i);
				} else {
					alert("O Item selecionado já foi Adicionado!!");
				}
		
		}
				
	}
	
	// Fazendo a Selecção dos Itens escolhidos
	for(i = 0; i < listFilho.options.length; i++) {
		listFilho.options[i].selected = true;
	}

}
/*
* delItem(Filho)
* Função para remover um item de uma LIST FILHO
* onclick="delItem('listB[]');"
*/
function delItem(Filho) {

	var listFilho = document.getElementById(Filho);
	
	// Removendo da Lista Pai
	for(i = 0; i < listFilho.options.length; i++) {
		if(listFilho.options[i].selected) {
				listFilho.remove(i);
		}
	}
	
	// Fazendo a Selecção dos Itens escolhidos
	for(i = 0; i < listFilho.options.length; i++) {
		listFilho.options[i].selected = true;
	}

}
/*
* selectAll(list)
* Função para selecionar todos os itens de um LISTBOX
* onclick="selectAll('listaB')"
*/
function selectAll(list) {
	
	var listFilho = document.getElementById(list);
	
  // Selecionando Todos
	for(i = 0; i < listFilho.options.length; i++) {
		listFilho.options[i].selected = true;
	}
}
/*
* desSelectAll(list)
* Função para desselecionar todos os itens de um LISTBOX
* onclick="selectAll('listaB')"
*/
function desSelectAll(list) {
	
	var listFilho = document.getElementById(list);
	
  // Selecionando Todos
	for(i = 0; i < listFilho.options.length; i++) {
		listFilho.options[i].selected = false;
	}
}
/*
* 
* 
* 
*/
function selectPrimeiro(campo) {
	
	//document.formul.miSelect.options[indice]
	
	/*
	
	texto = "O número de opções do select: " + document.formul.miSelect.length
	var indice = document.formul.miSelect.selectedIndex
	texto += "\nIndice da opção escolhida: " + indice
	var valor = document.formul.miSelect.options[indice].value
	texto += "\nValor da opção escolhida: " + valor
	var textoEscogido = document.formul.miSelect.options[indice].text
	texto += "\nTexto da opção escolhida: " + textoEscogido
	
	*/
	
	document.getElementById(campo).options[0].selected = true;
	
	//document.formul.miSelect.options[indice].value;
	
	//alert(indice);
	
	//for (var i = oList.options.length - 1; i >= 0; i--){
   //oList.options[i] = null;
 //}
 //oList.selectedIndex = -1;
}