
function saveAttribute(obj) {
	var dataToSend = {
		name: obj.id.split("-")[0],
		id: obj.id.split("-")[1],
		value: (obj.type=="checkbox"?(obj.checked?1:0):obj.value)
	};
	
	$.ajax({
		type: "POST",
		url: "/ajax/setattribute",
		data: dataToSend,
		success: function(response){
			alert("Saved!");
		}
	});
}

function filterList(url) {
	window.location.href = url;
}


function onRated(obj, doyourjob) {
	
	var data = jQuery(obj).parent("div").attr("id").split("-");
	
	if (doyourjob != true) {
		$("#ratingdisplay-"+data[1]).html("?");
		setTimeout(function(obj) { onRated(obj, true); }, 2000, obj);
		return;
	}
	
	$.ajax({
		type: "POST",
		url: '/rating/ajax/getresult',
		dataType: 'json',
		data: {
			identifier: 'stock#'+data[1]
		},
		success: function(response){
			if (response.errorcode == 0) {
				$("#ratingdisplay-"+data[1]).html(response.data.result);
			}
		}
	});
}


$(document).ready(function(){
	
	jQuery.each($('.rating'), function() {
		var data = this.id.split("-");
		$(this).rating('/rating/ajax/vote?identifier=stock%23'+data[1], {maxvalue:5, curvalue:data[2]});
    });
});

