function views() {
    return [    
        { view: 'Button',   rect: '350 10 100 24',  anchors: 'left top', text: 'Calculează' },

        { view: 'TextField',rect:  '20 10 35 24', anchors: 'left top', value: "3", placeholder: 'text', id: 'q', style: { textAlign: 'center' } },
        { view: 'Label',    rect:  '10 34 50 24', anchors: 'left top', text: 'Cantitate', selectable: false },        

        { view: 'TextField',rect:  '75 10 120 24', anchors: 'left top', value: "?", placeholder: 'text', style: { fontWeight: 'bold', fontSize: '14px', textAlign: 'center' }, id: 'r' },
        { view: 'Label',    rect: '105 34 60 24', anchors: 'left top', text: 'Preț unitar', selectable: false },

        { view: 'TextField',rect: '230 10 25 24', anchors: 'left top', value: "24", placeholder: 'text', id: 'vat', style: { textAlign: 'center' }},
        { view: 'Label',    rect: '220 34 25 24', anchors: 'left top', text: 'TVA (%)', selectable: false },

        { view: 'TextField',rect: '290 10 50 24', anchors: 'left top', value: "100", placeholder: 'text', id: 'total', style: { textAlign: 'center' }},
        { view: 'Label',    rect: '300 34 50 24', anchors: 'left top', text: 'Total', selectable: false },        

        { view: 'Label',    rect:  '60 10 10 38', anchors: 'left top', text: 'x', selectable: false,  style: { fontWeight: 'bold', fontSize: '16px' }},        
        { view: 'Label',    rect: '205 10 10 38', anchors: 'left top', text: 'x', selectable: false,  style: { fontWeight: 'bold', fontSize: '16px' }},        
        { view: 'Label',    rect: '270 10 10 38', anchors: 'left top', text: '=', selectable: false,  style: { fontWeight: 'bold', fontSize: '22px' }}
    ];
}

// page layout
uki(
    { view: 'Box', rect: '0 0 500 0', minSize: '480 0', anchors: 'top left right width', childViews: 
        [
        { view: 'Box', rect: '0 0 450 60',  anchors: 'top left right width', childViews: views() } 
        ]
    }
        
).attachTo( document.getElementById('vat_calculator'));

uki("Button[text^=Calc]").click(
  function() {
    var r = uki('#r')[0];
    r.value(computeUnitPrice(uki('#q').value(), 
                             uki('#vat').value(), 
                             uki('#total').value()));
    r._input.select();
  }
);

uki('#r').click(function(e) {
    e.domEvent.target.select();
  }
);

function computeUnitPrice(q, vat, total) {
  try {
  	if (vat == null){
	    vat = 1.24;
  	}
    else {
      vat = 1.00 + (vat/100);
    }
    res = (total/(vat*q)).toFixed(4);
    if (isNaN(res) || res == -Infinity || res == Infinity) {
      return "eroare ?";
    }
    else {
      return res;
    }
  }
  catch(err){
    return ("eroare ?");
  }
}