function abre_index(pagina){
	window.top.location='?p='+pagina;}
function logout(){
	window.top.location='login/login.php?ac=logout';}
function submete(event, id){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if(keyCode==13)
	 document.getElementById(id).submit;}
function abrePag(pag,tp){
	var jan;
	jan=pag+'.php';
	 if(tp!="")
	  jan+='?tp='+tp;
	window.open(jan, 'frame');}
function abreCont(cod){
	window.top.location='?p=visu_cont&cod='+cod;}
function inserirAlterar(marcacao, id){
	if( marcacao ){
		document.getElementById(id).checked = true;}
	else{
		document.getElementById(id).checked = false;}}
function selecionar_todas(retorno){
    var frm = document.sistema;
    for(i = 0; i < frm.length; i++){        
        if(frm.elements[i].type == "checkbox"){        
            frm.elements[i].checked = retorno;}}}
function abrir_foto(Img, iWidth, iHeight, p){
	 if(p==1){
 	   window.open('../visu_foto.php?c=' + Img, 'the_window', "width=" + iWidth + ",height=" + iHeight + ",resizable=yes,scrollbars=yes");}
	 else if(p==2){
 	   window.open('../visu_foto.php?op=2&c=' + Img, 'the_window', "width=" + iWidth + ",height=" + iHeight + ",resizable=yes,scrollbars=yes");}
	 else if(p==3){
 	   window.open('visu_foto.php?op=2&c=' + Img, 'the_window', "width=" + iWidth + ",height=" + iHeight + ",resizable=yes,scrollbars=yes");}
	 else if(p==4){
 	   window.open('visu_foto.php?op=3&c=' + Img, 'the_window', "width=" + iWidth + ",height=" + iHeight + ",resizable=yes,scrollbars=yes");}
	 else if(p==5){
 	   window.open('visu_foto.php?op=4&c=' + Img, 'the_window', "width=" + iWidth + ",height=" + iHeight + ",resizable=yes,scrollbars=yes");}}
function verifica_del_foto(){
	if(document.getElementById('foto').value!=""){
	   document.getElementById('del_foto').checked = false;}}
function abreNoti(cod){
	window.top.location='index.php?p=visu_noti&cod='+cod;}
function abreAlbum(cod){
	window.top.location='index.php?p=visu_album&cod='+cod;}
function abreConv(cod){
	window.top.location='index.php?p=visu_conv&cod='+cod;}
function abreEven(cod){
	window.top.location='index.php?p=visu_agenda&cod='+cod;}
function listaEven(data){
	window.top.location='index.php?p=visu_agenda&data='+data;}
function emailPara(cod){
	window.top.location='index.php?p=fale&paraa='+cod;}
function votar_enq(cod){
	window.top.location='index.php?p=votar_enquete&cod='+cod;}
function resultado_enq(cod){
	window.top.location='index.php?p=visu_enquete&cod='+cod;}
function mostrarTr(acao){
    if(acao=='S'){
	 document.getElementById('tr_partido').style.display = '';
	 document.getElementById('tr_encargo').style.display = '';
	 document.getElementById('tr_email').style.display = '';}
	if(acao=='N'){
	 document.getElementById('tr_partido').style.display = 'none';
	 document.getElementById('tr_encargo').style.display = 'none';
	 document.getElementById('tr_email').style.display = 'none';}}
function abreBatePapo(cod){
	window.top.location='index.php?p=batepapo&sala='+cod;}
function abreVideo(cod){
	window.top.location='index.php?p=visu_video&cod='+cod;}
function formata_data(cod){
	num=document.getElementById(cod).value.length;
	if((num==2)||(num==5))
	 document.getElementById(cod).value=document.getElementById(cod).value+"/";}
function downReque(file,ext,name){
	window.top.location='download.php?file='+file+'&ext='+ext+'&name='+name;}
