/////FUNÇÕES DO CARRINHO/////
function AutoNext(who, maxLength) 
{
	if (who.value.length == maxLength) 
	{
		var i=0,j=0, indice=-1;
		for (i=0; i<document.forms.length; i++) 
		{
			for (j=0; j<document.forms[i].elements.length; j++) 
			{
				if (document.forms[i].elements[j].name == who.name) 
				{
					indice=i;
					break;
				}
			}
			if (indice != -1)
		         break;
		}
		for (i=0; i<=document.forms[indice].elements.length; i++) {
			if (document.forms[indice].elements[i].name == who.name) {
				while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
						(i < document.forms[indice].elements.length) ) {
							i++;
				}
				document.forms[indice].elements[(i+1)].focus();
				break;
			}
		}
	}
}

function Verifica_Cep(obrigatorio){
//Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não
 	var cep1 = document.cart_frete.cep1.value;
	var cep2 = document.cart_frete.cep2.value;
 	var strcep = cep1 + cep2;
 	if((obrigatorio == 1) || (obrigatorio == 0 && strcep != "")){
		var strcep = cep1 + "-" + cep2;
 		if (strcep.length != 9){
 			alert("CEP informado inválido.");
 			return false;
 		}else{
 			if (strcep.indexOf("-") != 5){
 				alert("Formato de CEP informado inválido.");
 				return false;
 			}else{
 				if (isNaN(strcep.replace("-","0"))){
 					alert("CEP informado inválido.");
 					return false;
 				}
 			}
 		}
 	}
}

function Verifica_Login(obrigatorio){
//Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não
	var cep1 = document.login.cep1.value;
	var cep2 = document.login.cep2.value;
	var senha = document.login.senha.value;
	var email = document.login.email.value;
	
	if(!email.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+)/gi)){
 		alert("Informe um e-mail válido");
 		return false;
 	}
 		
	if(document.getElementById('primeira_compra').checked == true) {
		var strcep = cep1 + cep2;
		if((obrigatorio == 1) || (obrigatorio == 0 && strcep != "")){
			var strcep = cep1 + "-" + cep2;
			if (strcep.length != 9){
				alert("CEP informado inválido.");
				return false;
			}else{
				if (strcep.indexOf("-") != 5){
					alert("Formato de CEP informado inválido.");
					return false;
				}else{
					if (isNaN(strcep.replace("-","0"))){
						alert("CEP informado inválido.");
						return false;
					}
				}
			}
		}
	}else{
		if (senha.length == 0){
			alert("Você não preencheu a senha.");
			return false;
		}
	}
}
 
function Bloqueia_Caracteres(evnt){
 //Função permite digitação de números
 	if (clientNavigator == "IE"){
 		if (evnt.keyCode < 48 || evnt.keyCode > 57){
 			return false
 		}
 	}else{
 		if ((evnt.charCode < 48 || evnt.charCode > 57) && evnt.keyCode == 0){
 			return false
 		}
 	}
 }

function Ajusta_Cep(input, evnt){
 //Ajusta máscara de CEP e só permite digitação de números
 	if (input.value.length == 5){
 		if(clientNavigator == "IE"){
 			input.value += "-";
 		}else{
 			if(evnt.keyCode == 0){
 				input.value += "-";
 			}
 		}
 	}
 //Chama a função Bloqueia_Caracteres para só permitir a digitação de números
 	return Bloqueia_Caracteres(evnt);
 }
 
 
 function Verifica_Email(email, obrigatorio){
 //Se o parâmetro obrigatório for igual à zero, significa que elepode estar vazio, caso contrário, não
 	var email = document.getElementById(email);
 	if((obrigatorio == 1) || (obrigatorio == 0 && email.value != "")){
 		if(!email.value.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+)/gi)){
 			alert("Informe um e-mail válido");
 			email.focus();
 			return false
 		}
 	}
 }
 
 function Verifica_Tamanho(campo, tamanho){
 //usado para campos textarea onde não se tem o atributo maxlenght
 	var campo = document.getElementById(campo);
 	if(campo.value.length > tamanho){
 		alert("O campo suporta no máximo " + tamanho + " caracteres.");
 		campo.focus();
 		return false
 	}
 }
 
 function SetFocus( idToFocus ){
				var TextBox = document.getElementById( idToFocus );
				TextBox.focus();
	}

// Valida se o valor passado é numérico
function isNumber ( pStrExp ){
	var bolReturn = false;
	if ( trim( pStrExp ) != '' ){ // se foi passado algum valor
		var oRegNumber = /\D/;
		bolReturn = !oRegNumber.test( pStrExp );
	}
	return bolReturn;
}
 
function ShowCepPopup(){
	window.open('http://www.correios.com.br/servicos/cep/cep_default.cfm','ShowCep','location=no,resize=no, width=730,height=400,left=18,top=18,maximized=0,scrollbars=1');
}
// se acordo com o checkBox clicado de isento, habilita ou desabilita o campo tbxIE
function fEnableDisableIsento( bolIsChecked, tbxIEId ){

	var tbxIE = document.getElementById( tbxIEId );
	
	tbxIE.disabled = bolIsChecked;
	tbxIE.style.background = !bolIsChecked ? "white" : "silver";
	tbxIE.value = !bolIsChecked ? "" : "Isento";
	
}

function check_password(field_name_1, field_name_2, field_size, message_1, message_2) {
  if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) {
    var password = form.elements[field_name_1].value;
    var confirmation = form.elements[field_name_2].value;

    if (password == '' || password.length < field_size) {
      error_message = error_message + "* " + message_1 + "\n";
      error = true;
    } else if (password != confirmation) {
      error_message = error_message + "* " + message_2 + "\n";
      error = true;
    }
  }
}

function check_input(field_name, field_size, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value == '' || field_value.length < field_size) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}