﻿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_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_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 Enquete()
{
	var go = "conteudo/Enquete.aspx"+ arguments[0];
	var iTem = document.getElementsByTagName('input');
	var i;
	
	for(i = 0;i < iTem.length;i++)
	{
		if(iTem[i].getAttribute("type") == "radio")
		{
			if(iTem[i].checked == true)
			{
				window.open(go + '&opc='+ iTem[i].value,"enquete","width=450,height=300");
			}
		}
	}
}

function Selec()
{
	var d = document.getElementsByTagName("input");
	var i;
	
	for(i = 0; i < d.length;i++)
	{
		if(d[i].getAttribute("name") == "areaPreferencia")
		{
			if(arguments[0])
				d[i].checked = true;
			else
				d[i].checked = false;
		}
	}
}

function Selec1()
{
	var d = document.getElementsByTagName("input");
	var i;
	var sel = true;
	
	for(i = 0; i < d.length;i++)
	{
		if(d[i].getAttribute("name") == "areaPreferencia" && d[i].getAttribute("value") != arguments[0] )
		{
			if(!d[i].checked)
				sel = false
		}
	}
	
	for(i = 0; i < d.length;i++)
	{
		if(d[i].getAttribute("name") == "areaPreferencia" && d[i].getAttribute("value") == arguments[0] )
		{
			d[i].checked = sel;
		}
	}
}

function ConfirmDelete() 
{
	var msg = confirm('Deseja excluir esse iten?');
	if (msg)
		return true;
	else
		return false;

}

function checkMail()
{
	var obj = arguments[0];
	var alerta = document.getElementById(arguments[1]);
	  var txt = obj.value;
	  if ((txt.length != 0) && ((txt.indexOf("@") < 1) || (txt.indexOf('.') < 7)))
	  {
	    alerta.innerHTML = "Email Invalido";
		obj.focus();
	  }
	  else
	  {
		alerta.innerHTML = "";
	  }

}


function CepConfir()
{
	var d = arguments[0];
	if(d.value.length == 5)
		d.value = d.value + "-";
}

function Check()
{
	var valor = arguments[0];
	var cmp = document.getElementsByTagName('input');
	var i;
	var reg;
	for(i = 0;i < cmp.length; i++)
	{
		if(cmp[i].name == "rdCpfCnpj" && cmp[i].checked)
		{
			reg = cmp[i].value;
		}
	}
	
	var Cpf = new Array();
		Cpf[3] = ".";
		Cpf[7] = ".";
		Cpf[11] = "-";
		
	var Cnpj = new Array();
		Cnpj[2] = ".";
		Cnpj[6] = ".";
		Cnpj[10] = "/";
		Cnpj[15] = "-";
	
	switch (reg)
	{
		case "1":
			if(Cpf[valor.value.length] != undefined)
				valor.value += Cpf[valor.value.length];
			if(valor.value.length > 14)
				valor.value = valor.value.substring(0,14);
			else
				valor.onblur = new Function('validaCPF(this)');			
			break;
		case "2":
			if(Cnpj[valor.value.length] != undefined)
				valor.value += Cnpj[valor.value.length];
			
			valor.onblur = new Function('validaCNPJ(this)');			
			break;
	}
}

function validaCPF()   
{  
  erro = new String; 
  alerta = document.getElementById('Alerta');
  var cpf = arguments[0].value;
	if (cpf.length == 14)  
	{     
			cpf = cpf.replace('.', '');  
			cpf = cpf.replace('.', '');  
			cpf = cpf.replace('-', '');  
 
		   var nonNumbers = /\D/;  
			
		   if (nonNumbers.test(cpf))   
		   {  
				   erro = "A verificacao de CPF suporta apenas números!";   
		   }  
		   else  
		   {  
				   if (cpf == "00000000000" ||   
						   cpf == "11111111111" ||   
						   cpf == "22222222222" ||   
						   cpf == "33333333333" ||   
						   cpf == "44444444444" ||   
						   cpf == "55555555555" ||   
						   cpf == "66666666666" ||   
						   cpf == "77777777777" ||   
						   cpf == "88888888888" ||   
						   cpf == "99999999999") {  
							 
						   erro = "Número de CPF invádo!"  
				   }  
	 
				   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 = "Número de CPF inválido.";  
				   }  
		   }  
   }  
   else  
   {  
	   if(cpf.length == 0)  
		   return false  
	   else  
		   erro = "Número de CPF inválido.";  
   }  
   if (erro.length > 0) {  
		   alerta.innerHTML = erro;  
		   arguments[0].focus();  
		   return false;  
   }
   alerta.innerHTML = "";
   return true;      
}  

function validaCNPJ() 
{
	CNPJ = arguments[0].value;
	alerta = document.getElementById('Alerta');
	erro = new String;
	if (CNPJ.length < 18) erro += "È necessarios preencher CNPJ! \n\n";
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
	if (erro.length == 0) erro += "É necessarios preencher CNPJ! \n\n";
	}
	//substituir os caracteres que nao sao numeros
	if(document.layers && parseInt(navigator.appVersion) == 4)
	{
		x = CNPJ.substring(0,2);
		x += CNPJ.substring(3,6);
		x += CNPJ.substring(7,10);
		x += CNPJ.substring(11,15);
		x += CNPJ.substring(16,18);
		CNPJ = x;
	} 
	else 
	{
		CNPJ = CNPJ.replace(".","");
		CNPJ = CNPJ.replace(".","");
		CNPJ = CNPJ.replace("-","");
		CNPJ = CNPJ.replace("/","");
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas numeros! \n\n";
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	for (i=0; i<12; i++)
	{
		a[i] = CNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
	
	if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
		b = 0;

	for (y=0; y<13; y++) 
	{
	b += (a[y] * c[y]);
	}

	if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13]))
	{
		erro +="Cnpj invalido";
	}
	if (erro.length > 0){
		alerta.innerHTML = erro;
	return false;
	} 
	alerta.innerHTML = "";
	return true;
}

