// JavaScript Document
var sitePath = "http://www.fcmariani.org.br/";
var ahahPath = "ahah/"
var iDiv = "ahah";  // target das imagens
var eDiv = "agenda";  // target dos eventos


// Imagens randômicas
function baq_loadContent(url, target){
  req = window.XMLHttpRequest ?
     new XMLHttpRequest() :
     new ActiveXObject("Microsoft.XMLHTTP");
  if (req != undefined) {
    req.onreadystatechange = function() {baq_showContent(target);};
    req.open("GET", url, true);
    req.send("");	
  }
}

function baq_showContent(target){
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
/*      document.getElementById(target).innerHTML = "<div align=center>" + url +
	                                 "<br/><strong>Erro:</strong><br/>"+ req.status +
                            		 "<br/>" +req.statusText + "</div>";*/
      document.getElementById(target).innerHTML = "";
    }
  }
}

function baq_randomImg(){
  var t = 41; // total de imagens, mudar se for o caso
  var i = 0;
  while(i==0){ i = Math.round(t*Math.random())}
  var s = new String;
  if(i < 10){s = "00" + i}
  else if (i < 100){s = "0" + i}
  s = "i" + s;
  var url = sitePath + ahahPath + s + ".htm";
  return url;
}

// produz o url de uma imagem aleatória
function baq_loadImg(){
  var url = baq_randomImg();
  baq_loadContent(url, iDiv);
}




// Agenda

// carrega o próximo evento
function baq_nextDate(){
//  var response = new String;
  var header = '<p class="agendaCap">Agende-se</p>';
  var url = sitePath + ahahPath + "e000.htm"
  req = window.XMLHttpRequest ?
      new XMLHttpRequest() :
      new ActiveXObject("Microsoft.XMLHTTP");
  if (req != undefined) {
      req.open("GET", url, false);
      req.send("");
	  if (req.readyState == 4) { // only if req is "loaded"
        if (req.status == 200) { // only if "OK"
		  // response = req.responseText;
          document.getElementById(eDiv).innerHTML = req.responseText;
        } else { // if not "OK" (não tem nenhum evento)
          document.getElementById(eDiv).innerHTML = "";
        }
    
      }
  }
}


/*// produz as urls das páginas de eventos
function baq_toURL(aDate){
  var iy = aDate.getFullYear();
  var y = iy.toString();
  var im = aDate.getMonth() + 1;
  var m = im < 10 ? "0" + im.toString() : im.toString();
  var id = aDate.getDate();
  var d = id < 10 ? "0" + id.toString() : id.toString();
  var url = sitePath + ahahPath + "e" + y + m + d + ".htm";
  return url;
}

// carrega o envento mais próximo
function baq_nextDate(){
  var days = 40; // número de dias para buscar eventos no futuro 
  //evtLoaded = false;
  var aDate = new Date();
  var file = new String;
  for(i=0;i<days;i++){
    aDate.setDate(aDate.getDate() + 1);
    url = baq_toURL(aDate);
	req = window.XMLHttpRequest ?
      new XMLHttpRequest() :
      new ActiveXObject("Microsoft.XMLHTTP");
    if (req != undefined) {
    req.open("GET", url, false);
    req.send("");
	  if (req.readyState == 4) { // only if req is "loaded"
        if (req.status == 200) { // only if "OK"
          document.getElementById(eDiv).innerHTML = req.responseText;
		  break; // se já encontrou, sai do loop
        } else { // if not "OK" (não tem nenhum evento)
          document.getElementById(eDiv).innerHTML = "";
		}
      }
    }
  }
}*/


// Guia de fundos 
function baq_hideAllBut(showDiv){
  var s = new String;
  var aDiv = 1;
  for(i=1;i<9;i++){
	s = aDiv;
	document.getElementById(s).style.display = aDiv==showDiv ? "block" : "none";
	aDiv++;
    }
	baq_blur();
	// this.blur(); não funciona com IE
}

// Eventos realizados
function baq_hideAllBut2(showDiv){
var s = new String;
var aDiv = 2002;
for(i=2002;i<2009;i++){
	s = aDiv;
	document.getElementById(s).style.display = aDiv==showDiv? "block" : "none";
	aDiv++;
    }
    baq_blur();
}

function baq_blur(){
   document.getElementById("dummy").focus();
}