function ValidateLogin(objLogin, objSenha){
	var stLogin, stSenha
		stLogin = objLogin.value
		stSenha	= objSenha.value

	if(stLogin && stSenha){
		RunAjaxRequest('POST', 'http://revistainvicto.uol.com.br/scripts/secure/RetornaDados.asp', 'cpfcnpj='+stLogin, ReceiveXmlLogin);
	}else{
		alert("Favor preencher o campo CPF/CNPJ e o campo senha.");
		objLogin.focus();
	}
}

function FeedbackLoader(stValor){
	var objText		= document.getElementById("idLogin")
	objText.value	= stValor
}

function ReceiveXmlLogin(objXmlRequest){
	var stReturn
	var objButton	= document.getElementById("btnAutenticacao")
	var objText		= document.getElementById("idLogin")
	
	if(objXmlRequest.readyState != 4){
		objButton.disabled	= true
		objText.disabled	= true

		FeedbackLoader("Carregando");
	}
	
	if(objXmlRequest.readyState == 4){
		if (objXmlRequest.status == 200){
			stReturn = objXmlRequest.responseText

			window.setTimeout("FeedbackLoader('Carregando ..')",       0500);
			window.setTimeout("FeedbackLoader('Carregando ....')",     1000);
			window.setTimeout("FeedbackLoader('Carregando ......')",   1500);
			window.setTimeout("FeedbackLoader('Carregando ........')", 2000);
			window.setTimeout("AutenticaUsuario('"+stReturn+"')",      2000);
		}
	}
}

function AutenticaUsuario(stReturn){
	var objButton	= document.getElementById("btnAutenticacao")
	var objText		= document.getElementById("idLogin")
	
	if(stReturn == "S" || stReturn == "s"){
		alert("Login efetuado com sucesso.")
		document.location.href=("../Secure/Secure.asp");
	}else{
		alert("Atenção\nSeu Login está incorreto. Tente novamente.")
		objButton.disabled	= false
		objText.disabled	= false

		objButton.value		= " OK "
		objText.value		= ""
		objText.focus();
	}
}


function validateFormFiltro(obj_form){
	if (obj_form.strDivisao.value == "" && obj_form.strTipo.value == "" && obj_form.dtMes.value == "" && obj_form.dtAno.value == ""){
		alert("Atenção:\n\nFavor selecionar alguma opção para o filtro.")
		obj_form.strDivisao.focus();
		return false;
	}
}

// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(t1eObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}


//Pop-up
function abrePop(pPagina,pLargura,pAltura,pScroll){
  var posX
  var posY
  posX = (window.screen.width - pLargura - 16) / 2;
  posY = (window.screen.height - pAltura) / 2;
  var win = window.open(pPagina,"Popup","width=" + pLargura + ",height=" + pAltura + ",top=" + posY + ",left=" + posX + ",scrollbars=" + pScroll);
  win.focus();
}

function validacao() {
	stCpf = document.frmCad.stCpf.value;
	if (stCpf.length > 15) {
		validaCNPJ();
	} else {
		validaCPF();
	}
}
				
function validaCPF() {
					
	stCPF = document.frmCad.stCpf.value;
	stCPF = stCPF.replace(".", "");
	stCPF = stCPF.replace(".", "");
	stCPF = stCPF.replace("-", "");
	valor = true;
	erro = new String;
	if (stCPF.length < 11) erro += "Preencha corretamente o número do seu CPF! \n\n"; 
	var nonNumbers = /\D/;
	if (nonNumbers.test(stCPF)) erro += "Preencha corretamente o número do seu CPF! \n\n";	
	if (stCPF == "00000000000" || stCPF == "11111111111" || stCPF == "22222222222" || stCPF == "33333333333" || stCPF == "44444444444" || stCPF == "55555555555" || stCPF == "66666666666" || stCPF == "77777777777" || stCPF == "88888888888" || stCPF == "99999999999"){
		  erro += "Número de CPF inválido!"
	}
	var a = [];
	var b = new Number;
	var c = 11;
	for (i=0; i<11; i++){
		a[i] = stCPF.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 ((stCPF.charAt(9) != a[9]) || (stCPF.charAt(10) != a[10])){
		erro +="Número de CPF inválido!";
	}
	if (erro.length > 0){
		alert(erro);
	}
    else
    {
    	document.frmCad.nmAcao.value=1;document.frmCad.submit();
    }
}

window.status = 'INVICTO - Portal para quem vive futebol.';

function newAjaxObject(){
	var objAjax;

	try{
		objAjax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e){
		try {
			objAjax = new ActiveXObject("Msxml2.XMLHTTP");
			objAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		}
		catch(ex){
			try{
				objAjax = new XMLHttpRequest();
			}
			catch(exc){
				objAjax = null;
			}
		}
	}
	return objAjax;
}

function RunAjaxRequest(stMethod, stUrl, stParameters, stPosFunctionName){
	objXmlRequest 	= newAjaxObject()
	process 		= stPosFunctionName;
	
	objXmlRequest.onreadystatechange = function(){
		try{
			process(objXmlRequest);	
		}
		catch(objException){
		}
	}
	
	if (!stMethod) {
		stMethod = "POST";
	}
	
	stMethod = stMethod.toUpperCase();

	objXmlRequest.open(stMethod, stUrl, true);
	
	if (stMethod == "POST") {
		objXmlRequest.setRequestHeader("Connection", "close");
		objXmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		objXmlRequest.setRequestHeader("Method", "POST " + stUrl + "HTTP/1.1");
	}
	
	objXmlRequest.send(stParameters);
	return objXmlRequest;
}