// Preload de imagens
var img1 = new Image();
img1.src = "imagens/bt_fechar.gif";

var img2 = new Image();
img2.src = "imagens/bt_enviar.gif";

function janela(theURL,Name,W,H)
{ //v2.0
	var win = (screen.width - W) / 2;
	var props = 'left='+win+',top=0,width='+W+',height='+H+',scrollbars=0,alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,status=0,titlebar=1,toolbar=0';

	window.open(theURL,Name,props);
}

function indique()
{
	// Mostra a camada com efeito de transparencia
	flutuante();

	var mostrar = '';
	mostrar += '<div id="indique" class="caixa_flutuante">';
	mostrar += '<form method="post" name="fIndique" id="fIndique" onSubmit="return valida_indique(this);">';
	mostrar += '<h1>Indique o Site</h1>';
	mostrar += "<br>Preencha o formulário abaixo para indicar o site para um amigo:<br><br>";
	mostrar += 'Seu nome:<br>';
	mostrar += '<input type="text" id="seuNome" name="seuNome" class="form"><br>';
	mostrar += 'Seu e-mail:<br>';
	mostrar += '<input type="text" id="seuEmail" name="seuEmail" class="form"><br><br>';
	mostrar += 'Nome do amigo:<br>';
	mostrar += '<input type="text" id="nomeAmigo" name="nomeAmigo" class="form"><br>';
	mostrar += 'E-mail do amigo:<br>';
	mostrar += '<input type="text" id="emailAmigo" name="emailAmigo" class="form"><br><br>';
	mostrar += 'Mensagem: (Opcional)<br>';
	mostrar += '<textarea rows="3" id="mensagem" name="mensagem" class="form"></textarea><br><br>';
	mostrar += '<center><input type="image" name="btEnviar" src="imagens/bt_enviar.gif"> ';
	mostrar += '<a href="javascript:fechar();"><img src="imagens/bt_fechar.gif" class="bt_borda"></a></center>';
	mostrar += '</form>';
	mostrar += '</div>';

	// Escreve e mostra o painel com a enquete
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);

	$("painel").innerHTML = "";
	$("painel").innerHTML = mostrar;
	$("indique").style.left = ((screen.width - 390) / 2) + "px";
	$("indique").style.top = lightboxTop + "px";
	$("painel").style.visibility = 'Visible';
}

function valida_indique(form)
{
	var seuNome = $('seuNome').value;
	var seuEmail = $('seuEmail').value;
	var nomeAmigo = $('nomeAmigo').value;
	var emailAmigo  = $('emailAmigo').value;

	if( seuNome == "" )
	{
		alert("Por favor, preencha o campo: Seu Nome!");
		$('seuNome').focus();
	}
	else if( seuEmail == "" )
	{
		alert("Por favor, preencha o campo: Seu E-mail!");
		$('seuEmail').focus();
	}
	else if( nomeAmigo == "" )
	{
		alert("Por favor, preencha o campo: Nome do destinatário!");
		$('nomeAmigo').focus();
	}
	else if( emailAmigo == "" )
	{
		alert("Por favor, preencha o campo: E-mail do destinatário!");
		$('emailAmigo').focus();
	}
	else
	{
		var url = "ajax/varios.php?opt=indique";
		ajaxForm("indique", form, url, 1);
	}
	return false;
}

function fechar()
{
	// Fecha as janelas abertas
	$("painel").style.visibility = 'hidden';
	$("flutuante").style.visibility = 'hidden';
}

function flutuante ()
{
	// Mostra a camada com efeito de transparencia
	$("flutuante").style.visibility = 'Visible';
	$("flutuante").style.height = document.body.scrollHeight +"px";
	$("flutuante").style.width = document.body.scrollWidth +"px";
}

function $(id)
{
	return document.getElementById(id);
}

function getPageScroll()
{
	var yScroll;

	if( self.pageYOffset )
	{
		yScroll = self.pageYOffset;
	}
	else if( document.documentElement && document.documentElement.scrollTop )
	{	// Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	}
	else if( document.body )
	{	// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('', yScroll) 
	return arrayPageScroll;
}

function getPageSize()
{
	var xScroll, yScroll;
	
	if( window.innerHeight && window.scrollMaxY )
	{	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if( document.body.scrollHeight > document.body.offsetHeight )
	{	// all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{	// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;

	if( self.innerHeight )
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if( document.documentElement && document.documentElement.clientHeight )
	{	// Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if( document.body )
	{	// other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if( yScroll < windowHeight )
	{
		pageHeight = windowHeight;
	}
	else
	{ 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if( xScroll < windowWidth )
	{	
		pageWidth = windowWidth;
	}
	else
	{
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight) 
	return arrayPageSize;
}

function ver_foto(foto)
{
	flutuante();
	
	var mostrar = "";
	mostrar += "<div id='foto_amigos' onClick='fechar();'>";
		mostrar += "<div id='foto_centro'>";
		mostrar += "</div>";
	mostrar += "</div>";
	
	// Escreve e mostra o painel com a enquete
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);

	$("painel").innerHTML = "";
	$("painel").innerHTML = mostrar;
	$("foto_amigos").style.left = ((screen.width - 440) / 2) + "px";
	$("foto_amigos").style.top = lightboxTop + "px";

	var url = "ajax/amigos.php?foto="+ foto;
	ajaxLink("foto_centro", url, 3);

	$("painel").style.visibility = 'Visible';
}