/***********************************************
***  HERO IMAGE FADING  ************************
************************************************/

$(function() {
	$('#pollError').hide();
	
	$('#pollLink').click(function(){
		var action = $(this).closest('form').attr('action');
		var database = {
						'ajaxapp'	: 'resultslink',	
						'idPoll'	: $('#idPoll').val()
						}
		$.ajax({type: "POST",
				url: action,
				dataType: 'json',
				data: database ,
				beforeSend: function() {
					//$('#qty' + idProduct).val('');
				},
				success: function(r) {
					var status = parseInt(r.root.status);
					if (status ==1){
						$('#pollBlockContent').html(r.root.content);
					}else{
						$('#pollErrorP').text(r.root.msgText);
						$('#pollError').show();
					}
				},
				error: function() {
					$('#pollErrorP').text('Problem loading. Please try again.');
					$('#pollError').show();
				}
			});			

		return false;
	});

	$('#submitPoll').click(function(){
		var action = $(this).closest('form').attr('action');
		var database = {
						'ajaxapp'	: 'submitpoll',	
						'idOption'	: $('#poll input:checked').val(),
						'idPoll'	: $('#idPoll').val()
						}
		
		//validation method
		if ($('#poll input:checked').length == 1){
		
			$.ajax({type: "POST",
					url: action,
					dataType: 'json',
					data: database ,
					beforeSend: function() {
						//$('#qty' + idProduct).val('');
					},
					success: function(r) {
						var status = parseInt(r.root.status);
						if (status ==1){
							$('#pollBlockContent').html(r.root.content);
						}else{
							$('#pollErrorP').text(r.root.msgText);
							$('#pollError').show();
						}
					},
					error: function() {
						$('#pollErrorP').text('Problem updating. Please try again.');
						$('#pollError').show();
					}
				});			
		}else{
			$('#pollErrorP').text('Please select an option');
			$('#pollError').show();
		}
		return false;
	});


});
	
