var contactForm;
var emailFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

function ContactUs(theForm) {
	contactForm = theForm;
	
	if ((theForm.name.value == null) || (theForm.name.value.length == 0)) {
		alert('Please enter your name');
		theForm.name.focus();
		return false;
	}
	
	if ((theForm.email.value == null) || (theForm.email.value.length == 0)) {
		alert('Please enter your email address');
		theForm.email.focus();
		return false;
	}
	
	if (emailFilter.test(theForm.email.value) == false){
		alert('Your email address is invalid, please re-enter');
		theForm.email.focus();
		return false;
	}
	
	if (theForm.subject.selectedIndex <= 0) {
		alert('Please select a subject');
		theForm.subject.focus();
		return false;
	}
	
	if ((theForm.comments.value == null) || (theForm.comments.value.length == 0)) {
		alert('Please enter your question or comment');
		theForm.comments.focus();
		return false;
	}
	
	// error checking done
	
	var parms = new Array();
	parms[parms.length] = theForm.codiv.value;
	parms[parms.length] = theForm.name.value;
	parms[parms.length] = theForm.store.value;
	parms[parms.length] = theForm.email.value;
	parms[parms.length] = theForm.order.value;
	parms[parms.length] = theForm.subject.options[theForm.subject.selectedIndex].value;
	parms[parms.length] = theForm.comments.value;
	
	jsrsExecute("/common/comm/contactUs/server.asp", ContactUsCallBack, "ContactUs", parms, false);
	
	return false;
}

function ContactUsCallBack(str) {
	
	if (str.substr(0, 5) != 'ERROR') {
		contactForm.reset();
		location.href = "/contact_thankyou.asp"
	} else {
		alert(str);
	}
}
