﻿function AbreDetalheMega20(gid)
{
    var link = 'megasena20_escolha.aspx?codigoRef=' + gid;
    var janela = window.open(link, 'detalheGrupoMega20', 'menubar=yes, location=yes, width=760, height=660, status=no,scrollbars=yes,scrolling=yes');
}

function AbreDetalheMega20_Resultado(gid)
{
    var link = '../megasena20/megasena20_Resultado.aspx?codigoRef=' + gid;
    var janela = window.open(link, 'detalheGrupoMega20', 'menubar=yes, location=yes, width=850, height=660, status=no,scrollbars=yes,scrolling=yes');
}


// JScript File
function OpenPrintFormat()
{
    var link = 'ConfirmaPrint.aspx';
    var janela = window.open(link, 'ConfirmaPrint', 'scrollbars=yes, menubar=yes, resizable=yes, scrollbars=yes,location=no, width=640, height=480, status=no');
}

// JScript File
function AbreDetalheJogo(sec, gid)
{
    var link = 'PopupLstJogo.aspx?sec=' + sec + '&gid=' + gid;
    var janela = window.open(link, 'detalheGrupo', 'menubar=yes, location=yes, width=640, height=480, status=no,scrollbars=yes,scrolling=yes');
}
function AbreDetalheTime(sec, gid)
{
    var link = 'PopupLstLoteca.aspx?sec=' + sec + '&gid=' + gid;
    var janela = window.open(link, 'detalheGrupo', 'scrollbars=yes, menubar=yes, location=no, width=640, height=600, status=no');
}

// JScript File
function AbreDetalheJogoInt(sec, gid)
{
    var link = '../PopupLstJogo.aspx?sec=' + sec + '&gid=' + gid;
    var janela = window.open(link, 'detalheGrupo', 'menubar=yes, location=no, width=640, height=480, status=no,scrollbars=yes,scrolling=yes');
}

// JScript File
function AbreDetalheJogoInt_MinhasApostas(sec, gid)
{
    var link = '../PopupLstJogo.aspx?sec=' + sec + '&gid=' + gid + '&minhasapostas=true';
    var janela = window.open(link, 'detalheGrupo', 'menubar=yes, location=no, width=640, height=480, status=no,scrollbars=yes,scrolling=yes');
}

// JScript File
function AbreDetalheEsnInt(sec, item)
{
    var link = '../PopupLstEsn.aspx?sec=' + sec + '&item=' + item;
    var janela = window.open(link, 'detalheGrupo', 'menubar=yes, location=no, width=640, height=480, status=no');
}

function AbreDetalheTimeInt(sec, gid)
{
    var link = '../PopupLstLoteca.aspx?sec=' + sec + '&gid=' + gid;
    var janela = window.open(link, 'detalheGrupo', 'scrollbars=yes, menubar=yes, location=no, width=640, height=600, status=no');
}

// JScript File
function AbreDetalheJogoConf(sec, gid)
{
    var link = '../../PopupLstJogo.aspx?sec=' + sec + '&gid=' + gid;
    var janela = window.open(link, 'detalheGrupo', 'menubar=yes, location=no, width=640, height=480, status=no,scrollbars=yes,scrolling=yes');
}
function AbreDetalheTimeConf(sec, gid)
{
    var link = '../../PopupLstLoteca.aspx?sec=' + sec + '&gid=' + gid;
    var janela = window.open(link, 'detalheGrupo', 'scrollbars=yes, menubar=yes, location=no, width=640, height=600, status=no');
}

function AbreConcedeBonus(url)
{
    var janela = window.open(url, 'ConcederPedido', 'scrollbars=yes, menubar=yes, location=no, width=480, height=350, status=no');
}

function AbreBoleto()
{
    var url = 'PaymentBridgePost.aspx';
    var janela = window.open(url, 'Boleto', 'scrollbars=yes, location=no, width=640, height=480, status=no');
}

function AbreBoletoReemissao(compra_id)
{
    var url = '../Basket/Payment/PaymentBridgePost.aspx?reemitir_boleto=true&compra_id='+compra_id;
    var janela = window.open(url, 'Boleto', 'scrollbars=yes, location=no, width=640, height=480, status=no');
}

