function gup( name )
{//JMM - Ler parâmetro da URL
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );

 // alert("Resultado " + results[1]);

  if( results == null )
    return "";
  else
    return results[1];
}



function showPag(nPage, xVar)
{
     if (nPage > 1)
          document.getElementById("articleTitle").style.display = "none";
     else
     	document.getElementById("articleTitle").style.display = "inline";

     page = "pag" + nPage;
     
     for (i = 1; i <= xVar; i++)
     {
          xPage = "pag" + i;
          xLink = "link" + i;
          document.getElementById(xPage).style.display = "none";
          document.getElementById(xLink).disabled = false;
     }
     link = "link" + nPage;

     document.getElementById(link).disabled=true;
     document.getElementById(page).style.display = "inline";
     
     location.href="#anchor";     
}

function purgeCache(action)
{
     // -- alert(location.href);
      var url = 'Cache.aspx';                              
      var pars = "cache=" + action;
 
      var myAjax = new Ajax.Updater({success: 'info'}, url, {method: 'get', parameters: pars, onFailure: reportError});                                  
     
     //alert(location.href); 
     location.reload();      
}


function getAgendaByList(cat, imgid, tit)
{
     if (imgid.length > 5)
     {          
         span2 = document.getElementById("imgTitle");
         span2.innerHTML = "<img src='" + imgid + "'/>";
     }
     else
     {
         span1 = document.getElementById(imgid);
         span2 = document.getElementById("imgTitle");
         span2.innerHTML = span1.innerHTML;
     }
    
    document.getElementById("tdTitle").style.display = "inline";
    document.getElementById("agendaCat").innerHTML = tit;

    document.getElementById("agendaHomeBody").innerHTML = "<table height='250'><tr><td>&nbsp;</td></tr></table>";
          
     var url = 'AgendaList.aspx';                              
     var pars = "categoria=" + cat + "&imgid=" + imgid;
     
     var myAjax = new Ajax.Updater({success: 'agendaHomeBody'}, url, {method: 'get', parameters: pars, onFailure: reportError});				                                   
}

function getAgendaList(theForm)
{
     document.getElementById("tdTitle").style.display = "none";
     
     document.getElementById("agendaHomeBody").innerHTML = "<table height='250'><tr><td>&nbsp;</td></tr></table>";
          
     var url = 'AgendaList.aspx';                              
     var pars = "categoria=" + theForm.categoria.value + "&localidade=" + theForm.localidade.value + "&dataIni=" + theForm.dataIni.value + "&dataEnd=" + theForm.dataEnd.value + "&dispcat=1";
     
     var myAjax = new Ajax.Updater({success: 'agendaHomeBody'}, url, {method: 'get', parameters: pars, onFailure: reportError});				                              
     
     return false;     
}

function getAgenda()
{
      document.getElementById("agendaHomeBody").innerHTML = "<table height='250'><tr><td>&nbsp;</td></tr></table>";
      var url = 'AgendaHome.aspx';                              
      var pars = "";

      var myAjax = new Ajax.Updater({success: 'agendaHomeBody'}, url, {method: 'get', parameters: pars, onFailure: reportError});				                              
}

function getAutoSearch(pars)
{
     var url = '/educare/AutoSearch.aspx';                              
     var myAjax = new Ajax.Updater({success: 'resultsAutoSearch'}, url, {method: 'get', parameters: pars, onFailure: reportError});
}

function getUserInfo(id, userid)
{
      //document.getElementById(id).innerHTML = "<table height='20'><tr><td>TESTE&nbsp;</td></tr></table>";
      var url = 'UserInfo.aspx';                              
      var pars = "userid=" + userid;

      var myAjax = new Ajax.Updater({success: id}, url, {method: 'get', parameters: pars, onFailure: reportError});				                              
}

function LoadExames(cid, chid )
{
     if (document.getElementById(cid).style.display == "inline")
     {
          document.getElementById(cid).style.display = "none";
          document.getElementById(cid).innerHTML = "";
     }
     else
     {
          document.getElementById(cid).innerHTML = "<table height='10'><tr><td>&nbsp;</td></tr></table>";          
          document.getElementById(cid).style.display = "inline";
          // document.getElementById("agendaHomeBody").innerHTML = "Aguarde um momento, por favor...";          
          var url = 'ExamesAction.aspx';                              
          var pars = "contentid=" + cid + "&channelid=" + chid;
          var myAjax = new Ajax.Updater({success: cid}, url, {method: 'get', parameters: pars, onFailure: reportError});				                                        
     }
}

function getExames(pars)
{
     var url = 'ExamesAction.aspx';                              
     var myAjax = new Ajax.Updater({success: 'bodyExames'}, url, {method: 'get', parameters: pars, onFailure: reportError});				                              
}

function getExamesDisciplinas(id)
{
     if (document.getElementById(id).style.display == "inline")
          document.getElementById(id).style.display = "none";
     else
          document.getElementById(id).style.display = "inline";
}

function CheckLogin()
{
     var url = '/educare/user/CheckLogin.aspx';       
     var pars = "";
     var myAjax = new Ajax.Updater({success: 'spanLogout'}, url, {method: 'get', parameters: pars, onFailure: reportError});
}     

function reportError(request)
{
     //
}

