/* 
 DIREITOS AUTORAIS. HSBC HOLDINGS PLC 2003. TODOS OS DIREITOS RESERVADOS
 Este software é destinado apenas aos fins para os quais foi fornecido. 
 Nenhuma parte do mesmo pode ser reproduzida, desmembrada, transmitida, 
 armazenada em sistema recuperável, nem traduzida em qualquer outra linguagem
 humana ou de informática, de nenhuma forma ou para qualquer outra finalidade
 além daquela para o qual foi dada autorização prévia pelo HSBC Holdings plc.
*/

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;
//MSGBOX com titulo HSBC
function HSBCAlert(msg){parent.alert("HSBC BANK BRASIL S.A. - BANCO MÚLTIPLO  \n\n"+msg);} 
if(parent.frames&&parent.frames.length>0)window.alert=HSBCAlert;
function logout(app){
	function _cl(){if(parent.frames.length==0)window.close(); else parent.close();}
	if(!app){
		if(parent.finish)parent.finish();
		else{
			if(typeof getCanalID!="function")_cl();
			else if(getCanalID()==""||getCanalID()=="0")_cl();
			else parent.central.location.replace('/ITE/common/html/logout.htm?url=/HOB-PREMIER/servlets/Logout');
		}
	}else{
		if(app.indexOf("url=")==0)parent.central.location.replace('/ITE/common/html/logout.htm?'+app);			
		else _cl();
	}
}
//Abre popup do Chat
function popupChat(oferta){
  if(oferta==null){
    oferta='';
  }
  window.open('/ITE/app/ib/chat/chat.html?Oferta='+oferta, 'tinyWindow', 'scrollbars=no,width=372,height=450,top=0,left=410,menubar=no,toolbar=no,directories=no');		 			
}

//Abre popup do Chat não corr
function popupChatNC(oferta,CPF){
  if(oferta==null){
    oferta='';
  }
  window.open('/ITE/app/ib/chat/chatNC.html?Oferta='+oferta+'&CPFTITULAR='+String(CPF), 'tinyWindow', 'scrollbars=no,width=372,height=450,top=0,left=410,menubar=no,toolbar=no,directories=no');		 			
}

function popupHelp(anchor){
var width=750,height=460,url,
c=(typeof getCanalID=="function"?parseInt(getCanalID()):'0');
p=(typeof getProfileID=="function"?parseInt(getProfileID()):'0');
	if(arguments.length>1){anchor=arguments[1];}
	if(c==15)url="/ITE/app/autofinance/help/help.htm?ancora=";
	else if(c==7){
		if(p==4)url="/ITE/app/seguros/help/helpJuridico.htm?ancora=";
		else url="/ITE/app/seguros/help/helpFisico.htm?ancora=";
	}else if(c==8||c==16){url="/ITE/app/connect/help/help.html?ancora=";width=770;}
	else{url="/ITE/app/ib/help/help.html?ancora=";width=770;}
	var j=window.open(url+(anchor?anchor:"")+"&profile="+(typeof parent.getAppType=="function"&&parent.getAppType()!=null?parent.getAppType():p),'HelpWind'+random(1,9999),'left=0,top=0,width='+width+',height='+height+',directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no');
}
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);}

