// JavaScript Document

var _ajax = { handler: {}, idCounter: 0 }; // a prop handler do obj permite várias conexões  simultaneas

function makeHttpRequest(url, send_n_load, params, meth){ 
	
	this.id = ++_ajax.idCounter;
	_ajax.handler[this.id] = this; //estancio o proprio objeto para handler com um id unico
	this.meth = meth ? meth : 'GET';	
	this.url = url;	
	this.params = this.meth == 'POST' ? params : '';//null
	this.paramsforGet = this.meth == 'GET' ? '?'+params : '';
	this.http_request = false;
	this.oReturn = send_n_load;

	this.init = function(){ // inicializa o objeto XMLHttpRequest
		if (window.XMLHttpRequest) { // Mozilla, Safari,... 
		this.http_request = new XMLHttpRequest(); 
				   //if (this.http_request.overrideMimeType) { 
					  // this.http_request.overrideMimeType('text/xml'); 
				   //} 
		} else if (window.ActiveXObject) { // IE 
			try { 
			this.http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
			} catch (e) { 
				try { 
				this.http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
				} catch (e) {} 
			} 
		} 
	}

this.init();

   if (!this.http_request) { 
       alert('No browser support'); 
       return false; 
   } 
   
   this.http_request.onreadystatechange = new Function("_ajax.handler["+this.id+"].onChange();");   
   
   this.onChange = function() {
	// alert("here");
       if (this.http_request.readyState == 4) { 
           if (this.http_request.status == 200) {              
			  
			   new Function("_ajax.handler["+this.id+"].oReturn(_ajax.handler["+this.id+"].http_request.responseText);")();
			   //alert(this.http_request.responseText);                   
             
           } else { 
            alert('There was a problem with the request.(MCode: ' + this.http_request.status + ')'); 
			//if($GEBId("load"))$GEBId("load").style.display="none"; 
           } 
       } 
   } 
   
   
   this.http_request.open(this.meth, this.url+this.paramsforGet, true);
    if(this.meth == "POST"){
	   this.http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	this.http_request.send(this.params);
   }
} // fim classe makeHttpRequest


//intancia o objeto acima
function ajax(doc,retfunc,params,meth){
	/*alert(doc+" - "+retfunc+" - "+params+" - "+meth);
	return;*/
myAjax = new makeHttpRequest(doc, retfunc, params, meth);
}

function validaEmail(mail){
	
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
//var filter2=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var ok = filter.test(mail);
	if(!ok) return false;
	else return true;
	
}


function valEnvio(form){
	
	if(form.nome.value != '' && form.email.value != ''){
		
		if(!validaEmail(form.email.value)){
			alert("Email inválido");
			form.email.value = "";
			return false;
		}else{
		parametro = 'nome=' + form.nome.value + '&email=' + form.email.value;
		ajax('enviaPedido.php', setresp, parametro, 'POST');	
		}
	
	} else {
		
		alert('Preencha Nome e Email'); return false;
		
	}
	
	
}

