$(document).ready(function() {

	$('#divDepo').load('ppizza.php?action=depoimentoload');

	$('#btnDepo').click(function() {
		jQuery.blockUI({
        message: jQuery('#windowsDepoimentos'),
        css: {
            top:  (jQuery(window).height() - 300) /2 + 'px',
            left: (jQuery(window).width() - 350) /2 + 'px',
            width: '350px'
	        }
	    });
    });

    $('#btnCancelar').click(function() {
    	$.unblockUI('#windowsDepoimentos');
    	$('#txtNome').val('');
    	$('#txtDepo').val('');
    	$('#txtEmail').val('');
    });

    $('#btnEnviar1').click(function() {
		if( $('#txtNome').val() == '' || $('#txtDepo').val() =='' ){
			alert("Preencha o campo nome e o depoimento!");
		}else{
			$.post('ppizza.php?action=depoimentoi',
			{
			 txtNome: $('#txtNome').val(),
			 txtEmail: $('#txtEmail').val(),
			 txtDescricao: $('#txtDepo').val()
			},
			function(data){
				alert('Seu depoimento foi salvo em nossa base de dados. Obrigado');
				$.unblockUI('#windowsDepoimentos');
			});
		}

    });

    $('#btnEnviar2').click(function() {

		valores = '';
    	$(".chM").each(function()
		{
			if (this.checked){
				//valores += this.value + ',';
				valores += $(this).attr("iddep") + ',';
			}
		});
		var ids1 = valores;
		$.post('ppizza.php?action=depoimentoUpdate',
		{
		 ids:ids1
		},
		function(data){
			alert('Foram alterados os depoimentos a serem mostrados. Obrigado '+data);
			$('#divDepo').html('Carregando...');
			$('#divDepo').load('ppizza.php?action=depoimentoload');
			//alert(data);
		});
    });

    $('.btnDeleteDepo').click(function(){
    	var str = this.id;
    	var strid = str.substr(3,str.length);

    	$.post('ppizza.php?action=depoimentoDel',
		{
		 ids:strid
		},
		function(data){
			alert('O depoimento foi excluido. Obrigado');
			location.href = 'depoimentos.php';
		});

    });


});

