function resizeForm(pFormId, pTableId)
{
  try
  {
    var pScrollHeight = document.body.scrollHeight;
    var pForm = parent.document.getElementById(pFormId);
    var pTable = document.getElementById(pTableId);
    if (pForm != null)
    {
      pForm.setAttribute("height", pTable.scrollHeight +2);
    }
  }
  catch(e)
  {
    window.status = 'Error: ' + e.number + '; ' + e.description;
  }
}

function _JSCommaChar()
{
  var dv = (2.2).toString();
  return dv.replace(/2/g, "")
}

function _JSToASPComma(s)
{
  if (_JSCommaChar() != _ASPCommaChar())
    s = s.replace(_JSCommaChar(), _ASPCommaChar());
  return s;
}
function _ASPToJSComma(s)
{
  if (_JSCommaChar() != _ASPCommaChar())
    s = s.replace(_ASPCommaChar(), _JSCommaChar());
  return s;
}
	
function numPart(n)
{
  var dv = _JSCommaChar();
  var s = "" + Math.round(n * 100) / 100;
  var i = s.indexOf(dv);
  if (i < 0) 
  {
    s += dv + "00";
    return _JSToASPComma(s);
  }
  var t = s.substring(0, i + 1) + s.substring(i +1, i +3);
  if (i + 2 == s.length) t += "0";
  return _JSToASPComma(t);
}

function kuponHesap()
{
    var adet = 0, oran = 0;
    var pKuponSistem = "";
    document.getElementById("kuponAdet").value = 0;
    document.getElementById("kuponOrt").value = 0;
    if(Number(document.getElementById("kuponCnt").value) > 0)
    {
				var pValue = "0";
        var baslangic = document.getElementById("kuponKmbn").value;
        var iterasyon = Number(document.getElementById("kuponCnt").value);
        for(var j = 0 ; j< iterasyon; j++)
        {
            var i = j + Number(baslangic);
            var pKuponSistemi = document.getElementById("kuponSistemi"+i.toString());
            if(pKuponSistemi != null && pKuponSistemi.checked)
            {
                if (pKuponSistem.length > 0) pKuponSistem += ","
                pKuponSistem = pKuponSistem + pKuponSistemi.value;
                pValue = document.getElementById("kuponAdeti"+i.toString()).value;
                pValue = _ASPToJSComma(pValue);
                adet += Number(pValue);
                pValue = document.getElementById("kuponOrani"+i.toString()).value;
                pValue = _ASPToJSComma(pValue);
                oran += Number(pValue);
            }
        }
    }
    var maxMoneyLimit = 500000;
    var miktar = document.getElementById("miktar").value;
    if (oran > maxMoneyLimit)
      oran = maxMoneyLimit / Math.round(miktar);
    document.getElementById("kuponAdet").value = adet;
    document.getElementById("kuponOrt").value = oran;
    document.getElementById("kuponBedeli").value = numPart(miktar * adet);
    document.getElementById("kuponKolonSayisi").value = adet;//miktar*adet;
    document.getElementById("kuponKazanci").value = numPart(miktar * oran);
    document.getElementById("kuponSistem").value = pKuponSistem;
   
    if(document.getElementById("kuponKazanci").value > 500000)
        document.getElementById("kuponKazanci").value = 500000;
        
    document.getElementById("kuponBedel").innerHTML = 
      document.getElementById("kuponBedeli").value;
    document.getElementById("kuponKolonSayi").innerHTML =
      document.getElementById("kuponKolonSayisi").value;
    document.getElementById("kuponKazanc").innerHTML =
      document.getElementById("kuponKazanci").value;
}
