﻿// the table container
// need a checkbox renglish and rmetric
// and a table named 'ct'
// a class named simpleA (for the links)
// fmt3 second col
// fmt5 the others

	var mil=true;
	function fmt(t,p)
	{	var s=new String;
		s='' + t;
		if(s.length<=p)return s;
		var dp=(p==1)?'.':',';			
		return s.substr(0,s.length-p)+dp+s.substr(s.length-p,p)
	}
		
	function maketable(tblName, mil){
    	var tbl=document.getElementById(tblName);
	    var i,j;
	    while(tbl.rows.length>2)			// remove previous table, if there....
		    tbl.deleteRow(2)
	    for(i=0;i<container.length;i++){
		    var rw=container[i].split(";");				
		    var tr=tbl.insertRow(-1);		// at the begining
		    tr=tbl.rows.item(tbl.rows.length-1)
		    for (j=0;j<rw.length;j++)
		     {  var td=tr.insertCell();
			    var dp=(j>=3&&j<=7)?mil?3:1:(j>7&&j<=10)?3:99;
			    td.align=(j==2)?"center":(j>=3)?"right":"left";			
			    td.className=(j==2)?"fmt5":"fmt3";
			    if(j==1)
			    { var l="\<a class=\"simpleA\" href=\"\" onclick=\"javascript:return false;\" onmouseover=\"javascript:m_over(this)\"\>"+rw[j]+"<a>";
			      td.innerHTML=l;
			    }else
			    { td.innerText=(rw[j]==0)?"":(j>=3&&j<=7&&!(mil==false))?fmt(Math.floor(eval(rw[j]/25.4)),dp)+"\"":(j>=7&&j<=10&&!(mil==false))?fmt(Math.floor(eval(rw[j]*2.2)),dp)+"#":(j>=3&&j<=10)?fmt(rw[j],dp):rw[j];
			    }
		      } // for each column
          } // for each line
	    } // maketable
	 //
	var lasttr=null;
	//
	function m_over(t)
		{   if(lasttr)lasttr.bgcolor='white';
			lasttr=t.parentElement.parentElement;
			lasttr.bgcolor='#c0c0c0';			
			// msg.innerText=lasttr.children(2).innerText						
			var nm=lasttr.children(2).innerText
			// move the element to here...
			if(nm.indexOf("\/")>=0)nm=nm.split("\/")[0];	// take the first
			var img = "\/images\/containers\/c_" + nm + ".gif"
			var cimage=document.getElementById('cimage')
			cimage.src=img;
			cimage.style.top=t.style.top;
			return false;   // ignore the ckick
		}		
	//
	function newunit(n){
		var en=document.getElementById("renglish")		
		en.checked=(n.id=='renglish');
		var mm=document.getElementById("rmetric")		
		mm.checked=(n.id=='rmetric');
		mil=(n.id=='renglish');
		maketable("ct", mil);	
		}
