addLoadListener(init);

function init() {
	if (document.forms[0])
	{
		document.forms[0].onsubmit = validateFields;
		return true;
	}
}

function validateFields() { // this sends alerts if there is a problem
	var problem = 'no';
	var file = document.forms[0].elements["upload"];
	var pattern = /\.jp(e)?g/;
	if (!pattern.test(file.value)) {
  
    	alert("That file is not a jpg");
		problem = 'yes'
    	
	}
	// check description
	var descField = document.forms[0].elements["description"];
	if (descField.value == "") {
		alert("Please enter a description");
		problem = 'yes';
		
	}
	if (problem =='no') {
		return true;
	} else {
		return false;
	}
	
}

function addLoadListener(fn) {
	if (typeof window.addEventListener != 'undefined') {
    	window.addEventListener('load', fn, false);
	} else if (typeof document.addEventListener != 'undefined') {
    	document.addEventListener('load', fn, false);
	} else if (typeof window.attachEvent != 'undefined') {
    	window.attachEvent('onload', fn);
	} else {
    	var oldfn = window.onload;
    	if (typeof window.onload != 'function') {
      	window.onload = fn;
    	} else {
     	 window.onload = function() {
        oldfn();
        fn();
      };
    }
  }
};