//----------------------------
// Global ::::::::::::::::::::
//----------------------------
var pedido, winreq;
var destobj,destbox;
var navw,navh;
var bodystyle;
var reqdone = true;
var noti = 1;
var notimax = 2;
var ultmenu = '';
var parqtd = 13;
//--------------------------------------
// Evento redimensionamento do Navegador
this.onresize=function() {fullWin();centerWin();};
//---------------
// Colunas array:
// azulejos,cerâmicas,pastilhas,pedras,pisos,porcelanato,textura,interno,externo,piscinas,rejuntamento,sobreposição,especial.
var prodtab = new Array();
	//          |-Material----|-Utilizaçao|
	prodtab[0] ='1,1,0,0,1,0,0,1,0,0,0,0,0'; //'USO INTERNO - AC1';
	prodtab[1] ='1,1,0,0,1,0,0,1,1,1,0,0,0'; //'USO EXTERNO - AC2';
	prodtab[2] ='0,0,0,1,0,0,0,1,1,0,0,0,0'; //'ARDÓSIA E PEDRAS RÚSTICAS';
	prodtab[3] ='1,1,0,0,1,1,0,1,1,1,0,1,0'; //'SUPERLIGA - AC3';
	prodtab[4] ='1,1,0,0,1,1,0,1,1,0,0,1,0'; //'SUPERLIGA - AC3 (6 horas)';
	prodtab[5] ='0,0,0,1,0,0,0,1,1,0,0,0,0'; //'MÁRMORES, GRANITOS E PEDRAS';
	prodtab[6] ='0,0,0,0,0,1,0,1,0,0,0,0,0'; //'PORCELANATO INTERNO';
	prodtab[7] ='0,0,0,0,0,1,0,1,1,0,0,0,0'; //'PORCELANATO EXTERNO';
	prodtab[8] ='0,0,1,0,0,0,0,1,1,1,0,0,0'; //'PASTILHAS';
	prodtab[9] ='1,1,0,1,1,1,0,1,1,1,1,0,0'; //'REJUNTAMENTO FLEXÍVEL';
	prodtab[10]='0,0,0,0,0,0,1,1,1,0,0,0,0'; //'TEXTURA';
	prodtab[11]='1,1,1,1,1,1,1,1,1,1,1,1,1'; //'LINHA ESPECIAL';
	prodtab[12]='1,1,1,1,1,1,0,1,1,1,1,0,1'; //'REJUNTE EPOXI';
	prodtab[13]='1,1,0,0,0,1,0,1,0,0,0,1,1'; //'DrywallFix';