function CheckReplica()
{
	var d = document.getElementsByTagName('input');
	var i = 0;
	for(i = 0;i < d.length; i++)
	{
		if(d[i].type == 'checkbox')
			if(d[i].id == arguments[0].id)
				d[i].checked = arguments[0].checked;
	}
}

function ContaPessoas()
{
	var Qa = document.getElementById('ctl00_txtNAdultos');
	var Q6 = document.getElementById('ctl00_txtNCrianca6');
	var Q712 = document.getElementById('ctl00_txtNCrianca712');
	
	if(isNaN(Qa.value) || Qa.value.length == 0)
		Qa.value = "0";
		
	if(isNaN(Q6.value) || Q6.value.length == 0)
		Q6.value = "0";
		
	if(isNaN(Q712.value) || Q712.value.length == 0)
		Q712.value = "0";
		
	var campos = document.getElementById('tblAlimentacao').getElementsByTagName('input');
	var contaUsados = "0";
	var i;
	for(i = 0; i < campos.length; i++)
	{
		if(isNaN(campos[i].value) || campos[i].value.length == 0)
			campos[i].value = "0";
			
		contaUsados = eval(parseInt(contaUsados) + parseInt(campos[i].value));
	}
	document.getElementById('txtNrestantes').value = eval(parseInt(Qa.value) + parseInt(Q6.value) + parseInt(Q712.value) - parseInt(contaUsados));
	document.getElementById('txtNSoma').value = contaUsados;
}

function Verificax()
{
	var Qa = document.getElementById('ctl00_txtNAdultos');
	var Q6 = document.getElementById('ctl00_txtNCrianca6');
	var Q712 = document.getElementById('ctl00_txtNCrianca712');
	
	if(isNaN(Qa.value) || Qa.value.length == 0)
		Qa.value = "0";
		
	if(isNaN(Q6.value) || Q6.value.length == 0)
		Q6.value = "0";
		
	if(isNaN(Q712.value) || Q712.value.length == 0)
		Q712.value = "0";
	
	var	Atual = eval(parseInt(Qa.value) + parseInt(Q6.value) + parseInt(Q712.value))
	
	var campos = document.getElementById('tblAlimentacao').getElementsByTagName('input');
	var contaUsados = "0";
	var i;
	for(i = 0; i < campos.length; i++)
	{
		if(isNaN(campos[i].value) || campos[i].value.length == 0)
			campos[i].value = "0";
			
		contaUsados = eval(parseInt(contaUsados) + parseInt(campos[i].value));
	}
	
	if(parseInt(contaUsados) > parseInt(Atual))
	{
		arguments[0].value = parseInt(arguments[0].value) +(parseInt(contaUsados) - parseInt(Atual));
	}
	
	var camposP = document.getElementById('tblPrevilegio').getElementsByTagName('input');
	for(i = 0; i < camposP.length; i++)
	{
		if(isNaN(camposP[i].value) || camposP[i].value.length == 0)
			camposP[i].value = "0";
			
		if(parseInt(arguments[0].value) < parseInt(camposP[i].value))
			arguments[0].value = parseInt(arguments[0].value) + (parseInt(camposP[i].value) - parseInt(Atual));
	}
}

function Verifica()
{	
	var Qa = document.getElementById('ctl00_txtNAdultos');
	var Q6 = document.getElementById('ctl00_txtNCrianca6');
	var Q712 = document.getElementById('ctl00_txtNCrianca712');

	var Restante =  eval(parseInt(Qa.value) + parseInt(Q6.value) + parseInt(Q712.value));
	
	var campos = document.getElementById('tblAlimentacao').getElementsByTagName('input');
	var contaUsados = "0";
	var i;
	for(i = 0; i < campos.length; i++)
	{
		if(isNaN(campos[i].value) || campos[i].value.length == 0)
			campos[i].value = "0";
			
		contaUsados = eval(parseInt(contaUsados) + parseInt(campos[i].value));
	}

	var Recipient;
	var Atual = document.getElementById('txtNrestantes').value;
	if(isNaN(arguments[0].value) || arguments[0].value.length == 0)
			arguments[0].value = "0";
	
	if(parseInt(contaUsados) > parseInt(Restante))
	{
		Recipient = eval(parseInt(arguments[0].value) - parseInt(Atual))
		Recipient = eval(parseInt(arguments[0].value) - parseInt(Recipient));
		arguments[0].value = Recipient;
	}
}
	
function Previlegio()
{
	var Qa = document.getElementById('ctl00_txtNAdultos');
	var Q6 = document.getElementById('ctl00_txtNCrianca6');
	var Q712 = document.getElementById('ctl00_txtNCrianca712');
	
	var	Atual = eval(parseInt(Qa.value) + parseInt(Q6.value) + parseInt(Q712.value))
	
	if(isNaN(arguments[0].value) || arguments[0].value.length == 0)
		arguments[0].value = "0";
	
	if(parseInt(arguments[0].value) > parseInt(Atual))
		arguments[0].value = Atual;
}
