﻿function calcPrice()
{
  var tbCount = $get('ctl00_c_tbCount');
  var count = 0;
  try
  {
    count = parseInt(tbCount.value);
  }
  catch (e)
  {
  }
  
  if (count > 0)
  {
    var lPrice = $get('ctl00_c_lPrice');
    var lDiscountedPrice = $get('ctl00_c_lDiscountedPrice');
    var lAllPrice = $get('ctl00_c_lAllPrice');

    var discount = parseFloat($get('ctl00_c_hDiscount').value);

    
    var price = 1;
    var extraFix = 0;
    var extraPercentage = 1;
    
    var f;
    for (var i=0; i<document.forms[0].length; i++) 
    {
      f = document.forms[0].elements[i];
      if (f.type == 'radio')
      { 
        if (f.checked)
        {
          price += parseInt(f.attributes.getNamedItem("price").nodeValue);
        } 
      }
      if (f.type == 'checkbox')
      { 
        if (f.checked)
        {
          extraFix += parseInt(f.attributes.getNamedItem("price").nodeValue);
          extraPercentage += parseFloat(f.attributes.getNamedItem("percentage").nodeValue) / 100;
        } 
      }
    }
    price--;
    
    var priceExtra = Math.round(price * extraPercentage + extraFix);
    lPrice.innerHTML = String.localeFormat("{0:c:0}", priceExtra) + " + Áfa";
    
    var priceExtraDiscount = Math.round(priceExtra - (priceExtra * discount / 100));
    lDiscountedPrice.innerHTML = String.localeFormat("{0:c:0}", priceExtraDiscount) + " + Áfa";
    
    var priceExtraDiscountCount = Math.round(priceExtraDiscount * count);
    lAllPrice.innerHTML = String.localeFormat("{0:c:0}", priceExtraDiscountCount) + " + Áfa";
    
  }
}



function onEnterTextBox(evt,frm) 
{
  var keyCode = null;
  if( evt.which ) 
  {
    keyCode = evt.which;
  } 
  else 
  {
    if( evt.keyCode ) 
    {
      keyCode = evt.keyCode;
    }
  }
  if( 13 == keyCode ) 
  {
    __doPostBack(frm,'');
    return false;
  }
  return true;
}



