﻿	function hoverimg(id, links){
		document.getElementById(id).src = links;
	}
	
	function hoverclass(id, links){
		document.getElementById(id).className = links;
	}
	
	function confirmExclusao(msg,url, div, condicao,loadings )
{
	var resposta = confirm(msg);
	
	if (resposta == true ){
		
		return  menulink_excluir(url, div, condicao, loadings);	
	}else
	{
		return false;	
	}
}

//--------------------------------------------------INÍCIO FUNÇÕES DE MÁSCARA
function mask(cnpj,tMask,valor,evento)
	{
		if(tMask.length>14)
			{
				return MascaraCNPJ(cnpj,valor,evento);	
			}
			else
				{
					return MascaraCPF(cnpj,valor,evento);	
				}
	}
function vCNPJ_CPF(vl)
	{
		var objVl=vl.value.length;
		if(objVl>14)
			{
				return ValidarCNPJ(vl);
			}
			else
				{
					return ValidarCPF(vl);
				}
	}
function MascaraCNPJ(cnpj,valor,evento){
	if(mascaraInteiro(evento)==false){
        evento.returnValue = false;
    }
    return formataCampo(cnpj, '00.000.000/0000-00', evento);
}
//adiciona mascara ao CPF
function MascaraCPF(cpf,valor,evento){
  
    if(mascaraInteiro(evento)==false){
        evento.returnValue = false;
    }    
    return formataCampo(cpf, '000.000.000-00', evento);
}
//adiciona mascara de cep
function MascaraCep(cep, evento){
        if(mascaraInteiro(cep)==false){
        evento.returnValue = false;
    }    
    return formataCampo(cep, '00.000-0000', evento);
}

//adiciona mascara de data
function MascaraData(data,evento){
    if(mascaraInteiro(data)==false){
        evento.returnValue = false;
    }    
    return formataCampo(data, '00/00/0000', evento);
}

//adiciona mascara ao telefone
function MascaraTelefone(tel, evento){    
    if(mascaraInteiro(tel)==false){
        evento.returnValue = false;
    }
	if(tel.value!="")
		{
    		return formataCampo(tel, '(00) 0000-000', evento);
		}
		else
			{
				tel.value="";	
			}
}
//valida telefone
function ValidaTelefone(tel){
    if(tel.value!="")
		{
		exp = /\(\d{2}\)\ \d{4}\-\d{4}/
		if(!exp.test(tel.value))
			{
			alert('Telefone Inválido!'); 
			}
		}
		else
			{
				return true;	
			}
}

//valida CEP
function ValidaCep(cep){
    exp = /\d{2}\.\d{3}\-\d{3}/
    if(!exp.test(cep.value))
		{
        	alert('Cep Inválido!');  
		}
		else
			{
				return true;	
			}
}

//valida data
function ValidaData(data){
    exp = /\d{2}\/\d{2}\/\d{4}/
    if(!exp.test(data.value))
        alert('Data Invalida!');            
}
//valida o CPF digitado
function ValidarCPF(Objcpf){
    var cpf = Objcpf.value;
    exp = /\.|\-/g
    cpf = cpf.toString().replace( exp, "" );
    var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
    var soma1=0, soma2=0;
    var vlr =11;
	if(cpf=="") 
		{
			alert("O campo CNPJ/CPF é obrigatório, por favor preencha-o!");
			//Objcpf.focus();
			return false;
		}
	if((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!");
			Objcpf.value="";
			//Objcpf.focus();
			return false;
		}
	if(cpf.length!=11)
		{
			alert("CPF Inválido, tente novamente!");
			Objcpf.value="";
			//Objcpf.focus();
			return false;
		}	
		  var a = [];
		  var b = new Number;
		  var c = 11;
		  for (i=0; i<11; i++)
			{
			   a[i] = cpf.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 ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10]))
		{
        alert("CPF Inválido, tente novamente!");
			Objcpf.value="";
			//Objcpf.focus();
			return false;       
		}
}

//valida numero inteiro com mascara
function mascaraInteiro(evento){
   /* if (evento.keyCode < 48 || evento.keyCode > 57){
        evento.returnValue = false;
        return false;
    }*/
	
    return true;
}

