$(document).ready(function() {
	   
						   
	// perform action every time checkbox is checked
	$("input[@type=checkbox]").click( 
		function() {
			
			// create string of values that were checked off
				// values in checkbox should be in the format of ocid-definition id (ie. 9999-9999)
			var selection = "";
			$("input[@type=checkbox]:checked").each( function () {
				selection = selection + $(this).val() + ",";
			});
			// zero based, remove last character (",");			
			if (selection.length)
				{ selection = selection.slice(0,selection.length-1); }
			//alert(selection);
		
			// determine if selections need demographic questions
				// create json object of form variable
			var formval = { selection:selection };
			// alert(formval.selection);
			
			$.ajax({
				type: "POST",
				url: "/demographics/demographics.cfm",
				dataType: "json",
				data: formval,
				success: function(response){
					//alert(response.demographics)
					if ( response.demographics == "true")
						// demographics needed
						{						
						$(".demographics").css("display","block");
						$(".title-input").css("display","none");
						$(".title-text").attr("value","");
						$("#includeDemographics").attr("value","1");
						}
					else
						// demographics not needed
						{
						$(".demographics").css("display","none");
						$(".title-input").css("display","block");
						$("#includeDemographics").attr("value","0");
						}
				}
			});				
		} 
	);
});// EOF

function checkAdditionalDemographic(demographicID, value) {
	var formval = { demographicID:demographicID,selection:value };
	$.ajax({
			type: "POST",
			url: "/demographics/demographics-additional.cfm",
			dataType: "json",
			data: formval,
			success: function(response){
				//alert(response.additionaldemographichtml)
				//alert(response.additionaldemographics)
				if ( response.additionaldemographics == "true")
					// additional demographics requested
					{						
						$("#demographic_additional").html(response.additionaldemographichtml);
					}
				else
					{
						$("#demographic_additional").html("");
					}
			}
		});				
	
	
}