// form setorUsuario - isso aqui ta meio perdido...
var area = "";
var nivel = "";
var nome = "";
var email = "";
var login = "";
var senha = "";
var pass = "";
var active = "";
	
	
function coleta_dados_form(form){	
	
	////FORM SETOR USUARIO//////
	
	if(trimString(form.name) == "setorUsuario"){
		area = vAreaNome;
		nivel = vNivelNome;
		nome = trimString(form.nome.value);
		email = form.email.value;
		login = form.login.value;
		senha = form.senha.value;
		pass = form.confSenha.value;
		active = $GEBId("ativo").checked ? "Ativo" : "Inativo";
		//alert(area+" - "+nivel+" - "+nome+" - "+email+" - "+login+" - "+senha+" - "+pass+" - "+active);
	}
	
	////FORM AREAADMIN//////
	
	if(trimString(form.name) == "areaAdmin"){	
		area = form.area.value;
	}
	
	
	////FORM FUNC_P_AREA//////
	
	if(trimString(form.name) == "func_p_area"){	
		area = form.area.options[form.area.options.selectedIndex].text;
		func = form.tipo.value;
		//alert(area+" - "+func);
	}
	
	////FORM Comuna//////
	
	if(trimString(form.name) == "Comuna"){
		nome = trimString(form.nome.value);
		//pais = form.pais.options[form.pais.options.selectedIndex].text;
		//idioma = form.idioma.options[form.idioma.options.selectedIndex].text;
		
		desc = form.desc.value;
		
		destaque = $GEBId("destaque").checked ? "yes" : "no";
		//alert(nome+" - "+pais+" - "+idioma+" - "+desc+" - "+destaque);
	}
	
	////FORM Events//////
	if(trimString(form.name) == "Events"){
		
		nome = trimString(form.titulo.value);
		tipo = form.tipo.options[form.tipo.options.selectedIndex].text;
		press = form.press.value;
		descri = form.descricao.value;
		dia = form.dtDia.options[form.dtDia.options.selectedIndex].text;
		mes = form.dtMes.options[form.dtMes.options.selectedIndex].text;
		ano = form.dtAno.options[form.dtAno.options.selectedIndex].text;
		hora = form.hora.options[form.hora.options.selectedIndex].text;
		minu = form.minuto.options[form.minuto.options.selectedIndex].text;
		preco = form.preco.value;
		alvo = form.sexo.options[form.sexo.options.selectedIndex].text;
		opsex = form.opcSexual.options[form.opcSexual.options.selectedIndex].text;
		ageEntreIni = form.idadeEntreIni.options[form.idadeEntreIni.options.selectedIndex].text;
		ageEntreFim = form.idadeEntreFim.options[form.idadeEntreFim.options.selectedIndex].text;
		active = form.ativo.options[form.ativo.options.selectedIndex].text;
	}
	
	
	////FORM Banner//////
	if(trimString(form.name) == "Banner"){
		
		nome = trimString(form.titulo.value);

		dia = form.dtIniDia.options[form.dtIniDia.options.selectedIndex].text;
		mes = form.dtIniMes.options[form.dtIniMes.options.selectedIndex].text;
		ano = form.dtIniAno.options[form.dtIniAno.options.selectedIndex].text;
		hora = form.horaIniH.options[form.horaIniH.options.selectedIndex].text;
		minu = form.horaIniM.options[form.horaIniM.options.selectedIndex].text;
		
		diaFim = form.dtFimDia.options[form.dtFimDia.options.selectedIndex].text;
		mesFim = form.dtFimMes.options[form.dtFimMes.options.selectedIndex].text;
		anoFim = form.dtFimAno.options[form.dtFimAno.options.selectedIndex].text;
		horaFim = form.horaFimH.options[form.horaFimH.options.selectedIndex].text;
		minuFim = form.horaFimM.options[form.horaFimM.options.selectedIndex].text;
		
		linke = form.oLink.value;
		active = form.ativo.options[form.ativo.options.selectedIndex].text;
	}
	
	
	////FORM Entidades//////
	if(trimString(form.name) == "Entidades"){
		
		tipo = form.tipoEntidade.options[form.tipoEntidade.options.selectedIndex].text;
		my_cidade = nCidade;
		my_estado = nEstado;
		nome = trimString(form.nome.value);
		email = trimString(form.email.value);
		cep = form.cep.value;
		ddd = trimString(form.telDDD.value);
		tel = trimString(form.tel.value);
		obs = trimString(form.obs.value);
		
		
		
	}
	
	
	////FORM usuEntidades//////
	if(trimString(form.name) == "usuEntidades"){
		
		
		nome = trimString(form.nome.value);
		email = trimString(form.email.value);
		chave = form.chave.value;
		active = $GEBId("ativo").checked ? "Ativo" : "Inativo";
		
		
		
	}
	
	
}



