
///////////////////////////////////////////////////
//	Validações do formulário de Solicitação de
//	Prorrogação
///////////////////////////////////////////////////

//	Incluindo os interessados no Select
function AtualizaInteressados(form) {

	//tratar aqui da questão do string separado por ";"
	var selInteressados, vtInteressados, strEntrada;
	
	selInteressados = form.txtInteressados;
	strEntrada = form.strTemp.value;
	vtInteressados = strEntrada.split(";");
	
	for (var i=0; i < vtInteressados.length; i++) {
		var no = new Option(vtInteressados[i], vtInteressados[i]);
		selInteressados.options[selInteressados.options.length] = no;
		form.strTemp.value = "";
	}		
	form.strTemp.focus();

}

//	Removendo os interessados do Select
function remove(box) {
	for(var i=0; i<box.options.length; i++) {
		if(box.options[i].selected && box.options[i] != "") {
			box.options[i].value = "";
			box.options[i].text = "";
		}
	}
	BumpUp(box);
}

//	Selecionando várias opções ao mesmo tempo
function MarcaListaInteressados() {
	
	listaInteressados = document.forms[0].txtInteressados;
	var tamanho = listaInteressados.options.length;
	
	for (var i=0; i < tamanho; i++)
		listaInteressados.options[i].selected = true;	
}

//	Selecionando várias opções ao mesmo tempo
function MarcaLista(campo) {
	
	var tamanho = campo.options.length;
	
	for (var i=0; i < tamanho; i++)
		campo.options[i].selected = true;	
	
}

//	Apagando a opção em branco do select quando uma opção é removida
function BumpUp(box) { 
	for(var i=0; i<box.options.length; i++) { 
		if(box.options[i].value == "") { 
			for(var j=i; j<box.options.length-1; j++) { 
				box.options[j].value = box.options[j+1].value; 
				box.options[j].text = box.options[j+1].text; 
			} 
			var ln = i; 
			break; 
		} 
	} 
	if(ln < box.options.length) { 
		box.options.length -= 1; 
		BumpUp(box); 
	} 
} 
// Escondendo linhas opcionais de acordo com opção escolhida no select
function EscondeLinhaCircuito(form) {
	if (form.Acao.value != "Circuito") { 
		idCircuito.style.display = 'none';
		idData.style.display = 'none';
	} 
	else { 
		idCircuito.style.display = 'block';
		idData.style.display = 'block';
	} 
}

//	Abre janela para inclusão de documentos da qualidade
function IncluirLinks(CodProcesso) {
	//var sURL = "/SACP/Parametros/Links/VincularLink.asp?CodProcesso=" + CodProcesso;
	var sURL = "/SACP/Parametros/AnexarArquivo2.asp?CodProcesso=" + CodProcesso;
	var oJanela = window.open(sURL, 'Links', 'width=500, height=260, toolbar=0, menu=0, resizeable=1', false);
	oJanela.focus();
}

//	Inclui um documento
function IncluirLink(documento, txtLinks, hiddenLinks, CodTipo, SiglaLink, txtDescLink, txtEndLink, IndAnexo) {
	
	if((CodTipo > -1) && (txtDescLink != "") && (txtEndLink != "")) {
//		alert(CodTipo + " - " + txtDescLink + " - " + txtEndLink);
		//	Criando o ítem
		var oElement = documento.createElement("OPTION");

		//	Atribuindo o valor
		oElement.value = CodTipo + "<CAMPO>";
		oElement.value = oElement.value + txtDescLink + "<CAMPO>";
		oElement.value = oElement.value + txtEndLink + "<CAMPO>";
		oElement.value = oElement.value + IndAnexo + "<REGISTRO>";

		//	Atribuindo o texto
		if (txtDescLink.length > 0) {
			oElement.text = "Tipo: " + SiglaLink;
			oElement.text = oElement.text + " - Descrição: " + txtDescLink;
			oElement.text = oElement.text + " - Arquivo/Link: " + txtEndLink;
		}
		//	Adicionando ao campo
		txtLinks.add(oElement);
		
		//	Atualizando o campo hiddenLinks
		AtualizahiddenLinks(txtLinks, hiddenLinks);
		
	}
}

//	Remove a referência SQA
function RemoveLinks(txtLinks, hiddenLinks) {
	if (txtLinks.selectedIndex > -1) {
		txtLinks.remove(txtLinks.selectedIndex);
	}
	AtualizahiddenLinks(txtLinks, hiddenLinks);
}

//	Atualiza o campo hiddenLinks
function AtualizahiddenLinks(txtLinks, hiddenLinks) {
	//	Limpando o string anterior
	hiddenLinks.value = "";

	//	Contador
	var iCont;
	
	// Agrupando as referências ao SQA
	for (iCont = 0; iCont < txtLinks.options.length; iCont ++)
		hiddenLinks.value = hiddenLinks.value + txtLinks.options[iCont].value;
		//alert(hiddenLinks.value);
}