// JScript File
function AbreDetalheUsuarioCompra(cliente_id)
{
    var link = '../Misc/lstCadastroDetalheUsuarioCompra.aspx?cliente_id=' + cliente_id;
    var janela = window.open(link, 'detalheUsuarioCompra', 'menubar=yes, location=no, width=700, height=480, status=no,scrollbars=yes,scrolling=yes');
}

function RefreshPage()
{
    window.opener.location.replace(window.opener.location);
    self.close();
}

function AbreSiteBanco(objID)
{
    var objUrl = document.getElementById(objID);
    //alert(objUrl);
    var janela = window.open('http://' + objUrl.value.replace('http://','').replace('https://',''), 'Banco', '');
}
/* ------------------------------------------------------------- */

// Seta cookies
function setCookie(c_name,value,expiredays)
{
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/aapf/";
}	

// Recupera cookies
function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=")
	  if (c_start!=-1)
	    { 
	    c_start=c_start + c_name.length+1 
	    c_end=document.cookie.indexOf(";",c_start)
	    if (c_end==-1) c_end=document.cookie.length
	    return unescape(document.cookie.substring(c_start,c_end))
	    } 
	  }
	return ""
}	

// Formata o campo CEP
function formataCEP(campo){
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;

	if ( tam <= 3 )
		campo.value = vr;
	if ( tam > 3 ) 
		campo.value = vr.substr(0, tam-3 ) + '-' + vr.substr(tam-3, tam);
}

// Formata data no padr?o DDMMAAAA
function formataData(campo){
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;

	if ( tam > 2 && tam < 5 )
		campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
	if ( tam >= 5 && tam <= 10 )
		campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 

}

// Formata hora no padrao HH:MM
function formataHora(campo,teclapres) {
	var tecla = teclapres.keyCode;
	campo.value = filtraCampo(campo);
	vr = campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			campo.value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam );
	}
}

// Formata o campo valor
function formataValor(campo) {
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;

	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 <= 18) ){
 		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 ) ;}
 		
}


// Formata o campo valor
function formataNumerico(campo) {

	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;
}

// limpa todos os caracteres especiais do campo solicitado
function filtraCampo(campo){
	var s = "";
	var cp = "";
	vr = campo.value;
	tam = vr.length;
	for (i = 0; i < tam ; i++) {  
		if (vr.substring(i,i + 1) != "/" && vr.substring(i,i + 1) != "-" && vr.substring(i,i + 1) != "."  && vr.substring(i,i + 1) != "," ){
		 	s = s + vr.substring(i,i + 1);}
	}
	
	s = s.replace(/\D/g,"");
	
	campo.value = s;
	
	return cp = campo.value
}
		
function getTeclaPressionada(evt)
{
	if(typeof(evt)=='undefined')
		evt = window.event;
	return(evt.keyCode ? evt.keyCode : (evt.which ? evt.which : evt.charCode));
}

// teclas 63230 a 63240 = safari
function isTeclaEspecial(key)
{
	return key<32||(key>=35&&key<=36)||(key>=37&&key<=40)||key==46||(key>=63230&&key<=63240);
}

function isTeclaRelevante(key)
{
	return (key == 8)||(key == 46)||(key == 88)||(key>=48&&key<=57)||(key>=96&&key<=105);
}

function isCaracterRelevante(key)
{
	return (key == 88)||(key == 120)||(key>=48&&key<=57);
}

function isCopiaCola(ctrlKey, key)
{
	return ctrlKey && (key == 118 || key == 86 || key == 99 || key == 67);
}


function filtraTeclas(evt)
{
	var key = getTeclaPressionada(evt);
	if(isTeclaEspecial(key) || isTeclaRelevante(key) || isCopiaCola(evt.ctrlKey, key))
		return true;
	StopEvent(evt);
	return false;
}

function filtraCaracteres(evt)
{
	var key = getTeclaPressionada(evt);
	if(isTeclaEspecial(key) || isCaracterRelevante(key) || isCopiaCola(evt.ctrlKey, key))
		return true;
	StopEvent(evt);
	return false;
}

function StopEvent(evt)
{
	if(document.all)evt.returnValue=false;
	else if(evt.preventDefault)evt.preventDefault();
}

