function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);


function carregaFoto(file){
	getObj("img_foto").src = file.value;
	document.sem_foto = false;
}

function atualizaDadosFoto(foto,dir){
	getObj("imagem").value = foto;
	getObj("img_foto").src = dir + "/" + foto;
	getObj("foto_msg").innerHTML = "<b style='color:blue'>Foto salva com sucesso!</b>";	
	document.precisa_salvar = true;
}

function salvaPerfil(){
	var frm = document.frm_perfil;
	if(frm.mudou_senha.value>0)
		if(frm.senha.value != frm.senha2.value){
			alert("As senhas não conferem!");
			frm.senha.focus();
			return;
		}	
	getObj("foto_msg").innerHTML = "<b style='color:red'>Aguarde, salvando foto...</b>";	
	frm.submit();	
}

function salvaComunidade(){
	document.frm_comun.submit();	
}

//-------------------------------------------------
//DATA:		07/05/2003
//PROGR.:	Marcelo S. Pereira
//FUNÇÃO:	arquivo generico de funções JavaScript
//-------------------------------------------------

//ADIÇÃO DE METODO AO OBJETO STRING
String.prototype.trim = function(){
	var er = /^(\s)*(.*?)(\s)*$/;  
	return this.toString().replace(er,"$2");
}

//VARIÁVEL QUE REFERENCIA A WINDOW ABERTA PELA FUNÇÃO openWin()
var objWin = null;

// ABRE JANELAS POPUP 
// url, largura, altura, scroll e name(target)
function openWin(page,w,h,s,name){	
	if(!w)w = 640; if(!h)h = 480;
	if(s)w += 20; if(!name)name = "";
	window.status = "AGUARDE, ABRINDO JANELA...";
	var x = (window.screen.availWidth - w ) / 2;
	var y = (window.screen.availHeight - h ) / 2;		
	objWin = window.open(page,name,"height="+h+",width="+w+",top="+y+",left="+x+(s ? ",scrollbars":""));
	window.status = "";
}

//FUNÇÃO QUE RETORNA A REFERENCIA AO OBJETO CONF. ID
//id: identificação do objeto
function getObj(id){
	return (document.getElementById) ? document.getElementById(id) : document.all[id];
}

//FUNÇÃO QUE CRIA UM COOKIE
//nome: nome do cookie, valor: valor atribuido ao cookie, dtexp: data de expiração DD/MM/AAAA
//dom: dominio de atuação, path: caminho de validação
function setCookie(nome, valor, dtexp){
	document.cookie = nome + "=" + escape(valor) + "; expires=" + escape(dtexp);
}

//FUNÇÃO QUE RETORNA O VALOR DE UM COOKIE
//nome: nome do cookie
function getCookie(nome){
	var v = document.cookie.split("; ");
	for(i=0;i<v.length;i++){
		v[i] = v[i].split("=");
 		if(v[i][0]==nome)
			return v[i][1];
	}
	return false;
}

// VALIDA ENDEREÇO DE E-MAIL
function isEmail(email){
	var er = /^[\w\d][\w\d\_\.\-]*[\w\d]@[\w\d][\w\d\-]+[\w\d](\.[\w\d\-\_]+)*\.[a-z]{2,3}$/i;
	return email.match(er);
}

//FUNÇÃO QUE VALIDA FORMATO DE IMAGENS
//obj: referência ao input(file) da imagem
function isImage(obj){
	var er = /^.+\\[a-z0-9_]+\.(jpe?g|gif|png|swf)$/i;
	if(!obj.value.match(er) && obj.value.length>3){
		var msg = "ATENÇÃO!\n\nO nome do arquivo de imagem NÃO deve conter espaços NEM caracteres acentuados,\n";
		msg += "DEVE também estar em formato JPG, GIF, PNG ou SWF. Se alguma dessas regras não forem\n";
		msg += "seguidas poderão ocorrer sérios problemas de acesso e performance em alguns navegadores."
		alert(msg);	obj.focus(); return false;
	}else
		return true;
}

