var reEmail1 = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
var reEmail2 = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
var reEmail3 = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
var reEmail = reEmail3;

function AbrirAssociativa(pagina,entidade,w,h){
	if (w == '')
		w = 200;
	if (h == '')
		h = 200;
	window.open(pagina,entidade,'width='+ w +', height=' + h);
}
function Excluir(id){
	if (confirm('Deseja realmente excluir esse registro?'))
		window.location.href = '?IdExc='+id;	
}
function Editar(id){
	window.location.href = '?Id='+id;	
}
function Limpar(){
	window.location.href = '?';	
}


function EmailValido(pStr){
	pFmt = 2;
	eval("reEmail = reEmail" + pFmt);
	if (reEmail.test(pStr)) {
		return true; 
		//alert(pStr + " é um endereço de e-mail válido.");
	} else if (pStr != null && pStr != "") {
		return false; 
		//alert(pStr + " NÃO é um endereço de e-mail válido.");
	}
}

function MascaraNumero2(obj){
	NumeroFormatado = "";
	Num = LimparFormatacaoNumero(obj.value);
	Num = Num.replace(".","");
	Tam = Num.length;
	
	posDecimos = Tam - 2;
	Decimal = Num.substr(posDecimos,Tam);
	Inteiro = Num.substr(0,posDecimos);
	TamInt = Inteiro.length;
	c = 0;
	NumInteiro = "";
	for (var i=1; i<=TamInt; i++){
		if (c == 3){
			NumInteiro = Inteiro.substr(TamInt-i,1) +"."+ NumInteiro;
			c = 0;
		}
		else{
			NumInteiro = Inteiro.substr(TamInt-i,1) + NumInteiro;
		}
		c++;
	}
	
	if (Tam > 2)
		NumeroFormatado = NumInteiro +","+ Decimal;
	else
		NumeroFormatado = Num;
		
	obj.value = NumeroFormatado;
}


/*
12,3
12,34
123,45
1.234,56
12.345,67
123.456,78
1.234.567,89
*/

function MascaraNumero(obj){
	var nData = "";
	var nData2 = obj.value;
	var Data = obj.value;
	Data = Data.replace(".","");
	Data = Data.replace(".","");
	Data = Data.replace(".","");
	Data = Data.replace(",","");
	Data = Data.replace(",","");
	Data = Data.replace(",","");
	tam = Data.length;

	if (tam == 3)
	nData = Data.substr(0,1) +","+ Data.substr(1,2);
	if (tam == 4)
	nData = Data.substr(0,2) +","+ Data.substr(2,2);
	if (tam == 5)
	nData = Data.substr(0,3) +","+ Data.substr(3,2);
	if (tam == 6)
	nData = Data.substr(0,1) +"."+ Data.substr(1,3) +","+ Data.substr(4,2);
	if (tam == 7)
	nData = Data.substr(0,2) +"."+ Data.substr(2,3) +","+ Data.substr(5,2);
	if (tam == 8)
	nData = Data.substr(0,3) +"."+ Data.substr(3,3) +","+ Data.substr(6,2);
	if (tam == 9)
	nData = Data.substr(0,1) +"."+ Data.substr(1,3) +"."+ Data.substr(4,3) +","+ Data.substr(7,2);
	if (tam == 10)
	nData = Data.substr(0,2) +"."+ Data.substr(2,3) +"."+ Data.substr(5,3) +","+ Data.substr(8,2);
	if (tam == 11)
	nData = Data.substr(0,3) +"."+ Data.substr(3,3) +"."+ Data.substr(6,3) +","+ Data.substr(9,2);

	if (nData2 != nData){
		if (nData == "")
			obj.value = nData2;
		else
			obj.value = nData;
	}
}


function MascaraData(obj){
	var nData = "";
	var nData2 = obj.value;
	var Data = obj.value;
	Data = Data.replace("/","");
	Data = Data.replace("/","");
	tam = Data.length;

	if (tam == 3)
	nData = Data.substr(0,2) +"/"+ Data.substr(2,1);

	if (tam == 5)
	nData = Data.substr(0,2) +"/"+ Data.substr(2,2) +"/"+ Data.substr(4,4);

	if (nData == "")
		obj.value = nData2;
	else
		obj.value = nData;
}

function MascaraTelefone(obj){
//	Numero();
	var tam = obj.value.length;
	if (tam == 4)
		obj.value = obj.value.substr(0,4) +"-"+ obj.value.substr(5,1);
}

function MascaraCEP(obj){
//	Numero();
	var tam = obj.value.length;

	if (tam == 2)
		obj.value = obj.value.substr(0,2) +"."+ obj.value.substr(3,1);
		
	if (tam == 6)
		obj.value = obj.value.substr(0,2) +"."+ obj.value.substr(3,3) + "-" + obj.value.substr(7,1);
}

