//Funcoes para o Cantina Zinhani

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
function verificaEmail(newsletter,tipo){
	document.getElementById('acao').value = tipo;
	if(newsletter.email.value == ""){
		alert("Atenção!\nO campo EMAIL deve ser preenchido!");
		newsletter.email.focus();
		return false;
	}
	if(newsletter.email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1){
		alert("Atenção!\nVocê não preencheu o campo EMAIL corretamente!");
		newsletter.email.focus();
		return false;
	}
	return true;
}
//Funcao da Mascara
function fnMascara(objeto, evt, mask)
{ 
	var LetrasU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var LetrasL = 'abcdefghijklmnopqrstuvwxyz';
	var Letras  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';	
	var Numeros = '0123456789';
	var Fixos  = '().-:/ ';
	var Charset = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_/`abcdefghijklmnopqrstuvwxyz{|}~";

	evt = (evt) ? evt : (window.event) ? window.event : "";
	var value = objeto.value;
	if (evt) {
 	var ntecla = (evt.which) ? evt.which : evt.keyCode;
 	tecla = Charset.substr(ntecla - 32, 1);
 	if (ntecla < 32) return true;

 	var tamanho = value.length;
 	if (tamanho >= mask.length) return false;

 	var pos = mask.substr(tamanho,1);
 	while (Fixos.indexOf(pos) != -1)
	 	{
 	 		value += pos;
 	 		tamanho = value.length;
 	 		if (tamanho >= mask.length) return false;
 	 		pos = mask.substr(tamanho,1);
		}

 	switch (pos) 
		{
   			case '#' : if (Numeros.indexOf(tecla) == -1) return false; break;
   			case 'A' : if (LetrasU.indexOf(tecla) == -1) return false; break;
   			case 'a' : if (LetrasL.indexOf(tecla) == -1) return false; break;
   			case 'Z' : if (Letras.indexOf(tecla) == -1) return false; break;
   			case '*' : objeto.value = value; return true; break;
   			default : return false; break;
 		}
	}
	objeto.value = value;
	return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao de popup
function MM_openBrWindow(theURL,winName,features) 
{
	var myWin =  window.open(theURL,winName,features);
	myWin.focus();
}

/////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao para o Menu PopUp

function fnImagemPopUp( titulo, largura , altura , imagem , alt )
{
	var janela ;
	janela = window.open("","popFoto","width="+largura+",height="+altura+",scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,left=300,top=300'");
	janela.document.write('<html><head><title>' + titulo + '</title></head>');
	janela.document.write('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
	janela.document.write('<a href="javascript:window.close();"><img src="'+ imagem + '" alt="' + alt + '" border="0" /></a> ');
	janela.document.write('</body></html>');
}


/////////////////////////////////////////////////////////////////////////////////////////////////

//Fucao Adiciona a Favoritos
function fnAdicionaFavoritos()
{
	str_titulo = ":: Cantina Zinhani ::";
	str_url = "http://www.cantinazinhani.com.br";
	//FireFox
	if (window.sidebar)
	{
   		window.sidebar.addPanel(str_titulo, str_url,"");
	}
	//IE
	else if( window.external )
	{
  		window.external.AddFavorite( str_url, str_titulo);
	}
	//Opera
	else if(window.opera && window.print)
	{
   		return true;
	}
}

////////////////////////////////////////////////////////////////////////////////////////////

//Funcao Validacao do Indique Amigo
function validaIndique(form,evento) {

	if ( form.nome.value == '' )
	{
		alert('Atenção!\nO campo NOME deve ser preenchido.') ;
		form.nome.focus();
		return false ;
	}

	if (form.email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
	{
		alert("Atenção!\nO campo E-MAIL deve ser preenchido.");
		form.email.focus();
		return false;
	}
	
	if (form.emailamigo.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
	{
		alert("Atenção!\nO campo E-MAIL DO AMIGO deve ser preenchido.");
		form.emailamigo.focus();
		return false;
	}
	
	if ( form.mensagem.value == '' )
	{
		alert('Atenção!\nO campo MENSAGEM deve ser preenchido.') ;
		form.mensagem.focus();
		return false ;
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Funcao para o MENU
function fnMudaOn(id) {
	document.getElementById(id).style.display = '' ;
}
	
function fnMudaOff(id) {
	document.getElementById(id).style.display = 'none' ;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao para abrir news
function abrenews(){
document.getElementById('div1').style.display = 'none';
document.getElementById('div2').style.display = 'block';
}
function fechanews(){
document.getElementById('div1').style.display = 'block';
document.getElementById('div2').style.display = 'none';
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao para Abrir  Cardapio
function abrecardapio(){
document.getElementById('div4').style.display = '';
}
function fechacardapio(){
document.getElementById('div4').style.display = 'none';
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Funcao Validacao do Newsletter
function ValidaNews (form) 
{
	if ((form.nome.value.length <= 2 ) || (form.nome.value=="Nome"))
	{
		alert("O campo Seu nome deve ser preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	
	var str_email = form.email.value ;
    if (str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 )
   {
    alert("O campo E-mail deve ser preenchido corretamente");
	form.email.focus();
	return false;
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////

//valida formulario Contato
function ValidaForm_Contato(form){
	
	if(form.nome.value.length<=1){
		alert("O campo Nome deve estar preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	
	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
	
	if(form.telefone.value.length<=1){
		alert("O campo Telefone deve estar preenchido corretamente.");
		form.telefone.focus();
		return false;
	}
	
	if(form.cidade.value.length<=1){
		alert("O campo Cidade deve estar preenchido corretamente.");
		form.cidade.focus();
		return false;
	}
	
	if(form.estado.value.length<=1){
		alert("O campo Estado deve estar selecionado corretamente.");
		form.estado.focus();
		return false;
	}
	
	
	if(form.mensagem.value.length<=1){
		alert("O campo Mensagem deve estar preenchido corretamente.");
		form.mensagem.focus();
		return false;
	}
	
	if(form.cod.value.length<=1){
		alert("O campo Código de Segurança deve estar preenchido corretamente.");
		form.cod.focus();
		return false;
	}

}

//////////////////////////////////////////////////////////////////////////////////////////////

//valida formulario Contato
function ValidaForm_Reservas(form){
	
	if(form.nome.value.length<=1){
		alert("O campo NOME deve estar preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	
	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo E-MAIL deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
	
	if(form.telefone.value.length<=1){
		alert("O campo TELEFONE deve estar preenchido corretamente.");
		form.telefone.focus();
		return false;
	}
	
	if(form.data_reserva.value.length<=1){
		alert("O campo DATA DA RESERVA deve estar preenchido corretamente.");
		form.data_reserva.focus();
		return false;
	}
	
	if(form.numero_pessoas.value.length<=1){
		alert("O campo NUMERO DE PESSOAS deve estar selecionado corretamente.");
		form.numero_pessoas.focus();
		return false;
	}
	
	
	if(form.mensagem.value.length<=1){
		alert("O campo Mensagem deve estar preenchido corretamente.");
		form.mensagem.focus();
		return false;
	}
	
	if(form.cod.value.length<=1){
		alert("O campo Código de Segurança deve estar preenchido corretamente.");
		form.cod.focus();
		return false;
	}

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao para o flash

function fnFlash(str_url, int_largura, int_altura)
{
	document.writeln('<object type="application/x-shockwave-flash" data="' + str_url + '" width="' + int_largura + '" height="' + int_altura + '">');
	document.writeln('<param name="movie" value="' + str_url + '">');
	document.writeln('<param name="quality" value="high">');
	document.writeln('<param name="wmode" value="transparent">');
	document.writeln('</object>');
}


/////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao Validacao do Indique Amigo
function ValidaForm_IndiqueAmigo(form){	

	if (form.nome.value==""){
		alert("O campo Seu nome deve ser preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	
	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo Seu E-mail deve ser preenchido corretamente.");
    	form.email.focus();
    	return false;
	}
	
	var str_email = form.emailamigo.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo E-mail do Destinatário deve ser preenchido corretamente.");
    	form.emailamigo.focus();
    	return false;
	}
	
}
