// JavaScript Document
swfobject.registerObject("index", "9.0.0", "swfobject/expressInstall.swf");
var i_price,invoice;
var Rm={
	'IL':'2.81',
	
	'AU':'7.52',
	'NZ':'7.52',
	
	'RU':'4.71',
	'AD':'4.71',
	'AL':'4.71',
	'AT':'4.71',
	'BE':'4.71',
	'BA':'4.71',
	'BG':'4.71',
	'CZ':'4.71',
	'DK':'4.71',
	'EE':'4.71',
	'FR':'4.71',
	'DE':'4.71',
	'GR':'4.71',
	'HU':'4.71',
	'IE':'4.71',
	'IT':'4.71',
	'LV':'4.71',
	'LI':'4.71',
	'LT':'4.71',
	'LU':'4.71',
	'NL':'4.71',
	'PL':'4.71',
	'PT':'4.71',
	'RO':'4.71',
	'SM':'4.71',
	'SK':'4.71',
	'SI':'4.71',
	'ES':'4.71',
	'CH':'4.71',
	'TR':'4.71',
	'GB':'4.71',
	'VA':'4.71',
	
	'US':'5',
	'CA':'4.71',
	
	'AR':'5.73',
	'BR':'5.73',
	'EC':'5.73',
	'CO':'5.73',
	'CL':'5.73',
	'PE':'5.73',
	'MX':'5.73',
	'VE':'5.73',
	
	'BO':'7.52',
	'GT':'7.52',
	'UY':'7.52',
	'SV':'7.52',
	'PA':'7.52',
	'CR':'7.52',
	'BZ':'7.52',
	'NI':'7.52',
	
	'SE':'5.73',
	'FI':'5.73',
	'NO':'5.73',
	'IS':'5.73',
	
	//'HK':'5.73',
	'C2':'5.73',
	'TW':'5.73',
	'KR':'5.73',
	'JP':'5.73'
};
var rm={
	'IL':'1',
	
	'AU':'6.11',
	'NZ':'6.11',
	
	'RU':'3.3',
	'AD':'3.3',
	'AL':'3.3',
	'AT':'3.3',
	'BE':'3.3',
	'BA':'3.3',
	'BG':'3.3',
	'CZ':'3.3',
	'DK':'3.3',
	'EE':'3.3',
	'FR':'3.3',
	'DE':'3.3',
	'GR':'3.3',
	'HU':'3.3',
	'IE':'3.3',
	'IT':'3.3',
	'LV':'3.3',
	'LI':'3.3',
	'LT':'3.3',
	'LU':'3.3',
	'NL':'3.3',
	'PL':'3.3',
	'PT':'3.3',
	'RO':'3.3',
	'SM':'3.3',
	'SK':'3.3',
	'SI':'3.3',
	'ES':'3.3',
	'CH':'3.3',
	'TR':'3.3',
	'GB':'3.3',
	'VA':'3.3',
	
	'US':'3.61',
	'CA':'3.3',
	
	'AR':'4.33',
	'BR':'4.33',
	'EC':'4.33',
	'CO':'4.33',
	'CL':'4.33',
	'PE':'4.33',
	'MX':'4.33',
	'VE':'4.33',
	
	'BO':'6.11',
	'GT':'6.11',
	'UY':'6.11',
	'SV':'6.11',
	'PA':'6.11',
	'CR':'6.11',
	'BZ':'6.11',
	'NI':'6.11',
	
	'SE':'4.33',
	'FI':'4.33',
	'NO':'4.33',
	'IS':'4.33',
	
	'HK':'4.33',
	'C2':'4.33',
	'TW':'4.33',
	'JP':'4.33'
};
var rm_undef='7';
var Rm_undef='8';
function Money(m){
	m=Math.round(m*100)/100;
	m=m==Math.floor(m)?m+'.00':m*10==Math.floor(m*10)?m+'0':m;
	return m;
}
function Calculate(){
	var c=$('#country_code').val();
	var mt=$('#shipping_method').val();
	var m,t;
	if(c){
		if(mt=='rm') m=rm[c]?rm[c]:rm_undef;
		else m=Rm[c]?Rm[c]:Rm_undef;
		var s=m*1;
		t=Money(s+i_price);
		$('#taxes').text('$'+Money(s));
		$('#shipping').val(Money(s));
	}else{
		$('#taxes').text('-');
		t=Money(i_price);
	}
	$('#total').text('$'+t);
}
function Strip_tags(str){
	return str.replace(/<[^<>]+>/g,'. ');
}
function Hide(){
	$.ajax({
		type:'POST',
		url:'paypal/handler.php?f=deinvoice',
		data:'order_id='+$('#invoice').val(),
		// success:function(ans){ alert(ans); },
		error:function(){alert('Error!');}
	});
	$('#form_bg').remove(); $('#form').remove();
}
function Ajax(url,data,mode){
	$.ajax({
		type:'POST',
		url:url,
		data:data,
		success:function(msg){if(mode=='html')return msg; else displayMessage(msg);},
		error:function(){alert('Error!');}
	});
}
function Buy(custom,price,item_name,text){
	i_price=price*1;
	$.ajax({
		type:'POST',
		url:'paypal/handler.php?f=invoice',
		data:'item_id='+custom+'&mc_gross='+price+'&mc_currency=USD&item_name='+item_name,
		success:function(inv){
			invoice=inv;
			$('body').append('<div id="form"></div>');
			$('#form').load('paypal/paypal_form.html',function(){ 
				var m=Money(price);
				$('#paypal').prepend(
					'<h3>'+item_name+'<span>$'+m+'</span></h3>'
					+'<h4>Shipping and handling: <span id="taxes">-</span></h4>'
					+'<h3 class="total">Total: <span id="total">$'+m+'</span></h3>'
					+'<p>'+Strip_tags(text)+'</p>'
					);
				$('#form').show();
				$('#item_name').val(item_name);
				$('#custom').val(custom);
				$('#amount').val(Money(price));
				$('#invoice').val(inv);
				$('#country_code').bind('change',function(){ Calculate(); $('#real_country').val($(this).children('option:selected').text()); });
				$('#shipping_method').bind('change',function(){ Calculate(); });
				$('#close').bind('click', function(){ Hide(); });
				$('#paypal input:visible, #paypal select:visible').bind('change',function(){
					var id='#'+$(this).attr('id');
					checkEl($(id),a[id],true);
					checkAll(false);
				});
				$('#paypal input:visible').bind('keyup',function(){
					checkAll(false);
				});
				$('#submit').bind('click',function(){ checkAll('btn'); });
			});
			$('#form').after('<div id="form_bg"></div>');
			return 'www';
		},
		error:function(){alert('Error!');}
	});
}
