// FUNÇÕES CRIADAS POR JOÃO GILBERTO RECK

function apagaValor(id, valor)
{
	if(document.getElementById(id).value == valor)
		document.getElementById(id).value = '';
}
// FUNÇÃO SELECT C/ LINK
function comboLink(id, path)
{
	location = path + document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
}
// FUNÇÃO PRA ABRIR POPUP
function popup(pagina,w,h)
{    
	var popup = null;		
    popup = window.open(pagina, 'popup', 'toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+w+',height='+h+',left=0,top=0');
	
    if(popup != null)
        popup.location.href = pagina;
}
function popupForm(f,w,h)
{
	var popup = null;
	popup = window.open('', 'janela', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,width='+ w +',height='+ h +',left=0,top=0');
	f.target='janela';
	return true;	
}
// FUNÇÃO PRA ABRIR POPUP COM O MESMO TAMANHO DA IMAGEM
function popUp(dir,img,w,h) // abre pop-up da imagem grande
{
   	var pagina = 'pop_img.php';
	pagina = pagina+"?dir="+dir+"&img="+img;
	var div = w/h;
	var l_max = 800;
	var a_max = 600;
	// algorítmo pra controlar o tamalho da página
	if(w <= l_max)
	{
		if(h <= a_max)
		{
			width = w;
			height = (width/div);
		}
		else
		{
			height = a_max;
			width = (height*div);
		}
	}
	else // senão, se a largura > l_max
	{
		if(h <= a_max)
		{
			height = h;
			width = (height*div);
			if(width > l_max)
			{
				width = l_max;
				height = (width/div);
			}						
		}
		else // senão, se a largura > l_max e altura > l_max
		{
			height = a_max; // altura = l_max
			width = (height*div);
			if(width > l_max)
			{
				width = l_max;
				height = (width/div);
			}
		}
	}
	popup(pagina,width,height);	// função abre o popup
}
// FUNÇÃO PRA ABRIR POPUP DOS ÁUDIO E VÍDEOS
function popWmp(id,tipo)
{    
	//var popup = null;
	if(tipo == "audio")
	{
		var pagina = 'ver_audio.php';		
		var w = 325; 
		var h = 70;
	}
	else
	{
		var pagina = 'ver_video.php';		
		var w = 325; 
		var h = 325;	
	}
	pagina = pagina+"?idFile="+id;	
    popup(pagina,w,h); // função abre o popup 
}
// FUNÇÃO PARA ENVIAR O FORM COM VALIDAÇÃOD E E-MAIL
function validaEmail(id_email)
{    
	str = document.getElementById(id_email).value;		
	// tira espaços em branco do começo da string
	while (str.charAt(0) == " ")
	{
		str = str.substr(1,str.length -1);
	}	
	// tira espaços em branco do fim da string
	while (str.charAt(str.length-1) == " ")
	{
		str = str.substr(0,str.length-1);
	}
	
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str))) 
	{ 
		alert("Favor informar um e-mail válido!");
		document.getElementById(id_email).focus();
		document.getElementById(id_email).select();
		return false;
	}
	else
	{		
		return true;
	}	
}
// FUNÇÃO PARA ENVIAR O FORM DE NEWSLETTER P/ POPUP
function newsletter(f, id_email)
{    
	if(validaEmail(id_email) == true)	
		return popupForm(f,350,100);
	else
		return false;
}
function informe(f) // abre pop-up de confirmação de e-mail cadastrado pra newsletter
{    
	str = f.email.value;		
	// tira espaços em branco do começo da string
	while (str.charAt(0) == " ")
	{
		str = str.substr(1,str.length -1);
	}	
	// tira espaços em branco do fim da string
	while (str.charAt(str.length-1) == " ")
	{
		str = str.substr(0,str.length-1);
	}
	
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str))) 
	{ 
		alert("Favor informar um e-mail válido!");
		f.email.focus();
		f.email.select();
		return false;
	}
	else
	{
		var popup = null
		popup = window.open('' , 'legal' , 'toolbar=no, location=no,directories=no,status=yes,menubar=no,scrollbars=auto,resizable=yes,width=250,height=100,left=0,top=0')
    	f.target='legal';
		return true;
	}	
}
// FUNÇÃO PRA ABRIR POPUP COM O MESMO TAMANHO DA IMAGEM
function popUp(dir,img,w,h) // abre pop-up da imagem grande
{
   	var pagina = 'pop_img.php';
	pagina = pagina+"?dir="+dir+"&img="+img;
	var div = w/h;
	var l_max = 800;
	var a_max = 600;
	// algorítmo pra controlar o tamalho da página
	if(w <= l_max)
	{
		if(h <= a_max)
		{
			width = w;
			height = (width/div);
		}
		else
		{
			height = a_max;
			width = (height*div);
		}
	}
	else // senão, se a largura > l_max
	{
		if(h <= a_max)
		{
			height = h;
			width = (height*div);
			if(width > l_max)
			{
				width = l_max;
				height = (width/div);
			}						
		}
		else // senão, se a largura > l_max e altura > l_max
		{
			height = a_max; // altura = l_max
			width = (height*div);
			if(width > l_max)
			{
				width = l_max;
				height = (width/div);
			}
		}
	}		
	popup = window.open(pagina , 'popup' , 'toolbar=no, location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width='+width+',height='+height+',left=0,top=0')
    if (popup != null)
    {
        popup.location.href = pagina;
    }
}
// abre pop-up da imagem sem redimensionar e com barra de rolagem
function popUpImg(dir, w, h, img) 
{
    var popup = null;
	var pagina = "pop_img_diretoria.php";
	pagina = pagina+"?dir="+dir+"&img="+img;
	var w = w+20;
    popup = window.open(pagina , 'popup' , 'toolbar=no, location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+w+',height='+h+',left=0,top=0')
    if (popup != null)
    {
        popup.location.href = pagina;
    }
}
function todosCamposFale()
{
	if(document.getElementById('nome').value == "" || document.getElementById('email').value == "" || document.getElementById('mensagem').value == "")
	{
		alert("Todos os campos devem ser preenchidos !");
		return false;
	}
	else
	{
		return true;
	}
}
