$(document).ready(function(){
	$("#poll").submit(function(){
		var poll_id = $("#poll_id").val();
		var answer  = $("input[@name='answer']:checked").val();

		if(answer === undefined){
			alert('Please select an option for the poll.');
			return false;
		} else {
			//alert('Thank you for selecting option #' + answer);
			
			$.get("/includes/ajax.poll.php", {answer: answer, poll_id: poll_id}, function(data){
				//alert(data.toString());
				$("#home_poll").html(data);
			});
			
			return false;
		}
	});
	
	$("#newsletter_form").submit(function(){
		var name    = $("#contact_name");
		var email   = $("#contact_email");
		var phone   = $("#contact_phone");
		var company = $("#contact_company");

		if(name.val() == ""){
			alert('Please enter your name correctly.');
			name.focus();
			return false;
		}
		
		if(email.val() == ""){
			alert('Please enter your email correctly.');
			email.focus();
			return false;
		}
		
		if(phone.val() == ""){
			alert('Please enter your phone correctly.');
			phone.focus();
			return false;
		}
		
		if(company.val() == ""){
			alert('Please enter your company correctly.');
			company.focus();
			return false;
		}
					
		$.post("/myeternity/process_newsletter.php", {name: name.val(), email: email.val(), phone: phone.val(), company: company.val()}, function(data){
			//alert(data.toString());
			$("#home_newsletter").html(data);
		});
		
		return false;
	});
});
