function getCookie(cookieName)
{
  // declare the local variables
  var cookieIndexOne, cookieIndexTwo;
  // attempt to locate the passed cookie
  cookieIndexOne = document.cookie.indexOf(cookieName);
  cookieIndexTwo = document.cookie.indexOf(";", cookieIndexOne +
    cookieName.length + 1);
  // if the passed cookie is the last one in the string, continue
  if (!(cookieIndexOne == -1) && (cookieIndexTwo == -1))
    // set the end of the cookie value to the end of the string
    cookieIndexTwo = document.cookie.length;
  // if the passed cookie value can't be located, return a default result
  if ((cookieIndexOne == -1) || (cookieIndexTwo == -1) ||
    (unescape(document.cookie.substring(cookieIndexOne + cookieName.length + 1,
      cookieIndexTwo)) == ""))
    return "All"
  // otherwise, return the passed cookie's value
  else
    return unescape(document.cookie.substring(cookieIndexOne + cookieName.length
      + 1, cookieIndexTwo));
}

function setCookie(cookieName, cookieValue, refresh)
{
  // if there is no cookie value set, give it a default value
  if (cookieValue == "")
    document.cookie = cookieName + "=All"
  // otherwise, set the cookie with the specified value
  else
    document.cookie = cookieName + "=" + cookieValue;
  // if the 'tema' cookie is passed, set the 'areaaplica' cookie
  // if the page needs to be refreshed, do so
  if (refresh == "true")
    window.location.reload(false);
}

function testCookie()
{
  // set the test cookie
  setCookie("test", "valido", false);
  // inform the user on whether or not the test cookie can be retrieved
  if (getCookie("test") == "valido")
    return "true"
  else
    return "false";
}

function transformXML(xmlDocURL, xslDocURL, divID)
{
  // declare the local variables
  var xmlDoc, xslDoc, docProcessor, docCache, DocRequest, docFragment;
  // try the following
  try
  {
    // instantiate and load the xml document
    xmlDoc = new ActiveXObject("MSXML2.DOMDocument");
    xmlDoc.async = false;
    xmlDoc.load(xmlDocURL);
    // instantiate and load the xsl document
    xslDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
    xslDoc.async = false;
    xslDoc.load(xslDocURL);
    // prepare the xsl document for transformation
    docCache = new ActiveXObject("MSXML2.XSLTemplate");
    docCache.stylesheet = xslDoc;
    // instantiate the document processor and submit the xml document
    docProcessor = docCache.createProcessor();
    docProcessor.input = xmlDoc;
    // add parameters to the xsl document
	 // depende das variaveis de busca
    docProcessor.addParameter("keyword", getCookie("keyword"), "");
    // process the documents into html and submit to the passed div
    docProcessor.transform();
    // divID.innerHTML = docProcessor.output;
    document.getElementById(divID).innerHTML = docProcessor.output;
  }
  // catch any errors from the above code
  catch(e)
  {
    // try the following
    try
    {
      // instantiate and load the xml document
      docRequest = new XMLHttpRequest();
      docRequest.open("GET", xmlDocURL, false);
      docRequest.send(null);
      xmlDoc = docRequest.responseXML;
      // instantiate and load the xsl document
      docRequest = new XMLHttpRequest();
      docRequest.open("GET", xslDocURL, false);
      docRequest.send(null);
      xslDoc = docRequest.responseXML;
      // instantiate the document processor and submit the xsl document
      docProcessor = new XSLTProcessor();
      docProcessor.importStylesheet(xslDoc);
      // add parameters to the xsl document
		//
		docProcessor.setParameter(null, "keyword", getCookie("keyword"));
      // clear the passed div if anything was in it
      document.getElementById(divID).innerHTML = "";
      // process the documents into html and submit to the passed div
      docFragment = docProcessor.transformToFragment(xmlDoc, document);
      document.getElementById(divID).appendChild(docFragment);
    }
    // catch any errors from the above code
    catch(e)
    {
      // do nothing
    }
  }
}

function viewDetails(num)
{
  // open the trabalho details window
  window.open("trabalhos/"+num+".pdf", "details", "width=700,height=520");
}


