function Browser(){
	this.name=this.platform="Unknown";
	this.majorver=this.version=this.minorver="";
	this.mozilla=false;
	this.init=_Init;
	this.getName=function(){return this.name};
	this.getMinorver=function(){return this.minorver};
	this.getMajorver=function(){return this.majorver};
	this.getVersion=function(){return parseFloat(this.version,10)};
	this.getPlatform=function(){return this.platform}; 
	this.isIE=function(){return(this.name=="IE")};
	this.isNetscape=function(){return(this.name=="Netscape")};
	this.isMozilla=function(){return this.mozilla};
	this.isWindows=function(){return _has(this.platform,["Windows","WinNT"])};
	this.isWin2000=function(){return _has(this.platform,["Windows NT 5.0","Win2000","Windows 2000"])};
	this.isWinXP=function(){return _has(this.platform,["Windows NT 5.1","WinXP","Windows XP"])};
	this.isWinNT=function(){return _has(this.platform,["WinNT","Windows NT"]) && !this.isWin2000() && !this.isWinXP();};
	this.isWin95=function(){return _has(this.platform,["Win95","Windows 95"])};
	this.isWin98=function(){return _has(this.platform,["Win98","Windows 98"])};
	this.isWinME=function(){return _has(this.platform,["WinME","Win 9x 4.90","Windows ME"])};
	this.isLinux=function(){return _has(this.platform,"Unix")};
	this.isMac=function(){return _has(this.platform,["Mac","PPC"]);};
	this.init();
}
function _Init(){
var ua=navigator.userAgent,t="",ts="",i,bv;
bv=ua.slice(0,ua.indexOf("("));
ts=ua.slice(ua.indexOf("(")+1,ua.indexOf(")")).split(";");
for(i=0;i<ts.length;i++){
	t=ts[i].trim();
	if(_has(t,["MSIE","Opera"]))bv=t;
	else if(_has(t,["X11","SunOS","Linux"]))this.platform="Unix";
	else if(_has(t,["Mac","PPC","Win"]))this.platform=t;
}
//deixa passar Win32 como WinXP
if(typeof this.platform !="undefined" && this.platform!=null && String(this.platform)=="Win32"){
	this.platform="WinXP";
}
var idx=bv.indexOf("MSIE"),lo="";
if(idx>=0)bv=bv.slice(idx);
if(bv.slice(0,7)=="Mozilla"){
	lo="";
	this.name="Netscape";
	if(ua.indexOf("Gecko/")!=-1){
		if(/Netscape/.test(ua)){
			var v=/([^\/]+)\s*$/.exec(ua);
			if(v&&v.length>1)lo=v[1]+" ";
		}else{
			this.mozilla=true;
			var v=/rv:([^\)]+)\)/.exec(ua);
			if(v&&v.length>1)lo=v[1]+" ";
		}
	}
	if(lo=="")lo=bv.slice(8);
}else if (bv.slice(0,4)=="MSIE"){
	this.name="IE";lo=bv.slice(5);
}else if (bv.slice(0,27)=="Microsoft Internet Explorer"){
	this.name="IE";lo=bv.slice(28);
}else if (bv.slice(0,5)=="Opera"){
	this.name="Opera";lo=bv.slice(6);
}
lo=lo.trim();
i=lo.indexOf(" ");
if(i>=0)this.version=lo.slice(0,i);
else this.version=lo;
j=this.version.indexOf(".");
if(j>=0){
	this.majorver=this.version.slice(0,j);
	this.minorver=this.version.slice(j+1);
}else this.majorver=this.version;
}
function _has(s,a){
s=String(s);
if(typeof(a)=="string")return s.indexOf(a)!=-1;
else{
	for(var i=0;i<a.length;i++)if(s.indexOf(a[i])!=-1)return true;
	return false;
}
}
function _TRIM(){
var s=0,e=this.length;
while(s<e&&this.charAt(s)==' ')s++;
while(e>0&&this.charAt(e-1)==' ')e--;
return this.slice(s,e);
}
String.prototype.trim=_TRIM;

