function popitup(url) {
	var newwindow=window.open(url,'name','height=500,width=400,scrollbars=1');
	if (window.focus) {newwindow.focus()}
	return false;
}

function togglePayment()
{
  if ($('creditcard').checked) {
    $('creditcard').show();
  } else {
    $('creditcard').hide();
  }
}

  function copyBilling()
  {
    if ($('sb-identical').checked == true) {
      $('shipping-name').value = $('billing-name').value;
      $('shipping-company').value = $('billing-company').value;
      $('shipping-address1').value = $('billing-address1').value;
      $('shipping-address2').value = $('billing-address2').value;
      $('shipping-city').value = $('billing-city').value;
      $('shipping-state').value = $('billing-state').value;
      $('shipping-zip').value = $('billing-zip').value;
      $('shipping-country').value = $('billing-country').value;
    } else {
      $('shipping-name').value = "";
      $('shipping-company').value = "";
      $('shipping-address1').value = "";
      $('shipping-address2').value = "";
      $('shipping-city').value = "";
      $('shipping-state').value = "";
      $('shipping-zip').value = "";
      $('shipping-country').value = "";    
    }

  }
  
  function disableZfwPrint()
  {
    if ($('zfw-pdf').checked == true) {
      $('zfw-print').checked = false;
      $('bpm3e-zfw-bundle').checked = false;
    }
    
    updateTotal();
    
  }
  
  function disableZfwPdf()
  {
    if ($('zfw-print').checked == true) {
      $('zfw-pdf').checked = false;
      $('bpm3e-zfw-bundle').checked = false;
    }
    
    updateTotal();
    
  }  
  
  function enableBpm3e()
  {
    if ($('bpm3e-print').checked == true) {
      $('bpm3e-zfw-bundle').checked = false;
    }
    
    updateTotal();
   
  }
  
  function enableBundle()
  {
    if ($('bpm3e-zfw-bundle').checked == true) {
      $('zfw-pdf').checked = false;
      $('zfw-print').checked = false;
      $('bpm3e-print').checked = false;
    }
   
    updateTotal();
    
  }
  
	function currencyFormatted(amount)
	{
		var i = parseFloat(amount);
		if(isNaN(i)) { i = 0.00; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		s = new String(i);
		if(s.indexOf('.') < 0) { s += '.00'; }
		if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		return s;
	}  
  
  function updateTotal()
  {
    var total = 0.00;
    
    if ($('zfw-pdf').checked == true) {
      total = parseFloat(total) + parseFloat($('zfw-pdf-price').innerHTML);
    }
    
    if ($('zfw-print').checked == true) {
      total = parseFloat(total) + parseFloat($('zfw-print-price').innerHTML);
    }    
    
    if ($('bpm3e-print').checked == true) {
      total = parseFloat(total) + parseFloat($('bpm3e-print-price').innerHTML);
    } 
    
    if ($('bpm3e-zfw-bundle').checked == true) {
      total = parseFloat(total) + parseFloat($('bpm3e-zfw-bundle-price').innerHTML);
    } 
    
    total = currencyFormatted(total);
        
    document.getElementById('total').innerHTML = total;
    
  }  
  
  function applyDiscount()
  {
  
    var code = $('discount').value;
    
    var myAjax = new Ajax.Request('https://www.easyphpwebsites.com/buy/applydiscount',
      {method: 'get', parameters: {code: code},
      onComplete: postResponse});
  }
  
  function postResponse(transport)
  {
  
    if (transport.responseText != false)
    {
    
      var values = transport.responseText.split("|");
      
      if (values[0] != 0.00)
      {
          $('discount-error').innerHTML = "<b>Discount description</b>: " + values[2];
      } else {
          $('discount-error').innerHTML = "<b>Sorry, but this discount code does not exist or has expired.</b>";
      }
            
    }
    
  }  
  
  
  