
VerifiqueTAB = false;

function Mostra(quem, tammax) {

	if ( (quem.value.length == tammax) && (VerifiqueTAB) ) {
		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 == quem.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 == quem.name) {
				while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
				(i < document.forms[indice].elements.length) ) {
					i++;
				}

				document.forms[indice].elements[(i+1)].focus();
				VerifiqueTAB=true;
				break;
			}
		}
	}
}

function PararTAB(quem) { VerifiqueTAB=false; }

function ChecarTAB() { VerifiqueTAB=true; }

function suadacao(){
	var data = new Date();
	var hora = data.getHours();
	var saudacao;

	if ((hora < 12) && (hora >= 6)) {
		saudacao = "Bom dia";
	} else if((hora >= 12) && (hora <= 18)) {
		saudacao = "Boa tarde";
	} else {
		saudacao = "Boa noite";
	}
	return saudacao;
}
				
// Mostra Compra Rapida
var timerBotaoCompraRapida = new Array();

function mostrarBotaoCompraRapida (idproduto) {
    clearTimeout(timerBotaoCompraRapida[idproduto]);
    var o = document.getElementById('botaocomprarapida_' + idproduto);
    if (o) {
        o.style.display = 'block';
    }
}

function esconderBotaoCompraRapida (idproduto) {
    esconderBotaoCompraRapidaMesmo(idproduto);
}

function esconderBotaoCompraRapidaMesmo (idproduto) {
    clearTimeout(timerBotaoCompraRapida[idproduto]);
    var o = document.getElementById('botaocomprarapida_' + idproduto);
    if (o) {
        o.style.display = 'none';
    }
}


function mudarImagem(src) {
	document.getElementById('productImage').src = src;
}

function ampliarFotoProdutos(foto) {
	this.target = document.getElementById('ft_produto');
	this.target.src = foto;
}

function compraRapida(){
	var elementos = document.getElementById('produto').getElementsByTagName('td');
	for(i=0; i<elementos.length; i++){
		if(elementos[i].className == 'foto'){
			elementos[i].onmouseover = function(){
				this.getElementsByTagName('div')[0].style.display = "block";
			}
			elementos[i].onmouseout = function(){
				this.getElementsByTagName('div')[0].style.display = "none";
			}
			elementos[i].getElementsByTagName('a')[0].onclick = function(){
				document.getElementById('comprarapida').style.display = 'block';	
			}
		}
	}
}

function showHidden(){

		this.show = function(elemento){
			document.getElementById(elemento).style.display = 'block';
		}

		this.hidden = function(elemento){
			document.getElementById(elemento).style.display = 'none';
		}
}

var objShowHidden = new showHidden();

function abrirFoto(foto,width,height) {
	//abrirJanela('foto-maior.php?foto='+foto,'_blank',300,300,'no');
	window.divopen('foto-maior.php?foto='+foto,width,height);
}

function check_email(email){ return validarEmail(email); }

