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;
}

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&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


//Pop-ups
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 + ",status=no,toolbar=no,menubar=no,location=no,,scrollbars=" + pScroll);
  win.focus();
}

function abrePop2(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,"Popup2","width=" + pLargura + ",height=" + pAltura + ",top=" + posY + ",left=" + posX + ",status=no,toolbar=no,menubar=no,location=no,,scrollbars=" + pScroll);
  win.focus();
}

function displayFlash(largura, altura, arquivo){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="teste" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" />');
	document.write('<param name="movie" value="'+arquivo+'" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><embed src="'+arquivo+'" wmode="transparent" quality="best" width="'+largura+'" height="'+altura+'" name="teste" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

// Msg STATUS no Rodapé
window.status = 'Revista O2';

function validaDados(objForm){
	var countCampo = objForm.stCpfCnpj.value.length
	var stCpfCnpj = objForm.stCpfCnpj.value;
	
	if(countCampo <= 11){
		if(!validaCpf(stCpfCnpj)){
			alert("O CPF informado contém erros.");
			objForm.stCpfCnpj.focus();
			objForm.stCpfCnpj.value=""
			return false
		}
	}else{
		if(!validaCnpj(stCpfCnpj)){
			alert("O CNPJ informado contém erros.");
			objForm.stCpfCnpj.focus();
			objForm.stCpfCnpj.value=""
			return false
		}
	}
	
	document.frmInscricaoTreinador.nmAcao.value=1
	document.frmInscricaoTreinador.submit();
}

function validaCnpj(nmCnpj){
	var i;
	var c 	= nmCnpj.substr(0,12);
	var dv 	= nmCnpj.substr(12,2);
	var d1 	= 0;
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
	if (d1 == 0){
		//alert("O Cnpj informado está inválido.");
		return false;
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		//alert("O Cnpj informado está inválido.");
		return false;
	}
	d1 *= 2;
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		//alert("O Cnpj informado está inválido.");
		return false;
	}
	return true;
}

function validaCpf(nmCpf){
	valor = true;
	erro 	= new String;

	if(nmCpf.length < 11) erro += "É necessário 11 dígitos para verificação do CPF.\n";
	var nonNumbers = /\D/;
	if (nonNumbers.test(nmCpf)) erro += "A verificação de CPF suporta apenas números.\n";
	if (nmCpf == "00000000000" || nmCpf == "11111111111" || nmCpf == "22222222222" || nmCpf == "33333333333" || nmCpf == "44444444444" || nmCpf == "55555555555" || nmCpf == "66666666666" || nmCpf == "77777777777" || nmCpf == "88888888888" || nmCpf == "99999999999"){
		erro += "Número de CPF invalido."
	}

	var a = [];
	var b = new Number;
	var c = 11;
	for (i=0; i<11; i++){
		a[i] = nmCpf.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 ((nmCpf.charAt(9) != a[9]) || (nmCpf.charAt(10) != a[10])){
		erro +="Número do CPF está inválido.";
	}
	if (erro.length > 0){
		//alert(erro);
		return false;
	}
	return true;
}