function Buy(licenseTypeId, count, paymethod)
{
  if(typeof(count) == "undefined")
    count = document.purchaseForm.elements['COUNT_' + licenseTypeId].value;

  if(typeof(paymethod) == "undefined")
  {
  	window.open('/purchase/payMethodSelect.php?LICENSE_TYPE_ID=' + licenseTypeId + '&COUNT=' + count,'PayMethodWindow','width=400,height=400,scrollbars=no,resizable=yes');
  	return;
  }

  var form = document.createElement('form');
  form.action = 'purchase/purchase.php';
  form.method = 'post';

  var input = document.createElement('input');
  input.type = "text";
  input.name = "LICENSE_TYPE_ID";
  input.setAttribute("value", licenseTypeId);
  form.appendChild(input);

  input = document.createElement('input');
  input.type = "text";
  input.name = "COUNT";
  input.setAttribute("value", count);
  form.appendChild(input);

  input = document.createElement('input');
  input.type = "text";
  input.name = "paymethod";
  input.setAttribute("value", paymethod);
  form.appendChild(input);

  document.body.appendChild(form);
  form.submit();
}

