// FUNÇÃO FLASH
function addSWF (URL, WIDTH, HEIGHT, TRANSPARENT){
	document.write (' <object classid="clsid:27CDB6E-AE6D-11cf-96B8-444553540000" ');
	document.write (' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" ');
	document.write (' width="'+ WIDTH +'" height="'+ HEIGHT +'">');
	document.write (' <param name="movie" value="'+ URL +'" />');
	document.write (' <param name="quality" value="high" />');
	
	if ( TRANSPARENT ) {
		document.write (' <param name="Wmode" value="Transparent" />'); 
	}

	document.write (' <embed src="'+ URL +'" quality="high" ');

	if ( TRANSPARENT ) {
		document.write (' Wmode = "transparent" ');
	}

	document.write (' pluginspage="http://www.macromedia.com/go/getflashplayer" ');
	document.write (' type="application/x-shockwave-flash" width="'+ WIDTH +'" height="'+ HEIGHT +'"></embed> ');
	document.write (' </object>');
}

data = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/\d{4}$/;
email = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

function comprar(){
	if (document.comprar.tamanho[document.comprar.tamanho.selectedIndex].value == 0){
		alert("Selecione o tamanho desejado.");
	}
	else {
		document.comprar.action = 'add_produto.php';
		document.comprar.submit();
	}
}

function compra(){
	
	document.comprar.action = 'add_produto.php';
	document.comprar.submit();
	
}

function atualizaCep(){
	document.frmCarrinho.acao.value = "CEP";
	document.frmCarrinho.submit();
}

function atualizaCarrinho(){
	document.frmCarrinho.acao.value = "REFRESH";
	document.frmCarrinho.submit();
}

function confirma(target){
	if (confirm("Deseja excluir este produto do carrinho?")){
		document.location = target;
	}
}

function valida_precadastro() {
	erro = 0;
	cep = document.frmCadastro.cep.value;
	cep = cep.replace(".","");
	cep = cep.replace("-","");
	
	if (!email.test(document.frmCadastro.email.value)){
		alert("E-mail incorreto");
		document.frmCadastro.email.focus();
		erro = 1;
	}
	
	if ((cep.length != 8) && (erro == 0)){
		alert("CEP incorreto");
		document.frmCadastro.cep.focus();
		erro = 1;
	}
	
	if (erro == 0){
		document.frmCadastro.submit();
	}
}

function valida_cadastro() {
	erro = 0;
	cep = document.frmCadastro.cep.value;
	cep = cep.replace(".","");
	cep = cep.replace("-","");
	
	if (!email.test(document.frmCadastro.email.value)){
		alert("E-mail incorreto");
		document.frmCadastro.email.focus();
		erro = 1;
	}
	if ((document.frmCadastro.senha.value.length < 1) && (erro == 0)){
		alert("Preencha o campo 'Senha'.");
		document.frmCadastro.senha.focus();
		erro = 1;
	}
	if ((document.frmCadastro.senha.value != document.frmCadastro.senha2.value) && (erro == 0)){
		alert("Confirmação de senha não confere");
		document.frmCadastro.senha2.focus();
		erro = 1;
	}
	if ((document.frmCadastro.nome.value.length < 1) && (erro == 0)){
		alert("Preencha o campo 'Nome'.");
		document.frmCadastro.nome.focus();
		erro = 1;
	}
	if ((document.frmCadastro.cpf.value.length < 1) && (erro == 0)){
		alert("Preencha o campo 'CPF'.");
		document.frmCadastro.cpf.focus();
		erro = 1;
	}
	if ((document.frmCadastro.rg.value.length < 1) && (erro == 0)){
		alert("Preencha o campo 'RG'.");
		document.frmCadastro.rg.focus();
		erro = 1;
	}
	if ((!data.test(document.frmCadastro.nascimento.value)) && (erro == 0)){
		alert("Data de nascimento incorreta\n\rFormato DD/MM/AAAA");
		document.frmCadastro.nascimento.focus();
		erro = 1;
	}
	if ((document.frmCadastro.endereco.value.length < 1) && (erro == 0)){
		alert("Preencha o campo 'Endereço'.");
		document.frmCadastro.endereco.focus();
		erro = 1;
	}
	if ((document.frmCadastro.numero.value.length < 1) && (erro == 0)){
		alert("Preencha o campo 'Número'.");
		document.frmCadastro.numero.focus();
		erro = 1;
	}
	if ((document.frmCadastro.bairro.value.length < 1) && (erro == 0)){
		alert("Preencha o campo 'Bairro'.");
		document.frmCadastro.bairro.focus();
		erro = 1;
	}
	if ((cep.length != 8) && (erro == 0)){
		alert("CEP incorreto");
		document.frmCadastro.cep.focus();
		erro = 1;
	}
	if ((document.frmCadastro.cidade.value.length < 1) && (erro == 0)){
		alert("Preencha o campo 'Cidade'.");
		document.frmCadastro.cidade.focus();
		erro = 1;
	}
	if ((document.frmCadastro.estado[document.frmCadastro.estado.selectedIndex].value == 0) && (erro == 0)){
		alert("Preencha o campo 'Estado'.");
		document.frmCadastro.estado.focus();
		erro = 1;
	}
	if ((document.frmCadastro.telefone.value.length < 1) && (erro == 0)){
		alert("Preencha o campo 'Telefone'.");
		document.frmCadastro.telefone.focus();
		erro = 1;
	}
	
	if (erro == 0){
		document.frmCadastro.submit();
	}
}

function abre_foto(img){
	w = 650;
	h = 650;
	largura = screen.width;
	altura = screen.height;
	XX =(largura-w)/2;
	YY = (altura-h)/2;
	janela = window.open('img_gr.php?prod_id='+img,'FOTO','width='+w+',height='+h+',left='+XX+',top='+YY+',scrollbars=no,status=no,resizable=no, toolbar=no,directories=no,menubar=no');
	janela.focus();
}

function abreFoto(img){
	w = 550;
	h = 400;
	largura = screen.width;
	altura = screen.height;
	XX =(largura-w)/2;
	YY = (altura-h)/2;
	janela = window.open('fotoloja.php?f='+img,'FOTO','width='+w+',height='+h+',left='+XX+',top='+YY+',scrollbars=no,status=no,resizable=no, toolbar=no,directories=no,menubar=no');
	janela.focus();
}

function medidas(){
	w = 290;
	h = 540;
	largura = screen.width;
	altura = screen.height;
	XX =(largura-w)/2;
	YY = (altura-h)/2;
	janela = window.open('../home/medidas.php','MEDIDAS','width='+w+',height='+h+',left='+XX+',top='+YY+',scrollbars=no,status=no,resizable=no, toolbar=no,directories=no,menubar=no');
	janela.focus();
}
