var zIndexImages = Array();

$(function(){
	var images = '#fotos img';
	if($(images)){
		$(images).mouseover(imageTop);
		$(images).mouseout(imageBack);
		$('#bg').css('opacity', 0.7);
	}
});

var imageTop = function(){
	var classImg = $(this).attr('class');
	zIndexImages[classImg] = $(this).css('zIndex');
	$(this).css('zIndex', 6);
	classImg = null;
}

var imageBack = function(){
	var classImg = $(this).attr('class');
	$(this).css('zIndex', zIndexImages[classImg]);
	classImg = null;
}

var showPage = function(page, width, height){
	var windowHeight = $('html').css('height');
	windowHeight = windowHeight > 1000 ? windowHeight : 1000;
	
	$('#bg').css('height', windowHeight);
	$('#bg').show();
	
	var idPage = '#'+page;
	width = width ? width : 518;
	height = height ? height : 330;
	
	var marginLeft = -(width/2);
	$(idPage).width(width);
	$(idPage).css('margin-left', marginLeft);
	$('.fechar').css('margin-left', marginLeft);
	$('.fechar').width(width + 35);
		
	var marginTop = -(height/2)-10;
	$(idPage).height(height);
	$(idPage).css('margin-top', marginTop);
	$('.fechar').css('margin-top', marginTop - 20);
	
//	alert(marginTop);
		
	$('#conteudo').show();
	$(idPage).show();
	idPage = null;
	marginLeft = null;
	marginTop = null;
}

var hidePage = function(){
	$('#bg').hide();
	$('#conteudo .box:visible').hide();
	$('#conteudo').hide();
}

var validaFormInsc = function(objForm, admin){
	admin = admin ? true : false;
	
	if(!admin){
		var categorias = $('.categoria').get();
		var categoriasOk = false;
		for(chave in categorias){
			if(categorias[chave].checked){
				categoriasOk = true;
			}
		}
	
		if(!categoriasOk){
			alert("Selecione uma categoria!");
			categorias[0].focus();
			return false;
		}
	}
	
	if(!objForm.nome.value.length){
		alert("O campo Nome é obrigatório!");
		objForm.nome.focus();
		return false;
	}else if(!validaCpf(objForm.cpf.value)){
		alert("O número do CPF é inválido!");
		objForm.cpf.focus();
		return false;
	}else if(!objForm.rg.value.length){
		alert("O campo RG é obrigatório!");
		objForm.rg.focus();
		return false;
	}else if(objForm.cnpj.value.length && !validaCnpj(objForm.cnpj.value)){
		alert("O número do CNPJ é inválido!");
		objForm.cnpj.focus();
		return false;
	}else if(!objForm.endereco.value.length){
		alert("O campo Endereço é obrigatório!");
		objForm.endereco.focus();
		return false;
	}else if(objForm.uf.value.length < 2){
		alert("O campo Uf está inconpleto!");
		objForm.uf.focus();
		return false;
	}else if(!objForm.cidade.value.length){
		alert("O campo Cidade é obrigatório!");
		objForm.cidade.focus();
		return false;
	}else if(objForm.cep.value.length < 9){
		if(!objForm.cep.value.length)
			alert("O campo Cep é obrigatório!");
		else
			alert("O campo Cep está incompleto!");
		objForm.cep.focus();
		return false;
	}else if(objForm.telefone.value.length < 14){
		if(!objForm.telefone.value.length)
			alert("O campo Telefone é obrigatório!");
		else
			alert("O campo Telefone está incompleto!");
		objForm.telefone.focus();
		return false;
	}
	
	if(objForm.fax.value.length){
		if(objForm.fax.value.length < 14){
			alert("O campo Fax está incompleto!");
			objForm.fax.focus();
			return false;
		}
	}
		
	if(!validaEmail(objForm.email.value)){
		alert("O email é inválido!");
		objForm.email.focus();
		return false;
	}
	return true;
}

var validaFormContato = function(objForm){
	if(!objForm.nome.value.length){
		alert("O campo Nome é obrigatório!");
		objForm.nome.focus();
		return false;
	}else if(!validaEmail(objForm.email.value)){
		alert("O email é inválido!");
		objForm.email.focus();
		return false;
	}else if(!objForm.assunto.value.length){
		alert("O campo Assunto é obrigatório!");
		objForm.assunto.focus();
		return false;
	}else if(!objForm.mensagem.value.length){
		alert("O campo Menssagem é obrigatório!");
		objForm.mensagem.focus();
		return false;
	}
	return true;
}

var openGol = function(){
	window.open("http://gol.directtalk.com.br/clientes/custom/voegol/eventos_pax/init_pax.htm", "JANELA");
}