//---------------------------------------------------------------------------------
// (c) 2008 Eyegate Inc
// sitaxe: .../addFavourite.js - 
// AJAX que adiciona favorito
// Historico:
//   out08:Om: inicio
//---------------------------------------------------------------------------------
    // global flag
    var isIE = false;
    // global request and XML document objects
    var req;

// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file

function callAddFavouriteAJAX(url) {       // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = AJAXCallReturned;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {    // branch for IE/Windows ActiveX version
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = AJAXCallReturned;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function showStatus(aStatus) {
//  document.getElementById("updating").innerHTML = aStatus;
}

// handle onreadystatechange event of req object
function AJAXCallReturned() {
    // only if req shows "loaded"
    if (req.readyState == 4)  {         //4=complete. Ignora outros estados
       if (req.status == 200) {     	// use only if "200 OK"
         alert(req.responseText); //Ok: ou Error: 
       } else { 
         showStatus("error while adding favourite:"+req.status); 
       }
    }
}

// solicita lista de links via ajax e  retorna no elemento de id="midiaLinksSpan"
function goGetAddFavourite(aId,aUsername,aType) {
  if (aUsername == "anon_user") {
     alert("Sorry, you have to log in to use this features"); //Ok: ou Error:
  } else {
     var url = "addFavourite.php?id="+aId+"&user="+aUsername+"&tp="+aType; //fica tipo '/addFavourite.php?id=50&user=omar&tp=gal
     showStatus("updating..");
     callAddFavouriteAJAX(url);   //go get it
  }
}

