// requires jquery
function mySubmit()
{
	name = $('input#name').val();
	tel = $('input#telephone').val();
	em = $('input#email').val();
	em2 = $('input#email2').val();
	q = $('textarea#question').val();

	err = '';

	if ( !name ) { err += "You must enter your name.<br /><br>\n"; }

	if ( !( tel || ( em && em2 ) ) ) {
		err += "You must enter your telephone number with area code, and, if you have one, a valid e-mail address.<br /><br>\n";
	}

	if ( !tel ) {
		if ( em != em2 ) {
			err += "The e-mail addresses you entered do not match.<br /><br>\n";
		}
	}

	if ( !q ) { err += "What is your question?<br /><br>\n"; }

	if ( err ) {
		$('#resultBox').html( err );
		$('#resultBox').show();
	} else {
		//$('#resultBox').html('Please wait while the information is processed.');
		//$('#resultBox').show();
		//$('input#btnSearch').attr('disabled', 'disabled');

		// submit
		$.post( 
window.location.protocol +
'//' + document.domain + '/cgi-bin/ask-the-lawyer.cgi',
			{ name: name, telephone: tel, email: em,
				email2: em2, question: q, btnSearch: 1, ajax: 1 },
			function( result ) {
				if ( result.err ) {
					$('#resultBox').html( result.err );
					//$('#resultBox').append( '<br \/><br \/>click in this box to clear it' );
					$('#resultBox').show();
//					alert( result.err );
				}
				if ( result.good ) {
					// clear the contact form
					$('input#name').val('');
					$('input#telephone').val('');
					$('input#email').val('');
					$('input#email2').val('');
					$('textarea#question').val('');
				}
			}, "json" );

		$('input#btnSearch').removeAttr('disabled');
	}
}
document.write("<div id='resultBox' style='display:none;position:absolute;top:38%;left:41%;background:#800000;color:#fff;width:400px;border:solid white 5px;padding:10px;' onclick='clrBox()'><\/div>");
function clrBox(){
	$('#resultBox').hide();
}

