//----------------------------------------------------------------------------------------------------
//	-> FICHEIRO DE FUNCOES PARA OFFICECELL STD
//			Copyright 2005-2006, CreativeCell Design Studio
//			Criado: 	Luis Lourenço, 12 Janeiro 2005
//			Alterado: Luis Lourenço, 22 Novembro 2006
//----------------------------------------------------------------------------------------------------


//----------------------------------------------------------------------------------------------------
// Funcao que publica um SWF
//----------------------------------------------------------------------------------------------------
function publicaSWF(ficheiroSWF, versao, largura, altura){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+versao+'" width="'+largura+'" height="'+altura+'" style="z-index: 1;"><param name="movie" value="'+ficheiroSWF+'"><param name="quality" value="high"><embed src="'+ficheiroSWF+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+largura+'" height="'+altura+'" style="z-index: 1;"></embed></object>');
}

//----------------------------------------------------------------------------------------------------
// Funcao que publica um SWF Transparente
//----------------------------------------------------------------------------------------------------
function publicaSWF_transparente(ficheiroSWF, versao, largura, altura){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+versao+'" width="'+largura+'" height="'+altura+'" style="z-index: 1;"><param name="movie" value="'+ficheiroSWF+'"><param name="quality" value="high"><param name="wmode" value="transparent"><embed src="'+ficheiroSWF+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+largura+'" height="'+altura+'" wmode="transparent" style="z-index: 1;"></embed></object>');
}


//----------------------------------------------------------------------------------------------------
// Funcao que publica um MOV
//----------------------------------------------------------------------------------------------------
function publicaMOV(ficheiroMOV, largura, altura, autoplay, controles){
	document.write('<object width="'+largura+'" height="'+altura+'" classID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="'+ficheiroMOV+'"><param name="autoplay" value="'+autoplay+'"><param name="controller" value="'+controles+'"><embed width="'+largura+'" height="'+altura+'" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/" src="'+ficheiroMOV+'" autoplay="'+autoplay+'" controller="'+controles+'"></embed></object>');
}