function formataMascara(format, field)
{
	var result = "";
	var maskIdx = format.length - 1;
	var error = false;
	var valor = field.value;
	var posFinal = false;
	if( field.setSelectionRange ) 
	{
    	if(field.selectionStart == valor.length)
    		posFinal = true;
    }
	valor = valor.replace(/[^0123456789Xx]/g,'')
	for (var valIdx = valor.length - 1; valIdx >= 0 && maskIdx >= 0; --maskIdx)
	{
		var chr = valor.charAt(valIdx);
		var chrMask = format.charAt(maskIdx);
		switch (chrMask)
		{
		case '#':
			if(!(/\d/.test(chr)))
				error = true;
			result = chr + result;
			--valIdx;
			break;
		case '@':
			result = chr + result;
			--valIdx;
			break;
		default:
			result = chrMask + result;
		}
	}

	field.value = result;
	field.style.color = error ? 'red' : '';
	if(posFinal)
	{
		field.selectionStart = result.length;
		field.selectionEnd = result.length;
	}
	return result;
}

var confirmaAssinador = 0;
var linkJS = "";

function formataMesAno(campo){
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;

	if ( tam > 2 && tam < 5 )
		campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
	if ( tam >= 5 && tam <= 10 )
		campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 4 ); 
}

function formataCgc(campo) {
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;

	if ( tam <= 2 ){ 
 		campo.value = vr ; }
 	if ( (tam > 2) && (tam <= 6) ){
 		campo.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 7) && (tam <= 9) ){
 		campo.value = vr.substr( 0, tam - 6 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 10) && (tam <= 12) ){
 		campo.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 13) && (tam <= 14) ){
 		campo.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + 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 ) ;}	
}

function formataCPF(campo){
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length ;
	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 );}

}

function formataPercentual(campo) {
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;

	if ( tam <= 3 ){ 
 		campo.value = vr ; }
 	if ( (tam > 3) && (tam <= 6) ){
 		campo.value = vr.substr( 0, tam - 3 ) + ',' + vr.substr( tam - 3, tam ) ; }	
}

function formataTelefone(campo) {
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;

	if ( tam <= 4 )
		campo.value = vr;
	if ( tam > 4 ) 
		campo.value = vr.substr(0, tam-4 ) + '-' + vr.substr(tam-4, tam);
}

function limita(campo){
	var tamanho = document.forms.aapf[campo].value.length;
	var tex=document.forms.aapf[campo].value;
	if (tamanho>=1539) {
		document.forms.aapf[campo].value=tex.substring(0,1539); 
	}
	return true;
}

function formataCartaoCredito(campo, teclapres) {
    var tammax = 16;
	var tecla = teclapres.keyCode;
	vr = document.forms.aapf[campo].value;

	if ( tecla == 8 || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105)) {
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( ",", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		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 ( tam < 5 )
		   { document.forms.aapf[campo].value = vr ; }
	 	if ( ( tam >  4 ) && ( tam < 9 ) )
		   { document.forms.aapf[campo].value = vr.substr( 0, 4 ) + '.' + vr.substr( 4, tam-4 ) ; }
	 	if ( ( tam >  8 ) && ( tam < 13 ) )
		   { document.forms.aapf[campo].value = vr.substr( 0, 4 ) + '.' + vr.substr( 4, 4 ) + '.' + vr.substr( 8, tam-4 ) ; }
	 	if ( tam > 12 )
		   { document.forms.aapf[campo].value = vr.substr( 0, 4 ) + '.' + vr.substr( 4, 4 ) + '.' + vr.substr( 8, 4 ) + '.' + vr.substr( 12, tam-4 ); }
	}	
}

function mostraAjuda(objeto){
	document.getElementById(objeto).style.visibility = "visible";
}

function escondeAjuda(objeto){
	document.getElementById(objeto).style.visibility = "hidden";
}


// Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}


function Bloquear(o){
    
    
    var left = o.offsetLeft - 15;
    var top = o.offsetTop + 5;
    var span = document.createElement('SPAN');
    span.style.top = top + 'px';
    span.style.left = left + 'px';
    span.innerHTML = '<b>Aguarde o processamento...</b>';
    span.style.fontWeight = 'bold';
    o.parentNode.appendChild(span);
    o.style.display = 'none';
 
}


