// Pega o conteudo da janela "opener" que o abriu, 
// imprime e se fecha automaticamente
function getContentAndPrint(origem)
{
  // Pega o conteudo da janela que o abriu
//  document.getElementById('insConteudo').innerHTML = document.getElementById('insConteudo').innerHTML + opener.getParentContent(origem);
  var strContent = "<html><head><title>FFB - Faculdade Farias Brito</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n<link href=\"_css/geral.css\" type=\"text/css\" rel=\"stylesheet\" /><script language=\"javascript\" src=\"_javascripts/base.js\" type=\"text/javascript\"></script><script language=\"javascript\" src=\"_javascripts/base2.js\" type=\"text/javascript\"></script>\n<script language=\"javascript\" src=\"_javascripts/utils.js\" type=\"text/javascript\"></script></head><body topmargin=0>";
  document.write(strContent+
				 "\n<table width=100% bgcolor=#FFFFFF onLoad=\"window.status='ffbAlunoOnLine'\"><tr><td><div id=conteudo name=conteudo>\n"+
				 document.body.innerHTML+opener.getParentContent(origem)+
				 "<p>&nbsp;</p></td></tr></table>"+
				 "<center><a href=\"#\" onClick=\"JavaScript: window.print();\"><img border=\"0\" src=\"_images/buttons/btnImprimir.gif\"></a></center>"
				 );
  
  // Imprime
  window.print();
  // Fecha a janela de impressão
  //window.close();
}

// Retorna o conteudo HTML do que se deseja imprimir
function getParentContent(origem)
{
	return document.getElementById(origem).innerHTML;
}

// Abre uma nova janela para imprimir o conteudo desejado
function printProc(url)
{
  window.open( 
		url,
		'Imprimir',
		'toolbar=yes,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=660,height=400'
		);
}

function Imprimir(url) {
	window.open(url, 'printableversion','menubar,scrollbars,height=480,width=640,top=10,left=10');
}

function Navigate(url) {
	window.location.href = url;
}

function ValidaFormLogin(form) {
  if (form.id.value == "")
  {
    alert("O campo 'Matrícula' está vazio.\nPor favor, preencha-o.");
    form.id.focus();
    form.id.select();
    return (false);
  }
  if (form.pwd.value == "")
  {
    alert("O campo 'Senha' está vazio.\nPor favor, preencha-o.");
    form.pwd.focus();
    form.pwd.select();
    return (false);
  }
  return true;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function Imprimir(url) {
	window.open(url, 'ffbAlunoOnLine','menubar,scrollbars,height=480,width=640,top=10,left=10');
}

function writeGreetings() {

var d = new Date()
var h = d.getHours()

if (h < 12)
   document.write("Bom dia")
else
  if (h < 18)
     document.write("Boa tarde")
  else
     document.write("Boa noite")

}
function writeDate() {

        hoje = new Date()
        dia = hoje.getDate()
        dias = hoje.getDay()
        mes = hoje.getMonth()
        ano = hoje.getYear()
        if (dia < 10)
                dia = "0" + dia
        if (ano < 2000)
                ano = 1900 + ano
        function CriaArray (n) {
        this.length = n }
        NomeDia = new CriaArray(7)
        NomeDia[0] = "Domingo"
        NomeDia[1] = "Segunda-feira"
        NomeDia[2] = "Ter&ccedil;a-feira"
        NomeDia[3] = "Quarta-feira"
        NomeDia[4] = "Quinta-feira"
        NomeDia[5] = "Sexta-feira"
        NomeDia[6] = "S&aacute;bado"
 
        NomeMes = new CriaArray(12)
        NomeMes[0] = "Janeiro"
        NomeMes[1] = "Fevereiro"
        NomeMes[2] = "Mar&ccedil;o"
        NomeMes[3] = "Abril"
        NomeMes[4] = "Maio"
        NomeMes[5] = "Junho"
        NomeMes[6] = "Julho"
        NomeMes[7] = "Agosto"
        NomeMes[8] = "Setembro"
        NomeMes[9] = "Outubro"
        NomeMes[10] = "Novembro"
        NomeMes[11] = "Dezembro"

        document.write ( NomeDia[dias] + ", " + dia + " de " + NomeMes[mes] + " de " + ano )
}

// set speed of banner (pause in milliseconds between addition of new character)
var speed = 10 

// decrease value to increase speed (must be positive)
// set pause between completion of message and beginning of following message
var pause = 1500 

// increase value to increase pause
// set initial values
var timerID = null
var bannerRunning = false

// create array
var ar = new Array()

// assign the strings to the array's elements
ar[0] = "Bem Vindo ao Site Oficial do Farias Brito"
ar[1] = "Do Maternal a Faculdade,"
ar[2] = "Despontando em Primeiro Lugar."
ar[3] = "Fique ligado em nosso site,"
ar[4] = "Está sempre cheio de novidades"
ar[5] = "www.fariasbrito.com.br"
ar[6] = "Aqui você sabe!" 
// assign index of current message
var message = 0

// empty string initialization
var state = ""

// no value is currently being displayed
clearState()

// stop the banner if it is currently running
function stopBanner() {	
	// if banner is currently running	
	if (bannerRunning)		
	// stop the banner		
	clearTimeout(timerID)	
	// timer is now stopped	
	timerRunning = false
}

// start the banner
function startBanner() {	
	// make sure the banner is stopped	
	stopBanner()	
	// start the banner from the current position	
	showBanner()
}

// assign state a string of "0" characters of the length of the current message
function clearState() {	
	// initialize to empty string	
	state = ""	
	// create string of same length containing 0 digits	
	for (var i = 0; i < ar[message].length; ++i) {		
		state += "0"	
	}
}

// display the current message
function showBanner() {	
	// if the current message is done	
	if (getString()) {		
		// increment message		
		message++		
		// if new message is out of range wrap around to first message		
	if (ar.length <= message)			
		message = 0		
		// new message is first displayed as empty string		
		clearState()		
		// display next character after pause milliseconds		
		timerID = setTimeout("showBanner()", pause)	
	} 
	else {		
		// initialize to empty string		
		var str = ""		
		// built string to be displayed (only character selected thus far are displayed)		
	for (var j = 0; j < state.length; ++j) {			
		str += (state.charAt(j) == "1") ? ar[message].charAt(j) : "     "		
	}		
	// partial string is placed in status bar		
	window.status = str		
	// add another character after speed milliseconds		
	timerID = setTimeout("showBanner()", speed)	
	}
}

function getString() {	
	// set variable to true (it will stay true unless proven otherwise)	
	var full = true	
	// set variable to false if a free space is found in string (a not-displayed char)	
	for (var j = 0; j < state.length; ++j) {		
		// if character at index j of current message has not been placed in displayed string		
		if (state.charAt(j) == 0)			
		full = false	
	}	
	// return true immediately if no space found (avoid infinitive loop later)	
	if (full) return true	
	// search for random until free space found (braoken up via break statement)	
	while (1) {		
		// a random number (between 0 and state.length - 1 == message.length - 1)		
		var num = getRandom(ar[message].length)		
		// if free space found break infinitive loop		
	if (state.charAt(num) == "0")			
		break	
	}	
	// replace the 0 character with 1 character at place found	
	state = state.substring(0, num) + "1" + state.substring(num + 1, state.length)	
	// return false because the string was not full (free space was found)	
	return false
}

function getRandom(max) {	
	// create instance of current date	
	var now = new Date()		
	// create a random number (good generator)	
	var num = now.getTime() * now.getSeconds() * Math.random()	
	// cut random number to value between 0 and max - 1, inclusive	
	return num % max
}
