// JavaScript Document
var marginL = Math.floor((screen.width / 2)-(768/2));
var marginR = marginL+768; 
varJan = 'http://estacaogospel.net/news/cadastro.php';
// ------------------------------------------------ Declaração de Objetos
var layMenu,menuList,dtHora,frmDoc = null;
function registrar() {
	if(document.all) {
		layMenu = document.all.corpoMenu;
		menuList =document.all.listaMenu;
		dtHora = document.all.dataHora;
		frmDoc = document.all.principalFrame;
		frameProg = document.all.indProg;
	} else {
		layMenu = document.getElementById('corpoMenu');
		menuList = document.getElementById('listaMenu');
		dtHora = document.getElementById('dataHora');
		frmDoc = document.getElementById('principalFrame');
		frameProg = document.getElementById('indProg');
	}
}
// ------------------------------------------------ funções Comuns
function aleatorio(inf,spp) { 
var numPoss = spp - inf;
var aleat = Math.random() * numPoss; 
    aleat = Math.floor(aleat);
    return parseInt(inf) + aleat;
}
var cntOpc,indOpc,tmOpc,varOpc = 0;
var opcVer = false;
var objOpc = null;
function opcTrans() {
var tempo;
var a;
	if(opcVer) { indOpc=indOpc+varOpc; } else { indOpc=indOpc-varOpc; }
	if(cntOpc>0) { 
	  if (document.all) {
	  	objOpc.style.filter='Alpha(opacity='+indOpc+')';
	  } else {
	  	objOpc.style.MozOpacity=(indOpc/100);	
	  }
	  cntOpc--;
	  tempo = setTimeout("opcTrans()",tmOpc);
	} else {
	  clearTimeout(tempo);
	}
}
function opacidadeTrans(objeto,tempo,ver) {
	objOpc = document.getElementById(objeto);
	cntOpc = 20; // nr. de variações dentro do período de tempo
	varOpc = (100/cntOpc);
	tmOpc = (tempo*1000)/cntOpc;
	opcVer = ver;
	if(ver) { indOpc=0; } else { indOpc = 100;}
	opcTrans();
}
function carregar(p) {
	frmDoc.src = './cad/'+p;
}
var timerScroll;
function scrollFrm(frm,inc) {
  if (timerScroll) clearTimeout(timerScroll);
  if (window.frames[frm]) {
    window.frames[frm].scrollBy(0, inc);
    timerScroll = setTimeout("scrollFrm('" + frm + "'," + inc + ")",40);
  }
}
function stopTimer() { if (timerScroll) clearTimeout(timerScroll); }
function scrlFrame(frm,inc) {
	window.frames[frm].scrollBy(0, inc);
}
function refreshFrame() {
	if(document.all) {
		var	x = document.frames('indProg').location.reload(true);
	} else {
		frameProg.src = "http://estacaogospel.net/bin/rd_prog3.php";
	}
}
// ------------------------------------------------------------ MENUS ***
function mn(lista,x) {
var list = eval(lista);
var tam = list.length;
var tx = '';
  for (i=0;i<tam;i++) {
	tx += "<div id='mnItem'"+i+"' class='itemMenu' onmouseover='mnSobre(true,this);' ";
	tx += "onmouseout='mnSobre(false,this);' style='cursor:pointer;cursor:hand;' ";
	tx += "onclick="+list[i].fct+";>";
	tx += list[i].tit+"</div>\n";
  }
  menuList.innerHTML = tx;
  layMenu.style.left = (marginR - x);
  layMenu.style.visibility='visible';
}
function iMenu(tit,fct) {
	this.tit = tit;
	this.fct = fct;
}
function mnS() {
	layMenu.style.visibility='hidden';
}
function mnSobre(vlr,obj) {
	if (vlr) {
		obj.style.background="#DDEAEE";
		obj.style.color="#0099CC";
	} else {
		obj.style.background="#ffffff";
		obj.style.color="#333333";
	}
}
var mOuca = new Array(3);
mOuca[0] = new iMenu("Windows Média Player","winmedia()");
mOuca[1] = new iMenu("Winamp","winamp()");
mOuca[2] = new iMenu("Real Player","realplayer()");
var mPart = new Array(5);
mPart[0] = new iMenu("Cadastramentos","carregar('cadastrar.htm')");
mPart[1] = new iMenu("Alterações","carregar('alterar.htm')");
mPart[2] = new iMenu("Esqueci a Senha","carregar('esqueci.htm')");
mPart[3] = new iMenu("Privacidade","carregar('privacidade.htm')");
mPart[4] = new iMenu("Dúvidas","carregar('ajuda.htm')");
// ------------------------------------------------------------final MENUS ***
function hora() {
	makeRequest('../bin/hora.php', '', 'data');
}
// ------------------------------------------------------------ Timer
var ct_minuto = 0;
var ct_Palco = 0;
var pPalco = true;
function tempo() {
	if(ct_minuto==480) { hora(); refreshFrame(); ct_minuto=0; } else { ct_minuto++; }
	if(pPalco) { if(ct_Palco==96) { ct_Palco=0; pPalco=false; intro(); } else { ct_Palco++; } }
}
//-- final timer

