function parseTextAreas(spanObject, textAreaFields){

	textAreaField = textAreaFields.split(',');
	textoTotal = spanObject.innerHTML;
	textoFinal = '';
	texto = '';

	for (i=0; i<textAreaField.length; i++){
		textArea = parent.document.forms[0].elements[textAreaField[i]];

		valor = textArea.value;

		posicao = 10;
		posicao = textoTotal.indexOf(textAreaField[i]);

		texto = textoTotal.substring(parseInt(posicao-60), posicao)
		posicaoInicioTag = texto.toUpperCase().indexOf('<TEXTAREA');
		posicaoInicioTag = posicao-60 + posicaoInicioTag
		texto = textoTotal.substring(parseInt(posicaoInicioTag ), posicao + 10000);
		posicaoFimTag = texto.toUpperCase().indexOf('/TEXTAREA>');
		posicaoFimTag = posicaoInicioTag + posicaoFimTag + 10
		texto = textoTotal.substring(posicaoInicioTag, posicaoFimTag);

		textoFinal = textoTotal.substring(0,posicaoInicioTag) + '' + valor + textoTotal.substring(posicaoFimTag, textoTotal.length);

		textoTotal = textoFinal;

	}

	return (textoTotal);

}

function imprimirSpan(imprimirCabecalho, spanObject, tituloJanela, tituloPagina, arquivoEstilo, textAreaFields){

	var textoImprimir;
	//spanObject = eval(spanObject);
	win = open("", "janelaImpressao","width=600,height=400,status=no,scrollbars=yes,resizable=yes,toolbar=no,menubar=no");
	// abre o documento para altera��o
	win.document.open();
	// cria o documento
	win.document.write("<html><head><title>" + tituloJanela);
	win.document.write("</title>");
	if (arquivoEstilo != ''){
	    win.document.write('<link rel=stylesheet type="text/css" href="' + arquivoEstilo + '">');
	}
	win.document.write("</head><body>");
	
	if (imprimirCabecalho == true) {
		//Imprimir o cabecalho
		diretorio = arquivoEstilo.substring(0, arquivoEstilo.lastIndexOf("/"));
		data = montarData() + '<br>' + montarHora();
		win.document.write("<table width=\"100%\"><tr><td width=\"20%\" align=\"center\"><img src=\"" + diretorio + "/brasaopositivo.gif\" heigth=\"80\" width=\"80\"></td><td width=\"60%\"><img src=\"" + diretorio + "/head_titulo_impressao.jpg\"></td><td width=\"20%\" align=\"center\" class=\"txt\" valign=\"middle\">" + data + "</td></tr></table>");
	}
	if (tituloPagina != ''){
		win.document.write("<p><b class=\"tit_on\">" + tituloPagina + "</b></p>");
	}
	if (textAreaFields != ''){
		textoImprimir = parseTextAreas(spanObject, textAreaFields);
	}
	else{
		textoImprimir = spanObject.innerHTML;
	}
	//win.document.write(spanObject.innerHTML);
	win.document.write(textoImprimir);
	win.document.write("<script language=JavaScript>");
	win.document.write("	self.print();");
	win.document.write('</script>');
	win.document.write("</body></html>");
	// fecha o documento - (nao a janela!)
	win.document.close();
}
