function commas(nStr) {
nStr+='';
x=nStr.split('.');
x1=x[0];
x2=x.length > 1 ? '.'+x[1] : '';
var rgx=/(\d+)(\d{3})/;
  while (rgx.test(x1)) {
	x1=x1.replace(rgx, '$1'+','+'$2');
  }
return x1+x2;
}

function refresh(natmoney,nojob,suznji) {
money=document.getElementById('soldieratt').value*2000+document.getElementById('soldierdef').value*2000+document.getElementById('cworker').value*2500+document.getElementById('iworker').value*1500+document.getElementById('mworker').value*3000+document.getElementById('mslave').value*4000+document.getElementById('spyt').value*5500+document.getElementById('assassint').value*5500;
needpeople=document.getElementById('soldieratt').value*1+document.getElementById('soldierdef').value*1+document.getElementById('cworker').value*1+document.getElementById('iworker').value*1+document.getElementById('mworker').value*1+document.getElementById('spyt').value*1+document.getElementById('assassint').value*1;
needslaves=document.getElementById('mslave').value*1;
eval(money);
eval(needpeople);
eval(needslaves);

no = 0;
if (natmoney < money) {
no = 1;
}
if (nojob < needpeople) {
no = 1;
}
if (suznji < needslaves) {
no = 1;
}

if (no == 1) { //spremenimo slikco v X
document.getElementById('yesno').innerHTML="<img src=\"images/krizec.gif\">";
colorm = "<font color='red'>";
}else{ //slikca je klukca
colorm = "<font color='green'>";
  if (money == 0) {
	document.getElementById('yesno').innerHTML="<img src=\"images/krogec.gif\">";
  }else{
	document.getElementById('yesno').innerHTML="<img src=\"images/klukca.gif\">";
  }
}

printmoney = colorm + commas(money) + "</font>"
printpeople = colorm + commas(needpeople+needslaves) + "</font>"

document.getElementById('money').innerHTML=printmoney;
document.getElementById('needpeople').innerHTML=printpeople;
}

function refreshut(atk1,def1,pplc,ppli,pplm,suzenj,vohun,asasin) {
allpeople=document.getElementById('sl0').value*1+document.getElementById('sl1').value*1+document.getElementById('sl2').value*1+document.getElementById('sl3').value*1+document.getElementById('sl4').value*1+document.getElementById('sl5').value*1+document.getElementById('sl6').value*1+document.getElementById('sl7').value*1;
eval(allpeople);

no = 0;
if (atk1 < document.getElementById('sl0').value) {
no = 1;
}
if (def1 < document.getElementById('sl1').value) {
no = 1;
}
if (pplc < document.getElementById('sl2').value) {
no = 1;
}
if (ppli < document.getElementById('sl3').value) {
no = 1;
}
if (pplm < document.getElementById('sl4').value) {
no = 1;
}
if (suzenj < document.getElementById('sl5').value) {
no = 1;
}
if (vohun < document.getElementById('sl6').value) {
no = 1;
}
if (asasin < document.getElementById('sl7').value) {
no = 1;
}

if (no == 1) { //spremenimo slikco v X
document.getElementById('yesnout').innerHTML="<img src=\"images/krizec.gif\">";
}else{ //slikca je klukca
  if (allpeople == 0) {
	document.getElementById('yesnout').innerHTML="<img src=\"images/krogec.gif\">";
  }else{
	document.getElementById('yesnout').innerHTML="<img src=\"images/klukca.gif\">";
  }
}
}

function refresh1(natmoney,armatt1,armatt2,armatt3) {

money1=document.getElementById('att2').value*6000+document.getElementById('att3').value*12000+document.getElementById('att4').value*20000;
eval(money1);

no = 0;
if (natmoney < money1) {
no = 1;
}
//ce nimamo dovolj folka
if (armatt1 < document.getElementById('att2').value) {
no = 1;
}
if (armatt2 < document.getElementById('att3').value) {
no = 1;
}
if (armatt3 < document.getElementById('att4').value) {
no = 1;
}

if (no == 1) { //spremenimo slikco v X
colorm1 = "<font color='red'>";
document.getElementById('yesno1').innerHTML="<img src=\"images/krizec.gif\">";
}else{ //slikca je klukca
colorm1 = "<font color='green'>";
if (money1 == 0) {
	document.getElementById('yesno1').innerHTML="<img src=\"images/krogec.gif\">";
  }else{
	document.getElementById('yesno1').innerHTML="<img src=\"images/klukca.gif\">";
  }
}

printmoney = colorm1 + commas(money1) + "</font>"

document.getElementById('money1').innerHTML=printmoney;
}

