//checagens para assinatura
var promocao        = false;
var obrigaCNPJ      = 0;
var obrigaCPF       = 0;
var acao_pesq       = 0;
var passo           = 1;
var valor           = 0;
var desconto        = 0;
var valor_plano     = 0;
var valor_base_op1  = 0;
var valor_base_op2  = 0;
var valor_base_op3  = 0;
var valor_base_op4  = 0;
var valor_ad_web    = 0;
var valor_ad_disco  = 0;
var valor_ad_mysql  = 0;
var valor_ad_mail   = 0;
var valor_ad_transf = 0;
var valor_tarifas   = 0;
var dom_pesq        = '';
var suf_pesq        = '';
var plano           = '';
var pgto            = '';
var txt_prom        = '';
var txt_ad          = '';
var txt_base_op1    = '';
var txt_base_op2    = '';
var txt_base_op3    = '';
var txt_base_op4    = '';
var txt_ad_web      = '';
var txt_ad_disco    = '';
var txt_ad_mysql    = '';
var txt_ad_mail     = '';
var txt_ad_transf   = '';
var valor_turbomail = 0;
var txt_turbomail   = '';
var passoold        = 0;

try{
   window.addEventListener('load',createAll,true);
   }
catch(e){ }

function createAll(){
	var todos = document.getElementsByTagName('*');
	document.all = {};
	for (var i=0;i<todos.length;i++){
		delete name;
		var name = (typeof todos[i].name!='undefined')? todos[i].name:todos[i].id;
		if(typeof name == 'undefined'){
		 	 continue;
		   }
		
		if(typeof document.all[todos[i].name] == 'undefined'){
			 document.all[name] = todos[i];
		   }
		else{
			  if(typeof document.all[name].length =='undefined'){
				   document.all[name] = new Array(document.all[name]);
			     }
			  document.all[name].push(todos[i]);
		    }
	  }
 }

/* 1 = inicial; 	2 = basico;       3 = ideal;
	 4 = avancado;  5 = profissional; 6 = reserva;  72 = economico;*/	
		 
function iniciar(acao){
	acao_pesq = acao;
 	if (acao == '1'){
		DominioConf();
        }
  }

function DominioConf(){
	var bRetorno = true;
	var dominio  = document.getElementById('n_dom');
	var ext      = document.getElementById('ext');
		
	carrega('','Aguarde...');
	
    dominio.value = dominio.value.toLowerCase();
    bRetorno = checar(dominio);
	
    if (bRetorno) {
   	   if (InStr(dominio.value,'.')>0){
		    if (ext.options[ext.selectedIndex].value == 'nom.br'){
		       abrir(2);
			    }
			  else { alert("Atenção, não se deve digitar a extensão no campo do domínio.\nO domínio "+dominio.value+ "." + ext.options[ext.selectedIndex].value+" está incorreto.");
                     dominio.focus(); return false; 
				    }
		    }
		    else {
				 abrir(2);
				 }
	   }
	else{carrega('none','');}
	return bRetorno;
  }

/* ======================== */

function abrir(n) {
	var aPagamentos = document.getElementsByName('pagamento');
	carrega('','Processando...'); 

	box();
	//#######
	var testacelular = document.getElementById('celular').value;
	if (testacelular.substring(0,2) == "88" || testacelular.substring(0,2) == "87" || testacelular.substring(0,2) == "86"){
	   document.getElementById('pagto_oippago').style.display = '';
	   }
	else{
		document.getElementById('pagto_oippago').style.display = 'none';
		}
	
	var retorno = confirma(n);
	if (retorno == ''){
		document.getElementById('ass-direita').style.display = 'none';
		if (passo >= n){			
			if (n == 1) {
				document.getElementById('box_total').style.display = 'none';
			    }
		    else { 
			     document.getElementById('box_total').style.display = '';
			     document.getElementById('ass-direita').style.display = '';
				 }
			
			if (n == 2 && document.getElementById('opc_txt').value == 'novo'){
			   document.getElementById('barra_detalhes').style.height = 9;
		       }
		    else if (n == 2 && document.getElementById('opc_txt').value == 'transf'){
				    document.getElementById('barra_detalhes').style.height = 9;
					} 
			else if (n > 2){
				   document.getElementById('barra_detalhes').style.height = 9;
			} else {
				   document.getElementById('barra_detalhes').style.height = 9;
				   }
				   
			if (n !== 5) { 
			   limpa();	 
			   eval("document.getElementById('p" + n + "').style.display=''");
			   }
			else {
                 if (document.getElementById('p5').style.display == ''){
   		             //document.getElementById('p5').style.display='none';
				    }
				 else
  				    eval("document.getElementById('p" + n + "').style.display=''");
			     }

		try {
			if (n > passoold){ document.getElementById('img_passos'+(n-1)).src = 'imagens/bt-assina-'+(n-1)+'.jpg'; }
			else             { document.getElementById('img_passos'+(n+1)).src = 'imagens/bt-assina-'+(n+1)+'.jpg'; }
		    document.getElementById('img_passos'+n).src = 'imagens/bt-assina-'+n+'-on.jpg';
			passoold = n;
		    }
		catch(e){ }
		
		carrega('none','');
	    return true;
		}	
	}else{
		  if ((retorno != 'FormPesq') && (retorno != 'FormError')){ alert(retorno); }
	    carrega('none','');
		return false;
	    }
}

/* ======================== */

function limpa(){
	document.getElementById('box_prom_registro').style.display='none';
	for (i=1;i<=4;i++){ //aki 5
			eval("document.getElementById('p" + i + "').style.display='none'");
			}
	//sel_plano(3,'Ideal');
	//document.all.rbPlano[0].checked=true;
	//document.all.pagamento[1].checked=true;
    }

/* ======================== */

function AlteraCartao(){
	document.getElementById('retcartao').value = 0;
	}

