// JavaScript Document

function wGLBflash(id,w,h,src,bg,q,t)
{
	
	var object = '';
	object += '<object id="' + id + 'home" type="application/x-shockwave-flash" data="' + src + '" width="'+ w +'" height="'+ h +'" tabindex="0" title=""><param name="movie" value="' + src + '" /><param name="flashvars" value="' + q + '" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="bgcolor" value="' + bg + '" />';
	if(t) object += '<param name="wmode" value="transparent" />';
	object += '</object>';
	
	var cnt=document.getElementById(id)
	cnt.innerHTML  = object;
	//document.write(object);
}

function goPlay(n){
	window.open(n);
}

/*toggle Display menu dinâmico*/	


function toggleDisplay(sID)
	
	{
	
		    //PRELOAD
		transimg = new Image; 
		transimg.src = 'imgsite/seta_menu.gif';
		transimg2 = new Image; 
		transimg2.src = 'imgsite/seta_menu.gif';
	
		if (document.getElementById)
		{
		if (document.getElementById(sID).style.display == "none") {
			document.getElementById("img"+sID).src = transimg.src;
			document.getElementById(sID).style.display = "block";
			//alert("if");
			//document.getElementById("img"+sID).src = "imgsite/menu_setacima.gif";
			setCookie(sID, "1");
		}
		else {
			//alert("else");
			document.getElementById("img"+sID).src = transimg2.src;
			document.getElementById(sID).style.display = "none";
			//document.getElementById("img"+sID).src = "imgsite/menu_setabaixo.gif";
			deleteCookie(sID);
		}
		}
		else
		{
			alert('Your browser does not allow for dynamic javascript and is not standards-compliant.\nPlease update your browser to use our site and have it function correctly.');
		};

	}

	 function setCookie(name, value, expires, path, domain, secure) {
			  var curCookie = name + "=" + escape(value) +
			  ((expires) ? "; expires=" + expires.toGMTString() : "") +
			  ((path) ? "; path=" + path : "") +
			  ((domain) ? "; domain=" + domain : "") +
			  ((secure) ? "; secure" : "");
			  document.cookie = curCookie;
	 }
	 function getCookie(name) {
			var dc = document.cookie;
			var prefix = name + "=";
			var begin = dc.indexOf("; " + prefix);
			if (begin == -1) {
			begin = dc.indexOf(prefix);
			if (begin != 0) return null;
			} else
			begin += 2;
			var end = document.cookie.indexOf(";", begin);
			if (end == -1)
			end = dc.length;
			return unescape(dc.substring(begin + prefix.length, end));
	 }
	 function deleteCookie(name, path, domain) {
			if (getCookie(name)) {
				   document.cookie = name + "=" + 
				   ((path) ? "; path=" + path : "") +
				   ((domain) ? "; domain=" + domain : "") +
				   "; expires=Thu, 01-Jan-70 00:00:01 GMT";
				   //history.go(0);
			}
	 }
	 function fixDate(date) {
			var base = new Date(0);
			var skew = base.getTime();
			if (skew > 0) date.setTime(date.getTime() - skew);
	 } 
	 
	//--> 


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];}
}
	
	
function escondeMenu() {
 	if (menuAparente && !popupPrimeira) {
		if (escondido) {
			document.body.focus();
			rapido = 1;
		} else
			window.setTimeout("if (!menuAparente) document.body.focus()",600);
		menuAparente = 0;
		aparece();
	} else
	 	if (popupPrimeira)
			esconde()
}
function esconde() {
	menuAparente = 1;
	if ((ex && !escondido) || popupPrimeira) {
		for (iCnt = 0; iCnt < ex; iCnt++) {
			colSelec(iCnt).style.display  = "none";
		}
		escondido = 1;
	}
}



/*Menu fechando aquiS*/

/*-MENU DINAMICO--------------------------------------------------------------------------*/
ativo = null;
cellAtivo = null;
timeId = null;
document.onclick = new Function("show()");

