// Função POP Zoom Imagem
function sizedWindow(img,ntela) {
img1= new Image();
img1.src=(img);
Control(img,ntela);
}

function Control(img,ntela){
if((img1.width!=0)&&(img1.height!=0)) {
viewImg(img,ntela);
}
else{
fun="Control('"+img+"')";
interval=setTimeout(fun,20);
}
}

function viewImg(img,ntela) {
width=img1.width+20;
height=img1.height+20;
myLeft = (screen.width-img1.width)/2;
myTop = (screen.height-img1.height)/2;
string='width='+width+',height='+height+',top='+myTop+',left='+myLeft;
end=window.open(img,ntela,string);
}


// Função para mudança de idioma
function submit_idioma(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


// Função para validação de formulários
function validar_frm(theForm){
	if(theForm.Nome.value==''){
	   alert('O nome deve ser preenchido.')
	   theForm.Nome.focus()
	   return (false);
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.Email.value)){
		//return (true)
	}else{
		alert('O e-mail deve ser preenchido corretamente.')
		theForm.Email.focus()
		return (false);
	}
	if(theForm.Mensagem.value==''){
	   alert('A mensagem de contato deve ser preenchida.')
	   theForm.Mensagem.focus()
	   return (false);
	}
	return (true);
}


// Função para validação de login
function validar_login(theForm){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.Lgn_user.value)){
		//return (true)
	}else{
		alert('O e-mail deve ser preenchido corretamente.')
		theForm.Lgn_user.focus()
		return (false);
	}
	if(theForm.Pass_user.value==''){
	   alert('Digite a sua senha.')
	   theForm.Pass_user.focus()
	   return (false);
	}
	return (true);
}


// Função para máscara de formulários
function Mascara (formato, keypress, objeto){
	campo = eval (objeto);
	
	// CEP
	if (formato=='CEP'){
		separador = '-'; 
		conjunto1 = 5;
	if (campo.value.length == conjunto1){
		campo.value = campo.value + separador;
	}
	}
	
	// DATA
	if (formato=='DATA'){
		separador = '/'; 
		conjunto1 = 2;
		conjunto2 = 5;
	if (campo.value.length == conjunto1){
		campo.value = campo.value + separador;
	}
	if (campo.value.length == conjunto2){
		campo.value = campo.value + separador;
	}
	}
	
	// TELEFONE
	if (formato=='TELEFONE'){
		separador = '-'; 
		conjunto1 = 4;
	if (campo.value.length == conjunto1){
		campo.value = campo.value + separador;
	}
	}
}

