﻿// JScript File
// JavaScript Document

<!--
function AbreCupom(arquivo,nome,atrib) {
	window.open(arquivo,nome,atrib);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function Dcode(path, width, height, opacity) {
  document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='"+width+"' height='"+height+"'>");
  document.write("<param name='movie' value='"+path+"'>");
  document.write("<param name='quality' value='high'>");
  if(opacity == "yes"){
    document.write("<param name='wmode' value='transparent'>");
  }else{
    document.write("<param name='BGCOLOR' value='#ffffff'>");
  }
  document.write("<embed src='"+path+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'"); 
  if(opacity == "yes"){
    document.write(" wmode='transparent'");
  }else{
    document.write(" bgcolor='#ffffff' ");
  }
  document.write("width='"+width+"' height='"+height+"'></embed>");
  document.write("</object>");
}

function getBrowser() {
	this.Name = navigator.appName
}

function getJanela() {
	
	//alert("window.screen.width="+window.screen.width+"  window.screen.height="+window.screen.height)
	if ((window.screen.width==1280)&&(window.screen.height==1024)) {
		this.width=10;
		this.height=10;
		this.x=250;
		this.y=250;
	}
	
	else if ((window.screen.width==1024)&&(window.screen.height==768)) {
		this.width=10;
		this.height=10;
		this.x=250;
		this.y=250;
	} 
	
	else if ((window.screen.width==800)&&(window.screen.height==600)) {
		this.width=10;
		this.height=10;
		this.x=200;
		this.y=200;
	}
	
	else if ((window.screen.width==640)&&(window.screen.height==480)) {
		this.width=40;
		this.height=40;
		this.x=200;
		this.y=200;
	}
	
}

function AbreJanela(pagina) {

		Janela = window.open(pagina,"Janela","width="+objJanela.width+" ,height="+objJanela.height+" ,top="+objJanela.x+",left="+objJanela.y+" ,toolbar=no,menubar=no,resisable=no, scrollbars=no,status=no");
		Janela.focus();

}

function clock() {

    if ((Janela != undefined)) {
        alert("0Janela="+Janela);
        var repetidor = setInterval('ResizeJanela', 10000)
        alert("1");	    
	}
	//return false;
}

function ResizeJanela() {
            
    //alert("2");
	//alert("objeto="+parseInt(Janela.document.getElementById("tableCupom").clientWidth)+"objeto="+parseInt(Janela.document.getElementById("tableCupom").clientHeight))	
	var Browser = new getBrowser();
    		
	objJanela.width = parseInt(Janela.document.getElementById("imgCupom").clientWidth+10);
	if (Browser.Name != "Netscape") {
	    objJanela.height = parseInt(Janela.document.getElementById("imgCupom").clientHeight+170);
        //aumentado o tamanho de 30 para 50 por causa do botão Fechar no bottom da janela.
    }
	else {
	    objJanela.height = parseInt(Janela.document.getElementById("imgCupom").clientHeight+170);
	    //aumentado o tamanho de 50 para 70 por causa do botão Fechar no bottom da janela.
    }
    objJanela.x = (window.screen.height - objJanela.height)/2
    objJanela.y = (window.screen.width - objJanela.width)/2

    Janela.moveTo(objJanela.y,objJanela.x);
    Janela.resizeTo(objJanela.width,objJanela.height);	
    Janela.focus();
    //alert("3");
    //this.clearInterval(repetidor);
    //alert("4");
}

function ExibeBanner() {
if (screen.width != 800) {
	document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='200' height='445'>");
	document.write("<param name='movie' value='swf/contagem_unibanco2.swf?ano=2007&mes=7&dia=16&hora=23&minuto=59&segundo=59&clicktag=http://www.universodevantagens.com.br/promocao.aspx'>");
	document.write("<param name='quality' value='high'>");
	document.write("<param name='wmode' value='transparent'>");
	document.write("<embed src='swf/contagem_unibanco2.swf?ano=2007&mes=7&dia=16&hora=23&minuto=59&segundo=59&clicktag=http://www.universodevantagens.com.br/promocao.aspx' quality='high' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='200' height='445'></embed>");
    document.write("</object>"); }
}

//-->

function MascCpf()
{
	var valor;
	
	valor = event.srcElement.value;
	
	// Numerico
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
	     (event.keyCode != '8') ) 
	{
		event.returnValue=false;
	}
	else
	{
		if ( ( (valor.length + 1) == 3 ) ||
			 ( (valor.length + 1) == 7 ) ) 
		{
			event.srcElement.value += String.fromCharCode(event.keyCode) + '.';
			event.returnValue=false;
		}
		else
		{
			if ( ( (valor.length + 1) == 11 ) ) 
			{
				event.srcElement.value += String.fromCharCode(event.keyCode) + '-';
				event.returnValue=false;
			}
		}
	}
}

function MascTel()
{
	var valor;
	
	valor = event.srcElement.value;
	
	// Numerico
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
	     (event.keyCode != '8') ) 
	{
		event.returnValue=false;
	}
	
}

