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



function ServerModule(model) {

var a=model;

var max=0;
var idle=0;

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

switch (a) {
case 0: max=0; idle=0; break;
// Case of Model UltraSPARC T2+ 8-core CPUs (1.2 GHz)
case 1: 
if ((1*document.form1.power.value)==1) {

	if ((1*document.form1.FourGbMemory.value)==8) {
	max=586;
	idle=327;
	}
	if ((1*document.form1.FourGbMemory.value)==12) {
	max=644;
	idle=389;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max=715;
	idle=440;
	}
	if ((1*document.form1.FourGbMemory.value)==24) {
	max=860;
	idle=517;
	}
	if ((1*document.form1.FourGbMemory.value)==32) {
	max=968;
	idle=572;
	}
	
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max=562;
	idle=352;
	}
	if ((1*document.form1.TwoGbMemory.value)==12) {
	max=634;
	idle=402;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max=705;
	idle=452;
	}
	if ((1*document.form1.TwoGbMemory.value)==24) {
	max=805;
	idle=518;
	}
	if ((1*document.form1.TwoGbMemory.value)==32) {
	max=905;
	idle=584;
	}
	
	if ((1*document.form1.OneGbMemory.value)==8) {
	max=535;
	idle=330;
	}
	if ((1*document.form1.OneGbMemory.value)==12) {
	max=575;
	idle=384;
	}
	if ((1*document.form1.OneGbMemory.value)==16) {
	max=614;
	idle=394;
	}
	if ((1*document.form1.OneGbMemory.value)==24) {
	max=702;
	idle=502;
	}
	if ((1*document.form1.OneGbMemory.value)==32) {
	max=770;
	idle=525;
	}	
}

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

	if ((1*document.form1.FourGbMemory.value)==8) {
	max=568;
	idle=317;
	}
	if ((1*document.form1.FourGbMemory.value)==12) {
	max=625;
	idle=377;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max=694;
	idle=427;
	}
	if ((1*document.form1.FourGbMemory.value)==24) {
	max=834;
	idle=501;
	}
	if ((1*document.form1.FourGbMemory.value)==32) {
	max=939;
	idle=555;
	}
	
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max=545;
	idle=341;
	}
	if ((1*document.form1.TwoGbMemory.value)==12) {
	max=614;
	idle=390;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max=684;
	idle=438;
	}
	if ((1*document.form1.TwoGbMemory.value)==24) {
	max=781;
	idle=502;
	}
	if ((1*document.form1.TwoGbMemory.value)==32) {
	max=878;
	idle=566;
	}
	
	if ((1*document.form1.OneGbMemory.value)==8) {
	max=519;
	idle=320;
	}
	if ((1*document.form1.OneGbMemory.value)==12) {
	max=558;
	idle=372;
	}
	if ((1*document.form1.OneGbMemory.value)==16) {
	max=596;
	idle=382;
	}
	if ((1*document.form1.OneGbMemory.value)==24) {
	max=681;
	idle=487;
	}
	if ((1*document.form1.OneGbMemory.value)==32) {
	max=747;
	idle=509;
	}
	
}

break;

// Case of Model UltraSPARC T2+ 6-core CPUs (1.2 GHz)
case 2: 
if ((1*document.form1.power.value)==1) {

	if ((1*document.form1.FourGbMemory.value)==8) {
	max=557;
	idle=350;
	}
	if ((1*document.form1.FourGbMemory.value)==12) {
	max=629;
	idle=393;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max=701;
	idle=436;
	}
	if ((1*document.form1.FourGbMemory.value)==24) {
	max=792;
	idle=511;
	}
	if ((1*document.form1.FourGbMemory.value)==32) {
	max=883;
	idle=586;
	}
	
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max=519;
	idle=348;
	}
	if ((1*document.form1.TwoGbMemory.value)==12) {
	max=577;
	idle=385;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max=634;
	idle=422;
	}
	if ((1*document.form1.TwoGbMemory.value)==24) {
	max=739;
	idle=507;
	}
	if ((1*document.form1.TwoGbMemory.value)==32) {
	max=843;
	idle=591;
	}
	
	if ((1*document.form1.OneGbMemory.value)==8) {
	max=288;
	idle=175;
	}
	if ((1*document.form1.OneGbMemory.value)==12) {
	max=308;
	idle=202;
	}
	if ((1*document.form1.OneGbMemory.value)==16) {
	max=599;
	idle=428;
	}
	if ((1*document.form1.OneGbMemory.value)==24) {
	max=666;
	idle=510;
	}
	if ((1*document.form1.OneGbMemory.value)==32) {
	max=737;
	idle=580;
	}	
}

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

	if ((1*document.form1.FourGbMemory.value)==8) {
	max=540;
	idle=340;
	}
	if ((1*document.form1.FourGbMemory.value)==12) {
	max=610;
	idle=381;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max=680;
	idle=423;
	}
	if ((1*document.form1.FourGbMemory.value)==24) {
	max=768;
	idle=496;
	}
	if ((1*document.form1.FourGbMemory.value)==32) {
	max=857;
	idle=568;
	}
	
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max=503;
	idle=338;
	}
	if ((1*document.form1.TwoGbMemory.value)==12) {
	max=559;
	idle=373;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max=615;
	idle=409;
	}
	if ((1*document.form1.TwoGbMemory.value)==24) {
	max=716;
	idle=491;
	}
	if ((1*document.form1.TwoGbMemory.value)==32) {
	max=818;
	idle=573;
	}
	
	if ((1*document.form1.OneGbMemory.value)==8) {
	max=279;
	idle=170;
	}
	if ((1*document.form1.OneGbMemory.value)==12) {
	max=298;
	idle=196;
	}
	if ((1*document.form1.OneGbMemory.value)==16) {
	max=581;
	idle=415;
	}
	if ((1*document.form1.OneGbMemory.value)==24) {
	max=646;
	idle=495;
	}
	if ((1*document.form1.OneGbMemory.value)==32) {
	max=715;
	idle=563;
	}
	
}

