/**
 * @author karlstanley
 */
YAHOO.namespace('syzygy.validation');

YAHOO.syzygy.validation.enquiryForm = function(parentId){
	var parentEl = null;
	var fullname = null;
	var phone = null;
	var email = null;
	var address = null;
	var submit = null;
	
	var init = function(){
		parentEl = document.getElementById(parentId);
		fullname = document.getElementById('txtName');
		phone = document.getElementById('txtPhone');
		email = document.getElementById('txtEmail');
		address = document.getElementById('txtAddress');
		submit = document.getElementById('btnSubmit');
		
		YAHOO.util.Event.on(submit, 'click', validate);
	}
	
	var validate = function(e, obj){
		var error = 0;
	
		if (!fullname.value.match(/^[A-Z '-]+$/i)){
			alert('Please enter your name. No numbers or punctuation please.');
			error = 1;
		}
			
		if (0 == error && 'undefined' != typeof(phone.value) && null != phone.value && '' != phone.value){
			if (!phone.value.match(/^[0-9]{5,13}$/)){
				alert('Please enter a valid phone number with no spaces, brackets or punctuation.');
				error = 2;			
			}
		}
				
		if (0 == error && !email.value.match(/^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$/i)){
			alert('Please enter a valid email address.');
			error = 3;
		}
		
		if (0 < error){
			e.preventDefault();
		}
	}
	
	init();
}
