    // 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=="e800") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_specs.htm' target=_blank>Spezifikationen</a> | <a href='http://www.epiacenter.com/modules.php?name=Content&pa=showpage&pid=17' target=_blank>Review</a><br>";
	}	
	
	else if (tipMB=="e5000") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_specs.htm' target=_blank>Spezifikationen</a> | - <br>";
	}	
	
    else if (tipMB=="cl6k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_cl_specs.htm' target=_blank>Spezifikationen</a> | - <br>";
	}	
	
	else if (tipMB=="cl10k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_cl_specs.htm' target=_blank>Spezifikationen</a> | <a href='http://www.epiacenter.com/modules.php?name=Content&pa=showpage&pid=22' target=_blank>Review</a><br>";
	}	
	
	else if (tipMB=="m6k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_m_specs.htm' target=_blank>Spezifikationen</a> | - <br>";
	}	

	else if (tipMB=="m10k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_m_specs.htm' target=_blank>Spezifikationen</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") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_m2_specs.htm' target=_blank>Spezifikationen</a> | - <br>";
	}	
	
	else if (tipMB=="m2_10k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_m2_specs.htm' target=_blank>Spezifikationen</a> | <a href='http://epiacenter.com/modules.php?name=Content&pa=showpage&pid=36' target=_blank>Review</a><br>";
	}	
	
	else if (tipMB=="m2_12k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_m2_specs.htm' target=_blank>Spezifikationen</a> | <a href='http://epiacenter.de/modules.php?name=Content&pa=showpage&pid=135' target=_blank>Review</a><br>";
	}	
	
	else if (tipMB=="ml5k"||tipMB=="ml8k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_ml_specs.htm' target=_blank>Spezifikationen</a> | - <br>";
	}

	else if (tipMB=="ms8k"||tipMB=="ms10k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_ms_specs.htm' target=_blank>Spezifikationen</a> | - <br>";
	}

    else if (tipMB=="ms12k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_ms_specs.htm' target=_blank>Spezifikationen</a> | <a href='http://epiacenter.de/modules.php?name=Content&pa=showpage&pid=132' target=_blank>Review</a><br>";
	}

	else if (tipMB=="n5k"||tipMB=="n1k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/nano_itx/epia_n_specs.htm' target=_blank>Spezifikationen</a> | - <br>";
	}

	else if (tipMB=="n8k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/nano_itx/epia_n_specs.htm' target=_blank>Spezifikationen</a> | <a href='http://epiacenter.de/modules.php?name=Content&pa=showpage&pid=168' target=_blank>Review</a> <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' target=_blank>Spezifikationen</a> | - <br>";
	}
	
	else if (tipMB=="pd6k"||tipMB=="pd10k") {
	    label_notes.innerHTML="";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_pd_specs.htm' target=_blank>Spezifikationen</a> | - <br>";
	}
	
	else if (tipMB=="sp8k") {
	    label_notes.innerHTML ="Die EPIA SP Mainboard Dokumentation enthält keine Angaben zu 'Netzwerk' & 'MP3' Verbrauch. Deshalb sind diese Modi auf 0W gesetzt!<br>";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_sp_specs.htm' target=_blank>Spezifikationen</a> | - <br>";
	}
	
    else if (tipMB=="sp13k") {
	    label_notes.innerHTML ="Die EPIA SP Mainboard Dokumentation enthält keine Angaben zu 'Netzwerk' & 'MP3' Verbrauch. Deshalb sind diese Modi auf 0W gesetzt!<br>";
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_sp_specs.htm' target=_blank>Spezifikationen</a> | <a href='http://epiacenter.de/modules.php?name=Content&pa=showpage&pid=134' target=_blank>Review</a><br>";
	}
	
    else if (tipMB=="dp") {
	    label_notes.innerHTML ="Die EPIA DP310 Mainboard Dokumentation enthält nur Angaben zum Verbrauch bei 'div. Anwendungen', etwa mit dem Verbrauch bei 'Office Anwendungen' vergleichbar. Sonstige Modi sind auf 0W gesetzt!<br>";
	    label_links.innerHTML ="<a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_dp_specs.htm' target=_blank>Spezifikationen</a> | <a href='http://epiacenter.de/modules.php?name=Content&pa=showpage&pid=163' target=_blank>Review</a><br>";
	}

	else if (tipMB=="tc6k") {
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_tc_specs.htm' target=_blank>Spezifikationen</a> | - <br>";
	    label_notes.innerHTML="";
	}
	
	else if (tipMB=="tc10k") {
	    label_links.innerHTML ="  <a href='http://www.viac3.de/vepd/produkte/mini_itx/epia_tc_specs.htm' target=_blank>Spezifikationen</a> | <a href='http://epiacenter.de/modules.php?name=Content&pa=showpage&pid=67' 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>Spezifikationen</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;
    };
    
