<!---
//*******************************************************************************
//*                                                                             *
//* fuse and cable diameter calculator
//* 
//*
//*******************************************************************************
//* Sinn und Zweck:
//* Throw in basic data of your car audio install and get the required
//* main cable diameter and max fuse size calculated
//*
//* Version 2007
//* the tables are based on the EMMA Rulebook 2007
//* Update: 2006-11-27
//*
//*******************************************************************************
//*
//* copyright by ROWEX
//* author: Rothschopf Werner, Egidiweg 244, A 5582 St. Michael
//* email: noiasca@yahoo.com
//*
//* Lizenzbestimmungen:
//*
//* this source must not be coppied or provided without permission of the author.
//* removing this disclaimer is not allowed.
//*
//*******************************************************************************
//* functionality
//*
//* + vice versa cacuclating of power / WRMS per amplifer
//* + calculation of main (possible) wire diameter
//* + calculation of main fuse size
//* + calculation of 
//*
//* missing so far
//* - "small" diameters are not kicked out
//* - print function
//* - layout
//* - grafical diagram
//* 
//*
//*******************************************************************************

var correction = 2.5;   // given by EMMA also in Rulebook 2007
var voltage_loss=0.5;   // given by EMMA also in Rulebook 2007
var fi = 57;            // for copper  also in Rulebook 2007
var u = 13;             // average voltage according rulebook 2003/2004
var efficiency = 0.5 ;  // average efficiency of analog amplifier according rulebook 2003/2004 and 2007

function ausfuellen()
 {
// the crazy main programm ... 

   headunit();
   other();
   amplifier();
   
// output of caculcated DATA 
   document.frm_rowex.a_main.value=round(main_a());
   document.frm_rowex.diameter_main.value=round(calc_diameter(document.frm_rowex.length_main.value,document.frm_rowex.a_main.value ));
   document.frm_rowex.diameter_available.value=calc_wire (document.frm_rowex.diameter_main.value);
   document.frm_rowex.fuse_available.value=calc_fuse (document.frm_rowex.diameter_available.value*1);
   

}

function headunit()
{

//    document.frm_rowex.fuse_headunit.value=99;
      document.frm_rowex.diameter_headunit.value = round(calc_diameter (document.frm_rowex.length_headunit.value, document.frm_rowex.a_headunit.value));
      document.frm_rowex.fuse_headunit.value = calc_fuse (document.frm_rowex.diameter_headunit.value);
}


function other()
{

//    
      document.frm_rowex.diameter_other.value = round(calc_diameter (document.frm_rowex.length_other.value, document.frm_rowex.a_other.value));
      document.frm_rowex.fuse_other.value = calc_fuse (document.frm_rowex.diameter_other.value);
}



function amplifier()
{
//    calculate the diameters (and fuses) for the amplifiers

      document.frm_rowex.diameter_1.value = round(calc_diameter (document.frm_rowex.length_1.value, document.frm_rowex.a_1.value));
      document.frm_rowex.fuse_1.value = calc_fuse (document.frm_rowex.diameter_1.value);
      
      document.frm_rowex.diameter_2.value = round(calc_diameter (document.frm_rowex.length_2.value, document.frm_rowex.a_2.value));
      document.frm_rowex.fuse_2.value = calc_fuse (document.frm_rowex.diameter_2.value);

      document.frm_rowex.diameter_3.value = round(calc_diameter (document.frm_rowex.length_3.value, document.frm_rowex.a_3.value));
      document.frm_rowex.fuse_3.value = calc_fuse (document.frm_rowex.diameter_3.value);

      document.frm_rowex.diameter_4.value = round(calc_diameter (document.frm_rowex.length_4.value, document.frm_rowex.a_4.value));
      document.frm_rowex.fuse_4.value = calc_fuse (document.frm_rowex.diameter_4.value);

}

function calc_diameter(cabellength, ampere) {
// Kabeldiameter=correction*(cabellength*ampere)/(fi*voltage_loss)
	var diameter=correction * (cabellength*ampere)/(fi*voltage_loss);
	return diameter;

}

function calc_a_headunit (w){
// calculates Ampere out of Watt for Headunit
   return round(w/u);	

}

function calc_w_headunit (a){
// calculates Watt out of Ampere for Headunit
   return round(a*u);	
}


function calc_a (wrms){
// calculates Ampere out of WRMS
   return round(wrms/(efficiency*u));
}

function calc_w (ampere){
// calculates WRMS out of givven ampere
   return round(ampere*efficiency*u);
}


