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



function ServerModule(model) {

var a=model;

var max1=0;
var idle1=0;
var max2=0;
var idle2=0;
var max3=0;
var idle3=0;

var workload=(((1*document.form1.workload.value))/100);

switch (a) {
case 0: max1=0; idle1=0; break;
// Case of Model Quad Core Intel Xeon E7338 Processor (2.40 GHz / 80W) AC PSU
case 1: 
if ((1*document.form1.power.value)==1) {

	if ((1*document.form1.FourGbMemory.value)==4) {
	max1=409;
	idle1=260;
	}
	if ((1*document.form1.FourGbMemory.value)==8) {
	max1=453;
	idle1=300;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max1=541;
	idle1=380;
	}
	if ((1*document.form1.FourGbMemory.value)==32) {
	max1=717;
	idle1=540;
	}

	if ((1*document.form1.TwoGbMemory.value)==4) {
	max2=409;
	idle2=260;
	}
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max2=453;
	idle2=300;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max2=541;
	idle2=380;
	}
	if ((1*document.form1.TwoGbMemory.value)==32) {
	max2=717;
	idle2=540;
	}
}

if ((1*document.form1.power.value)==2) {

	if ((1*document.form1.FourGbMemory.value)==4) {
	max1=397;
	idle1=252;
	}
	if ((1*document.form1.FourGbMemory.value)==8) {
	max1=439;
	idle1=291;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max1=525;
	idle1=369;
	}
	if ((1*document.form1.FourGbMemory.value)==32) {
	max1=695;
	idle1=524;
	}

	if ((1*document.form1.TwoGbMemory.value)==4) {
	max2=397;
	idle2=252;
	}
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max2=439;
	idle2=291;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max2=525;
	idle2=369;
	}
	if ((1*document.form1.TwoGbMemory.value)==32) {
	max2=695;
	idle2=524;
	}
}

break;

}


// Calculates Total Memory Usage
// Logic is this way so that we can easily accomodate DIMM mixes - if needed
if ((max1>max2)&&(max1>max3)) {
var system_power=max1;
var system_idle=idle1;
}
else if ((max2>max1)&&(max2>max3)) {
var system_power=max2;
var system_idle=idle2;
}
else if ((max3>max2)&&(max3>max1)) {
var system_power=max3;
var system_idle=idle3;
}
else {
var system_power=0;
var system_idle=0;
}

//Subtract 1HDD & 1PCIe Wattage
system_power = system_power - 23;
system_idle = system_idle - 23;

// Calculates Total HDD Wattage
var hdd_idle=(8*document.form1.HardDrive146.value);
var hdd_max=(8*document.form1.HardDrive146.value);

// Calculates Total Optical Drive Wattage
var dvd_idle=(3*document.form1.DVD.value);
var dvd_max=(8*document.form1.DVD.value);


// Calculates Total PCI-E Wattage
var pci_idle=(15*document.form1.pci.value);
var pci_max=(15*document.form1.pci.value);

// Calculates Total PCI-X Wattage
var pcix_idle=(15*document.form1.pcix.value);
var pcix_max=(15*document.form1.pcix.value);


var total_idle=system_idle+hdd_idle+dvd_idle+pci_idle+pcix_idle;
var total_max=system_power+hdd_max+dvd_max+pci_max+pcix_max;

var tot=Math.round((100*((total_idle+((total_max-total_idle)*workload))))/100);

document.form1.tot2_idle.value=total_idle;
document.form1.tot2_power.value=tot;
document.form1.btu_power.value=Math.round((((document.form1.tot2_idle.value*3600)/1055.056)*100)/100);
document.form1.btu_power2.value=Math.round((((document.form1.tot2_power.value*3600)/1055.056)*100)/100);

}


