//
// Check that the selected image file is of an acceptable type
//
function checkFileName(img_form) {
	var fName;
	var l;
	var dotPos;
	var fileExt;

	fName = img_form.imagefile.value;
	l = fName.length;
	dotPos = fName.lastIndexOf('.');

	if (dotPos!=-1){
		fileExt = fName.substring(dotPos+1, l);
		fileExt = fileExt.toLowerCase();
		
		// check if the file extension is allowable
		if (fileExt=="jpg" || fileExt=="jpeg" || fileExt=="gif" || fileExt=="png"){
			return true;
		} else {
			alert('The file you have selected is not an acceptable type.  Files must be one of .jpg, .jpeg, .gif, .png.');
			return false;
		}
	} else {
		alert('The file you have selected is not an acceptable type.  Files must be one of .jpg, .jpeg, .gif, .png.');
		return false;
	}
}

var submitted=false;

function uploadOnSubmit(upload_form)
{
	if (submitted) {
		alert('Please be patient, your image is still uploading.');
		return false;
	}

	if (!checkFileName(upload_form)) {
		return false;
	}

	submitted=true;

	// show a popup window
	window.open('/shop/please_wait.pl','please_wait','location=no,toolbar=no,status=no,directories=no,scrollbars=no, resizable=no, width=200, height=200'); 

	return true;
}