// Função para validar o formulário de registro
function validar_registro(theForm){
	
	if(theForm.pessoa.value==''){
	   alert('Informe entre pessoa Física ou Jurídica,\nem seguida complemente adequadamente os respectivos dados.')
	   theForm.pfisica.focus()
	   return (false);
	}

	if(theForm.pessoa.value=='fisica'){ 
	
	   if(theForm.nome.value==''){
		   alert('Nome deve ser preenchido.')
		   theForm.nome.focus()
		   return (false);
	   }
	
	   if(theForm.sobrenome.value==''){
		   alert('Sobrenome deve ser preenchido.')
		   theForm.sobrenome.focus()
		   return (false);
	   }
	   
	   // validação de numeros, funciona perfeitamente
	   if (Number(theForm.cpf.value+1)>0 && theForm.cpf.value!=''){
			//alert('isso sim é número, massa!!!')
	   }else if(theForm.cpf.value!=''){
			alert('Por favor, preencha CPF somente com números.')
			theForm.cpf.focus()
			theForm.cpf.select()
			return false
	   }else{
			alert('Por favor, preencha CPF somente com números.')
			theForm.cpf.focus()
			return false
	   }
	   
	   if(theForm.rg.value==''){
		   alert('RG deve ser preenchido.')
		   theForm.rg.focus()
		   return (false);
	   }

	   if(theForm.dia.value==''|| theForm.mes.value=='' || theForm.ano.value=='') {
		   alert('Data de Nascimento deve ser selecionada por completa.')
		   return (false);
	   }
	   
	   if(theForm.sexo.value==''){
		   alert('Sexo deve ser informado.')
		   theForm.sexo.focus()
		   return (false);
	   }

	}else{ 

	   if(theForm.razao.value==''){
		   alert('Razão Social deve ser preenchida.')
		   theForm.razao.focus()
		   return (false);
	   }  
	
	   if(theForm.contato.value==''){
		   alert('Contato deve ser preenchido.')
		   theForm.contato.focus()
		   return (false);
	   } 
	   
	   if (Number(theForm.cnpj.value+1)>0 && theForm.cnpj.value!=''){
	   }else if(theForm.cnpj.value!=''){
			alert('Por favor, preencha C.N.P.J. somente com números.')
			theForm.cnpj.focus()
			theForm.cnpj.select()
			return false
	   }else{
			alert('Por favor, preencha C.N.P.J. somente com números.')
			theForm.cnpj.focus()
			return false
	   }
	   
	   if (theForm.isento.checked){
	   }else if (Number(theForm.ie.value+1)>0 && theForm.ie.value!=''){
	   }else if(theForm.ie.value!=''){
			alert('Por favor, preencha I.E. somente com números.')
			theForm.ie.focus()
			theForm.ie.select()
			return false
	   }else{
			alert('Por favor, preencha I.E. somente com números.')
			theForm.ie.focus()
			return false
	   }
	   
	} 
	
		if(theForm.endereco.value==''){
		   alert('Endereço deve ser preenchido.')
		   theForm.endereco.focus()
		   return (false);
		}
		
		if (Number(theForm.numero.value+1)>0 && theForm.numero.value!=''){
		}else if(theForm.numero.value!=''){
			alert('Por favor, preencha Nº somente com números.')
			theForm.numero.focus()
			theForm.numero.select()
			return false
		}else{
			alert('Por favor, preencha Nº somente com números.')
			theForm.numero.focus()
			return false
		}
		
		if(theForm.bairro.value==''){
		   alert('Bairro deve ser preenchido.')
		   theForm.bairro.focus()
		   return (false);
		}
	
		if(theForm.cidade.value==''){
		   alert('Cidade deve ser preenchido.')
		   theForm.cidade.focus()
		   return (false);
		}
		
		if(theForm.estado.value==''){
		   alert('Estado deve ser preenchido.')
		   theForm.estado.focus()
		   return (false);
		}
		
		if(theForm.cep.value==''){
		   alert('CEP deve ser preenchido.')
		   theForm.cep.focus()
		   return (false);
		}
		
		if(theForm.pais.value==''){
		   alert('Pais deve ser preenchido.')
		   theForm.pais.focus()
		   return (false);
		}
		
		if(theForm.ddd1.value=='' || theForm.fone1.value=='') {
		   alert('Informe um telefone para contato.')
		   theForm.ddd1.focus()
		   return (false);
		}
	
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value)){
			// return (true)
		}else{
			alert('Email deve ser preenchido corretamente.')
			theForm.email.focus()
			return (false);
		}
		
		if(theForm.senha.value==''){
			alert('Senha deve ser preenchido.')
			theForm.senha.focus()
			return (false);
		}
		
		if(theForm.repetirsenha.value==''){
			alert('O campo Repetir Senha deve conter a mesma informação da senha.')
			theForm.repetirsenha.focus()
			return (false);
		}
	
	return (true);
}

function validar_email(theForm){

		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value)){
			// return (true)
		}else{
			alert('Email deve ser preenchido corretamente.')
			theForm.email.focus()
			return (false);
		}

}

function validar_email_senha(theForm){

		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email_pw.value)){
			// return (true)
		}else{
			alert('Email deve ser preenchido corretamente.')
			theForm.email_pw.focus()
			return (false);
		}

}

// Função para validação do formulário de busca
function validar_busca(theForm){
	if(theForm.produtobusca.value==''){
	   alert('Informe uma palavra-chave.')
	   theForm.produtobusca.focus()
	   return (false);
	}
	return (true);
}