function _SPLT(c){
   var r=[],t="",i,l=this.length;
   if(l==0)return null;
   for(i=0;i<l;i++){
      var ch=this.slice(i,i+1);
      if(ch==c){r.push(t);t="";}
      else t+=ch;
   }
   r.push(t);
   return r;
}
function _PSH(i){this[this.length]=i;return this.length;}
function _POP(){
	l=this[this.length-1];
	this.length=Math.max(this.length-1,0);
	return l;
}
function _SPLI(ind,c){
	var t=arguments.length,i;
	if(t==0)return ind;
	if(typeof ind!="number")ind=0;
	if(ind<0)ind=Math.max(0,this.length+ind);
	if(ind>this.length){
		if(t>2)ind=this.length;
		else return [];
	}
	if(t<2)c=this.length-ind;
	c=(typeof c=="number")?Math.max(0,c):0;
	rmv=this.slice(ind,ind+c);
	end=this.slice(ind+c);
	this.length=ind;
	for(i=2;i<t;i++)this[this.length]=arguments[i];
	for(i=0;i<end.length;i++)this[this.length]=end[i];
	return rmv;
}
function _SHF(){var r=this[0];this.splice(0,1);return r;}
Array.prototype.shift=_SHF;
Array.prototype.splice=_SPLI;
Array.prototype.pop=_POP;
Array.prototype.push=_PSH;
String.prototype.split=_SPLT;
/*
# print.js,v 1.44 
*/
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 _show(){
	//Netscape imprime direto a tela de consulta
	if(String(navigator.appName).indexOf("Netscape")!=-1 && this.method=="get" &&this.same_content){
		window.print();return;
	}
	var r=(typeof random=="function"?random(1,9999):0);
	var j=window.open(this.getHTMPrint(),'HSBCImpr'+r,'left=0,top=0,width='+this.w+',height='+this.h+',directories=no,location=no,menubar=yes,resizable=no,scrollbars=yes,status=yes');
}
function _getHTMPrint(){
var uH="/ITE/common/html/",page="",uP=uH+"print/";
	switch(this.m){
		case "get":
			if(String(navigator.appName).indexOf("Internet Explorer")!=-1 && this.same_content){
				page=uP+"print.htm";
				if(this.print_logo)page+="?print_logo="+this.print_logo;
			}else page=this.getURL();
			break;
		case "post":page=uP+'printpagepost.html';break;
		default:alert("printWindow:Invalid method: "+this.m);
	}
	return page;
}
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 timeoutControl(url,seg){
	if(arguments.length==0){
		url="/ITE/common/html/telatimeout.htm";
		seg=300;url="/ITE/common/html/telatimeout.htm";
	}
	setTimer(seg);
	window._Page=url+(/\?/.test(url)?"&s=":"?s=")+seg;
	startInterval();
}
function resetTimeOut(seg){
	setTimer(seg);
	window._Page=String(window._Page).replace(/\?s=.*/,"?s="+seg);
	startInterval();
}
function callTimeout(){
	stopInterval();
	if(parent.operation&&parent.operation.OP_BAR)parent.operation.OP_BAR.hide();
	document.location.replace(window._Page);
}
function closeTimeout(){stopInterval();}
function setTimer(s){if(!s)s=300;window.rMin=window.tMin=Math.floor(s/60);window.rSec=window.tSec=s%60;}
function startInterval(){
	stopInterval();
	window.oInterval=window.setInterval("runTimeout()",5*1000);
	var o=parent.operation;
	shwInterval();
}

function stopInterval(){
	if(window.oInterval!=""){window.clearInterval(window.oInterval);window.oInterval="";}
	var o=parent.operation;
	if(o&&o.OP_BAR&&o.OP_BAR&&o.OP_BAR.WATCH)parent.operation.OP_BAR.WATCH.hide();
}
function runTimeout(){
	window.rSec-=5;
	if(window.rSec<0){window.rMin--;window.rSec=(60-5);}
	shwInterval();
	if(window.rMin<=0&&window.rSec<=0)callTimeout();
}
function shwInterval(){
	var o=parent.operation;
	if(o&&o.OP_BAR&&o.OP_BAR.WATCH){
		o.OP_BAR.WATCH.show();
		var n=((window.rMin<10?"0":"")+window.rMin+":"+(window.rSec<10?"0":"")+window.rSec);
		if(!isNaN(parseInt(n)) ){
			if(o && o.OP_BAR)o.OP_BAR.WATCH.setContent(n);
		}else{
			if(o && o.OP_BAR)o.OP_BAR.WATCH.hide();
		}
	}
}
//  $Header: /aplic/ITED/src/repository/aplic/ITED/www/htdocs/common/scripts/cookie.js,v 1.4 2003-01-30 09:21:32-02 e007413 EP $
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);
}
function validaConta(conta){
if(conta.length>=11)
//produção
parent.location.replace('http://www.hsbc.com.br/cgi-bin/cb_redirect.cgi?ID=IB&PARMS=CANAL%3Dinternet%26CONTAHSBC%3D'+conta);
//homologação
//parent.location.replace('http://uccpk027.ccp.br.hsbc:8089/cgi-bin/cb_redirect.cgi?ID=IB&PARMS=CANAL%3Dinternet%26CONTAHSBC%3D'+conta);
//desenvolvimento
//parent.location.replace('http://uccpk027.ccp.br.hsbc:8088/cgi-bin/cb_redirect.cgi?ID=IB&PARMS=CANAL%3Dinternet%26CONTAHSBC%3D'+conta);
}
