function startupload(progressID)
{
	Janela("progress.asp?progressid="+progressID,null,410,200);
}
function Janela(theURL,winName,w,h)
{
	l = (screen.availWidth-10 - w) / 2;
	t = (screen.availHeight-20 - h) / 2;
	features = "width="+w+",height="+h+",left="+l+",top="+t;
	features += ",screenX="+l+",screenY="+t;
	features += ",scrollbars=0,resizable=0,location=0";
	features += ",menubar=0,toolbar=0,status=0";
	window.open(theURL,winName,features);
}
function runSlideShow()
{
	if (document.all)
	{
		document.body.style.filter="blendTrans(duration=1)";
		document.body.style.filter="blendTrans(duration=crossFadeDuration)";
		document.body.filters.blendTrans.Apply();
		document.body.filters.blendTrans.Play();
	}
	slideOfertasAtual = document.form_ofertas.oferta_atual.value;
	slideLancamentosAtual = document.form_lancamentos.lancamento_atual.value;
	if (slideOfertasAtual != '' && slideLancamentosAtual != '')
	{
		slidesOfertas = document.form_ofertas.ofertas.value;
		proximoSlideOfertas = slidesOfertas.substr(slidesOfertas.indexOf(slideOfertasAtual+'-')+slideOfertasAtual.length+1);
		if (proximoSlideOfertas == '')
			proximoSlideOfertas = slidesOfertas.substr(0,slidesOfertas.indexOf('-'));
		else
			proximoSlideOfertas = proximoSlideOfertas.substr(0,proximoSlideOfertas.indexOf('-'));
		mudaSlideOfertas(slideOfertasAtual,proximoSlideOfertas);
		slidesLancamentos = document.form_lancamentos.lancamentos.value;
		proximoSlideLancamentos = slidesLancamentos.substr(slidesLancamentos.indexOf(slideLancamentosAtual+'-')+slideLancamentosAtual.length+1);
		if (proximoSlideLancamentos == '')
			proximoSlideLancamentos = slidesLancamentos.substr(0,slidesLancamentos.indexOf('-'));
		else
			proximoSlideLancamentos = proximoSlideLancamentos.substr(0,proximoSlideLancamentos.indexOf('-'));
		mudaSlideLancamentos(slideLancamentosAtual,proximoSlideLancamentos);
		setTimeout('runSlideShow()',6000);
	}
}
function mudaSlideOfertas(slideOfertasAtual,proximoSlideOfertas)
{
	divAtual = document.getElementById('oferta'+slideOfertasAtual);
	divAtual.style.display = 'none';
	var divs = document.getElementsByTagName('div');
	for (var i = 0; i < divs.length; i++)
	{
		div = divs[i];
		if (div.id == 'oferta'+proximoSlideOfertas)
			div.style.display = '';
	}
	document.form_ofertas.oferta_atual.value = proximoSlideOfertas;
}
function mudaSlideLancamentos(slideLancamentosAtual,proximoSlideLancamentos)
{
	divAtual = document.getElementById('lancamento'+slideLancamentosAtual);
	divAtual.style.display = 'none';
	var divs = document.getElementsByTagName('div');
	for (var i = 0; i < divs.length; i++)
	{
		div = divs[i];
		if (div.id == 'lancamento'+proximoSlideLancamentos)
			div.style.display = '';
	}
	document.form_lancamentos.lancamento_atual.value = proximoSlideLancamentos;
}
function minusculas(objeto)
{
	campo = eval (objeto);
	campo.value = campo.value.toLowerCase();
}
function maiusculas(objeto)
{
	campo = eval (objeto);
	campo.value = campo.value.toUpperCase();
}
function redireciona()
{
	window.location = "index.asp";
}
function checkUncheckAll(theElement)
{
	var theForm = theElement.form, z = 0;
	while (theForm[z].type == 'checkbox' && theForm[z].name != 'todos')
	{
		theForm[z].checked = theElement.checked;
		z++;
	}
}
function confirmSubmit(theTextConfirm,theTextError,theElement)
{
	var theForm = theElement.form, z = 0;
	var encontrou = false;
	while (theForm[z].type == 'checkbox')
	{
		if (theForm[z].checked)
			encontrou = true;
		z++;
	}
	if (encontrou)
		return confirm(theTextConfirm);
	else
		alert(theTextError);
	return false;
}
function mascaraTelefone(fld,keypress)
{
	campo = eval (fld);
	separador1 = '(';
	separador2 = ')';
	separador3 = '-';
	conjunto1 = 0;
	conjunto2 = 3;
	conjunto3 = 8;
	if (keypress > 47 && keypress < 58)
	{
		if (campo.value.length == conjunto1)
		{
			campo.value = campo.value + separador1;
		}
		if (campo.value.length == conjunto2)
		{
			campo.value = campo.value + separador2;
		}
		if (campo.value.length == conjunto3)
		{
			campo.value = campo.value + separador3;
		}
		return true;
	}
	return false;
}
function mascaraValor(fld, milSep, decSep, e)
{
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	if (len < 10)
	{
		for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
		aux = '';
		for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
		aux += key;
		len = aux.length;
		if (len == 0) fld.value = '';
		if (len == 1) fld.value = '0'+ decSep + '0' + aux;
		if (len == 2) fld.value = '0'+ decSep + aux;
		if (len > 2)
		{
			aux2 = '';
			for (j = 0, i = len - 3; i >= 0; i--)
			{
				if (j == 3)
				{
					aux2 += milSep;
					j = 0;
				}
				aux2 += aux.charAt(i);
				j++;
			}
			fld.value = '';
			len2 = aux2.length;
			for (i = len2 - 1; i >= 0; i--)
				fld.value += aux2.charAt(i);
			fld.value += decSep + aux.substr(len - 2, len);
		}
		return false;
	}
	return false;
}
function mascaraData(keypress,objeto)
{
	campo = eval (objeto);
	separador = '/';
	conjunto1 = 2;
	conjunto2 = 5;
	if (keypress > 47 && keypress < 58)
	{
		if (campo.value.length == conjunto1)
			campo.value = campo.value + separador;
		if (campo.value.length == conjunto2)
			campo.value = campo.value + separador;
		return true;
	}
	else
		return false;
}
function verificaEmail(theForm)
{
	if (theForm.email.value == '')
	{
		alert('Digite o e-mail!');
		theForm.email.focus();
		return false;
	}
	else
	{
		prim = theForm.email.value.indexOf("@");
		if (prim < 2)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf("@",prim + 1) != -1)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf(".") < 1)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf(" ") != -1)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf(";") > 0)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf(".@") > 0)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf("@.") > 0)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf(".com.br.") > 0)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf("/") > 0)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf("[") > 0)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf("]") > 0)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf("(") > 0)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf(")") > 0)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf("'") > 0)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf("\"") > 0)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
		if(theForm.email.value.indexOf("..") > 0)
		{
			alert("O e-mail informado não parece estar correto.");
			theForm.email.focus();
			return false;
		}
	}
	return true;
}
function verificaData(theElement)
{
	if (theElement.value != '')
	{
		var dia = parseInt(theElement.value.substring(0,2),10);
		var mes = parseInt(theElement.value.substring(3,5),10);
		var ano = parseInt(theElement.value.substring(6,10),10);
		data = new Date();
		if (dia <= 31 && mes <= 12 && ano >= 1900)
		{
			if (theElement.value.substring(0,1) == '0' && theElement.value.substring(1,2) != '0' || theElement.value.substring(0,1) != '0')
			{
				if (theElement.value.substring(2,3) == '/')
				{
					if (theElement.value.substring(3,4) == '0' && theElement.value.substring(4,5) != '0' || theElement.value.substring(3,4) != '0')
					{
						if (theElement.value.substring(5,6) == '/')
						{
							if (theElement.value.substring(6,7) == '0' || theElement.value.substring(6,7) == '' && theElement.value.substring(7,8) != '0')
							{
								alert('Verifique a data!');
								theElement.focus();
								return false;
							}
							if (mes == 2)
							{
								if ((dia > 0) && (dia <= 29))
								{
									if (dia == 29)
									{
										if ((ano % 4) != 0)
										{
											alert('Verifique a data!');
											theElement.focus();
											return false;
										}
									}
								}
								else
								{
									alert('Verifique a data!');
									theElement.focus();
									return false; 
								}
							}
							if ((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11))
							{
								if (!((dia > 0 ) && (dia <= 30)))
								{
									alert('Verifique a data!');
									theElement.focus();
									return false;
								}
							}
							if ((mes == 1) || (mes == 3) || (mes == 5) || (mes ==7) || (mes == 8) || (mes == 10) || (mes == 12))
							{
								if (!((dia > 0) && (dia <= 31)))
								{
									alert('Verifique a data!');
									theElement.focus();
									return false;
								}
							}
						}
						else
						{
							alert('Verifique a data!');
							theElement.focus();
							return false;
						}
					}
					else
					{
						alert('Verifique a data!');
						theElement.focus();
						return false;
					}
				}
				else
				{
					alert('Verifique a data!');
					theElement.focus();
					return false;
				}
			}
			else
			{
				alert('Verifique a data!');
				theElement.focus();
				return false;
			}
		}
		else
		{
			alert('Verifique a data!');
			theElement.focus();
			return false;
		}
	}
	return true;
}
function verificaSenha(theForm)
{
	if (theForm.login.value == '')
	{
		alert('Digite o login do usuário!');
		theForm.login.focus();
		return false;
	}
	if (theForm.senha1.value == '')
	{
		alert('Digite a senha!');
		theForm.senha1.focus();
		return false;
	}
	if (theForm.senha2.value == '')
	{
		alert('Confirme a senha!');
		theForm.senha2.focus();
		return false;
	}
	if (theForm.senha1.value != theForm.senha2.value)
	{
		alert('Confirmação de senha não confere!');
		theForm.senha1.focus();
		return false;
	}
	return true;
}
function verificaLinhas(theForm)
{
	if (theForm.familia.value == '')
	{
		alert('Digite o nome da linha de produtos!');
		theForm.familia.focus();
		return false;
	}
	return true;
}
function verificaFornecedores(theForm,progressID)
{
	if (theForm.fornecedor.value == '')
	{
		alert('Digite o nome do fornecedor!');
		theForm.fornecedor.focus();
		return false;
	}
	ext = theForm.imagem.value;
	if (theForm.acao.value == 'incluir')
		if (ext == '')
		{
			alert('Selecione a logomarca do fornecedor!');
			theForm.imagem.focus();
			return false;
		}
	if (ext != '')
	{
		ext = ext.substring(ext.length-3,ext.length);
		ext = ext.toLowerCase();
		if (ext != 'jpg')
		{
			alert('O arquivo selecionado não poderá ser enviado. Formato permitido: JPG!');
			theForm.imagem.focus();
			return false;
		}
		if (ext != '')
			startupload(progressID);
	}
	return true;
}
function verificaGrupos(theForm)
{
	if (theForm.grupo.value == '')
	{
		alert('Digite o nome do grupo!');
		theForm.grupo.focus();
		return false;
	}
	if (theForm.familia_id.selectedIndex == -1)
	{
		alert('Selecione a família!');
		theForm.familia_id.focus();
		return false;
	}
	if (theForm.descricao.value == '')
	{
		alert('Digite uma descrição para o grupo!');
		theForm.descricao.focus();
		return false;
	}
	return true;
}
function verificaImagensGrupos(theForm,progressID)
{
	if (theForm.titulo.value == '')
	{
		alert('Digite o título da imagem!');
		theForm.titulo.focus();
		return false;
	}
	ext = theForm.imagem.value;
	if (ext == '')
	{
		alert('Selecione a imagem!');
		theForm.imagem.focus();
		return false;
	}
	ext = ext.substring(ext.length-3,ext.length);
	ext = ext.toLowerCase();
	if (ext != 'jpg')
	{
		alert('O arquivo selecionado não poderá ser enviado. Formato permitido: JPG!');
		theForm.imagem.focus();
		return false;
	}
	startupload(progressID);
	return true;
}
function verificaFornecedoresGrupos(theForm)
{
	if (theForm.fornecedor_id.selectedIndex == -1)
	{
		alert('Selecione o fornecedor!');
		theForm.fornecedor_id.focus();
		return false;
	}
	return true;
}
function verificaVendedores(theForm)
{
	if (theForm.vendedor.value == '')
	{
		alert('Digite o nome do vendedor!');
		theForm.vendedor.focus();
		return false;
	}
	if (!verificaEmail(theForm))
		return false;
	if (theForm.telefone.value != '')
	{
		if (theForm.telefone.value.length < 13)
		{
			alert('Verifique o telefone do vendedor!');
			theForm.telefone.focus();
			return false;
		}
	}
	return true;
}
function verificaOfertas(theForm,progressID)
{
	if (theForm.titulo.value == '')
	{
		alert('Digite o título!');
		theForm.titulo.focus();
		return false;
	}
	if (theForm.modelo.value == '')
	{
		alert('Digite o modelo!');
		theForm.modelo.focus();
		return false;
	}
	if (theForm.fornecedor_id.selectedIndex == -1)
	{
		alert('Selecione o fornecedor!');
		theForm.fornecedor_id.focus();
		return false;
	}
	if (theForm.grupo_id.selectedIndex == -1)
	{
		alert('Selecione o grupo!');
		theForm.grupo_id.focus();
		return false;
	}
	if (theForm.descricao.value == '')
	{
		alert('Digite uma descrição!');
		theForm.descricao.focus();
		return false;
	}
	if (!verificaData(theForm.validade))
		return false;
	ext = theForm.imagem.value;
	if (ext != '')
	{
		ext = ext.substring(ext.length-3,ext.length);
		ext = ext.toLowerCase();
		if (ext != 'jpg')
		{
			alert('O arquivo selecionado não poderá ser enviado. Formato permitido: JPG!');
			theForm.imagem.focus();
			return false;
		}
		startupload(progressID);
	}
	return true;
}
function verificaLancamentos(theForm,progressID)
{
	if (theForm.titulo.value == '')
	{
		alert('Digite o título!');
		theForm.titulo.focus();
		return false;
	}
	if (theForm.modelo.value == '')
	{
		alert('Digite o modelo!');
		theForm.modelo.focus();
		return false;
	}
	if (theForm.fornecedor_id.selectedIndex == -1)
	{
		alert('Selecione o fornecedor!');
		theForm.fornecedor_id.focus();
		return false;
	}
	if (theForm.grupo_id.selectedIndex == -1)
	{
		alert('Selecione o grupo!');
		theForm.grupo_id.focus();
		return false;
	}
	if (theForm.descricao.value == '')
	{
		alert('Digite uma descrição!');
		theForm.descricao.focus();
		return false;
	}
	ext = theForm.imagem.value;
	if (ext != '')
	{
		ext = ext.substring(ext.length-3,ext.length);
		ext = ext.toLowerCase();
		if (ext != 'jpg')
		{
			alert('O arquivo selecionado não poderá ser enviado. Formato permitido: JPG!');
			theForm.imagem.focus();
			return false;
		}
		startupload(progressID);
	}
	return true;
}
function verificaBanners(theForm,progressID)
{
	if (theForm.titulo.value == '')
	{
		alert('Digite o título!');
		theForm.titulo.focus();
		return false;
	}
	if (theForm.acao.value == 'incluir')
	{
		ext = theForm.imagem.value;
		if (ext == '')
		{
			alert('Selecione o banner!');
			theForm.imagem.focus();
			return false;
		}
		else
		{
			ext = ext.substring(ext.length-3,ext.length);
			ext = ext.toLowerCase();
			if (ext != 'jpg' && ext != 'swf')
			{
				alert('O arquivo selecionado não poderá ser enviado. Formatos permitidos: JPG e SWF!');
				theForm.imagem.focus();
				return false;
			}
			startupload(progressID);
		}
	}
	return true;
}
function verificaCanalZaipo(theForm)
{
	if (theForm.destinatario.value == '')
		return false;
	if (theForm.nome.value == '')
	{
		alert('Digite o seu nome!');
		theForm.nome.focus();
		return false;
	}
	if (!verificaEmail(theForm))
		return false;
	if (theForm.mensagem.value == '')
	{
		alert('Digite a sua mensagem!');
		theForm.mensagem.focus();
		return false;
	}
	return true;
}
function verificaPesquisa(theForm)
{
	if (theForm.palavra.value == '')
	{
		alert('Digite o que deseja pesquisar!');
		theForm.palavra.focus();
		return false;
	}
	if (theForm.palavra.value.length < 2)
	{
		alert('Digite pelo menos duas letras para a pesquisa!');
		theForm.palavra.focus();
		return false;
	}
	return true;
}
