// webshop javascript functions

function popup(pageName, wide, high, forminfo) {
	var countryval = "country="+escape(forminfo.country.options[forminfo.country.options.selectedIndex].text);
	var amountval = "amount="+forminfo.amount.options[forminfo.amount.options.selectedIndex].value;
	var submitSTR = amountval+"&"+countryval;
		pageName = open(pageName+"?"+submitSTR, "shipping", "width="+wide+",height="+high+",resizeable=no,scrollbars=no");
	return false;
}

function checkOrder() {
	if (document.purchase.first_name.value == "" && document.purchase.first_name.value == ""){
		alert("Please submit either a first or last name.");
		return false;
	}

	if (document.purchase.address.value == ""){
		alert("A street number is needed.");
		return false;
	}

	if (document.purchase.city.value == ""){
		alert("Please fill in the city");
		return false;
	}
	if (document.purchase.country.options[document.purchase.country.options.selectedIndex].text == ""){
		alert("Please choose a country.");
		return false;
	}

	if (document.purchase.country.options[document.purchase.country.options.selectedIndex].text == "USA" && document.purchase.province.value.length != 2){
		alert("Please use a two letter state/province name.");
		return false;
	}

	if (document.purchase.postal_code.value == ""){
		alert("Please submit a postal or zip code.");
		return false;
	}

	if (document.purchase.phone.value == ""){
		alert("A telephone number is needed.");
		return false;
	}

	if (document.purchase.email.value == ""){
		alert("You need to provide an email address so that we may notifiy you of your order status.");
		return false;
	}

	if (document.purchase.email.value.indexOf("@") < 1){
		alert("You need to provide a valid email address so that we may notifiy you of your order status.");
		return false;
	}

	if (document.purchase.email.value.indexOf(".") < 4 && document.purchase.email.value.indexOf(".") > document.purchase.email.value.indexOf("@")){
		alert("You need to provide a valid email address so that we may notifiy you of your order status.");
		return false;
	}

	// We only go through this section if there's a different billing address
	if (document.purchase.billing_address.value != "")
	{
		if (document.purchase.billing_city.value == ""){
			alert("Please fill in the billing city value");
			return false;
		}

		if (document.purchase.billing_province.value == ""){
			alert("Please fill in the billing province/state value");
			return false;
		}

		if (document.purchase.billing_country.options[document.purchase.billing_country.options.selectedIndex].text == ""){
			alert("Please choose a billing country.");
			return false;
		}

		if (document.purchase.billing_postal_code.value == ""){
			alert("Please submit a billing postal or zip code.");
			return false;
		}
	}

	// if everything has cleared, then submit!
	return true;
}

function openWindow() {
	if (document.getID.email.value == "" || document.getID.email.value.indexOf("@") < 1 || document.getID.email.value.indexOf(".") < 4){
		alert("You need to provide a valid email address.");
		return false;
	}
	// The locationString will have to change to the actual location of the CGI
	locationString = "http://www.sonarkollektiv.com/getID.pl?redir=1&email=" + escape(document.getID.email.value);
	IDWin = window.open(locationString,"getID","width=400,height=300");
}