function confere_dados_form(form){
	
	////FORM SETOR USUARIO//////
	
	if(trimString(form.name) == "setorUsuario"){	
	
		
	var msg = "";
	
	if(document.forms[0].area.value == "") {
		msg += "* Campo Área vazio;\n";
	}
	if(document.forms[0].nivel.value == "") {
		msg += "* Campo Nível vazio;\n";
	}
	if(document.forms[0].nome.value == "") {
		msg += "* Campo nome vazio;\n";
	}
	if(document.forms[0].email.value == "") {
		msg += "* Campo e-mail vazio;\n";
	} else if(!isEmail(document.forms[0].email.value)) {
		msg += "* Campo e-mail inválido;\n";
	}
	if(document.forms[0].login.value == "") {
		msg += "* Campo login vazio;\n";
	}
	if(document.forms[0].senha.value != "") {
		if(document.forms[0].senha.value!=document.forms[0].confSenha.value) {
			msg += "* Senhas diferentes;\n";
		}
	}
	
	if(msg!="") {
		alert(msg);
		return false;
	
	} else {			
	
		var area_saida = form.area.options[form.area.options.selectedIndex].text;
		var nivel_saida = form.nivel.options[form.nivel.options.selectedIndex].text;
		
		if(form.envia.value == "Atualizar"){
			
				if(area_saida != area) changes+="Alterou Área De: "+area+" Para: "+area_saida+"<br />";
				if(nivel_saida != nivel) changes+="Alterou Função De: "+nivel+" Para: "+nivel_saida+"<br />";
				if(trimString(form.nome.value) != nome) changes+="Alterou Nome De: "+nome+" Para: "+form.nome.value+"<br />";
				if(form.email.value != email) changes+="Alterou email De: "+email+" Para: "+form.email.value+"<br />";
				if(form.login.value != login) changes+="Alterou Login De: "+login+" Para: "+form.login.value+"<br />";
				if(form.senha.value != senha) changes+="Alterou Senha De: "+senha+" Para: "+form.senha.value+"<br />";
				//if(form.confSenha.value != pass) changes+="confSenha#";		
				active_saida = $GEBId("ativo").checked ? "Ativo" : "Inativo";
					
				if(active_saida != active)changes+="Alterou Ativo De: "+active+" Para: "+active_saida+"<br />";		
			}else{
				
				changes+="Inseriu o usuário: "+form.nome.value+" - nível "+nivel_saida+" em: "+area_saida+"<br />";		
			
			}
			//changes = changes.replace(/#*$/, "");
			form.chg.value = "";
			form.chg.value = changes;  
			//alert(changes);
			
			
		}
	}
	
	////FORM AREAADMIN//////
	
	if(trimString(form.name) == "areaAdmin"){	
	
		if(!form.area.value.match(/[a-zA-Z0-9]+/)){			
			alert("Preencha o nome da área");
			return false;
		}
		
		if(form.envia.value == "Atualizar"){		
			if(form.area.value != area) changes+="De: "+area+" - Para: "+form.area.value;
		}else{
			if(form.area.value != area) changes+="Criou a área: "+form.area.value;
		}
		
		form.chg.value = "";
		form.chg.value = changes; 		
	}	
	
	
	////FORM frPagsUsu//////
	
	if(trimString(form.name) == "frPagsUsu"){	
	
		if(form.nivelUsuario.options[form.nivelUsuario.options.selectedIndex].text.match(/Selecione/)){			
			alert("Selecione área e função");
			return false;
		}
		//if(form.area.value != area) changes+="De: "+area+" - Para: "+form.area.value;		
		//form.chg.value = changes; 		
	}	
	
	
	////FORM FUNC_P_AREA//////
	
	if(trimString(form.name) == "func_p_area"){	
		var area_change = 0;
		var func_change = 0;
		var area_saida = form.area.options[form.area.options.selectedIndex].text;
		var func_saida = form.tipo.value;
			
			if(area_saida != area) area_change = 1;		
			if(form.tipo.value != func) func_change = 1;
			
		if(area_saida == "Selecione a área" || !func_saida.match(/[a-zA-Z0-9]+/)){			
			alert("Selecione a área e/ou preencha o nível");
			return false;
		}
		
		if(area == "Selecione a área"){			
			changes+="Criou o nível "+func_saida+" na área "+area_saida;				
		}else{
			//1-0
			if(area_change && !func_change){				
				changes+="Retirou o nível "+func+" da área "+area+" e colocou em "+area_saida;				
			}	
			
			//0-1
			if(!area_change && func_change){				
			changes+="Alterou o nível "+func+" em "+area+" para "+func_saida;			
			}		
			
			//1-1
			if(area_change && func_change){				
			changes+="Retirou o nível "+func+" da área "+area+" e criou o nível "+func_saida+" em "+area_saida;				
			}			
		}	
		
		form.chg.value = "";
		form.chg.value = changes;
		
	}
	
	
	////FORM Comuna//////
	
	if(trimString(form.name) == "Comuna"){	
	
		var msg = "";
		
		var msgObrigatorio = "Campos obrigatórios: \n******************************** \n\n";
		if(document.forms[0].nome.value == "") {
			msg += "* Nome\n";
		}

		if(document.forms[0].desc.value == "") {
			msg += "* Descrição\n";
		}
		
		if(msg!="") {
			alert(msgObrigatorio+msg);
			return false;
		
		} else {
		
			
			//var pais_saida = form.pais.options[form.pais.options.selectedIndex].text;
			//var idioma_saida = form.idioma.options[form.idioma.options.selectedIndex].text;
			
			if(form.envia.value == "Atualizar"){
		
			if(trimString(form.nome.value) != nome) changes+="Alterou Nome De: "+nome+" Para: "+form.nome.value+"<br />";
			//if(pais_saida != pais) changes+="Alterou País De: "+pais+" Para: "+pais_saida+"<br />";
			//if(idioma_saida != idioma) changes+="Alterou Idioma De: "+idioma+" Para: "+idioma_saida+"<br />";
			
			if(form.desc.value != desc) changes+="Alterou Descrição De: "+desc+" Para: "+form.desc.value+"<br />";
			
			//if(form.confSenha.value != pass) changes+="confSenha#";		
			destaque_saida = $GEBId("destaque").checked ? "Ativou Destaque" : "Desativou Destaque";
			if(destaque_saida != destaque) changes+=destaque_saida;	
			}else{
				
				changes+="Criou a comunidade: "+form.nome.value+"<br />";	
				
			}
			//changes = changes.replace(/#*$/, "");
			form.chg.value = "";
			form.chg.value = changes; 
			
		}
		//alert("inconfere: "+form.chg.value);
	}	
	
	////FORM pesquisa//////
	
	if(trimString(form.name) == "frPesquisa"){
		
	
		var msg = "";
		
		var msgObrigatorio = "Campos obrigatórios: \n******************************** \n\n";
		if(document.forms[0].titulo.value == "") {
			msg += "* Titulo\n";
		}
		if((document.forms[0].dtIniDia.value == "") || (document.forms[0].dtIniMes.value == "") || (document.forms[0].dtIniAno.value == "")){
			msg += "* Data Início\n";
		}
		if((document.forms[0].dtFimDia.value == "") || (document.forms[0].dtFimMes.value == "") || (document.forms[0].dtFimAno.value == "")){
			msg += "* Data Fim\n";
		}
		if(document.forms[0].ativo.value == "") {
			msg += "* Ativo\n";
		}
		if(document.forms[0].publicacao.value == "") {
			msg += "* Publicação\n";
		}
		
		ii = 0;	
		for(var i=1;i<=5;i++) {
			if(document.forms[0]["opc"+i].value=="") {
				ii++;
			}
		}
		if(ii>3) {
			msg += "* Pelo menos dois campos de opções tem que ser preenchidos\n";
		}
	
		
		if(msg!="") {
			alert(msgObrigatorio+msg);
			return false;
		} else {
					
		changes = "Criou Pesquisa: "+form.titulo.value;
			form.chg.value = "";
			form.chg.value = changes;  
		}
	}
	
	
	////FORM events//////
	if(trimString(form.name) == "Events"){
		
		
		var msg = "";
		
		var msgObrigatorio = "Campos obrigatórios: \n\n ******************************** \n";
		if(document.forms[0].titulo.value == "") {
			msg += "* Título\n";
		}
		if(document.forms[0].tipo.value == "") {
			msg += "* Título\n";
		}
		if(document.forms[0].press.value == "") {
			msg += "* Press Release\n";
		}
		if(document.forms[0].descricao.value == "") {
			msg += "* Descrição\n";
		}	
		if((document.forms[0].dtDia.value == "") || (document.forms[0].dtMes.value == "") || (document.forms[0].dtAno.value == "")){
			msg += "* Data \n";
		}
		if(document.forms[0].sexo.value == "") {
			msg += "* Sexo\n";
		}
		if(document.forms[0].opcSexual.value == "") {
			msg += "* Opção Sexual\n";
		}
		if(document.forms[0].opcSexual.value == "") {
			msg += "* Opção Sexual\n";
		}
		if((document.forms[0].idadeEntreIni.value == "") || (document.forms[0].idadeEntreFim.value == "")){
			msg += "* Idade \n";
		}
		if(document.forms[0].ativo.value == "") {
			msg += "* Ativo\n";
		}
		
		if(msg!="") {
			alert(msgObrigatorio+msg);
			return false;
			
		} else {		
		
		nome_saida = trimString(form.titulo.value);
		tipo_saida = form.tipo.options[form.tipo.options.selectedIndex].text;
		press_saida = form.press.value;
		descri_saida = form.descricao.value;
		dia_saida = form.dtDia.options[form.dtDia.options.selectedIndex].text;
		mes_saida = form.dtMes.options[form.dtMes.options.selectedIndex].text;
		ano_saida = form.dtAno.options[form.dtAno.options.selectedIndex].text;
		hora_saida = form.hora.options[form.hora.options.selectedIndex].text;
		minu_saida = form.minuto.options[form.minuto.options.selectedIndex].text;
		preco_saida = form.preco.value;
		alvo_saida = form.sexo.options[form.sexo.options.selectedIndex].text;
		opsex_saida = form.opcSexual.options[form.opcSexual.options.selectedIndex].text;
		ageEntreIni_saida = form.idadeEntreIni.options[form.idadeEntreIni.options.selectedIndex].text;
		ageEntreFim_saida = form.idadeEntreFim.options[form.idadeEntreFim.options.selectedIndex].text;
		active_saida = form.ativo.options[form.ativo.options.selectedIndex].text;
		
		if(form.envia.value == "Atualizar"){
		
		if(nome_saida != nome) changes+="Alterou Nome De: "+nome+" Para: "+nome_saida+"<br />";
		if(tipo_saida != tipo) changes+="Alterou Tipo De: "+tipo+" Para: "+tipo_saida+"<br />";
		if(press_saida != press)changes+="Alterou Press De: "+press+" Para: "+press_saida+"<br />";
		if(descri_saida != descri)changes+="Alterou Descrição De: "+descri+" Para: "+descri_saida+"<br />";
		if(dia_saida != dia)changes+="Alterou Dia De: "+dia+" Para: "+dia_saida+"<br />";		
		if(mes_saida != mes)changes+="Alterou Mes De: "+mes+" Para: "+mes_saida+"<br />";
		if(ano_saida != ano)changes+="Alterou Ano De: "+ano+" Para: "+ano_saida+"<br />";
		if(hora_saida != hora)changes+="Alterou Hora De: "+hora+" Para: "+hora_saida+"<br />";
		if(minu_saida != minu)changes+="Alterou Minuto De: "+minu+" Para: "+minu_saida+"<br />";
		if(preco_saida != preco)changes+="Alterou Preço De: "+preco+" Para: "+preco_saida+"<br />";
		if(alvo_saida != alvo)changes+="Alterou Alvo De: "+alvo+" Para: "+alvo_saida+"<br />";
		if(opsex_saida != opsex)changes+="Alterou Opção Sexual De: "+opsex+" Para: "+opsex_saida+"<br />";
		if(ageEntreIni_saida != ageEntreIni)changes+="Alterou Idade inicial De: "+ageEntreIni+" Para: "+ageEntreIni_saida+"<br />";
		
		if(ageEntreFim_saida != ageEntreFim)changes+="Alterou Idade final De: "+ageEntreFim+" Para: "+ageEntreFim_saida+"<br />";
		
		if(active_saida != active)changes+="Alterou Ativo De: "+active+" Para: "+active_saida+"<br />";
		}else{
			
			changes+="Inseriu o evento: "+form.titulo.value+"<br />";
		
		}
		form.chg.value = "";
		form.chg.value = changes; 
		
		}
	}
	
	
	////FORM Banner//////
	if(trimString(form.name) == "Banner"){
		
		
	var msg = "";
	
	var msgObrigatorio = "Campos obrigatórios: \n******************************** \n\n";
	if(document.forms[0].titulo.value == "") {
		msg += "* Título\n";
	}
	if(document.forms[0].arq.value == "") {
		msg += "* Arquivo\n";
	}
	if(document.forms[0].ativo.value == "") {
		msg += "* Status\n";
	}
	if(document.forms[0].oLink.value == "") {
		msg += "* Link\n";
	}

	
	if(msg!="") {
		alert(msgObrigatorio+msg);
		return false;
	} else {		
	
		
		nome_saida = trimString(form.titulo.value);

		dia_saida = form.dtIniDia.options[form.dtIniDia.options.selectedIndex].text;
		mes_saida = form.dtIniMes.options[form.dtIniMes.options.selectedIndex].text;
		ano_saida = form.dtIniAno.options[form.dtIniAno.options.selectedIndex].text;
		hora_saida = form.horaIniH.options[form.horaIniH.options.selectedIndex].text;
		minu_saida = form.horaIniM.options[form.horaIniM.options.selectedIndex].text;
		
		diaFim_saida = form.dtFimDia.options[form.dtFimDia.options.selectedIndex].text;
		mesFim_saida = form.dtFimMes.options[form.dtFimMes.options.selectedIndex].text;
		anoFim_saida = form.dtFimAno.options[form.dtFimAno.options.selectedIndex].text;
		horaFim_saida = form.horaFimH.options[form.horaFimH.options.selectedIndex].text;
		minuFim_saida = form.horaFimM.options[form.horaFimM.options.selectedIndex].text;
		
		linke_saida = form.oLink.value;
		active_saida = form.ativo.options[form.ativo.options.selectedIndex].text;
		
		if(form.envia.value == "Atualizar"){
		
		if(dia_saida != dia)changes+="Alterou Dia De: "+dia+" Para: "+dia_saida+"<br />";
		if(mes_saida != mes)changes+="Alterou Mes De: "+mes+" Para: "+mes_saida+"<br />";
		if(ano_saida != ano)changes+="Alterou Ano De: "+ano+" Para: "+ano_saida+"<br />";		
		if(hora_saida != hora)changes+="Alterou Hora De: "+hora+" Para: "+hora_saida+"<br />";
		if(minu_saida != minu)changes+="Alterou Minuto De: "+minu+" Para: "+minu_saida+"<br />";
		
		if(diaFim_saida != diaFim)changes+="Alterou Dia final De: "+diaFim+" Para: "+diaFim_saida+"<br />";
		if(mesFim_saida != mesFim)changes+="Alterou Mes final De: "+mesFim+" Para: "+mesFim_saida+"<br />";
		if(anoFim_saida != anoFim)changes+="Alterou Ano final De: "+anoFim+" Para: "+anoFim_saida+"<br />";
		if(horaFim_saida != horaFim)changes+="Alterou Hora final De: "+horaFim+" Para: "+horaFim_saida+"<br />";
		
		if(minuFim_saida != minuFim)changes+="Alterou Minuto final De: "+minuFim+" Para: "+minuFim_saida+"<br />";		
		
		
		if(mes_saida != mes)changes+="Alterou Mes De: "+mes+" Para: "+mes_saida+"<br />";
		if(ano_saida != ano)changes+="Alterou Ano De: "+ano+" Para: "+ano_saida+"<br />";		
		if(hora_saida != hora)changes+="Alterou Hora De: "+hora+" Para: "+hora_saida+"<br />";
		if(minu_saida != minu)changes+="Alterou Minuto De: "+minu+" Para: "+minu_saida+"<br />";
		
		if(linke_saida = linke)changes+="Alterou Link De: "+linke+" Para: "+linke_saida+"<br />";
									
		if(active_saida != active)changes+="Alterou Ativo De: "+active+" Para: "+active_saida+"<br />";
		}else{
		 
			changes+="Inseriu o banner: "+form.titulo.value+"<br />";
		
		}
		
		form.chg.value = "";
		form.chg.value = changes;
	}
		
	}
	
	
	if(trimString(form.name) == "Contamina"){
		
		vip = form.vip.checked ? "Sim" : "Não";
		
		if(form.tipo.value == "0") nome = form.nome.value;
		email = form.email.value;
		msg = form.mensagem.value;
		if(form.tipo.value == "0") changes += "Para: "+nome+"<br />";
		changes += "email: "+email+"<br />";
		changes += "Mensagem: "+msg+"<br />";
		changes += "Vip: "+vip+"<br />";
		
		form.chg.value = "";
		form.chg.value = changes; 
	}
	
	
	////FORM Entidades//////
	if(trimString(form.name) == "Entidades"){
		
		var msg = "";
	
		if(document.forms[0].estaId.value=="") {
			msg += "* Campo estado vazio;\n";
		}
		if(document.forms[0].cidaId.value=="") {
			msg += "* Campo cidade vazio;\n";
		}
		if(document.forms[0].tipoEntidade.value=="") {
			msg += "* Campo tipo entidade vazio;\n";
		}
		if(document.forms[0].nome.value=="") {
			msg += "* Campo nome vazio;\n";
		}
		if(document.forms[0].email.value == "") {
			msg += "* Campo e-mail vazio;\n";
		} else if(!isEmail(document.forms[0].email.value)) {
			msg += "* Campo e-mail inválido;\n";
		}
		if(document.forms[0].cep.value=="") {
			msg += "* Campo cep vazio;\n";
		}
		if(document.forms[0].telDDD.value=="") {
			msg += "* Campo DDD vazio;\n";
		}
		if(document.forms[0].tel.value=="") {
			msg += "* Campo telefone vazio;\n";
		}
		if(msg!="") {
			alert(msg);
			return false;
		
		} else {		
			
			
			tipo_saida = form.tipoEntidade.options[form.tipoEntidade.options.selectedIndex].text;
			my_cidade_saida = form.cidaId.options[form.cidaId.options.selectedIndex].text;
			my_estado_saida = form.estaId.options[form.estaId.options.selectedIndex].text;
			nome_saida = trimString(form.nome.value);
			email_saida = trimString(form.email.value);
			cep_saida = trimString(form.cep.value);
			ddd_saida = trimString(form.telDDD.value);
			tel_saida = trimString(form.tel.value);
			obs_saida = trimString(form.obs.value);
			
			if(form.envia.value == "Atualizar"){
			
			if(tipo_saida != tipo) changes+="Alterou Tipo De: "+tipo+" Para: "+tipo_saida+"<br />";
			if(my_cidade_saida != my_cidade) changes+="Alterou Cidade De: "+my_cidade+" Para: "+my_cidade_saida+"<br />";
			if(my_estado_saida != my_estado)changes+="Alterou Estado De: "+my_estado+" Para: "+my_estado_saida+"<br />";
			if(nome_saida != nome)changes+="Alterou Nome De: "+nome+" Para: "+nome_saida+"<br />";
			
			if(email_saida != email)changes+="Alterou email De: "+email+" Para: "+email_saida+"<br />";		
			if(cep_saida != cep)changes+="Alterou CEP De: "+cep+" Para: "+cep_saida+"<br />";
			if(ddd_saida != ddd)changes+="Alterou DDD De: "+ddd+" Para: "+ddd_saida+"<br />";
			
			if(tel_saida != tel)changes+="Alterou Tel De: "+tel+" Para: "+tel_saida+"<br />";
			if(obs_saida != obs)changes+="Alterou Obs De: "+obs+"<br />Para: "+obs_saida+"<br />";
			
			}else{
				
				changes+="Inseriu a entidade: "+form.nome.value+"<br />";	
				
			}
			form.chg.value = "";
			form.chg.value = changes; 
			
		}
	}
	
	
	////FORM usuEntidades//////
	if(trimString(form.name) == "usuEntidades"){
		
		
		nome_saida = trimString(form.nome.value);
		email_saida = trimString(form.email.value);
		chave_saida = form.chave.value;
		active_saida = $GEBId("ativo").checked ? "Ativo" : "Inativo";
		
		if(form.envia.value == "Atualizar"){
		if(nome_saida != nome)changes+="Alterou Nome De: "+nome+" Para: "+nome_saida+"<br />";
		if(email_saida != email)changes+="Alterou email De: "+email+" Para: "+email_saida+"<br />";
		if(chave_saida != chave)changes+="Alterou Chave De: "+chave+" Para: "+chave_saida+"<br />";
		if(active_saida != active) changes+="Alterou Ativo De: "+active+" Para: "+active_saida+"<br />";
		}else{
			
			changes+="Inseriu o usuário de entidade: "+form.nome.value+"<br />";	
			
		}
		form.chg.value = "";
		form.chg.value = changes; 
		
	}
	
	return true;
}



