function InputCallback(this_id, event_type)
{
	if (event_type == 'focus')
	{
		if (document.getElementById(this_id).type == 'textarea')
		{
			if (document.getElementById('div_lit_' + this_id))
			{
				HideLiterals();
				document.getElementById('div_lit_' + this_id).style.display = 'block';
			}
		}
	}
	else
	{
		id_prefix = this_id.substr(0, (this_id.length - 1));
		GenerateTotals(id_prefix);
	}
}

function HideLiterals()
{
	var literal_array = new Array('lit_s1_q1', 'lit_s1_q2', 'lit_s1_q3', 'lit_s1_q4', 'lit_s1_q5', 'lit_s1_q6', 'lit_s1_q7', 'lit_s1_q8', 'lit_s1_q9', 'lit_s1_q10', 'lit_s1_q11', 'lit_s1_q12', 'lit_s1_q13', 'lit_s1_q14', 'lit_s1_q15', 'lit_s1_q16', /*'lit_s9_q2a',*/ 'lit_s9_q2b', 'lit_s9_q2c', 'lit_s9_q2d', 'lit_s9_q2e', 'lit_s9_q2f');

	for(var i = 0; i < literal_array.length; i++)
	{
		if (document.getElementById('div_' + literal_array[i])) document.getElementById('div_' + literal_array[i]).style.display = 'none';
	}
}

function is_array(input)
{
	return typeof(input)=='object'&&(input instanceof Array);
}

function ShowLiteral(this_id)
{
	this_id_array = this_id.split(",");
	for (i = 0; i < this_id_array.length; i++)
	{
		if (document.getElementById('div_lit_' + this_id_array[i])) document.getElementById('div_lit_' + this_id_array[i]).style.display = 'block';
	}
}

function PopulateTotals(this_class)
{
	element_array = getElementsByClassName(document, 'div', this_class);

	for (key in element_array)
	{
		id_prefix = element_array[key].id.substr(0, (element_array[key].id.length - 6));
		GenerateTotals(id_prefix);
	}
}

function GenerateTotals(id_prefix)
{
	total = 0;

	for (i = 1; i <= 10; i++)
	{
		if ((document.getElementById(id_prefix + i)) && (!isNaN(document.getElementById(id_prefix + i).value)))
		{
			total = total + Number(document.getElementById(id_prefix + i).value);
		}
	}

	if (document.getElementById(id_prefix + "_total"))
	{
		document.getElementById(id_prefix + "_total").innerHTML = total;
	}
}

function getElementsByClassName(oElm, strTagName, strClassName)
{
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++)
	{
		oElement = arrElements[i];

		if(oRegExp.test(oElement.className))
		{
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

function checkAll(this_name, this_id, value)
{
	for (i = 0; i < 1000; i++)
	{
		id_name = this_name + '_' + i;
		if (document.getElementById(id_name))
		{
			document.getElementById(id_name).checked = value;
		}
	}

	document.getElementById(this_id).checked = false;
}

function inArray(array1, value) {
	var i;

	for (i=0; i < array1.length; i++) {

		if (array1[i] == value) {

			return true;
		}
	}
	return false;
};



function checkSome(this_name, this_type, this_id)
{
	for (i = 0; i < 1000; i++)
	{
		id_name = this_name + '_' + i;
		if (document.getElementById(id_name))
		{
			document.getElementById(id_name).checked = false;
		}
	}

	var myArray = [];

	if (this_type == 'CheckOccupationHealth')
	{
		myArray = [4  ,5  ,6  ,7  ,35  ,8,9,10, 23  ,11  ,12  ,13  ,14 ,15 ,16 ,17,18 ,29,19,20,21,22];
	}
	else if (this_type == 'CheckOccupationNonhealth')
	{
		myArray = [27 ,24 ,36 ,37 ,28  ,34  ,33  ,3,2,1  ,25, 26  ,18,31,30, 32];
	}
	else if (this_type == 'CheckOccAgriculture')
	{
		myArray = [23];
	}
	else if (this_type == 'CheckOccAttorney')
	{
		myArray = [27 ,24 ,25  ,36 ,3 ];
	}
	else if (this_type == 'CheckOccChildren')
	{
		myArray = [37];
	}
	else if (this_type == 'CheckOccCommunity')
	{
		myArray = [31, 30];
	}
	else if (this_type == 'CheckOccEducation')
	{
		myArray = [32];
	}
	else if (this_type == 'CheckOccHealth')
	{
		myArray = [4  ,5  ,6  ,7  ,35 ,8,9,10, 23  ,11  ,12  ,13  ,14 ,15 ,16 ,17,18 ,29,19,20,21,22];
	}
	else if (this_type == 'CheckOccNatural')
	{
		myArray = [33  ,1];
	}
	else if (this_type == 'CheckOccNorthern')
	{
		myArray = [2];
	}
	else if (this_type == 'CheckOccNoAffiliation')
	{
		myArray = [28];
	}

	for (i = 0; i < 1000; i++)
	{
		id_name = this_name + '_' + i;
		if (document.getElementById(id_name))
		{
			if (inArray(myArray, document.getElementById(id_name).value))
			{
				document.getElementById(id_name).checked = true;
			}
		}
	}




	/*
	for (i = 0; i < myArray.length; i++)
	{
		id_name = this_name + '_' + myArray[i];
		if (document.getElementById(id_name))
		{
			document.getElementById(id_name).checked = true;
		}
	}
	*/
	document.getElementById(this_id).checked = false;
}
