
if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}

function GetXmlHttpObject(handler) {
  var XMLHttp=null
  if (window.XMLHttpRequest) {
    XMLHttp=new XMLHttpRequest()
  }
  else if (window.ActiveXObject) {
    XMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
  return XMLHttp
}

function checkme(me) { 
  return
}



function ajaxpost(formi,divi) {
  var params = Form.serialize($(formi));
  var params = params+"&sid="+Math.random()
  http=GetXmlHttpObject()
  if (http==null) {
    alert ("Selaimesi ei tule toimintoa")
    return
  }
  var url="index.php"
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      /* document.getElementById(divi).style.display = "block" */
      document.getElementById(divi).innerHTML = http.responseText;
    }
  }
  http.open("POST",url,true)
  http.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
  http.send(params);
}

function c_osasto(arvo,trg) {
  http=GetXmlHttpObject()
  if (http==null) {
    alert ("Selaimesi ei tule toimintoa")
    return
  }
  var url="index.php"
  url=url+"?port=Ilmoitukset&osasto="+arvo
  url=url+"&sid="+Math.random()
    /* if ( arvo == 8)   */
    /*   document.getElementById("maksunapit").style.background = "#f1f1f1";*/
    if ( arvo == 8 ) { 
      vs = "none";
    } else {
      vs = "block";
    }
  var x = document.getElementById("maksunapit")
  koko = document.getElementById("maksunapit").parentNode.childNodes.length
  for ( j=0;j<x.childNodes.length;j++) {
    x.childNodes[j].style.display = vs
  }
  http.open("GET",url,true)
  http.send(null)
}


function mmmss(divi,id,mt){
  if (id.length==0) {
    document.getElementById(divi).innerHTML=""
    return
  }
  http=GetXmlHttpObject()
  if (http==null) {
    alert ("Browser does not support HTTP Request")
    return
  }
    var url="index.php"
    url=url+"?port=Etusivu&Etusivu[media]="+id+"&td="+divi
    url=url+"&sid="+Math.random()
    http.onreadystatechange=function() {
      if(http.readyState == 4) {
        document.getElementById(divi).innerHTML = http.responseText
        if (mt == 2) {
          document.getElementById(divi).style.zIndex=99
          document.getElementById(divi).style.width=500
          document.getElementById(divi).style.top=0
          document.getElementById(divi).style.position="absolute"
        }
      }
    }
    http.open("GET",url,true)
    http.send(null)
}
function mmms(divi,id,fp){
  document.getElementById(divi).src=""+fp+"";
  return
}


function orderme(st) {
 
  http=GetXmlHttpObject()
  if (http==null) {
    alert ("Selaimesi ei tule toimintoa")
    return
  }
  var url="index.php"
  url=url+"?port=Ilmoitukset&orderme=-1&st=" +st
  url=url+"&sid="+Math.random()
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById("sisus").innerHTML = http.responseText
    }
  }
  http.open("GET",url,true)
  http.send(null)
}


function selday(aika) {
  divi = "day" + aika
    // var n = document.getElementByID(divi);
    // n.style[color] = "green"; 
    document.getElementById(divi).style.background = "#9F9";
  // alert(divi);
}

function hinta(src, trg) {
  var chrs = document.getElementById(src).value.length
    //   document.getElementById(trg).innerHTML = chrs + "counting..."

    /*
  if (chrs==0) {
    document.getElementById(trg).innerHTML=""
    return
  }
    */
  http=GetXmlHttpObject()
  if (http==null) {
    alert ("Selaimesi ei tule toimintoa")
    return
  }
  var url="index.php"
  url=url+"?port=Ilmoitukset&chrs="+chrs
  url=url+"&sid="+Math.random()
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById(trg).innerHTML = http.responseText
    }
  }
  http.open("GET",url,true)
  http.send(null)
    // document.getElementById(trg).innerHTML = chrs + " &euro;"
}

function vaika(aika){
  /* selday(aika) */ 
  divi = "day" + aika
  if (aika.length==0) {
    document.getElementById(divi).innerHTML=""
    return
  }
  http=GetXmlHttpObject()
  if (http==null) {
    alert ("Selaimesi ei tule toimintoa")
    return
  }
  var url="index.php"
  url=url+"?port=Ilmoitukset&aika="+aika
  url=url+"&sid="+Math.random()
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById(divi).style.background = http.responseText
      hinta('teksti','hinta')
    }
  }
  http.open("GET",url,true)
  http.send(null)
}


function pb(mode) {
  
  http=GetXmlHttpObject()
  if (http==null) {
    alert ("Selaimesi ei tule toimintoa")
    return
  }
  var url="index.php"
  url=url+"?port=Etusivu&pb=1"
  url=url+"&sid="+Math.random()
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById("lehtilogo").innerHTML = http.responseText
    }
  }
  http.open("GET",url,true)
  http.send(null)
  if (mode == 1) setTimeout('pb(1)',1000)
  else exit();
}

function adl(formi) {

  var params = Form.serialize($(formi));
  var params = params+"&sid="+Math.random()
  http=GetXmlHttpObject()
  if (http==null) {
    alert ("Selaimesi ei tule toimintoa")
    return
  }
  var url="index.php"
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById("file1").innerHTML = http.responseText 
    }
  }
  http.open("POST",url,true)
  http.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
  http.send(params);
}

function showstory(bl,at,id) {
  http=GetXmlHttpObject()
  if (http==null) {
    alert ("Selaimesi ei tule toimintoa")
    return
  }
  var url="index.php"
  url=url+"?port="+bl+"&"+bl+"[arkisto]="+at+"&"+bl+"[show]="+id
  url=url+"&sid="+Math.random()
  http.onreadystatechange=function() {
    if (http.readyState == 4) {
      document.getElementById("fpstory").innerHTML = http.responseText
    }
  }
  http.open("GET",url,true)
  http.send(null)
}