function show(cell,obj)
{
	obj = document.getElementById(obj);
	if(ativo!=null) { 
		ativo.style.visibility = "hidden"; 
		ativo=null;  
		//cellAtivo.style.backgroundColor=''; 
	}
	if(cell)
	{
		//cell.style.backgroundColor='#F6F6F6';
		cellAtivo = cell;
		
	}
	if(timeId!=null){ clearTimeout(timeId); }
	if(obj)
	{
		obj.style.visibility = "visible";
		ativo = obj;
	}
}


function timerHidePop()
{
	if(ativo!=null)
	{
		timeId = setTimeout("ativo.style.visibility = 'hidden'; timeId=null; ativo=null;",500);
	}

}


/*ajax inteligente*/

// Função para iniciarmos o Ajax no browser do cliente.
function openAjax() {
	var ajax;
	try{
		ajax = new XMLHttpRequest(); // XMLHttpRequest para browsers decentes, como: Firefox, Safari, dentre outros.
	}catch(ee){
		try{
			ajax = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE da MS
		}catch(e){
			try{
				ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS
			}catch(E){
				ajax = false;
			}
		}
	}
	return ajax;
}

function ajaxinteligente(arquivo,querystring, id) {
	if(document.getElementById) { // Para os browsers complacentes com o DOM W3C.
		var exibeResultado = document.getElementById(id); // div que exibirá o resultado da busca.
		//alert(arquivo + ' ' + id)
		if(arquivo != "" && arquivo != null) { // Verifica se o campo não está vazio, ou se foi digitado no mínimo três caracteres.
			var ajax = openAjax(); // Inicia o Ajax.
			ajax.open("GET", arquivo + '?rnd=' + Math.random() + querystring, true); // Envia o termo da busca como uma querystring, nos possibilitando o filtro na busca.
			ajax.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
			//alert(querystring);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 1) { // Quando estiver carregando, exibe: carregando...
					exibeResultado.innerHTML = "<br /><div  style=\"background:#ffffff; width:125px;  border:solid 1px #666666; padding:2px; margin:2px; font: 11px; bold Arial, Helvetica, sans-serif; color:#666666;\"><img src=\"./imgsite/carregando.gif\"  align=\"absmiddle\">Carregando...</div>";
				}
				if(ajax.readyState == 4) { // Quando estiver tudo pronto.
					if(ajax.status == 200) {
						var resultado = ajax.responseText; // Coloca o resultado (da busca) retornado pelo Ajax nessa variável (var resultado).
						//resultado = resultado.replace(/\+/g," "); // Resolve o problema dos acentos (saiba mais aqui: http://www.plugsites.net/leandro/?p=4)
						//resultado = unescape(resultado); // Resolve o problema dos acentos
						//alert(resultado);
						exibeResultado.innerHTML = resultado;
					} else {
						exibeResultado.innerHTML = "Erro: ";
					}
				}
			}
			ajax.send(null); // submete
		} 
	}
}



//#CONTAR COMENTARIO#####################################################################################################
function validacomentario() {
	if(isEmpty(document.formcomenta.nome.value) || !checkField(document.formcomenta.nome.value))
	{
		warnInvalid(document.formcomenta.nome,'O NOME está vazio ou contém caracteres inválidos!');
		return false;
	}
	if(isEmpty(document.formcomenta.email.value) || !verificaEmail(document.formcomenta.email.value))
	{
		warnInvalid(document.formcomenta.email,'O E-MAIL está vazio ou contém caracteres inválidos!');
		return false;
	}
	if(isEmpty(document.formcomenta.comentario.value) || !checkField(document.formcomenta.comentario.value))
	{
		warnInvalid(document.formcomenta.comentario,'A COMENTÁRIO está vazia ou contém caracteres inválidos!');
		return false;
	}
	
	//document.formcomenta.submit();
	//alert(encodeURIComponent(document.formcomenta.comentario.value));
	
	comentario = document.formcomenta.comentario.value;

	
	ajaxinteligente('ajax-comentario.asp','&c=2&nome='+ escape(document.formcomenta.nome.value) +'&email='+ document.formcomenta.email.value +'&comentario='+ escape(comentario) +'&tipo='+ document.formcomenta.tipo.value +'&cod='+ document.formcomenta.cod.value +'', 'interagindo');
	return true;
}


