function JsPrinter (autoSplit,autoPrint){
	
	var autoSplilt,autoPrint;

	if (!autoSplit) this.autoSplilt=0;
	else this.autoSplilt=Math.max(eval(autoSplit),0);
	
	if (!autoPrint) this.autoPrint=0;
	else this.autoPrint=Math.max(eval(autoSplit),0);
	
	
	if (this.autoSplilt==1) this.__splitPage();
	if (this.autoPrint==1)  this.print();
	
	return true;
	
}

/** private member **/
JsPrinter.prototype.__tag="JsPrintSplit";
//JsPrint.prototype.autoSplilt=1;
//JsPrint.prototype.autoPrint=1;



/**
 *  do change it
 */
JsPrinter.prototype.isIE  = document.all ? 1 : 0
JsPrinter.prototype.isNs4 = document.layers ? 1 : 0
JsPrinter.prototype.isDom = document.getElementById ? 1 : 0
JsPrinter.prototype.isMac = navigator.platform == "MacPPC"
JsPrinter.prototype.isMo5 = document.getElementById && !document.all ? 1 : 0
JsPrinter.prototype.isWebBrowser=false;
JsPrinter.prototype.totalPage=0;
JsPrinter.prototype.WebBrowser=null;


JsPrinter.prototype.print = function (){
	window.print();
}

JsPrinter.prototype.prview = function (){
	
	if (this.isWebBrowser==false) this.__getWebBrowser();
	
	if (this.isMo5 == 1 || this.isWebBrowser==0) {
		alert("WebBrowser not support print View");
		return false;
	}
	this.WebBrowser.ExecWB(7,1);
}

JsPrinter.prototype.setPrint = function (){
	
	if (this.isWebBrowser==false) this.__getWebBrowser();

	if (this.isMo5 == 1 || this.isWebBrowser==0) {
		alert("WebBrowser not support this function");
		return false;
	}	
	this.WebBrowser.ExecWB(8,1);
	
}

JsPrinter.prototype.splitPage = function (){
	this.__splitPage();
}

JsPrinter.prototype.unSplitPage = function (){
	this.__splitPage(false);
}

JsPrinter.prototype.setTag = function (tag){
	this.__tag=tag;
}


/**
 * private method
 */
JsPrinter.prototype.__getWebBrowser = function (){
    this.WebBrowser = document.getElementById("WebBrowser");
	this.isWebBrowser = this.WebBrowser ? 1 : 0
}


/**
 * private method
 * @see http://www.w3schools.com/HTMLDOM/prop_style_pagebreakbefore.asp
 */
JsPrinter.prototype.__splitPage = function (disable){
	
	if (!disable) var isSpilt="always";
	else var isSpilt="avoid";
	
	var rows=document.getElementsByTagName("div");
	
	for (var i=0;i<rows.length;i++){
		if (rows[i].id==this.__tag){
			rows[i].style.pageBreakBefore="always";
			this.totalPage++;
		}
	}
	
}

var JsPrinter=new JsPrinter(1);