// JavaScript Document
    function makeRequest(url, topic)
	{
        var httpRequest;

        if (window.XMLHttpRequest)// Mozilla, Safari, ...
		{ 
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType)
			{
                httpRequest.overrideMimeType('text/xml');
            }
        } 
        else if (window.ActiveXObject)// IE
		{ 
            try 
			{
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e)
			{
				try {
                		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                    } 
                catch (e) {}
			}
		}

        if (!httpRequest)
		{
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
		

        httpRequest.onreadystatechange = function() { showResult(httpRequest, topic); };
        httpRequest.open('GET', url, true);
        httpRequest.send('');

    }
	
	//Display the chart
	function displayChart(x, y)
	{	
		document.getElementById(x).innerHTML = y;
		//return true;
	}


    function showResult(httpRequest, topic)
	{
        if (httpRequest.readyState == 4)
		{
            if (httpRequest.status == 200) 
			{
				 xmlDoc=httpRequest.responseXML;

				 var option = xmlDoc.getElementsByTagName("Option");
				 var total_vote = 0;
				 
				 for(i=0; i<option.length; i++)
				 { 
				 	total_vote += parseInt(xmlDoc.getElementsByTagName("Option")[i].firstChild.firstChild.data);
				 }
				 
				 for(i=0; i<option.length; i++)
				 { 
				    var elem_id = 'result_'+topic+'_'+(i+1);
					
				 	var temp = xmlDoc.getElementsByTagName("Option")[i].firstChild.firstChild.data;
					var bar_length = (temp/total_vote)*300;
					var showTime = 360*(i+1);
					
					if(bar_length > 0)
					{
						var data = '<img src="image/chart_bar.gif" alt="'+temp+'" height="16" width="'+bar_length+'" /> '+temp;
 			        	setTimeout("displayChart('"+elem_id+"','"+data+"')", showTime);
					}
				 }
            } 
			else
			{
                alert('There was a problem with the request.');
            }
        }
    }
