// Identificação de browser
var isNav4, isNav, isIE;
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
  isNav = (navigator.appName=="Netscape") ? true : false;
  isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
}
if (navigator.appName=="Netscape") {
	isNav4 = (parseInt(navigator.appVersion.charAt(0))==4);
}

//funcao de correcao do IE 5.5
function onClickHandler(e){
	var el = null;
	var flag = true;
	el = (isNav) ? e.target.parentNode : event.srcElement;
	while (flag && el){
		if ((el.tagName.toUpperCase()=="A")){
			var i = 0;
			flag = false;
			if (el.protocol.toUpperCase() == "JAVASCRIPT:"){
				var toexec = el.href;
				toexec = toexec.replace(/javascript\:/gi,'');
				eval(unescape(toexec));

			}
			else return true;
			return false;
		}
		else {
			el = (isNav) ? el.parentNode : el.parentElement;
		}
	}
}
document.onclick = onClickHandler;

function RTrim(s) {
    return s.replace (/\s+$/,'');
}

function LTrim(s) {
    return s.replace (/^\s+/,'');
}

function Trim(s) {
    return s.replace (/\s+/g,'');
}

function MTrim(s) {
    return s.replace (/\B\s+/g,' ');
}

//checks for Enter key, then if true, initiates page processing
//put the following into the HTML <INPUT> Tag:	ONKEYDOWN="Javascript:CheckENTER(formObj, buttonName);"


function CheckENTER(formObj, buttonName)
{

	var key = event.keyCode

	if (key == 13)		processPage(formObj, buttonName);

}


function LoggedOffEWF()
{
	var topmostParent = getTopmostParent();
	topmostParent.document.GlobalID = "0";
	topmostParent.document.EWF_ID = "0";
	topmostParent.document.EWF_FA =  "../i24scripts/cgiclnt.dll/CORE-Main%20Web/ND000_";
	topmostParent.document.Conta = "";
	topmostParent.document.Agencia = "";
	topmostParent.document.buttonClickedName = "";


}

function setFormValue(formValue, newValue)
{
	document.forms["APPS_FORM_MAIN"][formValue].value = newValue;
}

function GotoEWF(formObj, PlaceToGo)
{

	if (!formObj) return;

	var theTopMostParent = getTopmostParent();
	buttonClickedName = parent.document.buttonClickedName;

PlaceToGo = "Favoritos";

	formObj.action = theTopMostParent.document.EWF_FA;
	formObj["EWF_SYS_1"].value = theTopMostParent.document.EWF_ID;
	formObj["EXTRA1"].value = parent.document.GlobalID + "~~~" + parent.document.SESSAO + "~~"
	formObj["DATA1"].value = PlaceToGo;
	formObj.target = "infoText";

	formObj.BUTTON.name  = "EWF_BUTTON_" + buttonClickedName;
	formObj.BUTTON.value  = "EWF_BUTTON_" + buttonClickedName;

	if (formObj.BUTTON.name == "EWF_BUTTON_Logoff")
	{
		if (parent.document.EWF_ID == "0")
		{
			alert("You must be logged on to Logout!");
			return;
		}
		else
		{
			formObj.BUTTON.name= "EWF_BUTTON_Logoff";
			formObj.BUTTON.value= "EWF_BUTTON_Logoff";
			formObj.target = "infoText";
			formObj.submit();
			return;
		}
	}

	formObj.BUTTON.x = 1;
	formObj.BUTTON.y = 1;
	formObj.target = "infoText";
	formObj.submit();

}

function rollOn(GroupID, Image, Current)
{
	var currentImage = Current;
	var imageLocation = Image;

	if (currentImage == imageLocation)
	{
		var imageName = imageLocation.substring(0, imageLocation.length - 4);
		var newImage = imageName + "_o.gif";
		if (document.images) document.images[GroupID].src=newImage;
	}
}

function rollOff(GroupID, Image, Current)
{
	var currentImage = Current;
	var newImage = Image;

	if (newImage == currentImage)
	{
		document.images[GroupID].src=newImage;
	}
}

function rollOver(GroupID, Image)
{
	var imageLocation = Image;
	var imageName = imageLocation.substring(0, imageLocation.length - 4);
	var newImage = imageName + "_o.gif";
	if (document.images) document.images[GroupID].src=newImage;
}

function rollOut(GroupID, Image)
{
	var newImage = Image;
	if (document.images) document.images[GroupID].src=newImage;
}

