function showPdf(form, event, busyMsg, validate, nextAction)
{
  if(validate == true && validateLogbookPrintForm(form) == false) return false;
  win = window.open("", "showPdf","scrollbars=yes,resizable=yes,width=1100,height=900");
  thisTarget = form.target;
  form.target="showPdf";
  win.document.write('<html><head/>');
  win.document.write('<body>');
  win.document.write('<table align="right" bgcolor="red"><tr><td>');
  win.document.write(busyMsg);
  win.document.write('</td></tr></table>');
  win.document.write('</body>');
  win.document.write('</html>');
  win.document.close();
  form.submit();
  win.focus();
  form.target = thisTarget;
  /*if(nextAction != null)
  {
	form.action = nextAction;
	form.submit();
  }*/
  //window.history.back();
  return false;
}

function getElementX(element){
    var targetLeft = 0;
    if (element.offsetParent) {
        while (element.offsetParent) {
        targetLeft += element.offsetLeft;
            element = element.offsetParent;
        }
    } else if (element.x) {
        targetLeft += element.x;
    }
    if(isIE) {
        targetLeft += 6;
    }
    return targetLeft;
}

function getElementY(element){
    var targetTop = 0;
    if (element.offsetParent) {
        while (element.offsetParent) {
        targetTop += element.offsetTop;
            element = element.offsetParent;
        }
    } else if (element.y) {
        targetTop += element.y;
    }
    if(isIE) {
        targetTop += 4;
    }
    return targetTop;
}


function selectLogbookCategory(sourceCtrl, displaySelection, targetId) {
	target = document.getElementById(targetId);
	if(sourceCtrl.value == displaySelection)
	{
		target.style.visibility = "visible";
	}
	else
	{
		target.style.visibility = "hidden";
	}
}

function hideMenu(id)
{
   document.getElementById(id).style.display = 'none';
}

var menuInited = 0;

function showMenu(targetId, divId)
{
	if(menuInited ==0)
	{
		target = document.getElementById(targetId);
		menuPopup = document.getElementById(divId);
		menuPopup.style.left = getElementX(target) + "px";
		menuPopup.style.top = getElementY(target) + target.offsetHeight + "px";
	}
	document.getElementById(divId).style.display = 'block';
}

var timeoutId = null;

function menuOut(id)
{
   if (timeoutId != null)
   {
      clearTimeout(timeoutId);
      timeoutId = null;
   }
   
   // hide the menu after a seconds delay
   timeoutId = window.setTimeout("hideMenu('" + id + "')", 1000);
}

function showBlock(showId, hideId, divId)
{
	document.getElementById(showId).style.display = 'none';
	document.getElementById(hideId).style.display = 'block';
	document.getElementById(divId).style.display = 'block';
}

function hideBlock(showId, hideId, divId)
{
	document.getElementById(showId).style.display = 'none';
	document.getElementById(hideId).style.display = 'block';
	document.getElementById(divId).style.display = 'none';
}

function toggleChecked(theForm, prefix) {
    len = theForm.elements.length;
    for( i=0 ; i<len ; i++) {
        if (theForm.elements[i].type.indexOf("checkbox") == 0) {
            var checkbox = theForm.elements[i];
            if(checkbox.name.indexOf(prefix) == 0) {
                if (checkbox.checked) {
                    checkbox.checked = false;
                } else {
                    checkbox.checked = true;
                }
            }
        }
    }
}