function confirma(n){
	// n é acao e nao plano
	var txt = '';
	var dominio    = document.getElementById('n_dom');
	var sufixo     = document.getElementById('ext');
	var codplano   = document.getElementById('cod_plano');
	var pagamento  = document.all.pagamento;
	var formapagto = document.all.forma_pagto;
	var rbplano    = document.all.rbPlano;
	var opcaoform  = document.all.opc;
	var check_dominio  = document.getElementById('check_dominio').value;
	var PlanoEscolhido = GetFormaPagto();

  if ( n > 1){
	 if (dominio.value == '' && txt == ''){ 
	    txt = "Informe o nome do Domínio para o registro!"; 
		dominio.value = '';
		dominio.focus(); //return false;
	    }
	 }
			
  if (n >2 && n != 5){
	 if (txt == ''){	
	    txt = ValidaForm();
		}
	 }
		 
  if (n >3 && n != 5){ // 
	 if ((pagamento[0].checked == false) && (pagamento[1].checked == false) && 
         (pagamento[2].checked == false) && (pagamento[3].checked == false) && (pagamento[4].checked == false) && (txt == '')){
		  txt="Selecione o Tipo de Pagamento para o registro!";
		  }	
		else if ((PlanoEscolhido == false ) && (txt == '')){
		    txt="Selecione a Forma de Pagamento para o registro!";
		    }
	
	  if (PlanoEscolhido == 'visacard' || PlanoEscolhido == 'mastercard' || PlanoEscolhido == 'dinerscard' || PlanoEscolhido == 'amex'){
		 txt = '';
		 if (!document.getElementById('cartao_resp').value)         {txt = 'Informe o nome impresso no cartão';}
		 else if (!document.getElementById('cartao_numero').value)  {txt = 'Informe o número do cartão';}
		 else if (!document.getElementById('cartao_mes').selectedIndex == 1){txt = 'Informe o mês de vencimento do cartão';}
		 else if (!document.getElementById('cartao_ano').selectedIndex == 1){txt = 'Informe o ano de vencimento do cartão';}
		 else if (!document.getElementById('cartao_seguraca').value){txt = 'Informe o código de segurança do cartão';}
		 
		 var retcartao = document.getElementById('retcartao').value;
		 
		 if (txt=='' && retcartao==0){
			//checar frame
		    var rand = Math.random();
			XXYY  = document.getElementById('cartao_numero').value+"|#|";
			XXYY += document.getElementById('cartao_mes').value+"|#|";
			XXYY += document.getElementById('cartao_ano').value+"|#|";
			XXYY += document.getElementById('cartao_seguraca').value+"|#|";
			XXYY += PlanoEscolhido+"|#|";
			XXYY += document.getElementById('cartao_resp').value;
			
			document.getElementById('campo_aux').value = XXYY;
			document.getElementById('form_aux').action = 'ver_cartao.php?z='+rand;
		    document.getElementById('form_aux').target = 'frmAux';
		    document.getElementById('form_aux').submit();
			return false;
			}
		 
		 }
	   /*else if (document.getElementById('agree').checked == false && txt == ''){
		         txt="É necessário que você aceite os termos do contrato para o registro!";
		         }*/
		CarregaFinalizacao();
	  }
	
	//alert(n);
	
	// Valida dominio
	if (txt == '' && check_dominio==''){// && dominio.value != '' && (dominio.value != dom_pesq || sufixo.options[sufixo.selectedIndex].value != suf_pesq)){			
		dom_pesq  = dominio.value;
		suf_pesq  = sufixo.options[sufixo.selectedIndex].value;
		var pesquisa2 = '';
		txt       = "FormPesq";
		document.getElementById('dominio1').innerHTML = '';
		document.getElementById('dominio2').innerHTML = '';
		document.getElementById('dominio2').style.display = 'none';
		
		if (opcaoform[2].checked || opcaoform[3].checked){
		   var dominio2 = document.getElementById('n_dom2');
		   var sufixo2  = document.getElementById('ext2');
			
		   dom_pesq2 = dominio2.value;		
		   suf_pesq2 = sufixo2.options[sufixo2.selectedIndex].value;
		   pesquisa2 = '&dom2='+dom_pesq2+'&suf2='+suf_pesq2+'&num=2';
		   document.getElementById('dominio2').innerHTML = '2 - '+dom_pesq2+'.'+suf_pesq2+' (Redir)';
		   document.getElementById('dominio2').style.display = '';
		   }
		//alert(pesquisa2);			
		document.getElementById('frmAux').src='ver_dominio2.php?n='+n+'&dom='+dom_pesq+'&suf='+suf_pesq+'&acao='+acao_pesq+pesquisa2;
		document.getElementById('dominio1').innerHTML = '1 - '+dom_pesq+'.'+suf_pesq;
		acao_pesq = '0';
		//return false;
	    }
			
  if (n > 2 && txt == '' && n != 5) {
	 document.getElementById('frmAssina').submit();
	 }
		 
  if (n == 5 && txt == '' && codplano.value == '') {
	 txt="É necessário que você selecione algum dos planos para a seleção de opcionais!";
	 }
 
  if (n==5 && codplano.value == 6){
	 txt = "Este plano não tem opcionais."; 
	 }
 
  if (txt == '') { 
	 passo = n;
	 }

  if( opcaoform[2].checked && (rbplano[0].checked || rbplano[6].checked) ){
	txt = "Esta promoção não aceita planos Reserva ou Econômico."; 
	}
		
  return txt;
  }

/* ========== */
function mudax(){
  document.getElementById('check_dominio').value='';
  }

/* ======================== */

function box(){
	var cod_plano  = document.getElementById('cod_plano').value;
	var PagamentoEscolhido = GetFormaPagto();
	
	if (PagamentoEscolhido=='boleto' && document.all.pagamento[0].checked == true && cod_plano !== '6' && cod_plano !== '7' ){ 
   	   document.getElementById('avisotarifa').style.display='';
	   valor_tarifas = 2;
	   }
	else {
       document.getElementById('avisotarifa').style.display='none';
   	   valor_tarifas = 0; 
	     }

  var valplanonormal = 0;
	if (cod_plano) valplanonormal = eval("pl"+cod_plano);
  
	if (pgto == "Mensal"){
		 valor_plano = document.getElementById('val_m').innerHTML;
		 desconto = 0
		 }
	else if (pgto == "Trimestral"){
		 valor_plano = document.getElementById('val_t').innerHTML;
		 valplanonormal *= 3;

		if(cod_plano == 4 || cod_plano == 5){
		  desconto = 3;
		  }

		 }
	else if (pgto == "Semestral"){
		 valor_plano = document.getElementById('val_s').innerHTML;
		 valplanonormal *= 6;

		 if(cod_plano == 2 || cod_plano == 72){desconto = 0;}
		 }
	else if (pgto == "Anual"){
		 valor_plano = document.getElementById('val_a').innerHTML;
		 valplanonormal *= 12;
		 
		 if(cod_plano == 72){desconto = 0;}
		 }
	else{
		 valor_plano = document.getElementById('val_b').innerHTML;
		 valplanonormal *= 24;
		 
		 if(cod_plano == 72){desconto = 0;}
		 }
	
	if (document.getElementById('opc_txt').value != 'novo'){ document.getElementById('pEscolhe').style.display='none';}
	else{
		 if (cod_plano != 72){
		    //document.getElementById('pEscolhe').style.display='';
		    document.getElementById('opc_txt').value = 'novo';
		    }
		 //alert(document.getElementById('opc_txt').value);
	    }
	
	//
	if (cod_plano == 6 || cod_plano == 7 || cod_plano == 72 || document.all.opc[3].checked){ //reservas
	   //limpar opcionais
	   desconto = 0;
	   document.getElementById('pEscolhe').style.display='none';
	   }

	if (pgto != "Semestral" && pgto != "Anual" ){
	   document.getElementById('pEscolhe').style.display='none';		
	   }

	valor       = valor_plano;
	temp_desc   = 1-(desconto/100);	
    temp_desc_v = valplanonormal * (desconto/100);
	
	valor_plano = valor_plano.replace(',','.');
	valor_plano *= 1;

    valor_plano += (valor_base_op1+
						valor_base_op2+
						valor_base_op3+
						valor_base_op4+
						valor_ad_web+
						valor_ad_disco+
						valor_ad_mysql+
						valor_ad_mail+
						valor_ad_transf+
						valor_tarifas+
						valor_turbomail) * document.getElementById('n_pagto').value;
	 
	document.getElementById('txt_valor').innerHTML= format_number(valor_plano,2);

  // opcionais 2 - banco, trafego, etc
	document.getElementById('opcionais2').style.display=''; 
	if (cod_plano == 1 || cod_plano == 2){     // incial e basico
		 document.getElementById('opcionais2').style.display='none';
		 }

   ad_txt();
   vepromocao();
	
  if (desconto > 0){
		 document.getElementById('txt_desc').innerHTML    = desconto;
		 document.getElementById('txt_desc_v').innerHTML  = format_number(Arredonda(temp_desc_v),2);
		 document.getElementById('box_desc').style.display= "inline";
	   }
	else{
		  document.getElementById('box_desc').style.display="none";
	    }
	
	if (plano != ''){
		document.getElementById('txt_plano').innerHTML=plano;
		document.getElementById('box_plano').style.display="inline";
	  }
	else{
		  document.getElementById('box_plano').style.display="none";
	    }

	if (pgto != ''){
		 document.getElementById('txt_pgto').innerHTML=pgto;
		 document.getElementById('box_pgto').style.display="inline";
	   }
	else{
		  document.getElementById('box_pgto').style.display="none";
	    }

	if (txt_ad != ''){
		 document.getElementById('txt_opc').innerHTML=txt_ad;
		 document.getElementById('box_opc').style.display="inline";
	   }
	else{
		  document.getElementById('txt_opc').innerHTML='';
		  document.getElementById('box_opc').style.display="none";
	    }
			
	if (promocao == true) { 
		 document.getElementById('txt_prom').innerHTML=txt_prom;
		 document.getElementById('box_prom').style.display="inline";
	   }
	else {
		   document.getElementById('txt_prom').innerHTML='';
		   document.getElementById('box_prom').style.display="none";
	     }
  
  //document.getElementById('p3').style.display='';//AKI
  }