// called with navigateEWF(document.forms['APPS_FORM_GROUP'], buttonName)
function navigateEWF(formObj, buttonName)
{
		formObj.BUTTON.name="EWF_BUTTON_" + buttonName;
		formObj.BUTTON.value="EWF_BUTTON_" + buttonName;

		formObj.submit();
}

function spawnNewWindow(fileName,frameName) {
	window.open(fileName, frameName, "toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,copyhistory=no,width=490,height=300,left=0,top=0")
}


function submitLogon()
{
	var formObj = document.forms["APPS_FORM_GROUP"];

	var formAction = "../i24scripts/cgiclnt.dll/CORE-Main%20Web/ND000";
	var ewfSysID = "61118042-FF0A-11D0-98DF-006097B70359";

	var LogonData = "";

	var cQuote = "'";
	formObj.action = formAction ;

	formObj.EWF_SYS_1.value = cQuote + ewfSysID + cQuote;

	formObj.submit();

}

function addValueToData2(addValue)
{
	var formObj = document.forms["APPS_FORM_MAIN"];
	formObj.DATA2.value += addValue + "~";
}

function addFieldToData2(fieldName)
{
    var valueFound;
    var formObj = document.forms['APPS_FORM_MAIN'];
    var afield = formObj[fieldName];

    // If it's a checkbox, return a T for true or F for false to i24
    if (afield.type == "checkbox")
    {
    	if (afield.checked)
    		formObj.DATA2.value += "T~";
        else
    		formObj.DATA2.value += "F~";
    }
    // If it's a select, return the selected value
    else if (afield.type == "select-one")
    {
		for (var ix=0; ix < afield.options.length; ix++)
		{
			if (afield.options[ix].selected)
			{
				formObj.DATA2.value += afield.options[ix].value + "~";
				break;
			}
		}

    }
    // if it doesn't have a type see if it's a radio
    else if (!afield.type)
    {
       if (afield.length >0)
       {
            for (var ix=0; ix < afield.length; ix++)
            {
                if (afield[ix].checked)
                {
                    formObj.DATA2.value += afield[ix].value + "~";
                    break;
                }
            }
        }
    }
    // if its a text or only 1 radio with the name, just add the value
    // note: this will also add hiddens, etc.
    else
        formObj.DATA2.value += afield.value + "~";
}

// Used to activate the cross-sell module in EBS
function xsellFunc()
{
	return '[JS-XSELL]';
}

// Functions added to facilitate data field validation...


function validateNumber(form,input, min, max) {
  var str = input.value;
  for (var i = 0; i < str.length; i++) {
    var ch = str.substring(i, i + 1)
    if ((ch < "0" || "9" < ch) && ch != ',' ) {
     alert("Please enter only NUMERICS with Commas");
    return false;
    }
  }
  //Strip out the comma then validate amount range
    str = str.replace(",","")
    var num = parseFloat(str)
  if (num < min || max < num)   {
  // Format with commas before we display
   min = "22,50";
   max = "999999999999,99";
   alert("Please enter a Valor within the range " + min + " to " + max + " ");
  return false;
  }
return true;
}


function nullstring(item) {
  entry = item
  if (entry == "") return true;
return false;
}

function blanks(item) {
  entry=item
  for (var i=0; i<entry.length; i++) {
   if (entry.charAt(i) != " ") return false;
   }
	return true;
}

function checkEmpty(item) {
  entry = item
  if (nullstring(entry) || blanks(entry)) return true;
    return false;
}

function checkNumeric(item){
  var digits="0123456789"
  entry=item
  var temp
  for (var i=0; i < entry.length; i++) {
    temp = entry.substring(i,i+1)
    if (digits.indexOf(temp) == -1) {
      return false;
    }
  }
return true;
}

function checkAlpha(item){
  var digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  entry=item
  var temp
  for (var i=0; i < entry.length; i++) {
    temp = entry.substring(i,i+1)
    if (digits.indexOf(temp) == -1) {
      return false;
    }
  }
return true;
}

function abre2(qual,nome) {
  window.open (qual,nome, 'type=fullWindow,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=320,height=420,top=60,left=110,maximized');
}

// Format money Fields (functions: formata, arredonda, range)

function formata(valor) {
    var str="";
    var j=0;
    range(valor);
    if(valor.value=="") {
        valor.value="0"
    }
    str = valor.value + ","
    arredonda(valor)
}

