// JavaScript Document
// -------------------------------------------------------
// -------------------------------------------------------
function enter_tab(primeiro_form)
{
	nextfield = primeiro_form;
	netscape = "";
	ver = navigator.appVersion; len = ver.length;
	for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
		netscape = (ver.charAt(iln+1).toUpperCase() != "C");
	function keyDown(DnEvents) 
		{
			k = (netscape) ? DnEvents.which : window.event.keyCode;
			if (k == 13) 
			{
			if (nextfield == 'done') 
			{
				return false;
			} 
			else 
			{
				eval('document.fmcad.' + nextfield + '.focus()');
				return false;
			}
		}
	}
	document.onkeydown = keyDown;
	if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
}
// -------------------------------------------------------
function StatusMsg(msgStr) 
{
  status=msgStr;
  document.MM_returnValue = true;
}
// -------------------------------------------------------
function abre_janela(arquivo, nome_janela, largura, altura, maximiza, menu, barra, status)
{
	vleft=(((screen.availWidth/2)-(largura/2))-10);
  	vtop=(((screen.availHeight/2)-(altura/2))-30);
	janela=window.open(arquivo, nome_janela, 'width='+largura+',height='+altura+',top='+vtop+', left='+vleft+', resizable='+maximiza+',menubar='+menu+',scrollbars='+barra+', status='+status+'');
	janela.focus();
}
function abre_pop(arquivo, nome_janela, top, left, largura, altura, maximiza, menu, barra, status)
{
	vleft=(((screen.availWidth-785)/2)+left);
	
	janela=window.open(arquivo, nome_janela, 'width='+largura+',height='+altura+',top='+top+', left='+vleft+', resizable='+maximiza+',menubar='+menu+',scrollbars='+barra+', status='+status+'');
	janela.focus();
}
// -------------------------------------------------------
function vazio(campo, mensagem)
{
	if (campo.value.length==0)
	{
		alert('O campo '+mensagem+' deve ser preenchido!');
		campo.style.background='#F1F1F1';
		campo.focus();
		return true;
	}
	return false;
}
// -------------------------------------------------------
function vazio_radio(campo, mensagem)
{
	checado = false;
	for(i=0; i<campo.length; i++)
	{
		if (campo[i].checked)
			checado = true;
	}
	if (!checado)
	{
		alert('O campo '+mensagem+' deve ser preenchido!');
		return true;
	}
	else
		return false;
}
// -------------------------------------------------------
function valida_email(campo)
{
	if (campo.value.length==0)
		return true;
	else
	{
	parte1 = campo.value.indexOf("@");
	parte3 = campo.value.length;
	teste1	= (parte1)
	teste3	= ((parte3-parte1)-1)
	
	if (!(teste1 >= 2 && teste3 >= 4)) 
	{
        alert ("O campo E-mail deve ser conter um endereço eletronico válido!");
 		campo.style.background='#f1f1f1';
		campo.focus();
        return false;
	}
	return true;
	}
}

// -------------------------------------------------------
function mask(objForm, strField, sMask, evtKeyPress)
{
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	
	if(document.all) // Internet Explorer
		nTecla = evtKeyPress.keyCode;
	else if(document.layers) // Nestcape
		nTecla = evtKeyPress.which;
	
	sValue = objForm[strField].value;
	
	// Limpa todos os caracteres de formatação que
	// já estiverem no campo.
	while (sValue.indexOf('-')>=0)
		sValue = sValue.toString().replace( "-", "" );
	while (sValue.indexOf(':')>=0)
		sValue = sValue.toString().replace( ":", "" );
	while (sValue.indexOf('.')>=0)
		sValue = sValue.toString().replace( ".", "" );
	while (sValue.indexOf('/')>=0)
		sValue = sValue.toString().replace( "/", "" );
	while (sValue.indexOf("(")>=0)
		sValue = sValue.toString().replace( "(", "" );
	while (sValue.indexOf(")")>=0)
		sValue = sValue.toString().replace( ")", "" );
	while (sValue.indexOf(' ')>=0)
		sValue = sValue.toString().replace( " ", "" );
	fldLen = sValue.length;
	mskLen = sMask.length;
	
	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;
	
	while (i <= mskLen)
	{
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".")|| (sMask.charAt(i) == ":") || (sMask.charAt(i) == "/"))
		
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
	
		if (bolMask)
		{
			sCod += sMask.charAt(i);
			mskLen++;
		}
		else
		{
			sCod += sValue.charAt(nCount);
			nCount++;
		}
		i++;
	}
	
	objForm[strField].value = sCod;
	
	if (nTecla != 8) // backspace
		if (sMask.charAt(i-1) == "9") // apenas números...
			return ((nTecla > 47) && (nTecla < 58));// números de 0 a 9
	return true;
}
// -------------------------------------------------------
function teste_img(campo, local, mensagem)
{
	if (campo.value.length==0) return false;

			// testa tipo imagem
				caminho = campo.value.substr(1,1)
				var tipo = campo.value.substr(((campo.value.length)-4),4);
				tipo = tipo.toLowerCase()
			
				if (caminho != ":")
				{
					alert('O campo '+mensagem+' contem um CAMINHO INVÁLIDO !');
					campo.style.background='#F1F1F1';
					campo.focus();
					return true;
				}
				if ((tipo != ".jpg") && (tipo != "jpeg"))
				{
					alert('O campo '+mensagem+' contem um arquivo INVÁLIDO \r        O formato deve ser JPG ou JPEG!');
					campo.style.background='#F1F1F1';
					campo.focus();
					return true;
				}
			// teste se tem campo localizacao
			if (local=="") return false;

			else
			{
				if (local.value.length==0)
					{
						alert('O campo de Localização - '+mensagem+' deve ser preenchido!');
						local.style.background='#F1F1F1';
						local.focus();
						return true;
					}
			}
return false;
}
// ---------------- Teste Enquete
function vazio_enquete(campo, mensagem)
{
	checado = false;
	for(i=0; i<campo.length; i++)
	{
		if (campo[i].checked)
			checado = true;
	}
	if (!checado)
	{
		alert('Você deve escolher uma opção !');
		return true;
	}
	else
		return false;
}
// ---------------- Funcoes DIV
function abre_div(id, metodo)
{
	obj = document.getElementById(id);
	if(metodo == 'display')
	{
		obj.style.display = 'block';
	}
	else
	{
		obj.style.visibility = 'visible';
	}
}
function fecha_pop()
{
	document.getElementById('fundo_site').style.display = 'none';
	document.getElementById('div_001').style.display = 'none';
}