/* ======================== */

function ad_txt(){
	txt_ad = '';
	if (txt_base_op1  != ''){txt_ad += txt_base_op1  + '<br>'};
	if (txt_base_op2  != ''){txt_ad += txt_base_op2  + '<br>'};
	if (txt_base_op3  != ''){txt_ad += txt_base_op3  + '<br>'};
	if (txt_base_op4  != ''){txt_ad += txt_base_op4  + '<br>'};
	if (txt_ad_web    != ''){txt_ad += txt_ad_web    + '<br>'};
	if (txt_ad_disco  != ''){txt_ad += txt_ad_disco  + '<br>'};
	if (txt_ad_mysql  != ''){txt_ad += txt_ad_mysql  + '<br>'};
	if (txt_ad_mail   != ''){txt_ad += txt_ad_mail   + '<br>'};
	if (txt_ad_transf != ''){txt_ad += txt_ad_transf + '<br>'};
	if (txt_turbomail != ''){txt_ad += txt_turbomail + '<br>'};
}

function ad_txt_null(){
	txt_ad = '';
	txt_base_op1  = '';
	txt_base_op2  = '';
	txt_base_op3  = '';
	txt_base_op4  = '';
	txt_ad_web    = '';
	txt_ad_disco  = '';
	txt_ad_mysql  = '';
	txt_ad_mail   = '';
	txt_ad_transf = '';
	//txt_turbomail = '';
}

/* ======================== */

function vepromocao(){   
		var codplano   = document.getElementById('cod_plano').value;
		var pagamento  = document.all.pagamento;
		
		document.getElementById('txt_promocao').value = '';
        var PagtoEscolhido = GetFormaPagto();

		//---------------------------------------
		// Promoção registro internacional ou registro total
		//--------------------------------------- 
		var opcaoform  = document.all.opc;
		var promoreg   = true;
		if (opcaoform[2].checked || opcaoform[3].checked){ promoreg = false; }
  

		//---------------------------------------
		// Promoção TAXA DE REGISTRO GRÁTIS
		//--------------------------------------- 
		 //if (document.getElementById('opc_txt').value == 'novo' && promoreg){
		 if (document.getElementById('opc_txt').value == 'novo' && (document.all.pagamento[3].checked == true) && promoreg){
			 //if (codplano != 6 ) {
			 if (codplano > 1 && codplano < 6) {
				 txt_prom = 'Taxa de Registro GRÁTIS!';	
				 document.getElementById('txt_prom_registro').innerHTML=txt_prom;
				 document.getElementById('box_prom_registro').style.display="inline";				 
				 }
			 else { document.getElementById('box_prom_registro').style.display="none"; }
	         }
		 else { document.getElementById('box_prom_registro').style.display="none"; }

		//--------------------------------------- 
		// Promoção PAGAMENTO POR CARTAO DEBITO/CREDITO
		//--------------------------------------- 
		 if (codplano == 72)     {promocao = false;}
		 else if (codplano == 6) {promocao = false;}
		 else if (document.all.pagamento[0].checked) {promocao = false;}
		 else{
		     if (PagtoEscolhido == 'visacard' || PagtoEscolhido == 'mastercard' || PagtoEscolhido == 'dinerscard' ||
			     PagtoEscolhido == 'amex' || PagtoEscolhido == 'debito'){
				 promocao  = true;
 				 valor     = valor_plano;					
				 temp_desc = (valor * 10)/100;
				 valor    -= temp_desc;	
				 txt_prom	 = "10% de desconto! Débito / Crédito <br>( R$ " + format_number(temp_desc,2) +')';
				 document.getElementById('txt_valor').innerHTML=format_number(valor,2);					 
				 }
			 else{ promocao = false;}
		     }
		}

/* ======================== */

function sel_plano(n,nome){
  plano_preco(0);

	var formapagto = document.all.forma_pagto;
	var pagamento  = document.all.pagamento;
	var opcaoform  = document.all.opc;
	
	if ((opcaoform[2].checked || opcaoform[3].checked) && (n==6 || n==7 || n==1)){
	   alert('Plano incompativel com a promoção');
	   n    = 3;
	   nome = 'Ideal';
	   document.all.rbPlano[3].checked=true;
	   }
	
    var valorplano = eval("pl"+n);
	var vl_t1      = valorplano * 3;
	var vl_s1      = valorplano * 6;
	var vl_a1      = valorplano * 12;
	var vl_b1      = valorplano * 24;

	plano          = nome;
	var vl_t       = vl_t1;
	var vl_s       = vl_s1 - ((vl_s1*5)/100);
	var vl_a       = vl_a1 - ((vl_a1*10)/100);
	var vl_b       = vl_b1 - ((vl_b1*15)/100);
	var desc_s     = "&nbsp;&nbsp;(<b>-5%</b>)";
	var desc_a     = "&nbsp;&nbsp;(<b>-10%</b>)";
	var desc_b     = "&nbsp;&nbsp;(<b>-15%</b>)";
	var desc_t     = "";
	
	// basico / superturbo nao tem desconto semestral
	if(n == 2 || n == 72){
	  vl_s   = vl_s1;
	  desc_s = "";
	  desconto = 0;
	  }
	
	//superturbo nao tem desconto
	if(n == 72){
	  vl_a   = vl_a1;
	  vl_b   = vl_b1;
	  desc_s = "";
	  desc_b = "";
	  desc_a = "";
	  desconto = 0;
	  }


	if(n == 4 || n == 5){
	  vl_t   = vl_t1 - ((vl_t1*3)/100);
	  desc_t = "&nbsp;&nbsp;(<b>-3%</b>)";
	  desconto = 3;
	  }


   document.getElementById('cod_plano').value = n;
   document.getElementById('opcionais').style.display='none';
   //document.getElementById('p5').style.display='none';
   ad_txt_null();
    
   if (n != 6 && n != 7 && n != 1)	{ // planos reservas , incial
	   document.getElementById('opcionais').style.display='';
	   }

  for (i=0;i<10;i++){
	   try{ formapagto[i].checked = false; }
		catch(e){}
	    }
  
  for (i=0;i<4;i++){
 	  pagamento[i].checked  = false;
	  pagamento[i].disabled = false;
	  }
	
	document.getElementById('txtpg1').style.display= '';
	document.getElementById('plano_nome').value    = nome;
	document.getElementById('n_pagto').value       = 1;

  pgto = "Trimestral"; //Mensal
	//|| n == 72
  if (n == 6 || n == 7 || opcaoform[3].checked){ // reservas e economico
		 pagamento[0].disabled = true;
		 pagamento[1].disabled = true;
		 pagamento[2].disabled = true;
		 pagamento[3].checked  = true;
		 pgto = "Anual";
		 }
	/*else if (n == 1 || n == 2){     // incial e basico
			pagamento[1].checked  = true
			pagamento[0].disabled = true;
			pgto = "Trimestral";
			}*/
	else if (n == 72){ //superturbo semestral
		 pagamento[0].disabled = true;
		 pagamento[1].disabled = true;
		 pagamento[2].disabled = true;
		 pagamento[3].checked  = true;
		 pgto = "Anual";
		 }
	else{
		pagamento[1].checked  = true
		pagamento[0].disabled = true;
		pgto = "Trimestral";
		}
	
	if (n != 6 && n != 7){ // <> reservas e economico
		 document.getElementById('val_m').innerHTML=format_number(valorplano,2);   // Mensal
		 document.getElementById('val_t').innerHTML=format_number(vl_t,2); // Trimestral			
		 document.getElementById('val_tdesc').innerHTML=desc_t;
		 document.getElementById('val_s').innerHTML=format_number(vl_s,2);
		 document.getElementById('val_sdesc').innerHTML=desc_s;    // Semestral
		 document.getElementById('val_a').innerHTML=format_number(vl_a,2);    // Anual
		 document.getElementById('val_adesc').innerHTML=desc_a;
		 document.getElementById('val_b').innerHTML=format_number(vl_b,2);    // Bienal
		 document.getElementById('val_bdesc').innerHTML=desc_b;
		if (opcaoform[3].checked){ // ganhe2
		    document.getElementById('val_a').innerHTML=format_number(valorplano * 12,2); 
			}
		 }
	else{
		 if (opcaoform[3].checked){ // ganhe2
		    document.getElementById('val_a').innerHTML=format_number(valorplano * 12,2); 
			vl_b = valorplano * 24;
			}
		 else if (n == 72){ // economico Anual
				        document.getElementById('val_a').innerHTML=format_number(valorplano * 12,2); 
						vl_b = valorplano * 24;
						document.getElementById('val_bdesc').innerHTML=desc_b;
			            }
			  else { //reservas
				   document.getElementById('val_a').innerHTML=format_number(valorplano,2);
				   vl_b = valorplano*2;
				   }

			document.getElementById('val_b').innerHTML=format_number(vl_b,2);    // Bienal			
			document.getElementById('val_m').innerHTML=format_number(0,2); // Mensal
			document.getElementById('val_t').innerHTML=format_number(0,2); // Trimestral
			document.getElementById('val_s').innerHTML=format_number(0,2); // Semestral	
			}


  // reseta todos os opcionais
	if (n == 6){
		valor_turbomail = 0;
		txt_turbomail = '';
		document.getElementById('op4').checked = false;
	document.getElementById('cb_ad_web').selectedIndex   = 0;
	document.getElementById('cb_ad_disco').selectedIndex = 0;
	document.getElementById('cb_ad_mysql').selectedIndex = 0;
	document.getElementById('cb_ad_mail').selectedIndex  = 0;
	document.getElementById('cb_ad_transf').selectedIndex= 0;
	
    valor_base_op1 = 0;
	valor_base_op2 = 0;
	valor_base_op3 = 0;
	valor_base_op4 = 0;
	valor_ad_web   = 0;
	valor_ad_disco = 0;
	valor_ad_mysql = 0;
	valor_ad_mail  = 0;
	valor_ad_transf= 0;
	valor_tarifas  = 0;
	   }
	// refaz a tela
	adicionais(9,0);
	box();
}

