// PRINT FUNCTION
// USE THE FOLLOWING TAG :<a href="javascript:printPage();"></A>
// TAG WILL CALL PINTPAGE FUNCTION WHICH EXECUTES THE PRINT FUNCTIONALTIY OF THE BROWSER

function printPage(){
	if(navigator.appName == "Netscape"){
		if (parseInt(navigator.appVersion) > 3)
			window.print();
		else
			alert("Go to your File Menu and select Print.");
	}else{
		window.printFrame(top.main);
	}
}
// **********************************************************************************
// BEGIN PRINT-RELATED FUNCTIONS

function printFrame(frame, onfinish) {

  var browser = navigator.appName.toLowerCase();
  var msie = (browser.indexOf("microsoft") > -1) ? 1 : 0;
  var msiev4 = (msie) ? ( (parseInt(navigator.appVersion) > 4) ? 0 : 1 ) : 0;
  if (! msiev4){
	top.main.print();
	return;
  }	
  var version = navigator.appVersion.toLowerCase();
  if (version.indexOf("mac") > -1){
  	alert("Go to your File Menu and select Print Frame");
	return;
  }
  if ( !frame ) frame = window;

/*
  if ( frame.document.readyState !== "complete" &&
       !confirm("The document to print is not downloaded yet! Continue with printing?") )
  {
    if ( onfinish ) onfinish();
    return;
  }
*/
  if ( printIsNativeSupport() ) {
    /* focus handling for this scope is IE5Beta workaround,
       should be gone with IE5 RTM.
    */
    var focused = document.activeElement; 
    frame.focus();
    frame.self.print();
    if ( onfinish ) onfinish();
    if ( focused && !focused.disabled ) focused.focus();
    return;
  }

  var eventScope = printGetEventScope(frame);
  var focused = document.activeElement;

  window.printHelper = function() {
    execScript("on error resume next: printWB.ExecWB 6, 1", "VBScript");
    printFireEvent(frame, eventScope, "onafterprint");
    printWB.outerHTML = "";
    if ( onfinish ) onfinish();
    if ( focused && !focused.disabled ) focused.focus();
    window.printHelper = null;
  }

  document.body.insertAdjacentHTML("beforeEnd",
    "<object id=\"printWB\" width=0 height=0 \
    classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\"></object>");

  printFireEvent(frame, eventScope, "onbeforeprint");
  frame.focus();
  window.printHelper = printHelper;
  setTimeout("window.printHelper()", 0);
}

// helpers
function printIsNativeSupport() {
  var agent = window.navigator.userAgent;
  var i = agent.indexOf("MSIE ")+5;
  return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
}

function printFireEvent(frame, obj, name) {
  var handler = obj[name];
  switch ( typeof(handler) ) {
    case "string": frame.execScript(handler); break;
    case "function": handler();
  }
}

function printGetEventScope(frame) {
		
  var frameset = frame.document.all.tags("FRAMESET");
	
  if ( frameset.length ) return frameset[0];
  return top.document.body;
}

/*
	to use this call this function with the following HTML
	<a href="javascript:window.printFrame(top.main)">
*/
