// JavaScript Document

function acao_logar()
{
	
	try
	{
		
		if (document.getElementById('email').value == '')
		{
			alert('Informe o e-mail!');
			document.getElementById('email').focus();
		}		
		else if (document.getElementById('senha').value == '')
		{
			alert('Informe a senha!');
			document.getElementById('senha').focus();
		}
		else
		{
		
			document.getElementById('acao').value = 'logar';
			document.getElementById('form1').submit();
			
		}
		
	}
	catch(e)
	{
		alert(e.description);
	}
	
	
}

function trocar_diametro(indice)
{

	if (array_diametros[indice])
	{
		
		document.getElementById('img_diametros').src = 'imagens/produtos/diametros/' + array_diametros[indice];
		document.getElementById('codigo_diametro').innerHTML = array_codigos[indice];
	
	}
	
}

function acao_buscar()
{

	if (document.getElementById('txtbusca').value == '')
	{
	
		alert('Digite um parâmetro para busca.');
		document.getElementById('txtbusca').focus();		
		
	}
	else
	{
		
		window.location = 'produtos.php?busca='+document.getElementById('txtbusca').value;
	
	}
	
}

var capsError = 'Atenção:\n\n Caps Lock ativado!';

function capsDetect( e ) 
{
	if( !e ) { e = window.event; } if( !e ) { MWJ_say_Caps( false ); return; }
	//what (case sensitive in good browsers) key was pressed
	var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
	//was the shift key was pressed
	var theShift = e.shiftKey || ( e.modifiers && ( e.modifiers & 4 ) ); //bitWise AND
	//if upper case, check if shift is not pressed. if lower case, check if shift is pressed
	MWJ_say_Caps( ( theKey > 64 && theKey < 91 && !theShift ) || ( theKey > 96 && theKey < 123 && theShift ) );
}

function MWJ_say_Caps( oC ) 
{
	if( typeof( capsError ) == 'string' ) { if( oC ) { alert( capsError ); } } else { capsError( oC ); }
}

function MM_callJS(jsStr) { //v2.0
	return eval(jsStr)
}

function val_email(email)
{
	var reEmail1 = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	
	if(!reEmail1.test(email)) 
		return true;
	else
		return false;
	
}