function arredonda(valor) {
    var j=0, str="";
    for(var i=0; (i<=valor.value.length-1)&&(valor.value.charAt(i)!=',');i++) {
        str=str+valor.value.charAt(i);
        j++
    }
    if(valor.value.charAt(0)==',')
        str=str+"0"
    str=str + ",";
    j++
    if(valor.value.charAt(j)=='')
        str=str+0
    else
        str=str+valor.value.charAt(j)
    if(valor.value.charAt(j+1)=='')
        str=str+0
    else
        str=str+valor.value.charAt(j+1)
    valor.value=str;
    str=""
    str=str+valor.value;
    valor.value=str
}

function range(campo) {
    for(var i=0; i<=(eval(campo.value.length)-1); i++)
        if(campo.value.charAt(i)!='0' && campo.value.charAt(i)!='1' && campo.value.charAt(i)!='2'
           && campo.value.charAt(i)!='3' && campo.value.charAt(i)!='4' && campo.value.charAt(i)!='5'
           && campo.value.charAt(i)!='6' && campo.value.charAt(i)!='7' && campo.value.charAt(i)!='8'
           && campo.value.charAt(i)!='9' && campo.value.charAt(i)!=',')
        {
            alert("Valor inválido. Favor redigitar.");
            campo.value=0
        }
}

//<INPUT ONKEYPRESS="onlynum();>
//function onlynum() {
//	if ((event.keyCode < 48)||(event.keyCode > 57))
//		event.keyCode = 0;
//}

function checkDecimal(campo) {
	if (campo.value.length == 2)
		campo.value = '0,' + campo.value;
	if (campo.value.length == 1)
		campo.value = '0,' + campo.value + '0';
}

//<INPUT VALUE="" maxlength="14" ONKEYDOWN="Formatador(this,11,event);" ONCHANGE="checkDecimal(this);">

