function getRequest() {
    var xmlhttp=false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
     try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
      try {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
       xmlhttp = false;
      }
     }
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp=false;
        }
    }
    if (!xmlhttp && window.createRequest) {
        try {
            xmlhttp = window.createRequest();
        } catch (e) {
            xmlhttp=false;
        }
    }

    return xmlhttp;
}

function init_populate() {
	var catHTML = "";
	var restHTML = "";
  document.getElementById("category").innerHTML = catHTML;
  document.getElementById("restaurant").innerHTML = restHTML;
	buildcategorytable();
	buildrestauranttable("basic",0);
}

function buildcategorytable() {
	var request = getRequest();
  request.open("get", "/lookups/g2g_data.php?data=restcat&random=" + Math.floor(Math.random()*100001), false);
  request.send(null);
  catResponse = request.responseText;
	catArray1 = catResponse.split(";;");
	catArray1Cnt = catArray1.length;
	if(catArray1Cnt > 0) {
		catHTML = "<table width=\"99%\" id=\"catTable\" cellpadding=\"5\" cellspacing=\"0\" align=\"center\">";
		catHTML = catHTML + "<tr>";
		for(i = 0; i < (catArray1Cnt - 1); i++){
			catArray2 = catArray1[i].split("~~");
			catArray2Cnt = catArray2.length;
			catHTML = catHTML + "<td align=\"center\">";
			if(catArray2[0] == 7){
				catHTML = catHTML + "<a href=\"order_menu.php?id=16\" class=\"rest_cat\">Drinks</a>"
			}else{
				catHTML = catHTML + "<a href=\"#\" class=\"rest_cat\" onclick=\"buildrestauranttable('basic'," + catArray2[0] + ")\">" + catArray2[1] + "</a>";
			}
			catHTML = catHTML + "</td>";
		}
		catHTML = catHTML + "<td align=\"center\"><a href=\"#\" onclick=\"buildrestauranttable('basic',0)\"><a href=\"#\" class=\"rest_cat\" onclick=\"buildrestauranttable('basic',0)\">All</a></td>";
		catHTML = catHTML + "</tr>";
		catHTML = catHTML + "</table>";
	}
  document.getElementById("category").innerHTML = catHTML;
}

function buildrestauranttable(level,category) {
  var request = getRequest();
  request.open("get", "/lookups/g2g_data.php?data=rest&level=" + level + "&cat=" + category + "&random=" + Math.floor(Math.random()*100001), false);
  request.send(null);
  restResponse = request.responseText;
	restArray1 = restResponse.split(";;");
	restArray1Cnt = restArray1.length;
	if(restArray1Cnt > 0) {
		restHTML = "<table cellspacing=\"0\" cellpadding=\"8\" align=\"center\">";
		restHTML = restHTML + "<tr>";
		for(i = 0; i < (restArray1Cnt - 1); i++){
			restArray2 = restArray1[i].split("~~");
			restArray2Cnt = restArray2.length;
			if(i % 2 == 0) { restHTML = restHTML + "<tr>"; }
			restImage = restArray2[2];
			if(restImage == "") {
				restImage = "blank.gif";
			}
			restHTML = restHTML + "<td><a href=\"order_menu.php?id=" + restArray2[0] + "\"><img width=\"250\" height=\"85\" src=\"/images/" + restImage + "\" border=\"0\" alt=\"" + restArray2[1] + "\" /></a></td>";
			if(i % 2 == 1) { restHTML = restHTML + "</tr>"; }
		}
		restHTML = restHTML + "</tr>";
		restHTML = restHTML + "</table>";
	}
  document.getElementById("restaurant").innerHTML = restHTML;
}
// -->
