    // this holds the running mainboard onbject
    runningBoard = null;
    savedMode = "Idle";    
    // prototype to add rails for an object
    addRailsValue = function(rail3V, rail5V, rail5VSB, rail12V, rail12VCPU)
    {
	this.rail3V = rail3V;
	this.rail5V = rail5V;
	this.rail5VSB = rail5VSB;
	this.rail12V = rail12V;
	this.rail12VCPU = rail12VCPU;
    };

    //prototype add new current values for a given operation
    OperationValues =  function(name, object)
    {
	this.name = name;
	this.current = object;
	this.running = 0;
    }
    
    //prototype add new current values for a given mainboard mode
    ModeValues =  function(name, object)
    {
	this.name = name;
	this.current = object;
    }

    // main object (motherboard)
    Board = function(name)
    {
	// name of the board
	this.name = name;
	
	// the image of the board if exists
	this.image = ""
	
	// init voltagem, current, modes and operations.
	this.actualVoltage = new addRailsValue(0,0,0,0,0);;
	this.power = new addRailsValue(0,0,0,0,0);
	this.current = new addRailsValue(0,0,0,0,0);
	this.OperationsCount = 0;
	this.Operations = [];
	this.ModesCount = 0;
	this.Modes = [];
	this.ActualMode = "none";
	
    };
    
    //add a operation for the main object
    Board.prototype.addOperation = function(name, object)
    {
	this.Operations[this.OperationsCount] = new OperationValues(name, object);
	this.OperationsCount++;
    };
    //add a functional base mode for the main object 
    Board.prototype.addMode = function(name, object)
    {
	this.Modes[this.ModesCount] = new ModeValues(name, object);
	this.ModesCount++;
    };
    
    //computer the power needs for a given operation
    Board.prototype.computeOperationPower = function(index)
    {
	var power = new addRailsValue(0,0,0,0,0);
	
	power.rail3V += this.Operations[index].current.rail3V * this.actualVoltage.rail3V;
	power.rail5V += this.Operations[index].current.rail5V * this.actualVoltage.rail5V;
	power.rail5VSB += this.Operations[index].current.rail5VSB * this.actualVoltage.rail5VSB;
	power.rail12V += this.Operations[index].current.rail12V * this.actualVoltage.rail12V;
	power.rail12VCPU += this.Operations[index].current.rail12VCPU * this.actualVoltage.rail12VCPU;
	
	return power;
    };
    
    //computer the current needs for a given operation
    Board.prototype.computeOperationCurrent = function(index)
    {
	var current = new addRailsValue(0,0,0,0,0);
	
	current.rail3V += this.Operations[index].current.rail3V;
	current.rail5V += this.Operations[index].current.rail5V;
	current.rail5VSB += this.Operations[index].current.rail5VSB;
	current.rail12V += this.Operations[index].current.rail12V;
	current.rail12VCPU += this.Operations[index].current.rail12VCPU;
	
	return current;
    };

    //computer the power needs for a given mode
    Board.prototype.computeModePower = function(index)
    {
	var power = new addRailsValue(0,0,0,0,0);
	
	power.rail3V += this.Modes[index].current.rail3V * this.actualVoltage.rail3V;
	power.rail5V += this.Modes[index].current.rail5V * this.actualVoltage.rail5V;
	power.rail5VSB += this.Modes[index].current.rail5VSB * this.actualVoltage.rail5VSB;
	power.rail12V += this.Modes[index].current.rail12V * this.actualVoltage.rail12V;
	power.rail12VCPU += this.Modes[index].current.rail12VCPU * this.actualVoltage.rail12VCPU;
	
	return power;
    };
    
    //computer the current needs for a given mode
    Board.prototype.computeModeCurrent = function(index)
    {
	var current = new addRailsValue(0,0,0,0,0);
	
	current.rail3V += this.Modes[index].current.rail3V;
	current.rail5V += this.Modes[index].current.rail5V;
	current.rail5VSB += this.Modes[index].current.rail5VSB;
	current.rail12V += this.Modes[index].current.rail12V;
	current.rail12VCPU += this.Modes[index].current.rail12VCPU;
	
	return current;
    };
    
    

    //changes the basic mode of operation for the main object
    Board.prototype.changeMode = function(mode) 
    {
	var p = this.power;
	var c = this.current;
	var opower, ocurrent;
	var index = this.findMode(mode);
	var oldindex = this.findMode(this.ActualMode);
	if (index < 0) {
	    alert ("Mode not found or no mainboard selected");
	    return;
	}
	
	//remove the old mode and add the new one
	if ( oldindex >= 0) {
	    var oldpower = this.computeModePower(oldindex);
	    var oldcurrent = this.computeModeCurrent(oldindex);
	    
	    opower = this.computeModePower(index);
	    ocurrent = this.computeModeCurrent(index);
	    
	    opower.rail3V -= oldpower.rail3V;
	    opower.rail5V -= oldpower.rail5V;
	    opower.rail5VSB -= oldpower.rail5VSB;
	    opower.rail12V -= oldpower.rail12V;
	    opower.rail12VCPU -= oldpower.rail12VCPU;
	
	    ocurrent.rail3V -= oldcurrent.rail3V;
	    ocurrent.rail5V -= oldcurrent.rail5V;
	    ocurrent.rail5VSB -= oldcurrent.rail5VSB;
	    ocurrent.rail12V -= oldcurrent.rail12V;
	    ocurrent.rail12VCPU -= oldcurrent.rail12VCPU;
	    
	} else {
	    opower = this.computeModePower(index);
	    ocurrent = this.computeModeCurrent(index);
	}
	
	p.rail3V += opower.rail3V;
	p.rail5V += opower.rail5V;
	p.rail5VSB += opower.rail5VSB;
	p.rail12V += opower.rail12V;
	p.rail12VCPU += opower.rail12VCPU;
	
	c.rail3V += ocurrent.rail3V;
	c.rail5V += ocurrent.rail5V;
	c.rail5VSB += ocurrent.rail5VSB;
	c.rail12V += ocurrent.rail12V;
	c.rail12VCPU += ocurrent.rail12VCPU;
	
	//change the actual mode
	this.ActualMode = mode;
	savedMode = mode;
    }
    
    //finds a operation in a operations list
    Board.prototype.findOperation = function(operation)
    {
	var index = this.OperationsCount - 1;
	while (index >= 0)
	{
	    if (operation == this.Operations[index].name) 
		return index;
	    index--;
	}
	return -1;
    };
    
    //finds a specified mode in a modes list
    Board.prototype.findMode = function(mode)
    {
	var index = this.ModesCount - 1;
	while (index >= 0)
	{
	    if (mode == this.Modes[index].name) 
		return index;
	    index--;
	}
	return -1;
    };
    
    Board.prototype.startOperation = function(operation)
    {
	var p = this.power;
	var c = this.current;
	var opower, ocurrent;
	var index = this.findOperation(operation);
	
	if (index < 0) {
	    alert ("Operation not found or no mainboard selected");
	    return;
	}
	this.Operations[index].running++;
	opower = this.computeOperationPower(index);
	ocurrent = this.computeOperationCurrent(index);
	
	p.rail3V += opower.rail3V;
	p.rail5V += opower.rail5V;
	p.rail5VSB += opower.rail5VSB;
	p.rail12V += opower.rail12V;
	p.rail12VCPU += opower.rail12VCPU;
	
	c.rail3V += ocurrent.rail3V;
	c.rail5V += ocurrent.rail5V;
	c.rail5VSB += ocurrent.rail5VSB;
	c.rail12V += ocurrent.rail12V;
	c.rail12VCPU += ocurrent.rail12VCPU;
	
    };
    
    Board.prototype.stopOperation = function(operation)
    {
	var p = this.power;
	var c = this.current;
	var opower, ocurrent;
	var index;
	
	index = this.findOperation(operation);
	
	if (index < 0) {
	    alert ("Operation not found or no mainboard selected");
	    return;
	}
	
	if (this.Operations[index].running == 0) return;
	
	this.Operations[index].running--;
	opower = this.computeOperationPower(index);
	ocurrent = this.computeOperationCurrent(index);
	
	p.rail3V -= opower.rail3V;
	p.rail5V -= opower.rail5V;
	p.rail5VSB -= opower.rail5VSB;
	p.rail12V -= opower.rail12V;
	p.rail12VCPU -= opower.rail12VCPU;
	
	c.rail3V -= ocurrent.rail3V;
	c.rail5V -= ocurrent.rail5V;
	c.rail5VSB -= ocurrent.rail5VSB;
	c.rail12V -= ocurrent.rail12V;
	c.rail12VCPU -= ocurrent.rail12VCPU;
    };
    
    Board.prototype.displayPower = function()
    {
    
	var p = this.power;
	var totalPower = p.rail3V + p.rail5V + p.rail5VSB + p.rail12V + p.rail12VCPU;
	
	document.write("3V Rail: " + p.rail3V);
	document.write("<br>5V Rail: " + p.rail5V);
	document.write("<br>5V SB Rail: " + p.rail5VSB);
	document.write("<br>12V Rail: " + p.rail12V);
	document.write("<br>12VCPU Rail: " + p.rail12VCPU);
	document.write("<br>Total: " + totalPower);
    };
    
    Board.prototype.formdisplayPower = function(form)
    {
	var p, c, index, totalPower, totalCurrent, toperations;
	
	p = this.power;
	c = this.current;
	index = this.OperationsCount - 1 ;
	totalPower = p.rail3V + p.rail5V + p.rail5VSB + p.rail12V + p.rail12VCPU;
	totalCurrent = c.rail3V + c.rail5V + c.rail5VSB + c.rail12V + c.rail12VCPU;
	toperations = "";
	
	form.prail3V.value = p.rail3V.toFixed(2);
	form.prail5V.value = p.rail5V.toFixed(2);
	form.prail5VSB.value = p.rail5VSB.toFixed(2);
	form.prail12V.value = p.rail12V.toFixed(2);
	//form.prail12VCPU.value = p.rail12VCPU.toFixed(2);
	form.ptotal.value = totalPower.toFixed(2);
	
	form.crail3V.value = c.rail3V.toFixed(2);
	form.crail5V.value = c.rail5V.toFixed(2);
	form.crail5VSB.value = c.rail5VSB.toFixed(2);
	form.crail12V.value = c.rail12V.toFixed(2);
	//form.crail12VCPU.value = c.rail12VCPU.toFixed(2);
	//form.ctotal.value = totalCurrent.toFixed(2);
	
	
	// MY NEW SANDBOX
	
	var tipMB=document.forms[0].select.value;

	if (tipMB=="e5000"||tipMB=="e800") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/mini_itx/epia/index.jsp#spec' target=_blank>specifications</a> | <a href='http://www.epiacenter.com/modules.php?name=Content&pa=showpage&pid=17' target=_blank>review</a><br>";
	}	
	
	else if (tipMB=="cl6k"||tipMB=="cl10k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/mini_itx/epia_pd/index.jsp#spec' target=_blank>specifications</a> | <a href='http://www.epiacenter.com/modules.php?name=Content&pa=showpage&pid=22' target=_blank>review</a><br>";
	}	

	else if (tipMB=="cn10k"||tipMB=="cn13k") {
	    label_notes.innerHTML ="The EPIA CN motherboard documentation doesn't contain 'network', 'mp3' & 'DVD playback' (only for the CN13000) mode power consumption figures and therefore they have been set to 0w in these modes.<br>";
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/motherboards.jsp?motherboard_id=400#spec' target=_blank>specifications</a> | -<br>";
	}

	else if (tipMB=="ek8k"||tipMB=="ek10k") {
	    label_notes.innerHTML ="";
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/motherboards.jsp?motherboard_id=420#spec' target=_blank>specifications</a> | -<br>";
	}
	
	else if (tipMB=="m6k"||tipMB=="m10k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/mini_itx/epia_m/index.jsp#spec' target=_blank>specifications</a> | <a href='http://www.epiacenter.com/modules.php?name=Content&pa=showpage&pid=21' target=_blank>review</a><br>";
	}	

	else if (tipMB=="m2_6k"||tipMB=="m2_10k"||tipMB=="m2_12k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/mini_itx/epia_m2/index.jsp#spec' target=_blank>specifications</a> | <a href='http://www.epiacenter.com/modules.php?name=Content&pa=showpage&pid=41' target=_blank>review</a><br>";
	}	
	
	else if (tipMB=="ml5k"||tipMB=="ml8k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/mini_itx/epia_ml/index.jsp#spec' target=_blank>specifications</a> | - <br>";
	}

	else if (tipMB=="ms8k"||tipMB=="ms10k"||tipMB=="ms12k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/mini_itx/epia_ms/index.jsp#spec' target=_blank>specifications</a> | <a href='http://www.epiacenter.com/modules.php?name=Content&pa=showpage&pid=65' target=_blank>review</a><br>";
	}


	else if (tipMB=="n5k"||tipMB=="n8k"||tipMB=="n1k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/nano_itx/epia_n/#spec' target=_blank>specifications</a> | <a href='http://www.epiacenter.com/modules.php?name=Content&pa=showpage&pid=84' target=_blank>review</a><br><br>";
	}

	else if (tipMB=="nl5k"||tipMB=="nl8k"||tipMB=="nl1k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/nano_itx/epia_nl/index.jsp#spec' target=_blank>specifications</a> | - <br>";
	}
	
	else if (tipMB=="pd6k"||tipMB=="pd10k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/mini_itx/epia_pd/index.jsp#spec' target=_blank>specifications</a> | - <br>";
	}
	
	else if (tipMB=="sp8k"||tipMB=="sp13k") {
	    label_notes.innerHTML ="The EPIA SP motherboard documentation doesn't contain 'network' & 'mp3' mode power consumption figures and therefore they have been set to 0w in these two modes.<br>";
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/mini_itx/epia_sp/index.jsp#spec' target=_blank>specifications</a> | <a href='http://www.epiacenter.com/modules.php?name=Content&pa=showpage&pid=58' target=_blank>review</a><br>";
	}
	else if (tipMB=="dp") {
	    label_notes.innerHTML ="The VT-310DP documentation only contains power consumptions figures for 'running common system applications' which should be roughly equal to the 'office applications' mode. All other modes have been set to 0w.<br>";
	    label_links.innerHTML ="<a href='http://www.via.com.tw/en/products/mainboards/mini_itx/vt_310dp/index.jsp#spec' target=_blank>specifications</a> | - <br>";
	}

	else if (tipMB=="tc6k"||tipMB=="tc10k") {
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/mini_itx/epia_tc/index.jsp#spec' target=_blank>specifications</a> | <a href='http://www.epiacenter.com/modules.php?name=Content&pa=showpage&pid=33' target=_blank>review</a><br>";
	    label_notes.innerHTML="";
	}

	else if (tipMB=="en12k"||tipMB=="en15k") {
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/mini_itx/epia_en/index.jsp#spec' target=_blank>specifications</a> | - <br>";
	    label_notes.innerHTML="";
	}

	else if (tipMB=="vb_15ghz"||tipMB=="vb_26ghz") {
	    label_links.innerHTML ="  <a href='http://www.via.com.tw/en/products/mainboards/motherboards.jsp?motherboard_id=430' target=_blank>specifications</a> | - <br>";
	    label_notes.innerHTML="";
	}
	
	else{
		label_notes.innerHTML="";
		label_links.innerHTML="";
	}
	
	
	
//	if (c.rail12V > 1.5) {
//	    if (document.forms[0].pow)
//		document.forms[0].pow.value = "Current on 12V rail exceeds 1.5A, must select PW-60a/b or PW-70a/b";
//	}
	
	//Another sample test.
//	if (totalPower > 60) {
	    //Do we have a form object to write to ?
//	    if (document.forms[0].pow)
//		document.forms[0].pow.value = "Power needs exceed 60W. You must select a more powerful AC adaptor!";
//	}
	
	while (index >= 0)
	{
	    toperations += this.Operations[index].name + ": " + this.Operations[index].running + "\n";
	    index--;
	}
	
	form.operations.value = toperations;
    };
    