function plano_preco(n){
  var txt_info   = '';
	
	if(n == 0){
		pgto        = "Mensal";
		desconto    = 0;
		}
	else if(n == 1){
		pgto        = "Trimestral";
		txt_info    = 'x 3';
		desconto    = 0;
		}
	else if(n == 2){
		pgto        = "Semestral";
		txt_info    = 'x 6';
		desconto    = 5;
		}
	else if(n == 3){
		pgto        = "Anual";
		txt_info    = 'x 12';
		desconto    = 10;
		}
	else if(n == 4){
		pgto        = "Bienal";
		txt_info    = 'x 24';
		desconto    = 15;
		}
	
  for(i=1;i<9;i++){
	 //eval("document.getElementById('pg_info"+i+"').innerHTML='"+txt_info+"';");
	 }
	box();
}

function Arredonda(n){
	return Math.round(n*100)/100;
}

function desc(n){
	desconto = n;
	box();
}

function adicionais(n,qtd){
	
	var pagamento  = document.all.pagamento;
	var pagsel     = 1;
	var multiplicador = 1;
	var pagtos     = new Array();
	pagtos['Mensal']     = 1;
	pagtos['Trimestral'] = 3;
	pagtos['Semestral']  = 6;
	pagtos['Anual']      = 12;
	pagtos['Bienal']     = 24;

	for (i=0;i<5;i++){
 	    if (pagamento[i].checked == true) pagsel = pagamento[i].value;
	    }
   
    for (var i in pagtos){
	    if (i == pagsel){multiplicador = pagtos[i];}
        }
   //alert(pagsel+'='+multiplicador);

  switch (n) {
		case 0:
			if (qtd == 0){
				valor_base_op1 = 0;
				valor_base_op2 = 0;
				valor_base_op3 = 0;
				valor_base_op4 = 0;
				txt_base_op1 = '';
				txt_base_op2 = '';
				txt_base_op3 = '';
				txt_base_op4 = '';
				valor_ad_disco = 0;
				document.getElementById('tval_sql').innerHTML="0";
				txt_ad_disco = '';
				document.getElementById('cb_ad_disco').disabled=true;
				document.getElementById('cb_ad_disco').selectedIndex=0;
			}else if(qtd == 1){
				if (document.getElementById('op1').checked == true) { 
				  if (getCheckedValue(document.getElementById('rbSuporte')) == 'S')
   					valor_base_op1 = op1 * multiplicador;
					else	
   					valor_base_op1 = op2 * multiplicador;
					txt_base_op1 = 'TurboShopping';
				}
				else { valor_base_op1 = 0; txt_base_op1 = ''; }	
			}else if(qtd == 2){
				if (document.getElementById('op2').checked == true) {
  				valor_base_op2 = op3 * multiplicador;			
	  			txt_base_op2 = 'Disco Virtual 15 Mb';
				}
				else{ valor_base_op2 = 0; txt_base_op2 = ''; adicionais(2,0); }
			}else if(qtd == 3){
				if (document.getElementById('op3').checked == true) {
					valor_base_op3 = op4 * multiplicador;
					txt_base_op3 = 'TurboChat';
				}
				else { valor_base_op3 = 0; txt_base_op3 = '';	}
			}else if(qtd == 4){
				if (document.getElementById('op4').checked == true) {
					valor_base_op4 = op4 * multiplicador;
					txt_base_op4 = 'Album de Fotos';
				}
				else{ valor_base_op4 = 0;	txt_base_op4 = ''; }
			}
			if (document.getElementById('op2').checked == true) document.getElementById('cb_ad_disco').disabled=false;
			else { document.getElementById('cb_ad_disco').disabled=true;	document.getElementById('cb_ad_disco').selectedIndex=0; }
			break;
		
		case 1:
			if (qtd != 0){
				valor_ad_web = ad_web * qtd * multiplicador;
				document.getElementById('tval_web').innerHTML= valor_ad_web;
				txt_ad_web = "+ " + qtd + " Mb Espaço Web";
			}else{
				valor_ad_web = 0;
				document.getElementById('tval_web').innerHTML="0";
				txt_ad_web = '';				
			}
			break;

		case 2:
			if (qtd != 0){
				valor_ad_disco = ad_disco * qtd * multiplicador;
				document.getElementById('tval_sql').innerHTML= valor_ad_disco;
				txt_ad_disco = "+ "+qtd + " Mb  Disco Virtual";
			}else{
				valor_ad_disco = 0;
				document.getElementById('tval_sql').innerHTML="0";
				txt_ad_disco = '';				
			}
			break;

		case 3:
			if (qtd != 0){
				valor_ad_mysql = ad_mysql * qtd * multiplicador;
				document.getElementById('tval_mysql').innerHTML=valor_ad_mysql;
				txt_ad_mysql = "+ "+qtd + " Base MySQL";
			}else{
				valor_ad_mysql = 0;
				document.getElementById('tval_mysql').innerHTML="0";
				txt_ad_mysql = '';				
			}
			break;

		case 4:
			if (qtd != 0){
				valor_ad_mail = ad_mail * qtd * multiplicador;
				document.getElementById('tval_mail').innerHTML= valor_ad_mail;
				txt_ad_mail = "+ " + qtd + " Mb de e-mail";
			}else{
				valor_ad_mail = 0;
				document.getElementById('tval_mail').innerHTML="0";
				txt_ad_mail = '';				
			}
			break;

		case 5:
			if (qtd != 0){
				valor_ad_transf = ad_transf * qtd * multiplicador;
				document.getElementById('tval_transf').innerHTML = valor_ad_transf;
				txt_ad_transf = "+ "+qtd + " Gb de Transferência";
			}else{
				valor_ad_transf = 0;
				document.getElementById('tval_transf').innerHTML="0";
				txt_ad_transf = '';				
			}
			break;

		case 6:
		    if (document.getElementById('op4').checked == false) {
				qtd = 0;
			   }
			   //alert(multiplicador);
			if (qtd != 0){
				valor_turbomail = eval('turbomail'+qtd) * multiplicador;
				txt_turbomail = " TurboMail " + qtd;
				document.getElementById('pg_info4').innerHTML = 'R$ '+format_number((valor_turbomail/multiplicador),2);
			}else{
				 valor_turbomail = 0;
				 txt_turbomail   = '';
				 document.getElementById('pg_info4').innerHTML = 'R$ 25,00';
			}
			break;

	 }
  box();
}