function focusfile(){
	if(document.formcomenta.IDPCONT) document.formcomenta.submit.focus()
}

function validapedido() {
	if(isEmpty(document.formpedido.email.value) || !verificaEmail(document.formpedido.email.value))
	{
		warnInvalid(document.formpedido.email,'O E-MAIL está vazio ou contém caracteres inválidos!');
		return false;
	}
	if(isEmpty(document.formpedido.pedido.value) || !checkField(document.formpedido.pedido.value))
	{
		warnInvalid(document.formpedido.pedido,'Digite seu PEDIDO DE ORAÇÃO está vazio ou contém caracteres inválidos!');
		return false;
	}
	
	//document.formcomenta.submit();
	pedido = document.formpedido.pedido.value;
	<!--alert('?enviar=1&email='+ document.formpedido.email.value +'&pedido='+escape(pedido+'')+'');-->
	
	
	ajaxinteligente('ajax-pedido.asp','&enviar=1&email='+document.formpedido.email.value+'&pedido='+escape(pedido+'')+'', 'oracao_pedidos');
	return true;
}


function contar(obj){
	var campo ;
	campo = obj.value;  
	if (campo.length > 300){
		 alert('Numero máximo de caracteres desse campo é de 300');
		obj.value = campo.slice(0,300);
	}
		campo = obj.value;
		ContaFrase();
	}
	function ContaFrase()
	{
		window.document.formcomenta.IDPCONT.value = window.document.formcomenta.comentario.value.length;
		return true;
}
//#CONTAR COMENTARIO#####################################################################################################
//#ENVIAR PÁGINA#####################################################################################################
function Enviarpagina(){
	
	
	
if	((document.frmIndique.Nome_amigo1.value == "") && (document.frmIndique.Email_amigo1.value != "")) {
	alert ("Por favor, digite o nome de seu 1º amigo.");
} else if ((document.frmIndique.Nome_amigo2.value == "") && (document.frmIndique.Email_amigo2.value != "")){
	alert ("Por favor, digite o nome de seu 2º amigo.");
} else if ((document.frmIndique.Nome_amigo3.value == "") && (document.frmIndique.Email_amigo3.value != "")) {
	alert ("Por favor, digite o nome de seu 3º amigo.");
} else if ((document.frmIndique.Nome_amigo1.value != "") && (!checkEmail(document.frmIndique.Email_amigo1, false))){ 
	alert("Por favor, digite um e-mail válido para o 1º amigo.");
} else if ((document.frmIndique.Nome_amigo2.value != "") && (!checkEmail(document.frmIndique.Email_amigo2, false))){ 
	alert("Por favor, digite um e-mail válido para o 2º amigo.");
} else if ((document.frmIndique.Nome_amigo3.value != "") && (!checkEmail(document.frmIndique.Email_amigo3, false))){ 
	alert("Por favor, digite um e-mail válido para o 3º amigo.");
} else if (((document.frmIndique.Email_amigo1.value == document.frmIndique.Email_amigo2.value) || (document.frmIndique.Email_amigo1.value == document.frmIndique.Email_amigo3.value) || (document.frmIndique.Email_amigo2.value == document.frmIndique.Email_amigo3.value)) && ((document.frmIndique.Email_amigo1.value != "" && document.frmIndique.Email_amigo2.value != "") || (document.frmIndique.Email_amigo1.value != "" && document.frmIndique.Email_amigo3.value != "") || (document.frmIndique.Email_amigo2.value != "" && document.frmIndique.Email_amigo3.value != ""))) {
	alert("Foram digitados e-mails iguais de amigos.");
} else if ((document.frmIndique.Nome_amigo1.value == "") && (document.frmIndique.Nome_amigo2.value == "") && (document.frmIndique.Nome_amigo3.value == "") && (document.frmIndique.Email_amigo1.value == "") && (document.frmIndique.Email_amigo2.value == "") && (document.frmIndique.Email_amigo3.value == "")) {
	alert("É necessário digitar o nome e o e-mail de pelo menos um amigo.");
} else if	(document.frmIndique.Nome_sujeito.value == "") { 
	alert ("Por favor, digite seu nome.");
} else if (!checkEmail(document.frmIndique.Email_sujeito, false)) {
	alert("O seu e-mail deve ser um endereço de e-mail válido, por favor redigite-o.");
}


//else document.frmIndique.submit();
 else {
		var url = "";
		url += "&Nome_amigo1=" +  document.frmIndique.Nome_amigo1.value;
		url += "&Nome_amigo2=" +  document.frmIndique.Nome_amigo2.value+"";
		url += "&Nome_amigo3=" +  escape(document.frmIndique.Nome_amigo3.value+"");
		
		url += "&Email_amigo1=" +  escape(document.frmIndique.Email_amigo1.value+"");
		url += "&Email_amigo2=" +  escape(document.frmIndique.Email_amigo2.value+"");
		url += "&Email_amigo3=" +  escape(document.frmIndique.Email_amigo3.value+"");
		
		url += "&Nome_sujeito=" +  escape(document.frmIndique.Nome_sujeito.value+"");
		url += "&Email_sujeito=" +  escape(document.frmIndique.Email_sujeito.value+"");
		url += "&Obs=" +  escape(document.frmIndique.Obs.value+"");
		url += "&url=" +  escape(document.frmIndique.url.value+"");
		url += "&titulo=" +  escape(document.frmIndique.titulo.value+"");
		//alert(url);
		ajaxinteligente('ajax-enviar.asp','?c=2' + url, 'interagindo');
	}
}