function ServerModule2(model2) {

var a=model2;

var max1=0;
var idle1=0;
var max2=0;
var idle2=0;
var max3=0;
var idle3=0;

var workload=(((1*document.form1.workload.value))/100);


switch (a) {
case 0: max1=0; idle1=0; break;
// Case of Model Quad Core Intel Xeon E7338 Processor (2.40 GHz / 80W) AC PSU
case 1: 
if ((1*document.form1.power.value)==1) {

	if ((1*document.form1.FourGbMemory.value)==4) {
	max1=536;
	idle1=305;
	}
	if ((1*document.form1.FourGbMemory.value)==8) {
	max1=580;
	idle1=345;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max1=668;
	idle1=425;
	}
	if ((1*document.form1.FourGbMemory.value)==32) {
	max1=844;
	idle1=585;
	}

	if ((1*document.form1.TwoGbMemory.value)==4) {
	max2=536;
	idle2=305;
	}
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max2=580;
	idle2=345;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max2=668;
	idle2=425;
	}
	if ((1*document.form1.TwoGbMemory.value)==32) {
	max2=844;
	idle2=585;
	}
}

if ((1*document.form1.power.value)==2) {

	if ((1*document.form1.FourGbMemory.value)==4) {
	max1=520;
	idle1=296;
	}
	if ((1*document.form1.FourGbMemory.value)==8) {
	max1=563;
	idle1=335;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max1=648;
	idle1=412;
	}
	if ((1*document.form1.FourGbMemory.value)==32) {
	max1=819;
	idle1=567;
	}

	if ((1*document.form1.TwoGbMemory.value)==4) {
	max2=520;
	idle2=296;
	}
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max2=563;
	idle2=335;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max2=648;
	idle2=412;
	}
	if ((1*document.form1.TwoGbMemory.value)==32) {
	max2=819;
	idle2=567;
	}
}

break;

}


// Calculates Total Memory Usage
// Logic is this way so that we can easily accomodate DIMM mixes - if needed
if ((max1>max2)&&(max1>max3)) {
var system_power=max1;
var system_idle=idle1;
}
else if ((max2>max1)&&(max2>max3)) {
var system_power=max2;
var system_idle=idle2;
}
else if ((max3>max2)&&(max3>max1)) {
var system_power=max3;
var system_idle=idle3;
}
else {
var system_power=0;
var system_idle=0;
}

//Subtract 1HDD & 1PCIe Wattage
system_power = system_power - 23;
system_idle = system_idle - 23;

// Calculates Total HDD Wattage
var hdd_idle=(8*document.form1.HardDrive146.value);
var hdd_max=(8*document.form1.HardDrive146.value);

// Calculates Total Optical Drive Wattage
var dvd_idle=(3*document.form1.DVD.value);
var dvd_max=(8*document.form1.DVD.value);


// Calculates Total PCI-E Wattage
var pci_idle=(15*document.form1.pci.value);
var pci_max=(15*document.form1.pci.value);

// Calculates Total PCI-X Wattage
var pcix_idle=(15*document.form1.pcix.value);
var pcix_max=(15*document.form1.pcix.value);


var total_idle=system_idle+hdd_idle+dvd_idle+pci_idle+pcix_idle;
var total_max=system_power+hdd_max+dvd_max+pci_max+pcix_max;

var tot=Math.round((100*((total_idle+((total_max-total_idle)*workload))))/100);

document.form1.tot2_idle.value=total_idle;
document.form1.tot2_power.value=tot;
document.form1.btu_power.value=Math.round((((document.form1.tot2_idle.value*3600)/1055.056)*100)/100);
document.form1.btu_power2.value=Math.round((((document.form1.tot2_power.value*3600)/1055.056)*100)/100);

}



function systot() {
var a=(1*document.form1.Processor.value);
var b=(1*document.form1.Quantity.value);

if (b == 2) {
ServerModule(a);
}
else if (b == 4) {
ServerModule2(a);
}
}


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


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

selbox.options[selbox.options.length] = new Option('None','0');
selbox.options[selbox.options.length] = new Option('1 HDD','1');
selbox.options[selbox.options.length] = new Option('2 HDDs','2');

if (chosen == "0") {
  
  selbox.options[selbox.options.length] = new Option('3 HDDs','3');
  selbox.options[selbox.options.length] = new Option('4 HDDs','4');
}
if (chosen == "1") {
  //do nothing
}*/
}

function PrintMenu() {
var a=((1*document.form1.DVD.value));
if (a==0) {
setOptions('0');
}
if (a>0) {
setOptions('1');
}
}



function FinalCheck() {
//Checks to make sure user cannot proceed (Mozilla) if memory exceeds 16
if (((1*document.form1.FourGbMemory.value)+(1*document.form1.TwoGbMemory.value))>32) {
stop
}
//Checks to make sure user cannot proceed (Mozilla) if no memory is selected
else if (((1*document.form1.TwoGbMemory.value)+(1*document.form1.FourGbMemory.value))==0) {
stop
}
else {
proceed();
}
}


function CheckForm () { 

	//Initialise variables
	var errorMsg = "";


	//Check for DIMM quantity
	if ((document.form1.FourGbMemory.value == "0")&&(document.form1.TwoGbMemory.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();
}



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

