// JavaScript Document

cor = '';
if(cor == '')
	cor = '#FFFFFF';
else
	cor = '#'+cor;

//
var css = '';

if(imagem != '')
	css  = cor+' url(recursos/imagens/background/'+imagem+')';
else
	css  = cor;

//
if(repeat == '1')
	css  += ' top left';
else
	css  += ' top center no-repeat fixed';


$(document).ready(function(){
	$("body").css('background', css);
	
	var altura = document.body.offsetHeight;
	$('#neblinaAlerta').css('height',altura);
	$('#neblinaAlerta').click(function(){
		$('#neblinaAlerta').hide();
		$('#excluidoSucesso').hide();
		$('#popup-editar-servicos').hide();
	});
});


function servicoProtocolo(obj, servico_id)
{
	var link_ = obj.href;
	clickServico(link_, servico_id);

	$.ajax({
	   type: "POST",
	   url: obj.href,
	   data: "",
	   success: function(retorno)
	   {
	   		window.location.href=retorno;
	   }
	});

	return false;
}



function clickServico(href, servico_id)
{
	var pars = '';

	pars = "servico_url=" + href;

	if(servico_id != '')
	{
		pars += "&servico_id=" + servico_id;
	}

	$.ajax({
	   type: "POST",
	   url:  'clicks/servico',
	   data: pars,
	   success: function() {
	   }
	});

	return true;
}




function adicionar(obj)
{
	$.ajax({
	   type: "POST",
	   url: obj.href,
	   data: "",
	   success: function(retorno){
			alert(retorno)
	   }
	});

	return false;
}





function validaCadastroServico()
{
	var isGrupos = false;
	
	$(".gruposCls").each(function() {
		if(this.checked)						  
			isGrupos = true;							  
	});
	
	if(!isGrupos)
	{
		alert($("#mensagemGrupo").attr("title"));
		return false;
	}
	
	
	var vetor =  "";
	$(".gruposCls").each(function() {
		if(this.checked == true && this.value != 'NAN')							  	
			vetor += "&grupos[]=" + this.value;							  
	});
	
	
	$.ajax({
	   type: "POST",
	   url: $("#formularioContato").attr("action"),
	   data: "contato_id=" + $("#contato_id").val() + vetor,
	   success: function(retorno)
	   {
		   $('#popup-adicionar-contato').html(retorno);
		}
	});
}



function adicionarContato(obj, usuario_id)
{
	var div = '#popup-adicionar-contato';
	
	$(div).html('');
	$(div).html('<img src="templates/site/img/ajaxServicos.gif" />');

	var posTop = document.documentElement.scrollTop;

	var topo = posTop + 100;
	$(div).css('top',topo);
	/* $('#neblinaAlerta').show(); */
	$(div).fadeIn('normal');

	$.ajax({
	   type: "GET",
	   url:  obj.href + '/usuario_id/' + usuario_id,
	   data: "",
	   success: function(retorno) {
	   		$(div).html(retorno);
	   }
	});
		
	return false;
}



function adicionarContatoLogin(usuario_id)
{
	var div = '#popup-adicionar-contato';
	window.location.href = 'login/index/add/' + usuario_id;
	
	return false;
}





function fecharEdicao()
{
	var div = '#popup-adicionar-contato';
	$('#neblinaAlerta').hide();
	$(div).hide();
}


function mostraAlertaAviso()
{
	$('#neblinaAlerta').show();

	var posTop = document.documentElement.scrollTop;
	var margem = screen.availHeight / 2;
	margem = margem - 174;

	var topo = posTop + margem;

	$('#alertaAguarde').css('top',topo);
	$('#alertaAguarde').fadeIn('normal');

	setTimeout("$('#alertaAguarde').hide(); $('#neblinaAlerta').hide()",5000);
}


function fecharExcluir(){
	$('#neblinaAlerta').hide();
	//$('#popup-excluir-servicos').hide();
}
