function getXMLHttp()
{
  var xmlHttp

  try
  {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    //Internet Explorer
    try
    {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
        alert("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}
//MakeRequest is used to generate the star auction buys on the front page
function MakeRequest()
{
  var xmlHttp = getXMLHttp();
  
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      HandleResponse(xmlHttp.responseText);
    }
  }
  var rand = Math.floor(Math.random()*1000000);
  xmlHttp.open("GET", "../starAuctionBuyFrontPage.php?rand="+rand, true); 
  xmlHttp.send(null);
}

function HandleResponse(response)
{
  document.getElementById('ResponseDiv').innerHTML = response;
  for (i=1;i<=document.getElementById('dealCount').innerHTML;i++){
  	var countdown = document.getElementById('tst'+i).innerHTML;
  	var countdownArray = countdown.split(',');
  	var seconds = parseInt(countdownArray[0]);
  	var minutes = parseInt(countdownArray[1]);
  	var hours = parseInt(countdownArray[2]);
  	var days = parseInt(countdownArray[3]);
  	//alert(days+':'+hours+':'+minutes+':'+seconds);
  	zxcCountDown('tst'+i,'ended',seconds,minutes,hours,days);
  } 
}


//ShowShopSuggestion is used to show the shop suggestion box top right
function GetShopSuggestion(currentPage)
{
  var xmlHttp = getXMLHttp();
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      HandleShop(xmlHttp.responseText);
    }
  }
  xmlHttp.open("GET", "../shopSuggestion.php?url="+currentPage, true); 
  xmlHttp.send(null);
}

function HandleShop(response)
{
  document.getElementById('shopSuggestion').innerHTML = response;  
}


//ShowAllPrices is used to display all item listings
function ShowAllPrices(brand,query,categoryId,section)
{
  var pathName = window.location.pathname; 
  var pathNameArray = pathName.split("/");
  var xmlHttp = getXMLHttp();
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      HandleAllPrices(xmlHttp.responseText);
    }
  }
  var rand = Math.floor(Math.random()*1000000);
  xmlHttp.open("GET", "../displayAllPrices.php?type="+brand+"&query="+query+"&categoryId="+categoryId+"&section="+section+"&rand="+rand, true); 
  xmlHttp.send(null);
}

//lists all the items and then sets the star auction buy timer running (if there is one)
function HandleAllPrices(response)
{
  document.getElementById('listItems').innerHTML = response;  
  var countdown = document.getElementById('countdown').innerHTML;
  var countdownArray = countdown.split(',');
  var seconds = parseInt(countdownArray[0]);
  var minutes = parseInt(countdownArray[1]);
  var hours = parseInt(countdownArray[2]);
  var days = parseInt(countdownArray[3]);
  zxcCountDown('countdown','ended',seconds,minutes,hours,days);

}