function getWindowReg(url)
{
     wnd=window.open(url,'_registo','width=610,height=600,scrollbars');
     wnd.focus();
}

	function PopUp(page, myWidth, myHeight) {
		newWind=window.open(page,'popUp','width='+myWidth+',height='+myHeight+',toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,resizable=no');
		
		if(newWind.opener == null) {
			newWind.opener = window;
		}
		else {
			newWind.focus();
		}
	}
	
	function validarSubmit(frm) {

		var retorno = false;
		var resposta; 
		var x=0;
		frm = document.getElementById(frm);

		if (frm.todas.value=='1')
		{
               retorno=true;
          }
          
		if (frm.respostas.checked)
		{
			retorno = true;
		}
		else
		{
			for (x=0; x < frm.respostas.length; x++)
			{
				if (frm.respostas[x].checked)
				{
					retorno = true;
					resposta = frm.respostas[x].value;
				}
			}
		}
		
		if (retorno == false) {
			alert ('Por favor, selecione uma resposta.');
		}else {
			//window.open("about:blank","votacao",'width=350,height=550,toolbar=no,status=no,location=no,menubar=no,directories=no,scrollbars=yes,resizable=yes');
			frm.action="Votacao.aspx";
			//frm.target="votacao";
			frm.submit();
		}
	}
	
	function setResposta(frm, schema, channel, contentid){
		
		frm = document.getElementById(frm);
		frm.resposta_schema.value = schema;
		frm.resposta_channel.value = channel;
		frm.resposta_contentid.value = contentid;
	}
     
	function listAllVotos() {
		//newWind=window.open('Votacao.aspx?all=1','listAllVotos','width=400,height=350,toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,resizable=yes');
		
		//if(newWind.opener == null) {
		//	newWind.opener = window;
		//}
		//else {
		//	newWind.focus();
		//}
          this.location = 'Votacao.aspx?all=1';
	}
     
		
	function comentar(contentid){
		PopUp('Comentario.aspx?contentid=' + contentid ,568,350);
	}
	function arquivar(contentid){
		alert("do something");
	}
	function imprimir(contentid,channel,schema){
		//PopUp('Imprimir.aspx?contentid=' + contentid + '&channel='+ channel + '&schema=' + schema ,570,500);
          this.location = 'Imprimir.aspx?contentid=' + contentid + '&channel='+ channel + '&schema=' + schema;
	}
	function enviar(contentid,channel,schema,titulo){
    //JMM - Alterada a função passando a enviar o opsel correcto
	  this.location = 'Enviar.aspx?opsel='+ gup("opsel") + '&titulo=' + escape(titulo) + '&contentid=' + contentid + '&channel='+ channel + '&schema=' + schema;
	}
  /*
  function enviar(contentid,channel,schema,titulo){
		//PopUp('Enviar.aspx?titulo=' + titulo + '&contentid=' + contentid + '&channel='+ channel + '&schema=' + schema ,500,500);
          this.location = 'Enviar.aspx?opsel=1&titulo=' + escape(titulo) + '&contentid=' + contentid + '&channel='+ channel + '&schema=' + schema;
	} 
  */
	function sugestao(contentid,channel,schema,titulo){
		//JMM - Alterada a função passando a enviar o opsel correcto
    this.location = 'Sugestao.aspx?opsel='+ gup("opsel") + '&titulo=' + escape(titulo) + '&contentid=' + contentid + '&channel='+ channel + '&schema=' + schema;
	}
	
  /*
  function sugestao(contentid,channel,schema,titulo){
		//PopUp('Enviar.aspx?titulo=' + titulo + '&contentid=' + contentid + '&channel='+ channel + '&schema=' + schema ,500,500);
          //alert(unescape(titulo));
          this.location = 'Sugestao.aspx?opsel=1&titulo=' + escape(titulo) + '&contentid=' + contentid + '&channel='+ channel + '&schema=' + schema;
	}
  */
  
  
	function validaComentario(){
		frm = document.forms.frmComentario;
		PopUp('post_comentario.aspx?titulo='+ frm.titulo.value + '&comentario=' + frm.comentario.value + '&contentid=' + frm.contentid.value ,568,350);
	}
	
	function fTMinus(){
		iSeconds=iSeconds-1;
		if(iSeconds<0){
			iSeconds = 59;
			iMinutes=iMinutes-1;
			if(iMinutes<0){
				iMinutes = 59;
				iHours=iHours-1;
			}
		}
		if(iHours == 0 && iMinutes == 0 && iSeconds ==0){
			document.getElementById("PUBLICIDADE").style.display='none';
			clearInterval(); 
		}
	}

	function close(){
		document.getElementById("PUBLICIDADE").style.display='none';
		clearInterval(); 
	}
     

     function showEvento(id)
     {
          if (document.getElementById(id).style.display == "inline")
               document.getElementById(id).style.display = "none";
          else
               document.getElementById(id).style.display = "inline";
     }     

     function hideComboHeader()
     {
          var objCombo = document.getElementById("channelid");          
          objCombo.style.visibility = "hidden";          
     }
     
     function esconde_publi()
     {
          hide();
     }
     
     function hide()
     {
        //  var objCombo = document.getElementById("channelid");          
          //objCombo.style.visibility = "visible";          
          
          var obj = document.getElementById("Interstitials");          
          
          if (obj != null)
               obj.style.visibility = "hidden";
     }     
     
	function changeSize(val)
     {	          
          if (el != null)
          {
               var size = el.style.fontSize.substring(0,2);
               
               var fSize = parseFloat(size,10);
               if (val == 1) {
                    fSize += 1;
                    if (fSize > 20) fSize = 20;
               } else {
                    fSize -= 1;
                    if (fSize < 9) fSize = 9;
               }		
               el.style.fontSize = fSize + 'px';
          }
	}
     