Vouting = function(vtgId)
{
	this.vtgId = vtgId;

	this.vtgGlobalBlockId = 'vtg-blc-'+vtgId;
	this.vtgGlobalBlockLoadId = 'vtg-blc-load-'+vtgId;

	this.vtgEachBlockId = 'vtg-blc-vout-';

	this.vtgEachBlockTitleId = 'vtg-blc-title-';

	this.vtgEachBlockQuestionsId = 'vtg-blc-q-'+vtgId;
	this.vtgEachBlockResultsId = 'vtg-blc-r-'+vtgId;

	this.vtgEachBlockQuestionId = 'vtg-blc-var-q-';
	this.vtgEachBlockQuestionInputId = 'vtg-blc-inp-';

	this.vtgEachBlockResultId = 'vtg-blc-var-r-';
	this.vtgEachBlockResultLineId = 'vtg-blc-var-rl-';

	this.inputSelected = false;

	var pointer = this;

	$('input',$('#'+this.vtgEachBlockQuestionsId)).click(function(){pointer.variantOnClick(this)});
}

Vouting.prototype.variantOnClick = function(ele)
{
	var varId = ele.name.replace(this.vtgEachBlockQuestionInputId,'');

	if(this.inputSelected){
		if(this.inputSelected != varId)
			ele.checked = false;
		return;}

	this.inputSelected = varId;

	this.doRequest(varId);
}

Vouting.prototype.doRequest = function(varId)
{
	var pointer = this;
	$.get("vouting.php", {varId: varId}, function(data){pointer.getReguest(data)});
}

Vouting.prototype.getReguest = function(data)
{

	if(data == 0)
		return false; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

	var variant = Array();
	var variantsResult = Array();
	data = data.split('\n');
	for(v in data){
		variant = data[v].split('-');
		if(variant.length < 4) continue;

		variantsResult[v] = variant;}

	if(variantsResult.length > 0)
		this.showResult(variantsResult);
	else
		return false; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}

Vouting.prototype.showResult = function(data)
{
	$('#'+this.vtgEachBlockQuestionsId).hide();
	$('#'+this.vtgEachBlockResultsId).show();

	if(data.length == 0)
		return;

	var span = Array();
	for(v in data)
	{
		$('#'+this.vtgEachBlockResultLineId + data[v][1]).hide();

		$('span',$('#'+this.vtgEachBlockResultId + data[v][1]))[1].innerHTML = data[v][3] + '%'; // %
		$('span',$('#'+this.vtgEachBlockResultId + data[v][1]))[2].innerHTML = '('+data[v][2]+')'; // %

		$('#'+this.vtgEachBlockResultLineId + data[v][1]).css('width',data[v][3]+'%');
		$('#'+this.vtgEachBlockResultLineId + data[v][1]).show(1000);
	}




}
