// * @author José Ricardo M Castro - josericardomcastro@gmail.com

var ajax = null;
var pagina = null;

function openAjax(){
	var xajax;
	try{
		xajax = new XMLHttpRequest(); // XMLHttpRequest para browsers decentes, como: Firefox, Safari, dentre outros.
	}catch(ee){
		try{
			xajax = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE da MS
		}catch(e){
			try{				
				xajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS
			}catch(E){
				xajax = false;
			}
		}
	}
	return xajax;
}

function caixaAlta(campo){
	var string = campo.value;
	campo.value = string.toUpperCase();
}

function popup(url, top, left, width, height){
	string="top="+top+", left="+left+", width="+width+", height="+height+", scrollbars = yes, location = no";
	window.open(url,"",string);
}

function votarEnquete(enquete){	
	with(document.enquete){	
		var resposta_selecao = 0
		var resposta_value = "";
		for (var i=0; i<resposta.length; i++){
			if (resposta[i].checked == true){
				resposta_selecao++;
				resposta_value = resposta[i].value;
			}
		}		
		if (resposta_selecao == 0){
			alert("Selecione uma resposta!")
		}else{
			string="top=250, left=350, width=500, height=50, scrollbars = yes";
			window.open("votarenquete.php?enquete="+enquete+"&resposta="+resposta_value,"",string);
		}		
	}	
}

function checacpf(cpf) { //Sem pontos ou traços...
	if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
		cpf == "22222222222" ||	cpf == "33333333333" || cpf == "44444444444" ||
		cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
		cpf == "88888888888" || cpf == "99999999999")
		return false;
	soma = 0;

	for (i=0; i < 9; i ++)
		soma += parseInt(cpf.charAt(i)) * (10 - i);
	resto = 11 - (soma % 11);
	
	if (resto == 10 || resto == 11)
		resto = 0;
	
	if (resto != parseInt(cpf.charAt(9)))
		return false;
	
	soma = 0;
	
	for (i = 0; i < 10; i ++)
		soma += parseInt(cpf.charAt(i)) * (11 - i);
	resto = 11 - (soma % 11);
	
	if (resto == 10 || resto == 11)
		resto = 0;
	
	if (resto != parseInt(cpf.charAt(10)))
		return false;
    
	return true;
}

//Retorna 1 (true) se é uma data válida no calendário gregoriano
function checkDate(date) { //data no formato "dd/mm/aaaa"
	var d = date.substring(0,2);
	var m = date.substring(3,5);
	var y = date.substring(6,date.length);
	return m > 0 && m < 13 && y > 0 && y < 32768 && d > 0 && d <= (new Date(y, m, 0)).getDate();
}
//Adição da implementação da função "trim()" para os tipos String
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}