function calc_fuse (diameter) {
// calculates the max fuse for a given diameter

  if (diameter==0){ return "0" };  
  if (diameter<=0.5){ return "5"};
  if (diameter<=0.75){ return "7.5"};
  if (diameter<=1){ return "10"};
  if (diameter<=1.5){ return "15"};                
  if (diameter<=2.5){ return "25"};
  if (diameter<=4){ return "30"};   
  if (diameter<=6){ return "40"};   
  if (diameter<=8){ return "50"};   
  if (diameter<=10){ return "60"};   
  if (diameter<=16){ return "80"};   
  if (diameter<=20){ return "100"};   
  if (diameter<=25){ return "125"};   
  if (diameter<=35){ return "150"};   
  if (diameter<=50){ return "200"};   
  if (diameter<=70){ return "250"};   
  if (diameter<=95){ return "300"};
  if (diameter>95){ return "not mentioned by EMMA"};
  if (diameter=="a copper bar"){ return "not mentioned by EMMA"};

  
}

function calc_wire (diameter){
// looks for next available diameter 
//  alert(diameter);
  if (diameter==0){ return "0" };  
  if (diameter<=0.5){ return "0.5"};
  if (diameter<=0.75){ return "0.75"};
  if (diameter<=1){ return "1"};
  if (diameter<=1.5){ return "1.5"};                
  if (diameter<=2.5){ return "2.5"};
  if (diameter<=4){ return "4"};   
  if (diameter<=6){ return "6"};   
  if (diameter<=8){ return "8"};   
  if (diameter<=10){ return "10"};   
  if (diameter<=16){ return "16"};   
  if (diameter<=20){ return "20"};   
  if (diameter<=25){ return "25"};   
  if (diameter<=30){ return "30"};   
  if (diameter<=50){ return "50"};   
  if (diameter<=70){ return "70"};   
  if (diameter<=95){ return "95"};
  if (diameter>95){ return "a copper bar"}; 

 

}

// actions, if something is changed in form

function change_a_headunit(){
  document.frm_rowex.w_headunit.value=calc_w_headunit(document.frm_rowex.a_headunit.value);
  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
}

function change_w_headunit(){
  document.frm_rowex.a_headunit.value=calc_a_headunit(document.frm_rowex.w_headunit.value);	
  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
}

function change_a_other(){
  document.frm_rowex.w_other.value=calc_w_headunit(document.frm_rowex.a_other.value);	
  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
}

function change_w_other(){
  document.frm_rowex.a_other.value=calc_a_headunit(document.frm_rowex.w_other.value);	
  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
}

function change_a_1(){
  document.frm_rowex.w_1.value=round(calc_w(document.frm_rowex.a_1.value));	
  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
}

function change_w_1(){
  document.frm_rowex.a_1.value=round(calc_a(document.frm_rowex.w_1.value));	
  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
}

function change_a_2(){
  document.frm_rowex.w_2.value=round(calc_w(document.frm_rowex.a_2.value));	
  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
}

function change_w_2(){
  document.frm_rowex.a_2.value=round(calc_a(document.frm_rowex.w_2.value));	
  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
}

function change_a_3(){
  document.frm_rowex.w_3.value=round(calc_w(document.frm_rowex.a_3.value));	
  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
  }

function change_w_3(){
  document.frm_rowex.a_3.value=round(calc_a(document.frm_rowex.w_3.value));	
  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
  }

function change_a_4(){
  document.frm_rowex.w_4.value=round(calc_w(document.frm_rowex.a_4.value));	
  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
}
function change_w_4(){
  document.frm_rowex.a_4.value=round(calc_a(document.frm_rowex.w_4.value));	
  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
}

function change_length_main(){
//funny is, that this field will change it any time, no matter about autoproof

  if (document.frm_rowex.option_autoproof.checked){ausfuellen();}	
}

function main_a() {
// how much ampere must be delivered on main cable
   var ampere = 0;
   ampere = document.frm_rowex.a_1.value*1 + document.frm_rowex.a_2.value*1 + document.frm_rowex.a_3.value*1 + document.frm_rowex.a_4.value*1
   if (document.frm_rowex.option_headunit.value == "r" ){
      ampere = ampere + document.frm_rowex.a_headunit.value*1; 
      }
   if (document.frm_rowex.option_other.value == "r" ){
      ampere = ampere + document.frm_rowex.a_other.value*1; 
      }
   return ampere
}

function round(rowex) {
//   classical rounding or ;-) 
	 rowex = rowex + 0.05;
     rowex = Math.floor(rowex*10);
     rowex = rowex/10;
     return rowex;	
}



// --->


