    var iVar = 0;
    var gp_from = "USD";
	var gp_amount = "";
    function gp_currencySymbols() {

	$.getJSON("http://www.geoplugin.net/currency_symbols.gp?format=json&jsoncallback=?",
		function(data){
			var currencyCode = geoplugin_currencyCode();
			var toCurr = '';
			$.each(data, function(i,item){
				if ( i == 'AUD' ) {
					toCurr = toCurr + "<option value='"+i+"' selected>"+item.name+" "+(item.symbol?item.symbol:'')+"</option>";
				} else {
					toCurr = toCurr + "<option value='"+i+"'>"+item.name+" "+(item.symbol?item.symbol:'')+"</option>"; //{condition)? iftrue : iffalse
				}
			});
			$(toCurr).appendTo("#gp_to");
		});
};
function gp_convertIt(convertType) {
    gp_to = convertType;
	iVar = 0;
	for (var i = 0; i < document.forms.length; i++) {    
	    gp_amount = document.forms[i].gp_amount.value;
		getJsonNow(convertType);
		wait(1000);
    }
}
function getJsonNow (convertType){   
	$.ajax({
       type: 'GET',
       url: "http://www.geoplugin.net/currency_converter.gp?jsoncallback=?",
	   dataType: 'json',
       success: function(output){
   			 output.to.amount = output.to.amount.replace(/,/g,'');
			 output.to.amount = output.to.amount.substring(0,output.to.amount.indexOf('.')-1);
			 var amountArray = output.to.amount.split("");
			 var numEnd = amountArray.length;
			 
			 for (i=numEnd;i>1;i--) {  
				 if (parseFloat(amountArray[i]) > 4) {  
				     k = i - 1;
				     amountArray[k] = parseFloat(amountArray[k])+ 1;	
					 if (amountArray[k] == "10") {
					    amountArray[k] = "9";
					  }
				 } 
				amountArray[i] = 0;
			 }
             numAmount = amountArray.join("");
			 numAmount = parseFloat(numAmount).toFixed(2)
             numAmount = addCommas(numAmount);
	         var stuffOut ="<div style='padding:5px'>"+output.to.symbol+numAmount;
	         iVar = iVar + 1;
    	     idToLoadto = "#gp_converted" + iVar;
			 if (convertType == 'AUD') {
			    stuffOut = stuffOut + " AUD +GST </div>"; }
			 else { stuffOut = stuffOut + "</div>"; }
			 $(idToLoadto).html(stuffOut);
             },
       data: {from:gp_from, to:gp_to, amount:gp_amount},
	   async: false
     });
}
function wait(delay) {
  var start = new Date().getTime(); 
  while (new Date().getTime() < start + delay);
} 

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


