var HOME_FILE = 'home_counter.txt';
var JOURNAL_FILE = 'journal_counter.txt';
var WHATWEDO_FILE = 'whatwedo_counter.txt';
var ABOUT_FILE = 'about_counter.txt';
var LOSS_FILE = 'about_counter.txt';
var SOAP_FILE = 'soap_counter.txt';
var WORKSHOPS_FILE = 'workshops_counter.txt';

function query(file, name) {
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var url="./products.php";
    var p = (typeof name == "undefined") ? "all" : name;
    url="./products.php";
    url=url+"?x="+file+"&p="+p;
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function stateChanged() {
//    alert("readyState="+xmlhttp.readyState);
    if (xmlhttp.readyState==4) {
        document.getElementById("products").innerHTML=xmlhttp.responseText;
        if (document.getElementById("eof").innerHTML == 1)
            t = setTimeout("setWrapperHeight(830)", 2000);
    }
}

function getHomeCounter() {
    if(window.home_cid)
        clearTimeout(home_cid);
        
    document.getElementById("counter").innerHTML = "";
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var url = "./counter.php?fname=" + HOME_FILE;
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState==4) { 
            document.getElementById("counter").innerHTML=xmlHttp.responseText;
            home_cid = setTimeout("getHomeCounter()", 15000);
        }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    return;
}

function getJournalCounter() {
    if(window.journal_cid)
        clearTimeout(journal_cid);
        
    document.getElementById("counter").innerHTML = "";
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var url = "./counter.php?fname=" + JOURNAL_FILE;
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState==4) { 
            document.getElementById("counter").innerHTML=xmlHttp.responseText;
            journal_cid = setTimeout("getJournalCounter()", 15000);
        }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    return;
}

function getWhatWeDoCounter() {
    if(window.whatwedo_cid)
        clearTimeout(whatwedo_cid);
        
    document.getElementById("counter").innerHTML = "";
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var url = "./counter.php?fname=" + WHATWEDO_FILE;
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState==4) { 
            document.getElementById("counter").innerHTML=xmlHttp.responseText;
            whatwedo_cid = setTimeout("getWhatWeDoCounter()", 15000);
        }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    return;
}

function getAboutCounter() {
    if(window.about_cid)
        clearTimeout(about_cid);
        
    document.getElementById("counter").innerHTML = "";
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var url = "./counter.php?fname=" + ABOUT_FILE;
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState==4) { 
            document.getElementById("counter").innerHTML=xmlHttp.responseText;
            about_cid = setTimeout("getAboutCounter()", 15000);
        }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    return;
}

function getLossCounter() {
    if(window.about_cid)
        clearTimeout(about_cid);
        
    document.getElementById("counter").innerHTML = "";
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var url = "./counter.php?fname=" + LOSS_FILE;
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState==4) { 
            document.getElementById("counter").innerHTML=xmlHttp.responseText;
            about_cid = setTimeout("getLossCounter()", 15000);
        }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    return;
}

function getSoapCounter() {
    if(window.soap_cid)
        clearTimeout(soap_cid);
        
    document.getElementById("counter").innerHTML = "";
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var url = "./counter.php?fname=" + SOAP_FILE;
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState==4) { 
            document.getElementById("counter").innerHTML=xmlHttp.responseText;
            soap_cid = setTimeout("getSoapCounter()", 15000);
        }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    return;
}

function getWorkshopsCounter() {
    if(window.workshops_cid)
        clearTimeout(workshops_cid);
        
    document.getElementById("counter").innerHTML = "";
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var url = "./counter.php?fname=" + WORKSHOPS_FILE;
    xmlHttp.onreadystatechange=function() {
        if (xmlHttp.readyState==4) { 
            document.getElementById("counter").innerHTML=xmlHttp.responseText;
            workshops_cid = setTimeout("getWorkshopsCounter()", 15000);
        }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    return;
}

function GetXmlHttpObject() {
  xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

