var online = "";
  
function updates(first){

  var xmlHttp;
  
  	try{	
  		xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
  	}
  	catch (e){
  		try{
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
  		}
  		catch (e){
  		    try{
  				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  			}
  			catch (e){
  				alert("mallilista automaattinen päivitys ei käynnissä");
  			}
  		}
  	}    
    
    xmlHttp.onreadystatechange=function(){
      
    	if(xmlHttp.readyState==4){ 
    		
        if(xmlHttp.responseText != online && first == 0){
        
          reload();
    		  //alert("1: "+online+" 2: "+xmlHttp.responseText+" ".first);
          }
        
        online = xmlHttp.responseText;
        setTimeout("updates('0')",5000);
    	  //alert(online+" xxx "+xmlHttp.responseText+"homo");
      }
    	
    }
    
  xmlHttp.open("GET","ajax/onlineid.php",true);
  xmlHttp.send(null);
  
}

function reload(){

  var xmlHttp;
  
  	try{	
  		xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
  	}
  	catch (e){
  		try{
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
  		}
  		catch (e){
  		    try{
  				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  			}
  			catch (e){
  				//alert("No AJAX!?");
  			}
  		}
  	}    
    
    xmlHttp.onreadystatechange=function(){
    
    	if(xmlHttp.readyState==4){
        //alert("1: "+online+" 2: "+xmlHttp.responseText+" ");
    		document.getElementById("modellist").innerHTML=xmlHttp.responseText;
    	}
    	
    }
  
  xmlHttp.open("GET","ajax/modellist.php?ajax=1",true);
  xmlHttp.send(null);
  
}

window.onload=function(){updates('1');}