//valida o CNPJ digitado
function ValidarCNPJ(ObjCnpj){
    var cnpj = ObjCnpj.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)));
	if(cnpj=="") 
		{
			alert("O campo CNPJ/CPF é obrigatório, por favor preencha-o!");
			Objcpf.focus();
			return false;
		}
	if((cnpj=="00000000000000") || (cnpj=="11111111111111") || (cnpj=="22222222222222") || (cnpj=="33333333333333") || (cnpj=="44444444444444") || (cnpj=="55555555555555") || (cnpj=="66666666666666") || (cnpj=="77777777777777") || (cnpj=="88888888888888") || (cnpj=="99999999999999"))
		{
			alert("CNPJ Inválido, tente novamente!");
			ObjCnpj.value="";
			ObjCnpj.focus();
			return false;
		}
	if(cnpj.length!=14)
		{
			alert("CNPJ Inválido, tente novamente!");
			ObjCnpj.value="";
			ObjCnpj.focus();
			return false;
		}
    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 Inválido, tente novamente!");
			ObjCnpj.value="";
			ObjCnpj.focus();
			return false;
		}
        
}
function formataMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;    
    // 13=enter, 8=backspace as demais retornam 0(zero)
    // whichCode==0 faz com que seja possivel usar todas as teclas como delete, setas, etc    
    if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8))
    	return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
 
 
    if (strCheck.indexOf(key) == -1) 
    	return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) 
        	break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) 
        	aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) 
    	objTextBox.value = '';
    if (len == 1) 
    	objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) 
    	objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        	objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}
//formata de forma generica os campos
function formataCampo(campo, Mascara, evento) {
    var boleanoMascara;
    
    var Digitato = evento.keyCode;
    exp = /\-|\.|\/|\(|\)| /g
    campoSoNumeros = campo.value.toString().replace( exp, "" );
  
    var posicaoCampo = 0;    
    var NovoValorCampo="";
    var TamanhoMascara = campoSoNumeros.length;;
    
    if (Digitato != 8) { // backspace
        for(i=0; i<= TamanhoMascara; i++) {
            boleanoMascara  = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".")
                                || (Mascara.charAt(i) == "/"))
            boleanoMascara  = boleanoMascara || ((Mascara.charAt(i) == "(")
                                || (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " "))
            if (boleanoMascara) {
                NovoValorCampo += Mascara.charAt(i);
                  TamanhoMascara++;
            }else {
                NovoValorCampo += campoSoNumeros.charAt(posicaoCampo);
                posicaoCampo++;
              }          
          }    
        campo.value = NovoValorCampo;
          return true;
    }else {
        return true;
    }
}


//------------------------------------------------------FIM FUNÇÕES DE MÁSCARAS DE CAMPOS

function formatamoeda(num){
x = 0;
if(num<0){
num = Math.abs(num);
x = 1;
}
if(isNaN(num)) num = 0;
cents = Math.floor((num*100+0.5)%100);
num = Math.floor((num*100+0.5)/100).toString();
if(cents < 10) cents = "0" + cents;

for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+"."
+num.substring(num.length-(4*i+3));
ret = num + "," + cents;
if (x == 1) ret = " – " + ret;
return ret;
}

function desformatar(num){
	
	num = num.replace(".","");
	num = num.replace(",",".");
	return parseFloat(num);	
}

function mudarquant(id_quant, valor, id_volt, valorprod, tdtext, valortotal, quantidade){
	
	var int = parseFloat(valor);
	var total = desformatar($('#'+valortotal).text());
	if(id_quant >= 0){
		var ajustes = (valorprod - (valorprod * (id_quant/100))) *(int);
	}else{
		var ajustes = valorprod;
		
	}
	if(valorprod == ''){
		
		valorprod = 0;
	}

	$('#'+tdtext).text(formatamoeda(ajustes));
	
	
	
	
	
	
	
	
}


function mudarquantpos (id_quant, valor, id_volt, valorprod, tdtext, valortotal){
	var int = parseFloat(valor);
	var total = desformatar($('#'+valortotal).text());
	
	if(valorprod == ''){
		
		valorprod = 0;
	}
	$('#'+id_quant).text(int+1) ;
	$('#'+tdtext).text(formatamoeda(valorprod *(int+1)));
	
	$('#'+valortotal).text(formatamoeda(total + parseFloat(valorprod)));
	
	if((total+ parseInt(valorprod)) >= 20){
		
	$('#pont').text(Math.floor((total+ parseFloat(valorprod))/20)) ;
	}
	if( int == 0){
	$('#'+id_volt).removeClass("buttonLess") ;
	$('#'+id_volt).addClass("buttonLess_disable") ;	
	}else{
	$('#'+id_volt).removeClass("buttonLess_disable") ;
	$('#'+id_volt).addClass("buttonLess") ;
	}
	
	
}