//#ENVIAR PÁGINA#####################################################################################################
//#NOTA#####################################################################################################

//#ENVIAR PÁGINA#####################################################################################################
function Indicarpagina(){
	

if	((document.frmIndique.Nome_amigo1.value == "") && (document.frmIndique.Email_amigo1.value != "")) {
	alert ("Por favor, digite o nome de seu 1º amigo.");
} else if ((document.frmIndique.Nome_amigo2.value == "") && (document.frmIndique.Email_amigo2.value != "")){
	alert ("Por favor, digite o nome de seu 2º amigo.");
} else if ((document.frmIndique.Nome_amigo3.value == "") && (document.frmIndique.Email_amigo3.value != "")) {
	alert ("Por favor, digite o nome de seu 3º amigo.");
} else if ((document.frmIndique.Nome_amigo1.value != "") && (!checkEmail(document.frmIndique.Email_amigo1, false))){ 
	alert("Por favor, digite um e-mail válido para o 1º amigo.");
} else if ((document.frmIndique.Nome_amigo2.value != "") && (!checkEmail(document.frmIndique.Email_amigo2, false))){ 
	alert("Por favor, digite um e-mail válido para o 2º amigo.");
} else if ((document.frmIndique.Nome_amigo3.value != "") && (!checkEmail(document.frmIndique.Email_amigo3, false))){ 
	alert("Por favor, digite um e-mail válido para o 3º amigo.");
} else if (((document.frmIndique.Email_amigo1.value == document.frmIndique.Email_amigo2.value) || (document.frmIndique.Email_amigo1.value == document.frmIndique.Email_amigo3.value) || (document.frmIndique.Email_amigo2.value == document.frmIndique.Email_amigo3.value)) && ((document.frmIndique.Email_amigo1.value != "" && document.frmIndique.Email_amigo2.value != "") || (document.frmIndique.Email_amigo1.value != "" && document.frmIndique.Email_amigo3.value != "") || (document.frmIndique.Email_amigo2.value != "" && document.frmIndique.Email_amigo3.value != ""))) {
	alert("Foram digitados e-mails iguais de amigos.");
} else if ((document.frmIndique.Nome_amigo1.value == "") && (document.frmIndique.Nome_amigo2.value == "") && (document.frmIndique.Nome_amigo3.value == "") && (document.frmIndique.Email_amigo1.value == "") && (document.frmIndique.Email_amigo2.value == "") && (document.frmIndique.Email_amigo3.value == "")) {
	alert("É necessário digitar o nome e o e-mail de pelo menos um amigo.");
} else if	(document.frmIndique.Nome_sujeito.value == "") { 
	alert ("Por favor, digite seu nome.");
} else if (!checkEmail(document.frmIndique.Email_sujeito, false)) {
	alert("O seu e-mail deve ser um endereço de e-mail válido, por favor redigite-o.");
}


else document.frmIndique.submit();
}

