/*
var http_request = false;
function makeRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/xml');
    }
  } else if (window.ActiveXObject) { // IE
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  if (!http_request) {
    alert('Cannot create XMLHTTP instance');
    return false;
  }
  http_request.onreadystatechange = alertContents;
  http_request.open('GET', url + parameters, true);
  http_request.send(null);
}


function alertContents() {
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      //alert('The returned XML is: '+http_request.responseText);
      var text = http_request.responseText;

      if (window.ActiveXObject) {
        // code for IE
        var doc=new ActiveXObject("Microsoft.XMLDOM");
        doc.async="false";
        doc.loadXML(text);
      } else {
        // code for Mozilla, Firefox, Opera, etc.
        var parser=new DOMParser();
        var doc=parser.parseFromString(text,"text/xml");
      }

      var xmlDoc = doc.documentElement;

      var errorText = xmlDoc.childNodes[0].childNodes[0].childNodes[0].nodeValue;

      if(errorText != 'NONE') {
        alert("An error has occurred:\n" + errorText);
        return;
      }

      printDOMTree(xmlDoc);

      var itemCount = xmlDoc.childNodes[0].childNodes[1].childNodes[0].nodeValue;
      var items = xmlDoc.childNodes[0].childNodes[2].childNodes[0];
      //alert(items.innerHTML);

      for(i = 0; i < itemCount; i++) {
        var aItem = items.childNodes[i];
        //alert(aItem.getElementsByTagName('id').nodeValue);
        //alert(aItem.getElementsByTagName('title').nodeValue);
      }

      return;

    } else {
      alert('An error occurred. Unable to load the gallery items for the specified category.');
    }
  }
}

function displayFadeIn(itemId) {
  for(i = 0; i < 5; i++) {
    objFadeIn('rating_'+i+'_'+itemId, 0);
  }
}

function displayFadeOut(itemId) {
  for(i = 0; i < 5; i++) {
    objFadeOut('rating_'+i+'_'+itemId, 100);
  }
}

function getItemsByDropDown(selectId, userId, sessionId) {
  var selectObj = document.getElementById(selectId);
  var categoryId = selectObj.options[selectObj.selectedIndex].value;
  getItemsForCategory(categoryId, userId, sessionId);
}

function getItemsForCategory(categoryId, userId, sessionId) {
  var ajaxControlUrl = "components/com_gallery/ajax_gallery_integration.php?";
  var avgRating = makeRequest(ajaxControlUrl, 'categoryId=' + categoryId + '&sessionId=' + sessionId + '&userId=' + userId + '&action=load');
}

/*
function addrow(tablename, arr) {
var tbl = document.getElementById(tablename);
var lastRow = tbl.rows.length;
var row = tbl.insertRow(lastRow);
for (r = 0; r < arr.length; r++) {
var cell = row.insertCell(r);
cell.innerHTML = arr[r];
}
}
*/
/*
var userRatingsMap = new Array();
var avgRatingsMap = new Array();

function populateRatings(itemId, avgRating, userRating) {
userRatingsMap[itemId] = userRating;
avgRatingsMap[itemId] = avgRating;
}

function displayUserRatings(itemId) {
var tmpUserRating = userRatingsMap[itemId];
for(i = 0; i < 5; i++) {
if(tmpUserRating == 0) {
document.getElementById('rating_'+i+'_'+itemId).src = 'images/gallery/star_empty.gif';
} else if(i < tmpUserRating) {
document.getElementById('rating_'+i+'_'+itemId).src = 'images/gallery/star_gold.gif';
} else {
document.getElementById('rating_'+i+'_'+itemId).src = 'images/gallery/star_empty.gif';
}
}

}

function displayAvgRatings(itemId) {
var tmpAvgRating = avgRatingsMap[itemId];

for(i = 0; i < 5; i++) {
if(tmpAvgRating <= (i + .30)) {
document.getElementById('rating_'+i+'_'+itemId).src = 'images/gallery/star_empty.gif';
} else if((tmpAvgRating > (i + .30)) && (tmpAvgRating < (i + .70))) {
document.getElementById('rating_'+i+'_'+itemId).src = 'images/gallery/star_red_half.gif';
} else if(tmpAvgRating >= (i + .70)) {
document.getElementById('rating_'+i+'_'+itemId).src = 'images/gallery/star_red.gif';
} else {
document.getElementById('rating_'+i+'_'+itemId).src = 'images/gallery/star_empty.gif';
}
}
}
*/



// Print DOM tree
////////////////////////////////////////////
// This function traverses the DOM tree of an element and prints the tree.
// This function called recursively until the DOM tree is fully traversed.
//
// Parameters:
// - targetDocument is where the tree will be printed into
// - currentElement is the element that we want to print
// - depth is the depth of the current element
//   (it should be 1 for the initial element)
////////////////////////////////////////////

/*
function traverseDOMTree(targetDocument, currentElement, depth) {
  if (currentElement) {
    var j;
    var tagName=currentElement.tagName;
    // Prints the node tagName, such as <A>, <IMG>, etc
    if (tagName) {
      targetDocument.writeln("&lt;"+currentElement.tagName+"&gt;");
      targetDocument.writeln(" - " + depth);
    } else {
      targetDocument.writeln("[unknown tag]");
    }
    // Traverse the tree
    var i=0;
    var currentElementChild=currentElement.childNodes[i];
    while (currentElementChild) {
      // Formatting code (indent the tree so it looks nice on the screen)
      targetDocument.write("<BR>\n");
      for (j=0; j<depth; j++) {
        // &#166 is just a vertical line
        targetDocument.write("&nbsp;&nbsp;&#166");
      }
      targetDocument.writeln("<BR>");
      for (j=0; j<depth; j++) {
        targetDocument.write("&nbsp;&nbsp;&#166");
      }
      if (tagName)
        targetDocument.write("--");

      // Recursively traverse the tree structure of the child node
      traverseDOMTree(targetDocument, currentElementChild, depth+1);
      i++;
      currentElementChild=currentElement.childNodes[i];
    }
    // The remaining code is mostly for formatting the tree
    targetDocument.writeln("<BR>");
    for (j=0; j<depth-1; j++) {
      targetDocument.write("&nbsp;&nbsp;&#166");
    }
    targetDocument.writeln("&nbsp;&nbsp;");
    if (tagName) {
      targetDocument.writeln("&lt;/"+tagName+"&gt;");
    }
  }
}

////////////////////////////////////////////
// This function accepts a DOM element as parameter and prints
// out the DOM tree structure of the element.
////////////////////////////////////////////
function printDOMTree(domElement, destinationWindow)
{
  // Use destination window to print the tree.  If destinationWIndow is
  //   not specified, create a new window and print the tree into that window
  var outputWindow=destinationWindow;
  if (!outputWindow)
    outputWindow=window.open();

  // make a valid html page
  outputWindow.document.open("text/html", "replace");
  outputWindow.document.write("<HTML><HEAD><TITLE>DOM</TITLE></HEAD><BODY>\n");
  outputWindow.document.write("<CODE>\n");
  traverseDOMTree(outputWindow.document, domElement, 1);
  outputWindow.document.write("</CODE>\n");
  outputWindow.document.write("</BODY></HTML>\n");

  // Here we must close the document object, otherwise Mozilla browsers
  //   might keep showing "loading in progress" state.
  outputWindow.document.close();
}

*/