var xmlHttp

function showConstituencies(cand_id,election,button)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="../ajax/get_constituencies.php"
url=url+"?election="+election
url=url+"&cand="+cand_id+"&button="+button
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("constituencies").innerHTML=xmlHttp.responseText
document.getElementById("list_places").innerHTML=""
} 
} 


function showListPlaces(election,button,constituency)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="../ajax/get_list_places.php"
url=url+"?election="+election+"&button="+button+"&const="+constituency
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged2 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged2() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("list_places").innerHTML=xmlHttp.responseText 
} 
} 

function getLists(cand_id,election,button,constituency)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="../ajax/get_constituencies.php"
url=url+"?election="+election+"&const="+constituency+"&cand="+cand_id+"&button="+button
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged3
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged3() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("constituencies").innerHTML=xmlHttp.responseText
document.getElementById("list_places").innerHTML=""
} 
}

function getParties(election,button)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="../ajax/get_parties.php"
url=url+"?election="+election+"&button="+button
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged4
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged4() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("parties").innerHTML=xmlHttp.responseText
document.getElementById("constituencies").innerHTML=""
document.getElementById("list_places").innerHTML=""
} 
}

function showButtons(button,party)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="../ajax/show_buttons.php"
url=url+"?party="+party+"&button="+button
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged5
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged5() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("buttons").innerHTML=xmlHttp.responseText
} 
}

function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}

function pop(file)
{
helpwindow = window.open(file,"pop",'width=710,height=520,scrollbars=yes');
helpwindow.focus();
return false;
}

function showtooltip(tooltipId, parentId, posX, posY)
{
    it = document.getElementById(tooltipId);
    
        // need to fixate default size (MSIE problem)

        img = document.getElementById(parentId); 
    
        // if tooltip is too wide, shift left to be within parent 
        if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
        if (posX < 0 ) posX = 0; 
        
        x = xstooltip_findPosX(img) + posX;
        y = xstooltip_findPosY(img) + posY;
        
        it.style.top = y + 'px';
        it.style.left = x + 'px';
    
    it.style.visibility = 'visible'; 
}

function hidetooltip(id)
{
    it = document.getElementById(id); 
    it.style.visibility = 'hidden'; 
}

function xstooltip_findPosX(obj) 
{
  var curleft = 0;
  if (obj.offsetParent) 
  {
    while (obj.offsetParent) 
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function xstooltip_findPosY(obj) 
{
    var curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}