break;

// Case of Model UltraSPARC T2+ 8-core CPUs (1.4 GHz)
case 3: 
if ((1*document.form1.power.value)==1) {

	if ((1*document.form1.FourGbMemory.value)==8) {
	max=644;
	idle=385;
	}
	if ((1*document.form1.FourGbMemory.value)==12) {
	max=702;
	idle=447;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max=773;
	idle=498;
	}
	if ((1*document.form1.FourGbMemory.value)==24) {
	max=918;
	idle=575;
	}
	if ((1*document.form1.FourGbMemory.value)==32) {
	max=1026;
	idle=630;
	}
	
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max=620;
	idle=410;
	}
	if ((1*document.form1.TwoGbMemory.value)==12) {
	max=692;
	idle=460;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max=763;
	idle=510;
	}
	if ((1*document.form1.TwoGbMemory.value)==24) {
	max=863;
	idle=576;
	}
	if ((1*document.form1.TwoGbMemory.value)==32) {
	max=963;
	idle=642;
	}
	
	if ((1*document.form1.OneGbMemory.value)==8) {
	max=593;
	idle=388;
	}
	if ((1*document.form1.OneGbMemory.value)==12) {
	max=633;
	idle=442;
	}
	if ((1*document.form1.OneGbMemory.value)==16) {
	max=672;
	idle=452;
	}
	if ((1*document.form1.OneGbMemory.value)==24) {
	max=760;
	idle=560;
	}
	if ((1*document.form1.OneGbMemory.value)==32) {
	max=828;
	idle=583;
	}	
}

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

	if ((1*document.form1.FourGbMemory.value)==8) {
	max=626;
	idle=375;
	}
	if ((1*document.form1.FourGbMemory.value)==12) {
	max=683;
	idle=435;
	}
	if ((1*document.form1.FourGbMemory.value)==16) {
	max=752;
	idle=485;
	}
	if ((1*document.form1.FourGbMemory.value)==24) {
	max=892;
	idle=559;
	}
	if ((1*document.form1.FourGbMemory.value)==32) {
	max=997;
	idle=613;
	}
	
	if ((1*document.form1.TwoGbMemory.value)==8) {
	max=603;
	idle=399;
	}
	if ((1*document.form1.TwoGbMemory.value)==12) {
	max=672;
	idle=448;
	}
	if ((1*document.form1.TwoGbMemory.value)==16) {
	max=742;
	idle=496;
	}
	if ((1*document.form1.TwoGbMemory.value)==24) {
	max=839;
	idle=560;
	}
	if ((1*document.form1.TwoGbMemory.value)==32) {
	max=936;
	idle=624;
	}
	
	if ((1*document.form1.OneGbMemory.value)==8) {
	max=577;
	idle=378;
	}
	if ((1*document.form1.OneGbMemory.value)==12) {
	max=616;
	idle=430;
	}
	if ((1*document.form1.OneGbMemory.value)==16) {
	max=654;
	idle=440;
	}
	if ((1*document.form1.OneGbMemory.value)==24) {
	max=739;
	idle=545;
	}
	if ((1*document.form1.OneGbMemory.value)==32) {
	max=805;
	idle=567;
	}
	
}

break;

}


// Calculates Total Memory Usage
var system_power=max;
var system_idle=idle;

//Subtract 1DVD & 1PCIe Wattage
system_power = system_power - 16;
system_idle = system_idle - 11;

// 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);

//Uncomment and Extend below logic if more CPUs get added!
/*if (b == 1) {
ServerModule(a);
}
else if (b == 2) {
ServerModule2(a);
}*/

ServerModule(a);
}


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


function setOptions(chosen) {
	//Nothing needed for now.
/*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() {
	//Nothing needed for now.
/*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)+(1*document.form1.OneGbMemory.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)+(1*document.form1.OneGbMemory.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")&&(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();
}



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

