var timerID = null;
var timerRunning = false;
var arrayPlantao = new Array('Veja o Circuito Gastron&ocirc;mico da Rua das Pedras', 'Prefeitura vai recadastrar todos os im&oacute;veis', 'B&uacute;zios se prepara para o ver&atilde;o');
var z = 0;
var scrollerDelay = scrollerHeight = txt1 = txt2 = scrollerColunasHeight = coltxt1 = coltxt2 = '';
scrollerDelay = 3000; scrollerHeight = '110px'; scrollerColunasHeight = '70px';

	function movePrinc(t)
		{
			txt1 = eval(t);
			if(((parseInt(txt1.style.top) > 0) && (parseInt(txt1.style.top) <= 5)))
				{
					txt1.style.top = (0 + 'px'); setTimeout('movePrinc(txt1)', scrollerDelay);
					setTimeout('moveSecund(scrolltxt2)', scrollerDelay); return;
				}
			if(parseInt(txt1.style.top) >= (txt1.offsetHeight * -1))
				{
					txt1.style.top = ((parseInt(txt1.style.top) - 5) + 'px');
					setTimeout('movePrinc(scrolltxt1)', 50);
				}
			else
				{
					txt1.style.top = parseInt(scrollerHeight); txt1.innerHTML = arrayPlantao[i];
					(i == (arrayPlantao.length - 1)) ? i = 0 : i++
				}
		}
		
	function moveSecund(t)
		{
			txt2 = eval(t);
			if(((parseInt(txt2.style.top) > 0) && (parseInt(txt2.style.top) <= 5)))
				{
					txt2.style.top = (0 + 'px'); setTimeout('moveSecund(txt2)', scrollerDelay);
					setTimeout('movePrinc(scrolltxt1)', scrollerDelay); return;
				}
			if(parseInt(txt2.style.top) >= (txt2.offsetHeight * -1))
				{
					txt2.style.top = ((parseInt(txt2.style.top) -5) + 'px');
					setTimeout('moveSecund(scrolltxt2)', 50);
				}
			else
				{
					txt2.style.top = parseInt(scrollerHeight); txt2.innerHTML = arrayPlantao[i];
					(i == (arrayPlantao.length - 1)) ? i = 0 : i++
				}
		}
	
	function startScroll()
		{
			var d = window.document.getElementById;
			scrolltxt1 = d('txt1'); scrolltxt2 = d('txt2'); movePrinc(scrolltxt1);
			scrolltxt2.style.top = scrollerHeight; scrolltxt2.style.visibility = 'visible';
		}
	
	function moveColunasPrinc(t)
		{
			txt1 = eval(t);
			if(((parseInt(txt1.style.top) > 0) && (parseInt(txt1.style.top) <= 5)))
				{
					txt1.style.top = (0 + 'px'); setTimeout('moveColunasPrinc(txt1)', scrollerDelay);
					setTimeout('moveColunasSecund(col2)', scrollerDelay); return;
				}
			if(parseInt(txt1.style.top) >= (txt1.offsetHeight * -1))
				{
					txt1.style.top = ((parseInt(txt1.style.top) - 5) + 'px');
					setTimeout('moveColunasPrinc(col1)', 50);
				}
			else
				{
					txt1.style.top = parseInt(scrollerColunasHeight); txt1.innerHTML = arrayColunas[z];
					(z == (arrayColunas.length - 1)) ? z = 0 : z++
				}
		}
		
	function moveColunasSecund(t)
		{
			txt2 = eval(t);
			if(((parseInt(txt2.style.top) > 0) && (parseInt(txt2.style.top) <= 5)))
				{
					txt2.style.top = (0 + 'px'); setTimeout('moveColunasSecund(txt2)', scrollerDelay);
					setTimeout('moveColunasPrinc(col1)', scrollerDelay); return;
				}
			if(parseInt(txt2.style.top) >= (txt2.offsetHeight * -1))
				{
					txt2.style.top = ((parseInt(txt2.style.top) -5) + 'px');
					setTimeout('moveColunasSecund(txt2)', 50);
				}
			else
				{
					txt2.style.top = parseInt(scrollerColunasHeight); txt2.innerHTML = arrayColunas[z];
					(z == (arrayColunas.length - 1)) ? z = 0 : z++
				}
		}
	
	function startColunasScroll()
		{
			var d = window.document.getElementById;
			col1 = d('coltxt1'); col2 = d('coltxt2'); moveColunasPrinc(col1);
			col2.style.top = scrollerColunasHeight; col2.style.visibility = 'visible';
		}
	
	function startClock () 
		{
			stopClock(); Time();
		}
	
	function stopClock ()
		{
			if(timerRunning)clearTimeout(timerID);
			timerRunning = false;
		}
	
	function Time()
		{
			var now = new Date();
			var hours = now.getHours();
			var minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
			var seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
			var Time = (hours + minutes + seconds);
			window.document.getElementById('clock').innerHTML = Time;
			timerID = setTimeout("Time()",1000);
			timerRunning = true;
		}
	
	function clearStatus()
		{
			if(timerRunning)clearTimeout(timerID);
			timerRunning = false;
			document.all('t') = '';
		}
	
	String.prototype.Trim = Trim;
	function Trim()
		{
			return(this.replace(/^\s+|\s+$/gi, '').replace(/\s{2,}/gi, ' '));
		}
	
	var isNN = (navigator.appName.indexOf('Netscape') != -1);  

	function autoTab(input,len, e)
		{
			var keyCode = (isNN) ? e.which : e.keyCode;
			var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
			
			if(input.value.length >= len && !containsElement(filter,keyCode))
				{
					input.value = input.value.slice(0, len);
					input.form[(getIndex(input)+1) % input.form.length].focus();
				}
			
			function containsElement(arr, ele)
				{
					var found = false, index = 0;
					while(!found && index < arr.length)
						{
							if(arr[index] == ele)found = true;
							else index++;
						}
					return found;
				}
			
			function getIndex(input)
				{
					var index = -1, i = 0, found = false;
					while (i < input.form.length && index == -1)
						{
							if (input.form[i] == input)index = i;
							else i++;
						}
					return index;
				}
			return true;
		}
	
	function ValidaNumero(objeto)
		{
			campo = eval(objeto)
			if(((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 13))event.returnValue = true;
			else
				{
					alert ('O campo só aceita valores numéricos!');
					eval(campo).focus();
					event.returnValue = false;
				}
		}
		
	function ValidaMoeda(objeto)
		{
			input = eval(objeto)
			if(((event.keyCode > 47) && (event.keyCode < 58)) ||
			((event.keyCode == 13) || (event.keyCode == 44) || (event.keyCode == 46)))event.returnValue = true;
			else
				{
					alert ('O campo só aceita valores numéricos!');
					eval(input).focus();
					event.returnValue = false;
				}
		}
		
	function Mascaradata(formato, objeto)
		{
			input = eval(objeto)
			if(formato == 'data')
				{
					if(((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 13))
						{
							if (input.value.length == 2)input.value += '/';
							else if (input.value.length == 5)input.value += '/';
						}
					else
						{
							alert ('O campo só aceita valores numéricos!');
							eval(input).focus();
							event.returnValue = false;
						}
	        	}
		}
	
	function validadatanumero(S)
		{
			var temp = '';
			for(var i = 0; i < S.length; i++)
				{
					if(S.charAt(i) != '/')temp += S.charAt(i);
				}
			return temp
		}
	
	function validadata(objeto, anoatual)
		{
			input = eval(objeto)
			if(isNaN(validadatanumero(input.value)))
				{
					alert('O campo só aceita valores numéricos!')
					eval(input).select()
					return (false)
				}
			else
				{
					var dia = input.value.slice(0, 2)
					var mes = input.value.slice(3, 5)
					var ano = input.value.slice(6, 10)
					
					var bissexto = ((ano % 4 == 0) && ((ano % 100 != 0) || (ano % 400 == 0)));
					if(input.value.length < 10)
						{
							alert('Data inválida. A data deve estar no formato: dd/mm/yyyy!')
							eval(input).select()
							return false
						}
					else if(ano < 1900)
						{
							alert('Ano inválido. O ano deve ser maior 1900!')
							eval(input).select()
							return false
						}
					else if(ano > anoatual)
						{
							alert('Ano inválido. O ano deve ser menor ou igual a '+ anoatual +'!')
							eval(input).select()
							return false
						}
					else if((mes <= 0) || (mes > 12))
						{
							alert('Mês inválido.!')
							eval(input).select()
							return false
						}
					else if((mes == 2) && ((dia > 29) || ((dia == 29) && (!bissexto))))
						{
							alert('Dia inválido.!')
							eval(input).select()
							return false
						}
					else if(((mes == 1) || (mes == 3) || (mes == 5) || (mes == 7) || (mes == 8) || 
					(mes == 10) || (mes == 12)) && ((dia <= 0) || (dia > 31)))
						{
							alert('Dia inválido.!')
							eval(input).select()
							return false
						}
					else if(((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11)) && 
					((dia <= 0) || (dia > 30)))
						{
							alert('Dia inválido.!')
							eval(input).select()
							return false
						}
					else return true;
				}
		}
	
	function createNewDate(d)
		{
			var dia = d.slice(0, 2)
			var mes = d.slice(3, 5)
			ano = d.slice(6, 10)
			data = new Date(ano +'/'+ mes +'/'+ dia)
			return (data)
		}
	
	function MascaraCNPJ(formato, objeto)
		{
			input = eval(objeto);
			if(formato == 'cnpj')
				{
					if(((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 13))
						{
							if(input.value.length == 2)input.value += '.';
							else if(input.value.length == 6)input.value += '.';
							else if (input.value.length == 10)input.value += '/';
							else if (input.value.length == 15)input.value += '-';
						}
					else
						{
							alert ('O campo só aceita valores numéricos!');
							eval(input).focus();
							event.returnValue = false;
						}
				}
		}

	function Mascaracpf (formato, objeto)
		{
			input = eval(objeto);
			if(formato == 'cpf')
				{
					if(((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 13))
						{
							if (input.value.length == 3)input.value += '.';
							else if (input.value.length == 7)input.value += '.';
							else if (input.value.length == 11)input.value += '-';
						}
					else
						{
							alert ('O campo só aceita valores numéricos!');
							eval(input).focus();
							event.returnValue = false;
						}
				}
		}
	
	function Mascaracep (formato, objeto)
		{
			input = eval (objeto);
			if(formato == 'cep')
				{
					if(((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 13))
						{
							if (input.value.length == 5)input.value += '-';
						}
					else 
						{
							alert ('O campo só aceita valores numéricos!');
							eval(input).focus();
							event.returnValue = false;
						}
				}
		}
	
	function validacpf(objeto)
		{
			input = eval(objeto)
			var invalidos = new Array('000.000.000-00', '111.111.111-11', '222.222.222-22', '333.333.333-33', '444.444.444-44', '555.555.555-55', '666.666.666-66', '777.777.777-77', '888.888.888-88', '999.999.999-99');
			var valida = false;
			for(i = 0; i < invalidos.length; i++)
				{
					if(input.value == invalidos[i])
						{
							valida = true;
							break;
						}
				}
			if(valida)
				{
					alert ('CPF inválido. Favor verificar!');
					eval(input).focus();
					return false;
				}
			else
				{
					var s = limpa_string(input.value)
					var dv1 = dv2 = cpf = soma = p1 = 0;
					var d1 = '098765432';
					var d2 = '1098765432';
					var c1 = parseInt(s.slice(9, 10))
					var c2 = parseInt(s.slice(10, 11))
					var pri1 = s.slice(0, 9)
					var pri2 = s.slice(0, 10)
					
					for(i = 0; i < 9; i++)
						{
							if(d1.slice(i, (i + 1)) == '0')cpf = (10 * parseInt(pri1.slice(i, (i + 1))));
							else cpf = (parseInt(d1.slice(i, (i + 1))) * parseInt(pri1.slice(i, (i + 1))));
							soma += cpf;
						}
					
					dv1 = parseInt((soma % 11));
					if((dv1 == 0) || (dv1 == 1))dv1 = 0;
					else dv1 = (11 - dv1);
					
					if(c1 != dv1)
						{
							alert ('O primeiro dígito verificador do seu CPF não é válido. Favor verificar!');
							eval(input).focus();
							return false;
						}
					
					cpf = soma = 0;
					for(i = 0; i < 10; i++)
						{
							if(d2.slice(i, (i + 1)) == '1')cpf = (11 * parseInt(pri2.slice(i, (i + 1))));
							else if(d2.slice(i, (i + 1)) == '0')cpf = (10 * parseInt(pri2.slice(i, (i + 1))));
							else cpf = (parseInt(d2.slice(i, (i + 1))) * parseInt(pri2.slice(i, (i + 1))));
							soma += cpf;
						}
					
					dv2 = parseInt((soma % 11));
					if ((dv2 == 0) || (dv2 == 1))dv2 = 0;
					else dv2 = (11 - dv2);
					
					if (c2 != dv2)
						{
							alert ('O segundo dígito verificador do seu CPF não é válido. Favor verificar!');
							eval(input).focus();
							return false;
						}
				}
		}
	
	function limpa_string(S)
		{
			var Digitos = '0123456789';
			var temp = '';
			var digitos = '';
		
			for(var i = 0; i < S.length; i++)
				{
					digitos = S.charAt(i);
					if(Digitos.indexOf(digitos) >= 0)
						{
							temp = temp + digitos
						}
				}
			return temp
		}
	
	function valida_CNPJ(s)
		{
			var i;
			input = eval(s);
			s = limpa_string(input.value);
			var c = s.substr(0, 12);
			var dv = s.substr(12, 2);
			var d1 = 0;
			
			for (i = 0; i < 12; i++)
				{
					d1 += c.charAt(11 - i) * (2 + (i % 8));	
				}
			if(d1 == 0) return false;
			d1 = 11 - (d1 % 11);
			if(d1 > 9) d1 = 0;
			if(dv.charAt(0) != d1)
				{
					alert ('Primeiro dígito verificador inálido!');
					eval(input).focus();
					return false
				}
			d1 *= 2;
		
			for(i = 0; i < 12; i++)
				{
					d1 += c.charAt(11-i) * (2 + ((i + 1) % 8));
				}
			d1 = 11 - (d1 % 11);
			if(d1 > 9) d1 = 0;
			if(dv.charAt(1) != d1)
				{
					alert ('Segundo dígito verificador inálido!');
					eval(input).focus();
					return false
				}
			return true;
		}
	
	function PG(n)
		{
			var form = window.document.nav;
			form.CurrentPage.value = n;
			form.submit();
		}
	
	function validamail(obj)
		{
			input = eval(obj)
			if(input.value != '')
				{
					if((input.value.indexOf('@') < 0) || (input.value.indexOf('@') == 0) ||
					(input.value.substring((input.value.indexOf('@') + 1), input.value.length).indexOf('.') < 0) ||
					(input.value.charAt(input.value.indexOf('@') + 1) == '.'))
						{
							alert('E-mail inválido. Exemplo de um e-mail válido: jph@jph.com.br!')
							eval(input).focus()
							return false
						}
					else return true;
				}
		}
	
	function insereQuebraLinha(f)
		{
			var entrada = eval(f);
			var fe = entrada.elements;
			for(i = 0; i < fe.length; i++)
				{
					if(fe[i].type == 'textarea') fe[i].value = fe[i].value.replace(/\n/g, '<br />');
				}
		}
	
	function insereContraBarran(f)
		{
			var entrada = eval(f);
			var fe = entrada.elements;
			for(i = 0; i < fe.length; i++)
				{
					if(fe[i].type == 'textarea')
						{
							do
								fe[i].value = fe[i].value.replace('<br />', '\n');
							while(fe[i].value.indexOf('<br />') > -1);
							
							do
								fe[i].value = fe[i].value.replace('<br>', '\n');
							while(fe[i].value.indexOf('<br>') > -1);
							
							do
								fe[i].value = fe[i].value.replace('<BR>', '\n');
							while(fe[i].value.indexOf('<BR>') > -1);
							
							do
								fe[i].value = fe[i].value.replace('<Br>', '\n');
							while(fe[i].value.indexOf('<Br>') > -1);
						}
				}
		}
	
	function TrimReplace(f)
		{
			var entrada = eval(f);
			var fe = entrada.elements;
			for(i = 0; i < fe.length; i++)
				{
					if((fe[i].type == 'text') || (fe[i].type == 'textarea'))
						fe[i].value = fe[i].value.Trim();
				}
		}
	function JanelaPop(pagina, nome, w, h, scroll)
		{
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		propriedades = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'
		win = window.open(pagina, nome, propriedades)
		if (parseInt(navigator.appVersion) >= 4) { win.window.focus();}
		}
	function ContatoClass(email)
		{
		JanelaPop('/contato_class.asp?email='+email,'EnviarEmail','350','250','no')
		}
	function Enviar(id, caminho)
		{
		JanelaPop('http://www.jornalprimeirahora.com.br/email.asp?id='+id+'&link='+caminho,'EnviarEmail','350','320','no')
		}
	
	function EsqueciSenha()
		{
		JanelaPop('/lembrasenha.asp','bembrar','300','160','no')
		}
	function Imprimir(id, secao)
		{
		JanelaPop('/impressao.asp?id='+id+"&idsecao="+secao+'&list=1','imprimir','600','500','yes')
		}
	function Preenche(texto, valor, campo)
		{
		posicao=document.getElementById(campo).length++
		document.getElementById(campo).options[posicao] = new Option(texto,valor)
		document.getElementById(campo).selectedIndex = posicao
		}
	function PegaTecla()
		{
		return (document.all ? event.keyCode : -1);
		}
	function Deleta(campo, destino)
		{
		if (document.getElementById(campo).selectedIndex >= 0)
			{
			valor = document.getElementById(campo).options[document.getElementById(campo).selectedIndex].value
			window.location = destino+".asp?id=" + valor;
			document.getElementById(campo).options[document.geElementById(campo).selectedIndex]=null;
			document.getElementById(campo).selectedIndex=0;
			}
		}
	function Insere(campo, destino)
		{
		if (document.getElementById(campo).selectedIndex >= 0)
			{
			valor = document.getElementById(campo).options[document.getElementById(campo).selectedIndex].value
			window.location = destino+".asp?id=" + valor;
			document.getElementById(campo).options[document.geElementById(campo).selectedIndex]=null;
			document.getElementById(campo).selectedIndex=0;
			}
		}

