// JavaScript Document
/* INICIO DA ROTINA QUE MUDA O CADASTRO */
function _trocarCadTipoPessoa(opcao){
	
	if(opcao == 1){
		
		document.getElementById("titTipoCadastro").innerHTML	 	= '&nbsp;&nbsp;CADASTRO DE PESSOA FÍSICA';
		document.getElementById("TRPF_Nome").style.display 			= '';
		document.getElementById("TRPJ_RazaoSocial").style.display 	= 'none';
		
		document.getElementById("TRPF_CPF").style.display 			= '';
		document.getElementById("TRPJ_CNPJ").style.display 			= 'none';		
		
		document.getElementById("TRPF_RG").style.display 			= '';
		document.getElementById("TRPJ_IE").style.display 			= 'none';
		
		document.getElementById("TRPF_DataNasc").style.display 		= '';
		document.getElementById("TRPJ_DataAbertura").style.display 	= 'none';			
		
	} else {

		document.getElementById("titTipoCadastro").innerHTML	 	= '&nbsp;&nbsp;CADASTRO DE PESSOA JURÍDICA';
		document.getElementById("TRPF_Nome").style.display 			= 'none';
		document.getElementById("TRPJ_RazaoSocial").style.display 	= '';
		
		document.getElementById("TRPF_CPF").style.display 			= 'none';
		document.getElementById("TRPJ_CNPJ").style.display 			= '';	

		
		document.getElementById("TRPF_RG").style.display 			= 'none';
		document.getElementById("TRPJ_IE").style.display 			= '';
		
		document.getElementById("TRPF_DataNasc").style.display 		= 'none';
		document.getElementById("TRPJ_DataAbertura").style.display 	= '';			

	}
	
}

function _mudarFocoTipoCad(opcao){
	var form = document.cadastro;
	if(eval(opcao)==0){
		form.senha.value 	= "";
	} else {
		form.cep1.value 	= "";
		form.cep2.value 	= "";		
	}
	form.rbPossuiCad[opcao].checked	= true;
}

function _setfieldSelect(form, field, valueField){
	var frm 		= eval("document."+form);
	var fieldSelect	= frm.Estado;//frm+"."+field;
	
	for (i=0;i<fieldSelect.length;i++)
	{		
		var index = (fieldSelect.options[i].value == valueField)?i:index;
		fieldSelect.options.selectedIndex = index;
	}	
}

function _postarDados(page){
	
	var form 		= document.cadastro;
	var fieldsGet 	= "?act=Entrar&Email="+form.email.value+"&Senha="+form.senha.value;

	var ajax = _initXML_http();
	ajax.open("GET", 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"){
						if(form.url_redirect.value == ""){
							window.location.href = "_centralCliente.asp";
						} else if(form.url_redirect.value != ""){
							window.location.href = form.url_redirect.value;
						}
					}
				}

			} else {
				<!-- ajax.statusText; -->
			}
		}
	}		
	ajax.send(null);
}

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();		
	  }
	  
	}
}

/* FUNÇÃO UTILIZADA PARA RECUPERAÇÃO DE SENHA DE USUARIO E DESBLOQUEIO DE DADOS */
function _forgoutPass(option) {
	
	document.getElementById("identifyContent").innerHTML 		= "";	

	var fieldsGet 	= "?act="+option;

	var ajax = _initXML_http();
	ajax.open("GET", "_forgotPassword.aspx", true);
	ajax.onreadystatechange = function() {
		if(ajax.readyState == 4) {
			
			if(ajax.status == 200) {
				
				document.getElementById("identifyContent").innerHTML 		= ajax.ResponseText;					

			} else {
				<!-- ajax.statusText; -->
			}
		}
	}		
	ajax.send(null);	
}