//#ENVIAR PÁGINA#####################################################################################################

// Checa endereÃ§os de e-mail

function checkEmail (theField, emptyOK)
{   //if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
	if (emptyOK == true) return true;
    if (!isEmail(theField.value, false)) return false;
	else return true;
}

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isEmail (s)
{   
    var i = 1;
	var contarroba = 0;
    var sLength = s.length;
	
	// procura Ã§, ', ^, Ã¡, Ã©, Ã­, Ã³, Ãº, Ã¢, Ãª, Ã®, Ã´, Ã»
    while ((i < sLength) && (s.charAt(i) != "Ã§") && (s.charAt(i) != "^") && (s.charAt(i) != "'") && (s.charAt(i) != "Ã¡") && (s.charAt(i) != "Ã©") && (s.charAt(i) != "Ã­") && (s.charAt(i) != "Ã³") && (s.charAt(i) != "Ãº") && (s.charAt(i) != "Ã¢") && (s.charAt(i) != "Ãª") && (s.charAt(i) != "Ã®") && (s.charAt(i) != "Ã´") && (s.charAt(i) != "Ã»")) 
    { i++
    }

    if (i < sLength) return false;
    else i = 1;

	// verifica se existe mais de um @
	
    while (i < sLength) 
    { if (s.charAt(i) == "@") contarroba=contarroba+1
		i++
	}
    if (contarroba > 1) return false;
    else i=1;
	
	// procura @
    while ((i < sLength) && (s.charAt(i) != "@")) 
    { i++
    
	}
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // procura .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // deve existir no mÃ­nimo um caractere depois do ponto
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
    
    
}
//alert(encodeURI("amigos.asp?test=1& fulano=2"));
//alert(decodeURI(encodeURI("amigos.asp?test=1& fulano=2")));
//#ENVIAR PÁGINA#####################################################################################################



/*---------------------------------------------------------------------------*/

function openCentered(theURL,winName,winWidth,winHeight,features) {
  var w = (screen.width - winWidth)/2;
  var h = (screen.height - winHeight)/2 - 60;
  features = features+',width='+winWidth+',height='+winHeight+',top='+h+',left='+w;
  window.open(theURL,winName,features);
}
function fnAddToFavs(urlfav,textofav)
{
	window.external.AddFavorite(urlfav,textofav);
}


/*---------------------------------------------------------------------------*/
function menu(onde){

//alert(onde);

	switch (onde){
		
		case "home": 
			location.href = "./";
		break;
		case "noticias": 
			location.href = "noticias.asp";
		break;
		case "celulas": 
			location.href = "celulas.asp?id=13&ministerio=CÉLULAS";
		break;
		case "radio": 
			location.href = "radio.asp";
		break;
		case "galerias": 
			location.href = "galerias.asp";
		break;
		case "agenda": 
			location.href = "agenda.asp";
		break;
		case "testemunhos": 
			location.href = "testemunhos.asp";
		break;
		case "estudos": 
			location.href = "estudos.asp";
		break;
		case "mensagens": 
			location.href = "mensagens.asp";
		break;
		case "oracao": 
			location.href = "pedidosoracao.asp";
		break;
		case "dicas": 
			location.href = "dicas.asp?id=18&ministerio=DICAS";
		break;
		case "biblia": 
			location.href = "ecristaobilblia.asp";
		break;
			
		default : location.href = "./";
		
	}


}