function sel_pagamento(id,nome){
	document.getElementById('frm_pgto_nome').value = nome;
	box();
	
	if (id == 10){
		alert("Seu telefone deve estar habilitado para este serviço! \n\n Consulte a operada OI para saber mais informações.");
		}
    }


function s_opc(nome){
//	document.getElementById('opc_txt').value = nome;
  if (nome=="reserva"){
		valor_base_op1 = 0;
		valor_base_op2 = 0;
		valor_base_op3 = 0;
		valor_base_op4 = 0;
		valor_ad_web = 0;
		valor_ad_disco = 0;
		valor_ad_mysql = 0;
		valor_ad_mail = 0;
		valor_ad_transf = 0;
		valor_plano = 0;
		valor_tarifas = 0;
		txt_ad = '';
		txt_base_op1 = '';
		txt_base_op2 = '';
		txt_base_op3 = '';
		txt_base_op4 = '';
		txt_ad_web = '';
		txt_ad_disco = '';
		txt_ad_mysql = '';
		txt_ad_mail = '';
		txt_ad_transf = '';
		plano='';
		document.getElementById('cod_plano').value=6;
		document.getElementById('plano_nome').value='';
		document.getElementById('n_pagto').value='';
		pgto='';
		document.getElementById('cb_ad_web').selectedIndex=0;
		document.getElementById('cb_ad_disco').selectedIndex=0;
		document.getElementById('cb_ad_mysql').selectedIndex=0;
		document.getElementById('cb_ad_mail').selectedIndex=0;
		document.getElementById('cb_ad_transf').selectedIndex=0;
   	    document.getElementById('opcionais').style.display='none';
		document.all.rbPlano[0].checked=true;
		document.all.opc[1].checked=true;
		desc(0);
        sel_plano(6,'Reserva de Domínio');
        plano_preco(3);
		document.all.pagamento[3].checked=true;
	}
	else if (nome=="ganhe2"){
			pgto='';
			plano='';
			document.getElementById('opcionais').style.display='';
			document.getElementById('cod_plano').value='';
			document.getElementById('plano_nome').value='';
			document.getElementById('n_pagto').value='';
			document.all.pagamento[3].checked=true;
			document.all.rbPlano[3].checked=true;
			document.all.opc[3].checked=true;
			desc(0);
			sel_plano(3,'Ideal');
			plano_preco(3);
	}
   else if (nome=="promocao"){
			pgto='';
			plano='';
			document.getElementById('opcionais').style.display='';
			document.getElementById('cod_plano').value='';
			document.getElementById('plano_nome').value='';
			document.getElementById('n_pagto').value='';
			document.all.pagamento[0].checked=true;
			document.all.rbPlano[3].checked=true;
			document.all.opc[2].checked=true;
			sel_plano(3,'Ideal');
			plano_preco(0);
	}
	else if (nome=="regtotal"){
			pgto='';
			plano='';
			document.getElementById('opcionais').style.display='';
			document.getElementById('cod_plano').value='';
			document.getElementById('plano_nome').value='';
			document.getElementById('n_pagto').value='';
			document.all.pagamento[0].checked=true;
			document.all.rbPlano[3].checked=true;
			document.all.opc[3].checked=true;
			sel_plano(3,'Ideal');
			plano_preco(0);
	}else{
		pgto='';
		plano='';
		document.getElementById('opcionais').style.display='';
		document.getElementById('cod_plano').value='';
		document.getElementById('plano_nome').value='';
		document.getElementById('n_pagto').value='';
		document.all.pagamento[0].checked=true;
		document.all.opc[0].checked=true;
		valor_plano = 0;
	  }
}

function sel_opcionais(aceito){
	 if (aceito == 0){
		 var resposta = confirm("Cancelar seleção de opcionais?");
		 if (resposta){
			valor_base_op1 = 0;
			valor_base_op2 = 0;
			valor_base_op3 = 0;
			valor_base_op4 = 0;
			valor_ad_web = 0;
			valor_ad_disco = 0;
			valor_ad_mysql = 0;
			valor_ad_mail = 0;
			valor_ad_transf = 0;
			txt_ad = '';
			txt_base_op1 = '';
			txt_base_op2 = '';
			txt_base_op3 = '';
			txt_base_op4 = '';
			txt_ad_web = '';
			txt_ad_disco = '';
			txt_ad_mysql = '';
			txt_ad_mail = '';
			txt_ad_transf = '';
			document.getElementById('cb_ad_web').selectedIndex=0;
			document.getElementById('cb_ad_disco').selectedIndex=0;
			document.getElementById('cb_ad_mysql').selectedIndex=0;
			document.getElementById('cb_ad_mail').selectedIndex=0;
			document.getElementById('cb_ad_transf').selectedIndex=0;
			document.getElementById('op1').checked=false;
			document.getElementById('op2').checked=false;
			document.getElementById('op3').checked=false;
   	  abrir(2);
		 }
	 } else abrir(2);
}

function VerificaVale(){
	if (document.getElementById('vale_desconto').value.length >= 10){
		window.open("valida_vale.php?cod="+document.getElementById('vale_desconto').value,"frmAux");
	}else{
		alert("Código do Vale-Desconto inválido.");
	}
  document.getElementById('vale_desconto').focus();
	document.getElementById('vale_desconto').select();
}


function isEmail(str) {

	var supported = 0;

	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}

	if (!supported) return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}

