// JavaScript Document
//this shit was all hand coded by me, and im a total javascript noob!
//define some default values organized by country zone
var shippingclass = 0;
var shippingus = [];
shippingus[0] = 'United States<br />Puerto Rico<span class="shipdisclaimer">*</span>';
shippingus[1] = '$5.69';
shippingus[2] = '$8.49';
shippingus[3] = '$9.99';
shippingus[4] = 'free!';

var shippingus2 = [];
shippingus2[0] = 'United States<br />Puerto Rico<span class="shipdisclaimer">*</span>';
shippingus2[1] = '$9.99';
shippingus2[2] = '$12.99';
shippingus2[3] = '$14.99';
shippingus2[4] = '$16.99';

var shippingus3 = [];
shippingus3[0] = 'United States<br />Puerto Rico<span class="shipdisclaimer">*</span>';
shippingus3[1] = '$24.99';
shippingus3[2] = '$34.99';
shippingus3[3] = '$44.99';
shippingus3[4] = '$54.99';

var shippingca = [];
shippingca[0] = 'Canada*';
shippingca[1] = '$6.99';
shippingca[2] = '$12.99';
shippingca[3] = '$28.99';
shippingca[4] = 'free!';

var shippingca2 = [];
shippingca2[0] = 'Canada*';
shippingca2[1] = '$14.99';
shippingca2[2] = '$16.99';
shippingca2[3] = '18.99';
shippingca2[4] = '22.99';

var shippingmx = [];
shippingmx[0] = 'Mexico*';
shippingmx[1] = '$9.99';
shippingmx[2] = '$19.99';
shippingmx[3] = '$24.99';
shippingmx[4] = '$29.99';

var shippingmx2 = [];
shippingmx2[0] = 'Mexico*';
shippingmx2[1] = '$24.99';
shippingmx2[2] = '$29.99';
shippingmx2[3] = '$34.99';
shippingmx2[4] = '$39.99';

var shippingeu = [];
shippingeu[0] = 'Europe*';
shippingeu[1] = '$13.99';
shippingeu[2] = '$25.99';
shippingeu[3] = '$36.99';
shippingeu[4] = '$47.99';

var shippingeu2 = [];
shippingeu2[0] = 'Europe*';
shippingeu2[1] = '$30.99';
shippingeu2[2] = '$36.99';
shippingeu2[3] = '$46.99';
shippingeu2[4] = '$56.99';

var shippingelse = [];
shippingelse[0] = 'Other*';
shippingelse[1] = '$12.99';
shippingelse[2] = '$23.99';
shippingelse[3] = '$38.99';
shippingelse[4] = '$47.99';

var shippingelse2 = [];
shippingelse2[0] = 'Other*';
shippingelse2[1] = '$36.99';
shippingelse2[2] = '$39.99';
shippingelse2[3] = '$46.99';
shippingelse2[4] = '$56.99';

var others = [];
others[0] = 'Australia';
others[1] = 'China';
others[2] = 'Japan';
others[3] = 'Korea (Republic)';
others[4] = 'New Zealand ';
others[5] = 'Singapore';

//function to uncheck radio buttons when you need to switch country codes!

//show the shipping method based on what country you chose
function showMethod(){
	var countryclass = document.shipping_country.country_select.value;
	if (countryclass == 'United States'){
		document.getElementById('radio1').checked = "checked";
		document.getElementById('ship_method1').style.display = "inline";
		document.getElementById('ship_method2').style.display = "none";
		document.getElementById('ship_method3').style.display = "none";
		shippingclass = 1;
	}
	else if (countryclass == 'Canada'){
		document.getElementById('radio2').checked = "checked";
		document.getElementById('ship_method1').style.display = "none";
		document.getElementById('ship_method2').style.display = "inline";
		document.getElementById('ship_method3').style.display = "none";
		shippingclass = 2;
	}
	else {
		document.getElementById('radio3').checked = "checked";
		document.getElementById('ship_method1').style.display = "none";
		document.getElementById('ship_method2').style.display = "none";
		document.getElementById('ship_method3').style.display = "inline";
		shippingclass = 3;
	}
}

function changeCountry(txt){
	
   	document.getElementById('country').innerHTML = txt[0];
	document.getElementById('price1').innerHTML = txt[1];
	document.getElementById('price2').innerHTML = txt[2];
	document.getElementById('price3').innerHTML = txt[3];
	document.getElementById('price4').innerHTML = txt[4];
	
}
//try to find out if the country is european or some other crazy place
function findCountry(country){
for (var i=0; i < others.length; i++){
  if (others[i] == country){
    return "yes";
    }
	else {
		return "no";
	}
}	
}

//decide which country to show based on what value is sent by the form
function makeText(){
//get our basic value based on menu selection
var country_name = document.shipping_country.country_select.value;

//get value of radio button using the stupid function
for (var i=0; i < document.shipping_country.method.length; i++){
  if (document.shipping_country.method[i].checked){
    var type = document.shipping_country.method[i].value;
    }
}
//decide what values to show based on country and shipping method selected
if (shippingclass == 1){
	
	switch(type){
		case '1':
			var country_set = shippingus;
			break;
		case '2':
			var country_set = shippingus2;
			break;
		case '3':
			var country_set = shippingus3;
			break;
		default: alert("oops..");
		}
	}
else if (shippingclass == 2){
	switch(type){
		case '4':
			var country_set = shippingca;
			break;
		case '5':
			var country_set = shippingca2;
			break;
		default: alert("oops..");
	}
}
else if (shippingclass == 3){
	var found = findCountry(country_name);
	if (found == 'no')
	switch(type){
		case '6':
			var country_set = shippingeu;
			break;
		case '7':
			var country_set = shippingeu2;
			break;
		default: alert("oops..");
	}
	else {
		switch(type){
			case '6':
				var country_set = shippingelse;
				break;
			case '7':
				var country_set = shippingelse2;
				break;
			default: alert("oops..");
		}
	}
			
	}
country_set[0] = country_name + '<span class="shipdisclaimer">*</span>';
changeCountry(country_set);
}