/*---------------------------------------------------------------------------*/





/************************************************
* function verificaDataform
* Verifica se um campo data é válido.
* Input: Campo do formulário que contém a data
* Esta função pega o campo diretamente, pois assim
* pode dar uma resposta melhor ao usuário.
*************************************************/

function verificaDataform(data){
	var Date = new String(data);
	Day = "";
	Month = "";
	Year = "";
	i =  0;
	for (i=0;(i<Date.length) && (Date.charAt(i) != '/');i++)
		Day = Day + Date.charAt(i);
	i++;
	for (;(i<Date.length) && (Date.charAt(i) != '/');i++)
		Month = Month + Date.charAt(i);
	i++;
	for (;(i<Date.length);i++)
		Year = Year + Date.charAt(i);
	for(i=0;i<Date.length;i++){
		NroAsc = asc(Date.substring(i,i+1))
		if (!(NroAsc>=48 && NroAsc<=57) || !(NroAsc = 47) )  {
			return false;
		}
	}
	if(!isNumeric(Month)) {
		return false;
	}
	if (eval(Month) > 12){
		return false;
	}
	if(!isNumeric(Day)) {
		return false;
	}
	if (eval(Day) > 31){
		return false;
	}
	if(!isNumeric(Year)) {
		return false;
	}
	if(eval(Year) < 1900) {
		return false;
	}
	return true;
}


/************************************************
* function verificaCPF
* Verifica se um CPF é válido
* Input: cpf a ser verificado
************************************************/

function verificaCPF(cpf)
{
	var dac = "", inicio = 2, fim = 10, soma, digito, i, j
	for (j=1;j<=2;j++) {
		soma = 0
		for (i=inicio;i<=fim;i++) {
			soma += parseInt(cpf.substring(i-j-1,i-j))*(fim+1+j-i)
		}
		if (j == 2) { soma += 2*digito }
		digito = (10*soma) % 11
		if (digito == 10) { digito = 0 }
		dac += digito
		inicio = 3
		fim = 11
	}
	return (dac == cpf.substring(cpf.length-2,cpf.length))
}

/************************************************
* function verificaCGC
* Verifica se um CGC é válido
* Input: cgc a ser verificado
************************************************/

function verificaCGC(scgc) {
	cgc = trimtodigits(scgc);
	if ((cgc.indexOf("-") != -1) || (cgc.indexOf(".") != -1) || (cgc.indexOf("/") != -1)){
		return( false )
	}
	var df, resto, dac = ""
	df = 5*cgc.charAt(0)+4*cgc.charAt(1)+3*cgc.charAt(2)+2*cgc.charAt(3)+9*cgc.charAt(4)+8*cgc.charAt(5)+7*cgc.charAt(6)+6*cgc.charAt(7)+5*cgc.charAt(8)+4*cgc.charAt(9)+3*cgc.charAt(10)+2*cgc.charAt(11)
	resto = df % 11
	dac += ( (resto <= 1) ? 0 : (11-resto) )
	df = 6*cgc.charAt(0)+5*cgc.charAt(1)+4*cgc.charAt(2)+3*cgc.charAt(3)+2*cgc.charAt(4)+9*cgc.charAt(5)+8*cgc.charAt(6)+7*cgc.charAt(7)+6*cgc.charAt(8)+5*cgc.charAt(9)+4*cgc.charAt(10)+3*cgc.charAt(11)+2*parseInt(dac)
	resto = df % 11
	dac += ( (resto <= 1) ? 0 : (11-resto) )
	return (dac == cgc.substring(cgc.length-2,cgc.length))
}

