//VALIDA EMAIL
function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("O endereço de email "+emailStr+" não está correto.")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	if (user.match(userPat)==null) {
		// user is not valid
		alert("O nome do usuário do e-mail "+emailStr+" não parece ser válido.")
		return false
	}
	
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("O número do IP não é válido no e-mai "+emailStr+" !")
			return false
			}
		}
		return true
	}
	
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("O domínio do e-mail "+emailStr+" não parece estar correto.")
		return false
	}
	
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
	   alert("O endereço precisa terminar com 3 letras do domínio ou 2 letras do país.")
	   return false
	}
	
	if (len<2) {
	   var errStr="O endereço "+emailStr+" não contém o domínio!"
	   alert(errStr)
	   return false
	}
	
	return true;
}

//VOLTA PARA A PÁGINA ANTERIOR
function volta(){
		window.history.go(-1);
}

//ABRE POPUP DA FOTO - REQUISITO: ARQUIVO FOTO.PHP
function abreFoto(album, imagem, altu, larg, rolagem){
	window.open("foto.php?album="+album+"&imagem="+imagem+"", "Foto", "width="+larg+",height="+altu+",top=90,left=90,menubar=no,location=no,resizable=no,scrollbars="+rolagem+",status=no");
}

// CORRIGE A EXIBIÇÃO DE PNGS TRANSPARENTE NO IE 5.5 & 6.
function correctPNG(){
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
function redim(){
	alturatotal = document.getElementById('cabecalho_').offsetHeight;//tamanho do cabeçalho
	alturatotal += document.getElementById('cabecalho-esquerda_').offsetHeight;//tamanho do cabeçalho do frame de conteudo
	//tamanho do maior frame da área central da home (estes são os frames que variam de tamanho)
	x = 0;
	y = 0;
	maior = 0;
	if(	document.getElementById('conteudo_').offsetHeight >= document.getElementById('destaques_').offsetHeight){
		x = document.getElementById('conteudo_').offsetHeight;
	}else{
		x = document.getElementById('destaques_').offsetHeight;
	}
	if(document.getElementById('conteudo_').offsetHeight >= document.getElementById('menu_').offsetHeight){
		y = document.getElementById('conteudo_').offsetHeight;
	}else{
		y = document.getElementById('menu_').offsetHeight;
	}
	if(x>=y){
		maior = x;
	}else{
		maior = y;
	}
	alturatotal += maior;
	document.getElementById('patrocinadores_').style.top=""+alturatotal+"px";//seta a posição da barra de patrocinios
	alturatotal += document.getElementById('patrocinadores_').offsetHeight;//tamanho do frame de patrocinadores
	document.getElementById('rodape_').style.top=""+alturatotal+"px";//seta posicao do rodape
	alturatotal += document.getElementById('rodape_').offsetHeight;//tamanho do rodape
	document.getElementById('master_frame').style.height=""+alturatotal+"px";
}

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_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_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];}
}

//exibe a div especificada por "target"
function show(target) {
	if(div=document.getElementById(target)){
		div.style.display = 'inline';
		//Ganbiarra para forçar o reflow da página
		document.body.className += '';
	}
}

//exibe a div especificada por "target" com display mode definido pelo usuario
function showAs(target, mode) {
	if(div=document.getElementById(target)){
		div.style.display = mode;
		//Ganbiarra para forçar o reflow da página
		document.body.className += '';
	}
}

//exibe o frame especificado por "target" e carrega o conteudo de uma página externa
function showFrame(target, content) {
	if(frame=document.getElementById(target)){
		frame.style.display = 'none';
		frame.src = content;
		frame.style.display = 'inline';
		//Ganbiarra para forçar o reflow da página
		document.body.className += '';
	}
}

//oculta a div especificada por "target"
function hide(target) {
	if(div=document.getElementById(target)){
		div.style.display = 'none';
		//Ganbiarra para forçar o reflow da página
		document.body.className += '';
	}
}
//oculta a div especificada por "target"
function showhide(target) {
	if(div=document.getElementById(target)){
		if(div.style.display == 'none'){
			div.style.display = 'inline';
			//Ganbiarra para forçar o reflow da página
			document.body.className += '';
		}else{
			div.style.display = 'none';
			//Ganbiarra para forçar o reflow da página
			document.body.className += '';
		}
	}
}
//oculta a div especificada por "target"
function showhideAs(target, mode) {
	if(div=document.getElementById(target)){
		if(div.style.display == 'none'){
			div.style.display = mode;
			//Ganbiarra para forçar o reflow da página
			document.body.className += '';
		}else{
			div.style.display = 'none';
			//Ganbiarra para forçar o reflow da página
			document.body.className += '';
		}
	}
}

function videoPlayer(idRecado){
	window.open("mural/videoPlayer.php?idRecado="+idRecado+"", "Video_Player", "width=425px,height=344px,top=90,left=90,menubar=no,location=no,resizable=no,scrollbars=no,status=no");
}
function setavatar(imagem){
	document.form_recado.avatar.value = imagem;
}

function requerido(campo){
	if(document.getElementById(campo).value == ""){
		alert("Campo de preenchimento obrigatório ("+campo+")")
		return false
	}
	return true
}




String.prototype.trim=function(){  //trim leading or trailing whitespace and extra spaces
	return this.replace(/^\s*/, "").replace(/\s*$/, "").replace(/\s{2,}/, " ");
}

function checkEmail(valor){
	if(valor==''){return true;}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){return (true);}
	return (false);
}

function checaCampos(form){  //verifica o preenchimento obrigatorios dos campos antes de enviá-los
	if(!form){return false;}
	var element,enviar=true;
	for(var i=0;i<form.elements.length;i++){
		element=form.elements[i];
		if(element.className.indexOf('required')>=0){  //campo requerido
			if(element.type.toUpperCase()=='CHECKBOX'){  //se for um checkbox
				checkboxes=document.getElementsByName(element.name);
				for(var c=0;c<checkboxes.length;c++){
					if(checkboxes[c].checked){break;}
				}
				if(c<checkboxes.length){continue;}
				alert('Favor selecione pelo menos uma das opções apresentadas.');
				element.focus();
				return false;
			}
			if(element.value.length<=0){  //nao preenchido
				if(element.type.toUpperCase().indexOf('SELECT')>=0){
					alert('Favor selecione pelo menos uma opção.');
				}else{
					alert('Favor preencha o campo corretamente');
				}
				element.focus();
				enviar=false;
				break;
			}
		}
		if(element.className.indexOf('email')>=0){  //campo tipo email
			if(!checkEmail(element.value.trim())){
				alert('Favor escreva um e-mail válido.');
				element.focus();
				enviar=false;
				break;
			}
		}
	}
	return enviar;
}

function gotoanchor(target){
	location.href = target;
}


//Faz a Layer label seguir o mouse
/*if (document.all){}
else document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=mouse;

function mouse(e) {
	if (navigator.appName == 'Netscape'){
		xcurs = e.pageX;
		ycurs = e.pageY;
	} else {
		xcurs = event.clientX;
		ycurs = event.clientY;
	}
	document.getElementById('label').style.left = (xcurs-85)+'px';
	document.getElementById('label').style.top = (ycurs-235)+'px';
}
window.attachEvent("onload", mouse);*/

window.attachEvent("onload", correctPNG);
//window.attachEvent("onload", redim);