// JavaScript Document for the submit a lost or found animal page.
// This function just checks to make sure everything is filled out correctly

function validateSubmit(){
	var errors = new Array();
	var lorf_Field, type_Field, gender_Field, color_Field, size_Field, collar_Field, month_Field, day_Field, year_Field, zip_Field, txt_Field;

	lorf_Field = document.submitForm.lostOrfound.value;
	type_Field = document.submitForm.type.value;
	gender_Field = document.submitForm.genderBtn;
	color_Field = document.submitForm.color.value;
	size_Field = document.submitForm.size.value;
	collar_Field = document.submitForm.collar.value;
	month_Field = document.submitForm.month.value;
	day_Field = document.submitForm.day.value;
	year_Field = document.submitForm.year.value;
	zip_Field = document.submitForm.zip.value;
	txt_Field = document.submitForm.txt.value;
	
	//validate the lorf field
	if(lorf_Field == '0'){
		errors[0] = 'yes';
		document.getElementById('lorfError').style.display = "block";
	}else{
		errors[0] = '';
		document.getElementById('lorfError').style.display = "none";
	}
	
	//validate the type field
	if(type_Field == '0'){
		errors[1] = 'yes';
		document.getElementById('typeError').style.display = "block";
	}else{
		errors[1] = '';
		document.getElementById('typeError').style.display = "none";
	}
	
	//validate the gender field
	var i;
	var genderField = '';
	for(i=0; i<gender_Field.length; i++){
		if (gender_Field[i].checked){
			genderField = gender_Field[i].value;
			errors[2] = '';
			document.getElementById('genderError').style.display = "none";
		}
	}
	if(genderField == ''){
		document.getElementById('genderError').style.display = "block";
		errors[2] = 'yes';
	}
	
	//validate the color field
	if(color_Field == ''){
		errors[3] = 'yes';
		document.getElementById('colorError').style.display = "block";
	}else{
		errors[3] = '';
		document.getElementById('colorError').style.display = "none";
	}

	//validate the size field
	if(size_Field == '0'){
		errors[4] = 'yes';
		document.getElementById('sizeError').style.display = "block";
	}else{
		errors[4] = '';
		document.getElementById('sizeError').style.display = "none";
	}
	
	//validate the collar field
	if(collar_Field == ''){
		errors[5] = 'yes';
		document.getElementById('collarError').style.display = "block";
	}else{
		errors[5] = '';
		document.getElementById('collarError').style.display = "none";
	}
	
	//validate the date fields
	if(month_Field == '' || day_Field == '' || year_field == ''){
		errors[6] = 'yes';
		document.getElementById('dateError').style.display = "block";
	}else{
		errors[6] = '';
		document.getElementById('dateError').style.display = "none";
	}
	
	//validate the zip code field
	if(zip_Field == ''){
		errors[7] = 'yes';
		document.getElementById('zipError').style.display = "block";
	}else{
		errors[7] = '';
		document.getElementById('zipError').style.display = "none";
	}
	
	//validate the txt area field
	if(txt_Field == ''){
		errors[8] = 'yes';
		document.getElementById('txtError').style.display = "block";
	}else{
		errors[8] = '';
		document.getElementById('txtError').style.display = "none";
	}
	
	//check the errors array
	for(i=0; i<9; i++){
		if(errors[i] == 'yes'){
			allow = 'no';
		}
	}
	
	//check the allow flag. This flag determines whether or not to submit the information
	if(allow == 'no'){
		return false;

	}else{
		return true;
	}	
}