function MascCgc()
{
	var valor;
	
	valor = event.srcElement.value;
	
	// Numerico
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
	     (event.keyCode != '8') ) 
	{
		event.returnValue=false;
	}
	else
	{
		if ( ( (valor.length + 1) == 2 ) ||
			 ( (valor.length + 1) == 6 ) ) 
		{
			event.srcElement.value += String.fromCharCode(event.keyCode) + '.';
			event.returnValue=false;
		}
		else
		{
			if ( ( (valor.length + 1) == 10 ) ) 
			{
				event.srcElement.value += String.fromCharCode(event.keyCode) + '/';
				event.returnValue=false;
			}
			else
			{
				if ( ( (valor.length + 1) == 15 ) ) 
				{
					event.srcElement.value += String.fromCharCode(event.keyCode) + '-';
					event.returnValue=false;
				}
			}
		}
	}
}

function MascNum()
{
    var conteudo;
	conteudo = event.srcElement.value;
	
	// Procura se o usuario já digitou uma virgula, 
	// caso positivo entao rejeita.
//	alert(conteudo);
	if ( (event.keyCode == '44' && conteudo.indexOf(",") > 0 ) || 
		 (event.keyCode == '44' && conteudo == ",") )
		event.returnValue=false;
	    
	if ( (event.keyCode < '48' || event.keyCode > '57') &&
	     (event.keyCode != '44') &&
	     (event.keyCode != '8') ) 
		event.returnValue=false;

//alert(event.keyCode );
	if ( event.keyCode == '44' && conteudo.length == 0 )
	{
		event.srcElement.value = "0";
	}
	    
	return;
}

