
var browsertype;
var xmlHttp;// global instance of XMLHttpRequest
function createXmlHttpRequest()
{
       if(window.ActiveXObject)
       {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }

    else if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();
     }

}
function startRequest(id,bt)
{
  browsertype = bt;
  createXmlHttpRequest();

// xmlHttp.open("GET","http://localhost:8080/merchant/getMerchantFans.html?merchantId="+id ,true)

  xmlHttp.open("GET","http://www.videonary.com/videonary/merchant/getMerchantFans.html?merchantId="+id ,true)

    xmlHttp.onreadystatechange=handleStateChange;
  xmlHttp.send(null);

}
                 http://www.videonary.com/videonary/merchant/getMerchantDetails.html?searchField=galileo&page=1&merchantType=&foodType=&region=
function handleStateChange()
{

    if(xmlHttp.readyState==4){
        if(xmlHttp.status==200){



            var allusers = xmlHttp.responseXML.getElementsByTagName("userfans")[0];;
            var items = allusers.getElementsByTagName("item");   // gets array of items from xml doc


            var table = "<table width=\"730\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";

            for (var I = 0 ; I < items.length ; I++) {
                if ((items.length-I)>4){   // 5 items in a row
              //    alert("5 items are at least left");
                    table = table + "<tr><td><table width=\"724\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr> ";
                    for (var K = 0; K < 5; K++){
                        var item = items[I];
                        var name = item.getElementsByTagName("username")[0].firstChild.nodeValue;
                        var uid = item.getElementsByTagName("uid")[0].firstChild.nodeValue;

                        table = table + "<td align=\"center\" width=\"144\" height=\"80\" valign=\"middle\" ><table><tr><td width=\"144\" align=\"middle\" height=\"80\"  valign=\"middle\" class=\"title\" style=\"background-color:#FFFFFF; border: 1px solid #aaa\"><a href=\"/videonary/userFriendProfile.html?userID="+ uid+ "\">" +    "<img src=\"/videonary/getProfilePicture.html?userid="+ uid + "\" border=\"0\" ></a></td></tr>";
                        table = table + "<tr><td width=\"144\" valign=\"middle\" align=\"middle\" class=\"title\"><a class=\"title\" href=\"/videonary/userFriendProfile.html?userID="+ uid+ "\">" +  name + "</a></td></tr></table></td>";
                        I++;
                    }
                    I--;
                    table = table + "</tr></table></td></tr>";
                }
                else if ((items.length-I)>3){ // 4 items in the row
              //      alert("4 items are at least left")

                    table = table + "<tr><td><table width=\"728\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr> ";

                    for (var K = 0; K < 4; K++){
                        var item = items[I];
                        var name = item.getElementsByTagName("username")[0].firstChild.nodeValue;
                        var uid = item.getElementsByTagName("uid")[0].firstChild.nodeValue;

                        table = table + "<td align=\"center\" width=\"144\" height=\"80\" valign=\"middle\" ><table><tr><td width=\"144\" height=\"80\" align=\"middle\" valign=\"middle\" class=\"title\" style=\"background-color:#FFFFFF; border: 1px solid #aaa\"><a href=\"/videonary/userFriendProfile.html?userID="+ uid+ "\">" +    "<img src=\"/videonary/getProfilePicture.html?userid="+ uid + "\" border=\"0\" ></a></td></tr>";
                        table = table + "<tr><td width=\"144\" valign=\"middle\" align=\"middle\" class=\"title\"><a class=\"title\" href=\"/videonary/userFriendProfile.html?userID="+ uid+ "\">" +  name + "</a></td></tr></table></td>";
                        I++;
                    }
                       I--;
                    table = table + "<td align=\"center\" width=\"144\" height=\"80\" valign=\"middle\" ><table><tr><td align=\"middle\" width=\"144\" height=\"80\"  valign=\"middle\" class=\"title\"><img src=\"http://www.videonary.com/videonary/img/spacer.gif\"></td></tr>";
                    table = table + "<tr><td width=\"144\" align=\"middle\" valign=\"middle\" class=\"title\"><img src=\"http://www.videonary.com/videonary/img/spacer.gif\"></td></tr></table></td>";
                    table = table + "</tr></table></td></tr>";

                }
                else if ((items.length-I)>2){ // 3 items in the row
               //     alert("3 items are at least left");
                    table = table + "<tr><td><table width=\"728\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr> ";

                     for (var K = 0; K < 3; K++){
                        var item = items[I];
                        var name = item.getElementsByTagName("username")[0].firstChild.nodeValue;
                        var uid = item.getElementsByTagName("uid")[0].firstChild.nodeValue;
                        table = table + "<td align=\"center\" width=\"144\" height=\"80\" valign=\"middle\" ><table><tr><td align=\"middle\" width=\"144\" height=\"80\"  valign=\"middle\" class=\"title\" style=\"background-color:#FFFFFF; border: 1px solid #aaa\"><a href=\"/videonary/userFriendProfile.html?userID="+ uid+ "\">" +    "<img src=\"/videonary/getProfilePicture.html?userid="+ uid + "\" border=\"0\" ></a></td></tr>";
                        table = table + "<tr><td width=\"144\" valign=\"middle\" align=\"middle\" class=\"title\"><a class=\"title\" href=\"/videonary/userFriendProfile.html?userID="+ uid+ "\">" +  name + "</a></td></tr></table></td>";
                        I++;
                    }
                    I--;
                    table = table + "<td align=\"center\" width=\"288\" height=\"80\" valign=\"middle\" ><table><tr><td width=\"288\" height=\"80\"  valign=\"middle\" class=\"title\"><img src=\"http://www.videonary.com/videonary/img/spacer.gif\"></td></tr>";
                    table = table + "<tr><td width=\"288\" valign=\"middle\" class=\"title\"><img src=\"http://www.videonary.com/videonary/img/spacer.gif\"></td></tr></table></td>";
                    table = table + "</tr></table></td></tr>";
                }
                else if ((items.length-I)>1){ // 2 items in the row
                    table = table + "<tr><td><table width=\"728\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr> ";
                     for (var K = 0; K < 2; K++){
                        var item = items[I];
                        var name = item.getElementsByTagName("username")[0].firstChild.nodeValue;
                        var uid = item.getElementsByTagName("uid")[0].firstChild.nodeValue;
                         table = table + "<td align=\"center\" width=\"144\" height=\"80\" valign=\"middle\" ><table><tr><td width=\"144\" height=\"80\"  align=\"middle\" valign=\"middle\" class=\"title\" style=\"background-color:#FFFFFF; border: 1px solid #aaa\"><a href=\"/videonary/userFriendProfile.html?userID="+ uid+ "\">" +    "<img src=\"/videonary/getProfilePicture.html?userid="+ uid + "\" border=\"0\" ></a></td></tr>";
                        table = table + "<tr><td width=\"144\" align=\"middle\" valign=\"middle\" class=\"title\"><a class=\"title\" href=\"/videonary/userFriendProfile.html?userID="+ uid+ "\">" +  name + "</a></td></tr></table></td>";
                        I++;
                    }
                    I--;
                    table = table + "<td align=\"center\" width=\"432\" height=\"80\" valign=\"middle\" ><table><tr><td width=\"432\" height=\"80\" align=\"middle\" valign=\"middle\" class=\"title\"><img src=\"http://www.videonary.com/videonary/img/spacer.gif\"></td></tr>";
                    table = table + "<tr><td width=\"432\" align=\"middle\" valign=\"middle\" class=\"title\"><img src=\"http://www.videonary.com/videonary/img/spacer.gif\"></td></tr></table></td>";
                    table = table + "</tr></table></td></tr>";
                }
                else if ((items.length-I)>0){
                    // 1 items in the row
                    table = table + "<tr><td><table width=\"728\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr> ";

                     for (var K = 0; K < 1; K++){

                        var item = items[I];
                        var name = item.getElementsByTagName("username")[0].firstChild.nodeValue;
                        var uid = item.getElementsByTagName("uid")[0].firstChild.nodeValue;

                        table = table + "<td align=\"center\" width=\"144\" height=\"80\" valign=\"middle\" ><table><tr><td width=\"144\" height=\"80\" align=\"middle\" valign=\"middle\" class=\"title\" style=\"background-color:#FFFFFF; border: 1px solid #aaa\"><a href=\"/videonary/userFriendProfile.html?userID="+ uid+ "\">" +    "<img src=\"/videonary/getProfilePicture.html?userid="+ uid + "\" border=\"0\" ></a></td></tr>";
                        table = table + "<tr><td width=\"144\" valign=\"middle\" align=\"middle\" class=\"title\"><a class=\"title\" href=\"/videonary/userFriendProfile.html?userID="+ uid+ "\">" +  name + "</a></td></tr></table></td>";
                        I++;
                    }
                    I--;
                    table = table + "<td align=\"center\" width=\"576\" height=\"80\" valign=\"middle\" ><table><tr><td width=\"576\" height=\"80\" align=\"middle\" valign=\"middle\" class=\"title\"><img src=\"http://www.videonary.com/videonary/img/spacer.gif\"></td></tr>";
                    table = table + "<tr><td width=\"576\" align=\"middle\" valign=\"middle\" class=\"title\"><img src=\"http://www.videonary.com/videonary/img/spacer.gif\"></td></tr></table></td>";
                    table = table + "</tr></table></td></tr>";
                }
                else if ((items.length-I) == 0){
                    table = table + "<tr><td><table width=\"728\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr> ";
                    table = table + "<td align=\"center\" width=\"730\" height=\"80\" valign=\"middle\" ><table><tr><td width=\"730\" height=\"80\" align=\"middle\" valign=\"middle\" class=\"title\"><img src=\"http://www.videonary.com/videonary/img/spacer.gif\"></td></tr>";
                    table = table + "<tr><td width=\"730\" valign=\"middle\" align=\"middle\" class=\"title\"><img src=\"http://www.videonary.com/videonary/img/spacer.gif\"></td></tr></table></td>";
                    table = table + "</tr></table></td></tr>";
                }

            }
            table = table + "</table>";
           // prompt(table);
            if (browsertype == 'Explorer'){
                var first= document.getElementById('container');
                var second = first.document.getElementById('content');
                var third = second.document.getElementById('userfans');
                var forth = third.document.getElementById('bbb');
                forth.innerHTML = table;
            }
            else if (browsertype != 'Explorer'){
                document.all["bbb"].innerHTML = table;
            }

       }
        else
        {
            alert("Error loading pagen"+ xmlHttp.status +":"+xmlHttp.statusText);
        }
    }
}