/* determines whether or not to reject airbag unit */
function do_reject(form_name, field_name, fail_response) { 

	doc = document.forms[form_name];
   	field = doc.elements[field_name];
	
	/* set success response based on fail response */
	if(fail_response == "No") {
		success_response = "Yes";	
	}
	else {
		success_response = "No";	
	}
		
	/* alert user to reject condition & confirm reject, or cancel & return to inspection */
	if(field[field.selectedIndex].value == fail_response) {
		
		/* set fail_condition flag & submit form */
		if(confirm('Choosing `' + fail_response + '` Will Result in a Reject Report. Click `OK` to Generate Reject Report.\nClick `Cancel` to Continue Inspection.')) {
			doc.fail_condition.value = field_name;
			doc.submit();
		}
		/* otherwise, reset selected value to success response */
		else {
			field[field.selectedIndex].value = success_response;
			field[field.selectedIndex].text = success_response;
			field[0].value = fail_response;
			field[0].text = fail_response;
		}
	}
	/* if fail condition not blank, set to blank as user selected a non-reject response */
	else if(doc.fail_condition.value != "") {
		doc.fail_condition.value = "";	
	}
}

/* check VIN length -- must be exactly 17 digits */
function check_vin_length(form_name, field_name) {
	
	doc = document.forms[form_name];
	field = doc.elements[field_name];
   	length = field.value.length;
	//alert(length);
	
	/* set field to white background, if applicable */
	field.style.background = "#FFFFFF";	
	
	if(length != 17) {
		alert('VIN field must be exactly 17 digits in length.\n\nPlease modify supplied VIN field entry.');
		field.focus();
		field.style.background="#FFCC00";
		return false;
	}
}

/* confirm final unit submission */
function do_confirm() {
	
	/* set fail_condition flag & submit form */
	if(confirm('Click `OK` to Submit Report. Click `Cancel` to Review Your Submission.\n\nNOTE: once a report has been submitted, it is CLOSED and will NOT be editable.')) {
		return true;
	}	
	else {
		return false;	
	}
}

