$(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');
		    showContactForm('contactUs_consumerRelated');
			break;
		case 'notConsumerRelated':
		    hideContactForm('consumerRelated');
		    hideContactForm('contactUs_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
}