//FUNÇÃO QUE VALIDA FORMATO DE NOMES DE ARQUIVOS
//obj: referência ao input(file) da imagem
function isFile(obj){
	var er = /^.+\\[a-z0-9_]+\.[a-z0-9]{3}$/i;
	if(!obj.value.match(er) && obj.value.length>3){
		var msg = "ATENÇÃO!\n\nO nome do arquivo NÃO deve conter espaços NEM caracteres especiais ou acentuados,\n";
		msg += "DEVE ser formado por LETRAS (a-z) NÃO acentuadas e/ou NÚMEROS (0-9).\nA mesma regra ";
		msg += "vale para a extensão.\n\nExemplo: \n\t \"Nome Inválido.txt\" ==> \"nome_correto.txt\"";
		alert(msg);	obj.focus(); return false;
	}else
		return true;
}

//FUNÇÃO PARA VALIDAÇÃO DE DATAS
//data: Data de teste (dd/mm/yyyy ou dd/mm/yyyy hh:mm)
function isDate(data){
	if(data instanceof Date)return true;
	var adt = data.replace(/[\s\:\/\.\-]/g,"-").split("-");
	if(adt.length>3){
		var odt = new Date(adt[2],--adt[1],adt[0],adt[3],adt[4]);
		var hr = (odt.getHours()==adt[3] && odt.getMinutes()==adt[4]);
	}else 
		var odt = new Date(adt[2],--adt[1],adt[0]);		
	var dt = (odt.getFullYear()==adt[2] && odt.getMonth()==adt[1] && odt.getDate()==adt[0]);
	return (adt.length>3) ? dt && hr : dt;
}

//FUNÇÃO QUE CONVERTA UMA DATA EM MILISEGUNDOS PARA FINS DE COMPARAÇÃO
function getMsec(data){
	if(!isDate(data))return 0;
	if(data instanceof Date)return data.valueOf();
	var dt = data.replace(/[\/\.\-]/g,"-").split("-");
	return (new Date(dt[2],--dt[1],dt[0]).valueOf());	
}
//FUNÇÃO PARA EXIBIR UMA IMAGEM NUMA POPUP CENTRALIZADA E EM SEU TAMANHO NATURAL
//E SE PASSAR DE 800X600 GERA SCROLLBARS
function openImg(img_url,title){
	document.MyImg = new Image();
	document.MyImg.onload = function(){
		var img = document.MyImg.src;
		var w = document.MyImg.width, h = document.MyImg.height;
		var s = (h > 525 || w > 700) ? ",scrollbars,resizable" : "";
		w = (w > 700) ? 700 : w; h = (h > 525) ? 525 : h; if(title) h += 40;
		var x = (window.screen.availWidth - w) / 2, y = (window.screen.availHeight - h) / 2;
		var win = window.open("","imagens","left="+x+",top="+y+",width="+w+",height="+h+s);
	    win.document.open();
	    win.document.write("<html><head><title>Imagens - "+title+"</title></head>");
		win.document.write("<body bgcolor='white' style='margin:0px'><center>");
		if(title)win.document.write("<p style='font:bold 9pt verdana'><br>"+title+"");
	    win.document.write("<a href='javascript:window.close()'><img src='"+img+"' border='0'></a>");
	    win.document.write("</p></center></body></html>\n");
	    win.document.close();
	}
	document.MyImg.src = img_url;
}

//OBTEM AS DIMENSÕES DA IMAGEM E AS ATRIBUI AO value DO obj_param
function getImgSize(obj_img,obj_param){
	document.NewImg = new Image();
	document.NewImg.onload = function(){
		obj_param.value = document.NewImg.width+"|";
		obj_param.value += document.NewImg.height;
	};
	document.NewImg.src = obj_img.value;
}

//formata um campo data com "/" entre dd, mm e aaaa
function formatDate(obj){
	if(obj.value.match(/[^0-9]$/))
		obj.value = obj.value.substr(0,obj.value.length-1);
	if(!(obj.len) || obj.value.length > obj.len)
		switch(obj.value.length){
			case 2: case 5:
				obj.value += "/"; break;
		}
	obj.len = obj.value.length;
}


/*********************************************
					AJAX
*********************************************/
var http = null;

if(window.XMLHttpRequest)
	http = new XMLHttpRequest();
else if (window.ActiveXObject)
	http = new ActiveXObject("Msxml2.XMLHTTP");
if(!http)
	http = new ActiveXObject("Microsoft.XMLHTTP");


//obtem os dados recuperados no destino da Url e passa para o objeto
function execUrl(url){
	if(http){
		http.open("GET", url, true);
		http.onreadystatechange = function(){
			if (http.readyState == 4 && http.status == 200) {
				eval(http.responseText);				
			}	
		};
		http.send(null);
	}
}




