$(document).ready(function()
{
	$("#contact_form").submit(function()
	{
		// remove all the class add the messagebox classes and start fading
		$("#msgbox2").removeClass().addClass('messagebox').text('Submitting Question...').fadeIn(1000);
		// check the data exists or not from ajax
		$.post("do_question.php",{ question_type:$('#question_type').val(),email:$('#email').val(),company:$('#company').val(),switch:$('#switch').val(),maintainer:$('#maintainer').val(),lines:$('#lines').val(),question:$('#question').val() },function(data)
		{
		  if(data=='yes') // if question submitted successfully
		  {
			$("#msgbox2").fadeTo(200,0.1,function()  // start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Your question was sent successfully').addClass('messageboxok').fadeTo(900,1);
			  setTimeout("window.location.reload()",2000);
			});
		  }
		  else if(data=='invalid')
		  {
			$("#msgbox2").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('The email address is not valid!').addClass('messageboxerror').fadeTo(900,1);
			});		
		  }
		  else if(data=='no')
		  {
			$("#msgbox2").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Please complete ALL required fields!').addClass('messageboxerror').fadeTo(900,1);
			});		
		  }
		});
		return false; // not to post the form physically
	});
});
