
var vEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
var vCampos = /^(.){1,}/;

//Função para abrir uma janela popup
function popupx(url,target,parametros, largura, altura, center) {

	if (parametros != '') {
		parametros += ',';
	}
	if (center == 1) {
		var vLeft = (screen.width-largura)/2;
		var vTop = (screen.height-altura)/2;

		parametros += 'left='+vLeft+',top='+vTop;
	}
	if (parametros != '') {
		parametros += ',';
	}
	parametros += 'width='+largura+',height='+altura;
	window.open(url, target, parametros)
}

function abrepopup(pagina) { window.open (pagina,'fotos','toolbar=no,location=no,status=no,menubar=no,status=no,resizable=no,scrollbars=yes,width=541,height=395,top=50,left=80');}
function popupobra(pagina) { window.open (pagina,'suaobra','toolbar=no,location=no,status=no,menubar=no,status=no,resizable=no,scrollbars=yes,width=560,height=500,top=50,left=80');}
/*
// Validar os campos do formulário
// Tipos: (1) E-mail ; (2) Numérico
// v|CAMPO|TIPO{1, 2}
// 
//  by Élison Gomes (2005)
// < elison@fievel.com.br >
*/
function checkForm(form) {
	var campo;
	var campo_valor;
	var campo_nome;
	var msg = '';
	var erro = 0;
	var icampo = -1;
	var pEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	for (var i = 0; i < form.length; i++) {
		try {
			campo = form[i].id.split('|');
			campo_valor = form[i].value;
			campo_nome = campo[1].toUpperCase();

			if (campo[0] == "v") {
				/* CAMPO VAZIO */
				if (campo_valor.length < 1) {
					erro++;
					msg += '- O campo ' + campo_nome + ' deve ser preenchido.\n';
					if (icampo == -1) {
						icampo = i;
					}
				}
				/* VALIDAÇÃO ESPECÍFICA */
				else if (campo.length > 2) {
					/* E-MAIL */
					if ( (campo[2] == 1) && (!pEmail.test(campo_valor)) ) {
						erro++;
						msg += '- O campo ' + campo_nome + ' deve ser preenchido com um e-mail válido.\n';
						if (icampo == -1) {
							icampo = i;
						}
					}
					/* NUMÉRICO */
					else if ( (campo[2] == 2) && (isNaN(campo_valor)) ) {
						erro++;
						msg += '- O campo ' + campo_nome + ' deve conter somente números.\n';
						if (icampo == -1) {
							icampo = i;
						}
					}
				}
			}
		} catch(e) {}
	}
	if (erro > 0)
	{
		alert('Atenção, foi detectado '+erro+' erro(s) no preenchimento do formulário:\n\n'+msg);
		form[icampo].focus();
		return false;
	} else
	{
		return true;
	}
}

function barraRolagem () {
	try {
		var iScroll = document.body.scrollHeight*1;
		if (iScroll > 410) {
			document.body.scroll = 'yes';
		}
	} catch (e) { alert('erro'); }
}

function sMsg(str)
{
  window.status = str;
}

function vEnquete(id) {
  var nm_opcoes = document.enquete.opcao.length;
  var resposta = nm_opcoes;
  var respostas = "";
  for(i=0;i<nm_opcoes;i++) {
	if(document.enquete.opcao[i].checked) {
		resposta = i;
		respostas=respostas + "voto=" + document.enquete.opcao[i].value;
	}
  }
  if(resposta==nm_opcoes) {
	alert("Selecione uma opção antes de votar.");
  }
  else {
	popupx('enquete.php?op=votar&amp;id='+id+'&amp;'+respostas,'bruna_enquete','menubar=no, scrollbars=yes, resizable=no','300','410','1');
  }
}

function pEnquete(id) {
	popupx('enquete.php?id='+id,'bruna_enquete','menubar=no, scrollbars=yes, resizable=no','300','410','1');
}

function vCartao()
{

  if (!checkForm(document.cartao))
  {
    return false;
  } else
  {
      popupx('about:blank','cartao','status=no,scrollbars=yes','440','500','1');
      return true;
  }
}

function ShowHideLayer(layerNome)
{

  var elemLayerID = document.getElementById(layerNome);

  if (elemLayerID.style.display == 'none')
  {
    elemLayerID.style.display = '';
  }
  else {
    elemLayerID.style.display = 'none';
  }
}

//Função para limitar o tamanho da textarea num formulário
function textMax(obj, objcount, max)
{
  str = obj.value;
  if( str.length > max )
  {
    obj.value = str.substring( 0, max );
  } else
  {
    objcount.innerText = max - str.length;
  }
}

function ir(url) {
	location.href = url;
}

function abreChat()
{
	popupx('./chat','shirley_chat','menubar=no, scrollbars=no, resizable=no','350','330','1');
}

function isEmpty (x)
{
	y = new String (x.value)
	return (y.length == 0)
}

function verifica()
{
    ok = true;
	ff = document.f
    msg = ""
	
    if (isEmpty(ff.nome))
    	{
        ok = false;
        msg = msg + " - Preencha o campo Nome\n";
    	}
   if (isEmpty(ff.end))
    	{
        ok = false;
        msg = msg + " - Preencha o campo Endereço\n";
    	}
   if (isEmpty(ff.fone))
    	{
        ok = false;
        msg = msg + " - Preencha campo Telefone com DDD e telefone\n";
    	}		
   if (isEmpty(ff.mail))
    	{
        ok = false;
        msg = msg + " - Preencha o seu email.\n";
    	}		
	else 
		{
		var e = ff.mail.value;
		if (e.indexOf("@") == -1)
			{
			ok = false;
	        msg = msg + " - Email inválido!\n";
			}
		}

if (! ok)
	alert (msg)
return ok
}