function refresh2(natmoney,armdef1,armdef2,armdef3) {
money2=document.getElementById('def2').value*6000+document.getElementById('def3').value*12000+document.getElementById('def4').value*20000;
eval(money2);

no = 0;
if (natmoney < money2) {
no = 1;
}
//ce nimamo dovolj folka
if (armdef1 < document.getElementById('def2').value) {
no = 1;
}
if (armdef2 < document.getElementById('def3').value) {
no = 1;
}
if (armdef3 < document.getElementById('def4').value) {
no = 1;
}

if (no == 1) { //spremenimo slikco v X
colorm2 = "<font color='red'>";
document.getElementById('yesno2').innerHTML="<img src=\"images/krizec.gif\">";
}else{ //slikca je klukca
colorm2 = "<font color='green'>";
if (money2 == 0) {
	document.getElementById('yesno2').innerHTML="<img src=\"images/krogec.gif\">";
  }else{
	document.getElementById('yesno2').innerHTML="<img src=\"images/klukca.gif\">";
  }
}

printmoney = colorm2 + commas(money2) + "</font>"

document.getElementById('money2').innerHTML=printmoney;
}

function refreshAW(natmoney) {
money=document.getElementById('aw1').value*1000+document.getElementById('aw2').value*2750+document.getElementById('aw3').value*5000+document.getElementById('aw4').value*12000+document.getElementById('aw5').value*25000+document.getElementById('aw6').value*60000+document.getElementById('aw7').value*125000;
eval(money);

no = 0;
if (natmoney < money) {
no = 1;
}

if (no == 1) { //spremenimo slikco v X
colorm = "<font color='red'>";
document.getElementById('yesnoaw').innerHTML="<img src=\"images/krizec.gif\">";
}else{ //slikca je klukca
colorm = "<font color='green'>";
if (money == 0) {
	document.getElementById('yesnoaw').innerHTML="<img src=\"images/krogec.gif\">";
  }else{
	document.getElementById('yesnoaw').innerHTML="<img src=\"images/klukca.gif\">";
  }
}

printmoney = colorm + commas(money) + "</font>"

document.getElementById('moneyaw').innerHTML=printmoney;
}

function refreshDW(natmoney) {
money=document.getElementById('dw1').value*1000+document.getElementById('dw2').value*2750+document.getElementById('dw3').value*5000+document.getElementById('dw4').value*12000+document.getElementById('dw5').value*25000+document.getElementById('dw6').value*60000+document.getElementById('dw7').value*125000;
eval(money);

no = 0;
if (natmoney < money) {
no = 1;
}

if (no == 1) { //spremenimo slikco v X
colorm = "<font color='red'>";
document.getElementById('yesnodw').innerHTML="<img src=\"images/krizec.gif\">";
}else{ //slikca je klukca
colorm = "<font color='green'>";
if (money == 0) {
	document.getElementById('yesnodw').innerHTML="<img src=\"images/krogec.gif\">";
  }else{
	document.getElementById('yesnodw').innerHTML="<img src=\"images/klukca.gif\">";
  }
}

printmoney = colorm + commas(money) + "</font>"

document.getElementById('moneydw').innerHTML=printmoney;
}

