/****************************************************************************************
 Script to provide the correct countries for each continent using only one pulldown menu
                      Written by Mark Wilton-Jones, 13/9/2001
*****************************************************************************************

Please see http://www.howtocreate.co.uk/jslibs/ for details and a demo of this script
Please see http://www.howtocreate.co.uk/jslibs/termsOfUse.html for terms of use

To use this, the form must be called 'mainform' and the continent and country menus must
exactly match those shown below. If you change anything on the menus, you will have to
work out what to change in the script. Don't use any <body onload="whatever"> code.

The full countries list is given after the script.

To use this script, insert the following line between the <head> tags:

<script src="PATH TO SCRIPT/countryselect.js" type="text/javascript" language="javascript1.2"></script>

_______________________________________________________________________________________*/

var contin = new Array(); //each cell will hold an array of all the countries in a continent
var numincont = new Array(0,18,44,36,15,42,29,15); //number of countries in each continent
//prepare the continent arrays
for( var z = 1; z < numincont.length; z++ ) { contin[z] = new Array(); }
//tell it to set up the select menu when the page loads
window.onload = myprep;
function myprep() {
	//Because Netscape 4 will act strangely on reloading . . .
	if( document.getElementById("country_select").options.length < 60 ) { self.location.reload(); }
	//now that the document has fully loaded, take out all of the countries and put them into
	//an array representing that continent (the continent arrays)
	var y = 1; //y = number of options to bypass at the start - 1
	for( var z = 1; z < numincont.length; z++ ) {
		//each continent in turn. start at 1 because options[0] is 'Please select one'
		for( x = 1; x <= numincont[z]; x++ ) {
			//insert countries into arrays
			contin[z][x] = new Option(document.getElementById("country_select").options[x+y].text,document.getElementById("country_select").options[x+y].value);
		}
		//offset by the number we have already done
		y += numincont[z] + 1; //the 1 allows for the '       ------ Continent name ------' options
	}
	refillme();
}

function refillme() {
	//erase the select menu then refill it with all countries from the selected continent
	//the reason I deconstruct then reconstruct is to allow non JavaScript browsers to work
	while( document.getElementById("country_select").options.length ) { document.getElementById("country_select").options[0] = null; }
	if( document.getElementById("continent_select").selectedIndex ) {
		//they have selected a continent. insert a 'Please select one' option
		document.getElementById("country_select").options[0] = new Option("Please select one","");
		for( var z = 1; z < contin[document.getElementById("continent_select").selectedIndex].length; z++ ) {
			//for the selected continent, put in each country
			document.getElementById("country_select").options[z] = contin[document.getElementById("continent_select").selectedIndex][z];
		}
		//give them an 'Other' option and enable the select menu (if it was disabled)
		//document.getElementById("country_select").options[z] = new Option("Other (please use the box below)","Other");
		document.getElementById("country_select").disabled = false;
		applyprice(document.getElementById("continent_select").value);
	} else {
		//wait for them to select a continent
		document.getElementById("country_select").options[0] = new Option("Please select an area above","");
		document.getElementById("country_select").disabled = true;
	}
	document.getElementById("country_select").options[0].selected = true;
	//document.mainform.other.disabled = true;
}

function applyprice(continent) {
method = document.getElementById("ship_method").value;
if (method == "express_mail") {
	switch (continent){
	case "Arab_World":
		document.getElementById("other").value = 20;
		calculateprice();
	break;
	case "Africa":
		document.getElementById("other").value = 37;
		calculateprice();
	break;
	case "Asia":
		document.getElementById("other").value = 33;
		calculateprice();
	break;
	case "Australasia":
		document.getElementById("other").value = 37;
		calculateprice();
	break;
	case "Europe":
		document.getElementById("other").value = 33;
		calculateprice();
	break;
	case "North_America":
		document.getElementById("other").value = 37;
		calculateprice();
	break;
	case "South_America":
		document.getElementById("other").value = 37;
		calculateprice();
	break;
	default : 
		document.getElementById("other").value = 0;
		calculateprice();
	}
} else {
	switch (continent){
	case "Arab_World":
		document.getElementById("other").value = 7;
		calculateprice();
	break;
	case "Africa":
		document.getElementById("other").value = 10;
		calculateprice();
	break;
	case "Asia":
		document.getElementById("other").value = 9;
		calculateprice();
	break;
	case "Australasia":
		document.getElementById("other").value = 10;
		calculateprice();
	break;
	case "Europe":
		document.getElementById("other").value = 9;
		calculateprice();
	break;
	case "North_America":
		document.getElementById("other").value = 10;
		calculateprice();
	break;
	case "South_America":
		document.getElementById("other").value = 10;
		calculateprice();
	break;
	default : 
		document.getElementById("other").value = 0;
		calculateprice();
	}
}
}
	function CheckSame(Id)
	{
	if (document.getElementById("country_select").value == document.getElementById("info_country").value)
	{
	if (document.getElementById(Id).checked == true)
	{
				
			document.getElementById("shipping_fname").value = document.getElementById("info_fname").value;
			document.getElementById("shipping_lname").value = document.getElementById("info_lname").value;
			document.getElementById("shipping_address").value = document.getElementById("info_address").value;
			document.getElementById("shipping_postal").value = document.getElementById("info_postal").value;
			document.getElementById("shipping_city").value = document.getElementById("info_city").value;
			document.getElementById("shipping_state").value = document.getElementById("info_state").value;
	}
	else
	{	
			document.getElementById("shipping_fname").value = "";
			document.getElementById("shipping_lname").value = "";
			document.getElementById("shipping_address").value = "";
			document.getElementById("shipping_postal").value = "";
			document.getElementById("shipping_city").value = "";
			document.getElementById("shipping_state").value = "";
	}	
	} else {
	alert('You have to choose the same country of your persoanl information.');
	document.getElementById(Id).checked = false;
	}
	}
	
function ShippingSelect()
	{
		if 	(document.getElementById("ship_method").value == 0) {
		 document.getElementById("country_select").disabled = true;
		 document.getElementById("continent_select").disabled = true;
		} else {
		 document.getElementById("country_select").options[0].selected = true;		 
		 document.getElementById("continent_select").disabled = false;
		 document.getElementById("country_select").disabled = true;
		 document.getElementById("continent_select").options[0].selected = true;	
		 document.getElementById("other").value = 0;
		calculateprice();
		}
	}

function Calc()
	{
	document.getElementById("qtytot").value = document.getElementById("qty").value * 10;
	document.getElementById("totamount").value = document.getElementById("qtytot").value;
	}
function calculateprice()
	{
	document.getElementById("totamount").value = eval(document.getElementById("other").value) + 10;
	}



