function link(p){
	//window.iframe.location.href=p;
	document.getElementById("iframe3").src=p;
}

function ValidaInscricao(){
	var color1 = "#ff6665";
	var color2 = "#ff6665";

	var valida2ok = valida2("login", "confirma login", "senha", "confirma senha", "nome", "CPF", "RG", "endereco", "cidade", "cidade", "cep", "tel", "fax", "pais", "email");
	if (valida2ok == false)
		return false;	
	
	  // VALIDA Apelido
	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
	  var checkStr = document.cadastro.login.value;
	  var allValid = true;
	  for (i = 0;  i < checkStr.length;  i++) 
	  {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		  if (ch == checkOK.charAt(j))
			break;
		if (j == checkOK.length)
		{
		  document.cadastro.login.focus();
		  allValid = false;
		  break;
		}
	  }
	  if (!allValid)
	  {
		alert("Caracteres inválidos em seu Apelido.\n\nSão permitidos apenas números e letras.");
		document.cadastro.login.focus();
		return (false);
	  }
	  
	  // FIM VALIDA EMAIL  
 
	
	// Validando Email
	if( document.FInscricao.Email.value.indexOf('@')==-1 || document.FInscricao.Email.value.indexOf('.')==-1){
		alert( "Seu E-mail é inválido!" );
		document.cadastro.email.focus();
		document.cadastro.email.style.background = color1;
		return false;
	}else{
		document.cadastro.email.style.background = color2;
	}	
		
	// Total de caracteres do apelido
	if(document.FInscricao.Apelido.value.length < 4){
		alert( "Seu apelido deve ter mais que 3 caracteres!" );
		document.cadastro.login.focus();
		document.cadastro.login.style.background = color1;
		return false;
	}
		
	// atribui a senha e contra senha a variaveis
	var senha = document.cadastro.senha.value;
	var confsenha = document.cadastro.confsenha.value;	
	
	// Total de caracteres da senha
	if(senha.length < 4){
		alert( "Sua senha deve ter mais que 3 caracteres!" );
		document.cadastro.senha.focus();
		document.cadastro.senha.style.background = color1;
		return false;
	}	
	
	// Verifica se a senha e contra senha são iguais
	if(senha != confsenha){
		alert( "A confirmação de senha não corresponde com a senha!" );
		document.cadastro.confsenha.focus();
		document.cadastro.confsenha.style.background = color1;
		return false;
	}
		
	   var cpf = document.cadastro.CPF.value;
	   cpf = cpf.replace(/-/g,"");
	   cpf = cpf.replace(/\./g,"");

	   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
		  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
		  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
		  cpf == "88888888888" || cpf == "99999999999"){
		  alert("CPF inválido. Tente novamente.");
		  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))){
		 alert("CPF inválido. Tente novamente.");
		 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))){
	     alert("CPF inválido. Tente novamente.");
		 return false;
	   }	
	
	return true;	
}
	
		
function ValidaInscricao_Confirma(){
	var valida2ok = valida2("login", "confirma login", "senha", "confirma senha", "nome", "CPF", "RG", "endereco", "cidade", "cidade", "cep", "tel", "fax", "pais", "email");
	if (valida2ok == false)
		return false;
		
	return true;
}		


function valida2(){
	
	if(arguments.length>0){
		for(var i=0; i<arguments.length; i++){
			var varQQ = arguments[i];
			var varQQnome = varQQ;
			//alert(varQQnome);
			
			if(document.getElementById(varQQ).value == ""){
			
				while(varQQnome.indexOf( "_" ) != "-1"){			
					varQQnome = varQQnome.replace("_"," ");
				}
				
				alert("Por favor, preencha o campo "+varQQnome);
				document.getElementById( varQQ ).focus();
				document.getElementById( varQQ ).style.background = "#ff6665";
				return false;
			}	
		}	
	}

}



/**********************************************************************/
/*  LIMITA CARACTERES */
/**********************************************************************/
		
function max(txarea,id,total)
{
	//total = 200;
	tam = txarea.value.length;
	str="";
	str=str+tam;
	//document.getElementById("digitado"+).innerHTML = str;
	document.getElementById(id+"_restante").innerHTML = total - str;
	
	if (tam > total){
		aux = txarea.value;
		txarea.value = aux.substring(0,total);
		//document.getElementById("digitado").innerHTML = total;
		document.getElementById(id+"_restante").innerHTML = 0;
	}
}


/**********************************************************************/
/* FORMULARIOS - FUNCAO PARA LIMITAR DADOS DIGITADOS */
/**********************************************************************/

 function mascara(o,f){
v_obj=o
v_fun=f
setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

function Ntelefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function Ncpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function Ncep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function Ncnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}

function romanos(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M
    //Essa é complicada! Copiei daqui: http://www.diveintopython.org/refactoring/refactoring.html
    while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
        v=v.replace(/.$/,"")
    return v
}

function site(v){
    //Esse sem comentarios para que você entenda sozinho ;-)
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}

// Permite apenas mes e ano no formulario

function MesAnoZera(v){
if (v == "mes/ano")v=""
return v
}


function MesAno(v){
	if(v.length==2 && !(v.indexOf("/")>-1))
	{
		if(v > 12)
		{
			alert('O mês não deve ser maior que 12');
			v = (v.substring( 0,(v.length-1) )); 
		}else{
			v=v+"/";				
		}
	}
    
	return v
	//  onkeypress="javascript:mascara(this,MesAno)" onclick="javascript:mascara(this,MesAnoZera)" value="mes/ano"
}

/* body - onkeypress="mascara(this,soNumeros)" */


