function handleHttpResponse() {
  if (metaHttp.http.readyState == 4) {
    // Split the comma delimited response into an array
 //     arrayP = http.responseText.split(";");
 //   document.getElementById('city').value = results[0];
 //   document.getElementById('state').value = results[1];
//    document.getElementById('running').innerHTML='done';
      
      metaHttp.cible.innerHTML=metaHttp.http.responseText;
      metaHttp.cible._processed='done';
      if (metaHttp.stop) {
              metaHttp.stop=false;
              } else {
              metaHttp.next();
              }
  }
}




function invokeURL() {
  var myURL=this.url+'?param='+this.cible.parameter+'&class='+this.cible.className+'&oid='+this.cible.id+
                     '&metaHttpId='+this.current;

  var reg=new RegExp("%", "g");
  myURL=myURL.replace(reg,"%25");
 //  alert(myURL);
  this.http.open("GET", myURL, true); // false = get the result immediatly

  this.http.onreadystatechange = handleHttpResponse;
  this.http.send(null);
}


function _invokeOneURL(url,addParam) {
  var myURL=url+'?param='+this.cible.parameter+'&class='+this.cible.className+'&oid='+this.cible.id+
                '&metaHttpId='+this.current+'&'+addParam;

  var reg=new RegExp("%", "g");
  myURL=myURL.replace(reg,"%25");
  this.http.open("GET", myURL, true); // false = get the result immediatly
  this.http.onreadystatechange = handleHttpResponse;
  this.http.send(null);
}


function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function _next()
    {
    	var j=0;
    	var detected=false;
    	
    	for (j=0;j<this.myObjects.length;j++) {
    		var item=this.myObjects[j];
    		if (item._processed != 'done') {
    			this.cible=item;
                        this.current=j;
    			detected=true;
    			break;
    			}
    		}
    	if (detected) this.invokeURL();
    }
    	

function _parseObject() {
	var tagsArray=new Array('p','td','span','div');
	this.myObjects= new Array();
	var item;
    var j=0;
    var k=0;
    for (j=0;j<tagsArray.length;j++) {      
        var t=tagsArray[j];
        var tags=document.getElementsByTagName(t);     
        var i=0;
	    for (i=0;i<tags.length;i++) {
		    item=tags[i];           
		    if ((item.className== 'pnxarticles' || item.className=='pnxproducts')) {
		    	        this.myObjects[k]=item;
                        item.parameter=(item.parameter == undefined ? item.innerHTML : item.parameter);
                        k=k+1; 
                                                              
			            }
		    }
       }
}
function _runAgain(){
	var j=0;
	if (this.myObjects.length !=0) {
		for (j=0;j<this.myObjects;j++) {
			this.myObjects[j]._processed='';
		    }
		this.cible=this.myObjects[0];
                this.current=0;
		this.invokeURL();
		}
	}

function _runId(id,url,addParameter) {
var item=document.getElementById(id);
this.cible=item;
this.stop=true;
this.invokeOneURL(url,addParameter);
}

function _runMetaHttpId(id,url,addParameter) {
var item=this.myObjects[id];
this.cible=item;
this.current=id;
this.stop=true;
this.invokeOneURL(url,addParameter);
}



function _runMetaHttp() {
	   
	    var j=0;
	    if (this.myObjects.length !=0) {
		   this.cible=this.myObjects[0];
                   this.current=0;
		   this.invokeURL();			
		}
	}
	
function metaHTTPInit(myurl){
	this.parseObject();
        this.stop=false;
	this.url=myurl;
        this.runMetaHttp();

}

function metaHTTP () {
  var myObjects;
  var cible;
  var current;
  var stop;
  this.url='';
  this.http = getHTTPObject(); // We create the HTTP Object
  this.init=metaHTTPInit;
  this.invokeURL=invokeURL;
  this.handleHttpResponse=handleHttpResponse;
  this.parseObject=_parseObject;
  this.runMetaHttp=_runMetaHttp;
  this.next=_next;
  this.runAgain=_runAgain;
  this.runId=_runId;
  this.invokeOneURL=_invokeOneURL;
  this.runMetaHttpId=_runMetaHttpId;
}

var metaHttp=new metaHTTP();


