var BCCount = 0;
var BCFound = false;
// Function to call onLoad
function bcb4() {
	// check for Internet Explorer
	if (navigator.appVersion.indexOf("MSIE") == -1) {
		bcshow("BC_waiting", false);
		bcshow("ERR_IE");
		return; //FAIL
	}
	// Launch delayed check for Printable web
	var t=setTimeout("tpw()",1200);
}

// Tests for printable web
function tpw() {
	if (!LEXMARK.CEEHSAWWW.isActive()) {
		bcshow("BC_waiting", false);
		bcshow("ERR_BHO");
		return; //FAIL
	}
	LEXMARK.CEEHSAWWW.getPrinters(onPrinters);
}  

// Downloads the Printable Web
function startPWDownload() {
	bcshow("ERR_BHO", false);
	bcshow("ERR_RELOAD");
	window.location.href = 'http://www.lexmarklabs.com/downloads/PrintableWeben.exe';
}

// Gets a list of printers
function onPrinters(o) {
	if("undefined" !== typeof(o.result)) {
		BCCount = o.result.length;
		for (var i = 0; i < o.result.length; i++) {
			LEXMARK.CEEHSAWWW.getPrinterDriverName(onDriverName, o.result[i]);
		}
	}
}

// Checks the driver name
function onDriverName(o) {
	if("undefined" !== typeof(o.result)) {
		if (o.result[0].indexOf("Pro200") != -1 ||
		o.result[0].indexOf("Pro700") != -1 ||
		o.result[0].indexOf("Pro800") != -1 ||
		o.result[0].indexOf("Pro900") != -1 ) {
			BCFound = true;
			bcshow("BC_waiting", false);
			bcshow("BC_content");
		}
	}
	BCCount--;
	if (BCCount == 0 && !BCFound)
	  {
	  bcshow("BC_waiting", false);
	  bcshow("ERR_PRINTER");
	  }
}  

// Shows or hides an element on the page.
function bcshow(id, show) {
	if (show == undefined) {
		show = true;
	}
	var e = document.getElementById(id);
	e.style.display = show ? "block" : "none";
}
