/* set values from the table staff_percents in the ALL doc */
/*
var staff1 = ['.25','.2','.15','.2','.2','.1','.1','.05','.05'];
var staff2 = ['.25','.3','.35','.35','.35','.4','.4','.4','.4'];
var staff3 = ['.4','.35','.35','.25','.25','.25','.2','.2','.2'];
var staff4 = ['.1','.15','.15','.2','.2','.25','.3','.35','.35'];
*/
var staff1 = ['.4','.3','.3','.25','.25','.25','.2','.2','.2'];
var staff2 = ['.1','.2','.2','.25','.3','.25','.3','.35','.35'];
var staff3 = ['.4','.35','.35','.3','.25','.25','.2','.2','.2'];
var staff4 = ['.1','.15','.15','.2','.2','.25','.3','.25','.25'];

var salary = [];

	
function calculate () {
	var staff_percent = [];	
	var staff_cost = [];
	var complexity, fulltimestaff, staff_percent, staff_total_percent, staff_cost, annual_cost;
	var cost_you_low, cost_you_high, cost_ac_low, cost_ac_high, save_cost_low, save_cost_high;
	
	/* start calling out functions needed for computation */

	var num_users = document.getElementById('val_num_users').value;
	var num_servers = document.getElementById('val_num_servers').value;
	var equip_age = document.getElementById('val_equip_age').value;
	var user_soph = document.getElementById('val_user_soph').value;
	var app_cap = document.getElementById('val_app_cap').value;
	
	var sal1 = document.getElementById('sal1').value;
	var sal2 = document.getElementById('sal2').value;
	var sal3 = document.getElementById('sal3').value;
	var sal4 = document.getElementById('sal4').value;
	
	salary = [sal1, sal2, sal3, sal4];
	complexity = get_complexity(num_users, num_servers, equip_age, user_soph, app_cap);
	fulltimestaff = get_fulltimestaff(complexity);
	staff_percent = get_staff_percent(complexity, fulltimestaff);
	staff_total_percent = get_staff_total_percent(staff_percent);
	staff_cost = get_staff_cost(staff_percent, salary);
	annual_cost = get_annual_cost(staff_cost);
	cost_you_low = get_cost_you_low(annual_cost);
	cost_you_high = get_cost_you_high(annual_cost);
	cost_ac_low = get_cost_ac_low(cost_you_low);
	cost_ac_high = get_cost_ac_high(cost_you_high);
	save_cost_low = get_save_low(cost_you_low,cost_ac_low); 
	save_cost_high = get_save_high(cost_you_high,cost_ac_high);
	
	set_cost_you_low (cost_you_low);
	set_cost_you_high (cost_you_high);
	set_cost_ac_low (cost_ac_low);
	set_cost_ac_high (cost_ac_high);
	set_full_time_staff (fulltimestaff);
	set_save_low (save_cost_low);
	
	return false;
}

function get_complexity(num_users,num_servers,equip_age,user_soph,app_cap) {
	var complexity = ((num_users * .75) + (num_servers * 3.25) + (equip_age * 3) + (user_soph * 4) + (app_cap * 4))/10;
	//alert ("complexity:" + complexity);
	if (complexity < 1) {
		complexity = 1;
	}
	if (complexity > 9) {
		complexity = 9; 
	}

	if ((complexity > 1) && (complexity < 2)) {
		complexity = 1;
	}
	if ((complexity > 2) && (complexity < 3)) {
		complexity = 2;
	}
	if ((complexity > 3) && (complexity < 4)) {
		complexity = 3;
	}
	if ((complexity > 4) && (complexity < 5)) {
		complexity = 4;
	}
	if ((complexity > 5) && (complexity < 6)) {
		complexity = 5;
	}
	if ((complexity > 6) && (complexity < 7)) {
		complexity = 6;
	}
	if ((complexity > 7) && (complexity < 8)) {
		complexity = 7;
	}
	if ((complexity > 8) && (complexity < 9)) {
		complexity = 8;
	}

	return complexity;
}

function get_fulltimestaff(complexity) {
	var fulltimestaff;

	if (complexity == 1) {
		fulltimestaff = .33;
	} else if (complexity == 2) {
		fulltimestaff = .5;
	} else if (complexity == 3) {
		fulltimestaff = .75;
	} else if (complexity == 4) { 
		fulltimestaff = 1.0;
	} else if (complexity == 5) {
		fulltimestaff = 1.5;
	} else if (complexity == 6) {
		fulltimestaff = 1.75;
	} else if (complexity == 7) {
		fulltimestaff = 2.0;
	} else if (complexity == 8) {
		fulltimestaff = 2.5;
	} else if (complexity == 9) {
		fulltimestaff = 3.0;
	}
	
	return fulltimestaff;
}

function get_staff_percent(complexity, fulltimestaff) {
	var staffpercent1 = staff1[complexity-1];

	var staffpercent2 = staff2[complexity-1];
	var staffpercent3 = staff3[complexity-1];
	var staffpercent4 = staff4[complexity-1];
	
	var staff1_percent = Math.round(100 * staffpercent1 * fulltimestaff)/100;
	var staff2_percent = Math.round(100 * staffpercent2 * fulltimestaff)/100;
	var staff3_percent = Math.round(100 * staffpercent3 * fulltimestaff)/100;
	var staff4_percent = Math.round(100 * staffpercent4 * fulltimestaff)/100;
	
	var staff_percent = [staff1_percent,staff2_percent,staff3_percent,staff4_percent];
/*	alert ("staff1_percent: "+ staff_percent[0]);
	alert ("staff1_percent: "+ staff_percent[1]);
	alert ("staff1_percent: "+ staff_percent[2]);
	alert ("staff1_percent: "+ staff_percent[3]);
*/	
	return staff_percent;
}