function isAnchor(){
	if(window.currentLink){
		var obj=window.currentLink;
		if(obj.tagName=="IMG")obj=obj.parentElement;
		if(obj.tagName=="A"){
			var locAnchor=obj.href.split('#')[0],
			locWin=location.href.split('#')[0],
			re=new RegExp('Ap{1,2}lic');
			if(locAnchor==locWin ||re.test(obj.mimeType))return true;
		}
	}
	window.currentLink=null;
	return false;
}
function testAnchor(){if(window.event&&window.event.srcElement)window.currentLink=window.event.srcElement;}
function popup(url,j,atr){var w= window.open(url,j,removeStr(atr," "));}
function random(r1,r2){return Math.round(Math.random()*(r2-r1))+ (r2>r1?r1:r2);}
function trim(s){return String(s).replace(/^\s+/,"").replace(/\s+$/,"");}
function autoSkip(field,orient){
	var ind=-1,f=field.form;
	for(i=0;i<f.elements.length;i++)
		if(field==f.elements[i]){ind=i;break;}
	focusCampByPos(f,ind,orient);
}
function autoFocus(f,justInputSelect){focusCampByPos((arguments.length==0?document.forms[0]:f),-1,'down',justInputSelect);}
function focusCampByPos(fr,ind,orient,justInpSelect){
	reValidTypes=(justInpSelect?/^(text|password|select.*)$/:/^(text|password|select.*|radio|checkbox.*)$/);
	orient=orient?orient:"down";
	var iNext=(orient=="down"?1:-1),el;
	if((typeof fr.elements[ind+iNext])=="undefined"){
      if(ind!=-1)if(fr.elements[ind]&&fr.elements[ind].blur)fr.elements[ind].blur();
		return;
   }
	for(var i=ind+iNext;i<fr.elements.length;i+=iNext){
		el=fr.elements[i];
		if(reValidTypes.test(el.type) && !el.disabled){el.focus();return;}
   }
	if(ind>=0 && fr.elements[ind]&&fr.elements[ind].type && fr.elements[ind].type!='hidden' && fr.elements[ind].blur)fr.elements[ind].blur();
}
function isNumeric(v){return /^[0-9]+$/.test(v);}
function isAlfa(v){return /^[a-zA-ZáéíóúçãõâêôàÁÉÍÓÚÇÃÕÂÊÔÀ]+$/.test(v);}
function isAlfaNumeric(v){return /^[0-9a-zA-Z]+$/.test(v);}
function invertStr(s){
	var t="",i;
	for(i=0;i<s.length;i++)t=s.charAt(i)+t;
	return t;
}
function removeStr(src,arg){
	var v=(typeof arg=="string")?[arg]:arg;
	var r="";
	for(var i=0;i<v.length;i++)r=changeStr(src,v[i],"");
	return r;
}
function repeatStr(src,str,size,orient){
	var r=String(src);
	if(!orient)orient="left";
	while(r.length < size)r=orient.toLowerCase()=="right"?(r+str):(str+r);
	return r;
}
function changeStr(src,from,to)
{
	src=String(src);
	var i,li=0,lFrom= from.length,dst="";
	while((i=src.indexOf(from,li))!=-1){
		dst+=src.substring(li,i)+to;
		li=i+lFrom;
	}
	dst+=src.substring(li);
	return dst;
}
function justNumbersStr(s){return String(s).replace(/\D*/g,"");}
function onlySameNumber(s){return isNumeric(s)&& (new RegExp("^("+s.charAt(0)+")(\\1)*$")).test(s);}

var _Win=null;
window.ObjP=null;
window._PEND=null;
window._K=(typeof parent.isWebKiosk!="undefined"&&parent.isWebKiosk())||/\&kiosk=true/.test(location.href);
window._IMAC=(String(navigator.appVersion).indexOf("Mac")!=-1 && navigator.appName.indexOf("Internet Explorer")!=-1);
window._INFOC=null;
window._TimeP=10000;

function canP(){
	var ag=navigator.userAgent;var i=ag.indexOf("MSIE ")+5;
	return !window._K&&(navigator.appName.indexOf("Netscape")!=-1||(parseInt(ag.substr(i))>=5&& ag.indexOf("5.0b1")<0));
}

function _pGE(frm){
	var d=frm.document,f=d.all.tags("FRAMESET");
 	return f.length?f[0]:d.body;
}
function _pFrm(f,of){
	if(!f)f=window;
	if(f.document.readyState!=="complete"&&!confirm("Continue with printing?")){
		if(of)of();
		return;
	}
	var eS=printGetEventScope(f);
	window.printHelper=function(){
		var s="on error resume next: printWB.ExecWB "+(window._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);
}
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(window._PEND)endP();
}
if(!canP()){
	window.printFrame=_pFrm;
	window.printFireEvent=_pFire;
	window.printGetEventScope=_pGE;
}

function printPage(w,end){
	if(!w)w=window;
	if(w._IMAC)return;
	_Win=w;
	//Se aviso de lancamento, forca fechar a janela.
	if(w && typeof w.name!= "undefined" && (String(w.name).indexOf("AvisoLanc")==0) ){
		end=true;
	}
	w._PEND=(typeof end =="undefined"?true:end);
	if(typeof end=="undefined")end=true;
	w.focus();
	if(!canP())printFrame(w);
	else{w.print();if(w._PEND)endP();}
}

