
/////////////////////////////////////////////////////////////////////////
/////////// 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 L5408 Processor (2.13 GHz / 40W LVATCA) AC PSU
case 1: 
if ((1*document.form1.power.value)==1) {

	if ((1*document.form1.TwoGbMemory.value)==2) {
	max2=172;
	idle2=155;
	}
	if ((1*document.form1.TwoGbMemory.value)==4) {
	max2=194;
	idle2=175;
	}
	if ((1*document.form1.TwoGbMemory.value)==6) {
	max2=216;
	idle2=195;
	}
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max2=238;
	idle2=215;
	}
	if ((1*document.form1.TwoGbMemory.value)==10) {
	max2=260;
	idle2=235;
	}
	if ((1*document.form1.TwoGbMemory.value)==12) {
	max2=282;
	idle2=255;
	}
	if ((1*document.form1.TwoGbMemory.value)==14) {
	max2=304;
	idle2=275;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max2=326;
	idle2=295;
	}

	if ((1*document.form1.FourGbMemory.value)==2) {
	max1=172;
	idle1=155;
	}
	if ((1*document.form1.FourGbMemory.value)==4) {
	max1=194;
	idle1=175;
	}
	if ((1*document.form1.FourGbMemory.value)==6) {
	max1=216;
	idle1=195;
	}
	if ((1*document.form1.FourGbMemory.value)==8) {
	max1=238;
	idle1=215;
	}
	if ((1*document.form1.FourGbMemory.value)==10) {
	max1=260;
	idle1=235;
	}
	if ((1*document.form1.FourGbMemory.value)==12) {
	max1=282;
	idle1=255;
	}
	if ((1*document.form1.FourGbMemory.value)==14) {
	max1=304;
	idle1=275;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max1=326;
	idle1=295;
	}
}

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

	if ((1*document.form1.TwoGbMemory.value)==2) {
	max2=166;
	idle2=149;
	}
	if ((1*document.form1.TwoGbMemory.value)==4) {
	max2=188;
	idle2=169;
	}
	if ((1*document.form1.TwoGbMemory.value)==6) {
	max2=208;
	idle2=188;
	}
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max2=230;
	idle2=208;
	}
	if ((1*document.form1.TwoGbMemory.value)==10) {
	max2=251;
	idle2=227;
	}
	if ((1*document.form1.TwoGbMemory.value)==12) {
	max2=273;
	idle2=247;
	}
	if ((1*document.form1.TwoGbMemory.value)==14) {
	max2=294;
	idle2=266;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max2=316;
	idle2=286;
	}
	
	if ((1*document.form1.FourGbMemory.value)==2) {
	max1=166;
	idle1=149;
	}
	if ((1*document.form1.FourGbMemory.value)==4) {
	max1=188;
	idle1=169;
	}
	if ((1*document.form1.FourGbMemory.value)==6) {
	max1=208;
	idle1=188;
	}
	if ((1*document.form1.FourGbMemory.value)==8) {
	max1=230;
	idle1=208;
	}
	if ((1*document.form1.FourGbMemory.value)==10) {
	max1=251;
	idle1=227;
	}
	if ((1*document.form1.FourGbMemory.value)==12) {
	max1=273;
	idle1=247;
	}
	if ((1*document.form1.FourGbMemory.value)==14) {
	max1=294;
	idle1=266;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max1=316;
	idle1=286;
	}

	
}

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 L5408 Processor (2.13 GHz / 40W LVATCA) AC PSU
case 1: 
if ((1*document.form1.power.value)==1) {

	if ((1*document.form1.TwoGbMemory.value)==2) {
	max2=209;
	idle2=169;
	}
	if ((1*document.form1.TwoGbMemory.value)==4) {
	max2=231;
	idle2=189;
	}
	if ((1*document.form1.TwoGbMemory.value)==6) {
	max2=253;
	idle2=209;
	}
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max2=275;
	idle2=229;
	}
	if ((1*document.form1.TwoGbMemory.value)==10) {
	max2=297;
	idle2=249;
	}
	if ((1*document.form1.TwoGbMemory.value)==12) {
	max2=319;
	idle2=269;
	}
	if ((1*document.form1.TwoGbMemory.value)==14) {
	max2=341;
	idle2=289;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max2=363;
	idle2=309;
	}

	if ((1*document.form1.FourGbMemory.value)==2) {
	max1=209;
	idle1=169;
	}
	if ((1*document.form1.FourGbMemory.value)==4) {
	max1=231;
	idle1=189;
	}
	if ((1*document.form1.FourGbMemory.value)==6) {
	max1=253;
	idle1=209;
	}
	if ((1*document.form1.FourGbMemory.value)==8) {
	max1=275;
	idle1=229;
	}
	if ((1*document.form1.FourGbMemory.value)==10) {
	max1=297;
	idle1=249;
	}
	if ((1*document.form1.FourGbMemory.value)==12) {
	max1=319;
	idle1=269;
	}
	if ((1*document.form1.FourGbMemory.value)==14) {
	max1=341;
	idle1=289;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max1=363;
	idle1=309;
	}
}

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

	if ((1*document.form1.TwoGbMemory.value)==2) {
	max2=202;
	idle2=163;
	}
	if ((1*document.form1.TwoGbMemory.value)==4) {
	max2=224;
	idle2=183;
	}
	if ((1*document.form1.TwoGbMemory.value)==6) {
	max2=244;
	idle2=202;
	}
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max2=266;
	idle2=222;
	}
	if ((1*document.form1.TwoGbMemory.value)==10) {
	max2=287;
	idle2=241;
	}
	if ((1*document.form1.TwoGbMemory.value)==12) {
	max2=309;
	idle2=261;
	}
	if ((1*document.form1.TwoGbMemory.value)==14) {
	max2=330;
	idle2=279;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max2=352;
	idle2=299;
	}

	if ((1*document.form1.FourGbMemory.value)==2) {
	max1=202;
	idle1=163;
	}
	if ((1*document.form1.FourGbMemory.value)==4) {
	max1=224;
	idle1=183;
	}
	if ((1*document.form1.FourGbMemory.value)==6) {
	max1=244;
	idle1=202;
	}
	if ((1*document.form1.FourGbMemory.value)==8) {
	max1=266;
	idle1=222;
	}
	if ((1*document.form1.FourGbMemory.value)==10) {
	max1=287;
	idle1=241;
	}
	if ((1*document.form1.FourGbMemory.value)==12) {
	max1=309;
	idle1=261;
	}
	if ((1*document.form1.FourGbMemory.value)==14) {
	max1=330;
	idle1=279;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max1=352;
	idle1=299;
	}
}

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 == 1) {
ServerModule(a);
}
else if (b == 2) {
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');
}
selbox.options[1].selected = true;
}

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))>16) {
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();
}