function mudarquantant (id_quant, valor, id_volt, valorprod, tdtext, valortotal){
	var int = parseFloat(valor);
	var total = parseFloat(desformatar($('#'+valortotal).text()));
	
	if(int == 1  || int == 0){
		intvai = int;
		$('#'+id_volt).addClass("buttonLess_disable") ;	
	}else if(int == 2){
		intvai = int-1;
		$('#'+id_quant).text(int-1) ;
		$('#'+valortotal).text(formatamoeda(total - parseFloat(valorprod)))
		$('#'+id_volt).addClass("buttonLess_disable") ;
		$('#pont').text(Math.floor((total- parseFloat(valorprod))/20)) ;
	}else{
		intvai = int-1;
		$('#'+id_quant).text(int-1) ;
		$('#'+valortotal).text(formatamoeda(total - valorprod))
		$('#'+id_volt).removeClass("buttonLess_disable") ;
		$('#'+id_volt).addClass("buttonLess") ;	
		$('#pont').text(Math.floor((total- parseFloat(valorprod))/20)) ;
		
	}
	
	
	$('#'+tdtext).text(formatamoeda(valorprod *intvai));
	
}

function remover(desliga,valortd, valortotal, idtarget, desliga1){
	var total = parseFloat(desformatar($('#'+valortotal).text()));
	var totaltd = parseFloat(desformatar($('#'+valortd).text()));
	var valortotalresult = total-totaltd;
	$('#'+valortotal).text(formatamoeda(valortotalresult));
	$('#pont').text(Math.floor(valortotalresult/20)) ;
	$('#'+desliga).hide("fast");
	$('#'+desliga1).hide("fast");
	menulink1('carrinho.php','carrinhocontent','&excluir=sim&id='+idtarget,'loading12');

								
}

function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}
function Formata(campo,tammax,teclapres,decimal) {
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal
	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
	
	if (tecla == 8 )
	{ tam = tam - 1 ; }
	
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
	{
	
	if ( tam <= dec )
	{ campo.value = vr ; }
	
	if ( (tam > dec) && (tam <= 5) ){
	campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 6) && (tam <= 8) ){
	campo.value = vr.substr( 0, tam - 5 ) + "" + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
	}
	if ( (tam >= 9) && (tam <= 11) ){
	campo.value = vr.substr( 0, tam - 8 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 12) && (tam <= 14) ){
	campo.value = vr.substr( 0, tam - 11 ) + "" + vr.substr( tam - 11, 3 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
	if ( (tam >= 15) && (tam <= 17) ){
	campo.value = vr.substr( 0, tam - 14 ) + "" + vr.substr( tam - 14, 3 ) + "" + vr.substr( tam - 11, 3 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
	} 

}

   function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
	
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8 &&  tecla != 0) return false;
	else return true;
    }
}


function valuenulo(ids, value, tipo){
		if(tipo == 'f'){
			if($('#'+ids.id).attr('value') == value)
				$('#'+ids.id).attr('value','');
		}
		
			if(tipo == 'b'){
				if($('#'+ids.id).val() == '')
					$('#'+ids.id).attr('value',value);
		}
}

function enviabusca(busca1,busca2){
	
		newbusca1 = (($('#busca1').val()!='') && ($('#busca1').val() != busca1)) ? $('#busca1').val()+'/' : 'autor/';
		newbusca2 = (($('#busca2').val()!='') && ($('#busca2').val() != busca2)) ? $('#busca2').val()+'/' : 'nome/';
		window.location= urlprincipal+'busca/topo/'+newbusca2+newbusca1;
	
}

function redimensionasoft(dim,aum,ids){

	if($('#'+ids.id).attr('title') == dim){
		$('.softGamesTopSubConteudo').attr('style','width:400px;');	
		$('.softCursoTopSubConteudo').attr('style','width:400px;');	
		$('.corcont').attr('style','width:421px;');
		$('.corcontcurso').attr('style','width:421px;');
		$('.conteudosoftware').attr('style','width:450px;');
		$('#'+ids.id).attr('title',aum);
	}else{
		$('.softCursoTopSubConteudo').attr('style','width:850px;');	
		$('.softGamesTopSubConteudo').attr('style','width:850px;');	
		$('.corcont').attr('style','width:871px;');	
		$('.corcontcurso').attr('style','width:871px;');
		$('.conteudosoftware').attr('style','width:900px;');
		$('#'+ids.id).attr('title',dim);
		
	}
}


