var BODYSCAPE = BODYSCAPE || {};

BODYSCAPE.checkEmpty = function(input, fname,err) {
	if (input.value.length == 0 || input.value == input.defaultValue) {
		input.className = 'error';
		return 'Please enter a valid '+fname+'\n';
	}
	return '';
}
BODYSCAPE.checkPhone  = function(input) {
   var strng = input.value, err = '';
	if (strng == "") {
		err = "You didn't enter a phone number.\n";
	} else {
		var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped))) {
			err = "The phone number contains illegal characters.\n";	
		}
		if (!(stripped.length == 10)) {
			err = "The phone number is the wrong length. Make sure you included an area code.\n";
		} 
	}
	if (err != '') {
		input.className = 'error';
	}
	return err;
}

BODYSCAPE.contactUsValidate = function(form) {
	var errors = new Array(), err;
	errors += BODYSCAPE.checkEmpty(form['name'], 'name');
	errors += BODYSCAPE.checkPhone(form['homephone'], 'homephone');
	if (errors != '') {
		window.alert(errors);
		return false;
	}
	return true;
}
