function callPrint(strid)
{
  hideButtons();
  
    var prtContent = findPrintDiv(strid);
  var winPrint =
  window.open('','','left=0,top=0,width=1,height=1,t oolbar=0,scrollbars=0,status=0');
  winPrint.document.write(prtContent.innerHTML);
  winPrint.document.close();
  winPrint.focus();
  winPrint.print();
  winPrint.close();
  
  //showButtons();
  
}
//class="gwt-DialogBox"
function findPrintDiv(divClass)
{
  divList = $("div");
  for(i=0; i < divList.length; i++){
    clazz = $(divList[i]).attr("class");
    if((null != clazz) && (clazz == divClass)){
      // Found it so return
      return divList[i];
    }
  }
}

function timedReplacePrintButton()
{
	if($('#new_print_but').length > 0){
			// If the new print button is present then we are in the print window
		clearTimeout(timerID);
		return;
	}
  printBut = findPrintButton();
  if(null != printBut){
  	clearTimeout(timerID);
  	//printBut.hide();
    //printBut.attr("id", "old_print_but");
    var parent = printBut.parent();
	parent[0].removeChild(printBut[0]);
    newPrintBut = $('<button id="new_print_but">Print</button>');
    newPrintBut.attr('onclick','callPrint("gwt-DialogBox");');
    parent.append(newPrintBut);  	
  }
}


function findPrintButton()
{

 	buttons = $("button");
  for(i=0; i < buttons.length; i++){
  	var but = buttons[i];
  	if(but.innerHTML.search("Print") > -1){
          //parent.removeChild(but);
          return $(but);
      }
  }
  
  return null;
}

function hideButtons()
{
	$("button").hide();
    window.onfocus=showButtons;   
}

function showButtons()
{
	$("button").show();
}

// Get rid of the old print button
//addLoadEvent(replacePrintButton);
timerID = setTimeout('timedReplacePrintButton()', 1000 );
