/*
# $Header: /aplic/ITED/src/repository/aplic/ITED/www/htdocs/common/scripts/print.js,v 1.44 2002-12-11 15:34:38-02 e007413 EP $
*/
var tIDP,_TimeP=5500,_Win,ObjP=null,_PEND,_Brow=new Browser(),_K=(typeof parent.isWebKiosk!="undefined"&&parent.isWebKiosk())||/\&kiosk=true/.test(location.href);
var _IMAC=_Brow.isMac()&&_Brow.isIE(),_lnx=_Brow.isLinux();
if(!canP())window.printFrame=_pFrm;
function _pFrm(f,of){
	if(!f)f=window;
	if(f.document.readyState!=="complete"){if(of)of();return;}
	var eS=printGetEventScope(f);
	window.printHelper=function(){
		var s="on error resume next: printWB.ExecWB "+(_K?"6,2,1":"6,1");
		_Win.execScript(s,"VBScript");
		printFireEvent(f,eS,"onafterprint");
		_Win.printWB.outerHTML="";
		window.printHelper=null;
	}
	_Win.document.body.insertAdjacentHTML("beforeEnd","<object id=\"printWB\" width=0 height=0 classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\"></object>");
	printFireEvent(f,eS,"onbeforeprint");
	f.focus();
	window.printHelper=printHelper;
	setTimeout("window.printHelper()", 0);
}
if(!canP())window.printFireEvent=_pFire;
function _pFire(f,o,name){
	var handler=o[name];
	switch(typeof(handler)){
		case "string":f.execScript(handler);break;
		case "function":handler();
	}
	if(name=="onafterprint")if(_PEND)endP();
}
if(!canP())window.printGetEventScope=_pGE;
function _pGE(frm){
	var d=frm.document,f=d.all.tags("FRAMESET");
 	return f.length?f[0]:d.body;
}
function printPage(w,end){
	_PEND=(typeof end =="undefined"?true:end);
	_Win=w;
	if(!_Win)_Win=window;
	if(typeof end=="undefined")end=true;
	_Win.focus();
	if(_IMAC)return;
	if(!canP())printFrame(_Win);
	else{_Win.print();if(_PEND)endP();}
}
function closeP(){
var t=(typeof _Win.parent);
if(t!="unknown"&&t!="undefined")_Win.parent.close();
}
function endP(){
tIDP=(_lnx?setTimeout("if(parent.central&&parent.central._closePrnLnx)parent.central._closePrnLnx()",_TimeP):(parent.frames.length==0)?setTimeout("_Win.close();",_TimeP):setTimeout("closeP()",_TimeP));
}
function canP(){
	var ag=navigator.userAgent;var i=ag.indexOf("MSIE ")+5;
	return !_K&&(navigator.appName.indexOf("Netscape")!=-1||(parseInt(ag.substr(i))>=5&& ag.indexOf("5.0b1")<0));
}

function getObjPrint(){return ObjP;}
function printWindow(attr){ObjP=new PrintWindow(attr);}
function PrintWindow(attr){
	this.attr=attr;
	this.getURL=_getURL;this.getParam=_getParam;this.getParms=_getParms;
	this.show=_show;this.init=_init;
	this.init();
}
function _init(){
	this.getParms("method,action,same_content,print_logo,submit_function,form,debug,orientation");
	var s=trim(this.same_content);
	this.same_content=((!s && !this.action)||s=="false")?false:true;
	this.debug=(!this.debug||this.debug=="no")?false:true;
	if(_IMAC)this.debug=true;
	this.m=(this.method?this.method.toLowerCase():"get");
	if(this.m=="post"){
		var f=this.form;
		if(!f||typeof(f)=="undefined"||f.length==0){alert('printWindow: The form attribute must be defined.');return;}
	}
	this.show();
}
function _show(){
	var o=this.orientation,msgL="Lembre-se: para imprimir, você deve "+(_IMAC?"acessar o menu File e clicar na opção Print.":"configurar sua impressora para o FORMATO PAISAGEM.");
	if(_IMAC||(o&&o.toLowerCase()=="landscape"))alert(msgL);  
  if(_IMAC&&this.same_content)openFPrint("/ITE/common/html/print/printIE.html",700,500,true);
  else if(!this.same_content&&(_IMAC ||this.debug))openFPrint(this.getURL(),700,500,true);
  else if(this.method=="get"&&this.same_content){
	  if(_Brow.isIE()||typeof document.getElementById=="function"){
			changeLogo(this.print_logo);
   		if(document.all&&parent.central){
				d=parent.central.document.all;
				if(d.ponto&&d.ponto.style)d.ponto.style.visibility="hidden";
				if(d.info_print&&d.info_print.style)d.info_print.style.visibility="hidden";
			}
    }
  	printPage(window,false);
  }else if(this.method=="get"&&!this.same_content)openFPrint(this.getURL(),403,200);
  else if(this.method=="post")openFPrint("/ITE/common/html/print/printpagepost.html",403,200);
}
function openFPrint(u,w,h,debug){
	var l=(screen.width-w)/2,t=(screen.height-h)/2;
	window.open((debug?u:'/ITE/common/html/print/frame.htm?central='+escape(u)),'PW'+random(1,9999),'left='+l+',top='+t+',width='+w+',height='+h+',directories=no,location=no,menubar=no,scrollbars='+(!debug?'no':'yes')+',status=no,resizable=no');
}
function _getURL(){
	var a=this.action;var h=a?a:document.location.href,mp="media=print";
	if(typeof getCurrentState=="function"){
		h=h.replace(/ServletState=[0-9]+\&?/,"").replace(/\?$/,"");
		mp+="&ServletState="+getCurrentState();
	}
	if(!this.form)this.form=0;
	var f=document.forms[this.form];
	if(this.m=="get"||(!f ||!f.media ||f.media.value!="print"))h+=h.indexOf("?")==-1?"?"+mp:"&"+mp;
	return h+(_K?'&kiosk=true':'');
}
function _getParam(prop,def){
	var re,p=trim(prop);
	if(p.toLowerCase()!="submit_function")re=new RegExp(".*" +p+"=([^,]*)(,.*|$)");
	else re=/.*submit_function=([^,]*\\(.*\\)[^,]*)(,.*|$)"/;
	var r=re.exec(trim(this.attr));
	if(!r||!r.length||r.length<2)return def?def:"";
	else return String(r[1]);
}
function _getParms(p){
	var a=String(p).split(","),i=0;
	for(i=0;i<a.length;i++)eval("this."+a[i]+"=this.getParam('"+a[i]+"')");
}
function changeLogo(print_logo){
if(print_logo){
 	var dI=document.images;
 	if(!(dI&&dI.LogoPrint))return;
	if(print_logo=="none"){dI.LogoPrint.style.width=0;dI.LogoPrint.style.height=0;
  }else{
		var s=dI.LogoPrint.src.replace(/http:\/\/[^\/]+/,"");
		if(s!=print_logo&&dI&&dI.LogoPrint)dI.LogoPrint.src=print_logo;   	
  }
}
}