function ValidaForm(){

  var nonNumbers = /\D/;
	var saida = '';
  var responsavel  = (document.getElementById('nome').value.indexOf(' ') > 0 ) ? document.getElementById('nome').value.split(' ') : 0;
	var telefone_aux = document.getElementById('telefone').value;
	var telefone = telefone_aux.substr(0, 1);
	
  if ((obrigaCNPJ == 1) && (document.getElementById('empresa').value == '')){
		  alert("Atenção!\n\nNome da Empresa não pode ser nulo.");
		  document.getElementById('empresa').focus();
		  saida = 'FormError';
	}else if ((obrigaCNPJ == 1) && (document.getElementById('cnpj').value == '')){
		  alert("Atenção!\n\nCNPJ da Empresa não pode ser nulo.");
		  document.getElementById('cnpj').focus();
		  saida = 'FormError';
	}else if ((document.getElementById('cnpj').value != '') && (validaCNPJ(document.getElementById('cnpj').value) == false)){
		  if (document.getElementById('cnpj').readOnly != false) { document.getElementById('cnpj').focus(); }
		  saida = 'FormError';
	}else if  (document.getElementById('nome').value.length < 2){
		  alert("Atenção!\n\nInforme um nome para o responsável do domínio.");
		  document.getElementById('nome').focus();
		  saida = 'FormError'; 
	}else if  (responsavel == '0' || responsavel[1] == ''){
		  alert("Atenção!\n\nInforme um nome e sobrenome para o responsável do domínio.");
		  document.getElementById('nome').focus();
		  saida = 'FormError';
	}else if ((obrigaCPF == 1) && (document.getElementById('cpf').value.length < 2)){
		  alert("Atenção!\n\nCPF do responsável não pode ser nulo.");
		  document.getElementById('cpf').focus();
		  saida = 'FormError';
	}else if ((document.getElementById('cpf').value != '') && (validaCPF(document.getElementById('cpf').value) == false)) {
		  if (document.getElementById('cpf').readOnly != false) { document.getElementById('cpf').focus(); }
		  saida = 'FormError';
	}else if ((obrigaCNPJ == 0 && obrigaCPF == 0) && (document.getElementById('cpf_cnpj').value == '')){
		  alert("Atenção!\n\nInforme o CPF ou CNPJ para registro.");
		  document.getElementById('cpf_cnpj').focus();
		  saida = 'FormError';
	}else if ((document.getElementById('cpf_cnpj').value != '') && (validaCPF_CNPJ(document.getElementById('cpf_cnpj').value) == false)) {
		  if (document.getElementById('cpf_cnpj').readOnly != false) { document.getElementById('cpf_cnpj').focus(); }
		  saida = 'FormError';
	}else if (document.getElementById('ddd1').value.length < 2){
		  alert("Atenção!\n\nO campo DDD do Telefone não pode ser nulo.");
		  document.getElementById('ddd1').focus();
		  saida = 'FormError';
	}else if (document.getElementById('telefone').value.length < 2){
		  alert("Atenção!\n\nO campo Telefone não pode ser nulo.");
		  document.getElementById('telefone').focus();
		  saida = 'FormError';
	}else if (telefone == 7 || telefone == 8 || telefone == 9){
		  alert("Atenção!\n\nO campo Telefone não pode ser um celular.");
		  document.getElementById('telefone').focus();
		  saida = 'FormError';
	}else if ((document.getElementById('ddd1').value.length > 0) && (nonNumbers.test(document.getElementById('ddd1').value))){
		  alert("Atenção!\n\nO campo DDD do Telefone é númerico.");
		  document.getElementById('ddd1').focus();
		  saida = 'FormError';
	}else if ((document.getElementById('telefone').value.length > 0) && (nonNumbers.test(document.getElementById('telefone').value))){
		  alert("Atenção!\n\nO campo TELEFONE é númerico.");
		  document.getElementById('telefone').focus();
		  saida = 'FormError';
	}else if ((document.getElementById('ddd2').value.length > 0) && (nonNumbers.test(document.getElementById('ddd2').value))){
		  alert("Atenção!\n\nO campo DDD do Celular é númerico.");
		  document.getElementById('ddd2').focus();
		  saida = 'FormError';
	}else if ((document.getElementById('celular').value.length > 0) && (nonNumbers.test(document.getElementById('celular').value))){
		  alert("Atenção!\n\nO campo CELULAR é númerico.");
		  document.getElementById('celular').focus();
		  saida = 'FormError';
	}else if ((document.getElementById('celular').value.length > 0) && (document.getElementById('ddd2').value.length < 2)){
		  alert("Atenção!\n\nInforme o DDD do número do seu celular.");
		  document.getElementById('ddd2').focus();
		  saida = 'FormError';
	}else if ((document.getElementById('celular').value.length > 0) && (document.getElementById('ddd2').value.length = 2) && (validaCEL(document.getElementById('celular').value) == false)){
		  document.getElementById('celular').focus();
		  saida = 'FormError';
	}else if (!isEmail(document.getElementById('em_tec').value)){
		  alert("Atenção!\n\nE-mail Técnico inválido.");
		  document.getElementById('em_tec').focus();
		  saida = 'FormError';
	}else if (!isEmail(document.getElementById('em_cob').value)){
		  alert("Atenção!\n\nE-mail de Cobrança inválido.");
		  document.getElementById('em_cob').focus();
		  saida = 'FormError';
	}else if (document.getElementById('endereco').value.length < 2){
		  alert("Atenção!\n\nO campo Endereço não pode ser nulo.");
		  document.getElementById('endereco').focus();
		  saida = 'FormError';
	}else if (document.getElementById('numero').value.length < 2){
		  alert("Atenção!\n\nO campo Número não pode ser nulo.");
		  document.getElementById('numero').focus();
		  saida = 'FormError';
	}else if (document.getElementById('bairro').value.length < 2){
		  alert("Atenção!\n\nO campo Bairro não pode ser nulo.");
		  document.getElementById('bairro').focus();
		  saida = 'FormError';
	}else if (document.getElementById('cidade').value.length < 2){
		  alert("Atenção!\n\nO campo Cidade não pode ser nulo.");
		  document.getElementById('cidade').focus();
		  saida = 'FormError';
	}else if (document.getElementById('cep').value.length < 2){
		  alert("Atenção!\n\nO campo CEP não pode ser nulo.");
		  document.getElementById('cep').focus();
		  saida = 'FormError';
	}else if ((document.getElementById('cep').value != '') && (validaCEP(document.getElementById('cep').value) == false)) {
		  document.getElementById('cep').focus();
		  saida = 'FormError';
	}else if ((document.getElementById('cod_par').value.length > 0) && (nonNumbers.test(document.getElementById('cod_par').value))){
		  alert("Atenção!\n\nO campo Código do Parceiro é númerico.");
		  document.getElementById('cod_par').focus();
		  saida = 'FormError';
	}else if (document.getElementById('cod_plano').value == ''){
		  alert("Atenção!\n\nSelecione algum plano para a assinatura.");
		  document.all.rbPlano[0].focus();
		  saida = 'FormError';
	}
	return saida;
}

function PreencheCep(rua,bairro,uf,cidade){
	document.getElementById('endereco').value = rua;
	document.getElementById('bairro').value = bairro;
	document.getElementById('uf').value = uf;
	document.getElementById('cidade').value = cidade;

	if (rua.length > 0){ if (document.getElementById('p4').style.display != 'none') document.getElementById('numero').focus() };
}

function AtualizaForm(sufixo){ //|| (sufixo == "com.br") -> tb pode com cnfj
  if ((sufixo == "agr.br") || (sufixo == "am.br")  || (sufixo == "art.br") || (sufixo == "coop.br") || 
	    (sufixo == "edu.br") || (sufixo == "esp.br") || (sufixo == "far.br") || (sufixo == "fm.br")  || (sufixo == "g12.br")  || 
		  (sufixo == "gov.br") || (sufixo == "imb.br") || (sufixo == "ind.br") || (sufixo == "inf.br") || (sufixo == "mil.br")  || 
		  (sufixo == "org.br") || (sufixo == "psi.br") || (sufixo == "rec.br") || (sufixo == "srv.br") || (sufixo == "radio.br") || 
		  (sufixo == "tmp.br") || (sufixo == "art.br") || (sufixo == "tur.br") || (sufixo == "tv.br")  || (sufixo == "etc.br")  || 
			(sufixo == "br")) {
      document.getElementById('infoEmpresa1').style.display = '';  
      document.getElementById('infoEmpresa2').style.display = '';  
			document.getElementById('infoResponsavel1').style.display = '';	
			document.getElementById('infoResponsavel2').style.display = 'none';	
      document.getElementById('infoCNPJCPF').style.display = 'none';	
			document.getElementById('alerta').innerHTML = "Por determinação do órgão gestor Registro.Br, é exigido <b>CNPJ</b> para o registro do domínio: <b>"+document.getElementById('n_dom').value + "." + document.getElementById('ext').options[document.getElementById('ext').selectedIndex].value + "</b>";
			obrigaCNPJ = 1; obrigaCPF = 0;
	}
  else if ((sufixo == "com.br") || (sufixo == "net.br") || (sufixo == "com") || (sufixo == "net") || (sufixo == "biz") || (sufixo == "info") || (sufixo == "org") || (sufixo == "us")) {
      document.getElementById('infoEmpresa1').style.display = '';  
      document.getElementById('infoEmpresa2').style.display = 'none';  
			document.getElementById('infoResponsavel1').style.display = '';	
			document.getElementById('infoResponsavel2').style.display = 'none';	
			document.getElementById('infoCNPJCPF').style.display = '';	
			document.getElementById('alerta').innerHTML = "Para domínios internacionais informe o <b>CNPJ ou CPF</b> do responsável para o registro do domínio: <b>" + document.getElementById('n_dom').value + "." + document.getElementById('ext').options[document.getElementById('ext').selectedIndex].value + "</b>";
			obrigaCNPJ = 0; obrigaCPF = 0;
	}
  else if ((sufixo == "blog.br") || (sufixo == "vlog.br") || (sufixo == "flog.br") || (sufixo == "wiki.br")) {
      document.getElementById('infoEmpresa1').style.display = 'none';  
      document.getElementById('infoEmpresa2').style.display = 'none';  
			document.getElementById('infoResponsavel1').style.display = '';	
			document.getElementById('infoResponsavel2').style.display = '';	
			document.getElementById('infoCNPJCPF').style.display = 'none';	
			document.getElementById('alerta').innerHTML = "Por determinação do órgão gestor Registro.Br, esta terminação é somente para pessoas fisicas e sendo exigido o <b>CPF</b> para o registro do domínio: <b>" + document.getElementById('n_dom').value + "." + document.getElementById('ext').options[document.getElementById('ext').selectedIndex].value + "</b>";
			obrigaCNPJ = 0; obrigaCPF = 1;
	}
	else {
      document.getElementById('infoEmpresa1').style.display = 'none';  
      document.getElementById('infoEmpresa2').style.display = 'none';  
			document.getElementById('infoResponsavel1').style.display = '';	
			document.getElementById('infoResponsavel2').style.display = '';	
			document.getElementById('infoCNPJCPF').style.display = 'none';	
			document.getElementById('alerta').innerHTML = "Por determinação do órgão gestor Registro.Br, é exigido <b>CPF</b> para o registro do domínio: <b>" + document.getElementById('n_dom').value + "." + document.getElementById('ext').options[document.getElementById('ext').selectedIndex].value + "</b>";
			obrigaCNPJ = 0; obrigaCPF = 1;
	}
}

