 var active_obj=false;function my_round(v){if( v==0 )return parseFloat(String(v));if( !v || v=="")return "";obj=document.getElementById("dokla"); 	
    if( obj )x=obj.selectedIndex+2;else x=2;x_max=Math.pow(10,x); 	
    if( Math.abs(parseFloat(v)) < parseFloat(1/x_max) ){ 	
      var v=new Number(v);
      return v.toExponential(x);
      } 
    if( v > 100000 ){ 
      var v=new Number(v); 
      return v.toExponential(x); 
      } 
    num=Math.round(v*x_max); 
    return parseFloat(num/x_max); 
    } 
  function licz(wg){  
    if( wg ) 
      active_obj=wg; 
    else 
      wg=active_obj; 
    wg.style.fontWeight="bold"; 
    wg.style.color="yellow";  
    str=String(wg.id) 
    ix=str.substring(1,3); 
    wg_addx=wg.getAttribute("addx"); 
    wg_base=wg.getAttribute("base"); 
    if( wg_addx )b1=wg_addx;else b1=0; 
    for( i=1; i<=50; i++ ){ 
      obj=document.getElementById( "g"+i ); 
      if( !obj )break; 
      if( ix!=i ){ 
      obj.style.color="white"; 
      obj.style.fontWeight="normal"; 
      obj_addx=obj.getAttribute("addx"); 
      if( obj_addx )b2=obj_addx;else b2=0; 
      obj_base=obj.getAttribute("base"); 
      if( obj_base ){ 
        if( !b1 && !b2 ){ 
          obj.value=my_round(((wg.value*wg_base))/obj_base); 
          } 
        else  { 
           obj.value=my_round((parseFloat(obj_base)*(parseFloat(wg.value)-parseFloat(b1)))/parseFloat(wg_base)+parseFloat(b2)); 
          } 
          } 
        }  
        } 
    if( typeof(user_fun)!="undefined" )user_fun();
    } 
  function ckey(e){ 
    if( typeof(act_opis)!="undefined" ){
      act_opis=0;
      opis(0);
      }
    if( typeof(dtc_clear)!="undefined" ){
      dtc_clear();
      }
    fld=(!e ? window.event.srcElement : e.target ); 
    if( !e )e=window.event; 
      k=e.keyCode; 
    a=String.fromCharCode( k ); 
    v=String(fld.value); 
    if( k==190 || k==110 ){  
      if( v.indexOf( "." )==-1 ) 
        return true; 
      else 
        return false; 
      } 
    if( v.length==0 ) 
      if( k==189 || k==109 ){ 
        return true; 
        } 
    if( ((a<'0' || a>'9') && k >=48)||k==32 ){  
        return false; 
        }   
    return true; 
    } 
    
  function gup( name ){  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  var regexS = "[\\?&]"+name+"=([^&#]*)";  var regex = new RegExp( regexS );  var results = regex.exec( window.location.href );  if( results == null )    return "";  else    return results[1];}
  function init(){ for( i=1; i<=50; i++ ){ obj=document.getElementById( "g"+i ); if( !obj ){break;} 
      obj.onkeydown=ckey; 
      if (obj.captureEvents) obj.captureEvents(Event.ONKEYDOWN); 
      } 
      //store defaults
      //alert( window.location.href );
      //alert( gup("val"));
      def_obj = ini_obj;def_val=ini_val;def_nap=ini_nap;
      //set init
      if( v=gup( "unit" ) ){
          if( document.getElementById( v ) )ini_obj = v;
            }
      if( v=gup( "val" ) ){
          if( parseFloat(v) )ini_val=v;
            }
      if( v=parseInt(gup( "ac" )) ){
          if( v>=2 && v<=6 )ini_nap=v;
            }
      if( v=gup( "ch" ) ){
        ch_obj = document.getElementById(v);
        my_click(ch_obj);
        }
        
      //alert( ini_obj+" "+ini_val+" "+ini_val );
      
      if( ini_nap ){ 
        document.getElementById("dokla").selectedIndex=ini_nap-2; 
        } 
      if( ini_obj && ini_val ){ 
        obj1=document.getElementById(ini_obj); 
        obj1.value=ini_val; 
        licz(obj1); 
        } 
    } 
    
    function show_link(){
      lnk_page = new String(window.location.href);
      if( (ix=lnk_page.indexOf("?") )>-1 ){
        lnk_page=lnk_page.substr( 0,ix );
        }
      lnk_u = active_obj.id;
      lnk_v = active_obj.value;      
      lnk_a = document.getElementById("dokla").selectedIndex+2;  
      lnk_query = "";
      if( typeof(act_opis)!="undefined" && act_opis )
          lnk_query += "ch="+act_opis;
      if( lnk_u!=def_obj )
          lnk_query += (lnk_query?"&":"")+"unit="+lnk_u;
      if( lnk_v!=def_val )
          lnk_query += (lnk_query?"&":"")+"val="+lnk_v;
      if( lnk_a!=def_nap )
          lnk_query += (lnk_query?"&":"")+"ac="+lnk_a;
      lnk_page += (lnk_query?"?":"")+lnk_query;
       
      prompt( "Copy this link into your clipboard then paste it onto any internet page", lnk_page );
      if( act_opis )document.getElementById(act_opis).focus();
      }
    //uwaga ta funkcja moze byc wylorzystana tylko w init
    function my_click(obj){
      if( !obj )return;
      if( obj.click ){
        obj.click();
        }
      else{ //mozilla
          var e = document.createEvent("Events");
          obj.addEventListener('click',function(e){}, false);
          e.initEvent("onclick", false, false);
          obj.dispatchEvent(e);
          
          }
      obj.focus();opis(obj);act_opis=obj.id;
      }
     
 