function Formatador(campo,tammax,teclapres) {
var tecla = teclapres.keyCode;
vr = campo.value;
vr = vr.replace( "/", "" );
vr = vr.replace( "/", "" );
vr = vr.replace( ",", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
tam = vr.length;

if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
if (tecla == 8 ){	tam = tam - 1 ; }
if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
if ( tam <= 2 ){ campo.value = vr ; }
if ( (tam > 2) && (tam <= 5) ){campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
if ( (tam >= 9) && (tam <= 11) ){campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
if ( (tam >= 12) && (tam <= 14) ){campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
if ( (tam >= 15) && (tam <= 17) ){campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' +
vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}
}

// callhotsite("[ZUNI_I24_AGENCIA_CLIENTE]", "[ZUNI_I24_CONTA_CLIENTE]", "[ZUNI_I24_NOME_GUERRA_CLIENTE]", "");
function callhotsite(agencia, conta, pseudo, page) {
	processMenu(document.forms['APPS_FORM_MAIN'], 'GROUP-ASSINATURA ELETRONICA', 'ZRPM', '');
/*	var strURL;
	var newwin;
	var strPage=page;
	var str = new RegExp("[&]","g");
	var strPseudo=pseudo.replace( str, "|" );
	if (strPage=="") strPage="verifpermag.asp";
	strURL = "https://ubb.unibanco.com.br/newhotsite/"+ strPage +"?Agencia="+agencia+"&Conta="+conta+"&Pseudo="+strPseudo;
	newwin=window.open("../../../blank.htm","","scrollbars");
	if(document.all) {
		newwin.moveTo(0,0);
		newwin.resizeTo(screen.width,screen.height);
	}
	newwin.location=strURL; */
}



// INICIO // funcoes para formartacao de valor
// <INPUT name="NomeDoCampo" maxlength="17" SIZE="17" onKeyDown="formatarOnKeyDown(this)" onKeyUp="formatarOnKeyUp(this)" onSelect="refreshCampo(this)"  Onkeypress="onlynum()">
function tirarZerosEsquerda(STR){

  var sAux='';
  var i=0;
  STR=new String(STR);

  while (i < STR.length ){
    if ((STR.charAt(i)!='.') && (STR.charAt(i)!=',')){
	  sAux += STR.charAt(i);
    }
	i++
  }


  STR = new String(sAux);
  sAux = '';
  i=0;

  while (i < STR.length ){
    if (STR.charAt(i) != '0'){
      sAux = STR.substring(i,STR.length)
	  i = STR.length;
	}
    i++;
  }

  return  sAux;
}


function formatarOnKeyUp(OBJ){
  var decimal,inteiro;
  var i,count;
  STR = new String(OBJ.value);
  STR = tirarZerosEsquerda(STR);
  inteiro='';
  if (isIE) {
		if (STR.length == 1){
			  inteiro  = '0';
			  decimal = '0' + STR;
			}
			else {
			  if (STR.length == 2){
				  inteiro  = '0';
				  decimal = STR;
				}
				else{
				  decimal = STR.substring(STR.length-2,STR.length);
				  i=3;
				  count=0;
				  while (i<=STR.length){
			 		if (count==3) {
					  inteiro = '.' + inteiro;
					  count = 0;
					}
				    inteiro = STR.charAt(STR.length-i) + inteiro;
					count++;
					i++;
				  }
				}
			}


		if (inteiro == '') {
		  inteiro = '0';
		}

		if (decimal == '') {
		  decimal = '00';
		}
		OBJ.value = inteiro+','+decimal;
  }
  else
  {

	if (navigator.appName=="Netscape")
	{
		var versao = navigator.userAgent;
		versao=versao.toString();
		menorVersao = versao.search("/6.0");
		if (menorVersao>-1)
		{
			var isNS6="sim";
		}
	}

	if(isNS6=="sim")
		OBJ.style.textAlign	= "left";


	if(STR=="")
		OBJ.value = "0,00";
	if((STR.length==1 || STR.length==2 || STR.length==3) && OBJ.value.substr(0,1)=='0')
		OBJ.value = OBJ.value.substr(1,OBJ.value.length-1);
	if((STR.length==2) && OBJ.value.substr(0,1)!='0')
		OBJ.value = "0," + OBJ.value;
	if((STR.length==1) && OBJ.value.substr(0,1)!='0')
		OBJ.value = "0,0" + OBJ.value;


	if(isNS6=="sim")
		OBJ.style.textAlign	= "right";

  }

}


function formatarOnKeyDown(OBJ,tammax,teclapres){
  var decimal,inteiro;
  var i,count;
  STR = new String(OBJ.value);

  inteiro='';

  if (isIE) {
	if (OBJ.maxLength > STR.length){
	  STR = tirarZerosEsquerda(STR); //ESTA FUNCAO TIRA TAMBEM PONTO E VIRGULA

	  if ( ((event.keyCode > 47) && (event.keyCode < 59)) || ((event.keyCode > 95) && (event.keyCode < 106))   ){

			if (STR.length == 0){
			  inteiro  = '0';
			  decimal = '0' + STR;
			}
			else {
			  if (STR.length == 1){
			    inteiro  = '0';
			    decimal = STR;
			  }
			  else{
			    decimal = STR.substring(STR.length-1,STR.length);
			    i=2;
			    count=0;
			    while (i<=STR.length){
			 		if (count==3) {
			  	  inteiro = '.' + inteiro;
			  	  count = 0;
			  	}
			      inteiro = STR.charAt(STR.length-i) + inteiro;
			  	count++;
			  	i++;
			    }
			  }
			}

	  }
	  else{
	    if (event.keyCode == 8){

	      if (STR.length == 0){
			  inteiro  = '0';
			  decimal = '000';
			}
			else {
			  if (STR.length == 1){
			    inteiro  = '0';
			    decimal = '00' + STR;
			  }
			  else {
			    if (STR.length == 2){
		          inteiro  = '0';
			      decimal = '0' + STR;
			     }
		         else{
	 			   decimal = STR.substring(STR.length-3,STR.length);
				   i=4;
				   count=0;
				   while (i<=STR.length){
			 		 if (count==3) {
					   inteiro = '.' + inteiro;
					   count = 0;
					  }
				      inteiro = STR.charAt(STR.length-i) + inteiro;
					  count++;
					  i++;
				    }
			     }
			  }
	      }
	    }
	    else {

	      if (STR.length == 1){
		 	  inteiro  = '0';
		      decimal = '0' + STR;
			}
			else {
			  if (STR.length == 2){
				  inteiro  = '0';
				  decimal = STR;
				}
				else{
				  decimal = STR.substring(STR.length-2,STR.length);
				  i=3;
				  count=0;
				  while (i<=STR.length){
			 		if (count==3) {
					  inteiro = '.' + inteiro;
					  count = 0;
					}
				    inteiro = STR.charAt(STR.length-i) + inteiro;
					count++;
					i++;
				  }
				}
			}
	    }
	  }

	  if (inteiro == '') {
	    inteiro = '0';
	  }

	  if (decimal == '') {
	    decimal = '00';
	  }
	  OBJ.value = inteiro+','+decimal;
	}
  }
  else
  {
	var tecla = teclapres.keyCode;
	valorSemFormato = OBJ.value;
	valorSemFormato = valorSemFormato.replace( ",", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	tamanho = valorSemFormato.length;

	if (tecla == 46) {
	     OBJ.value = OBJ.value;

	}if (tamanho < tammax && tecla != 8) {
	    tamanho = valorSemFormato.length + 1;

	}if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
	     if (tecla == 8) {
	         tamanho = tamanho - 1;
	     }

	     if (tamanho <= 2) {
	 		 OBJ.value = valorSemFormato;

	 	 }else if ((tamanho > 2) && (tamanho <= 5)) {
	 		 OBJ.value = valorSemFormato.substr(0, tamanho - 2) + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);

	 	 }else if ((tamanho >= 6) && (tamanho <= 8)) {
	 	 	 OBJ.value = valorSemFormato.substr(0, tamanho - 5) + '.' +
	 	 	               valorSemFormato.substr(tamanho - 5, 3) + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);

	 	 }else if ((tamanho >= 9) && (tamanho <= 11)) {
	 		 OBJ.value = valorSemFormato.substr(0, tamanho - 8) + '.' +
	 		               valorSemFormato.substr(tamanho - 8, 3) + '.' +
	 		               valorSemFormato.substr(tamanho - 5, 3) + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);

	 	 }else if ((tamanho >= 12) && (tamanho <= 14)) {
	 	 	 OBJ.value = valorSemFormato.substr(0, tamanho - 11) + '.' +
	 		               valorSemFormato.substr(tamanho - 11, 3) + '.' +
	 		               valorSemFormato.substr(tamanho - 8, 3)  + '.' +
	 		               valorSemFormato.substr(tamanho - 5, 3)  + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);

	 	 }else if ((tamanho >= 15) && (tamanho <= 17)) {
	 	 	 OBJ.value = valorSemFormato.substr(0, tamanho - 14) + '.' +
	 		               valorSemFormato.substr(tamanho - 14, 3) + '.' +
	 		               valorSemFormato.substr(tamanho - 11, 3) + '.' +
	 		               valorSemFormato.substr(tamanho - 8, 3)  + '.' +
	 		               valorSemFormato.substr(tamanho - 5, 3)  + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);
	    }
	}
  }
}

