//
//	Purpose: Verify photo size, etc.
//
//

/*--------------------------
	verifyData
	Validates that all of the text fields for the metadata are filled
	Called when the user submits the returned metadata from Photo_Scrape.php
	Returns true if the text fields are filled
--------------------------*/
function verifyData(photoInfo){
	//alert("reached verifyData function");
	
	var metadata = document.getElementById("photoScrape");
	
	if(metadata.fileName.value == ""){
		alert("No File Name!");
		return false;
	}
	else if(metadata.theDate.value == ""){
		alert("No Date provided!");
		return false;
	}
	else if(metadata.theTime.value == ""){
		alert("No Time Provided!");
		return false;
	}
	else if(metadata.theLat.value == "" || metadata.theLong.value == ""){
		alert("Missing either the Latitude or Longitude!");
		return false;
	}
	//validation here for City when google maps autofill is working
	
	return true;
}

/*--------------------------
	verifySize
	Validates that a photo has a size less than 2 MB
	Called by the event handler submitMe
	returns true if a photo is 2 MB or less, else false
--------------------------*/
function verifySize(){
	//alert("In verifySize");
	var fileInput = document.getElementById("fileName");
	//var fileInput = document.getElementsByName("fileName");
	
	alert(`File Size: ${fileInput.files[0].size}`);
	if(fileInput.files[0].size > 2000000){
		alert("File size must be less than 2 MB!");
		return false;
	}
	else{
		//alert("File was less than 2 MB");
		return true;
	}
}

/*--------------------------
	eventHandler that is called when a user uploads a photo
	Parameters: Form that contains the uploaded photo
	returns true if a photo was uploaded
--------------------------*/
function submitMe(photoInfo){
	//alert("Reached eventHandler");
	if (verifySize()){
		return true;
	}
	else{
		return false;
	}
}