var validateFields = ['Company','Contact','Email','Phone','Departure','Destination','Weight','Delivery'];
var validateLabels = ['Company Name','Contact Name','Email','Phone','Departure City','Destination City','Weight','Delivery Period'];
var errorLabel = null;

function validate( theForm ) {
	var val = '';
	errorLabel = new Array();
	var alertString = '';
	for( i = 0; i < validateFields.length; i++ ) {
		val = theForm[ validateFields[ i ] ].value;
		if ( isEmpty( val ) ) {
			addErrorLabel( validateLabels[ i ] );
		}
	}

	if ( errorLabel.length > 0 ) {
		alertString = 'The following fields are required:\n';
		for ( i = 0; i < errorLabel.length; i++ ) {
			alertString += errorLabel[ i ];
			if ( i < errorLabel.length - 1 ) {
				alertString += ',\n';
			}
		}
		alert( alertString );
		return false;
	}
	return true;
}

function isEmpty( str ) {
	if( str.replace(/^\s+|\s+$/g, '') == '' ) {
		return true;
	}
	return false;
}

function addErrorLabel( name ) {
	errorLabel[ errorLabel.length ] = name;
}

