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_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_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 XMLHTTPRequest() {
	var tXHR=0;
	if (window.XMLHttpRequest) {
		tXHR=new XMLHttpRequest();
	} else {
		try{ tXHR=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(e){
			try { tXHR=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e){ tXHR=false; }
		}
	}
	return tXHR;
}
var tXHR=XMLHTTPRequest();
function carrega(lk,div){
	var conteudo = "";
	if(tXHR){
		conteudo=document.getElementById(""+div+"");
		lk = lk + "&ajax=1&" + Math.ceil ( Math.random() * 100000 );
		conteudo.innerHTML = "<div class='loading'>{carregando}</div>";
		tXHR.open("GET", lk, true);
		tXHR.onreadystatechange=function(){
			if (tXHR.readyState==4){
				if(tXHR.status == 200) {
					repl = /\+/g;
					conteudo.innerHTML = unescape(tXHR.responseText.replace(repl," "));
				}
			}
		}
		tXHR.send(null);
		//setTimeout("hideRecadoBD('')",2000);
	} else {
		alert("Ative as funções de Javascript em seu computador.");
		return false;
	}
}

function getCheckedValue(radioObj, numRadio) {
	if(radioObj.checked){ return radioObj.value; }
	for(var i = 0; i < numRadio; i++) {
		if(radioObj[i].checked) { return radioObj[i].value; }
	}
	//return "aa";
}

function getCheckedRadio(radioObj){
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined){
		if(radioObj.checked){
			return radioObj.value;
		} else {
			return "";
		}
	}
	for(var i=0;i<radioLength;i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


// submitForm(div, form, php, arg1, arg2...)
function submitForm(){
	div = arguments[0];
	form = arguments[1];
	php = arguments[2];
	var poststr = "";
	var vvalue = "";
	for(var j=3; j<arguments.length;j++){
		var vfield = arguments[j];
		if(vfield == "fa_ch"){
			if(eval("document."+form+"." + vfield + ".checked") == true){ vvalue = "1"; } else { vvalue = "0"; }
		} else if(vfield.indexOf("rd_") >= 0){
			vvalue = getCheckedValue(eval("document."+form+"." + vfield),10);
		} else {
			vvalue = eval("document."+form+"." + vfield).value;
		}
		if(vfield == "cod_solucao"){ cod_solucao = vvalue; }
		if(vvalue != "" && vvalue != undefined){
			vvalue = vvalue.replace(/&/g,"*am*");
			vvalue = vvalue.replace(/=/g,"*eq*");
			vvalue = vvalue.replace(/\+/g,"*pl*");
		}
		//poststr += vfield + "=" + encodeURI(vvalue) + "&";
		poststr += vfield + "=" + escape(vvalue) + "&";
	}
	//alert(php+"?"+poststr+" , para "+div+" -- vindo de: "+form);
	carrega(php+"?"+poststr, div);
}

function redBt(BA){
	document.getElementById(""+BA+"").style.backgroundColor="#FF3333";
}


function checkConvida(){
	var erro = "";
	if(document.convideF.r_nomelist.value.length<2){ erro += "SEU NOME\n"; }
	if(document.convideF.r_maillist.value.length<2){ erro += "SEU E-MAIL\n"; }
	if(document.convideF.d_nomelist.value.length<2){ erro += "NOME DO AMIGO\n"; }
	if(document.convideF.d_maillist.value.length<2){ erro += "E-MAIL DO AMIGO\n"; }
	if(erro != ""){
		alert("Preencha todos os campos para enviar o convite\n\n"+erro);
	} else {
		submitForm('divConvide', 'convideF', 'o_access.php', 'r_nomelist', 'r_maillist', 'd_nomelist', 'd_maillist', 'id_conc','assuntoMail','id_cartaz_show','id_curso_show','id_olhaisso_show');
	}	
}

over = function(tdiv){
	var sfEls = "";
	var sfEls = tdiv;
	if(!sfEls.ok){
		sfEls.ok=1;
		sfEls.onmouseover=function(){
			this.className = this.className + " over";
		}
		sfEls.onmouseout=function(){
			this.className = this.className.replace(new RegExp("\\s?over\\b"), "");
		}
		sfEls.className += " over";
	}
};

changeModeSearch = function(mode,t){
	arrModeSearch = new Array("","textos","videos","usuarios");
	for(m=1;m<=t;m++){
		if(m == mode){
			document.getElementById("ms"+m).className = "lkativo";
		} else {
			document.getElementById("ms"+m).className = "lk";
		}
	}
	document.formBusca.modeSearch.value = arrModeSearch[mode];
};





window.defaultStatus = "";
function janela(param,nome,w,h) {
	ns = document.layers;
	ie = document.all;
	rs = "yes";
	sc = "yes";
	if(w == "100%"){
		w = screen.width - 20;
		larg = 10;
	}
	if(h == "100%"){
		h = screen.height - 70;
		alt = 10;
	}
	if(!w) w=500;
	larg = ((screen.width - w)/2) - 12;
	if(!h) h=500;
	if(h == "h") {
		h=(screen.height-70);
		if(navigator.userAgent.indexOf("OS") > 0){ alt = 30; } else { alt = 5; }
		rs = "yes";
		sc = "yes";
	} else {
		alt = ((screen.height - h)/2) - 50;
	}
	if(nome == "PRINTCAPA"){ mn="yes"; tb="yes"; } else { mn="no"; tb="no"; }
	//alert(param+","+nome+",scrollbars="+sc+",location=no,directories=no,status=no,menubar=no,resizable="+rs+",toolbar=no,top="+alt+",left="+larg+",width="+w+",height="+h);
	winvar = window.open(param,nome,"scrollbars="+sc+",location=no,directories=no,status=no,menubar="+mn+",resizable="+rs+",toolbar="+tb+",top="+alt+",left="+larg+",width="+w+",height="+h);
	winvar.focus();
}

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage){
    if ((version >= 5.5) && (version < 7) && (document.body.filters)){
		var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
		var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
		var imgTitle = (myImage.title) ? "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
		var imgStyle = "display:inline-block;" + myImage.style.cssText
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
		+ " style=\"" + "width:" + myImage.width 
		+ "px; height:" + myImage.height 
		+ "px;" + imgStyle + ";"
		+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		+ "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
		myImage.outerHTML = strNewHTML	  
    }
}


function sizeimg(img, v, s){
	iw = Math.floor(eval(img).width);
	ih = Math.floor(eval(img).height);
	//alert("altura 1: "+ih+" = "+eval(img).height + " .");
	if(v == "h" && ih > s){  document.getElementById(img).style.width = ((s/ih) * iw) + "px"; document.getElementById(img).style.height = s+"px"; }
	if(v == "w" && iw > s){ document.getElementById(img).style.height = ((s/iw) * ih) + "px"; document.getElementById(img).style.width = s+"px"; }
	//setTimeout("sizeimg('"+img+"','"+v+"',"+s+")",1000);
}




function showFoto(file){
	document.getElementById("divFoto").style.display = "block";
	document.getElementById("imgAmplia").src = file;
}


function checkOS(){
	if(navigator.userAgent.indexOf('Linux') != -1){
		var OpSys = "Linux";
	} else { 
		if((navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('95') != -1)){
			var OpSys = "Win";
		} else{
			if((navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('98') != -1)){
				var OpSys = "Win";
			} else {
				if(navigator.userAgent.indexOf('Win') != -1){
					var OpSys = "Win";
				} else {
					if(navigator.userAgent.indexOf('Mac') != -1){
						var OpSys = "Macintosh";
					} else {
						var OpSys = "Other";
					}
				}
			}
		}
	}
	return OpSys;
}
var OpSys = checkOS();

function restaura(){
	var myWidth = 0, myHeight = 0;
	if(typeof(window.innerWidth) == 'number'){
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		if(myWidth < 801){ myWidth=788; }
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	if(document.getElementById("divOver")){
		wf = myWidth;
		hf = myHeight;
		//document.getElementById("divOver").style.width = wf + "px";
		document.getElementById("divOver").style.height = hf + "px";
		document.getElementById("divOver").style.width = "100%";
		//document.getElementById("divOver").style.height = "100%";
		document.getElementById("divOver").style.left = "0px";
		document.getElementById("divOver").style.top = "0px";
	}
}

function topOver(){
	if(typeof(window.scrollTop) == 'number'){
		positionY = window.scrollTop;
	} else if(document.documentElement && (document.documentElement.scrollTop)){
		positionY = document.documentElement.scrollTop;
	} else if(document.body && (document.body.scrollTop)){
		positionY = document.body.scrollTop;
	} else {
		var positionY = document.body.scrollTop;
	}
	if(document.getElementById("divOver")){
		document.getElementById("divOver").style.top = (positionY) + "px";
	}
}
function setIntervalo(){
	var intervalo = window.setInterval("topOver()",50);	
}

//document.onLoad = setIntervalo();

function showOver(v){
	if(v == 1){
		document.getElementById("divOver").style.display = "block";
		//document.body.style.overflow = "hidden";
		//document.body.scroll = "no";
		//this.document.body.scroll = 'no'; 
	} else {
		document.getElementById("divOver").style.display = "none";
		document.body.style.overflow = "auto";
		//document.body.scroll = "yes";
	}
}

function topBanner(){
	if(typeof(window.scrollTop) == 'number'){
		positionY = window.scrollTop;
	} else if(document.documentElement && (document.documentElement.scrollTop)){
		positionY = document.documentElement.scrollTop;
	} else if(document.body && (document.body.scrollTop)){
		positionY = document.body.scrollTop;
	} else {
		var positionY = document.body.scrollTop;
	}
	if(document.getElementById("divBanner")){
		if(positionY > 185){
			document.getElementById("divBanner").style.top = (positionY + 5) + "px";
		} else {
			document.getElementById("divBanner").style.top = (185) + "px";
		}
	}
}





function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}
function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 20);
	var timer = 0;
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	changeOpac(0, imageid);
	document.getElementById(imageid).src = imagefile;
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}
function addEvent(elm, evType, fn, useCapture){
	if (elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	}
}
var capanIni = 0;
var capanMax = 0;
function loopimg(){
	capan++;
	if(capan > capanMax){ capan=capanIni; }
	capaImg = "../image/chamada/" + JSvarImg[capan];
	capaTit = JSvarTit[capan];
	capaTxt = JSvarTxt[capan];
	capaLnk = JSvarLnk[capan];
	blendimage('blenddiv','blendimage', capaImg ,100);
	document.getElementById("titulo_ch1").innerHTML = capaTit;
	document.getElementById("texto_ch1").innerHTML = capaTxt;
	document.getElementById("titulo_ch2").innerHTML = capaTit;
	document.getElementById("texto_ch2").innerHTML = capaTxt;
	document.getElementById("linkimage").href = capaLnk;
	for(cf=1;cf<=totCapa;cf++){
		if(capan == cf){
			document.getElementById("btFlash"+cf+"").className = "btFlashAtivo";
		} else {
			document.getElementById("btFlash"+cf+"").className = "btFlash";	
		}
	}
	InitTimer = setTimeout("loopimg()", 6000);
}
function start(){
	document.getElementById("lineBts").style.display="block";
	loopimg();
}
function mudaimg(grp,c){
	capanIni = JSvarGroup[grp][0];
	capanMax = JSvarGroup[grp][JSvarGroup[grp].length - 1];
	capan = c;
	if(InitTimer) clearTimeout(InitTimer);
	loopimg();
}