function get_staff_total_percent(staff_percent) {
	set_staff_total_percent(staff_percent);
	return staff_percent[0]+staff_percent[1]+staff_percent[2]+staff_percent[3];	
}
function set_staff_total_percent(staff_percent)
{
document.getElementById("staffpercent").value= staff_percent[0]+","+staff_percent[1]+","+staff_percent[2]+","+staff_percent[3];	
}

function get_staff_cost(staff_percent, salary) {
	var staff1_cost = Math.round(staff_percent[0] * salary[0]);
	var staff2_cost = Math.round(staff_percent[1] * salary[1]);
	var staff3_cost = Math.round(staff_percent[2] * salary[2]);
	var staff4_cost = Math.round(staff_percent[3] * salary[3]);
	
	var staff_cost = [staff1_cost, staff2_cost, staff3_cost, staff4_cost];
	/*alert ("staff_cost:"+ staff_cost);*/
	return staff_cost;
}

function get_annual_cost (staff_cost) {
	var cost_you = ((staff_cost[0] + staff_cost[1] + staff_cost[2] + staff_cost[3]));
	return cost_you;
}

function get_cost_you_low(cost_you) {
	var cost_you_low = cost_you * .67;
	/*alert ("cost_you_low:"+cost_you_low);*/
	return Math.round(cost_you_low);
}
function get_cost_you_high(cost_you) {
	var cost_you_high = cost_you * 1.33;
	//("get_cost_you_high:"+cost_you_high);
	return Math.round(cost_you_high);
}	
function get_cost_ac_low(cost_you_low) {
	var cost_ac_low = cost_you_low * .35;
	if (cost_ac_low < 12) {
		cost_ac_low = 12;
	}
	return Math.round(cost_ac_low);
}
function get_cost_ac_high(cost_you_high) {
	var cost_ac_high = cost_you_high * .35;
	return Math.round(cost_ac_high);
}
function get_save_low(cost_you_low, cost_ac_low) {
	var save_low = cost_you_low - cost_ac_low;
	//alert ("save_low: "+ save_low);
	return Math.round(save_low);
	
}
function get_save_high(cost_you_high, cost_ac_high) {
	var save_high = cost_you_high - cost_ac_high;
	//alert ("save_high: "+ save_high);
	return Math.round(save_high);
}

function set_cost_you_low (cost) {
	document.getElementById('cost-you-low').value = Math.round(cost);
	document.getElementById('cost-you-low2').value = Math.round(cost);
	return false;
}
function set_cost_you_high (cost) {
	document.getElementById('cost-you-high').value  = Math.round(cost);
	document.getElementById('cost-you-high2').value  = Math.round(cost);
	return false;
}
function set_cost_ac_low (cost) {
	document.getElementById('cost-ac-low').value  = Math.round(cost);
	document.getElementById('cost-ac-low2').value  = Math.round(cost);
	return false;
}
function set_cost_ac_high (cost) {
	document.getElementById('cost-ac-high').value  = Math.round(cost);
	document.getElementById('cost-ac-high2').value  = Math.round(cost);
	return false;
}
function set_full_time_staff (value) {
	document.getElementById('full-time-staff').value = value;
	return false;
}
function set_save_low (value) {
	document.getElementById('save-low').value = value;
	return false;
}



function changeDesc(id) {
	var desc_title;
	var desc_text;
	
	if(id==1) {
		desc_title = "Support Specialist";
		desc_text = "Entry Level, Provides Day to Day Desktop Support";
	} else if(id==2) {
		desc_title = "Systems Enginner";
		desc_text = "Seasoned Design and Deploys LAN, WAN, Servers";
	} else if(id==3) {
		desc_title = "Solutions Architect";
		desc_text = "Senior, Plans IT decisions based on Business needs";
	} else if(id==4) {
		desc_title = "IT Manager";
		desc_text = "Senior, Plans IT decisions based on Business needs";
	} else if(id==5) {
		desc_title = "CIO/CTO";
		desc_text = "Chief Information/Technology Officer provides short and long term technology planning, managed technology strategy and implementation";
	} else if(id==6) {
		desc_title = "Help Desk";
		desc_text = "Multi member supprt team of on-demand resources available to troubleshoot, diagnose and correct IT issues.";
	} else if(id==7) {
		desc_title = "Remote Services";
		desc_text = "24/7 Monitoring and Remote Support of critical systems";
	}
		
	document.getElementById('desc_title').innerHTML = desc_title;
	document.getElementById('desc_text').innerHTML = desc_text;
}

function set_record_values(num_users, num_servers, equip_age, user_soph, app_cap) {
	var record = "Users: " + num_users + "- Servers: " + num_servers + " - Equipment age: " + equip_age + "- Users: " + user_soph + " - Complexity: " + app_cap;
	document.getElementById('record').value = record;
	//alert(record);
}