function strItem(str,index) {
	return str.substr(index,1);
}

function prettyFormat(number) {
	snum=''+Math.round(number*100);
	res='';
	if(snum.length>2) {
		for(i=0;i<snum.length-2;i++)
			res+=strItem(snum,i);
		res+='.';
		for(i=snum.length-2;i<snum.length;i++)
			res+=strItem(snum,i);
	} else if(snum.length==2) res+='0.'+strItem(snum,0)+strItem(snum,1);
	else if(snum.length==1) res+='0.0'+strItem(snum,0);
	else res+='0.00';
	return res;
}
function check_number(id) {
	field=document.getElementById(id);
	newstr="";
	for(i=0;i<field.value.length;i++) {
		if(strItem(field.value,0).search("[^1-9]")==-1)
		if(strItem(field.value,i).search("[^0-9]")==-1)
			newstr+=strItem(field.value,i);
	}
	field.value=newstr;

	recount_price();
	return true;
}
function check_number2(id) {
	field=document.getElementById(id);
	newstr="";
	for(i=0;i<field.value.length;i++) {
		if(strItem(field.value,i).search("[^0-9]")==-1)
			newstr+=strItem(field.value,i);
	}
	field.value=newstr;

	recount_price();
	return true;
}

function recount_price() {
	otype=document.getElementById('orderTypesList').value;
	type=parseInt(document.getElementById('order_typ').value);
	slots=parseInt(document.getElementById('order_slots').value);
	months=parseInt(document.getElementById('order_time').value);

	if (slots<=19 && type==0) base_price=0.50;
	if (slots<=19 && type==1) base_price=0.25;
	if (slots<=19 && type==2) base_price=0.18;
	if (slots<=19 && type==3) base_price=0.63;
	if (slots>=20 && slots<=29 && type==0)base_price=0.49;
	if (slots>=20 && slots<=29 && type==1)base_price=0.24;
	if (slots>=20 && slots<=29 && type==2)base_price=0.17;
	if (slots>=20 && slots<=29 && type==3)base_price=0.62;
	if (slots>=30 && slots<=49 && type==0)base_price=0.48;
	if (slots>=30 && slots<=49 && type==1)base_price=0.23;
	if (slots>=30 && slots<=49 && type==2)base_price=0.16;
	if (slots>=30 && slots<=49 && type==3)base_price=0.61;
	if (slots>=50 && slots<=75 && type==0)base_price=0.47;
	if (slots>=50 && slots<=75 && type==1)base_price=0.22;
	if (slots>=50 && slots<=75 && type==2)base_price=0.15;
	if (slots>=50 && slots<=75 && type==3)base_price=0.60;
	if (slots>=76 && slots<=99 && type==0)base_price=0.46;
	if (slots>=76 && slots<=99 && type==1)base_price=0.21;
	if (slots>=76 && slots<=99 && type==2)base_price=0.14;
	if (slots>=76 && slots<=99 && type==3)base_price=0.59;
	if (slots>=100 && type==0)base_price=0.45;
	if (slots>=100 && type==1)base_price=0.20;
	if (slots>=100 && type==2)base_price=0.13;
	if (slots>=100 && type==3)base_price=0.58;

	if (months ==2) rabat=0.03;
	if (months ==3) rabat=0.05;
	if (months ==6) rabat=0.10;
	if (months ==9) rabat=0.15;
	if (months ==12) rabat=0.20;
	if (months ==1) rabat=0;
	
ident1=0.25;
	ident2=0.50;
	ident3=1.00;
	ident4=2.50;
	ident5=4.50;
	ident6=9.00;
	ident7=13.50;

	sekunda=(base_price/(30*86400))*slots;

	przedluz1=ident1/sekunda;
	przedluz2=ident2/sekunda;
	przedluz3=ident3/sekunda;
	przedluz4=ident4/sekunda;
	przedluz5=ident5/sekunda;
	przedluz6=ident6/sekunda;
    przedluz7=ident7/sekunda;

dni1 = (przedluz1 / 86400);
hour1 = (przedluz1 / 3600);
min1 = (przedluz1 / 60);	 
	 if (dni1 > 0)
      { 
       endtime1 = Math.round(dni1) +' dni'; 
      }
 
     if (hour1 < 25 && hour1 > 0 )
      {
       endtime1 = Math.round(hour1) +' godzin';
      }
    
     if (min1 < 60 && min1 > 0)
      {
       endtime1 = Math.round(min1) +' minut';
      }
	   if (min1 < 0)
      {
       endtime1 = 0;
      }

    
dni2 = (przedluz2 / 86400);
hour2 = (przedluz2 / 3600);
min2 = (przedluz2 / 60);	 
	 if (dni2 > 0)
      { 
       endtime2 = Math.round(dni2) +' dni'; 
      }
 
     if (hour2 < 25 && hour2 > 0 )
      {
       endtime2 = Math.round(hour2) +' godzin';
      }
    
     if (min2 < 60 && min2 > 0)
      {
       endtime2 = Math.round(min2) +' minut';
      }

     if (min2 < 0)
      {
       endtime2 = 0;
      }

dni3 = (przedluz3 / 86400);
hour3 = (przedluz3 / 3600);
min3 = (przedluz3 / 60);	 
	 if (dni3 > 0)
      { 
       endtime3 = Math.round(dni3) +' dni'; 
      }
 
     if (hour3 < 25 && hour3 > 0 )
      {
       endtime3 = Math.round(hour3) +' godzin';
      }
    
     if (min3 < 60 && min3 > 0)
      {
       endtime3 = Math.round(min3) +' minut';
      }

     if (min3 < 0)
      {
       endtime3 = 0;
      }
dni4 = (przedluz4 / 86400);
hour4 = (przedluz4 / 3600);
min4 = (przedluz4 / 60);	 
	 if (dni4 > 0)
      { 
       endtime4 = Math.round(dni4) +' dni'; 
      }
 
     if (hour4 < 25 && hour4 > 0 )
      {
       endtime4 = Math.round(hour4) +' godzin';
      }
    
     if (min4 < 60 && min4 > 0)
      {
       endtime4 = Math.round(min4) +' minut';
      }

     if (min4 < 0)
      {
       endtime4 = 0;
      }

dni5 = (przedluz5 / 86400);
hour5 = (przedluz5 / 3600);
min5 = (przedluz5 / 60);	 
	 if (dni5 > 0)
      { 
       endtime5 = Math.round(dni5) +' dni'; 
      }
 
     if (hour5 < 25 && hour5 > 0 )
      {
       endtime5 = Math.round(hour5) +' godzin';
      }
    
     if (min5 < 60 && min5 > 0)
      {
       endtime5 = Math.round(min5) +' minut';
      }

     if (min5 < 0)
      {
       endtime5 = 0;
      }

	dni6 = (przedluz6 / 86400);
hour6 = (przedluz6 / 3600);
min6 = (przedluz6 / 60);	 
	 if (dni6 > 0)
      { 
       endtime6 = Math.round(dni6) +' dni'; 
      }
 
     if (hour6 < 25 && hour6 > 0 )
      {
       endtime6 = Math.round(hour6) +' godzin';
      }
    
     if (min6 < 60 && min6 > 0)
      {
       endtime6 = Math.round(min6) +' minut';
      }

     if (min6 < 0)
      {
       endtime6 = 0;
      }
	  dni7 = (przedluz7 / 86400);
hour7 = (przedluz7 / 3600);
min7 = (przedluz7 / 60);	 
	 if (dni7 > 0)
      { 
       endtime7 = Math.round(dni7) +' dni'; 
      }
 
     if (hour7 < 25 && hour7 > 0 )
      {
       endtime7 = Math.round(hour7) +' godzin';
      }
    
     if (min7 < 60 && min7 > 0)
      {
       endtime7 = Math.round(min7) +' minut';
      }

     if (min7 < 0)
      {
       endtime7 = 0;
      }


	price1=(base_price*slots*months);
	price=price1-(price1*rabat);
	rabat=price1*rabat;
	document.getElementById('order_price').innerHTML=isNaN(price)?"":prettyFormat(price);
	document.getElementById('order_rabat').innerHTML=isNaN(rabat)?"":prettyFormat(rabat);

	document.getElementById('order_przedluz1').innerHTML=isNaN(przedluz1)?"":endtime1;
	document.getElementById('order_przedluz2').innerHTML=isNaN(przedluz2)?"":endtime2;
	document.getElementById('order_przedluz3').innerHTML=isNaN(przedluz3)?"":endtime3;
	document.getElementById('order_przedluz4').innerHTML=isNaN(przedluz4)?"":endtime4;
	document.getElementById('order_przedluz5').innerHTML=isNaN(przedluz5)?"":endtime5;
	document.getElementById('order_przedluz6').innerHTML=isNaN(przedluz6)?"":endtime6;
	document.getElementById('order_przedluz7').innerHTML=isNaN(przedluz7)?"":endtime7;

	return true;
}
function displayType() {
	gamelist=document.getElementById('serwer');
	lists=document.getElementsByName('gameServerTypes');
	for(i=0;i<lists.length;i++)
		lists[i].style.display='none';
	types=document.getElementById("gameServerTypes_"+gamelist.value);
	if(types) types.style.display='block';

}


