// Direct payment
	function fnValidatePayment() {
		// Get the paymentref object
		var res = false; 
		var frm = document.forms[0];
		var pref = frm.paymentref.value;
		if(pref == "") {
			window.alert("You must include a payment reference.");
			frm.paymentref.focus();
		} else {
			var pamount = frm.paymentamt.value;
			if(pamount == "") {
				window.alert("You must specify an amount.");
				frm.paymentamt.focus();
			} else {
				var v = parseFloat(pamount);
				if((v < 1) || (v == 0)) {
					window.alert("Please enter a valid amount.");
					frm.paymentamt.focus();
				} else {
					res = true;
				};
			};
		};
		if(res == true) { frm.submit(); };
	};

// Step 1
	function Step1() { document.frmProduct.rbProduct[0].focus(); };

	function fnValidateStep1() {
		// Get the quantity object
		var res = false; var qty = document.forms[0].qty;
		if(qty) {
			var q = parseInt(qty.value);
			if((q < 0) || (q == 0)) {
				window.alert("Please enter a quantity greater than 0.");
				qty.focus();
			} else {
				res = true;
			};
		};
		if(res == true) { document.forms[0].submit(); };
	};

// Step 2
	function Step2() { document.frmLicense.rbLicense[0].focus(); };

	function fnValidateStep2() {
		// Get the license object and type
		// rbLicense, ebCompany, ebVAT
		var res = false; 
		var frm = document.forms[0];	//frmLicense;
		var rb = frm.rbLicense;
		if(rb) {
			if(rb[0].checked) {
				res = true;				// Personal license
			} else {
				var company = frm.ebCompany.value;	// Corporate license
				if(company == "") {
					window.alert("For a corporate license, you must enter the name of the company.");
					frm.ebCompany.focus();
				} else {
					var vat = frm.ebVAT.value;
					if(vat == "") {
						window.alert("For a corporate license, you must enter the companys VAT/registration number.");
						frm.ebVAT.focus();
					} else {
						res = true;
					};
				};
			};
		};
		if(res == true) { frm.submit(); };
	};

// Step 3
	function Step3() { document.forms[0].rbPMethod[0].focus(); };
	function fnValidateStep3() { document.forms[0].submit(); };

// Step 4
	function Step4() { document.forms[0].Name.focus(); };

	function CountryFromEmail() {
		var sEmail, sExt, s, i, frm
		frm = document.forms[0];
		sEmail = frm.Email.value;
		sExt = ""; s = ""; i = 0;

		if (sEmail!="") {
			s = sEmail.substring(sEmail.length-3, sEmail.length);
			i = s.indexOf(".");
			sExt = s.substring(i+1, s.length).toUpperCase();
			if (sExt!="") {
				switch(sExt) {
					case "COM" : sExt = "US"; break;
					case "NET" : sExt = "US"; break;
					case "MIL" : sExt = "US"; break;
					case "EDU" : sExt = "US"; break;
					case "GOV" : sExt = "US"; break;
					case "ORG" : sExt = "US"; break;
					case "UK"  : sExt = "GB"; break;
				};
				for (i=0; i<frm.Country.length; i++) {
					if(frm.Country.options[i].value == sExt) { 
						frm.Country.selectedIndex = i; break;
					};
				};
			};
		};
	};

	function fnValidateStep4() {
		// Validate!
		if(ValidateStep4Ex()) {
			document.forms[0].submit();	// frmAddress
		};
	};

	function ValidateStep4Ex() {
		var s = ""; var s2 = ""; var i = 0;
		var sErrors = ""; var obj;
		var bOK = false;
		var form = document.forms[0];	//frmAddress

		function Require(sValue, MinLen, bNumber, sMsg, focusObj) {
			var bValid = false; var s = "";
			if (bNumber) {
				bValid = ((sValue!="")&&(isNaN(parseInt(sValue))==false));
				if (bValid) { 
					s = sValue.toString();
					bValid = (s.length>=MinLen); 
				}
			} else {
				bValid = (sValue.length>=MinLen);
			}
			if (bValid==false) {
				sErrors += (sMsg + "\n");
				if ((focusObj)&&(!obj)) { obj = focusObj; }
			}
			return bValid;
		}

		// Billing Address
		Require(form.Name.value, 5, false, "Name", form.Name);
		Require(form.Address.value, 5, false, "Address", form.Address);
		Require(form.Zipcode.value, 4, false, "Zipcode", form.Zipcode);
		Require(form.City.value, 2, false, "City", form.City);
		s = form.Country.options[form.Country.selectedIndex].value;
		Require(s, 2, false, "Country", form.Country);
		if (s.toUpperCase()=="US") {
			Require(form.State.value, 2, false, "State (US)", form.State);
		}

		s = form.Email.value;
		s2 = s.substring(s.length-4, s.length);
		x = s2.indexOf(".");
		if ((s=="")||(s.indexOf("@")<1)||(x>1)||(x<0)) {
			sErrors += "Email\n"; 
			if (!obj) { obj = form.Email; } 
		}

		s = form.Password.value;
		if (s=="") {
			sErrors += "Password\n"; 
			if (!obj) { obj = form.Password; } 
		}

		// Any errors ?
		if (sErrors=="") {
			form.JSValidated.value = "TRUE";
			return true;
		} else {
			sErrors = "The following fields have not been filled out correctly :\n\n" + sErrors;
			form.JSValidated.value = "FALSE";
			window.alert(sErrors);
			if (obj) { obj.focus(); }
			return false;
		}
	};

// Step 5
	function fnValidateStep5() { document.forms[0].submit(); };	// frmPreview