function refreshCampo(obj){
	if (isIE) {
		obj.value = obj.value;
	}
}

//  FIM   // funcoes para formartacao de valor

function div(dividendo,divisor){
  return (dividendo-(dividendo % divisor))/divisor;
}

function AbrirRegrasAgendamento(){
  var leftPos,topPos, W, H;
  W = 320;
  H = 420;
  //leftPos = div( screen.width - W , 2 );
  //topPos  = div( screen.height - H , 2 );
  leftPos = 115;
  topPos  = 70;
  window.open("/Documentos/ajudaagenda.htm","","width="+W+",height="+H+",left="+leftPos+",top="+topPos)
}

/*------------------------------------------------------------------
 callemailunibanco
 Descricao: Redireciona o usuario para o site de atualiza‡Æo de email
 Parametros: Agencia, Conta, DigitodaConta, NSUSessao
 Retorno: Naum retorna nada
 callemailunibanco(ag, ct, dg, nsu)
 callemailunibanco(ag, ct, dg, '') NSU Vazio redireciona para o login do site email com Ag, Ct, Dg preenchidos
 callemailunibanco('', '', '', nsu) Ag, Ct, Dg vazios redireciona para o interior do site baseado no NSU
 callemailunibanco('', '', '', '') Tudo Vazio redireciona para o login do site sem nada preenchido
------------------------------------------------------------------*/
function callemailunibanco(ag, ct, dg, nsu)
{
	// Endere‡o alterado a Pedido de Patricia Gadotti para realizar os testes em desenv.
	// De investcenter.unibanco.com.br Para 200.246.185.198
	var newwin;
	if(nsu == '' && ag != '' && ct != '' && dg != '')
	{
		newwin = window.open('https://200.246.185.198/informacoesporemail/login.asp?ag=' + ag + '&ct=' + ct + '&dg=' + dg, '' , 'top=0, left=0, scrollbars, copyhistory=no, location=yes, menubar=yes, toolbar=yes, resizable=yes, height=' + screen.height + ', width=' + screen.width + ', top=0, left=0');
	}
	else if(nsu != '')
	{
		newwin = window.open('https://200.246.185.198/informacoesporemail/MailingConsultaCliente.asp?NSU=' + nsu, '' , 'top=0, left=0, scrollbars, copyhistory=no, location=yes, menubar=yes, toolbar=yes, resizable=yes, height=' + screen.height + ', width=' + screen.width);
		//newwin = window.open('https://investcenter.unibanco.com.br/informacoesporemail/MailingConsultaCliente.asp?NSU=' + nsu, '' , 'top=0, left=0, scrollbars, copyhistory=no, location=yes, menubar=yes, toolbar=yes, resizable=yes, height=' + screen.height + ', width=' + screen.width);
	}
	else
	{
		newwin = window.open('https://200.246.185.198/informacoesporemail/login.asp', '' , 'top=0, left=0, scrollbars, copyhistory=no, location=yes, menubar=yes, toolbar=yes, resizable=yes, height=' + screen.height + ', width=' + screen.width);
	}
	newwin.focus();
}