function getText(url, callback)
{ 
  var XMLHttpRequestObject = false; 
  
  if (window.XMLHttpRequest) {
    XMLHttpRequestObject = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    XMLHttpRequestObject = new 
     ActiveXObject("Microsoft.XMLHTTP");
  }

  if(XMLHttpRequestObject) {
    XMLHttpRequestObject.open("GET", url); 

    XMLHttpRequestObject.onreadystatechange = function() 
    { 
      if (XMLHttpRequestObject.readyState == 4 && 
        XMLHttpRequestObject.status == 200) { 
          callback(XMLHttpRequestObject.responseText); 
          delete XMLHttpRequestObject;
          XMLHttpRequestObject = null;  
      } 
    } 

    XMLHttpRequestObject.send(null); 
  }
}
function ins_td_categoria(resp)
{
	document.getElementById('td_categoria').innerHTML = resp;
}
function fun_categoria(tp)
{
	 if((document.getElementById('n_categoria').value == "")&&(tp!=2))
	  {
		  document.getElementById('td_n_categoria').style.display = '';
	  }
	 else
	  {
		  cat = document.getElementById('n_categoria').value;
		  cl = document.getElementById('categoria').value;
		  document.getElementById('n_categoria').value = '';
		  document.getElementById('td_n_categoria').style.display = 'none';
		  getText('convenios/sel_categoria.php?tipo='+tp+'&cat='+cat+'&cl='+cl,ins_td_categoria);
	  }
}
function ins_td_convenio(resp)
{
	document.getElementById('td_convenio').innerHTML = resp;
}
function sele_con()
{
	var c = document.getElementById('categoria').value;
	getText('convenios/sel_convenio.php?c='+c+'&tt=1',ins_td_convenio);
}
function sele_con_principal()
{
	var c = document.getElementById('categoria').value;
	getText('convenios/sel_convenio.php?c='+c,ins_td_convenio);
}
function disableEnterKey(e)
{
     var key = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;

     if(key == 13)
          return false;
     else
          return true;
}
function mostra_tr(id)
{
	if(document.getElementById(id).style.display=='')
	{
		document.getElementById(id).style.display='none';
	}
	else
	{
		document.getElementById(id).style.display='';
	}
}
function add_opc()
{
	document.getElementById('span_opc').innerHTML+='<input name="opc[]" id="opc[]" type="text" class="inpt" size="40" maxlength="50" onKeyDown="submete(event, \'opcao\')"></br>';
}
function abrePag2(p,pag){
	window.top.location='index.php?p='+p+'&pag='+pag;}
function abrePag3(p,pag){
	var mes = document.getElementById('mes').value;
	var ano = document.getElementById('ano').value;
	window.top.location='index.php?p='+p+'&pag='+pag+'&mes='+mes+'&ano='+ano;}
function abrePag4(p,pag){
	var categoria = document.getElementById('categoria').value;
	window.top.location='index.php?p='+p+'&pag='+pag+'&categoria='+categoria;}
function getText(url, callback)
{
  var XMLHttpRequestObject = false;

  if (window.XMLHttpRequest) {
    XMLHttpRequestObject = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    XMLHttpRequestObject = new
     ActiveXObject("Microsoft.XMLHTTP");
  }

  if(XMLHttpRequestObject) {
    XMLHttpRequestObject.open("GET", url);

    XMLHttpRequestObject.onreadystatechange = function()
    {
      if (XMLHttpRequestObject.readyState == 4 &&
        XMLHttpRequestObject.status == 200) {
          callback(XMLHttpRequestObject.responseText);
          delete XMLHttpRequestObject;
          XMLHttpRequestObject = null;
      }
    }

    XMLHttpRequestObject.send(null);
  }
}
function ver_calendario()
{
	var mes = document.getElementById('mes').value;
	var ano = document.getElementById('ano').value;
	getText('calendario.php?mes='+mes+'&ano='+ano, tdcalendario);
}
function tdcalendario(resp)
{
	document.getElementById('calendario').innerHTML = resp;
}
function atualiza_agenda()
{
	var mes = document.getElementById('mes').value;
	var ano = document.getElementById('ano').value;
	window.top.location='index.php?p=lista_agenda&mes='+mes+'&ano='+ano;
}
function atualiza_videos()
{
	var categoria = document.getElementById('categoria').value;
	window.top.location='index.php?p=lista_videos&categoria='+categoria;
}
function ins_td_marca(resp)
{
	document.getElementById('td_marca').innerHTML = resp;
}
function fun_marca(tp)
{
	 if((document.getElementById('n_marca').value == "")&&(tp!=2))
	  {
		  document.getElementById('td_n_marca').style.display = '';
	  }
	 else
	  {
		  cat = document.getElementById('n_marca').value;
		  cl = document.getElementById('marca').value;
		  document.getElementById('n_marca').value = '';
		  document.getElementById('td_n_marca').style.display = 'none';
		  getText('pianos/sel_marca.php?tipo='+tp+'&cat='+cat+'&cl='+cl,ins_td_marca);
	  }
}
function listaPianos(cod){
	window.top.location='index.php?p=lista_pianos&cod='+cod;}
function abrePiano(cod){
	window.top.location='index.php?p=visu_piano&cod='+cod;}
function visu_med_img(cod, i)
{
	document.getElementById('td_img').innerHTML = "Carregando..."
	getText('pianos/img.php?cod='+cod+'&i='+i, tdimg);
}
function tdimg(resp)
{
	document.getElementById('td_img').innerHTML = resp;
}
