// funcoes gerais PARTE PUBLICA
$(function () {
    $('#menu_index').each(function () {
        $(this).toggle(function () {
            $('#caixa').slideToggle('fast');
        }, function () {
            $('#caixa').slideToggle('fast');
        });
    });
    $("#tabs").tabs();
    $("#carousel").featureCarousel();

    // tooltips
    // exemplo: <a href="link.html" title="texto do tooltip" class="tooltip" />
    $('.tooltip').tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        fade: 250
    });

    $('.imagem-tooltip').tooltip({
        delay: 0,
        showURL: false,
        bodyHandler: function () {
            return $("<img/>").attr("src", this.src);
        }
    });

    $(".HiddenDiv").click(function () {
        $(this).fadeOut("slow");
    });
});
//login e senha
//function login() {
//    cidade_digitada = document.getElementById('email').value;

//    if (cidade_digitada == "seu login") {
//        document.getElementById('email').value = "";
//    }
//    else {
//        document.getElementById('email').value = cidade_digitada;
//    }
//}

//function verifica_login() {
//    cidade_digitada = document.getElementById('email').value;

//    if (cidade_digitada == "") {
//        document.getElementById('email').value = "seu login";
//    }
//    else if ((cidade_digitada != "seu login") && (cidade_digitada != "")) {
//        document.getElementById('email').value = cidade_digitada;
//    }
//}
//function senha1() {
//    cidade_digitada = document.getElementById('senha').value;

//    if (cidade_digitada == "sua senha") {
//        document.getElementById('senha').value = "";
//    }
//    else {
//        document.getElementById('senha').value = cidade_digitada;
//    }
//}

function CheckLogin() {    
    var s = document.getElementById('senha').value, l = document.getElementById('email').value;

    if (s == "" || l == "") {
        document.getElementById('email').focus();
        alert("Entre com seu login e senha !");
        return false;
    }
}

//google analytics
var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-17715597-1']);
	_gaq.push(['_trackPageview']);

	(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();

/// Cria uma caixa de mensagem de erro
// tipo : 0 - para notificacao, 1 - para erro
// container : elemento que recebera a caixa de dialogo
// mensagem : mensagem de erro para ser exibida
function Mensagem(tipo, container, mensagem) {
    var icone = "ui-icon-alert";
    var text = "Alerta:";
    var estilo = "ui-state-error ";

    if (tipo == 0) {
        icone = "ui-icon-info";
        text = "Atenção:";
        estilo = "ui-state-highlight ";
    };

    var erroDialog = "<div id='erroContainer' class='ui-widget'>" +
            "<div class='" + estilo + " ui-corner-all' style='padding: .7em .7em .7em .7em;'>" +
		    "<p style='text-align : left;'><span class='ui-icon " + icone + "' style='float: left; margin-right: .3em; margin-left: .3em;'></span>" +
		    "<strong>" + text + "</strong> " + mensagem + "</p></div></div>";

    $(container).html(erroDialog);
};

var max = 250; /* Total de caracteres */
var ancho = 300;
function contaTextarea(valor) {
    var barrinha = document.getElementById("barrinha");

    if (valor.value.length < max) {
        barrinha.style.backgroundColor = "#ddd";
        barrinha.style.backgroundImage = "url(barrinha.jpg)"; /* Aqui fica o outro endereço da barrinha */
        barrinha.style.color = "#000000";
        var pos = ancho - parseInt((ancho * parseInt(valor.value.length)) / 250); /* Total de caracteres */
        barrinha.style.backgroundPosition = "-" + pos + "px 0px";
    } else {
        barrinha.style.backgroundColor = "#BB0000";
        barrinha.style.backgroundImage = "url()";
        barrinha.style.color = "#FFFFFF";
    }
    barrinha.innerHTML = "(" + valor.value.length + " / " + max + ")";
};

function abrir_foto(URL) {
    var width = 600;
    var height = 400;
    var left = 99;
    var top = 99;
    window.open(URL, 'login_foto', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=yes, fullscreen=no');
};

function abrir(URL) {
    var width = 500;
    var height = 450;

    var left = 99;
    var top = 99;

    window.open(URL, 'chamado', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
};

function abrircompra(URL) {
    var width = 500;
    var height = 300;
    var left = 99;
    var top = 99;

    window.open(URL, 'Popup', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=yes, fullscreen=yes');

}

function abrircompra2() {
    var width = 500;
    var height = 300;
    var left = 99;
    var top = 99;

    window.open('', 'Popup', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=yes, fullscreen=yes');
 //   document.form.submit();
}


function altera_dependente(URL) {
    var width = 700;
    var height = 500;
    var left = 99;
    var top = 99;
    window.open(URL, 'alteradependente', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=yes, fullscreen=yes');
};

function right(e) {
    var msg = "Sem permissão";
    if (navigator.appName == 'Netscape' && e.which == 3) {
        alert(msg);
        return false;
    };

    if (navigator.appName == 'Microsoft Internet Explorer' && event.button == 2) {
        alert(msg);
        return false;
    }
    else return true;
};

function trap() {
    if (document.images) {
        for (i = 0; i < document.images.length; i++) {
            document.images[i].onmousedown = right;
            document.images[i].onmouseup = right;
        }
    }
};