$(function () {
	function removeCampo() {
		$(".removerCampo").unbind("click");
		$(".removerCampo").bind("click", function () {
			i=0;
			$("#tabelasite tbody .removerCampo").each(function () {
				i++;
				
			});
			if (i>1) {
				
				$(this).parent().parent().parent().remove();
				
			}
		});
	}
	
	$(".adicionarCampo").click(function () {
		novoCampo = $("#tabelasite tbody:first").clone();
		novoCampo.find("input").val($('#registro input:text[name=sites]').val());
		novoCampo.find("img").css('display','');
		
		$('#registro input:text[name=sites]').val('http://');
		novoCampo.insertAfter("#tabelasite tbody:last");
		removeCampo();
	});
});


function mudaform(valor){
	
	if(valor=='1'){
		$("#empresaform").css('visibility','hidden');
		$("#empresaform1").css('visibility','hidden');
		$("#dataniver").css('visibility','hidden');
		$("#dataniver1").css('visibility','hidden');
		
		
		var razao = $("#razao").html();
		$("#razao").html($('#razao').attr('lang'));
		$('#razao').attr('lang', razao);
		var fantasia = $("#fantasia").html();
		$("#fantasia").html($('#fantasia').attr('lang'));
		$('#fantasia').attr('lang', fantasia);
		var cnpj = $("#cnpj").html();
		$("#cnpj").html($('#cnpj').attr('lang'));
		$('#cnpj').attr('lang', cnpj);
		
		$('#registro input:text[name=cpf]').val('');
		$('#registro input:text[name=cpf]').attr('onkeydown','MascaraCNPJ(this,"",event)');
		$('#registro input:text[name=cpf]').attr('maxlength',"18");
	}else{
		$("#empresaform").css('visibility','');
		$("#empresaform1").css('visibility','');
		$("#dataniver").css('visibility','');
		$("#dataniver1").css('visibility','');
		
		
		var razao = $("#razao").html();
		$("#razao").html($('#razao').attr('lang'));
		$('#razao').attr('lang', razao);
		var fantasia = $("#fantasia").html();
		$("#fantasia").html($('#fantasia').attr('lang'));
		$('#fantasia').attr('lang', fantasia);
		var cnpj = $("#cnpj").html();
		$("#cnpj").html($('#cnpj').attr('lang'));
		$('#cnpj').attr('lang', cnpj);
		
		
		$('#registro input:text[name=cpf]').val('');
		$('#registro input:text[name=cpf]').attr('onkeydown','MascaraCPF(this,"",event)');
		$('#registro input:text[name=cpf]').attr('maxlength',"14");
	}
}


function gerarcodigo(chave,erro,erro2){
	var links = $('#registro input:text[name=link]').val();
	var img = $('#registro input:text[name=img]').val();
	var tipo = $('#registro input:radio[name=tipo]:checked').val();
	$('#registro textarea[name=textcodigo]').val('');
	if(links.indexOf(urlprincipal) < 0 ){
		MostraRegistroFiliados(erro);
		return false;
	}
	if(tipo == 2){
		if(img.indexOf(".jpg") < 0 && img.indexOf(".png") < 0 && img.indexOf(".gif") < 0 && img.indexOf(".jpeg") < 0   ){
			MostraRegistroFiliados(erro2);
			return false;
		}
	}
	if(tipo == 1){
			img = $('#ImgTipo1').attr('src');
	}
	if(tipo == 0){
			img = $('#ImgTipo0').attr('src');
	}
	links = (links.charAt(links.length-1)!='/')? links+'/'+chave+'/': links+chave+'/';
	
	var areahtml = '<a href="'+links+'" target="_blank"><img src="'+img+'" border="0" /></a>'; 
	
	$('#registro textarea[name=textcodigo]').val(areahtml);
	$('#registro textarea[name=textcodigo]').focus();
}

function estacaoconteudo(id){
	for(i=0;i<8;i++){
		$('#controle'+i).hide();
		$('#btn'+i).removeClass().addClass("menusoft btn");
	}
	
	$('#controle'+id).show();
	$('#btn'+id).addClass("menusoft btnmarca");
	
}

  

	

   
