//assess-sliders.js must be loaded before this file

//set assessment specific variables
numquestions = 14;
answers = new Array(numquestions);
questSliders = new Array(numquestions);

//initialize all the arrays of answers
answers[0] = new Array("Critical", 
	"Important, but not critical", 
	"Very useful, but not important", 
	"Sometimes useful",
	"We don't have IT");

answers[1] = new Array("0 - 50", 
	"51 - 200", 
	"201 - 500",
	"500 - 1000", 
	"1000+");

answers[2] = new Array("Maintain in-house", 
	"Mostly in-house, but some systems are outsourced",
	"Approximately half and half",
	"Mostly outsourced, but some systems are inhouse", 
	"Outsourced"); 

answers[3] = new Array("Less than 1 year", 
	"1 - 2 years", 
	"2 - 3 years", 
	"3 - 6 years",
	"6 + years");

answers[4] = new Array("0 - 2", 
	"3 - 7", 
	"8 - 15",
	"15 - 25",
	"25+");
 
answers[5] = new Array("1", 
	"2", 
	"3", 
	"4", 
	"5");
 
answers[6] = new Array("10+",
	"5 - 10",
	"3- 5",
	"1 - 2",
	"0");
 
answers[7] = new Array("Yes, we regularly upgrade including testing.",
	"We upgrade regularly, and usually test.",
	"We upgrade regularly, and occasionally test.",
	"We upgrade regularly, but do not test.", 
	"We do not regularly upgrade software or I'm not sure");
 
answers[8] = new Array("Yes, all of it is licensed.", 
	"Most of it is licensed.", 
	"Some of it is licensed.", 
	"None of it is.",
	"I'm not sure."); 

answers[9] = new Array("Both physical and electronic measures",
	"Physical, such as controlled access to systems and ID cards",
	"Electronic, including strong password policies and firewalls",
	"Neither",
	"I'm not sure what security measures we have");
 
answers[10] = new Array("Yes, we regularly monitor for abuse.", 
	"Sometimes we monitor for abuse.", 
	"We rarely monitor for abuse.",
	"We never monitor for abuse.",
	"I'm not sure.");
 
answers[11] = new Array("Back-up generators for all systems",
	"Back-up generators for critical systems", 
	"UPS for all systems", 
	"UPS for critical systems only", 
	"We have no backup system or I'm not sure"); 

answers[12] = new Array("Daily", 
	"Weekly", 
	"Monthly", 
	"Less than monthly",
	"Irregular or I don't know");
 
answers[13] = new Array("Both off-site storage for backups and multiple locations with IT assets",
	"Multiple locations with IT assets",
	"Off-site storage for copies of all backups",
	"Off-site storage for copies of critical backups",
	"Neither");

//register the init function so that all the sliders are initialized once the page is loaded
addLoadEvent( function(){ init(questSliders, answers, 200); } );
addLoadEvent( function(){ initAllNavButtons("navbutton");
						  document.getElementById("genassess").action = "javascript: assess();"; } );

/*
getSliderValue - returns the value of a slider based on the calculated increment
param i - int - the position of the slider in the slider array
*/
function getSliderValue(i)
{
	return questSliders[i].getValue() * ( 1 / ( 200 / answers[i].length ) ) + 1;
}

/*
assess - compute a score for the survey based on the given answers
*/
function assess(){
	
	var total = 0;
	var instanceAnswers = new Object;
	
	var importance = 6 - getSliderValue(0);
	var numbercomps = getSliderValue(1);
	var inhouse = 6 - getSliderValue(2);
	
	var itCriticality =  ( importance + numbercomps + inhouse )/3;
	
	instanceAnswers['compage'] = 6 - getSliderValue(3);
	instanceAnswers['personnel'] = getSliderValue(4);
	instanceAnswers['itprof'] = getSliderValue(5); 
	instanceAnswers['classes'] = 6 - getSliderValue(6);
	
	if ( !(instanceAnswers['personnel'] < (numbercomps - 1)) )
	{
		instanceAnswers['personnel'] = 5;
	}
	
	
	
	instanceAnswers['upgrades'] = 6 - getSliderValue(7);
	instanceAnswers['licensed'] = 6 - getSliderValue(8);
	
	
	
	instanceAnswers['security'] = 6 - getSliderValue(9);
	instanceAnswers['abuse'] = 6 - getSliderValue(10);
	
	
	
	instanceAnswers['power'] = 6 - getSliderValue(11);
	instanceAnswers['backups'] = 6 - getSliderValue(12);
	instanceAnswers['offsite'] = 6 - getSliderValue(13);
	
	

	for ( var i in instanceAnswers )
	{
		if ( instanceAnswers[i] <= 3 && i != 'personnel')
		{
			instanceAnswers[i] -= Math.round(itCriticality/2);
		}

		
		if ( instanceAnswers[i] < 0) { instanceAnswers[i] = 0; }

		total += instanceAnswers[i]
		
	}
	var personnel = instanceAnswers['personnel'] + instanceAnswers['itprof'] + instanceAnswers['classes'];
	var software = instanceAnswers['upgrades'] + instanceAnswers['licensed'];
	var security = instanceAnswers['security'] + instanceAnswers['abuse'];
	var continuity = instanceAnswers['power'] + instanceAnswers['backups'] + instanceAnswers['offsite'];
	
	
	document.hiddenForm.total.value = Math.round( (total / 55) * 100 );
	document.hiddenForm.itCriticality.value = itCriticality;
	if( personnel <= 8 ) { document.hiddenForm.personnel.value = true; }
	if( software <= 6 ) { document.hiddenForm.software.value = true; }
	if( (instanceAnswers['compage'] < 3 && itCriticality > 3) || instanceAnswers['compage'] == 1 ) { document.hiddenForm.compage.value = true; }
	if( security <= 6 ) { document.hiddenForm.security.value = true; }
	if( continuity <= 9 ) { document.hiddenForm.continuity.value = true; }

	document.hiddenForm.submit();
}

