
function insert_paypal(amount, item_description, base_on_usd) {
	var seller = "john@modelaviationproducts.com"
	var exch_rate = 1.00;
	
	cad = '';
	usd = '';
	
	if (String(amount).indexOf('|') != -1) {
		price_array = String(amount).split('|');
		var cad     = parseFloat(price_array[0]);
		var usd     = parseFloat(price_array[1]);
	}
	
	else if (base_on_usd) {
		var cad = amount * exch_rate;
		var usd = amount;
	}
	else {
		var usd = amount / exch_rate;
		var cad = amount;
	}
	
	document.write('<table border="0" cellspacing="1" cellpadding="0">');
	
	if ((typeof HideCADPrices == 'undefined' || typeof HideCADPrices == undefined || HideCADPrices != true) && !isNaN(cad)) {
		cad = formatCurrency(cad);
		
		document.write(		
		  '<tr>' +
		    '<td valign="top"><nobr><img src="http://www.modelaviationproducts.com/images/flag_ca.png" align="absmiddle" width="23" height="13"> ' + cad + '</nobr></td>' +
		      '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="paypal">' +
		        '<td valign="top"><nobr>&nbsp;' +
			'<input type="input" size="1" value="1" name="quantity"> ' +
			'<input type="image" alt="Pay with PayPal" src="http://www.modelaviationproducts.com/images/paypal_add.gif" align="absMiddle" border="0" name="submit" width="41" height="23">' +
			'<input type="hidden" value="1" name="add">' +
			'<input type="hidden" value="_cart" name="cmd">' +
			'<input type="hidden" value="' + seller + '" name="business">' +
			'<input type="hidden" value="' + item_description + '" name="item_name">' +
			'<input type="hidden" value="' + cad + '" name="amount">' +
			'<input type="hidden" value="0" name="no_shipping">' +
			'<input type="hidden" value="1" name="no_note">' +
			'<input type="hidden" value="CAD" name="currency_code">' +
			'<input type="hidden" value="CA" name="lc">' +
			'<input type="hidden" value="PP-ShopCartBF" name="bn"></nobr></td>' +
		      '</form>' +
		     '</td>' +
		    '</tr>' +
		  '<tr>' +
		    '<td valign="top" colspan="2" bgcolor="#C0C0C0"><img src="http://www.modelaviationproducts.com/images/spacer.gif" align="absmiddle" width="1" height="1"></td>' +
		  '<tr>');
	}
		
	if (!isNaN(usd)) {
	   usd = formatCurrency(usd);
	  document.write(
	    '<td valign="top"><img src="http://www.modelaviationproducts.com/images/flag_us.png" align="absmiddle" width="23" height="13"> ' + usd + '</td>' +
	      '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="paypal">' +
	        '<td valign="top">&nbsp;' +
		'<input type="input" size="1" value="1" name="quantity"> ' +
		'<input type="image" alt="Pay with PayPal" src="http://www.modelaviationproducts.com/images/paypal_add.gif" align="absMiddle" border="0" name="submit" width="41" height="23">' +
		'<input type="hidden" value="1" name="add">' +
		'<input type="hidden" value="_cart" name="cmd">' +
		'<input type="hidden" value="' + seller + '" name="business">' +
		'<input type="hidden" value="' + item_description + '" name="item_name">' +
		'<input type="hidden" value="' + usd + '" name="amount">' +
		'<input type="hidden" value="0" name="no_shipping">' +
		'<input type="hidden" value="1" name="no_note">' +
		'<input type="hidden" value="USD" name="currency_code">' +
		'<input type="hidden" value="CA" name="lc">' +
		'<input type="hidden" value="PP-ShopCartBF" name="bn"></td>' +
	      '</form>' +
		'</tr>' +
		'</table>');
	}

}

function make_usd(cad) {
	var exch_rate   = 1.00;
	var usd = cad / exch_rate;
	usd = formatCurrency(usd);
	cad = formatCurrency(cad);
	document.write('- ' + cad + ' Cdn Funds<br>- ' + usd + ' US Funds')
}

function formatCurrency(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function openWindow(url, iwidth, iheight) {
	
  WinName = 'popup_' + String(Math.random()).replace(/\./gi, '');	
	
  var params = 'resizable,width='+iwidth+',height='+iheight
  popupWin = window.open(url, WinName, params)
  popupWin.focus()
}