/************************************************
* function verificaEmail
* Verifica se um email é válido
* Input: email a ser verificado
************************************************/

function verificaEmail(email) {
	var s = new String(email);
	// { } ( ) < > [ ] | \ /
	if ((s.indexOf("{")>=0) || (s.indexOf("}")>=0) || (s.indexOf("(")>=0) || (s.indexOf(")")>=0) || (s.indexOf("<")>=0) || (s.indexOf(">")>=0) || (s.indexOf("[")>=0) || (s.indexOf("]")>=0) || (s.indexOf("|")>=0) || (s.indexOf("\"")>=0) || (s.indexOf("/")>=0) )
		return false;
	if (vogalAcentuada(email))
		return false;
	// & * $ % ? ! ^ ~ ` ' "
	if ((s.indexOf("&")>=0) || (s.indexOf("*")>=0) || (s.indexOf("$")>=0) || (s.indexOf("%")>=0) || (s.indexOf("?")>=0) || (s.indexOf("!")>=0) || (s.indexOf("^")>=0) || (s.indexOf("~")>=0) || (s.indexOf("`")>=0) || (s.indexOf("'")>=0) )
		return false;
	// , ; : = #
	if ((s.indexOf(",")>=0) || (s.indexOf(";")>=0) || (s.indexOf(":")>=0) || (s.indexOf("=")>=0) || (s.indexOf("#")>=0) )
		return false;
	// procura se existe apenas um @
	if ( (s.indexOf("@") < 0) || (s.indexOf("@") != s.lastIndexOf("@")) )
		return false;
	// verifica se tem pelo menos um ponto após o @
	if (s.lastIndexOf(".") < s.indexOf("@"))
		return false;
	return true;
}

/************************************************
* function verificaCEP
* Verifica se o CEP está no formato correto
* Input: CEP a ser verificado
************************************************/

function verificaCEP (cep) {
	s = new String(cep);
	if ((s.length > 9) || (s.length < 5))
		return false;
	if (!isInteger(cep))
		return false;
	return true;
}

/************************************************
* function isInteger
* Verifica se um campo é inteiro, inclui dígitos de 0 a 9, vírgula, ponto, espaços e -
* Input: campo a ser verificado
************************************************/

function isInteger(s){
	var i;
	if (isEmpty(s)) 
		return false;
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (!isNumber(c)) return false;
	}
	return true;
}

/************************************************
* function isNumeric
* Verifica se um campo é numérico. Se contém apenas dígitos de 0 a 9
* Input: campo a ser verificado
************************************************/

function isNumeric(s){
	var i;
	if (isEmpty(s)) 
		return false;
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (!isDigit(c)) return false;
	}
	return true;
}

/************************************************
* function warnInvalid
* Gera um alert para o usuário e volta o foco para
* o campo que está com problema
* Input: theField - campo do formulário com problema
*        warnText - texto a ser mostrado no alert
************************************************/

function warnInvalid (theField, warnText)
{   theField.focus()
	theField.select()
	alert(warnText)
	return false
}

// Verifica se o caracter é um dígito de 0 a 9
function isDigit (c)
{ return ((c >= "0") && (c <= "9")) }

// Verifica se uma string tem vogais acentuadas
function vogalAcentuada(s) {
	ls = s.toLowerCase();
	if ((ls.indexOf("á")>=0) || (ls.indexOf("à")>=0) || (ls.indexOf("ã")>=0) || (ls.indexOf("â")>=0) || (ls.indexOf("é")>=0) || (ls.indexOf("í")>=0) || (ls.indexOf("ó")>=0) || (ls.indexOf("õ")>=0) || (ls.indexOf("ô")>=0) || (ls.indexOf("ú")>=0) || (ls.indexOf("ü")>=0))
		return true;
}

