function ajaxSave(url)
{
 var web = new XMLHttpRequest();
 web.open("GET", url, false);
 web.send(null);
}

function ajaxNoted(kayttaja,koodi,tapa,korkeus,ajaxrun)
{
    
 if (tapa == 'hide')
 {
  if (ajaxrun==1)
  {
   var web = new XMLHttpRequest();
   web.open("GET", '/ajaxtarkistus.inc?kohde=huomautusluettu&koodi='+koodi+'&uid='+kayttaja, false);
   web.send("");
  } 
  
  new Effect.Fade('noticeMessage', { duration: 1.0, queue: {position: 'end', scope: 'noticehider'} });
  if (ajaxrun==1)
  {
   new Effect.Morph('noticeBox', { style: 'height:40px;margin-bottom:15px;', duration: 1.5, queue: {position: 'end', scope: 'noticehider'} });
   new Effect.Appear('noticeTip', { duration: 1.0, queue: {position: 'end', scope: 'noticehider'} });
  }
  else
  {
   new Effect.Morph('noticeBox', { style: 'height:0px;', duration: 0.5, queue: {position: 'end', scope: 'noticehider'} });
  }
 } 

 if (tapa == 'show')
 {
  new Effect.Fade('noticeTip', { duration: 1.0, queue: {position: 'end', scope: 'noticehider'} });
  new Effect.Morph('noticeBox', { style: 'height:'+korkeus+'px;margin-bottom:15px;', duration: 1.5, queue: {position: 'end', scope: 'noticehider'} });
  new Effect.Appear('noticeMessage', { duration: 1.0, queue: {position: 'end', scope: 'noticehider'} });
 } 
 
  
}

function ajaxRead(url,toiminta,changeimage)
{
 aika = new Date();
 http = new XMLHttpRequest();
 url = url;// +'&aika='+ aika;
 
 var datapaketti = "";
 
 http.open("GET", url); 
 
 var paketti = "empty";
 
 http.onreadystatechange = function()
 {
  if (http.readyState == 4)
  {
   tulos = http.responseText;
   if (toiminta == 'rekisterointi')
   {
    if (tulos == '0') kuva = '/sg/regbtn_varattu.gif';
    if (tulos == '1') kuva = '/sg/regbtn_vapaa.gif';
    if (changeimage==true) document.getElementById('kayttajatunnusvalo').src = kuva;
   }
   
   if (toiminta == 'global')
   {
    latestGlobalData = http.responseText;
   }
  }
 }
  
 http.send("");
}

function setcookie( name, value, expires, path, domain, secure )
{
 var today = new Date();
 today.setTime( today.getTime() );
 if (expires) expires = expires * 1000 * 60 * 60 * 24;
 var expires_date = new Date( today.getTime() + (expires) );
 document.cookie = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) +( ( domain ) ? ";domain=" + domain : "" ) +( ( secure ) ? ";secure" : "" );
}


function aikalaskuri(kohdeaika)
{
 var now = new Date();
 var kohdeAika = new Date(kohdeaika);
 var msPaivat   = 24 * 60 * 60 * 1000;
 var msTunnit   = 60 * 60 * 1000;
 var msMinuutit = 60 * 1000;
 var msSekunnit = 1000;
 var msSekSadat = 1;

 cdSekSadat = (kohdeAika.getTime() - now.getTime()) / msSekSadat;
 cdSekunnit = (kohdeAika.getTime() - now.getTime()) / msSekunnit;
 cdMinuutit = (kohdeAika.getTime() - now.getTime()) / msMinuutit;
 cdTunnit   = (kohdeAika.getTime() - now.getTime()) / msTunnit;
 cdPaivat   = (kohdeAika.getTime() - now.getTime()) / msPaivat;

 cdTime = cdSekSadat;
 
 if (cdSekSadat > 1000) cdSekSadat = cdSekSadat - (Math.floor(cdSekunnit)*1000);
 if (cdSekunnit > 60)   cdSekunnit = cdSekunnit - (Math.floor(cdMinuutit)*60);
 if (cdMinuutit > 60)   cdMinuutit = cdMinuutit - (Math.floor(cdTunnit)*60);
 if (cdTunnit   > 24)   cdTunnit   = cdTunnit   - (Math.floor(cdPaivat)*24);

 cdPaivat   = Math.floor(cdPaivat);
 cdTunnit   = Math.floor(cdTunnit);
 cdMinuutit = Math.floor(cdMinuutit);
 cdSekunnit = Math.floor(cdSekunnit);
 cdSekSadat = Math.floor(cdSekSadat);

 if (cdTime < 1)
 {
  cdPaivat   = 0;
  cdTunnit   = 0;
  cdMinuutit = 0;
  cdSekunnit = 0;
  cdSekSadat = 0;
 }
  
 txtPaivat   = cdPaivat;
 txtTunnit   = cdTunnit;
 txtMinuutit = cdMinuutit;
 txtSekunnit = cdSekunnit;
 txtSekSadat = cdSekSadat;
  
 if (txtPaivat < 100) txtPaivat = "0" + txtPaivat;
 if (txtPaivat < 10)  txtPaivat = "0" + txtPaivat;
 
 if (txtTunnit < 10)  txtTunnit = "0" + txtTunnit;
 
 if (txtMinuutit < 10) txtMinuutit = "0" + txtMinuutit;
 
 if (txtSekunnit < 10) txtSekunnit = "0" + txtSekunnit;
 
 if (txtSekSadat < 100) txtSekSadat = "0" + txtSekSadat;
 if (txtSekSadat < 10) txtSekSadat = "0" + txtSekSadat;

 if (cdTime > 0) var txtLaskuri = txtPaivat+"<small>D</small>" + " " + txtTunnit+"<small>H</small>" + " " + txtMinuutit+"<small>M</small>" + " " + txtSekunnit+"<small>S</small>" + " " + txtSekSadat+"<small>MS</small>";
 if (cdTime<= 0) 
 {
  var txtLaskuri = "<a href=\"?refresh\">Aika kulunut loppuun, päivitä sivu</a>";
  //history.go(0);
 }
 
 document.getElementById("stepCounter").innerHTML = txtLaskuri;
}


function in_array (needle, haystack, argStrict) 
{
 
    var key = '', strict = !!argStrict;
 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }
 
    return false;
}