/*------------------------------------------------------------------
 Fal   Castanho
 Descricao: Abre uma novas instancia do Browser com a pagina de Telefones
 Parametros: Nenhum
 Retorno: Naum retorna nada
-------------------------------------------------------------------*/
function Fal(){
  var leftPos,topPos, W, H;
  W = 800;
  H = 420;
  leftPos = 0;
  topPos  = 0;
  window.open("http://galeriadeinvestimentos.unibanco.com.br/sou/pef/fal/faq/index.asp","","toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width="+W+",height="+H+",left="+leftPos+",top="+topPos)
}

/*------------------------------------------------------------------
 MostrarTelefone30Horas
 Descricao: Abre uma novas instancia do Browser com a pagina de Telefones
 Parametros: Nenhum
 Retorno: Naum retorna nada
-------------------------------------------------------------------*/
function MostrarTelefone30Horas(){
  var leftPos,topPos, W, H;
  W = 800;
  H = 420;
  leftPos = 115;
  topPos  = 70;
  window.open("http://www.unibanco.com.br/index.asp?redir=fconosco/telefone.asp","","toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width="+W+",height="+H+",left="+leftPos+",top="+topPos)
}

// funcoes retiradas dos templates do EWF

	function FinalizaSessao(obj){
		
			if (navigator.appName=="Netscape") {
			document.APPS_FORM_GROUP.BUTTON.name="EWF_BUTTON_Logoff";
			document.APPS_FORM_GROUP.BUTTON.value="EWF_BUTTON_Logoff";
			document.APPS_FORM_GROUP.submit();
			alert("Você está saindo do ambiente seguro.\nObrigado por utilizar o Internet 30 Horas.");
			window.location.href = obj.href;
		} 
	}

	function rollOver(GroupID, Image) {
		var imageLocation = Image;
		var imageName = imageLocation.substring(0, imageLocation.length - 4);
		var newImage = imageName + "_o.gif";
		if (document.images) document.images[GroupID].src=newImage;
	}

	function rollOut(GroupID, Image) {
		var newImage = Image;
		if (document.images) document.images[GroupID].src=newImage;
	}

	function spawnHelpWindow(fileName,frameName) {
		window.open (fileName, frameName, "scrollbars=yes,menubar=no,resizable=1,copyhistory=1,width=550,height=450");
	}

// fim - funcoes retiradas dos templates do EWF



// onFocus=UpCursor(this, indice_caixa_texto, maxLength)
function UpCursor(ctrl, indice, max) {
		ctrl.tam=max;
		ctrl.saltar=false;
		ctrl.indice=indice;
		ctrl.onkeyup=AlteraFoco;
}
function AlteraFoco() {
	this.saltar=(this.value.length==this.tam);
	if (this.saltar==true) {
		indice=this.indice;
		document.forms[this.form.name].elements[indice].focus();
	}
	return true;
}

// Bloquear caracteres nao numericos - onKeyPress=onlynum()
function onlynum(e) {
	var keyNumber = (isIE) ? event.keyCode : e.which;
	if (((keyNumber<48)||(keyNumber>57)) && (keyNumber!=13) && (keyNumber!="0") && (keyNumber!=8)) {
		if (isIE) event.keyCode=0;
		return false;
	}
}

function formatarvalor(STR){
  var decimal,inteiro;
  var i,count;
  STR = new String(STR);
  STR = tirarZerosEsquerda(STR);
  inteiro='';
  if (STR.length == 1){
	  inteiro  = '0';
	  decimal = '0' + STR;
	}
	else {
	  if (STR.length == 2){
		  inteiro  = '0';
		  decimal = STR;
		}
		else{
		  decimal = STR.substring(STR.length-2,STR.length);
		  i=3;
		  count=0;
		  while (i<=STR.length){
		 		if (count==3) {
				  inteiro = '.' + inteiro;
				  count = 0;
				}
		    inteiro = STR.charAt(STR.length-i) + inteiro;
				count++;
				i++;
		  }
		}
	}
  if (inteiro == '') {
    inteiro = '0';
  }
  if (decimal == '') {
    decimal = '00';
  }
  return inteiro+','+decimal;
}