function validarEmail(email) {
	email = email.toLowerCase();
	tmpEmail = /^[\w-]+(\.[\w-]+)*@(([0-9a-z\d][0-9a-z\d-]{0,61}[0-9a-z\d]\.)+[0-9a-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	eval("tmpEmail = tmpEmail");
	if (tmpEmail.test(email)) return true;
	else return false;
}

function emitirAlerta(msg,obj) {
	if (msg != '') alert(msg);
	if (obj) obj.focus();
}

function boxMarcados(objForm) {
	qtd = 0;
	for (i = 0;i < objForm.elements.length;i++) {
		if (objForm.elements[i].type == 'checkbox') {
			if (objForm.elements[i].checked) {
				qtd++;
			}
		}
	}
	return qtd;
}

function abrirJanela(url,target,w,h) {
	abrirJanelaScroll(url,target,w,h,'no');
}

function abrirJanelaScroll(url,target,w,h,scrollbar) {
	l = parseInt((screen.width - w) / 2);
	t = parseInt((screen.height - h) / 2);
	window.open(url,target,'width='+w+',height='+h+',left='+l+',top='+t+',scrollbars='+scrollbar);
}

function imprimirAudio(arquivo,w,h) {
	//document.write('<embed src="'+arquivo+'" width="'+w+'" height="'+h+'"></embed>');
	document.write('<object id="MediaPlayer1" width='+w+' height='+h+' classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby="Carregando o Windows Media Player" type="application/x-oleobject" align="middle">');
	document.write('<param name="FileName" value="'+arquivo+'">');
	document.write('<param name="AutoStart" value="True">');
	document.write('<param name="ShowStatusBar" value="True">');
	document.write('<param name="DefaultFrame" value="mainFrame">');
	document.write('<embed type="application/x-mplayer2" pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/" src="'+arquivo+'" align="middle" width='+w+' height='+h+' defaultframe="rightFrame" showstatusbar=false></embed>');
	document.write('</object>');
}

function imprimirFlash(arquivo,w,h,transparente,params,id) {
	document.write('<object'+(((typeof id != 'undefined') && (navigator.appVersion.indexOf('MSIE') > -1))?' id="'+id+'"':'')+' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"' + ((typeof w == 'undefined')?'':' width="'+w+'"') + ((typeof h == 'undefined')?'':' height="'+h+'"') + '>');
	document.write('<param name="movie" value="'+arquivo+'">');
	document.write('<param name=quality value=high>');
	document.write('<param name="menu" value="false">');
	if (typeof params != 'undefined') {
		var p = '';

		for (var i in params) {
			p += i + '="' + params[i] + '" ';
			document.write('<param name="'+i+'" value="'+params[i]+'">');
		}
	}
	if (transparente) {
		document.write('<param name="wmode" value="transparent">');
	}
	document.write('<embed'+(((typeof id != 'undefined') && (navigator.appVersion.indexOf('MSIE') < 0))?' id="'+id+'"':'')+' src="'+arquivo+'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"' + ((typeof w == 'undefined')?'':' width="'+w+'"') + ((typeof h == 'undefined')?'':' height="'+h+'"') + ' ');
	if (transparente) {
		document.write('wmode="transparent" ');
	}
	document.write(p);
	document.write(' menu="false"></embed>');
	document.write('</object>');
}

function toggleDisplay(id) {
	if (typeof id == 'string') {
		obj = document.getElementById(id);
	} else {
		obj = id;
	}
	if (obj && obj.style) {
		obj.style.display = (obj.style.display == ''?'none':'');
	}
}

function hiddenDisplay(arrId) {
	for (i = 0;i < arrId.length;i++) {
		if (typeof arrId[i] == 'string') {
			obj = document.getElementById(arrId[i]);
		} else {
			obj = arrId[i];
		}
		obj.style.display = 'none';

	}
}

function validaCPF(cpf){
	s = cpf.substring(0,3) + cpf.substring(4,7) + cpf.substring(8,11) + cpf.substring(12,14);
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (var i = 0; i < 9; i++){
		d1 += c.charAt(i)*(10-i);
	}
	if (d1 == 0){
		return false;
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		return 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){
		return false;
	}

	if (cpf == '111.111.111-11') return false;
	return true;
}

function verificarMascara(tecla,m) {
	if (m == '?') {
		return ('0123456789ABCDEFGHIJKLMNOPQRSTUVXWYZÇÁÀÉÈÃÕÏÖÜÄ'.toLowerCase().indexOf(tecla.toLowerCase()) > -1);
	} else if (m == '#') {
		return ('0123456789'.indexOf(tecla) > -1);
	} else if (m == '$') {
		return ('ABCDEFGHIJKLMNOPQRSTUVXWYZÇÁÀÉÈÃÕÏÖÜÄ'.toLowerCase().indexOf(tecla.toLowerCase()) > -1);
	} else return false;
}

function mascaraCampo(elemento, mascara, event){
	if (navigator.appName.toLowerCase().indexOf("netscape") > -1){
		ntecla=event.which;
	} else {
		ntecla=event.keyCode;
	}

	tecla = String.fromCharCode(ntecla);

	var m = mascara.charAt(elemento.value.length);

	var teclas = new Array(0, 8, 9, 13, 16, 17, 18, 20, 27, 28, 29, 30, 31, 37, 38, 39, 40, 46, 116);

	for (var i = 0; i < teclas.length; i ++) {
		if (teclas[i] == ntecla) {
			return true;
		}
	}

	if ((m == '?') || (m == '#') || (m == '$')) return verificarMascara(tecla,m);
	else {
		elemento.value += mascara.charAt(elemento.value.length);
		m = mascara.charAt(elemento.value.length);
		if (mascara.charAt(elemento.value.length-1) == tecla){
			return false;
		}
		else{
			return verificarMascara(tecla,m);
		}
	}
}

function abrirRadio() {

}

function exibirHitMedia(id) {
	obj = document.getElementById(id);
	if (obj) {
		obj.style.visibility='visible';
		obj.style.position = 'absolute';
	}
}

function esconderHitMedia(id) {
	obj = document.getElementById(id);
	if (obj) {
		obj.style.visibility = 'hidden';
		obj.style.position = 'absolute';
	}
}

function jsQuery(src) {
	var h = document.getElementsByTagName('script')[0];
	var s = document.createElement('script');
	s.setAttribute('type', 'text/javascript');
	s.setAttribute('src', src);
	h.appendChild(s);
}

function inputOnFocus(obj,padrao) {
	if (obj.value == padrao) {
		obj.value = '';
	}
}

function inputOnBlur(obj,padrao) {
	if (obj.value == '') {
		obj.value = padrao;
	}
}

function nextFocusOnFull(obj, event) {
	var teclas = new Array(0, 8, 9, 13, 16, 17, 18, 20, 27, 28, 29, 30, 31, 37, 38, 39, 40, 36, 35);
	if ((obj.value.length == obj.maxLength) && (teclas.indexOf(event.keyCode || event.which) < 0)) {
		for (var i = 0; i < obj.form.elements.length; i++) {
			if (obj.form.elements[i] == obj) {
				var el = obj.form.elements[(i+1) % obj.form.elements.length];
				el.focus();
				event.returnValue = false;
				event.cancelBubble = true;
				if (event.preventDefault) {
					event.preventDefault();
				}
				return true;
			}
		}
	}
}

function inverterSelecao(obj, e) {
	if (e.preventDefault) {
		e.preventDefault();
	} else {
		e.cancelBubble = true;
		e.returnValue = false;
	}
	for (var i = 0; i < obj.form.elements.length; i++) {
		if (obj.form.elements[i].type == 'checkbox') {
			obj.form.elements[i].checked = !obj.form.elements[i].checked;
		}
	}
}

function selecionarState(){
	var states = new Array("AC", "AL", "AM", "AP", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SE", "SP", "TO"), state = document.getElementById('state').value, aux;
	for(var x = 0; x < states.length; x++)
		if(states[x] == state)
			aux = x;
	sComboUf.setSelectedIndex(aux);
}

function prosseguirPrimeiraCompra(){
	if(validarEmail(document.getElementById('cpf2').value)){
			objShowHidden.show('primeira_compra');
			document.getElementById('email').value = document.getElementById('cpf2').value;
	} else {
		alert('Digite um email valido');
	}
}

function confirmarExclusao(endereco,id){
	if(confirm('Voce tem certeza que deseja apagar o endereco '+endereco+'?')) {
		document.getElementById("form_" + id).submit();
	}
}

function oPopup(URL,NAME) {
    window.open(URL, NAME, "width=466,height=450,status=no,crollbars=yes,top=50,left=50")
}

function validarBusca(oform){
	var minLength = 3;
	if(oform.keyword.value.length < minLength){
		alert('Preencha no minimo 3 caracteres para a busca');
	}
	return (oform.keyword.value.length >= minLength);
}
