var validImgExtensions = ['gif', 'GIF', 'jpg', 'JPG', 'jpe', 'JPE', 'jpeg', 'JPEG', 'png', 'PNG']; // bmp, png?  :)

function check(imgPath) {

	if (imgPath == "") {
		return true;
	}

	if (imgPath.charAt(0,7).toLowerCase() == "http://" || imgPath.charAt(0,6).toLowerCase() == "ftp://") {
		alert("Pictures from a web page cannot be upload - " + " : " + ImgPath);
		return false;
	}

	if(!isValidImageExt(imgPath)) {
		alert("Select only pictures with the following extensions: " + validImgExtensions.join(", "));
		return false;
	}
	
	return true;
}

function isValidImageExt(imageName) {
	for (var i in validImgExtensions) {
		var ext = validImgExtensions[i];
		if (endsWith(imageName, ext)) { return true; }
	}
	return false;
}

function endsWith(file, ext) {
	ext = '.' + ext;
	var startPos = file.length - ext.length;
	var endString = file.substr(startPos);
	return (endString == ext) ? true : false;
}

