function submit_form(){
	$("#l_form").submit();
}

function requestField(){
	id_elem = $("select option:selected").val();
	elem_txt = $("input[name=met"+id_elem+"]").val();
	if(elem_txt == undefined)
		$("#req").html("");
	else
		$("#req").html(elem_txt+":");
}

function checkAllPayment(id){
	if($("#"+id+" input[type=checkbox]").attr("checked") == true)
      $("#"+id).find("input[type=radio][value=1]").attr("checked", "checked");
     else
      $("#"+id).find("input[type=radio][value=1]").attr("checked", "");
}

function getPayment(id){
	$.getJSON("../ajax/payment.php", { "id": id },
   function(data){
   	$("#basic-modal-content").html('<tr><th>Month</th><th>Room</th><th>Sum</th></tr>');
   	total = 0;
     $.each(data, function(month,item){
     	$.each(item, function(i,val){
     		if(val.sum)
     			total += val.sum;
     		str = "<tr><td>"+month+"</td><td>"+val.room+"</td><td style='text-align: right;'>&euro;"+roundNumber(val.sum,2)+"</td></tr>";
     		$("#basic-modal-content").append(str);
     	});
    });	
    
    str = "<tr><td><b>Total</b></td><td colspan='2' style='text-align: right;'><b>&euro;"+roundNumber(total,2)+"</b></td></tr>";
     $("#basic-modal-content").append(str); 
   });
}

function getPNP(month, bonus, status){
	$.getJSON("../ajax/pnp.php", { "month": month, "bonus" : bonus, "status": status },
   function(data){
   	$("#basic-modal-content").html('<tr><th>Username</th><th>Room</th><th>Sum</th></tr>');
   	total = 0;
     
     	$.each(data, function(i,val){
     		total += val.pnp;
     		str = "<tr><td>"+val.user+"</td><td>"+val.room+"</td><td style='text-align: right;'>&euro;"+roundNumber(val.pnp,2)+"</td></tr>";
     		$("#basic-modal-content").append(str);
     	});
  
    str = "<tr><td><b>Total</b></td><td style='text-align: right;' colspan='2'><b>&euro;"+roundNumber(total,2)+"</b></td></tr>";
     $("#basic-modal-content").append(str); 
   });
}

function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  return newnumber;
}
