function Siirry(osoite){
 document.location.href=osoite;
}

function Rastita(did){
 if(document.getElementById(did).checked){
  document.getElementById(did).checked=false;
 }else{
  document.getElementById(did).checked=true;
 }
}

function parsinro(eid){
 var r=parseFloat(document.getElementById(eid).value.replace(" ","").replace(",","."));
 if(isNaN(r)){r=0;}
 return r;
}

function valuutta(nro){
 var n=parseFloat(nro).toFixed(2);
 n+='';
 x=n.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.replace(".",",");
}

function numero(nro){
 var n=parseFloat(nro).toFixed(0);
 n+='';
 x=n.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.replace(".",",");
}

function tarkistapaivat(){
 document.getElementById("alkaap").value=parsipaiva(document.getElementById("alkaap").value,1);
 document.getElementById("paattyyp").value=parsipaiva(document.getElementById("paattyyp").value,1);
 document.getElementById("vanheneep").value=parsipaiva(document.getElementById("vanheneep").value,1);
 document.getElementById("poistetaanp").value=parsipaiva(document.getElementById("poistetaanp").value,1);
 document.getElementById("alkaak").value=parsiklo(document.getElementById("alkaak").value,1);
 document.getElementById("paattyyk").value=parsiklo(document.getElementById("paattyyk").value);
 document.getElementById("vanheneek").value=parsiklo(document.getElementById("vanheneek").value);
 document.getElementById("poistetaank").value=parsiklo(document.getElementById("poistetaank").value);
 if(parsipaiva(document.getElementById("paattyyp").value,0)<parsipaiva(document.getElementById("alkaap").value,0)){
  document.getElementById("paattyyp").value=parsipaiva(document.getElementById("alkaap").value,1);
  document.getElementById("paattyyk").value=parsiklo(document.getElementById("alkaak").value);
 }
 if(parsipaiva(document.getElementById("vanheneep").value,0)<parsipaiva(document.getElementById("paattyyp").value,0)){
  document.getElementById("vanheneep").value=parsipaiva(document.getElementById("paattyyp").value,1);
  document.getElementById("vanheneek").value=parsiklo(document.getElementById("paattyyp").value);
 }
 if(parsipaiva(document.getElementById("poistetaanp").value,0)<parsipaiva(document.getElementById("vanheneep").value,0)){
  document.getElementById("poistetaanp").value=parsipaiva(document.getElementById("vanheneep").value,1);
  document.getElementById("poistetaank").value=parsiklo(document.getElementById("vanheneek").value);
 }
}

function parsipaiva(pva,muoto){
 var pvaa=pva.split(".");
 var d=new Date();
 if(pvaa.length<2){
  pvaa[1]=1+d.getMonth();
 }
 if(pvaa.length<3){
  pvaa[2]=d.getFullYear();
 }
 if(pvaa.length==3){
  if(parseInt(pvaa[0])<1||isNaN(parseInt(pvaa[0]))){pvaa[0]=1;}
  if(parseInt(pvaa[0])>31){pvaa[0]=31;}
  if(parseInt(pvaa[1])<1||isNaN(parseInt(pvaa[1]))){pvaa[1]=1;}
  if(parseInt(pvaa[1])>12){pvaa[1]=12;}
  if(parseInt(pvaa[2])<50){pvaa[2]=2000+parseInt(pvaa[2]);}
  if(parseInt(pvaa[2])>50&&parseInt(pvaa[2])<100){pvaa[2]=1900+parseInt(pvaa[2]);}
  if(parseInt(pvaa[2])<1970||isNaN(parseInt(pvaa[2]))){pvaa[2]=1970;}
  if(parseInt(pvaa[2])>2037){pvaa[2]=2037;}
  if(muoto==0){
   return parseInt(pvaa[2])+"-"+etunollat(parseInt(pvaa[1]),2)+"-"+etunollat(parseInt(pvaa[0]),2);
  }else{
   return etunollat(parseInt(pvaa[0]),2)+"."+etunollat(parseInt(pvaa[1]),2)+"."+parseInt(pvaa[2]);
  }
 }else{
  return "0"; 
 }
}

function parsiklo(klo){
 var kloa=klo.replace(".",":").split(":");
 if(kloa.length<1){
  kloa[1]=0;
 }
 if(parseInt(kloa[0])<0||isNaN(parseInt(kloa[0]))||parseInt(kloa[0])>23){kloa[0]=0;}
 if(parseInt(kloa[1])<0||isNaN(parseInt(kloa[1]))||parseInt(kloa[1])>59){kloa[1]=0;}
  return etunollat(parseInt(kloa[0]),2)+":"+etunollat(parseInt(kloa[1]),2);
}

function etunollat(n,totalDigits){ 
 n=n.toString(); 
 var pd=''; 
 if(totalDigits>n.length){ 
  for(i=0;i<(totalDigits-n.length);i++){pd+="0";} 
 } 
 return pd+n.toString(); 
}