function bankInvest(banked) {
isel=document.getElementById('isel').value;
if (isel==1) {
procent = 1.05;
document.getElementById('percinvs').innerHTML="5%";
}
if (isel==2) {
procent = 1.15;
document.getElementById('percinvs').innerHTML="15%";
}
if (isel==3) {
procent = 1.3;
document.getElementById('percinvs').innerHTML="30%";
}

moneycheck=document.getElementById('icash').value;
eval(moneycheck);

money=Math.round(moneycheck*procent);
eval(money);

no = 0;
if (banked < moneycheck) {
no = 1;
}
if (moneycheck < 0) {
no = 1;
}

if (no == 1) { //spremenimo slikco v X
document.getElementById('yesnoinvs').innerHTML="<img src=\"images/krizec.gif\">";
}else{ //slikca je klukca
if (moneycheck == 0) {
	document.getElementById('yesnoinvs').innerHTML="<img src=\"images/krogec.gif\">";
  }else{
	document.getElementById('yesnoinvs').innerHTML="<img src=\"images/klukca.gif\">";
  }
}

document.getElementById('moneyinvs').innerHTML=commas(money);
}

function refreshSAW(str_att1,str_att2,str_att3,str_att4,str_att5,str_att6,str_att7) {
Katt1 = document.getElementById('saw1').value*str_att1/100*1000*0.75;
Katt2 = document.getElementById('saw2').value*str_att2/250*2750*0.75;
Katt3 = document.getElementById('saw3').value*str_att3/400*5000*0.75;
Katt4 = document.getElementById('saw4').value*str_att4/850*12000*0.75;
Katt5 = document.getElementById('saw5').value*str_att5/1500*25000*0.75;
Katt6 = document.getElementById('saw6').value*str_att6/3000*60000*0.75;
Katt7 = document.getElementById('saw7').value*str_att7/5000*125000*0.75;
money=Math.round(Katt1+Katt2+Katt3+Katt4+Katt5+Katt6+Katt7);
eval(money);

document.getElementById('moneysaw').innerHTML=commas(money);
}

function refreshSDW(str_def1,str_def2,str_def3,str_def4,str_def5,str_def6,str_def7) {
Kdef1 = document.getElementById('sdw1').value*str_def1/100*1000*0.75;
Kdef2 = document.getElementById('sdw2').value*str_def2/250*2750*0.75;
Kdef3 = document.getElementById('sdw3').value*str_def3/400*5000*0.75;
Kdef4 = document.getElementById('sdw4').value*str_def4/850*12000*0.75;
Kdef5 = document.getElementById('sdw5').value*str_def5/1500*25000*0.75;
Kdef6 = document.getElementById('sdw6').value*str_def6/3000*60000*0.75;
Kdef7 = document.getElementById('sdw7').value*str_def7/5000*125000*0.75;
money=Math.round(Kdef1+Kdef2+Kdef3+Kdef4+Kdef5+Kdef6+Kdef7);
eval(money);

document.getElementById('moneysdw').innerHTML=commas(money);
}

function marketChange(res1,res2,res3,res4,res5) {
isel=document.getElementById('isel').value;
if (isel==1) { allresurce = res1; }
if (isel==2) { allresurce = res2; }
if (isel==3) { allresurce = res3; }
if (isel==4) { allresurce = res4; }
if (isel==5) { allresurce = res5; }
eval(allresurce);
document.getElementById('allresurs').innerHTML=allresurce;
}

function updateResurs(res1,res2,res3,res4,res5) {
isel=document.getElementById('isel').value;
if (isel==1) { allresurce = res1; }
if (isel==2) { allresurce = res2; }
if (isel==3) { allresurce = res3; }
if (isel==4) { allresurce = res4; }
if (isel==5) { allresurce = res5; }
document.getElementById('amount').value=allresurce;
}

function updateBuy1(amt,cena) {
document.getElementById('totalpay').innerHTML=commas(amt*cena);
document.getElementById('amount').value=amt;
}

function updateBuy2(maxamt,cena) {
amt=document.getElementById('amount').value;
if (amt > maxamt) {
document.getElementById('totalpay').innerHTML=commas(maxamt*cena);
document.getElementById('amount').value=maxamt;
}else{
document.getElementById('totalpay').innerHTML=commas(amt*cena);
}
}

function chtipspy() {
tp_sp=document.getElementById('tp_sp').value;
if (tp_sp==1) { turns = 1; }
if (tp_sp==2) { turns = 10; }
if (tp_sp==3) { turns = 10; }
document.getElementById('turnspy').innerHTML=turns;
}