// FUNCOES SISTEMA EDITORIAL
// #########################

function edInsertLink(myField) {
	var defaultValue = 'http://';
	var URL = prompt('Endereco:' ,defaultValue);
	var URLTemp = URL.substr(7);
	URLText = URLTemp;
	var URLText = prompt('Texto "XXX" que aparece para o leitor:\n<a href="' + URL + '" target="_blank">XXX</a>' ,URLTemp);
	if(URL){
		myValue = '<a href="' + URL + '" target="_blank">' + URLText + '</a>';
		insertAtTexto(myField, myValue);
	}
}

imagemN = 0;
function insertAtTexto(myField, myValue) {
	var selTemp = "";
	if (document.selection) {
		myField.focus();
	    var sel = document.selection.createRange();
		if (sel.text.length > 0) {
			selTemp = sel.text;
		}
		
	} else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		selTemp = myField.value.substring(startPos, endPos);
	}

	if(myValue == "urlInsert"){
		var defaultValue = 'http://';
		var URL = prompt('Endereco:' ,defaultValue);
		if(URL && URL != null){
			if(selTemp == ""){
				var selTemp = URL.substr(7);
				var URLText = prompt('Texto "XXX" que aparece para o leitor:\n<a href="' + URL + '" target="_blank">XXX</a>' ,selTemp);
			} else {
				URLText = selTemp;
			}
			myValue = '<a href="' + URL + '" target="_blank">' + URLText + '</a>';
		} else {
			myValue = "";
		}
	}
	if(myValue == "linkInsert"){
		var defaultValue = 'index.php?id_pg=';
		var URL = prompt('Link para materia:' ,defaultValue);
		if(URL && URL != null){
			if(selTemp == ""){
				var selTemp = "VEJA AQUI";
				var URLText = prompt('Texto que aparece para o leitor:' ,selTemp);
			} else {
				URLText = selTemp;
			}
			myValue = '<a href="' + URL + '">' + URLText + '</a>';
		} else {
			myValue = "";
		}
	}
	if(myValue == "b>" || myValue == "i>"){
		if(selTemp == ""){
			selTemp = prompt('Texto para formatar' ,'');
		}
		myValue = '<' + myValue + '' + selTemp + '</' + myValue;
	}
	
	if(myValue.length > 0){
		if (document.selection) {
			sel.text = myValue;
			myField.focus();
		} else if (myField.selectionStart || myField.selectionStart == '0') {
			myField.value = myField.value.substring(0, startPos)
						  + myValue 
						  + myField.value.substring(endPos, myField.value.length);
			myField.focus();
			myField.selectionStart = startPos + myValue.length;
			myField.selectionEnd = startPos + myValue.length;
		} else {
			myField.value += myValue;
			myField.focus();
		}
	}
}


function Get_Cookie(check_name){
	var a_all_cookies = document.cookie.split(';');
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	for(i=0; i< a_all_cookies.length; i++){
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if(cookie_name == check_name){
			b_cookie_found = true;
			if(a_temp_cookie.length > 1){
				cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if(!b_cookie_found){
		return null;
	}
}

function flash(arquivo, w, h){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + w + '" height="' + h + '">');
	document.write('<param name="movie" value="'+arquivo+'">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<embed src="'+arquivo+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '" WMODE="transparent"></embed>');
	document.write('</object>');
}

function printflash(divf, arquivo, w, h){
	var flp = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + w + '" height="' + h + '">';
	flp += '<param name="movie" value="'+arquivo+'">';
	flp += '<param name="quality" value="high">';
	flp += '<param name="wmode" value="transparent">';
	flp += '<embed src="'+arquivo+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '" WMODE="transparent"></embed>';
	flp += '</object>';
	eval("document.getElementById('"+divf+"')").innerHTML = flp;
}

var musica = "";
var musicaNome = "";
function musicaVars(){
	//alert("MUSICA: "+musica);
	//return "&musica="+musica;
	return musica;
}
function setaMusica(arquivo){
	musica = arquivo;
	alert("MUSICA: "+musica);
}