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();

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{
		sendNewsLetter();
	}
}
function sendNewsLetter(){
	document.formNewsLetter.submit();
	jAlert('Informações enviadas com sucesso!','Atenção',function(){
			document.getElementById('campo_texto_caixa_newsletter').value = '';
	});
}

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 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 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");
	setTimeout("DataHora()",1000);
}

function dropHide(){
	$("#divDropMenu").hide();
}

function gotoItemSecao(textH2) {
	if(textH2){
		var $item = $(".itemSecao:has(h2:contains('"+textH2+"'))");
		if($item.length > 1){
			window.location.href = "#"+textH2;
			for(var i = 0; i < $item.length; i++){
				var $i = $item.filter(":eq("+i+")");
				if($i.children("h2:first").text() == textH2){
					$item = $i;
					break;
				}
			}
		}
		$("html, body").animate({scrollTop : ($item.offset().top - 20)},{ duration : 500, complete : function(){
			var $h2 = $item.find("h2:first");
			$h2.css({"text-decoration" : "underline"});
			setTimeout(function(){$h2.css({"text-decoration" : "none"});},750);
		}});
	}
}

$(function() {
	if(!$.browser.msie){
		$(window).scroll(function(){
			var scrollTop = $(window).scrollTop();
			if(scrollTop != 0)
				$('#nav').stop().animate({'opacity':'0.2'},400);
			else			
				$('#nav').stop().animate({'opacity':'1'},400);
		});
		$('#nav').hover(
				function (e) {
					var scrollTop = $(window).scrollTop();
					if(scrollTop != 0){
						$('#nav').stop().animate({'opacity':'1'},400);
					}
				},
				function (e) {
					var scrollTop = $(window).scrollTop();
					if(scrollTop != 0){
						$('#nav').stop().animate({'opacity':'0.2'},400);
					}
				}
		);
	}
	$("#plusSearch").click(function(){
		$("#caixa_busca").slideDown('slow');
		$("#plusSearch, #plusIntegra, #plusNewsletter").hide();
		$("#minusSearch").css({"display":"block"});
	});
	$("#minusSearch").click(function(){
		$("#minusSearch").hide('fast');
		$("#caixa_busca").slideUp('slow',function(){
			$("#plusSearch, #plusIntegra, #plusNewsletter").fadeIn();
		});
	});
	$("#plusIntegra").click(function(){
		$("#caixa_integra").slideDown('slow');
		$("#plusSearch, #plusIntegra, #plusNewsletter").hide();
		$("#minusIntegra").css({"display":"block"});
	});
	$("#minusIntegra").click(function(){
		$("#minusIntegra").hide('fast');
		$("#caixa_integra").slideUp('slow',function(){
			$("#plusSearch, #plusIntegra, #plusNewsletter").fadeIn();
		});
	});
	$("#plusNewsletter").click(function(){
		$("#caixa_newsletter").slideDown('slow');
		$("#plusSearch, #plusIntegra, #plusNewsletter").hide();
		$("#minusNewsletter").css({"display":"block"});
	});
	$("#minusNewsletter").click(function(){
		$("#minusNewsletter").hide('fast');
		$("#caixa_newsletter").slideUp('slow',function(){
			$("#plusSearch, #plusIntegra, #plusNewsletter").fadeIn();
		});
	});
});

function init(){
//	var $source = $("img.img_slide").attr("src");
//	$('#page-body').css({
//		'backgroundImage': 'url(' + $source +')',
//		'backgroundRepeat': 'no-repeat',
//		'backgroundPosition': 'top center'
//	});
//	$("#imgTopo .img_slide").hide();
	
	if($.browser.msie && $.browser.version == 6){
		$("#alert").show();
		$("body").css({"background-image":"none","background-color":"#cccccc"});
		$("#home").hide();
		$("#topoAlert").corner("cc:#8c8c8c top 10px");
		$("#alertBox").corner("cc:#8c8c8c 10px");
	}
	if($.browser.msie && $.browser.version == 7){
		$("#home #fraseEfeito").css({"margin-top":"-52px"});
		$("#contato .buttonContato").css({"margin-left":"45px"});
		$("#caixa_busca.caixa_servicos").css({"width":"288px"});
		$(".servicosNav").css({"float":"right"});
		$("#menu").css({"float":"left"});
	}

	$("#logo").click(function(){ window.location.href = '/home.jsp' });

	$("#abaExtra br").remove();
	$("#depoimentos br").remove();
	
	$("#menu .itemMenu, #divDropMenu .itemMenu").mouseover(function(){
		$(this).addClass("menuOver");
	}).mouseout(function (){
		$(this).removeClass("menuOver");
	});
	$(".menu li, #divDropMenu .itemMenu").click(function(){ window.location.href = $(this).find("a:first").attr("href"); });
	$('#menu .itemMenu a, #divDropMenu .itemMenu a').each(function(){ 
		var link = $(this).attr("href"); 
		$(this).closest("li").click(function(){ 
			window.location.href = link; });
	});
	var $liMenuMais = $("#menuMais");
	$liMenuMais.bind("mouseover",function(event){
		$("#divDropMenu").css({
			"top"	:	$liMenuMais.outerHeight(true),
			"left"	:	$liMenuMais.offset().left - 20
		});
		$("#divDropMenu").show();
	});
	$liMenuMais.add("#divDropMenu").bind("mouseout",function(event){
		if($(event.relatedTarget).closest("#divDropMenu").length == 0){
				$("#divDropMenu").hide()
		};
	});
}