//cria a lista de parametros do form
/*function createparams(form){
//if($GEBId('userfile')) 
var str = "";
var tags = $GEBTn('input',form);
var tarea = $GEBTn('textarea',form);
var slect = $GEBTn('select',form);
	for(d=0;d < tags.length;d++){
	if(tags[d].type == 'hidden' || tags[d].type == 'text' || tags[d].id == 'foto' || tags[d].type == 'file'  || (tags[d].type == 'radio' && tags[d].checked)) str+=tags[d].id+"="+tags[d].value+"&"; 
	}
	
	for(d=0;d < tarea.length;d++){
	str+=tarea[d].id+"="+tarea[d].value+"&"; 
	}
	
	
er=/^indc(\d{1,2})*_gmatu/;
er2=/^expu(\d{1,2})*_gmatu/;

	for(d=0;d < slect.length;d++){
		var hu = slect[d].id;
		if(!er.test(hu) && !er2.test(hu)){		
		str+=hu+"="+slect[d].value+"&"; 
		}
	}
	
	
	str = str.replace(/\&$/,"");
		//alert("popde "+str);	
	//return false;
form.params.value = str;
//alert("formParams: "+form.params.value);
}




function disonoff(oDiv){ // NAO UTILIZADA AQUI
	var theex = $GEBId(oDiv);
	if(theex.style.display == "none") theex.style.display = "";
	else theex.style.display = "none";
}

function offslash(){//caso haja, retira a barra do fim do endereço digitado // NAO UTILIZADA AQUI
	var thedir = $GEBId("dir_xml");
	c = thedir.value;
	var barra = c.charAt(c.length - 1);
		if(barra == "/"){		
		c = c.replace(/\//,"");	
		thedir.value = c;	
		}
}

*/