// Gera uma string com os caracteres básicos na sequência de códigos ASC
function makeCharsetString(){
	var astr
	astr = ' !"#$%&\'()*+,-./0123456789:;<=>?@'
	astr+= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	astr+= '[\]^_`abcdefghijklmnopqrstuvwxyz'
	astr+= '{|}~'
	return astr
}

// Retorna o código ASC do caracter passada por parâmetro
function asc(achar){
	var n=0;
	var ascstr = makeCharsetString()
	for(i=0;i<ascstr.length;i++){
		if(achar==ascstr.substring(i,i+1)){
			n=i;
			break;
		}
	}
	return n+32
}

//Remove todos os caracteres excetos 0-9
function trimtodigits(tstring){
  s=""; 
  ts=new String(tstring);
  for (x=0;x<ts.length;x++){
   ch=ts.charAt(x);
	if (asc(ch)>=48 && asc(ch)<=57){
	  s=s+ch;
	}
  }
  return s;
}
/*inicio */


// Retorna o código ASC do caracter passada por parâmetro
function asc(achar){
	var n=0;
	var ascstr = makeCharsetString()
	for(i=0;i<ascstr.length;i++){
		if(achar==ascstr.substring(i,i+1)){
			n=i;
			break;
		}
	}
	return n+32
}
// Gera uma string com os caracteres básicos na sequência de códigos ASC
function makeCharsetString(){
	var astr
	astr = ' !"#$%&\'()*+,-./0123456789:;<=>?@'
	astr+= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	astr+= '[\]^_`abcdefghijklmnopqrstuvwxyz'
	astr+= '{|}~'
	return astr
}

// Verifica se uma string tem vogais acentuadas
function vogalAcentuada(s) {
	ls = s.toLowerCase();
	if ((ls.indexOf("á")>=0) || (ls.indexOf("à")>=0) || (ls.indexOf("ã")>=0) || (ls.indexOf("â")>=0) || (ls.indexOf("é")>=0) || (ls.indexOf("í")>=0) || (ls.indexOf("ó")>=0) || (ls.indexOf("õ")>=0) || (ls.indexOf("ô")>=0) || (ls.indexOf("ú")>=0) || (ls.indexOf("ü")>=0))
	return true;
}

// Verifica se o caracter pode fazer parte de um número: 0-9 , . ( ) - e espaço
function isNumber (c) { 
	return ((c >= "0") && (c <= "9") || (c=="-") || (c=="(") || (c==")") || (c==" ") || (c==".") || (c==",")) 
}

// Verifica se o caracter é um dígito de 0 a 9
function isDigit (c) { 
	return ((c >= "0") && (c <= "9")) 
}

/************************************************
* function checkField
* Verificação básica de um campo de formulário por "coisas bobas": & < > | \ /
* Input: campo a ser verificado
************************************************/

function checkField(s) {
	if ((s.indexOf("&")>=0) || (s.indexOf("<")>=0) || (s.indexOf(">")>=0) || (s.indexOf("|")>=0) || (s.indexOf("\"")>=0) || (s.indexOf("/")>=0) )
		return false;
	return true;
}

/************************************************
* function isEmpty
* Verifica se um campo está vazio
* Input: campo a ser verificado
************************************************/

function isEmpty(s) {
	return ((s == null) || (s.length == 0));
}


/************************************************
* function warnInvalid
* Gera um alert para o usuário e volta o foco para
* o campo que está com problema
* Input: theField - campo do formulário com problema
*        warnText - texto a ser mostrado no alert
************************************************/

function warnInvalid (theField, warnText)
{   theField.focus()
	theField.select()
	alert(warnText)
	return false
}

/************************************************
* function warnInvalid_SelectBox
* Gera um alert para o usuário e volta o foco para
* o campo que está com problema
* Esta função é específica para ser usada com campos Select, para outros campos, usar a warnInvalid
* Input: theField - campo do formulário com problema
*        warnText - texto a ser mostrado no alert
************************************************/
function warnInvalid_SelectBox (theField, s)
{
	theField.focus();
	alert(s);
	return false;
}

