function randomString(string_length) {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = (string_length == null)?8:string_length;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

$(function(){
	$('#conteudo').addClass('show')
})

/* troca do Sumario agrianual2010 */
function tAgri2010(ativo){

	document.getElementById('artigos').style.display = 'none';
	document.getElementById('terras').style.display = 'none';
	document.getElementById('mecanizacao').style.display = 'none';
	document.getElementById('indicadores').style.display = 'none';
	document.getElementById('biocombustivel').style.display = 'none';
	document.getElementById('c_a').style.display = 'none';
	document.getElementById('c_b').style.display = 'none';
	document.getElementById('c_c').style.display = 'none';
	document.getElementById('c_d').style.display = 'none';
	document.getElementById('c_f').style.display = 'none';
	document.getElementById('c_g').style.display = 'none';
	document.getElementById('c_h').style.display = 'none';
	document.getElementById('c_m').style.display = 'none';
	document.getElementById('c_n').style.display = 'none';
	document.getElementById('c_p').style.display = 'none';
	document.getElementById('c_s').style.display = 'none';
	document.getElementById('c_t').style.display = 'none';
	document.getElementById('c_u').style.display = 'none';
	
	if(ativo != 'nenhum'){
		document.getElementById(ativo).style.display = 'block';
	}
	
}

function carSuss(tipo){

	if(tipo == 'credito'){

		alert('Foram debitados os cr�ditos de sua conta, clique no link ao lado para fazer o download');

	} else {
		
		alert('pedido adicionado com sucesso ao carrinho!');
		
	}
	
}

/*# Abre popup centralizada na tela. Passar largura e altura */
function wopen(page,wdt,hgt)
{
	var _x				= wdt / 2;
	var _y				= hgt / 2;
	var pos_tela_width		= (screen.width / 2) - _x;
	var pos_tela_height		= (screen.height / 2) - _y;

	window.open(page,"pre","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=2,noresize,copyhistory=no,width="+wdt+",height="+hgt+",top="+pos_tela_height+",left="+pos_tela_width);
}

/* FUNÇÃO PARA VALIDAR CPF */
function checkCPF(numero) {
	var CPF, pos, i, soma, dv, dv_informado;
	var digito = new Array(10);								// Cria array para armazenar os valores
	
	if (numero.length > 0) {
		CPF				= numero.replace(/[.-]/gi, "");		// Retira os '.' e '-' do número
		dv_informado	= CPF.substr(9, 2);					// Armazena os dois últimos dígito do CPF
		
		/* Desmembra o número do CPF na array digito */
		for (i=0; i<=8; i++) {
			digito[i] = CPF.substr( i, 1);					
		}
		
		/* Calcula o valor do 10° dígito da verificação */
		posicao		= 10;
		soma		= 0;
		for (i = 0; i <= 8; i++) {
			soma	+= digito[i] * posicao;
			posicao	 = posicao - 1;
		}
		digito[9] = soma % 11;
		if (digito[9] < 2) {
			digito[9] = 0;
		} else {
			digito[9] = 11 - digito[9];
		}
		
		/* Calcula o valor do 11° dígito da verificação */
		posicao	= 11;
		soma		= 0;
		for (i = 0; i <= 9; i++) {
			soma	+= digito[i] * posicao;
			posicao	 = posicao - 1;
		}
		digito[10] = soma % 11;
		if (digito[10] < 2) {
			digito[10] = 0;
		} else {
			digito[10] = 11 - digito[10];
		}
		
		/* Verifica se os dígitos verificadores conferem */
		dv = digito[9] * 10 + digito[10];
		
		if (dv != dv_informado) {
			//alert("CPF inválido");
			return false;
		} else {
			//alert("CPF válido");
			return true;
		}
	} else {
		//alert("CPF inválido");
		return false;
	}
}