function printWindow(attr){window.ObjP=new PrintWindow(attr);}
function PrintWindow(attr){
	this.attr=attr;this.w=775;this.h=435;
	this.getURL=_getURL;this.getParam=_getParam;this.getParms=_getParms;
	this.show=_show;this.init=_init;this.getHTMPrint=_getHTMPrint;
	this.init();
}
function _init(){
	this.getParms("method,action,same_content,xml,print_logo,submit_function,form,debug,orientation,css");
	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(window._IMAC)this.debug=true;
	var msgL="Lembre-se: para imprimir, você deve "+(window._IMAC?"acessar o menu File e clicar na opção Print.":"configurar sua impressora para o FORMATO PAISAGEM."),o=this.orientation;
	if(window._IMAC)alert(msgL);
	else if(o&&o.toLowerCase()=="landscape")alert(msgL);
	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.same_content=false;
	
	}
	if(this.same_content){ //same_content imprime direto.	
		this.show();
	}else if(this.action && !window._IMAC){
		var url=this.getURL(),r=(typeof random=="function"?random(1,9999):0);
		if(/\?/.test(url))url+="&r="+r;
		else url+="?r="+r;
		trataInitPrint();
		var j=window.open(url,'AvisoLanc'+r,'left=0,top=0,width='+this.w+',height='+this.h+',directories=no,location=no,menubar=yes,resizable=no,scrollbars=yes,status=yes');
	}else this.show();
	
}
function trataInitPrint(){
	if(navigator.appName.indexOf("Internet Explorer")== -1)return;
	if(InfoPrintControl && typeof window.onbeforeprint!="undefined"){
		window._INFOC= new InfoPrintControl();
		if(window._INFOC.hide)window._INFOC.hide();
	}
}
function removeInfoPrint(){
if(!document.all)return;
var d=document.all.info_print;
	if(!d)return;
	if(d.innerHTML)d.innerHTML="";
	if(typeof d.style.width!="undefined")d.style.width=0;
	if(typeof d.style.height!="undefined")d.style.height=0;
}
function InfoPrintControl(){
this.hide=function(){if(parent.buttons && parent.buttons.hideBtInfo)parent.buttons.hideBtInfo();}
this.show=function(){if(parent.buttons && parent.buttons.callBtInfo)parent.buttons.callBtInfo();}
}
function _getURL(){
	var a=this.action;var h=a?a:document.location.href;
	var r=/\?xml=([^&]+)/.exec(h),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+(window._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 closeP(){
var t=(typeof _Win.parent);
if(t!="unknown"&&t!="undefined")_Win.parent.close();
}
function endP(){
	if(parent.frames.length==0)setTimeout("_Win.close();",window._TimeP);
	else setTimeout("closeP()",window._TimeP);
}
function getObjPrint(){return window.ObjP;}
window._Page=null;window.oInterval="";
window.CdTimeOut=0;
window.rMin=0;window.rSec=0;window.tSec=0;window.tMin=0;

function setCookie(name,value,dexp,path,domain,secure){
var expires=dexp;
if(typeof expires=="number"){expires=new Date();fixDate(expires);expires.setTime(expires.getTime()+dexp*60*60*1000);}
var curCookie=name+"="+escape(value)+((expires)?"; expires="+expires.toGMTString():"")+((path)?"; path="+path:"")+((domain)?"; domain="+domain:"")+((secure)?"; secure":"");
document.cookie=curCookie;
}
function getCookie(name){
var dc=document.cookie,prefix=name+"=",begin=dc.indexOf(prefix);
if(begin==-1)return null;
var end=document.cookie.indexOf(";",begin);
if(end==-1)end=dc.length;
return unescape(dc.substring(begin+prefix.length,end));
}
function deleteCookie(name,path,domain){
if(getCookie(name)){document.cookie=name+"="+((path)?"; path="+path:"")+((domain)?"; domain="+domain:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT";}
}
function verifyCookie(){
var valor,flag=0,nomeCookie="STCV";
setCookie(nomeCookie,"ligado");
if(getCookie(nomeCookie)!=null){flag=0;valor=1;deleteCookie(nomeCookie);
}else{if(!flag){flag=1;deleteCookie(nomeCookie);valor=0;}}
return valor;
}
function fixDate(date){
var base=new Date(0),skew=base.getTime();
if(skew>0)date.setTime(date.getTime()-skew);
}