function InfoCampoCadastro(Campo,Valor,Ativo){
    document.getElementById(Campo).value = '';	
    document.getElementById(Campo).value = Valor;	
    document.getElementById(Campo).readOnly = Ativo; 
    if (Ativo) document.getElementById(Campo).className = 'campotexto-readonly';
		else document.getElementById(Campo).className= 'campotexto';
        }

function DominioExiste(nome){
	if (nome != ''){
		abrir(1);
		document.getElementById('n_dom').value = '';
		document.getElementById('n_dom').focus();
		alert('O domínio www.'+nome+' já está cadastrado em nosso sistema.\nQualquer dúvida, entre em contato pelo email: suporte@turbosite.com.br');
	}
}

function CarregaFinalizacao(){
	document.getElementById('pd_txt_dominio').innerHTML   = document.getElementById('n_dom').value + "." + document.getElementById('ext').options[document.getElementById('ext').selectedIndex].value;
	document.getElementById('pd_txt_formapgto').innerHTML = document.getElementById('frm_pgto_nome').value;
	document.getElementById('pd_txt_empresa').innerHTML   = document.getElementById('empresa').value;
	document.getElementById('pd_txt_nome').innerHTML      = document.getElementById('nome').value;
	document.getElementById('pd_txt_cnpj').innerHTML      = document.getElementById('cnpj').value;
  document.getElementById('pd_txt_cpf').innerHTML       = document.getElementById('cpf').value;

	if (document.getElementById('cpf_cnpj').value.length == 14)
     document.getElementById('pd_txt_cpf').innerHTML    = document.getElementById('cpf_cnpj').value;
  else if (document.getElementById('cpf_cnpj').value.length == 18)
     document.getElementById('pd_txt_cnpj').innerHTML   = document.getElementById('cpf_cnpj').value;
 
  document.getElementById('pd_txt_endereco').innerHTML  = document.getElementById('endereco').value+", "+document.getElementById('numero').value+" - "+document.getElementById('complemento').value;
	document.getElementById('pd_txt_cep').innerHTML       = document.getElementById('cep').value;
	document.getElementById('pd_txt_cidade').innerHTML    = document.getElementById('cidade').value;
	document.getElementById('pd_txt_estado').innerHTML    = document.getElementById('uf').value;
	document.getElementById('pd_txt_telefone').innerHTML  = "("+document.getElementById('ddd1').value+") "+document.getElementById('telefone').value;
	if (document.getElementById('ddd2').value){
		document.getElementById('pd_txt_celular').innerHTML   = "("+document.getElementById('ddd2').value+") "+document.getElementById('celular').value;
		}
	document.getElementById('pd_txt_etec').innerHTML      = document.getElementById('em_tec').value;
	document.getElementById('pd_txt_ecob').innerHTML      = document.getElementById('em_cob').value;
	document.getElementById('pd_txt_codpar').innerHTML    = document.getElementById('cod_par').value;
}

function FinalizarPedido(cod){
	 if (document.getElementById('agree').checked == false){
		txt="É necessário que você aceite os termos do contrato para o registro!";
		alert(txt);
		return false;
		}
	 
	 carrega('','Concluindo pedido!');
	 document.getElementById('frmAssina').action='cadastro.php?acao=cad_cli&cod_cli='+cod;
	 document.getElementById('frmAssina').submit();
     }

function InStr(n, s1, s2){
	var numargs=InStr.arguments.length;	
	if(numargs<3)
		return n.indexOf(s1)+1;
	else
		return s1.indexOf(s2, n)+1;
}

function CPFVal(s){
	var i; 
	var rtrn = true;
	var c = s.substr(0,9); 
	var dv = s.substr(9,2); 
	var d1 = 0; 
	for (i = 0; i < 9; i++) d1 += c.charAt(i)*(10-i);
	if (d1 == 0) rtrn = false; 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(0) != d1) rtrn = false; 
	d1 *= 2; 
	for (i = 0; i < 9; i++) d1 += c.charAt(i)*(11-i);
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(1) != d1) rtrn = false;
	return rtrn;
}

function validaCEL(valor){
	erro = new String; 
	if (valor.length > 0 && valor.length < 8) erro += "É necessário preencher corretamente o número do CELULAR!\n\n";
	if (valor.substring(0,1) < 7)  erro += "O número do celular está incorreto!\n\n";
	if (erro.length > 0){
		alert(erro);
		return false;
	}
	return true;
}

function validaCPF_CNPJ(valor){
	valor = valor.replace(".","");
	valor = valor.replace(".","");
	valor = valor.replace("-","");
	valor = valor.replace("/","");
	if (valor.length > 12) 
	 return validaCNPJ(valor);
	else	
	 return validaCPF(valor);
}

function validaCEP(cep) {
	erro = new String; 
	if (cep.length < 7) erro += "É necessário preencher corretamente o número do CEP!\n\n";
	if (cep.length == 7) { 
	   cep = cep.substring(0,5)+'-'+cep.substring(5,8); 
	   document.getElementById('cep').value = cep;
	}
	if(document.layers && parseInt(navigator.appVersion) == 4){
		//x = cep.substring(0,5);
		//x += cep.substring(6,9);
		//cep = x;	
	} else {
		cep = cep.replace(".","");
		cep = cep.replace(".","");
		cep = cep.replace("-","");
		cep = cep.replace("/","");
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(cep)) erro += "A verificação de CEP suporta apenas números! \n\n";	
	if (erro.length > 0){
		alert(erro);
    document.getElementById('cep').focus();
		return false;
	}
	return true;
}
function validaCNPJ(CNPJ) {
	erro = new String; 
	if (CNPJ.length == 14) { 
	   CNPJ = CNPJ.substring(0,2)+'.'+CNPJ.substring(2,5)+'.'+CNPJ.substring(5,8)+'/'+CNPJ.substring(8,12)+'-'+CNPJ.substring(12,14); 
	   if (obrigaCNPJ == 0 && obrigaCPF == 0) document.getElementById('cpf_cnpj').value = CNPJ; else document.getElementById('cnpj').value = CNPJ;
	}
	if (CNPJ.length < 18) erro += "É necessário preencher corretamente o número do CNPJ!\n\n";
	if (CNPJ.length == 19) CNPJ = CNPJ.substring(1,19);
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
		if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! (18 caracteres)\n\n";
	}

	if(document.layers && parseInt(navigator.appVersion) == 4){
		x = CNPJ.substring(0,2);
		x += CNPJ.substring(3,6);
		x += CNPJ.substring(7,10);
		x += CNPJ.substring(11,15);
		x += CNPJ.substring(16,18);
		CNPJ = x;	
	} else {
		CNPJ = CNPJ.replace(".","");
		CNPJ = CNPJ.replace(".","");
		CNPJ = CNPJ.replace("-","");
		CNPJ = CNPJ.replace("/","");
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n";	
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	for (i=0; i<12; i++){
		a[i] = CNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
	if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
	b = 0;
	for (y=0; y<13; y++) {
		b += (a[y] * c[y]); 
	}
	if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13]) || (CNPJ == '00000000000000')){
		erro +="Digito verificador do CNPJ inválido!";
	}
	if (erro.length > 0){
		alert(erro);
    if (obrigaCNPJ == 0 && obrigaCPF == 0) document.getElementById('cpf_cnpj').focus(); else document.getElementById('cnpj').focus();
		return false;
	}
	return true;
}