// ----------------------------------------------------------- início código AJAX
function makeRequest(url, valores, objeto) {
	http_request = false;
	_obj = objeto;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
    	http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
		try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
        try {
              http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        alert('Giving up :( Impossível instanciar objeto XMLHTTP!');
        return false;
    }
	http_request.onreadystatechange = function() { alertContents(http_request); };
	if (valores!='') {
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http_request.send(valores);
	} else {
	  if(document.all) { http_request.open('PUT', url, true); }
		else { http_request.open('GET', url, true); }
		http_request.send(null); 
	}
}
function alertContents(http_request) {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
			var doc = http_request.responseText;
			switch (_obj) {
				case 'data': dtHora.innerHTML = doc
					break 
			}
        } else {
			var doc = 'There was a problem with the request.';
            alert('Algum problema ocorreu com o retorno da chamada!');
        }
    }
}
// ------------------------------------------------------------ final do AJAX
function iniciar() {
	registrar();
	carregar(_pg);
	hora();
	setInterval("tempo()", 125);    // A CADA OITAVOS DE SEGUNDO ***********
}
var verPalco = true;
function intro() {
	pPalco = false;
	if (verPalco) {
		opacidadeTrans2('palco2',3,true);
		verPalco = false;
	} else {
		opacidadeTrans2('palco2',3,false);
		verPalco = true;
	}
	pPalco = true;
}
var cntOpc2,indOpc2,tmOpc2,varOpc2 = 0;
var opcVer2 = false;
var objOpc2 = null;
function opcTrans2() {
var tempo2;
	if(opcVer2) { indOpc2=indOpc2+varOpc2; } else { indOpc2=indOpc2-varOpc2; }
	if(cntOpc2>0) { 
	  if (document.all) {
	  	objOpc2.style.filter='Alpha(opacity='+indOpc2+')';
	  } else {
	  	objOpc2.style.MozOpacity=(indOpc2/100);	
	  }
	  cntOpc2--;
	  tempo2 = setTimeout("opcTrans2()",tmOpc2);
	} else {
	  clearTimeout(tempo2);
	}
}
function opacidadeTrans2(objeto,tempo,ver) {
	objOpc2 = document.getElementById(objeto);
	cntOpc2 = 20; // nr. de variações dentro do período de tempo
	varOpc2 = (100/cntOpc2);
	tmOpc2 = (tempo*1000)/cntOpc2;
	opcVer2 = ver;
	if(ver) { indOpc2=0; } else { indOpc2 = 100;}
	opcTrans2();
}
// --------------------------------------------------------- Funções 
function winmedia() {
 winPlayer = window.open("http://estacaogospel.net/pluggins/testar.htm","winPlayer","width=400,height=225");
}
function winamp() {
	window.open('http://estacaogospel.net/player/estacaogospel_winamp.m3u','_blank');
}
var janSomReal;
function realplayer() {
	janSomReal = window.open('mms://radios.acessaradios.com.br:9090/estacaogospel','_blank');
	setTimeout(goNews(),3200);
}
function goNews() { janSomReal.location = "http://www.estacaogospel.net/news/news.php"; }
//--