$(function(){
	$('#btn_action').click(function(){SubmitForm();});
	$('#btn_reset').click(function(){ResetForm();});
});

function ResetForm(){
	$('#fname').val('');
	$('#lname').val('');
	$('#email').val('');
	$('#phone1').val('');
	$('#phone2').val('');
	$('#phone3').val('');
	$('#comments').val('');
}

function SubmitForm(){

	if($('#fname').val()=="" || $('#lname').val()==""){
		 alert("Please enter the required information.");
		 return false;
    }

    if ($('#email').val()=="" || $('#email').val().search("@") <= 0) {
		alert("Please enter a valid email.");
		return false;
    }  

	if( $('#session_security').val()!=$('#security_code').val() || $('#security_code').val() == "" ){
		 alert("The security code is not correct. Please check the security code again, and type it exactly as it is seen in the box.");
		 return false;
	}

	var json='';
	json='{"fname":"'+$('#fname').val()+'","lname":"'+$('#lname').val()+'","email":"'+$('#email').val()+'","phone":"'+$('#phone1').val()+'-'+$('#phone2').val()+'-'+$('#phone3').val()+'","comments":"'+$('#comments').val()+'","join_newsbuddy":"'+$('#join_newsbuddy').get(0).checked+'"}';


	$.ajax({
		type: "POST",
		url: "ajax_funcs/process.contactus.php",
		data: "json="+json,
		success: function(ajax_return){
			//alert( ajax_return );
			if (ajax_return!='0'){
				$('#contactus_form').slideUp('slow',function(){
					$('#contactus_form').html('<center><p>Thank you. Your message has been successfully sent to us.</p><div style="width:400px; height: 220px; background-color:#FFFFFF; border:1px solid #333333; overflow:auto;"><pre>'+ajax_return+'</pre></div></center>');
					$('#contactus_form').slideDown('slow');
				});
			}
		}
	});
	
}