function formataNumero(objetoTxt,numCasasDec,usaMascara) 
{
  //     Cadu - 01/07/2005
  //      esta função formata um campo numérico, podendo ou não conter casas decimais
  //      propriedades da caixa de texto para uso desta funcao :
  //
  //     ex.: onkeydown="formataNumero(this,2)" value='0,00' style='text-align: right;' maxlength='10'
  //     ex.: onkeydown="formataNumero(this,3)" value='0,000' style='text-align: right;' maxlength='10'
  //     ex.: onkeydown="formataNumero(this,0)" value='0' style='text-align: right;' maxlength='10'
  //     ex.: onkeydown="formataNumero(this,0)" value='' style='text-align: right;' maxlength='10' porem se o 
  //                                                                                               usuario preencher
  //                                                                                               e apagar,
  //                                                                                               ficara com 0.      
  //        
  //    OBS:  Caso o valor venha do asp, precisa vir formatado conforme a mascara. Ex.:(#.###.###.###,##)
  //    OBS2: o Maxlength é tratado aqui e não conta com '.', mas conta com a ','
  //    OBS3: Para remover os pontos da parte inteira, em javascript "string = string.replace(/\./g,'');"   
  //    OBS4: usaMascara é opcional, se colocar 'N', ele permite apagar a mascara 0,00
  var fracionario;
  var inteiro;
  var separadorDec;
  var funcao;
  var excluir;
  var novoValor;
  var ponto;
  if ( (objetoTxt.keyCode < '48' || objetoTxt.keyCode > '57') &&(e.keyCode != '8') ) 
  {
		event.returnValue=false;
    	return false;
  }	
  if (usaMascara == '')
  {
    usaMascara = 'S';
  }
  
  //define o separador utilizado, ou nenhum se casas decimais = 0
  if (numCasasDec == 0)
    separadorDec='';
  else
    separadorDec=',';  
  
  if (event.keyCode >= '96' && event.keyCode <= '105') //teclado Numerico
    event.keyCode = event.keyCode - 48;  //converte para numero padrao
    

  // trata diferente de numeros  
  if ( (event.keyCode < '48' || event.keyCode > '57') && (event.keyCode != '8') && (event.keyCode != '46') )  
  {
    event.returnValue=false;
    return;
  }  

  //trata delete e backspace 
  if ((event.keyCode == '8' || event.keyCode == '46'))       
    excluir = 1;
  else
    excluir = 0;    
  
  novoValor = objetoTxt.value;
  
  if (excluir == 0)
  {
    //trata maxLength
    if ((objetoTxt.maxLength) && (objetoTxt.maxLength <= novoValor.replace(/\./g,'').length) && (novoValor.substr(0,1)!='0'))
      return; 

    //inclui valor
    novoValor = novoValor + (event.keyCode - 48);
  }
  
  //monta novo valor
  novoValor = novoValor.replace(separadorDec,'');
  if (numCasasDec == 0) // se o numero é inteiro
  {
    fracionario = '';      
    inteiro     = novoValor.substr(0,(novoValor.length)-excluir);
  }
  else
  {
    fracionario     = novoValor.substr((novoValor.length)-(numCasasDec)-excluir,numCasasDec);
    inteiro         = novoValor.substr(0,(novoValor.length)-(numCasasDec)-excluir);
  }  
  if (!inteiro)
    temp=0; //parte inteira temporaria
  else
  {
    inteiro = inteiro.replace(/\./g,'');  
    if (parseFloat(inteiro) <= 999)
      temp = parseFloat(inteiro);
    else
    {
      temp = '';
      ponto = '';
      while (inteiro.length > 0)
      {
        if (inteiro.length >=3)
        {
          temp = inteiro.substr((inteiro.length-3),3) + ponto + temp;
          inteiro = inteiro.substr(0,(inteiro.length-3));
          ponto = '.';
        }
        else
        {
          temp = inteiro + '.' + temp;
          inteiro = '';
        }      
      } 
    }
  }
  valor = temp + separadorDec + fracionario; 
  
  temp = valor.replace(/\./g,'');
  temp = temp.replace(/\,/g,'.');
  if ((usaMascara == "N") && (parseFloat(temp) == 0) && (excluir == 1)) 
  {
    valor = '';
  }    
  objetoTxt.value = valor;

  event.returnValue=false;
  return;     
}

function FormataValor(id,tammax,teclapres) {

if(window.event) { // Internet Explorer
var tecla = teclapres.keyCode;
var nova = window.event; }
else if(teclapres.which) { // Nestcape / firefox
var tecla = teclapres.which;
var nova = teclapres.which;
}

if ( (tecla < '48' || tecla > '57') && (tecla != '8') && (tecla != '46') )  
  {
    nova.returnValue = false; 
    
    return;
  }  
        vr = document.getElementById(id).value;
        vr = vr.toString().replace( "/", "" );
        vr = vr.toString().replace( "/", "" );
        vr = vr.toString().replace( ",", "" );
        vr = vr.toString().replace( ".", "" );
        vr = vr.toString().replace( ".", "" );
        vr = vr.toString().replace( ".", "" );
        vr = vr.toString().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 ){
        document.getElementById(id).value = vr; }
        if ( (tam > 2) && (tam <= 5) ){
        document.getElementById(id).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
        if ( (tam >= 6) && (tam <= 8) ){
        document.getElementById(id).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
        if ( (tam >= 9) && (tam <= 11) ){
        document.getElementById(id).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) ){
        document.getElementById(id).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) ){
        document.getElementById(id).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 );}
        }
        }

    
 