function trimString (str) {
  return str.replace(/^\s+/g, '').replace(/\s+$/g, ''); 
} 


/*function foc(){
	document.form1.addr.focus();
}

function foclog(){
	document.f1.login.focus();
}

function mk_importObj(formItem){
		myrssfeed_obj = new importXML(formItem);	//rssclass.js
		return true;
}


var firstTitle = 0;
function mkBold(){
var titels = $GEBTn('td');
$GEBId('imglink').innerHTML=myrssfeed_obj.theImgLink; // COLOCA A IMG DO CANAL NO TITULO
	for(h=0;h < titels.length; h++){
		if(titels[h].firstChild && (titels[h].firstChild.nodeValue == "Channel" || titels[h].firstChild && titels[h].firstChild.nodeValue == "Title")){
		firstTitle++;
			if(firstTitle == 1){
			titels[h].nextSibling.style.height="40px";
			titels[h].nextSibling.style.verticalAlign="top";
			titels[h].nextSibling.style.color="#f9f9f9";
			titels[h].nextSibling.style.backgroundColor="#006699";
			titels[h].nextSibling.style.fontWeight="bold";
			titels[h].nextSibling.style.fontSize="13px";
			}else{
			titels[h].nextSibling.style.fontWeight="bold";
			titels[h].nextSibling.style.fontSize="12px";
			}
		}
	}
	firstTitle = 0;
}


function setMkBold(){	// chama a func que set all titles bold and bigger
	setTimeout("mkBold()",100);
}
*/

function $GEBId(id,doc) { return (doc || document).getElementById(id); }

function $GEBTn(nome,doc) { return (doc || document).getElementsByTagName(nome); }