var xmlHttp;

// from www.w3schools.com - http://www.w3schools.com/php/php_ajax_suggest.asp
function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}


function qadd(filmid, rtype) {
    var url="xml.php";
    url += "?f=qadd&filmid=" + filmid;
    url += "&rtype=" + rtype;
    url += "&time=" + new Date().getTime();
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Browser does not support AJAX.");
        return;
    }

    xmlHttp.onreadystatechange=qaStateChanged;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function qaStateChanged() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        filmid = xmlHttp.responseXML.getElementsByTagName("filmid")[0].childNodes[0].nodeValue;        
        result = xmlHttp.responseXML.getElementsByTagName("result")[0].childNodes[0].nodeValue;        
        document.getElementById("rqa"+filmid).innerHTML=result;
    }
}

function ca_toggle(ca_type) {
   button = document.getElementById("ca_"+ca_type);
   if (button.className == "active") {
       button.className='';
       divs = document.getElementsByTagName("div");
       for (i=0; i<divs.length; i++) {
           if ( divs[i].className=='ca_'+ca_type ) {
               divs[i].style.display='none';
           }
       }
   } else {
       button.className="active";
       divs = document.getElementsByTagName("div");
       for (i=0; i<divs.length; i++) {
           if ( divs[i].className=='ca_'+ca_type ) {
               divs[i].style.display='block';
           }
       }
   }
}