//----------------------------
// MM ::::::::::::::::::::::::
//----------------------------
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];}
}
//----------------------------
// Developer :::::::::::::::::
//----------------------------
// Coloca na página a string msg
//
function debug(msg) {
	var deb=document.getElementById('debug');
	deb.innerHTML+=msg+'<br \/>';
	return;
}
//-------------------------
// Retorna valor de propriedade 'prop' do elemento elem
// considerando recursividade para com seus encapsulantes.
function getAbsProp(elem,prop) {
	valor=0;
	while (elem != null) {
	valor+=elem['offset'+prop];
	elem=elem.offsetParent;
	}
	return valor;
}
function initAJAX() {

}
//-------------------------
// Obtém parâmetro passado na URL
function getUrlPar(name)
{
	var url, all, par, i, dub, res;
	url=window.location.href;
	all=url.indexOf('?');
	if (all==-1) return false;
	all=url.substr(all,999);
	par=all.indexOf('?'+name+'=');
	if (par==-1) par=all.indexOf('&'+name+'=');
	if (par==-1) return false;
	res='';
	all=all.substr(1,999);
	par=all.split('&');
	for (i=0;i<par.length;i++) {
		dub=par[i].split('=');
		if (name==dub[0]) {
			res=dub[1];
			break;
		}
	}
	if (res=='') {
		return false;
	} else {
		getWin(res,'wind','central');
	}
}
//----------------------------
// Input :::::::::::::::::::::
//----------------------------
function calcula() {
	// B6
	var clarg=makeNumber(document.getElementById('larg'));
	if (clarg<=0) {
		document.getElementById('larg').value="ERRO";
		return;
	}
	//D6
	var ccomp=makeNumber(document.getElementById('comp'));
	if (ccomp<=0) {
		document.getElementById('comp').value="ERRO";
		return;
	}
	//E6
	var cespe=makeNumber(document.getElementById('espe'));
	if (cespe<=0) {
		document.getElementById('espe').value="ERRO";
		return;
	}
	//G6
	//var cporc=document.getElementById('porc').checked;
	//B7
	var aatot=makeNumber(document.getElementById('atot'));
	if (aatot<=0) {
		document.getElementById('atot').value="ERRO";
		return;
	}
	//F7
	var aajun=makeNumber(document.getElementById('ajun'));
	if (aajun<=0) {
		document.getElementById('ajun').value="ERRO";
		return;
	}
	//F8
	var aexte=document.getElementById('exte').checked;
	//D10
	var qtdpc=aatot*10000/(clarg*ccomp);
	document.getElementById('qtdp').innerHTML=maskNumber(qtdpc.toFixed(2));
	//D11
	var cojun=qtdpc*((clarg/100)+(ccomp/100))+2*Math.sqrt(aatot);
	document.getElementById('comj').innerHTML=maskNumber(cojun.toFixed(2))+'m';
	//F11
	var aux1=cojun*(aajun/1000)*(cespe/1000);
	document.getElementById('aux1').value=aux1;
	//G11
	var aux2=((clarg*ccomp)<401)?1:1.5;
	document.getElementById('aux2').value=aux2;
	//D12
	var rcmi=aux1*700*1.907238838318;
	document.getElementById('rcmi').innerHTML=maskNumber(rcmi.toFixed(2));
	//F12
	var rsmi=Math.abs(rcmi/20+0.9);
	document.getElementById('rsmi').innerHTML=maskNumber(rsmi.toFixed(2));
	//A13
	document.getElementById('rtip').innerHTML=(aajun<4)?'Junta Fina':'';
	//D13
	var rcma=rcmi*1.2;
	document.getElementById('rcma').innerHTML=maskNumber(rcma.toFixed(2));
	//F13
	var rsma=Math.abs(rcma/20+0.9);
	document.getElementById('rsma').innerHTML=maskNumber(rsma.toFixed(2));
	//B14
	document.getElementById('comi').innerHTML=((clarg*ccomp)<401)?'Consumo m&iacute;nimo':'Consumo m&iacute;nimo + Tardoz';
	//D14
	var acmi=aatot*5*aux2;
	document.getElementById('acmi').innerHTML=maskNumber(acmi.toFixed(2));
	//F14
	var asmi=Math.abs(acmi/20+0.9);
	document.getElementById('asmi').innerHTML=maskNumber(asmi.toFixed(2));
	//A15
	document.getElementById('atip').innerHTML=(aexte)?'Flex&iacute;vel AC II':'colante';
	//B15
	document.getElementById('coma').innerHTML=((clarg*ccomp)<401)?'Consumo m&aacute;ximo':'Consumo m&aacute;ximo + Tardoz';
	//D15
	var acma=acmi*1.2;
	document.getElementById('acma').innerHTML=maskNumber(acma.toFixed(2));
	//F15
	var asma=Math.abs(acma/20+0.9);
	document.getElementById('asma').innerHTML=maskNumber(asma.toFixed(2));
	//A16
	if (aexte) {
		document.getElementById('txus').innerHTML='Usar Argamassa tipo AC II e Rejunte Flex&iacute;vel';
	} else {
		document.getElementById('txus').innerHTML='&nbsp;';
	}
	//G16
	//document.getElementById('sius').innerHTML=(cporc?'AC III':'');
	//A17
	document.getElementById('txas').innerHTML=((clarg*ccomp)>401)?'Pelas dimensões das peças informadas, é necessária a aplicação de dupla camada; isto é, aplicar também no verso das peças':'Assentamento convencional - movimentar as peças';
	//G17
	document.getElementById('sias').innerHTML=((clarg*ccomp)<900)?'':'ABNT';
}
// Permite somente dígitos numéricos
// Uso: OnKeyUp="numerico(this,event)"
function numerico(obj,e){
	var tecla, dec;
	var num='';
	var tammax = obj.maxLength;
	if (e) {evt = e} else {evt = event}
	tecla = evt.keyCode;
	if (!((tecla==8) || (!isNaN(tecla)))) { return false;}
	for (n=0;n<obj.value.length;n++) {
		dec=obj.value.charAt(n);
		if ( ((dec.charCodeAt(0)>47) && (dec.charCodeAt(0)<58)) ) {num+=dec};
	}
	obj.value=num;
}
function makeNumber(obj) {
	var aux='';
	var val=obj.value;
	var ret=new Number();
	for (i=0;i<val.length;i++) {
		if ( ((val.charCodeAt(i)>47) && (val.charCodeAt(i)<58)) || (val.charAt(i)==',') ) aux+=val.charAt(i);
	}
	var num= aux.split(',');
	if (num[0]=='') num[0]=0;
	if (num.length>1) {
		ret=Number(num[0]+'.'+num[1]);
	} else {
		ret=Number(num[0]);
	}
	return ret;
}
// Formata valor monetário
// Uso: onKeyUp="formataValor(this,event)"
function formataValor(obj,e) {
	var tecla, dec;
	var num='';
	var lz=false;
	var tammax = obj.maxLength;
	if (e) {evt = e} else {evt = event}
	tecla = evt.keyCode;
	if (!((tecla==8) || (!isNaN(tecla)))) { return false;}
	for (n=0;n<obj.value.length;n++) {
		dec=obj.value.charAt(n);
		if (!lz) {
			if (dec=='0') {continue;} else {lz=true}
		}
		if ( ((dec.charCodeAt(0)>47) && (dec.charCodeAt(0)<58)) ) {num+=dec};
	}
	tam = num.length;
	if ( tam <= 2 ){
		obj.value = (tam==2?'0,'+num:(tam==1?'0,0'+num:num));
	} else {
		for (n=3;n<18;n+=3) {
			if ( (tam >= n) && (tam <= (n+2)) ){
				obj.value=num.substr(0,tam-(n-1));
				dec=n;
				for (c=1;c<=(n/3);c++) {
					if (c==(n/3)) obj.value+=','
					else obj.value+='.';
					obj.value+=num.substr(tam-(dec-1),(c==(n/3)?tam:3));
					dec-=3;
				}
				break;
			}
		}
	}
	return true;
}
// Mascara um valor com formato monetário
function maskNumber(val) {
	var val=(Math.round(val*100))/100;
	var i, dec, buf='';
	val=val.toString();
	ndx=val.length-1;
	for (i=0;i<val.length;i++) {
		car=val.charAt(ndx);
		dec=!(buf.indexOf(',')<0);
		if (dec) {
			if ( (buf.length>3) && (((buf.length-2)%4)==0) ) buf='.'+buf;
		} else {
			if ( (buf.length>0) && (((buf.length+1)%4)==0) ) buf='.'+buf;
		}
		if (car=='.') {
			if (buf.length<2) {
				buf+=(buf.length<1)?('00'):('0');
			}
			buf=','+buf;
		} else { buf=car+buf; }
		ndx--;
	}
	var num= buf.split(',');
	if (num[0]=='') num[0]=0;
	if (num[0].substr(0,2)=='-.') {
		num[0]='-'+num[0].substr(2,999);
	}
	if (num.length>1) {
		ret=num[0]+','+num[1];
	} else {
		ret=num[0]+',00';
	}
	return ret;
}
function getCaretPos (ctrl) {
	var caretPos = 0;
	// IE Support
	if (document.selection) {
		ctrl.focus ();
		var sel = document.selection.createRange();
		var selLength = document.selection.createRange().text.length;
		sel.moveStart ('character', -ctrl.value.length);
		caretPos = sel.text.length - selLength;
	}
	// Firefox support
	else if (ctrl.selectionStart || ctrl.selectionStart == '0')
		caretPos = ctrl.selectionStart;
return (caretPos);
}
function setCaretPos(ctrl, pos) {
	// IE Support
	if (document.selection) {
		// Set focus on the element
		ctrl.focus ();
		// Create empty selection range
		var sel = document.selection.createRange ();
		// Move selection start and end to 0 position
		sel.moveStart ('character', -ctrl.value.length);
		// Move selection start and end to desired position
		sel.moveStart ('character', pos);
		sel.moveEnd ('character', 0);
		sel.select ();
	}
	// Firefox support
	else if (ctrl.selectionStart || ctrl.selectionStart == '0') {
		ctrl.selectionStart = pos;
		ctrl.selectionEnd = pos;
		ctrl.focus ();
	}
}
//----------------------------
// Notícias ::::::::::::::::::
//----------------------------
// Envia pedido de notícia (ajax)
function getFile(arquivo) {
	// Coloca conexão AJAX no objeto global pedido
	if (navigator.appName == 'Microsoft Internet Explorer') {
		pedido = new ActiveXObject('Microsoft.XMLHTTP');
	} else {
		pedido = new XMLHttpRequest();
	}
	reqdone=false;
	pedido.onreadystatechange=recebeNovi;
	// false não funciona no Firefox
	var d=new Date();
	arquivo=arquivo+'?'+d.getTime();
	pedido.open('GET',arquivo,true);
	pedido.send(null);
}
//-------------------------
// Recebe notícia (ajax)
function recebeNovi() {
	document.getElementById('g'+noti).style.width=(pedido.readyState)*40+'px';
	if (pedido.readyState==4) {
		if (pedido.status==200) {
			var aux=pedido.responseText.split('|');
			var qual=aux.shift();
			document.getElementById('noticia_'+qual).innerHTML=aux[0];
			if (noti<notimax) {
				noti++;
				var d=new Date();
				getFile('noticia0'+noti+'.txt');
			} else {
				reqdone=true
			}
		} else {
			document.getElementById('noticia_0'+noti).innerHTML='&nbsp;&nbsp;Falha no carregamento.';
		}
	}
}
//----------------------------
// Carrega página ::::::::::::
//----------------------------
// Envia pedido de página (ajax)
function getPage(page,item) {
	try {
		var x=pedido.status;
	} catch(e) {
		return;
	}
	pedido.onreadystatechange = function () {};
	var browser = navigator.appName;
	// Coloca objeto na variável global http
	if (browser == 'Microsoft Internet Explorer') {
		pedido = new ActiveXObject('Microsoft.XMLHTTP');
	} else {
		pedido = new XMLHttpRequest();
	}
	pedido.onreadystatechange=recebePage;
	var d=new Date();
	page=page+'?'+d.getTime();
	pedido.open('GET',page,true);
	pedido.send(null);
	document.getElementById('page').innerHTML='&nbsp;';
	document.getElementById('ldpg').style.display='';
	document.getElementById('pg').innerHTML='';
	document.getElementById('pg').style.backgroundColor='#003388';
	//if (item.length>0)
	setMenu(item);
}
//-------------------------
// Recebe página (ajax)
function recebePage() {
	document.getElementById('pg').style.width=(pedido.readyState)*100+'px';
	if (pedido.readyState==4) {
		if (pedido.status==200) {
			document.getElementById('page').innerHTML=pedido.responseText;
			document.getElementById('ldpg').style.display='none';
		} else {
			document.getElementById('pg').style.backgroundColor='#c00000';
			document.getElementById('pg').innerHTML='&nbsp;&nbsp;Falha no carregamento.';
			getPage('pageman.html',ultmenu);
		}
	}
}
//----------------------------
// Overlay :::::::::::::::::::
//----------------------------
// Envia pedido de módulo (ajax)
function getWin(page,item,box) {
	var browser = navigator.appName;
	// Coloca objeto na variável global winreq
	if (browser == 'Microsoft Internet Explorer') {
		winreq = new ActiveXObject('Microsoft.XMLHTTP');
	} else {
		winreq = new XMLHttpRequest();
	}
	winreq.onreadystatechange=showWin;
	document.getElementById(item).style.visibility='visible';
	var d=new Date();
	page=page+'?'+d.getTime();
	winreq.open('GET',page,true);
	winreq.send(null);
	document.getElementById(box).innerHTML='<div id="ldwi" class="wisp">&nbsp;Carregando...<div align="left" class="gaugewin"><div id="wi" class="loaderwin"><\/div><\/div><\/div>';
	document.getElementById(item).style.left=0+'px';
	document.getElementById(item).style.top=0+'px';
	document.getElementById('wi').innerHTML='';
	document.getElementById('wi').style.backgroundColor='#003388';
	destobj=item;
	destbox=box;
	fullWin();
}
//-------------------------
// Recebe módulo (ajax)
function showWin() {
	if (winreq.readyState==4) {
		if (winreq.status==200) {
			document.getElementById(destbox).innerHTML=winreq.responseText;
			centerWin();
			bodystyle=document.body.style.overflow;
			document.body.style.overflow='hidden';
			//if (document.getElementById('nome'))
			//document.activeElement=document.getElementById('nome');//.focus();
		} else {
			centerWin();
			document.getElementById('wi').style.backgroundColor='#c00000';
			document.getElementById('wi').innerHTML='&nbsp;&nbsp;Falha no carregamento.';
		}
	} else {
		if (document.getElementById('wi')) document.getElementById('wi').style.width=(winreq.readyState)*40+'px';
	}
}
//-------------------------
// Apaga módulo
function hideWin() {
	document.getElementById(destobj).style.visibility='hidden';
	document.getElementById(destbox).innerHTML='';
	document.body.style.overflow=bodystyle;
	destobj=null;
	destbox=null;
}
//-------------------------
// Redimensiona módulo na tela
function fullWin() {
	if (destobj!=null) {
		getNavSize();
		document.getElementById(destobj).style.width=(navw-1)+'px';
		document.getElementById(destobj).style.height=(navh-1)+'px';
	}
}
//-------------------------
// Centraliza módulo na tela
function centerWin() {
	if (destobj!=null) {
		var vid=document.getElementById(destobj).offsetHeight;
		var qua=document.getElementById(destbox).offsetHeight;
		var h=(vid-qua)/2+'px';
		document.getElementById(destbox).style.marginTop=h;
		document.getElementById(destbox).style.marginBottom=h;
	}
}
//----------------------------
// Controla Menu :::::::::::::
//----------------------------
// Ajusta status do menu
function setMenu(item) {
	var obj;
	if (ultmenu!='') {
		obj=document.getElementById(ultmenu);
		obj.onmouseout=MM_swapImgRestore;
		document.getElementById(ultmenu).src='images/'+ultmenu+'.jpg';
	}
	if (item!='') {
		obj=document.getElementById(item);
		obj.onmouseout='';
		document.getElementById(item).src='images/'+item+'x.jpg';
	}
	ultmenu=item;
}
//----------------------------
// Trata menu de imagem
// causa: image map bug no MSIE
function naveg(par) {
	if (par=='i') document.location='index.html';
	if (par=='c') getPage('pageopo.html','');
	if (par=='m') getWin('ajmail.html','wind','central');
}
//----------------------------
// Pesquisa ::::::::::::::::::
//----------------------------
// Limpa pesquisa
function parClear() {
	for (var i=0;i<parqtd;i++) {
		document.getElementById('chk'+i).checked=false;
	}
	parGetit();
}
//-------------------------
// Seleciona material
function parGetMat() {
	//for (var i=7;i<parqtd;i++) document.getElementById('chk'+i).checked=false;
	parGetit();
}
//-------------------------
// Seleciona utilização
function parGetUti() {
	//for (var i=0;i<7;i++) document.getElementById('chk'+i).checked=false;
	parGetit();
}
//-------------------------
// Pesquisa produtos
function parGetit() {
	var pp; // ponteiro produto
	var proqtd=prodtab.length; // qtde. de produtos
	var pa; // ponteiro atributo
	var par=''; // atributos selecionados
	var qtd=0; // qtde. de atributos selecionados
	var bp;
	var ok;
	for (var i=0;i<parqtd;i++) {
		par+=(i==0)?'':',';
		bp=document.getElementById('chk'+i).checked;
		par+=bp?'1':'0';
		qtd+=bp?1:0;
		if (bp=='1') ok=true;
	}
	if (qtd==0) {
		for (pp=0;pp<proqtd;pp++) document.getElementById("prod"+pp).style.display='';
		return; // sem parâmetro selecionado
	}
	var as=par.split(',');
	for (pp=0;pp<prodtab.length;pp++) {
		var ap=prodtab[pp].split(',');
		ok=0
		for (pa=0;pa<parqtd;pa++) ok+=((as[pa]=='1')&&(ap[pa]=='1'))?1:0;
		document.getElementById("prod"+pp).style.display=(ok==qtd)?'':'none';
	}
}
//----------------------------
// Download ::::::::::::::::::
//----------------------------
// Exibe painel abrir / baixar
function downOptions(event) {
	var x=event.clientX;
	var y=event.clientY;
	document.getElementById('downarea').style.top=(y-15)+'px';
	document.getElementById('downarea').style.left=(x-25)+'px';
	document.getElementById('downarea').style.display='block';
}
//-----------------------------
// Troca imagens abrir e baixar
function selImage(event) {
	var y=event.clientY;
	var dy=document.getElementById('downarea').offsetTop;
	document.getElementById('downarea').src=((y-dy)<16)?document.MM_p[1].src:document.MM_p[2].src;
}
//--------------------------------
// Manda abrir ou baixar o arquivo
function selDownMode(event) {
	var y=event.clientY;
	var dy=document.getElementById('downarea').offsetTop;
	var mode=((y-dy)<16)?1:0;
	document.getElementById('downarea').style.display='none';
	document.location='files/downfiles.php?file=ab_produtos.pdf&mode='+mode;
}
//--------------------------------
// Oculta painel abrir / baixar
function downHide() {
	document.getElementById('downarea').style.display='none';
}
//--------------------------------
// Tela ::::::::::::::::::::::::::
//--------------------------------
// Obtém dimensões da tela
function getNavSize() {
	var w=0,h=0;
	if( typeof( window.innerWidth ) == 'number' ) {
		// Não é MSIE
		w=window.innerWidth;
		h=window.innerHeight;
	} else {
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//MSIE 6+ standard mode
			w=document.documentElement.clientWidth;
			h=document.documentElement.clientHeight;
		} else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				w=document.body.clientWidth;
				h=document.body.clientHeight;
			}
		}
	}
	navw=w;
	navh=h;
}
//--------------------------------
// Validações ::::::::::::::::::::
//--------------------------------
// Validação do form
function valida(elem) {
	var obj=new Object();
	var msg='';
	// nome
	obj=document.getElementById('nome');
	if (taVazio(obj.value)) {
		erro=obj;
		msg='O campo <b>Nome<\/b> deve ser preenchido.';
		showValid(elem,msg);
		return false;
	} else normal(obj);
	// e-mail
	obj=document.getElementById('email');
	if (!validaEmail(obj.value)) {
		erro=obj;
		msg='O campo <b>E-mail<\/b> &eacute; inv&aacute;lido.';
		showValid(elem,msg);
		return false;
	} else normal(obj);
	// assunto
	obj=document.getElementById('assunto');
	if (taVazio(obj.value)) {
		erro=obj;
		msg='O campo <b>Assunto<\/b> deve ser preenchido.';
		showValid(elem,msg);
		return false;
	} else normal(obj);
	// mensagem
	obj=document.getElementById('mensagem');
	if (taVazio(obj.value)) {
		erro=obj;
		msg='O campo <b>Mensagem<\/b> deve ser preenchido.';
		showValid(elem,msg);
		return false;
	} else normal(obj);
	return true;
}
//--------------------------------
// Verifica se o campo está vazio
function taVazio(txt){
	var pos,ndx=0;
	for (pos=0;pos<txt.length; pos++) {
		if (txt.charAt(pos)!=' ') ndx++;
	}
	return (ndx==0);
}
//--------------------------------
// Valida email.
function validaEmail(eml) {
	if (eml.length==0) return false;
	if (eml.length<6) return false;
	per='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@.-_';
	arb=0;
	tst='';
	for (ind=0;ind<eml.length;ind++) {
		tst=tst+eml.substring(ind,ind+1);
		if (per.indexOf(eml.substring(ind,ind+1))<0) return false;
		if (eml.charAt(ind)=='@') {
			arb++;
			if ((ind==(eml.length-1))||(ind==0)) return false;
		}
		if ((eml.charAt(ind)=='.')&&(ind==(eml.length-1))) return false;
		if ((eml.charAt(ind)=='.')&&((eml.charAt(ind-1)=='@')||(eml.charAt(ind+1)=='@'))) return false;
	}
	if ((arb>1)||(arb<1)) return false;
	if (eml.indexOf('.')<1) return false;
	return true;
}
//--------------------------------
// Recoloca borda normal
function normal(obj) {
	obj.style.border='1px solid #b0b0b0';
}
//--------------------------------
// Mostra mensagem de validação
function showValid(obj,msg) {
	//var pos=getAbsProp(obj,'Top')-30;
	document.getElementById('errpanel').innerHTML=msg;
	//document.getElementById('errpanel').style.top=pos+'px';
	document.getElementById('errpanel').style.backgroundColor='#dc0009';
	//document.getElementById('errpanel').style.display='';
	erro.style.border='1px solid #dc0009';
}
//--------------------------------
// Oculta mensagem de validação
function hideValid() {
	document.getElementById('errpanel').style.backgroundColor='';
	//document.getElementById('errpanel').style.display='none';
	document.getElementById('errpanel').innerHTML='';
}
// Limita o tamanho do input em textarea
function limitSize(obj,tam) {
	if (obj.value.length<=tam) return;
	obj.value=obj.value.substr(0,tam);
}
//--------------------------------
// Submit se form  for válido
function doSubmit(ok,xform) {
	if (!ok) return false;
	var x=document.getElementById(xform)
	x.submit();
	return true;
}