function isArtist() {
  var myform = document.forms["shop_content_submission"];

  if (myform.relationship_to_studio.value == 1) {
	// Artist
	document.getElementById("artist_info").style.display = "block";
	enableFlashOption();
  } else {
	// Client
	document.getElementById("artist_info").style.display = "none";
	disableFlashOption();
	enableTattooLocations();
  }
}

function isFlashOrPhoto(fieldnumber) {
  var myform = document.forms["shop_content_submission"];
  var fieldname = "flash_or_photo"+fieldnumber.toString();
  var divname = "div_tattoo_location"+fieldnumber.toString();
  var dropdownIndex = document.getElementById(fieldname).selectedIndex;
  if (document.getElementById(fieldname)[dropdownIndex].value.toLowerCase() == 'flash') {
	document.getElementById(divname).style.display = "none";
  } else {
	document.getElementById(divname).style.display = "block";
  }
}

function enableTattooLocations() {
	for (var x=1; x<=5; x++) {
		var field_to_change = "div_tattoo_location"+x.toString();
		document.getElementById(field_to_change).style.display = "block";
	}
}

function disableFlashOption() {
	for (var x=1; x<=5; x++) {
		var field_to_change = "flash_or_photo"+x.toString();
		document.getElementById(field_to_change)[1] = null;
	}

}

function enableFlashOption() {
	for (var x=1; x<=5; x++) {
		var field_to_change = "flash_or_photo"+x.toString();
		var opt = document.createElement("option");
		if (document.getElementById(field_to_change).length == 1) {
			document.getElementById(field_to_change).options.add(opt);
			opt.text = "Flash";
			opt.value = "flash";
	        }
	}
}

function locationChosen(fieldnumber) {
	var okay = true;
	var myform = document.forms["shop_content_submission"];
  	var fieldname = "tattoo_location"+fieldnumber.toString();
	var dropdownIndex = document.getElementById(fieldname).selectedIndex;
  	if (document.getElementById(fieldname)[dropdownIndex].value.length > 0) {
	        document.getElementById("msg_tattoo_location"+fieldnumber.toString()).innerHTML = "";
	} else {
                document.getElementById("msg_tattoo_location"+fieldnumber.toString()).innerHTML = "Please specify the location of this tattoo on the body in the photograph.";
		okay = false;
  	}
	return okay;
}

function classificationChosen(fieldnumber) {
	var okay = true;
	var myform = document.forms["shop_content_submission"];
  	var fieldname = "tattoo_classification"+fieldnumber.toString();
	var dropdownIndex = document.getElementById(fieldname).selectedIndex;
  	if (document.getElementById(fieldname)[dropdownIndex].value.length > 0) {
	        document.getElementById("msg_tattoo_classification"+fieldnumber.toString()).innerHTML = "";
	} else {
                document.getElementById("msg_tattoo_classification"+fieldnumber.toString()).innerHTML = "Please specify Tattoo Style.";
		okay = false;
  	}
	return okay;
}

function relationshipChosen() {
	var okay = true;
	if (document.getElementById("relationship_to_studio").value == 1) {
		document.getElementById("msg_relationship_to_studio").innerHTML = "";
   	} else if (document.getElementById("relationship_to_studio").value == 2) {
		document.getElementById("msg_relationship_to_studio").innerHTML = "";
	} else {
		document.getElementById("msg_relationship_to_studio").innerHTML = "<BR>You must select your relationship to this Tattoo Studio";
		okay = false;
	}
	return okay;
}

function checkSubmission() {
  var okay_to_process = true;
  var myform = document.forms["shop_content_submission"];
  // First we check if the Submitter Information Block Exists and
  // if so, we ensure all elements are filled out, if is doesn't exist
  // we can skip this validation.

  if (document.getElementById("relationship_to_studio")) {
	okay_to_process = relationshipChosen();
  }

  // Now we check each submission for an existing file selection.  If
  // a file is selected we check that a tattoo style is selected.  We
  // then proceed to check the image type.  If the image type is Photograph
  // we ensure that the Location on the Body field is selected.

  var total_files = 0;

  for (var x=1; x<=5; x++) {
	thisFileRef = "uploaded_file"+x.toString();
	if (document.getElementById(thisFileRef).value.length >=5) {
		var fileName = document.getElementById(thisFileRef).value;
		var fileLength = fileName.length-3;
		var fileExt = fileName.substring(fileLength, fileLength+3).toLowerCase();
		//alert(fileName + ' - ' + fileLength + ' - ' + fileExt);
		if ((fileExt != 'jpg') && (fileExt != 'gif') && (fileExt != 'png')) {
			document.getElementById("msg_"+thisFileRef).innerHTML = "File Rejected and Removed.  Uploads must be either a .jpg, .png or .gif format!";
			document.getElementById(thisFileRef).value = null;
			okay_to_process = false;
		} else {
			total_files++;
			document.getElementById("msg_"+thisFileRef).innerHTML = "";
			if (document.getElementById("flash_or_photo"+x.toString()).value.toLowerCase() == 'photo') {
				okay_to_process = locationChosen(x);
			} else {
				document.getElementById("msg_tattoo_location"+x.toString()).innertHTML = '';
			}
			if (okay_to_process == true) {
				okay_to_process = classificationChosen(x);
			}
		}
	}
  }

  if (total_files == 0 && okay_to_process == true) {
	alert('There are no files selected for upload.  Please select at least one file to upload and press the Submit button to proceed.');	
	okay_to_process = false;
  }

  // Once all of these items have been identified as valid without any 
  // errors, we can return a True to submit, otherwise show the errors
  // and return false.  

  // alert(myform.uploaded_file1.value);
  // alert(myform.uploaded_file2.value);
  // alert(myform.uploaded_file3.value);
  // alert(myform.uploaded_file4.value);
  // alert(myform.uploaded_file5.value);
  //if (okay_to_process == true) {
  //	alert('At this point, your file(s) would have been submitted for processing, thanks for testing!');
  //}
  if (okay_to_process == true) {
	document.getElementById('submit_button').innerHTML = "Submission(s) being processed.  Please wait."
  }
  // okay_to_process = false;
  return okay_to_process;
}