
/////////////////////////////////////////////////////////////////////////
/////////// Calculates Total Wattage for System Configuration///////////
///////////////////////////////////////////////////////////////////////


function systot() {
	
// Calculates Total Power of Processor
var cpu=1*document.form1.Processor.value;
var workload=(((1*document.form1.workload.value))/100);

if (cpu == 1) {
var cpu_idle=232.9;
var cpu_peak=358.1;
}
else if (cpu == 2) {
var cpu_idle=201.9;
var cpu_peak=243.1;
}
else if (cpu == 3) {
var cpu_idle=41.11;
var cpu_peak=62.53;
}
else if (cpu == 4) {
var cpu_idle=115.3;
var cpu_peak=145.9;
}
else if (cpu == 5) {
var cpu_idle=242.9;
var cpu_peak=370.2;

}


// Calculates Total Power of Memory
var mem_idle=((2*document.form1.EightGbMemory.value)+(2*document.form1.FourGbMemory.value)+(2*document.form1.TwoGbMemory.value)+(2*document.form1.OneGbMemory.value));
var mem_peak=((7.5*document.form1.EightGbMemory.value)+(8.3*document.form1.FourGbMemory.value)+(8.3*document.form1.TwoGbMemory.value)+(8.3*document.form1.OneGbMemory.value));

// Calculate Total Power of Hard Drives
var hdd_idle=(((8*document.form1.HardDrive146.value)+(.1*document.form1.sata.value)));
var hdd_peak=(((10*document.form1.HardDrive146.value)+(2.4*document.form1.sata.value)));

// Calculates Total Power for PCI-Express and XAUI Cards
var cards_idle=((10*document.form1.pci.value)+(6*document.form1.xaui.value));
var cards_peak=((17*document.form1.pci.value)+(12*document.form1.xaui.value));

var dvd=(9*document.form1.dvd.value);

// Assigns values for fixes components
var motherboard_idle=0;
var motherboard_peak=0;
var fans_idle=0;
var fans_peak=0;


// Assigns Final Power Values
var tot_power=Math.round((cpu_peak+mem_peak+hdd_peak+cards_peak+motherboard_peak+fans_peak+dvd)*100)/100;
var tot_idle=Math.round((cpu_idle+mem_idle+hdd_idle+cards_idle+motherboard_idle+fans_idle+dvd)*100)/100;

var tot=Math.round(100*((tot_idle+((tot_power-tot_idle)*workload))))/100;
document.form1.tot2_power.value=Math.round(tot/.85);
document.form1.tot2_idle.value=Math.round(tot_idle/.85);

var btu_idle=(1*document.form1.tot2_idle.value);
var btu_peak=(1*document.form1.tot2_power.value);
var btu_tot_idle=((btu_idle*3600)/1055.056);
var btu_tot_peak=((btu_peak*3600)/1055.056);

document.form1.btu_power.value=Math.round(btu_tot_idle);
document.form1.btu_power2.value=Math.round(btu_tot_peak);
}


function FinalCheck() {
//Checks to make sure user cannot proceed (Mozilla) if memory is mixed
if ((1*document.form1.EightGbMemory.value>0)&&((1*document.form1.FourGbMemory.value>0)||(1*document.form1.OneGbMemory.value>0)||(1*document.form1.TwoGbMemory.value>0))) {
stop
}
if ((1*document.form1.FourGbMemory.value>0)&&((1*document.form1.EightGbMemory.value>0)||(1*document.form1.OneGbMemory.value>2)||(1*document.form1.TwoGbMemory.value>0))) {
stop
}
else if ((1*document.form1.TwoGbMemory.value>0)&&((1*document.form1.EightGbMemory.value>0)||(1*document.form1.OneGbMemory.value>2)||(1*document.form1.FourGbMemory.value>0))) {
stop
}
else if ((1*document.form1.OneGbMemory.value>0)&&((1*document.form1.EightGbMemory.value>0)||(1*document.form1.TwoGbMemory.value>2)||(1*document.form1.FourGbMemory.value>0))) {
stop
}
//Checks to make sure user cannot proceed (Mozilla) if no memory is selected
else if (((1*document.form1.EightGbMemory.value)+(1*document.form1.OneGbMemory.value)+(1*document.form1.TwoGbMemory.value)+(1*document.form1.FourGbMemory.value))==0) {
stop
}
//Checks to make sure user cannot proceed (Mozilla) if hard drives are mixed
else if (((1*document.form1.HardDrive146.value)+(1*document.form1.sata.value))>16) {
stop
}
else {
proceed();
}
}


function CheckForm () { 

	//Initialise variables
	var errorMsg = "";


	//Check for DIMM quantity
	if ((document.form1.EightGbMemory.value == "0")&&(document.form1.FourGbMemory.value == "0")&&(document.form1.TwoGbMemory.value == "0")&&(document.form1.OneGbMemory.value == "0")){
		errorMsg += "\n\tDIMMs \t\t- Enter # of DIMMs desired";	
	}
	

	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Your request has not been processed because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	FinalCheck();
}


function setOptions(chosen) {
var selbox = document.form1.pci
 
selbox.options.length = 0;

if (chosen == "0") {
  selbox.options[selbox.options.length] = new Option('None','0');
  selbox.options[selbox.options.length] = new Option('1 PCIe Card','1');
  selbox.options[selbox.options.length] = new Option('2 PCIe Cards','2');
  selbox.options[selbox.options.length] = new Option('3 PCIe Cards','3');
  selbox.options[selbox.options.length] = new Option('4 PCIe Cards','4');
  selbox.options[selbox.options.length] = new Option('5 PCIe Cards','5');
  selbox.options[selbox.options.length] = new Option('6 PCIe Cards','6');
}
if (chosen == "1") {
  selbox.options[selbox.options.length] = new Option('None','0');
  selbox.options[selbox.options.length] = new Option('1 PCIe Card','1');
  selbox.options[selbox.options.length] = new Option('2 PCIe Cards','2');
  selbox.options[selbox.options.length] = new Option('3 PCIe Cards','3');
  selbox.options[selbox.options.length] = new Option('4 PCIe Cards','4');
  selbox.options[selbox.options.length] = new Option('5 PCIe Cards','5');
}
if (chosen == "2") {
  selbox.options[selbox.options.length] = new Option('None','0');
  selbox.options[selbox.options.length] = new Option('1 PCIe Card','1');
  selbox.options[selbox.options.length] = new Option('2 PCIe Cards','2');
  selbox.options[selbox.options.length] = new Option('3 PCIe Cards','3');
  selbox.options[selbox.options.length] = new Option('4 PCIe Cards','4');
}
}


function PrintMenu() {
var a=document.form1.xaui.value;
if (a==0) {
setOptions('0');
}
if (a==1) {
setOptions('1');
}
if (a==2) {
setOptions('2');
}
}


// Calls ALL Functions
function proceed() {
systot();
}


// Ttests to ensure that at least 4 DIMMS are selected
function parameterchecksone() {
CheckForm();
}