function MascaraCPF(obj){
//	Numero();
	var tam = obj.value.length;

	if (tam == 3)
		obj.value = obj.value.substr(0,3) +"."+ obj.value.substr(3,1);

	if (tam == 7)
		obj.value = obj.value.substr(0,3) +"."+ obj.value.substr(4,3) +"."+ obj.value.substr(8,1);
		
	if (tam == 11)
		obj.value = obj.value.substr(0,3) +"."+ obj.value.substr(4,3) +"."+ obj.value.substr(8,3) + "-";
}

function MascaraCNPJ(obj){
//	12.456.789/0909-09
	var tam = obj.value.length;

	if (tam == 2)
		obj.value = obj.value.substr(0,2) +"."+ obj.value.substr(2,1);
	if (tam == 6)
		obj.value = obj.value.substr(0,2) +"."+ obj.value.substr(3,3) +"."+ obj.value.substr(6,1);
	if (tam == 11)
		obj.value = obj.value.substr(0,2) +"."+ obj.value.substr(3,3) +"."+ obj.value.substr(7,3) +"/"+ obj.value.substr(10,1);
	if (tam == 15)
		obj.value = obj.value.substr(0,2) +"."+ obj.value.substr(3,3) +"."+ obj.value.substr(7,3) +"/"+ obj.value.substr(11,4) + "-";
}


function Numero()
{
	if ((window.event.keyCode>=48) && (window.event.keyCode<=57) )
		return(true)
	else
	{
		window.event.keyCode=0;
		return(false);
	}
}

function LimparFormatacaoInt(num){
	var valor = num.toString();
	return valor
}
function LimparFormatacaoTotal(num){
	var valor = num.toString();
	valor = valor.replace(".","");
	valor = valor.replace(".","");
	valor = valor.replace(".","");
	valor = valor.replace(",","");
	return parseFloat(valor)
}

function LimparFormatacaoNumero(num){
	var jNum = num.toString();
	jNum = jNum.replace(".","");
	jNum = jNum.replace(".","");
	jNum = jNum.replace(".","");
	jNum = jNum.replace(".","");
	jNum = jNum.replace(".","");
	jNum = jNum.replace(",",".");
	return jNum;
}

function ManipularSelects(acao){

	tam = document.forms[0].elements.length;

	for (i=0; i<tam; i++){
		if (document.forms[0].elements[i].name != 'DescricaoIndicada'){
			if (document.forms[0].elements[i].type == 'select-one'){
				document.forms[0].elements[i].style.visibility = acao;
			}
		}
	}
}

function MudarData(data){
	var v = data.split('/');
	return v[2] +'-'+ v[1] +'-'+ v[0]
}
function ExibirData(data){
	var v = data.split('-');
	var retorno = v[2] +'/'+ v[1] +'/'+ v[0]
	
	if ((retorno == "/undefined/undefined") || (retorno == '00/00/0000')){
		retorno = ''
	}
	return retorno;
}


function paginacaoProxima(){

	if (numI <= numF){
		html = '<table border=0 align=right><tr><td><a class="opcoesPaginacao" href="javascript:paginacaoAnterior()"> << </a></td>';	
		i = 1;
		numIpg = numI;
		do{
			if (numI <= numF){
				final = ((numI+qtde)-1);
				
				if ((final/15) == pagSel)
					fundo = 'bgColor="#FFFFCC"';
				else
					fundo = 'bgColor="#FFFFFF"';
				
				
				html += '<td class="ListagemPaginacao" '+ fundo +'><a class="opcoesPaginacao" href="javascript:Pagina('+ (final/15) +')"><b>' + numI +" - "+ final + '</b></a></td>';
				numI += qtde;
			}
		i++;
		}while(i<=6)
		html += '<td><a class="opcoesPaginacao" href="javascript:paginacaoProxima()"> >> </a></td></tr></table>';
		document.getElementById('paginacao').innerHTML = html;
	}		
}

function paginacaoAnterior(){
	if (numIpg > 1){
		html = '<table border=0 align=right><tr><td><a class="opcoesPaginacao" href="javascript:paginacaoAnterior()"> << </a></td>';
		i = 1;
		numI = numIpg - (qtde * 6);
		numIpg = numI;
		do{
			if (numI >= 1){
				final = ((numI+qtde)-1);
				if ((final/15) == pagSel)
					fundo = 'bgColor="#FFFFCC"';
				else
					fundo = 'bgColor="#FFFFFF"';
				
				
				html += '<td class="ListagemPaginacao" '+ fundo +'><a class="opcoesPaginacao" href="javascript:Pagina('+ (final/15) +')"><b>' + numI +" - "+ final + '</b></a></td>';
				numI += qtde;
			}
		i++;
		}while(i<=6)
		html += '<td><a class="opcoesPaginacao" href="javascript:paginacaoProxima()"> >> </a></td></tr></table>';
		document.getElementById('paginacao').innerHTML = html;
	}
}

