
// Toggle show/hide descriptions
var toggle = new Array;
function show_hide_toggle(id){
   if (toggle[id] != null) {
      if (toggle[id]) change(id, "description hide");
      else            change(id, "description show");
      toggle[id] = ! toggle[id];
   }
   else{
      change(id, "description show");
      toggle[id] = 1;
   }
}
function change(id, newClass) {
   identity=document.getElementById(id);
   identity.className=newClass;
}

// Hide/Show/SetPosition for the "delete popup"
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == "number" ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == "number" ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in standards compliant mode
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight];
}

// Event handler init
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEDOWN);
    document.onclick = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onclick = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onclick = captureMousePosition;
}

// Global variables
xMousePos = 0; // Horizontal position of the mouse on the displayed portion of the page
yMousePos = 0; // Vertical position of the mouse on the displayed portion of the page

function captureMousePosition(e) {
   if (!e) var e = window.event;
   if (e.pageX || e.pageY)    {
      xMousePos = e.pageX;
      yMousePos = e.pageY;
   }
   else if (e.clientX || e.clientY)    {
      xMousePos = e.clientX + document.body.scrollLeft
         + document.documentElement.scrollLeft;
      yMousePos = e.clientY + document.body.scrollTop
         + document.documentElement.scrollTop;
   }
}

var ROOT_DOC="undefined";
var username="undefined";
function ask_confirmation(dyn_title, dyn_item_id){
   xy = getScrollXY();
   wh = getSize();

   identity=document.getElementById("alert_box");

   x = xMousePos - 130 ; //  bubble arrow position (background image image)
   y = yMousePos - 85 - 20; // message box height (fixed by css)
 
 x = wh[0] / 2 - 225 + xy[0];
 y = wh[1] / 2 - 50 + xy[1];
 
   identity.style.top = y+"px";
   identity.style.left = x+"px";    

   var dyn=document.getElementById("dyn_text");
   // if a delete box was already openned, clear the previous msg
   if (dyn.childNodes.length) dyn.removeChild(dyn.childNodes[0]);  
   var newdiv = document.createElement("div");
   newdiv.innerHTML = "<p>" + dyn_title + "</p>" + "<p class=\"action_link\"><a class=\"green\" href=\"" + ROOT_DOC + "/" + username + "?action=delete&item_id=" + dyn_item_id + "\">Yes</a> <a class=\"red\" href=\"javascript:change(\'alert_box\', \'hide\')\">No</a>";
   dyn.appendChild(newdiv);

   change("alert_box", "show");
}
