var chkd = 0;
function init(nb){
	if(chkd != 0){ return; }
	var myDate = new Date();
	var tx = "ptn=" + nb + "&amp;bt=" + myDate.getTime();
	sendRequest('./tpi.php',writeCont2,'GET',tx,false);
}

function writeCont2(req){
	if(chkd != 0){ return; }
	var txt,imgElem;
	chkd++;
	var result = req.responseXML.getElementsByTagName("tpi");
	if(result.length > 0){
		for(var i=0;i<result.length;i++){
			imgElem = document.createElement('img'); imgElem.src = "../img/new.gif?b=3";
			txt = "tpi" + result[i].getAttribute('val');
			document.getElementById(txt).appendChild(imgElem);
		}
	}
}

function sendRequest( url, callback, method, data ){
  var req = createXMLHTTP();
  if( !req ){ return; }
  req.onreadystatechange = function(){
    getResponse( req, callback );
  }
  
  if(method.toUpperCase() == 'GET' && data.length > 0){
    url += '?'+ data;
    data = '';
  }
  req.open( method, url, true );
  req.setRequestHeader("Content-Type", 
                       "application/x-www-form-urlencoded; charset=UTF-8");
  req.send( data );
}

function createXMLHTTP(){
  if( window.XMLHttpRequest ){
    return new XMLHttpRequest();
  }
  else if( window.ActiveXObject ){
    try {
      return new ActiveXObject("MSXML2.XMLHTTP");
    }
    catch (e) {
      try {
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e2) {
        return null;
      }
    }
  }
  return null
}

function getResponse( req, callback ){
  if( req.readyState == 4 ){
    if( req.responseText ){
      callback(req);
    }
  }
}
