/* idTabs ~ Sean Catchpole - Version 2.2 - MIT/GPL */ 
(function(){ 
var dep = {"jQuery":"http://code.jquery.com/jquery-latest.min.js"}; 
var init = function(){  
 
(function($){ 
 
  $.fn.idTabs = function(){ 
    //Loop Arguments matching options 
    var s = {}; 
    for(var i=0; i<arguments.length; ++i) { 
      var a=arguments[i]; 
      switch(a.constructor){ 
        case Object: $.extend(s,a); break; 
        case Boolean: s.change = a; break; 
        case Number: s.start = a; break; 
        case Function: s.click = a; break; 
        case String: 
          if(a.charAt(0)=='.') s.selected = a; 
          else if(a.charAt(0)=='!') s.event = a; 
          else s.start = a; 
        break; 
      } 
    } 
 
    if(typeof s['return'] == "function") //backwards compatible 
      s.change = s['return']; 
     
    return this.each(function(){ $.idTabs(this,s); }); //Chainable 
  } 
 
  $.idTabs = function(tabs,options) { 
    //Settings 
    var meta = ($.metadata)?$(tabs).metadata():{}; 
    var s = $.extend({},$.idTabs.settings,meta,options); 
 
    //Play nice 
    if(s.selected.charAt(0)=='.') s.selected=s.selected.substr(1); 
    if(s.event.charAt(0)=='!') s.event=s.event.substr(1); 
    if(s.start==null) s.start=-1; //no tab selected 
     
    //Setup Tabs 
    var showId = function(){ 
      if($(this).is('.'+s.selected)) 
        return s.change; //return if already selected 
      var id = "#"+this.href.split('#')[1]; 
      var aList = []; //save tabs 
      var idList = []; //save possible elements 
      $("a",tabs).each(function(){ 
        if(this.href.match(/#/)) { 
          aList.push(this); 
          idList.push("#"+this.href.split('#')[1]); 
        } 
      }); 
      if(s.click && !s.click.apply(this,[id,idList,tabs,s])) return s.change; 
      //Clear tabs, and hide all 
      for(i in aList) $(aList[i]).removeClass(s.selected); 
      for(i in idList) $(idList[i]).hide(); 
      //Select clicked tab and show content 
      $(this).addClass(s.selected); 
      $(id).show(); 
      return s.change; //Option for changing url 
    } 
 
    //Bind idTabs 
    var list = $("a[href*='#']",tabs).unbind(s.event,showId).bind(s.event,showId); 
    list.each(function(){ $("#"+this.href.split('#')[1]).hide(); }); 
 
    //Select default tab 
    var test=false; 
    if((test=list.filter('.'+s.selected)).length); //Select tab with selected class 
    else if(typeof s.start == "number" &&(test=list.eq(s.start)).length); //Select num tab 
    else if(typeof s.start == "string" //Select tab linking to id 
         &&(test=list.filter("[href*='#"+s.start+"']")).length); 
    if(test) { test.removeClass(s.selected); test.trigger(s.event); } //Select tab 
 
    return s; //return current settings (be creative) 
  } 
 
  //Defaults 
  $.idTabs.settings = { 
    start:0, 
    change:false, 
    click:null, 
    selected:".selected", 
    event:"!click" 
  }; 
 
  //Version 
  $.idTabs.version = "2.2"; 
 
  //Auto-run 
  $(function(){ $(".idTabs").idTabs(); }); 
 
})(jQuery); 
 
 
 
} //init 
 
// Check Dependencies 
var check = function(o,s){ 
  s = s.split('.'); 
  while(o && s.length) o = o[s.shift()]; 
  return o; 
} 
 
// Add Script 
var head = document.getElementsByTagName("head")[0]; 
var add = function(url){ 
  var s = document.createElement("script"); 
  s.type = "text/javascript"; s.src = url; 
  head.appendChild(s); 
} 
 
// Save Self 
var s = document.getElementsByTagName('script'); 
var src = s[s.length-1].src; 
 
// Load Dependencies 
var ok=true; 
for(d in dep) { 
  if(check(this,d)) continue; 
  ok=false; 
  add(dep[d]); 
} if(ok) return init(); 
 
// Reload Self 
add(src); 
 
})(); 
 
<!--
function zaokr( Liczba, Dokladnosc)
{
  if ( Dokladnosc < 0.0001 ) { Dokladnosc = 0.0001 };
  var Liczba_str = "" + Math.round(Liczba / Dokladnosc);
  var Liczba_len = Liczba_str.length;
  var poz = Math.log(1/Dokladnosc)/Math.log(10);
  if (Dokladnosc < 1)
  {
    return parseFloat(Liczba_str.substring(0, Liczba_len - poz) + "." + Liczba_str.substring(Liczba_len - poz, Liczba_len));
  }
  else
  {
    return Math.round(Dokladnosc * Liczba_str);
  }

}
function waluta_scr(Liczba)
{
  var Waluta = Math.round(Liczba*100);
  var Waluta_str = "" + Waluta;
  var Waluta_len = Waluta_str.length;
  return Waluta_str.substring(0, Waluta_len - 2) + "." + Waluta_str.substring(Waluta_len - 2, Waluta_len);
}

function Analizuj(info)
{
  var p_temp = ""+info;
  var p1_temp = null;
  var p2_temp = null;
  if (p_temp.indexOf(",")>-1)
  {  var p1_temp=p_temp.substring(0,p_temp.indexOf(","));
     var p2_temp=p_temp.substring(p_temp.indexOf(",")+1);
     p_temp=p1_temp+"."+p2_temp;
  };
  p_temp = parseFloat(p_temp);
  if (isNaN(p_temp)) {p_temp = 0};
  return p_temp;
}

function fLiczRaty(cena,czy_raty_malejace)
{

  //document.getElementById('').value = waluta_scr(Math.abs( zaokr( Analizuj( document.Kalkulator.Kredyt.value ) , 0.01 )));
  //document.Kalkulator.Rat.value = Math.abs( zaokr( Analizuj( document.Kalkulator.Rat.value ) , 1 ));
  if ( document.getElementById('okres_splaty').value < 1 )
  {
     document.getElementById('okres_splaty').value = 10;
  };
  if (isNaN(document.getElementById('depozyt').value) || document.getElementById('depozyt').value <= 0 )
  {
     document.getElementById('depozyt').value = 0;
  };
  if ( isNaN(document.getElementById('oprocentowanie').value) || document.getElementById('oprocentowanie').value==0 )
  {
     document.getElementById('oprocentowanie').value = 7;
  };
  document.getElementById('oprocentowanie').value = waluta_scr(Math.abs( zaokr( Analizuj( document.getElementById('oprocentowanie').value ) , 0.01 )));
  if (document.getElementById('oprocentowanie').value > 0)
   {var Stopa_m =  document.getElementById('oprocentowanie').value / 100 /12;
     if(!czy_raty_malejace)
     {
   		document.getElementById('input_rata1a').value = FormatNumberBy3(waluta_scr(zaokr( Stopa_m * (cena - document.getElementById("depozyt").value) * ( 1 + 1 / ( Math.pow(Stopa_m + 1, (document.getElementById("okres_splaty").value * 12)) -1)) , 0.01)));
     }else
     {
   		fLiczRatyVar( cena, Stopa_m );
     }
}/*
  else
    {document.Kalkulator.Rata_const.value = waluta_scr(zaokr( document.Kalkulator.Kredyt.value / document.Kalkulator.Rat.value , 0.01));
     document.Kalkulator.Ods_sum_const.value = 0;
     fLiczRatyVar( 0 );}
*/
}


/*function fLiczRaty(cena,czy_raty_malejace)
{

  //document.getElementById('').value = waluta_scr(Math.abs( zaokr( Analizuj( document.Kalkulator.Kredyt.value ) , 0.01 )));
  //document.Kalkulator.Rat.value = Math.abs( zaokr( Analizuj( document.Kalkulator.Rat.value ) , 1 ));
  if ( document.getElementById('okres_splaty').value < 1 )
  {
     document.getElementById('okres_splaty').value = 10;
  };
  if (isNaN(document.getElementById('depozyt').value) || document.getElementById('depozyt').value <= 0 )
  {
     document.getElementById('depozyt').value = 0;
  };
  if ( isNaN(document.getElementById('oprocentowanie').value) || document.getElementById('oprocentowanie').value==0 )
  {
     document.getElementById('oprocentowanie').value = 7;
  };
  document.getElementById('oprocentowanie').value = waluta_scr(Math.abs( zaokr( Analizuj( document.getElementById('oprocentowanie').value ) , 0.01 )));
  if (document.getElementById('oprocentowanie').value > 0)
   {var Stopa_m =  document.getElementById('oprocentowanie').value / 100 /12;
     if(!czy_raty_malejace)
     {
   		document.getElementById('input_rata1a').value= FormatNumberBy3(waluta_scr(zaokr( Stopa_m * (cena - document.getElementById("depozyt").value) * ( 1 + 1 / ( Math.pow(Stopa_m + 1, (document.getElementById("okres_splaty").value * 12)) -1)) , 0.01)));
     }else
     {
   		fLiczRatyVar( cena, Stopa_m );
     }
}*//*
  else
    {document.Kalkulator.Rata_const.value = waluta_scr(zaokr( document.Kalkulator.Kredyt.value / document.Kalkulator.Rat.value , 0.01));
     document.Kalkulator.Ods_sum_const.value = 0;
     fLiczRatyVar( 0 );}
*/
/*
}

function fLiczRatyVar(cena, Sm )
{
  document.getElementById('input_rata1').value = FormatNumberBy3(waluta_scr(zaokr( (cena - document.getElementById("depozyt").value) * ( Sm + 1 / (document.getElementById("okres_splaty").value * 12) ) , 0.01)));
  document.getElementById('input_rata2').value = FormatNumberBy3(waluta_scr(zaokr( (cena - document.getElementById("depozyt").value) * ( Sm + 1 ) / (document.getElementById("okres_splaty").value * 12) , 0.01)));
}


*/
function fLiczRatyVar(cena, Sm )
{
  document.getElementById('input_rata1a').value = FormatNumberBy3(waluta_scr(zaokr( (cena - document.getElementById("depozyt").value) * ( Sm + 1 / (document.getElementById("okres_splaty").value * 12) ) , 0.01)));
  document.getElementById('input_rata2').value = FormatNumberBy3(waluta_scr(zaokr( (cena - document.getElementById("depozyt").value) * ( Sm + 1 ) / (document.getElementById("okres_splaty").value * 12) , 0.01)));
}



/*
Author: Robert Hashemian
http://www.hashemian.com/

You can use this code in any manner so long as the author's
name, Web address and this disclaimer is kept intact.
********************************************************
Usage Sample:

<script language="JavaScript" src="http://www.hashemian.com/js/NumberFormat.js"></script>
<script language="JavaScript">
document.write(FormatNumberBy3("1234512345.12345", ".", ","));
</script>
*/

// function to format a number with separators. returns formatted number.
// num - the number to be formatted
// decpoint - the decimal point character. if skipped, "." is used
// sep - the separator character. if skipped, "," is used
function FormatNumberBy3(num, decpoint, sep) {
  // check for missing parameters and use defaults if so
  if (arguments.length == 2) {
    sep = " ";
  }
  if (arguments.length == 1) {
    sep = " ";
    decpoint = ".";
  }
  // need a string for operations
  num = num.toString();
  // separate the whole number and the fraction if possible
  a = num.split(decpoint);
  x = a[0]; // decimal
  y = 0;//a[1]; // fraction
  z = "";


  if (typeof(x) != "undefined") {
    // reverse the digits. regexp works from left to right.
    for (i=x.length-1;i>=0;i--)
      z += x.charAt(i);
    // add seperators. but undo the trailing one, if there
    z = z.replace(/(\d{3})/g, "$1" + sep);
    if (z.slice(-sep.length) == sep)
      z = z.slice(0, -sep.length);
    x = "";
    // reverse again to get back the number
    for (i=z.length-1;i>=0;i--)
      x += z.charAt(i);
    // add the fraction back in, if it was there
    if (typeof(y) != "undefined" && y.length > 0)
      x += decpoint + y;
  }
  return x;
}

//-->