// ALTERANDO IMAGEM DO FORMULARIO
//var ImagemAtual = new Image();
function MudaImagem(MyImgNumber,Total){	
	var Ni = new String;
	// Altera a classe de todas as imagens para a classe padrao
	for(i = 1;i<=Total;i++){
		Ni = "0000"+i;
		Ni = Ni.substr( Ni.length - 4 );
		document.getElementById("fake_"+Ni).className = "ImagemNormal";
	}
	Ni = "0000"+MyImgNumber;
	Ni = Ni.substr( Ni.length - 4 );
	// Altera a classe de todas as imagens para a classe selecionada
	document.getElementById("fake_"+Ni).className = "ImagemSelecionada";	
	//.getElementById("Imagem_Escolhida_Media").src = "imagens/fake_"+Ni+".jpg";
	document.getElementById("Imagem_Escolhida").value = "imagens/fake_"+Ni+".jpg";	
}

function ValidaEsqueciSenha(){
	if( document.Fesqueci_minha_senha.email.value.indexOf('@')==-1 || document.Fesqueci_minha_senha.email.value.indexOf('.')==-1 || document.Fesqueci_minha_senha.email.value == ""){
	    alert( "Informe seu e-mail corretamente!" );
		document.Fesqueci_minha_senha.email.focus();
		return false;
	}else{
		return true;
	}
}

function ValidaCPF(){
	
   var cpf = document.FValidaCPF.cpf.value;
   cpf = cpf.replace(/-/g,"");
   cpf = cpf.replace(/\./g,"");

   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999"){
	  alert("CPF inválido. Tente novamente.");
	  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))){
	 alert("CPF inválido. Tente novamente.");
	 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))){
	 alert("CPF inválido. Tente novamente.");
	 return false;
   }
   
   return true;
}

function ValidaFReenvieAtivacao(){
	if(!(document.getElementById("tipo1").checked)){
		if( document.FReenvieAtivacao.novoemail.value.indexOf('@')==-1 || document.FReenvieAtivacao.novoemail.value.indexOf('.')==-1 || document.FReenvieAtivacao.novoemail.value == ""){
		    alert( "Informe seu e-mail corretamente!" );
			document.FReenvieAtivacao.novoemail.focus();
			return false;
		}
		if( document.FReenvieAtivacao.senha.value == ""){
		    alert( "Informe sua senha corretamente!" );
			document.FReenvieAtivacao.senha.focus();
			return false;
		}
	}
	
	return true;

}

function alterastatus(tipo){
	if(tipo == 1){
		document.FReenvieAtivacao.novoemail.value = document.FReenvieAtivacao.emailoriginal.value;		
		document.FReenvieAtivacao.novoemail.disabled = true;
		document.getElementById("MinhaSenha").style.display = "block";
		document.getElementById("NovaSenha").style.display = "none";		
		document.getElementById("tipo1").checked = true;
		document.getElementById("tipo2").checked = false;
	}else{
		document.FReenvieAtivacao.novoemail.value = "";
		document.FReenvieAtivacao.novoemail.disabled = false;
		document.getElementById("MinhaSenha").style.display = "none";
		document.getElementById("NovaSenha").style.display = "block";
		document.getElementById("tipo1").checked = false;
		document.getElementById("tipo2").checked = true;
	}
}

function abrepop(link, l, a){
	/*
	var l = l;
	var a = a;
	var agt=navigator.userAgent.toLowerCase(); 
	var Vnav = agt.indexOf("msie");
	if(Vnav != -1)
		l=l-50;
	else
		a = a+80;
	*/
	//var a = a+60;
	pp = window.open( '', null, "height=" + a + ",width=" + l + ",status=no,toolbar=no,menubar=no,location=no");
	pp.moveTo( ( screen.width - l) / 2, ( screen.height - a) /2 );
	//pp.window.resizeTo( l, a );
	pp.location = link;
	pp.focus();
}


	// VALIDA CNPJ
	/*
	var cnpj = document.FInscricao.empresa_cnpj.value;
	var valida = new Array(6,5,4,3,2,9,8,7,6,5,4,3,2);
	var dig1= new Number;
	var dig2= new Number;
	
	exp = /\.|\-|\//g
	cnpj = cnpj.toString().replace( exp, "" );
	var digito = new Number(eval(cnpj.charAt(12)+cnpj.charAt(13)));
		
	for(i = 0; i<valida.length; i++){
		dig1 += (i>0? (cnpj.charAt(i-1)*valida[i]):0);    
		dig2 += cnpj.charAt(i)*valida[i];    
	}
	dig1 = (((dig1%11)<2)? 0:(11-(dig1%11)));
	dig2 = (((dig2%11)<2)? 0:(11-(dig2%11)));
	
	if(((dig1*10)+dig2) != digito)   
	{
		alert('CNPJ Invalido!');
		return false;	        
	}
	*/		

		
	// VALIDA CPF	
	
	/*
	   var cpf = document.fcadastro.CPF.value;
	   cpf = cpf.replace(/-/g,"");
	   cpf = cpf.replace(/\./g,"");

	   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
		  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
		  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
		  cpf == "88888888888" || cpf == "99999999999"){
		  alert("CPF inválido. Tente novamente.");
		  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))){
		 alert("CPF inválido. Tente novamente.");
		 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))){
	     alert("CPF inválido. Tente novamente.");
		 return false;
	   }*/		
		 
		 
		 // OnMouseOver - Miguel

			function aparece(){
			document.getElementById("cont").style.display="block";
			}
			function some(){
			document.getElementById("cont").style.display="none";
			}
			
			function aparece2(){
			document.getElementById("cont2").style.display="block";
			}
			function some2(){
			document.getElementById("cont2").style.display="none";
			}
			
			function aparece3(){
			document.getElementById("cont3").style.display="block";
			}
			function some3(){
			document.getElementById("cont3").style.display="none";
			}