$(function(){
	//$('#consumerInquery').validate();
	//$('#retailerInquery').validate();
	//showContactForm('retailer');
	//showContactForm('consumerRelated');
	$('input[name=contactType]').each(function(){
		$(this).click(function(){
			changeContactForm($(this).attr('value'));
		});
	});
});

function hideContactForms(){
	//hideContactForm('default');
	hideContactForm('other');
	hideContactForm('retailer');
	hideContactForm('consumer');
	hideContactForm('consumerRelated');
}

function showContactForm(type){
	$('#' + type + 'Div').fadeIn(250);
	$('#formSelect').blur();
}

function hideContactForm(type){
	$('#' + type + 'Div:visible').fadeOut(250);
}

function changeContactForm(type){
	switch(type){
		case 'consumer':
			hideContactForms();
			showContactForm(type);
			break;
		case 'retailer':
			hideContactForms();
			showContactForm(type);
			break;
		case 'other':
			hideContactForms();
			showContactForm(type);
			break;
		case 'consumerRelated':
			showContactForm('consumerRelated');
			break;
		case 'notConsumerRelated':
			hideContactForm('consumerRelated');
			break;
		default:
			// Do nothing
	}
}

function displayRelatedForm(show){
	show ? showContactForm('consumerRelated') : hideContactForm('consumerRelated');
	$('#consumerRelatedSelect').blur();
}


function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
	 if (str.indexOf(" ")!=-1){
	    return false
	 }
	 return true					
}

/*
FORM VALIDATION MOVED INLINE WITH EACH FORM SECTION FOR EASIER TROBULESHOOTING
function validateConsumerForm(form) {
	var valid = true;
	
	if (form.firstName.value.length < 2) {
		valid = false;
		alert("Please provide your first name.") ;
		form.firstName.focus() ;
	}
	else if (form.lastName.value.length < 2) {
		valid = false;
		alert("Please provide your last name.") ;
		form.lastName.focus() ;
	}
	else if (form.addr1.value.length < 5) {
		valid = false;
		alert("Please provide your address.") ;
		form.addr1.focus() ;
	}
	else if (form.city.value.length < 2) {
		valid = false;
		alert("Please provide your city.") ;
		form.city.focus() ;
	}
	else if (form.state.value.length < 2) {
		valid = false;
		alert("Please provide your state/territory.") ;
		form.state.focus() ;
	}
	else if (form.zip.value.length < 5) {
		valid = false;
		alert("Please provide your zip code.") ;
		form.zip.focus() ;
	}
	else if (form.country.value.length < 2) {
		valid = false;
		alert("Please select your country.") ;
		form.country.focus() ;
	}
	else if (form.emailAddr.value.length < 1) {
		valid = false;
		alert("Please provide your email address.") ;
		form.emailAddr.focus() ;
	}
	else if (echeck(form.emailAddr.value) == false) {
		valid = false;
		alert("Your email address does not appear to be valid.\nPlease check your email address.") ;
		form.emailAddr.focus() ;
	}
	else if (form.phone.value.length < 10) {
		valid = false;
		alert("Please provide your phone number in ten digit format.") ;
		form.phone.focus() ;
	}
	else if (form.question.value.length < 15) {
		valid = false;
		alert("Please enter a question or comment to communicate to us.") ;
		form.question.focus() ;
	}
	
	if(valid){
		return true;
	}else{
		return false;
	}
}

function validateRetailerForm(form) {
	var valid = true;
	var condition1 = form.concern.value == 'consumerRelated';
	
	if (form.retailerName.value.length < 1){
		valid = false;
		alert("Please provide your retailer's name.") ;
		form.retailerName.focus() ;
	}
	else if (form.storeNumber.value.length < 1) {
		valid = false;
		alert("Please provide your store or distribution center's phone number.") ;
		form.storeNumber.focus() ;
	}
	else if (form.addr1.value.length < 5) {
		valid = false;
		alert("Please provide your address.") ;
		form.addr1.focus() ;
	}
	else if (form.city.value.length < 2) {
		valid = false;
		alert("Please provide your city.") ;
		form.city.focus() ;
	}
	else if (form.state.value.length < 2) {
		valid = false;
		alert("Please provide your state/territory.") ;
		form.state.focus() ;
	}
	else if (form.zip.value.length < 5) {
		valid = false;
		alert("Please provide your zip code.") ;
		form.zip.focus() ;
	}
	else if (form.country.value.length < 2) {
		valid = false;
		alert("Please select your country.") ;
		form.country.focus() ;
	}
	else if (form.emailAddr.value.length < 1) {
		valid = false;
		alert("Please provide your email address.") ;
		form.emailAddr.focus() ;
	}
	else if (echeck(form.emailAddr.value) == false) {
		valid = false;
		alert("Your email address does not appear to be valid.\nPlease check your email address.") ;
		form.emailAddr.focus() ;
	}
	else if (form.firstName.value.length < 2) {
		valid = false;
		alert("Please provide your first name.") ;
		form.firstName.focus() ;
	}
	else if (form.lastName.value.length < 2) {
		valid = false;
		alert("Please provide your last name.") ;
		form.lastName.focus() ;
	}
	else if (form.phone.value.length < 10) {
		valid = false;
		alert("Please provide your phone number in ten digit format.") ;
		form.phone.focus() ;
	}
	else if (form.product.value.length < 1) {
		valid = false;
		alert("Please provide a product name.") ;
		form.product.focus() ;
	}
	else if (form.brand.value.length < 1) {
		valid = false;
		alert("Please provide a brand name.") ;
		form.brand.focus() ;
	}
	else if (condition1 && form.consumerFirstName.value.length < 1) {
		valid = false;
		alert("Please provide the consumer's first name.") ;
		form.consumerFirstName.focus() ;
	}
	else if (condition1 && form.consumerLastName.value.length < 1) {
		valid = false;
		alert("Please provide the consumer's last name.") ;
		form.consumerLastName.focus() ;
	}
	else if (condition1 && form.consumerAddr1.value.length < 1) {
		valid = false;
		alert("Please provide the consumer's address.") ;
		form.consumerAddr1.focus() ;
	}
	else if (condition1 && form.consumerCity.value.length < 1) {
		valid = false;
		alert("Please provide the consumer's city.") ;
		form.consumerCity.focus() ;
	}
	else if (condition1 && form.consumerState.value.length < 1) {
		valid = false;
		alert("Please provide the consumer's state.") ;
		form.consumerState.focus() ;
	}
	else if (condition1 && form.consumerZip.value.length < 5) {
		valid = false;
		alert("Please provide the consumer's zip.") ;
		form.consumerZip.focus() ;
	}
	else if (condition1 && form.consumerPhone.value.length < 10) {
		valid = false;
		alert("Please provide the consumer's phone number in ten digit format.") ;
		form.consumerPhone.focus() ;
	}
	else if (condition1 && form.consumerQuestion.value.length < 10) {
		valid = false;
		alert("Please enter a question or comment from the consumer.") ;
		form.consumerQuestion.focus() ;
	}
	
	if(valid){
		return true;
	}else{
		return false;
	}
}
*/
