function showpopup(image) {
	link = "/images/news/" + image;
	target = "/popupwindow.php?image=" + link;
	popWindow = window.open(target, "Photo", "toolbar=no,scrollbars=yes,width=450,height=400,resizable=yes")
}

function getnews(form) {
	newsid = form.newsoptions.options[form.newsoptions.selectedIndex].value;
	location = "newsitem.shtml?id=" + newsid;
}

function getartist(form) {
	artistid = form.artistoptions.options[form.artistoptions.selectedIndex].value;
	location = "artist.shtml?id=" + artistid;
}

function getproduct(form) {
	product_id = form.productoptions.options[form.productoptions.selectedIndex].value;
	artist_id = form.artist_id.value;

	location = "product.shtml?id=" + product_id + "&artist_id=" + artist_id;
}

function reserved(id) {
   var msg = "Another shopper has placed this item in their shopping cart but has not purchased it.\nDo You Wish To Add This Item To Your Cart Anyway?";

   if (confirm(msg)) {
      dest = "/cgi-local/addtocart.pl?product_id=" + id;
      location = dest;
   }
}

function checkout() {
   location = "checkout_p.shtml";
}

function continue_shopping() {
   location = "store.shtml";
}

function getexhibition(form) {
	exhibition_id = form.exhibitionoptions.options[form.exhibitionoptions.selectedIndex].value;
	location = "exhibition.shtml?id=" + exhibition_id;
}

function search(form) {
	keywords = form.keywords.value;

	if ( (keywords == null) || (keywords.length == 0) ) {
		alert("Please Specify a Keyword to Search For.");
		form.keywords.focus();
	} else {
		location = "search.shtml?keywords=" + keywords;
	}
}


function isEmail(s) {
	var i = 1;
	var sLength = s.length;

	// look for @
	while ((i < sLength) && (s.charAt(i) != "@")) { i++; }

	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else i += 2;

	// look for .
	while ((i < sLength) && (s.charAt(i) != ".")) { i++; }

	// there must be at least one character after the .
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else return true;
}

function checkaddr(form) {
	fname = form.fname.value;
	lname = form.lname.value;
	street1 = form.street1.value;
	phone = form.phone.value;
	email = form.email.value;
	country = form.country.options[form.country.selectedIndex].value;
	state = form.state.options[form.state.selectedIndex].value;
	zip = form.zip.value;

	if ((fname == null) || (fname.length == 0)) {
		alert("You must supply a First Name");
		form.fname.focus();
		return(false);
	}

	if ((lname == null) || (lname.length == 0)) {
		alert("You must supply a Last Name");
		form.lname.focus();
		return(false);
	}

	if ((street1 == null) || (street1.length == 0)) {
		alert("You must supply a street address");
		form.street1.focus();
		return(false);
	}

	if ((phone == null) || (phone.length == 0)) {
		alert("You must supply a phone number.");
		form.phone.focus();
		return(false);
	}

	if ((email  == null) || (email.length == 0)) {
		alert("You must supply an email address");
		form.email.focus();
		return(false);
	} else {
		if (! isEmail(email)) {
			alert("Your email appears to be invalid.\nPlease supply an alternative email address.");
			form.email.focus();
			return(false);
		}
	}

	if (country == "USA") {
		if (state == "XX") {
			msg = "Since you have selected USA, you must select a state.";
			alert(msg);
		} else if ((zip == "none") || (zip == null) || (zip.length != 5) ) {
			msg = "Since you have selected USA, you must supply a 5 digit zip code.";
			form.zip.focus();
			alert(msg);
		} else {
			form.submit();
		}
	} else {
		if (state != "XX") {
			msg = "The state field applies only to the US. Please set this to Not Applicable which appears at the top of the drop down menu.";
			alert(msg);
		} else if ((zip != "none") && (zip != null) && (zip.length != 0) ) {
			alert ("The zip code applies only to US addresses.");
		} else {
			form.submit();
		}
	}
}

function imgpopup(image) {
	target = "/popupwindow.php?image=" + image;
	popWindow = window.open(target, "Photo", "toolbar=no,scrollbars=yes,width=450,height=400,resizable=yes")
}

function register(form) {
	email = form.email.value;

	if (! isEmail(email)) {
		alert("Your email appears to be invalid.\nPlease supply an alternative email address.");
		form.email.focus();
		return(false);
	}

	target = "/register.shtml?email=" + email;
	win = window.open(target, "Photo", "toolbar=no,scrollbars=yes,width=350,height=250,resizable=yes")
}

function contact(form) {
	contactname = form.contactname.value;
	email = form.email.value;
	phone = form.phone.value;
	comment = form.comment.value;

	if ((contactname == null) || (contactname.length == 0)) {
		alert("Please Supply a Contact Name.");
		form.contactname.focus();
		return(false);
	}

	if (! isEmail(email)) {
		alert("Your email appears to be invalid.\nPlease supply an alternative email address.");
		form.email.focus();
		return(false);
	}

	if ((comment == null) || (comment.length == 0)) {
		alert("Please Supply The Text of Your Query.");
		form.comment.focus();
		return(false);
	}

	form.submit();
}

function privacy() {
	target = "/privacy.shtml";
	win = window.open(target, "Privacy", "toolbar=no,scrollbars=yes,width=450,height=500,resizable=yes")
}

function copyright() {
	target = "/copyright.shtml";
	win = window.open(target, "Copyright", "toolbar=no,scrollbars=yes,width=450,height=500,resizable=yes")
}

function closeChild(loc) {
   opener.document.location = loc;
   window.close();
}

