
var URL_DIG = "/domains/vote/dig";
var URL_BURY = "/domains/vote/bury";


function VoteCounter(counter, plus, minus) {
	this.domid = counter.id.substring("counter_".length);
	this.counter = counter;
	this.plus = plus;
	this.minus = minus;
	this.onDug = function(xml) {
		var result = xml.getElementsByTagName('result');
		if (!result || result.length < 1) return;
		var code = result[0].getAttribute('code');
		var data = result[0].firstChild.data;
		if (code != '0') {
			alert(data);
			return;
		}
		this.counter.innerHTML = data;
	};
	
	this.dig_it = function(evt) {
		xmlPost(URL_DIG, "domain_id=" + this.domid, this.onDug.bind(this));
	};
	this.bury_it = function(evt) {
		xmlPost(URL_BURY, "domain_id=" + this.domid, this.onDug.bind(this));
	};
	
	Event.observe(plus, 'click', this.dig_it.bindAsEventListener(this));
	Event.observe(minus, 'click', this.bury_it.bindAsEventListener(this));
}


VoteCounter.prototype = {
};

/*

function setupCounters(doc) {
	var domlist = $('domainlist');
	
	if (!domlist || !domlist.childNodes)
		return;

	var domains = domlist.childNodes;
	for (i = 0; i < domains.length; i++) {
		var dom = domains[i];
		if (dom.tagName != "DIV" || dom.className != "domlist")
			continue;
			
		if (!dom.childNodes)
			return;

		var nlist = dom.childNodes;
		for (j = 0; j < nlist.length; j++) {
			var counter = nlist[j];
			if (counter.className != "vote_counter")
				continue;
				
			// find all TDs
			var tds = counter.getElementsByTagName('td');
			for (k = 0; k < tds.length; k++) {
				var td = tds[k];
				var voteCounter;
				var votePlus;
				var voteMinus;
				switch (td.className) {
					case 'counter':
						voteCounter = td;
						break;
					case 'plus':
						votePlus = td;
						break;
					case 'minus':
						voteMinus = td;
						break;
				}
				
			}
			
			// found all the elements of the vote counter?
			if (voteCounter && votePlus && voteMinus) {
				new VoteCounter(voteCounter, votePlus, voteMinus);
			}			
		}
	}
}


//Event.observe(window, 'load', setupCounters);


*/


function dig_it(id)
{
	xmlPost(URL_DIG, "domain_id="+id, function() { alert("ok"); });
}


function bury_it(id)
{
	xmlPost(URL_BURY, "domain_id="+id, function() { alert("ok"); });
}