function fecha_div(id, metodo)
{
	obj = document.getElementById(id);
	if(metodo == 'display')
	{
		obj.style.display = 'none';
	}
	else
	{
		obj.style.visibility = 'hidden';
	}
}

/*function abre_fotos(id, ft, altura)
{
	parent.document.getElementById('pop_fotos').style.display = 'block';
	parent.document.getElementById('loading').style.display = 'none';
	parent.document.getElementById('pop_fotos').style.height = altura+'px';
	parent.document.getElementById('frame_fotos').height = (altura-20)+'px';
	parent.document.getElementById('frame_fotos').src = 'site/conteudo.php?pag=not_fotos&ft='+ft+'&id='+id;
}
function fecha_fotos()
{
	document.getElementById('frame_fotos').src = '';
	document.getElementById('pop_fotos').style.display = 'none';
	parent.document.getElementById('loading').style.display = 'block';
}*/
        var keyStr = "ABCDEFGHIJKLMNOP" +
                    "QRSTUVWXYZabcdef" +
                    "ghijklmnopqrstuv" +
                    "wxyz0123456789+/" +
                    "=";
      
function encode64(input) 
{
  var output = "";
  var chr1, chr2, chr3 = "";
  var enc1, enc2, enc3, enc4 = "";
  var i = 0;

  do {
	 chr1 = input.charCodeAt(i++);
	 chr2 = input.charCodeAt(i++);
	 chr3 = input.charCodeAt(i++);

	 enc1 = chr1 >> 2;
	 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
	 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
	 enc4 = chr3 & 63;

	 if (isNaN(chr2)) {
		enc3 = enc4 = 64;
	 } else if (isNaN(chr3)) {
		enc4 = 64;
	 }

	 output = output + 
		keyStr.charAt(enc1) + 
		keyStr.charAt(enc2) + 
		keyStr.charAt(enc3) + 
		keyStr.charAt(enc4);
	 chr1 = chr2 = chr3 = "";
	 enc1 = enc2 = enc3 = enc4 = "";
  } while (i < input.length);

  return output;
}
// -------------------------------------------------------
function redigita_campo(campo_1, campo_2)
{
	if (campo_1.value!=campo_2.value)
	{
		alert('A senha não confere. Favor Redigitar');
		campo_2.focus();
		return false;
	}
	return true;
}
function abre_bebe(id, sexo)
{
	parent.document.getElementById('pop_bebe').style.display = 'block';
	parent.document.getElementById('intBebe').src = 'site/conteudo.php?pag=bebe_detalhe&id='+id;
}
function fecha_bebe()
{
	parent.document.getElementById('intBebe').src = '';
	parent.document.getElementById('pop_bebe').style.display = 'none';
}
function valida_nro(campo, mensagem)
{
	var valor = campo.value.replace( ",", "" );
    if (isNaN(valor))
	{
		alert('O campo '+mensagem+' deve conter apenas números!');
		campo.style.background='#E5E5E5';
		campo.focus();
        return true;
	}
	return false;
}

