	function ajaxInit() {
		var req;
		try {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(ex) {
				try {
					req = new XMLHttpRequest();
				} catch(exc) {
					alert("Esse browser não tem recursos para uso do Ajax");
					req = null;
				}
			}
		}
		return req;
	}

	function acAjaxPagina(pagina,acao,reg){
		var wmDiv = document.getElementById("lista");
		if (document.getElementById('ini')) {
			var x = document.getElementById('ini');
			var fim = document.getElementById('fim');
			if (acao == 'vai')	x.innerHTML++;
			if (acao == 'vem')	x.innerHTML--;	

			var y = (x.innerHTML-1) * reg;
			
			if (x.innerHTML == 1)  document.getElementById('vem').style.visibility = "hidden";
			else document.getElementById('vem').style.visibility = "visible";
			if (fim.innerHTML == x.innerHTML) document.getElementById('vai').style.visibility = "hidden";
			else  document.getElementById('vai').style.visibility = "visible";
			corp = x.innerHTML;
		}
		else {
			y = 0;
			corp = 1;
		}
			ajax = ajaxInit();
			ajax.open("GET", pagina+".asp?pag="+y+"&acao=Ajax&ini="+corp, true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.onreadystatechange=function() {
				if (ajax.readyState==1){
					wmDiv.innerHTML = "<img src='../imagens/carregando.gif'/>";
	   			}
				if (ajax.readyState==4){
					wmDiv.innerHTML = ajax.responseText;	
				}
			}
			ajax.send(null);
		}
		function acMostraEdit() {
			var div = document.getElementById('divEdit');
			if (div.style.display=='block') { 
				div.style.display='none';
				document.getElementById('msgsForum').style.display='block';
				document.getElementById('btForum').value=document.getElementById('forum_tipo').value;
			}
			else  {
				div.style.display='block';
				wmIniciar();
				document.getElementById('msgsForum').style.display='none';
				document.getElementById('btForum').value="Desistir";
			}

		}
		/*------------------------- Editor----------------------------------------------- */
	var IE;
	if (navigator.appName == 'Microsoft Internet Explorer') IE = 'IE';
	else IE = '';

	function wmIniciar() {
			menulize("menuEditor");
			getIFrameDocument('editor').designMode="on";
			document.getElementById('editor').contentWindow.focus();
		 }
	   function acEdit(arg,valor) {
			if(IE) editor.document.execCommand(arg,false, valor);
			else document.getElementById('editor').contentDocument.execCommand(arg, false, valor);
			document.getElementById('editor').contentWindow.focus();
		}
		function wmEventOnMouseOver(id) {
			if (document.getElementById(id).style.background.search('butback-press.gif') == -1) document.getElementById(id).style.background=" url('includes/butback-over.gif') no-repeat";
		}
		function wmEventOnMouseOut(id) {
			if (document.getElementById(id).style.background.search('butback-press.gif') == -1) document.getElementById(id).style.background=" url('includes/butback.gif') no-repeat";
		}
		function getIFrameDocument(aID){
			if (!IE){  
				return document.getElementById(aID).contentDocument;
			} else {
				return document.frames[aID].document;
			}
		} 

	function menulize(id) {
		var x = document.getElementById(id).getElementsByTagName('li');
		//else var x = document.getElementById(id).tags('li');
		for(i=0;i<x.length;i++) {
			if(x[i].id != 'sep') {
				x[i].onmouseover= function() { this.style.border='1px inset white'; }
				x[i].onmouseout= function() { this.style.border='1px outset white'; }
				x[i].onclick= function() { 
					valor = null;
					if (this.id == "insertimage") {
						Path = prompt("Selecione o caminho da imagem", 'http://');	
						if(Path) valor = Path; 
					}
					if (this.id == "createlink") {
						//verifica qd seleciona o texto ou não
						if (!IE) {
							var str = getIFrameDocument('editor').getSelection();
						}
						else {
							var str = getIFrameDocument('editor').selection.createRange();
						}
						if (str) {
							Path = prompt("Digite a URL:", 'http://');	
							if(Path) valor = Path; 
						} else {
							alert('Selecione algum texto antes');
							document.getElementById('editor').contentWindow.focus();
						}
					}
					if (this.id == "unlink") {
						//verifica qd seleciona o texto ou não
						if (!IE) {
							var str = getIFrameDocument('editor').getSelection();
						}
						else {
							var str = getIFrameDocument('editor').selection.createRange();
						}
						if (str) {
							if(Path) valor = null; 
						} else {
							alert('Selecione algum texto antes');
							document.getElementById('editor').contentWindow.focus();
						}
					}
					
					if (this.id == "forecolor") {
						Paleta('forecolor');	
					}
					if (this.id == "hilitecolor") {
						if(IE) Paleta('backcolor');	
						else Paleta('hilitecolor');
					}
					else acEdit(this.id, valor);
				}
			}
		}
	}
	function Paleta(acao) {
		var paleta = document.getElementById('Paleta');
		paleta.style.display = 'block';
		if(!IE) var x = paleta.getElementsByTagName('td');
		else {
			var x = paleta.getElementsByTagName('td');
		}
		//verifica qd seleciona o texto ou não
		
		if (!IE) {
			var str = getIFrameDocument('editor').getSelection();
		}
		else {
			
			var str = getIFrameDocument('editor').selection.createRange();
		}
				
		for( var i=0; i<x.length; i++ ) {
			x[i].onmouseover = function() { this.style.border='1px dotted white'; }
			x[i].onmouseout = function() { this.style.border='1px solid gray'; }
			x[i].onclick = function() {
			//verifica se tem selecionado
			if (str) {
			if (IE){
				str.select();
			}
				acEdit(acao,this.id);
			} else {
				//se nao, manda o focus e verifica se eh IE
				document.getElementById('editor').contentWindow.focus();
				if (IE){
					//se for IE manda o cursor pro final com a cor
					getIFrameDocument('editor').body.innerHTML = getIFrameDocument('editor').body.innerHTML;
				}
				acEdit(acao,this.id);
			}
				document.getElementById("Paleta").style.display = 'none';

			}
		}
	}

	function wmSeguranca(acao) {
		var campos = new Array ();
		if (acao) {
			var dados = "autor;e-mail;Texto"
			var dados2 = "autor;email;texto"
		} else {
			var dados = "título;autor;e-mail;Texto"
			var dados2 = "titulo;autor;email;texto"
		}
		
		campos = dados.split(';');
		var dadosGerais;
		var info = dados2.split(';');
		
		for (i=0; i < campos.length;i++ ){
			var campo = document.getElementById(campos[i]);
			if (campos[i] == 'Texto') {
				var texto = getIFrameDocument("editor").body.innerHTML;
				document.getElementById('Texto').value = texto;
				if(document.getElementById('Texto').value=="" || document.getElementById('Texto').value=="<br>"){
					acAlert("ATENÇÃO!\nO campo Texto não pode ser vazio",campos[i]);
					return false;
				}
			}
			if (campo.value == '') {
				acAlert('O campo '+campos[i]+' não pode ser deixado em branco',campos[i]);
				return false
			} 
			seguranca2 = new Array ("select", "insert", "update", "delete");
			for (x=0; x < 4 ; x ++) {
				if (campo.value.indexOf(seguranca2[x]) >= 0) {
					acAlert('A palavra ' + seguranca2[x] + ' não é permitida',campos[i]);  
					return false
				}
			}
			teste = String.fromCharCode("39");
			if (campo.value.indexOf(teste) >= 0) {
				campo.value = campo.value.replace("'","´");
			}
			/* Substitui " por ´*/
			teste = String.fromCharCode("34");
			if (campo.value.indexOf(teste) >= 0) {
				campo.value = campo.value.replace('"','´');
			}
			/* Substitui ; por ,*/
			teste = String.fromCharCode("59");
			if (campo.value.indexOf(teste) >= 0) {
				campo.value = campo.value.replace(";",",");
			}
			
			if (i==0){
				dadosGerais = info[i] +'='+escape(campo.value);
			} else {
				dadosGerais = dadosGerais+'&'+info[i] +'='+ escape(campo.value);
			}
		}
		acEnviaForm(dadosGerais,acao);
	}

	function acEnviaForm(parametros,acao){
		var wmDiv = document.getElementById("conteudo");
		ajax = ajaxInit();
		ajax.open("POST", "includes/forumAcao.asp?acao="+acao, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.onreadystatechange=function() {
			if (ajax.readyState==1){
				wmDiv.innerHTML = "<img src='imagens/carregando.gif' alt='Carregando' style='margin: 20px;' />";
   			}
			if (ajax.readyState==4){
				resposta = unescape(ajax.responseText);
				if (resposta == "erro") {
					acAlert('Ocorreu um erro, favor tentar denovo.');
				} else {
					document.location="forum.asp?id="+acao;
				}
			}
		}
		ajax.send(parametros);
	}

	function acAlert(msg,campo) {
		document.getElementById('alert').style.display='block'; 
		document.getElementById('alertMsg').innerHTML= msg;
		document.getElementById('rodape').style.visibility = "hidden";
		document.getElementById('topo').style.visibility = "hidden";
		document.getElementById('menu').style.visibility = "hidden";
		if (campo) document.getElementById('campoerrado').value = campo;
		
	}

	function acFechaAlerta() {
		document.getElementById('alert').style.display='none';
		var valor = document.getElementById('campoerrado').value;
		if (valor) {
			if (valor == "Texto") document.getElementById('editor').contentWindow.focus();
			else document.getElementById(valor).focus();
		}
		document.getElementById('rodape').style.visibility = "visible";
		document.getElementById('topo').style.visibility = "visible";
		document.getElementById('menu').style.visibility = "visible";
		
	}
