// JavaScript Document
var win = null;

function _formatarCampos(src, mask)
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
  if (texto.substring(0,1) != saida)
  {
     src.value += texto.substring(0,1);
  }
}

function __openCertificadoSSL(mypage, myname, w, h, scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=no'
	win = window.open(mypage,myname,settings)
}

function __ajudaValePresente(){
	
	var style_TDAjudaVP = document.getElementById("TDAjudaValePresente").style.display;	
	document.getElementById("TDAjudaValePresente").style.display = ((style_TDAjudaVP == "none") ? "block" : "");
	
	__toggleSlide("divAjudaValePresente");
	
}

function checkCEP(field, maxLen, nextField){
	if(field.value.length == maxLen) {
		nextField.focus();	
	}
}

function _pesqPedidos(){
	
	var Checkbox 		= true;
	var tpPedAberto		= document.all.rbPedidos[0]; 
	var tpTodosPed		= document.all.rbPedidos[1];
	var tpNumPed		= document.all.rbPedidos[2];
	var NumPedBusca		= document.all.NumPed.value;
	var tpBuscaPedidos	= 0;
	
	for( c = 0; c < document.all.rbPedidos.length; ++c )
	{
		if ( document.all.rbPedidos[c].checked )
		tpBuscaPedidos 	= 1 ;
	}
	
	if ( tpBuscaPedidos == 0 ) 
	{
		alert( "É preciso que você selecione um tipo de Busca de Pedidos" ) ;
		Checkbox = false;
	}
	
	if (tpNumPed.checked == true){
		if(NumPedBusca==""){
			alert("É necessário informar um Número de Pedido");	
			Checkbox = false;
		}
	}
		
	return Checkbox;
}

/* Funções operacionais da Cesta de Carrinhos */
function _postCesta() {
	
 var form 		= document.AltQuantidade;
 var CEP1		= form.cep1;
 var CEP2		= form.cep2;
 var haveerrors = 0;
 
 if (CEP1.value == ""){
	CEP1.focus();
	alert('Informe o CEP');
  }
  else if (CEP2.value == ""){
	CEP2.focus();
	alert('Informe o CEP');
  }
  else{
	
	if(CEP1.value.length < 5){
		alert('O CEP informado está incorreto');
		form.cep1.focus();
	}
	else if (CEP2.value.length < 3){
		alert('O CEP informado está incorreto');
		form.cep2.focus();
	}
	else {
  		form.submit();
	}
	
  }	

  
}

function _calculaFrete(page){
	
	var form 		= document.AltQuantidade;

	if (form.cep1.value == ""){
		form.cep1.focus();
		alert('Informe o CEP');
	}
	else if (form.cep2.value == ""){
		form.cep2.focus();
		alert('Informe o CEP');
	} else{	
	
		var fieldsGet 	= "?act=frete&idPedido="+form.Pedido.value+"&Produto="+form.Produto.value+"&Quant="+form.Preco.value+"&CEP1="+form.cep1.value+"&CEP2="+form.cep2.value;
	
		var ajax = _initXML_http();
		ajax.open("GET", "includes/"+page+fieldsGet, true);
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) {
				
				if(ajax.status == 200) {
					
					/*if(ajax.responseText=="Erro") { 
	
						document.getElementById("idLoginError").style.display 	= '';
						document.getElementById("idLoginError").innerHTML 		= "<span class=titulos_inicio>&nbsp;&nbsp;&nbsp;&nbsp;E-mail ou Senha são inválidos!</span>";
						
					} else {
						
						document.getElementById("idLoginError").style.display 	= 'none';
						document.getElementById("idLoginError").innerHTML 		= "";					
						var Dados = ajax.responseText.split("|");
						if(Dados[0]=="Success"){
							window.location.href = "_centralCliente.asp";
						}
					}*/
					alert(ajax.responseText)
	
				} else {
					<!-- ajax.statusText; -->
				}
			}
		}		
		ajax.send(null);
	}
}

/* Funções operacionais para concluir a compra */
function Payment()
{

	var checaFormaPagto = false ;
	var FormaPagtoSel	= "";
	var form	= document.Cadastro;
	var inicio 	= form.FormaPagamento.length;
	
	if ( form.FormaPagamento.value )
	{ 
		checaFormaPagto = true;
		FormaPagtoSel	= form.FormaPagamento.value
	}      

	for( c = 0; c < form.FormaPagamento.length; ++c )
	{
		if ( form.FormaPagamento[c].checked ) {
			checaFormaPagto = true;
			FormaPagtoSel	= form.FormaPagamento[c].value
		}
	}
	
	if ( checaFormaPagto == false) {
		alert( "É preciso selecionar uma Forma de Pagamento" ) ;
		checaFormaPagto = false;
	} else {

		switch ( parseInt(FormaPagtoSel) ) {
			
			case 12: /* CASO A OPÇÂO DE PAGAMENTO SEJA CARTÃO DE CRÉDITO VISA */
			
				if (form.bin_vn.value == "") { /* CASO O CAMPO DOS 6º DIGITOS DO CARTÃO ESTEJA EM BRANCO */
					alert("É necessário informar os 6 primeiros digitos do seu cartão de crédito Visa");
					form.bin_vn.focus();
					checaFormaPagto = false;
				} else {
					checaFormaPagto = true;
				}
		
			break;

		}
		
	}		

	return checaFormaPagto;
	
}

/*function envia_formulario(form){
	
	var PrimeiraCompra	= document.all.rbPossuiCad[0]; 
	var PossuiCadastro	= document.all.rbPossuiCad[1];
	if (PossuiCadastro.checked == true){
		
	  document[form].action	= "identificacao.asp?act=Entrar";
	  if (document[form].email.value == ""){
		document[form].email.focus();
		alert('Informe seu email');
	  }
	  else if (document[form].senha.value == ""){
		document[form].senha.focus();
		alert('Informe sua senha');
	  }
	  else{
		//document[form].submit();
		_postarDados("includes/_checkLogin.asp")
		
	  }
	  
	} else if (PrimeiraCompra.checked == true) { //CASO SEJA A PRIMEIRA COMPRA DO USUÁRIO
		
	  document[form].action="cadastro.asp";
	  
	  if (document[form].email.value == ""){
		
		document[form].email.focus();
		alert('Informe seu email');
		
	  } else if (document[form].cep1.value == ""){

		document[form].cep1.focus();
		alert('Informe o CEP corretamente');
	
	  } else if (document[form].cep2.value == ""){

		document[form].cep2.focus();
		alert('Informe o CEP corretamente');
	
	  } else{		  
		document[form].submit();		
	  }
	  
	}
}*/
