$(document).ready(function()
{
	var showtools = $('#show_tools_text_box').attr("value");
	var topic_id = $('#topic_id_box').attr("value");
	var article_id = $('#article_id_box').attr("value");
	
	if (showtools == "true")
	{
		sendPopupRequest('adding_child',topic_id,article_id);
	}
	
	$('#poll_thankyou').hide();

}
);
function submitPollResult(poll_type)
{
	//alert(poll_type);
	for(var i=0; i<window.document.poll.choice.length; i++)
	{
		if (document.poll.choice[i].checked)
      {
      var choice = document.poll.choice[i].value;
      }

	}
	
	//alert(choice);
	
	 $.post(
				"/en_ca/useful_information/ajax_response/update_poll.php",
				{
				  'choice': choice,'poll_type': poll_type
				  
				 
				},
				pollResponse,
				"json"
				
				);
	 
	
	
	
	
}
function pollResponse(data)
{

	if(data[0] == "true")
	{	
	
		$('#poll_thankyou').show();
	}
	
	
	
}








function saveArticleToChild(articleid,topicid,childid)
{
	
	
	 $.post(
				"/en_ca/useful_information/ajax_response/associateArticleToChild.php",
				{
				  'articleID': articleid,'topicID':topicid,'childID': childid
				  
				 
				},
				saveArticleResponse,
				"json"
				
				);
	 
	
	
	
	
}
function saveArticleResponse(data)
{
	
	if(data[0] == false)
	{
		
		displayErrorMessage(1);
	}
	else
	{
		displayErrorMessage(2);
	}
	
	
}



function selectChildId(articleid, topicid)
{
	
	var child_selected_index = document.getElementById("child_selector").selectedIndex;
	var child_selected_value = document.getElementById("child_selector").options[child_selected_index].value;
	
	
	if(child_selected_value == "sel")
	{
		$('#article_error_content_text').html("Please select a child");
		
		$('#article_error_button').html("<img src='/en_ca/products/includes/images/helpful_tools/bt_ok.jpg' onclick='javascript:hideArticleError();' width='70' height='26' >");

		$('#article_content').hide();
		$('#article_error_content').show();
		
		
		
	}
	else
	{
		saveArticleToChild(articleid,topicid,child_selected_value);
	}
	
	
	
}

function displayErrorMessage(error_type)
{
	
	if(error_type == 1)
	{
		$('#article_content').hide();
		$('#article_error_button').html("<img src='/en_ca/products/includes/images/helpful_tools/bt_ok.jpg' onclick='javascript:BAM_AD_hide();' width='70' height='26' >");
		
		$('#article_error_content_text').html("The item you specified has already been added to the selected child&rsquo;s profile");

		$('#article_error_content').show();
	}
	
	
	if(error_type == "2")
	{
		
		
		$('#article_content').hide();
		$('#article_error_button').html("<img src='/en_ca/products/includes/images/helpful_tools/bt_ok.jpg' onclick='javascript:BAM_AD_hide();' width='70' height='26' >");
		$('#article_error_content_text').html("The information has successfully been added to your My Heinz Baby profile.");

		$('#article_error_content').show();
	}
}
function hideArticleError()
{
	$('#article_content').show();
	$('#article_error_content').hide();
}


