// JavaScript Document

$(document).ready(function(){
					   
	// password reset link handler
	$('#contact_request').submit(function() {
		
		var filter = /^([a-zA-Z0-9_	\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test($('#email').val()))
			alert('Please provide a valid email address');
		else {
			$("#txtAjaxMessageBox").removeClass().addClass('messagebox').text('Processing...').fadeIn(900);
			//check the username exists or not from ajax 
			$.getJSON("contact.php",{ company:$('#company').val(), contactname:$('#contactname').val(), jobtitle:$('#jobtitle').val(), 
									  phone:$('#phone').val(), email:$('#email').val(), typeofbusiness:$('#typeofbusiness').val(), 
									  sendliterature:$('#sendliterature').is(':checked')?"Yes":"No", callme:$('#callme').is(':checked')?"Yes":"No", 
									  howdidyouhear:$('input[@name=howdidyouhear]:checked').val(), facilitator:$('#facilitator').val(), articlename:$('#articlename').val(), 
									  vendorname:$('#vendorname').val(), other:$('#other').val(), specificquestion:$('#specificquestion').val()
									}, function(jsondata) //input[@name='howdidyouhear']:checked
			{
				if("SUCCESS"==jsondata.message) //if correct login detail 
				{
					$("#txtAjaxMessageBox").fadeTo(200,0.1,function() //start fading the messagebox
					{
						//add message and change the class of the box and start fading
						$(this).html('Contact request sent.').addClass('messageboxok').fadeTo(900,1);
					});
				}
				else
				{
					$("#txtAjaxMessageBox").fadeTo(200,0.1,function() //start fading the messagebox
					{
						//add message and change the class of the box and start fading
						$(this).html("Error sending contact request.<br />Please call Engleman Associates at 1-888-421-8372 for assistance").addClass('messageboxerror').fadeTo(900,1);
					});
				}
			});
		}
		return false;
	});

});