var intervalo = setInterval(atualiza, 500);
function atualiza(){
	atualizaSombra();
	
	var centroReady = false;
	var $centro = $("#centro script");
	if($centro.length && $centro.text().toLowerCase().indexOf("feed") > 0){
		centroReady =  $("#itens_jusbrasilAtualiza_lista").length > 0;
	}
	else{
		centroReady =  $("#centro").length > 0;
	}
	
//	if($("#logo").height() > 0){
//		$("#logo").css("marginTop", (55 - $("#logo").height()/2));
//		$("#topoContent").css("marginTop",( 110 - $("#logo").height() - $("#logo").css("marginTop").replace("px", "")) );
//	}
	
	if( centroReady ){
		$("#shadowRight, #shadowLeft").css("height",$("#principal").outerHeight(false));
	}
	
	$("#frasePosicionamento p").css("marginTop",$("#frasePosicionamento").height() - $("#frasePosicionamento p").height());
}
$(window).resize(function(){
	atualizaSombra();
});

$(function(){
	$(document).pngFix();
});

function atualizaSombra(){
	$("#shadowRight, #shadowLeft").css("height",$("#principal").outerHeight(false));
}

function validateMail(str)
{
	if(!str){
		return false;
	}
	if( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(str) ){
		return true;
	}
	return false;
}
/*
*	All png images must be a child of a span tag with class = "clearPng"

if(navigator.userAgent.toLowerCase().indexOf("msie 6") != -1){
	$(function(){
		$('.clearPng').pngFix();
	});
}
*/
function BrowserCheck() {
	var uA = new String(navigator.userAgent);
	if(uA.match(/firefox/gi)){
		this.app = "Firefox";
	}
	else if(uA.match(/chrome/gi)){
		this.app = "Chrome";
	}
	else if(uA.match(/safari/gi)){
		this.app = "Safari";
	}
	else if(uA.match(/opera/gi)){
		this.app = "Opera";
	}
	else if(uA.match(/msie/gi)){
		this.app = "Internet Explorer";
	}
	else{
		this.app = navigator.appName;
	}
	
	this.ns = (this.app=="Netscape" && this.v>=4);
	this.firefox = this.app == "Firefox";
	this.chrome = this.app == "Chrome";
	this.safari = this.app == "Safari";
	this.opera = this.app == "Opera";
	this.ie = this.app == "Internet Explorer";
	this.unknown = !(this.ns || this.firefox || this.chrome || this.safari || this.opera || this.ie);
	
	var version = new String(navigator.appVersion);
	if (this.ie){
		var vs = navigator.appVersion.substring(navigator.appVersion.indexOf('MSIE'));
		this.v = parseInt(vs.substring(5,vs.indexOf(';')));
	}
	else if(!this.unknown){
		var toMatch = (this.safari ? "Version" : this.app) + "/";
		var idx = version.indexOf(toMatch) + toMatch.length;
		this.v = parseFloat(version.substring(idx,version.indexOf(' ',idx)));
	}
	else{
		this.v = parseInt(version);
	}
	
	this.toString = function(){
		return this.app + " versão " + this.v;
	}
}

var browser = new BrowserCheck();

var dias_semana = new Array("Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "S&aacute;bado");

var mes_ = new Array("Janeiro", "Fevereiro", "Mar&ccedil;o", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro","Outubro","Novembro","Dezembro");

function DataHora(){
	var data = new Date();
	var diaS = data.getDay();
	var dia = data.getDate();
	var ano = data.getFullYear();
	var mes = data.getMonth();
	var tempo = document.getElementById("tempo");
	tempo.innerHTML = dias_semana[diaS] + ", " + dia + " de " + mes_[mes] + " de " + ano;
	setTimeout("DataHora()",1000);
}
function apareceMenuMais(aparece, posicao){
	var div = document.getElementById('divDropMenu').style;
	if (aparece){
		if (posicao == 'h'){
			document.getElementById('divDropMenu').style.left=($("#menuMais").offset().left)+"px";
		}
		else{
			document.getElementById('divDropMenu').style.left = ( $("#menu ul").offset().left)+"px";
			document.getElementById('divDropMenu').style.top = ($("#menuMais").offset().top + $("#menuMais").height() + 5) +"px";
		}
		$("#divDropMenu").show();
		if($.browser.msie && $.browser.version == 6){
			$("#combo_caixa_busca").hide();
		}
	}else{
		$("#divDropMenu").hide();
		if($.browser.msie && $.browser.version == 6){
			$("#combo_caixa_busca").show();
		}
	}
	
}

function ValidaDados()
{
	if (document.getElementById("campo_usuario_caixa_integra").value.lenght == 0)
	{
		jAlert('O campo usu&aacute;rio &eacute; obrigat&oacute;rio.','Atenção',function(){
			document.getElementById('campo_usuario_caixa_integra').focus();
		});
		return false;
	}
	if (document.getElementById("campo_senha_caixa_integra").value.lenght == 0)
	{	
		jAlert('O campo senha &eacute; obrigat&oacute;rio.','Atenção',function(){
			document.getElementById('campo_senha_caixa_integra').focus();
		});
		return false;
	}
	return true;
}	
function validaNewsLetter(){
	if(!validateMail(document.getElementById('campo_texto_caixa_newsletter').value)){
		jAlert('Favor preencher o campo E-mail corretamente.','Atenção',function(){
		document.getElementById('campo_texto_caixa_newsletter').focus();
		});
	}
	else{
		sendNews();
	}
}
function sendNews(){
	document.formNewsLetter.submit();
	jAlert('Informações enviadas com sucesso!','Atenção',function(){
			document.getElementById('campo_texto_caixa_newsletter').value = '';
	});
}

function validaApoiadorForm(){
	var nomeCampo = new Array();
	if(document.getElementById('nome').value == ''){
	
		jAlert('Favor preencher o campo Nome corretamente.','Atenção',function(){
			document.getElementById('nome').focus();
		});
		
	}
	else if(!validateMail(document.getElementById('idName').value)){
	//else if(document.getElementById('idName').value == ""){
		jAlert('Favor preencher o campo E-mail corretamente.','Atenção',function(){
			document.getElementById('idName').focus();
		});
	}
	else if(document.getElementById('tel').value == ''){
		jAlert('Favor preencher o campo Telefone corretamente.','Atenção',function(){
			document.getElementById('tel').focus();
		});
		
	}
	
	else{
		
		sendContato();
		
	}
}

function clearFields(){
	document.getElementById('nome').value = '';
	document.getElementById('idName').value = ''; 
	document.getElementById('tel').value = '';
	document.getElementById('msg').value = '';
}

function sendContato(){
	document.contatoForm.submit();
	clearFields();
	jAlert('Informações enviadas com sucesso!','Atenção');
	//alert('Informações enviadas com sucesso!');
}
function runLogin(){
	$("#formLogin").hide();
	$("#box").hide();
	$("#imgLoginFixo").click(function(){
		$("#formLogin").height($(document).height()+5).width($(window).width());
		$("#box").css("align", "center").css("margin-top", "-"+($("#box").height()/2)+"px").css("margin-left", "-"+($("#box").width()/2)+"px");
		$("#box").show();
		$("#formLogin").show();
		$('html,body').animate({scrollTop: 0}, 1000);
	});
}