// ******** Extraida da bankmain.asp
	function ValidaConta(AgCta) {
		var parte1, parcial, soma, Dv, cont;
		soma=0;
		dv=0;
		cont = new CriaArray(10);
		cont[0]=1;cont[1]=2;cont[2]=1;cont[3]=2;cont[4]=1;cont[5]=2;cont[6]=1;cont[7]=2;cont[8]=1;cont[9]=2;

		varasc = new CriaArray(10);
		varasc[0]=48;varasc[1]=49;varasc[2]=50;varasc[3]=51;varasc[4]=52;varasc[5]=53;varasc[6]=54;varasc[7]=55;varasc[8]=56;varasc[9]=57;

		for(var i=0;i<=9;i++){
			parcial = (varasc[parseInt(AgCta.substr(i,1))]-48) * cont[i];
			parte1 = String(parcial/10);
			if (parte1.substr(0,1)=="."){
				parte1 = 0;
			}
			parte1 = parseInt(parte1);
			soma = soma + (parcial - (parte1 * 10)) + (parte1);
		}
		soma = soma * 9;
		parte1 = String(soma/10);
		if (parte1.substr(0,1)=="."){
			parte1 = 0;
		}
		parte1 = parseInt(parte1);
		Dv = (soma - (parte1 * 10)) + 48;
		if (Dv != varasc[AgCta.substr(10,1)])
			return false;
		else
			return true;
	}
	//CRIA ARRAY
	function CriaArray(n){
		var i,n;
		this.length = n;
		for (i = 1; i <=n; i++) {
			this[i] = 0;
		}
		return this;
	}


// *********************** Inicio Novas Funçoes *******************************
/*------------------------------------------------------------------
 VerificaValor
 Descricao: Efetua a validação de campos tipo valor (money,currency)
 Parametros: Numero
						 bVerPonto
 Retorno: boolean, sendo true se valor Ok
-------------------------------------------------------------------*/
function VerificaValor(Numero, bVerPonto)
{
	var i;
	var iQtdCharAux1 = Numero.length-1;
	var sAux         = ReplaceString(Numero, ",", "");
	var sAux1        = ReplaceListChar(Numero, ",.", "");
	var bPonto;

	bPonto = (bVerPonto.toUpperCase()=="TRUE") ? true : false;

	if (bPonto)
	{
		if (Numero.charAt(Numero.length-3) != ",")
			return false;
		if (sAux.length != Numero.length-1)
			return false;
		if (!IsNumber(sAux1))
			return false;
		if(Numero.length > 6)
		{
			i = Numero.length - 7;
			while(i >= 0)
			{
				if(Numero.charAt(i) != "." || i==0)
					return (false);
				iQtdCharAux1 = iQtdCharAux1 - 1;
				i = i - 4;
			}
		}
		else if (sAux1.length != iQtdCharAux1)
				return false;
	}
	else
	{
		if(Numero.charAt(Numero.length-3) != ",")
			return false;
		if (sAux.length != Numero.length-1)
			return false;
		if (!IsNumber(sAux))
			return false;
	}
	return true;
}

/*----------------------------------------------------------------------
 ReplaceString
 Descricao: Procura e substitui um caracter ou uma string dentro de
						uma outra string
 Parametros: sIn - string de entrada
						 sFind - string a ser procurada
						 sReplace - string a ser substituida
 Retorno: String substituida.
-----------------------------------------------------------------------*/
function ReplaceString(sIn, sFind, sReplace) {
	var converted="";
	var expr1;
	var sResult=sIn;
	for (i=0;i<sFind.length;i++) {
		converted = converted+"\\x"+hexConvert(sFind.charCodeAt(i));
	}
	expr1=new RegExp(converted,"g");
	sResult=sResult.replace(expr1,sReplace);

	return sResult;
}

/*----------------------------------------------------------------------
 ReplaceListChar
 Descricao: Procura e substitui um caracter ou uma lista de caracteres
						dentro de uma outra string
 Parametros: sIn - string de entrada
						 sFind - Lista de caracteres a serem substiutidos
						 sReplace - caracter ou string a ser substituida
 Retorno: String substituida.
-----------------------------------------------------------------------*/
function ReplaceListChar(sIn, sFind, sReplace) {
	var converted="";
	var expr1;
	var sResult=sIn;
	for (i=0;i<sFind.length;i++) {
		converted = "\\x"+hexConvert(sFind.charCodeAt(i));
		expr1=new RegExp(converted,"g");
		sResult=sResult.replace(expr1,sReplace);
	}
	return sResult;
}