//----------------------------------------------------------------------------------------------------
//  FUNCAO que remove caracteres de HTML
//----------------------------------------------------------------------------------------------------
function removeHTML(texto){
	// formatamos as TABLES caso tenham o parametro WIDTH
	texto = texto.replace(/<\s*table\s*.*width=\W*(\w+%*)[^>]*>/gi, "\yAtable width=\"$1\" cellpadding=\"0\" cellspacing=\"0\" border=\"1\"\yB");
	// formatamos as TABLES sem parametro WIDTH
	texto = texto.replace(/<\s*table\s*[^>]*>/gi, "\yAtable cellpadding=\"0\" cellspacing=\"0\" border=\"1\"\yB");
	// formatamos os HREFS
	texto = texto.replace(/<\s*a\s*.*href=\W*([^"\s>]+)[^>]*>/gi, "\yAa href=\"$1\"\yB");
	
	// formatamos os TD com COLSPAN e ROWSPAN (exitentes os 2)
	texto = texto.replace(/<\s*td\s*.*colspan=\W*([^"\s>]+).*rowspan=\W*([^"\s>]+)[^>]*>/gi, "\yAtd colspan=\"$1\" rowspan=\"$2\"\yB");
	// formatamos os TD com COLSPAN
	texto = texto.replace(/<\s*td\s*.*colspan=\W*([^"\s>]+)[^>]*>/gi, "\yAtd colspan=\"$1\"\yB");
	// formatamos os TD com ROWSPAN
	texto = texto.replace(/<\s*td\s*.*rowspan=\W*([^"\s>]+)[^>]*>/gi, "\yAtd rowspan=\"$1\"\yB");

	texto = texto.replace(/<\s*td\s*[^>]*>/gi, "\yAtd\yB");

	// formatamos os restantes elementos (SIMPLES)
	texto = texto.replace(/<\s*\/table\s*[^>]*>/gi, 												"\y01");
	texto = texto.replace(/<\s*p\s*(align=center|align="center")[^>]*>/gi, 	"\y02");
	texto = texto.replace(/<\s*p\s*(align=left|align="left")[^>]*>/gi, 			"\y03");
	texto = texto.replace(/<\s*p\s*(align=right|align="right")[^>]*>/gi, 		"\y04");
	texto = texto.replace(/<\s*p\s*[^>]*>/gi, 															"\y03");
	texto = texto.replace(/<\s*\/p\s*[^>]*>/gi, 														"\y05");
	texto = texto.replace(/<\s*br\s*[^>]*>/gi, 															"\y06");
	texto = texto.replace(/<\s*strong\s*[^>]*>/gi, 													"\y07");
	texto = texto.replace(/<\s*\/strong\s*[^>]*>/gi, 												"\y08");
	texto = texto.replace(/<\s*em\s*[^>]*>/gi, 															"\y09");
	texto = texto.replace(/<\s*\/em\s*[^>]*>/gi, 														"\y10");
	texto = texto.replace(/<\s*ul\s*[^>]*>/gi, 															"\y11");
	texto = texto.replace(/<\s*\/ul\s*[^>]*>/gi, 														"\y12");
	texto = texto.replace(/<\s*ol\s*[^>]*>/gi, 															"\y13");
	texto = texto.replace(/<\s*\/ol\s*[^>]*>/gi, 														"\y14");
	texto = texto.replace(/<\s*li\s*[^>]*>/gi, 															"\y15");
	texto = texto.replace(/<\s*\/li\s*[^>]*>/gi, 														"\y16");
	texto = texto.replace(/<\s*u\s*[^>]*>/gi, 															"\y17");
	texto = texto.replace(/<\s*\/u\s*[^>]*>/gi, 														"\y18");
	texto = texto.replace(/<\s*blockquote\s*[^>]*>/gi, 											"\y19");
	texto = texto.replace(/<\s*\/blockquote\s*[^>]*>/gi, 										"\y20");
	texto = texto.replace(/<\s*tr\s*[^>]*>/gi, 															"\y21");
	texto = texto.replace(/<\s*\/tr\s*[^>]*>/gi, 														"\y22");
	texto = texto.replace(/<\s*\/td\s*[^>]*>/gi, 														"\y23");
	texto = texto.replace(/<\s*\/a\s*[^>]*>/gi, 														"\y24");

	// eliminamos os restantes elementos entre TAGS
	texto = texto.replace(/<[^>]+>/g, "");

	// repomos os elementos SIMPLES
	texto = texto.replace(/\y01/g, "</table>");
	texto = texto.replace(/\y02/g, "<p align=\"center\">");
	texto = texto.replace(/\y03/g, "<p>");
	texto = texto.replace(/\y04/g, "<p align=\"right\">");
	texto = texto.replace(/\y05/g, "</p>");
	texto = texto.replace(/\y06/g, "<br>");
	texto = texto.replace(/\y07/g, "<strong>");
	texto = texto.replace(/\y08/g, "</strong>");
	texto = texto.replace(/\y09/g, "<em>");
	texto = texto.replace(/\y10/g, "</em>");
	texto = texto.replace(/\y11/g, "<ul>");
	texto = texto.replace(/\y12/g, "</ul>");
	texto = texto.replace(/\y13/g, "<ol>");
	texto = texto.replace(/\y14/g, "</ol>");
	texto = texto.replace(/\y15/g, "<li>");
	texto = texto.replace(/\y16/g, "</li>");
	texto = texto.replace(/\y17/g, "<u>");
	texto = texto.replace(/\y18/g, "</u>");
	texto = texto.replace(/\y19/g, "<blockquote style=\"margin-right: 0px\">");
	texto = texto.replace(/\y20/g, "</blockquote>");
	texto = texto.replace(/\y21/g, "<tr>");
	texto = texto.replace(/\y22/g, "</tr>");
	texto = texto.replace(/\y23/g, "</td>");
	texto = texto.replace(/\y24/g, "</a>");

	// repomos os INICIOS e FINS de Tabelas e HREFs
	texto = texto.replace(/\yA/g, "<");
	texto = texto.replace(/\yB/g, ">");
	
	return texto;
}

//----------------------------------------------------------------------------------------------------
// Função que actualiza DATA e HORA no campo dhAprovacao
//----------------------------------------------------------------------------------------------------
function actualizarDataHora(){
	var actual = new Date();

	// formatamos a variavel para dar entrada no campo
	if (actual.getDate() < 10) { dia = "0" + actual.getDate(); } else { dia = actual.getDate(); } 
	if (actual.getMonth() < 10) { mes = "0" + (actual.getMonth()+1); } else { mes = (actual.getMonth()+1); }
	if (actual.getHours() < 10) { horas = "0" + actual.getHours(); } else { horas = actual.getHours(); }
	if (actual.getMinutes() < 10) { minutos = "0" + actual.getMinutes(); } else { minutos = actual.getMinutes(); }
	if (actual.getSeconds() < 10) { segundos = "0" + actual.getSeconds(); } else { segundos = actual.getSeconds(); }

	var agora = dia + "-" + mes + "-" + actual.getFullYear() + " " + horas + ":" + minutos + ":" + segundos;
	
	document.frmArtigo.dhAprovacao.value = agora;
	return;
}
/*
//----------------------------------------------------------------------------------------------------
// Função que formata a seleccao efectuada
//----------------------------------------------------------------------------------------------------
function formataSeleccao(campo,formato){
	var cadeia = document.selection.createRange().text;
	campo.focus();
	var seleccao = document.selection.createRange();
	seleccao.text = "<" + formato + ">" + cadeia + "</" + formato + ">";
	return;
}

//----------------------------------------------------------------------------------------------------
// Função que formata como link a seleccao efectuada
//----------------------------------------------------------------------------------------------------
function formataBullets(campo){
	// a variavel cadeia armazena o texto seleccionado pelo utilizador
	var cadeia = document.selection.createRange().text;
	campo.focus();
	cadeia = cadeia.replace(/\r|\n|\r|\n/g, "~");
	cadeia = cadeia.replace(/~~~~/g, "\r\n\r\n• ");
	cadeia = cadeia.replace(/~~/g, "\r\n• ");
	cadeia = "• " + cadeia;
	cadeia = cadeia + "\r\n";
	
	// finalmente aplicamos o resultado final
	var seleccao = document.selection.createRange();
	seleccao.text = cadeia;
	return;
}

//----------------------------------------------------------------------------------------------------
// Função que formata como link a seleccao efectuada
//----------------------------------------------------------------------------------------------------
function formataLink(campo){
	var cadeia = document.selection.createRange().text;
	campo.focus();
	var sLink = prompt("Por favor insira o URL:","http://");
	if (sLink != null){
		var seleccao = document.selection.createRange();
		seleccao.text = "<a href=\"" + sLink + "\">" + cadeia + "</a>";
	}
	return;
}

*///----------------------------------------------------------------------------------------------------
// Função que activa uma classe CSS
//----------------------------------------------------------------------------------------------------
function activaClasse(elemento,classe){
	document.getElementById(elemento).className = classe;
}

//----------------------------------------------------------------------------------------------------
// Função que mostra layer
//----------------------------------------------------------------------------------------------------
function mostraLayer(nomeLayer){
	if (document.getElementById(nomeLayer).style.visibility == 'visible'){
		document.getElementById(nomeLayer).style.visibility = 'hidden';
	}
	else{
		document.getElementById(nomeLayer).style.visibility = 'visible';
	}
}

//----------------------------------------------------------------------------------------------------
// Função que avalia se um determinado campo se encontra preenchido
//----------------------------------------------------------------------------------------------------
function estaPreenchido(campo){
	if (campo.value == "" || campo.value == null){
		return false;
		}
	return true;
}

//----------------------------------------------------------------------------------------------------
// Função que avalia se um determinado campo é numerico
//----------------------------------------------------------------------------------------------------
function eNumerico(campo){
	if (campo.value == "" || campo.value == null){
		return false;
		}
	for (var i = 0; i < campo.value.length; i++){
		if (campo.value.charAt(i) < "0" || campo.value.charAt(i) > "9"){
			return false;
		}
	}
	return true;
}


//----------------------------------------------------------------------------------------------------
// Função que avalia se a tecla pressionada é ENTER
//----------------------------------------------------------------------------------------------------
function eEnter(e){
	var Cod;
	if (window.event) 
		Cod = window.event.keyCode;
	else if (e) 
		Cod = e.which;
	
	if (Cod == 13)
		 return true;
	else
		 return false;
}

//----------------------------------------------------------------------------------------------------
// Função para REFRESH de ARTIGO
//----------------------------------------------------------------------------------------------------
function refreshArtigo(){
	if (frmArtigo.operacao.value == 1){
		frmArtigo.operacao.value = -3;

	}
	else{
		frmArtigo.operacao.value = -4;		
	}

	i = 1;
	while (i <= frmArtigo.totalIdiomas.value){
		actualizaTextArea("texto"+i);		// executamos a actualizacao da CAIXA de TEXTO
		i++;
	}
	frmArtigo.submit();
}