function validaCPF(cpf) {
	valor = true;
	erro = new String;
	if (cpf.length < 11) erro += "São necessários 11 digitos para verificação do CPF! \n\n"; 

	if(document.layers && parseInt(navigator.appVersion) == 4){
		x = cpf.substring(0,3);
		x += cpf.substring(4,7);
		x += cpf.substring(8,11);
		cpf = x;	
	} else {
		cpf = cpf.replace(".","");
		cpf = cpf.replace(".","");
		cpf = cpf.replace(".","");
		cpf = cpf.replace("-","");
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(cpf)) erro += "A verificação de CPF suporta apenas números! \n\n";	
	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "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] = 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])){
		erro +="Digito verificador do CPF inválido!";
	}
  cpf = cpf.substring(0,3)+'.'+cpf.substring(3,6)+'.'+cpf.substring(6,9)+'-'+cpf.substring(9,11); 
  if (obrigaCNPJ == 0 && obrigaCPF == 0) document.getElementById('cpf_cnpj').value = cpf; else document.getElementById('cpf').value = cpf;
	if (erro.length > 0){
		alert(erro);
    if (obrigaCNPJ == 0 && obrigaCPF == 0) document.getElementById('cpf_cnpj').focus(); else document.getElementById('cpf').focus();
		return false;
	}
	return true;
}

function format_number(p,d) { 
	var r; 
	if(p<0){p=-p;r=format_number2(p,d);r="-"+r;} 
	else {r=format_number2(p,d);} 
	return r; 
} 

function format_number2(pnumber,decimals) { 
	var strNumber = new String(pnumber); 
	var arrParts = strNumber.split('.'); 
	var intWholePart = parseInt(arrParts[0],10); 
	var strResult = ''; 
  if (isNaN(intWholePart)) 
     intWholePart = '0'; 
  if(arrParts.length > 1) { 
		var decDecimalPart = new String(arrParts[1]); 
		var i = 0; 
		var intZeroCount = 0; 
    while ( i < String(arrParts[1]).length ) { 
      if( parseInt(String(arrParts[1]).charAt(i),10) == 0 ) { 
        intZeroCount += 1; 
        i += 1; 
      } 
      else 
        break; 
    } 
		decDecimalPart = parseInt(decDecimalPart,10)/Math.pow(10,parseInt(decDecimalPart.length-decimals-1)); 
		Math.round(decDecimalPart); 
		decDecimalPart = parseInt(decDecimalPart)/10; 
		decDecimalPart = Math.round(decDecimalPart); 
	
		if(decDecimalPart==Math.pow(10, parseInt(decimals))) { 
			intWholePart+=1; 
			decDecimalPart="0"; 
		} 
		var stringOfZeros = new String(''); 
		i=0; 
		if( decDecimalPart > 0 ) { 
			while( i < intZeroCount)  { 
				stringOfZeros += '0'; 
				i += 1; 
			} 
		} 
		decDecimalPart = String(intWholePart) + "," + stringOfZeros + String(decDecimalPart); 
		var dot = decDecimalPart.indexOf(','); 
		if(dot == -1) { 
			decDecimalPart += ','; 
			dot = decDecimalPart.indexOf(','); 
		} 
		var l=parseInt(dot)+parseInt(decimals); 
		while(decDecimalPart.length <= l) { 
			decDecimalPart += '0'; 
		} 
		strResult = decDecimalPart; 
  } 
  else { 
		var dot; 
		var decDecimalPart = new String(intWholePart); 
		
		decDecimalPart += ','; 
		dot = decDecimalPart.indexOf(','); 
		var l=parseInt(dot)+parseInt(decimals); 
		while(decDecimalPart.length <= l) { 
		 decDecimalPart += '0'; 
		} 
    strResult = decDecimalPart; 
  } 
  return strResult; 
} 

function onMouseOver(object) {
  if (object.className == 'TabelaSelecao') object.className = 'onMouseOver';
}

function onMouseOut(object) {
  if (object.className == 'onMouseOver') object.className = 'TabelaSelecao';
}

function Mascara(formato, key, campo){
  var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keypress = (isNN) ? key.which : key.keyCode;
	if (formato=='CEP'){
		//if (campo.value.indexOf("-") == -1 && campo.value.length > 5){ campo.value = ""; }
		//	if (campo.value.length == 5){
		//		campo.value += "-";
		//	}
	}
	
	if (formato=='CPF'){
		caracteres = '01234567890';
		separacoes = 3;
		separacao1 = '.';
		separacao2 = '-';
		conjuntos = 4;
		conjunto1 = 3;
		conjunto2 = 7;
		conjunto3 = 11;
		conjunto4 = 14;
		if ((caracteres.search(String.fromCharCode(keypress))!=-1) && campo.value.length < (conjunto4)) {
				if (campo.value.length == conjunto1) 
						campo.value = campo.value + separacao1;
				else if (campo.value.length == conjunto2) 
						campo.value = campo.value + separacao1;
				else if (campo.value.length == conjunto3) 
						campo.value = campo.value + separacao2;
		}
	}	else if (formato=='CNPJ'){
		caracteres = '01234567890';
		separacoes = 4;
		separacao1 = '.';
		separacao2 = '.';
		separacao3 = '/';
		separacao4 = '-';						
		conjuntos = 4;
		conjunto1 = 2;
		conjunto2 = 6;
		conjunto3 = 10;
		conjunto4 = 15;
		if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (conjunto1 + conjunto2 + conjunto3 + conjunto4 + 1)){
			if (campo.value.length == conjunto1) campo.value = campo.value + separacao1;
			if (campo.value.length == conjunto2) campo.value = campo.value + separacao2;
			if (campo.value.length == conjunto3) campo.value = campo.value + separacao3;
			if (campo.value.length == conjunto4) campo.value = campo.value + separacao4;			
			}			
		}
}

function cbinc(valor){
	if (document.getElementById('cb_ad_mysql').value > 0 || valor > 0)  {
   	document.getElementById('cb_ad_mysql').value = eval(document.getElementById('cb_ad_mysql').value) + valor;
	  adicionais(3,document.getElementById('cb_ad_mysql').value);
	}
}

function getIndex(input) {
	var index = -1, i = 0, found = false;

	while (i < input.form.length && index == -1)
	      if (input.form[i] == input)index = i;
	      else i++;

	return index;
	}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
			
	return found;
    }

function autoTab(input, e) {
  var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	var indice;
	var campo;
	var i=1;
	var merd =containsElement(filter,keyCode);
	
	if(input.value.length >= input.maxLength && !merd) {
   	input.value = input.value.slice(0, input.maxLength);
    indice = getIndex(input);
	
	if (indice < 11 && obrigaCPF == 0 && obrigaCNPJ == 0)      i += 1;
	else if (indice < 11 && obrigaCPF == 1 && obrigaCNPJ == 0) i += 1;
	else if (indice < 11 && obrigaCPF == 0 && obrigaCNPJ == 1) i += 3;
			 
   	campo = input.form[(indice+i) % input.form.length];
  	//campo.focus();
    }
  return true;
  }

function GetFormaPagto(){
	  var OpcoesPagamento = document.all.forma_pagto;
	  var PagtoEscolhido  = false;
			  
	  for (i=0; i<8; i++){
		   try{
			  if (OpcoesPagamento[i].checked){
				 PagtoEscolhido = OpcoesPagamento[i].value;
				 break;
				 }
			  }
		   catch(e){}
		  }				  
	  return PagtoEscolhido;			  
	  }

