// Pridaj input file do formulara
 
var counter = 1;

function addField(origFieldID)
{
  counter++;
  var newField = document.getElementById(origFieldID).cloneNode(true);
  //alert(newField.name);
  newField.id = origFieldID + counter;
  //newField.name = 'userfile[]';
  //alert(newField.nodeType);
  //alert(newField.name);
  //alert(newField.type);
  
  members = newField.childNodes;
  for(i=0; i<members.length; i++)
  {
    //alert(members[i].type);
    if(members[i].type == 'file')
    {
      members[i].name = 'userfile[]';
    }
    else if (members[i].id == 'del')
    {
      members[i].id = '';
      members[i].href = 'javascript:delField("'+ newField.id + '")';
      //alert(members[i].href);
    }
  }
  
  newField.style.display = 'block';
  var insertHere = document.getElementById(origFieldID);
  insertHere.parentNode.insertBefore(newField,insertHere);
}

function delField(origFieldID)
{
  var node2kill = document.getElementById(origFieldID);
  node2kill.parentNode.removeChild(node2kill);
}


function getElementValue(formElement)
{
	if(formElement.length != null) var type = formElement[0].type;
	if((typeof(type) == 'undefined') || (type == 0)) var type = formElement.type;

	switch(type)
	{
		case 'undefined': return;

		case 'radio':
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].checked == true)
			return formElement[x].value;

		case 'select-multiple':
			var myArray = new Array();
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].selected == true)
					myArray[myArray.length] = formElement[x].value;
			return myArray;

		case 'checkbox': return formElement.checked;
	
		default: return formElement.value;
	}
}



function uprav(hod,aid) {

	var hodnoty = hod.split("-");
 
  var vys1 = hodnoty[0] / hodnoty[5] * 100; vys1 = Math.round(vys1*10)/10;
  var vys2 = hodnoty[1] / hodnoty[5] * 100; vys2 = Math.round(vys2*10)/10;
  var vys3 = hodnoty[2] / hodnoty[5] * 100; vys3 = Math.round(vys3*10)/10;
  var vys4 = hodnoty[3] / hodnoty[5] * 100; vys4 = Math.round(vys4*10)/10;
  var vys5 = hodnoty[4] / hodnoty[5] * 100; vys5 = Math.round(vys5*10)/10;
      
  $("#"+aid+'od_1').css( { width: vys1+'%' } ).show('normal'); $("#"+aid+'odp_1').text(vys1+'%'); $("#"+aid+'ot_1').text(hodnoty[6]);
  $("#"+aid+'od_2').css( { width: vys2+'%' } ).show('normal'); $("#"+aid+'odp_2').text(vys2+'%'); $("#"+aid+'ot_2').text(hodnoty[7]);
  $("#"+aid+'od_3').css( { width: vys3+'%' } ).show('normal'); $("#"+aid+'odp_3').text(vys3+'%'); $("#"+aid+'ot_3').text(hodnoty[8]);
  $("#"+aid+'od_4').css( { width: vys4+'%' } ).show('normal'); $("#"+aid+'odp_4').text(vys4+'%'); $("#"+aid+'ot_4').text(hodnoty[9]);
  $("#"+aid+'od_5').css( { width: vys5+'%' } ).show('normal'); $("#"+aid+'odp_5').text(vys5+'%'); $("#"+aid+'ot_5').text(hodnoty[10]);
        
  $("#"+aid+"anketa_oznam").html("<div style='padding:2px;margin-bottom:5px'>V tejto ankete si už hlasoval(a)!</div>");
      
}


function hlasuj(aid, oid) {

	$("#"+aid+"anketa_oznam").html("<div style='padding:2px;margin-bottom:5px'>Moment prosím...</div>");
	
	$.post("/query.php?do=anketa_hlas", { aid:aid, oid:oid }, 
		function(data){
 			if(data) uprav(data,aid);
		});
	
	return false;

}