/*----------------------------------------------------------------------
 hexConvert
 Descricao: Converte um numero de decimal para hexadecimal
						(utilizada pela funçao ReplaceString e ReplaceListChar)
 Parametros: convert - numero no formato decimal
 Retorno: numero no formato decimal
-----------------------------------------------------------------------*/
function hexConvert(convert) {
	var hexa;
	var firstnum;
	var lastnum;
	b = Math.floor (convert / 16);
	c = convert; c %= 16
	charx = '0123456789ABCDEF';
	firstnum = charx.substring(b,b+1);
	lastnum = charx.substring(c,c+1);
	hexa = firstnum + lastnum;
	return hexa;
}


/*-----------------------------------------------------------------*
  IsNumber
  Descricao   : Verifica se e um numero
  Parametros  : string contendo apenas numeros
  Retorno			: boolean - true ou false
 -----------------------------------------------------------------*/
function IsNumber(Numero) {
	return (Numero.search(/\D/)==-1) ? true : false;
}


function valData(campo){
	
	if (campo == "form1.dtNasc"){
		objData = form1.dtNasc
	}
	else if(campo == "form2.dataini"){
			objData = form2.dataini
	}
	else if(campo == "form2.datafim"){
			objData = form2.datafim
	}
	else if(campo == "form2.inicio"){
			objData = form2.inicio
	}
	else if(campo == "form2.fim"){
			objData = form2.fim
	}
	else{
		objData = form2.dtNasc
	}
	
	
	
	valorData = objData.value;
	arrData = valorData.split('/');
	
  if(objData.value.length > 0) {
	if (arrData.length != 3){
		alert("A data possui erros, o formato aceitado é : dd/mm/yyyy ex:31/12/1980 !"); objData.focus(); return false
	} else {
		if (arrData[0].length < 2){ arrData[0] = "0" + arrData[0] }
		valor = /[^0-9]/.exec(arrData[0]);
		if ((arrData[0] > 31) || (arrData[0] == 0) || (arrData[0].length > 2) || (valor != null)){
			alert("O dia da data esta errado!"); objData.focus(); return false
		}
		if (arrData[1].length < 2){ arrData[1] = "0" + arrData[1] }
		valor = /[^0-9]/.exec(arrData[1]);
		if ((arrData[1] > 12) || (arrData[1] == 0) || (arrData[1].length > 2) || (valor != null)){
			alert("O mes da data esta errado!"); objData.focus(); return false
		}
		valor = /[^0-9]/.exec(arrData[2]);
		if ((arrData[2] < 1900) || (arrData[2].length > 4) || (valor != null)){
			alert("O ano da data esta errado!"); objData.focus(); return false
		}
	}
	if (valorData == ""){
		alert("O campo data esta vazio!"); objData.focus(); return false	
	}
	
	objData.value = arrData[0] +"/"+ arrData[1] +"/"+ arrData[2];
	return true
 }
} // end valData


function validaCPF() {
                 cpf = document.form1.cpfCand.value;
                 erro = new String;
                 if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
                 var nonNumbers = /\D/;
                 if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n"; 
                 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
                         erro += "Numero de CPF invalido!"
               }
               var a = [];
               var b = new Number;
               var c = 11;
               for (i=0; i<11; i++){
                       a[i] = cpf.charAt(i);
                      if (i < 9) b += (a[i] * --c);
              }
               if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
              b = 0;
              c = 11;
               for (y=0; y<10; y++) b += (a[y] * c--); 
              if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
               if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
                       erro +="Digito verificador com problema!";
              }
               if (erro.length > 0){
                      alert(erro);
                      return false;
               }
              return true;
      }

function validaCPF2() {
                 cpf = document.form2.cpfCand.value;
                 erro = new String;
                 if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
                 var nonNumbers = /\D/;
                 if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n"; 
                 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
                         erro += "Numero de CPF invalido!"
               }
               var a = [];
               var b = new Number;
               var c = 11;
               for (i=0; i<11; i++){
                       a[i] = cpf.charAt(i);
                      if (i < 9) b += (a[i] * --c);
              }
               if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
              b = 0;
              c = 11;
               for (y=0; y<10; y++) b += (a[y] * c--); 
              if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
               if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
                       erro +="Digito verificador com problema!";
              }
               if (erro.length > 0){
                      alert(erro);
                      return false;
               }
              return true;
      }



function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Email Inválido")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Email Inválido")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Email Inválido")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Email Inválido")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Email Inválido")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Email Inválido")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Email Inválido")
		    return false
		 }

 		 return true					
	}

