var exchange_rate_usd = 0.75;
var exchange_rate_gbp = 0.39;
var gstation_price = 270;
var CDROM_price = 5;
//var component_price = 2025/65;
var component_price = 2565/85; // (gstation_price * individual game cost) / single user cost
var NZ_post = 4.30;
var AU_post = 4.50;
var SP_post = 4.50;
var EA_post = 5.00;
var US_post = 5.00;
var UK_post = 5.00;
var RW_post = 5.00;
//var price_factor = 65/270;
var price_factor = 85/270;
var delimitem = 'X';

function get_postage(country_code, ship_to_code){
	var the_postage = 0;

	if (ship_to_code == '00') {
		the_postage = 0;}
	if (ship_to_code == 'NZ') {
		the_postage = NZ_post;}
	if (ship_to_code == 'AU') {
		the_postage = AU_post;}
	if (ship_to_code == 'SP') {
		the_postage = SP_post;}
	if (ship_to_code == 'EA') {
		the_postage = EA_post;}
	if (ship_to_code == 'US') {
		the_postage = US_post;}
	if (ship_to_code == 'UK') {
		the_postage = UK_post;}
	if (ship_to_code == 'RW') {
		the_postage = RW_post;}

	if (country_code == 'US') {
		the_postage = the_postage * exchange_rate_usd;
	}

	return the_postage;
}

function get_price(country_code, product_id, license_type){
	var the_price = 0;

	if (product_id.substring(0,2) == 'r0') {
		the_price = component_price;
	} else {
		the_price = gstation_price;
	}

	if (license_type.indexOf('school') == -1) {
		the_price = the_price * price_factor;
	}

	if (product_id == 'r101') {
		the_price = the_price + CDROM_price;
	}

	if (country_code == 'US') {
		the_price = the_price * exchange_rate_usd;
	}

	if (country_code == 'UK') {
		the_price = the_price * exchange_rate_gbp;
	}

	return the_price;
}


function get_name (product_id){
	var the_name = '';

	if (product_id == 'r100') {
		the_name = 'Registration Key for Funmaths Game Station'; }
	if (product_id == 'r101') {
		the_name = 'Funmaths Game Station CD-ROM'; }
	if (product_id == 'r001') {
		the_name = 'Registration Key for Bingo'; }
	if (product_id == 'r002') {
		the_name = 'Registration Key for Bouncer'; }
	if (product_id == 'r003') {
		the_name = 'Registration Key for Stomper'; }
	if (product_id == 'r004') {
		the_name = 'Registration Key for Puzzler'; }
	if (product_id == 'r005') {
		the_name = 'Registration Key for Bomber'; }
	if (product_id == 'r006') {
		the_name = 'Registration Key for Plotter'; }
	if (product_id == 'r007') {
		the_name = 'Registration Key for Seeker'; }
	if (product_id == 'r009') {
		the_name = 'Registration Key for Thrower'; }
	if (product_id == 'r010') {
		the_name = 'Registration Key for Hopper'; }
	if (product_id == 'r011') {
		the_name = 'Registration Key for Dodger'; }
	if (product_id == 'r012') {
		the_name = 'Registration Key for Dodger Pro'; }

	return the_name;
}



function show_image(product_code, the_image){
	document.write ('<img src="images/' + product_code + '.gif" border="1">');
}


//Format field with two decimals
function formatamount(amount){
    var decpoint;
    var begin;
    var end;
    var valstr;
    var temp_char;

    amount = Math.round(amount * 100) / 100
    valstr = "" + amount;
    decpoint = valstr.indexOf(".")
    if (decpoint != -1) {
        begin = valstr.substring(0,decpoint);
        end = valstr.substring(decpoint+1,valstr.length);
	}
    else {
        begin = valstr;
        end = "";
	} 
	if (end.length < 2)
	 {while (end.length < 2)
	    {end += "0";}
	 }   
	end = end.substring(0,2);
    return (begin+"."+end);
}


function EncodeSearch (S)
{
	var NewS = S;
	var i = -1;

	i = NewS.indexOf(' ');
	while (i != -1) {
		NewS = NewS.substring(0,i) + '%20' + NewS.substring(i+1);
		i = NewS.indexOf(' ');
	}

	return NewS;
}

function DecodeSearch (S)
{
	var NewS = S;
	var i = -1;

	i = NewS.indexOf('%20');
	while (i != -1) {
		NewS = NewS.substring(0,i) + ' ' + NewS.substring(i+3);
		i = NewS.indexOf('%20');
	}

	return NewS;
}


// Get checked value from radio button.

function getRadioButtonValue (radio){
	for (var i = 0; i < radio.length; i++){
	   if (radio[i].checked) { break }
	}
	if(i<radio.length){return radio[i].value}
	else{return "nogood";}
}
