function montarSelect(alvo, data, selected, text) {
	jQuery("<option>").attr("value", '').text(text).appendTo("#"+alvo);
	for (var e in data) jQuery("<option>").attr("value", e).text(data[e]).appendTo("#"+alvo);
	jQuery('#'+alvo).val(selected);
}

//o value do select é o mesmo valor da tag
function montarSelect2(alvo, data, selected, text) {
	jQuery("<option>").attr("value", '').text(text).appendTo("#"+alvo);
	for (var e in data) jQuery("<option>").attr("value", data[e]).text(data[e]).appendTo("#"+alvo);
	jQuery('#'+alvo).val(selected);
}

function mostra_comissao(id) {

    if(id != "") {        
         jQuery.ajax({
            url: '/pedido/detalhes_comissao/'+id,
            success: function(data){

                for(i = 1; i < 5; i++) {
                    jQuery('#comissao'+i).hide();
                    jQuery('#origem'+i).val('');
                    jQuery('#valor'+i).val('');
                    jQuery("#idOrigem"+i).val('');
                }

                for(i = 1; i < data.tamanho + 1; i++) {
                    jQuery('#comissao'+i).show();
                    jQuery("#origem"+i).val(data[i].titulo);
                    jQuery("#valor"+i).val(data[i].valor);
                    jQuery("#idOrigem"+i).val(data[i].id);
                }

            },
            dataType: 'json'
        });
    }

        /*jQuery.post('/pedido/detalhes_comissao/'+id,  function(data) {
            //jQuery('#comissao').html(data);
            alert(data.titulo);
        });
    } 
    else {
        jQuery('#comissao').html("");
    }*/
}

function mostra_produtos(produto_id, admin) {

	jQuery.post('/pedido/detalhes/'+produto_id+'/'+admin,  function(data) {
		if (jQuery('#meus_produtos_'+produto_id).html() == '') {
			jQuery('#meus_produtos_'+produto_id).html(data);
			jQuery('#mostra_'+produto_id).attr('src', "/img/icon_menos.gif");
		}
		else {
			jQuery('#mostra_'+produto_id).attr('src', "/img/icon_mais.gif");
			jQuery('#meus_produtos_'+produto_id).html('');
		}
	});
}

function formatItem(row) {
	return row[0] + " (<strong>id: " + row[1] + "</strong>)";
}

function formatResult(row) {
	return row[0].replace(/(<.+?>)/gi, '');
}

