function salvaNovoCurso(curso) {
  var my = new Ajax.Updater(
	    {success: 'manut_cursos'},
      		'cursos_cadastra.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm+"&curso="+encodeURIComponent(curso),
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function carregaCursos(){
  var my = new Ajax.Updater(
	    {success: 'manut_cursos'},
      		'cursos_cadastrados.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function abreCurso(elem, idcurso){
   if(curso_atual != ''){
     curso_atual.style.background = '#ccffcc';
   }
   curso_atual = elem;
   elem.style.background = '#FFCECE';

   var my = new Ajax.Updater(
	    {success: 'curso_cont'},
      		'cursos_conteudo.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm+"&idcurso="+idcurso,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function abreMostraCurso(elem, idcurso){
   if(curso_atual != ''){
     curso_atual.style.background = '#ccffcc';
   }
   curso_atual = elem;
   elem.style.background = '#FFCECE';

   var my = new Ajax.Updater(
	    {success: 'curso_cont'},
      		'cursos_mostra_cont.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm+"&idcurso="+idcurso,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function salvaDescrCab(texto){
  var my = new Ajax.Updater(
	    {success: 'retsalvac'},
      		'cursos_salva.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm+"&texto="+encodeURIComponent(texto)+"&item=1",
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function salvaDescrCurso(id, texto){
  var my = new Ajax.Updater(
	    {success: 'retsalvac'},
      		'cursos_salva.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm+"&idcurso="+id+"&texto="+texto+"&item=2",
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function excluiCurso(id){
  var my = new Ajax.Updater(
	    {success: 'retsalvac'},
      		'cursos_exclui.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm+"&idcurso="+id,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function abreInserirImagem(wysiwyg){
  if($("insi")){
    winIm.destroy();
  }
  winIm = new Window({className: "darkX", title: "", width:410, height:320, destroyOnClose: true, recenterAuto:false, top: 20, left: 100, resizable: false, closable: true, minimizable: false, maximizable: false});
  winIm.getContent().update("<div id='insi' style='background: transparent; height: 100%; text-align: center'><iframe frameborder='0' height='100%' width='100%' src='includes/openwysiwyg/popups/insert_image.php?wysiwyg="+wysiwyg+"'></iframe></div>");
  winIm.showCenter();
}

function abreInserirVideo(wysiwyg){
  if($("insiv")){
    winIv.destroy();
  }
  winIv = new Window({className: "darkX", title: "", width:400, height:100, destroyOnClose: true, recenterAuto:false, top: 20, left: 100, resizable: false, closable: true, minimizable: false, maximizable: false});
  winIv.getContent().update("<div id='insiv' style='background: transparent; height: 100%; text-align: center'><iframe frameborder='0' height='100%' width='100%' src='includes/openwysiwyg/popups/insert_video.php?wysiwyg="+wysiwyg+"'></iframe></div>");
  winIv.showCenter();
}

function verificaForm(){
	if(document.getElementById("nome").value == ''){
		alert("Preencha seu Nome corretamente.");
		document.getElementById("nome").focus();
		return false;
	}else if(document.getElementById("email").value == '' && document.getElementById("fone").value == ''){
		alert("O campo E-mail ou Telefone deve ser preenchido.");
		document.getElementById("email").focus();
		return false;
	}else if(document.getElementById("cidade").value == ''){
        alert("O campo Cidade deve ser preenchido.");
		document.getElementById("cidade").focus();
		return false;
    }else if(document.getElementById("assunto").value == ''){
        alert("O campo Assunto deve ser preenchido.");
		document.getElementById("assunto").focus();
		return false;
    }else if(document.getElementById("msg").value == ''){
        alert("O campo Mensagem deve ser preenchido.");
		document.getElementById("msg").focus();
		return false;
    }

    if(document.getElementById("email").value != ''){
      var mail = document.getElementById("email").value;
      mail1 = mail.split("@");
      if(mail1.length < 2){
        alert ("O conteudo do campo E-mail está incorreto.");
		document.getElementById("email").focus();
		return false;
      }
	}

    var serialized = $("contato").serialize();
    var my = new Ajax.Updater(
	    {success: 'dfc'},
      		'contato_salva.php',
	    {
	 	    method: 'post',
	 	    parameters: serialized,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });

	return false;
}

function alteraDados(login, escola, responsavel, email, endereco, bairro, telefone, cep, cidade, estado) {
  if(escola!="" && responsavel!="" && endereco!="" && telefone!="" && cep!="" && cidade!="" && estado!=""){
    var my = new Ajax.Updater(
  	    {success: 'ret_admsis'},
        		'cadastro_altera.php',
  	    {
  	 	    method: 'post',
  	 	    parameters: "login="+login+"&escola="+encodeURIComponent(escola)+"&responsavel="+encodeURIComponent(responsavel)+"&email="+encodeURIComponent(email)+"&endereco="+encodeURIComponent(endereco)+"&bairro="+encodeURIComponent(bairro)+"&telefone="+encodeURIComponent(telefone)+"&cep="+encodeURIComponent(cep)+"&cidade="+encodeURIComponent(cidade)+"&uf="+encodeURIComponent(estado),
  	 		onFailure: retiraCarr,
  	 	    onCreate: mostraCarr(2),
  	 	    onComplete: retiraCarr,
  	 	    evalScripts: true
  	    });
  } else{
    alert("Todos os campos são obrigatórios!");
  }
}

function testa_senha(login, pass) {
    var my = new Ajax.Updater(
  	    {success: 'r_senha'},
        		'senha_verifica.php',
  	    {
  	 	    method: 'post',
  	 	    parameters: "login="+login+"&senha="+encodeURIComponent(pass),
  	 		onFailure: retiraCarr,
  	 	    onCreate: mostraCarr(2),
  	 	    onComplete: retiraCarr,
  	 	    evalScripts: true
  	    });
}

function Altera_Senha(login, senha) {
  if($('n_senha').value == $('c_senha').value && $('senha').value!=$('n_senha').value && $('senha').value!=$('c_senha').value){
    var my = new Ajax.Updater(
  	    {success: 'r_novasenha'},
        		'senha_nova.php',
  	    {
  	 	    method: 'post',
  	 	    parameters: "login="+login+"&senha="+encodeURIComponent(senha),
  	 		onFailure: retiraCarr,
  	 	    onCreate: mostraCarr(2),
  	 	    onComplete: retiraCarr,
  	 	    evalScripts: true
  	    });
  } else {
    alert('A nova senha e a confirmação devem ser iguais, porém, diferentes da senha antiga!');
  }
}
function Mail_Solicita(login, dados){
  var my = new Ajax.Updater(
	    {success: 'r_mailsolic'},
      		'mail_solicita.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+login+"&dados="+encodeURIComponent(dados),
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}
function cadEscola(){
	if(document.getElementById("cad_cnpj").value == ''){
		alert("CNPJ é um campo obrigatório!");
		document.getElementById("cad_cnpj").focus();
		return false;
	}else if(document.getElementById("cad_escola").value == ''){
		alert("Escola (descrição) é um campo obrigatório!");
		document.getElementById("cad_escola").focus();
        document.getElementById("cad_envia").disabled = false;
		return false;
	}else if(document.getElementById("cad_responsavel").value == ''){
        alert("Responsável é um campo obrigatório!");
		document.getElementById("cad_responsavel").focus();
        document.getElementById("cad_envia").disabled = false;
		return false;
    }else if(document.getElementById("cad_telefone").value == ''){
        alert("Informe um telefone para contato!");
		document.getElementById("cad_telefone").focus();
        document.getElementById("cad_envia").disabled = false;
		return false;
    }else if(document.getElementById("cad_endereco").value == ''){
        alert("Endereço é obrigatório!");
		document.getElementById("cad_endereco").focus();
        document.getElementById("cad_envia").disabled = false;
		return false;
    }else if(document.getElementById("cad_cidade").value == ''){
        alert("Cidade é obrigatório!");
		document.getElementById("cad_cidade").focus();
        document.getElementById("cad_envia").disabled = false;
		return false;
    }else if(document.getElementById("cad_cep").value == ''){
        alert("CEP é obrigatório!");
		document.getElementById("cad_cep").focus();
        document.getElementById("cad_envia").disabled = false;
		return false;
    }else if(document.getElementById("cad_login").value == ''){
        alert("Defina um login de acesso para a nova escola!");
		document.getElementById("cad_login").focus();
        document.getElementById("cad_envia").disabled = false;
		return false;
    }else if(document.getElementById("cad_senha").value == ''){
        alert("Defina uma senha para o acesso da nova escola!");
		document.getElementById("cad_senha").focus();
        document.getElementById("cad_envia").disabled = false;
		return false;
    }
    var serialized = $("nova_escola").serialize();
    var my = new Ajax.Updater(
	    {success: 'r_novaescola'},
      		'cadastro_cria.php',
	    {
	 	    method: 'post',
	 	    parameters: serialized,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
    document.getElementById("cad_envia").disabled = true;
	return false;
}

function mostraCarr(tipo) {
	var cor = (tipo == 1)? '#00CC33' : 'red';
	var car = document.createElement('div');
	car.id = '_carregando';
	car.style.backgroundColor = cor;
	car.style.position = 'absolute';
	car.style.top = '10px';
	car.style.left = '10px';
	car.style.color = '#FFFFFF';
	car.innerHTML = '<span style="font-size: 32px; 	border-width: 3px; border-style: double; border-color: Black; padding: 2px;">&nbsp;<img src="includes/windows_js/themes/alert/progress.gif" border="0">&nbsp;&nbsp;Aguarde...&nbsp;</span>';
	document.body.appendChild(car);
  }

  function retiraCarr() {
	if ($('_carregando'))
		document.body.removeChild($('_carregando'));
  }

var numeros="0123456789";
var letras="abcdefghyjklmnñopqrstuvwxyz";
var letras_maiusculas="ABCDEFGHYJKLMNÑOPQRSTUVWXYZ";

function tem_numeros(texto){
   for(i=0; i<texto.length; i++){
      if (numeros.indexOf(texto.charAt(i),0)!=-1){
         return 1;
      }
   }
   return 0;
}

function tem_letras(texto){
   texto = texto.toLowerCase();
   for(i=0; i<texto.length; i++){
      if (letras.indexOf(texto.charAt(i),0)!=-1){
         return 1;
      }
   }
   return 0;
}

function tem_minusculas(texto){
   for(i=0; i<texto.length; i++){
      if (letras.indexOf(texto.charAt(i),0)!=-1){
         return 1;
      }
   }
   return 0;
}

function tem_maiusculas(texto){
   for(i=0; i<texto.length; i++){
      if (letras_maiusculas.indexOf(texto.charAt(i),0)!=-1){
         return 1;
      }
   }
   return 0;
}

function seguranca_senha(senha){
   var seguranca = 0;
   if (senha.length!=0){
      if (tem_numeros(senha) && tem_letras(senha)){
         seguranca += 40;
      }
      if (tem_minusculas(senha) && tem_maiusculas(senha)){
         seguranca += 30;
      }
      if (senha.length >= 4 && senha.length <= 5){
         seguranca += 20;
      }else{
         if (senha.length >= 6 && senha.length <= 8){
            seguranca += 30;
         }else{
            if (senha.length > 8){
               seguranca += 50;
            }
         }
      }
   }
   if(seguranca>='100'){
	   seguranca='100';
   }
   if(seguranca>='0' && seguranca<='65'){
	   $('seguranca').style.background= 'red';
   } else if(seguranca>'65' && seguranca<='80'){
	   $('seguranca').style.background= 'yellow';
   } else if(seguranca>'80'){
	   $('seguranca').style.background= 'green';
   }
   if(seguranca>='100'){
	   $('seguranca').style.background= 'green';
   }
   $('seguranca').value=seguranca + "%";
   //$('c_senha').focus();
}

function nova_senha(nova){
  if(nova==$('n_senha').value){
    $('salva_alterasenha').style.display='';
    $('conf_senha').innerHTML="<b>Senhas iguais!</b>";
  } else {
    $('salva_alterasenha').style.display='none';
    $('conf_senha').innerHTML="<b>Senhas diferentes!</b>";
  }
}

function configSite(sistema){
  if(!($("ado"))){
    var ie = (document.all)? true: false;
    if(ie){
       var altura = document.body.clientHeight;
    }else {
       var alturas = document.viewport.getDimensions();
       var altura = alturas.height;
    }
    if(altura > 600){
       altura = 640;
    }
    winA = new Window({className: "bluelighting", title: "Administração do Site - "+sistema, width:750, height: (altura - 40), destroyOnClose: true, recenterAuto:false, top: 20, left: 100, resizable: true, closable: true, minimizable: false, maximizable: false});
    winA.getContent().update("<div id='ado' style='background-color: #FFFFD9; height: 100%; overflow: auto;'></div>");
    winA.showCenter();

    var my = new Ajax.Updater(
	    {success: 'ado'},
      		'adm_option.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm+"&sys="+sistema,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
  }
}

function findPosSimpler(id) {
  var off=document.getElementById(id)
  if (off.offsetParent) {
    curleft = off.offsetLeft;
    curtop = off.offsetTop;
    while (off) {
      curleft += off.offsetLeft;
      curtop += off.offsetTop;
      off=off.offsetParent;
    }
  }
  return [curleft,curtop];
}

function mostraTooltip(){
  Dialog.closeInfo();

  var links = document.getElementsByTagName("a");
  var x = 0;

  for (var i = 0; i < links.length; i++){
   if(links[i].title != ""){
    var ida = links[i].id;
/*
    var poss = findPosSimpler(links[i].id);
    var left = poss[0]; //links[i].offsetLeft;
    var top =  poss[1]; //links[i].offsetTop;

    alert(left + ' - ' + top + ' - ' + ida);
*/
    var arr = $(ida).cumulativeOffset();
    var top = arr[1];
    var left = arr[0];
    //alert(ida + ': ' + arr[0] + ' - ' + arr[1]);
    x = (links[i].dir == "ltr")? 0: 1;
    showToolTip(left, top, ida, 'Gerenciar '+links[i].title, x);
   }
  }
}

function loginAdm(){
  if(!($("ado"))){
    var ie = (document.all)? true: false;

    Dialog.confirm($('login').innerHTML, {className:"alphacube", width:400,
     okLabel: "Login", cancelLabel: "Cancelar",
     onOk:function(retLogin){
       var my = new Ajax.Updater(
	    {success: 'retorno'},
      		'adm_login.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+$("logadm").value+"&senha="+$("pasadm").value,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
     }
    });
  }
  if(ie){
     document.body.scrollTop = 0;
  }else {
     window.pageYOffset = 0;
  }
}

function retErroLogin(){
  $('login_error_msg').innerHTML='Usu&aacute;rio ou senha incorreta !!!';
  $('login_error_msg').show();
  Windows.focusedWindow.updateHeight();
  new Effect.Shake(Windows.focusedWindow.getId()); return false;
}

function mostraCursos(){
  if($("curs")){
    winC.destroy();
  }
  var ie = (document.all)? true: false;
    if(ie){
       var altura = document.body.clientHeight;
    }else {
       var alturas = document.viewport.getDimensions();
       var altura = alturas.height;
    }
    if(altura > 600){
       altura = 640;
    }
  winC = new Window({className: "bluelighting", title: "Cursos - Cipex Idiomas", width:750, height: (altura - 40), destroyOnClose: true, recenterAuto:false, top: 20, left: 100, resizable: true, closable: true, minimizable: false, maximizable: false});
  winC.getContent().update("<div id='curs' style='background-color: #FFFFFF; height: 100%; text-align: center; overflow: auto;'></div>");
  winC.showCenter();

  var my = new Ajax.Updater(
	    {success: 'curs'},
      		'cursos_mostra.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function mostraUnidades(tmp){
  if($("unis")){
    winC.destroy();
  }
  var ie = (document.all)? true: false;
    if(ie){
       var altura = document.body.clientHeight;
    }else {
       var alturas = document.viewport.getDimensions();
       var altura = alturas.height;
    }
    if(altura > 600){
       altura = 640;
    }

  winC = new Window({className: "bluelighting", title: "Unidades - Cipex Idiomas", width:750, height: (altura - 40), destroyOnClose: true, recenterAuto:false, top: 20, left: 100, resizable: true, closable: true, minimizable: false, maximizable: false});
  winC.getContent().update("<div id='unis' style='background-color: #FFFFFF; height: 100%; text-align: center; overflow: auto;'></div>");
  winC.showCenter();

  var my = new Ajax.Updater(
	    {success: 'unis'},
      		'unidades_mostra.php',
	    {
	 	    method: 'post',
	 	    parameters: "gerencia="+tmp,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function listaCont(cid, tmp, arquivo, id){
  if(cid != ''){
    var param;
    param = "";
    if($("dini")){
      param = "&dini="+$("dini").value+"&dfim="+$("dfim").value;
    }
    var my = new Ajax.Updater(
	    {success: 'unidlist'},
      		arquivo,
	    {
	 	    method: 'post',
	 	    parameters: "cidade="+cid+"&gerencia="+tmp+param+"&id="+id,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
  }
}

function excluiUn(cn, obj, cor, tmp){
  if(confirm("Deseja realmente excluir do sistema esta Unidade ???")){
    var my = new Ajax.Updater(
	    {success: 'unidlist'},
      		'unidades_exclui.php',
	    {
	 	    method: 'post',
	 	    parameters: "cn="+cn+"&gerencia="+tmp,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
  }else {
    obj.style.backgroundColor = cor;
  }
}

function contato(){
  if($("cto")){
    winCt.destroy();
  }
  var ie = (document.all)? true: false;
    if(ie){
       var altura = document.body.clientHeight;
    }else {
       var alturas = document.viewport.getDimensions();
       var altura = alturas.height;
    }
    if(altura > 600){
       altura = 640;
    }

  winCt = new Window({className: "bluelighting", title: "Contato - Cipex Idiomas", width:750, height: (altura - 40), destroyOnClose: true, recenterAuto:false, top: 20, left: 100, resizable: true, closable: true, minimizable: false, maximizable: false});
  winCt.getContent().update("<div id='cto' style='background-color: #ece9d8; height: 100%; text-align: center; overflow: auto;'></div>");
  winCt.showCenter();

  var my = new Ajax.Updater(
	    {success: 'cto'},
      		'contato_mostra.php',
	    {
	 	    method: 'post',
	 	    parameters: "a=1",
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function listaContato(tmp, arquivo){
    var param;
    param = "";
    if($("dini")){
      param = "&dini="+$("dini").value+"&dfim="+$("dfim").value;
    }
    var my = new Ajax.Updater(
	    {success: 'unidlist'},
      		arquivo,
	    {
	 	    method: 'post',
	 	    parameters: "gerencia="+tmp+param,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function historia(){
  if($("his")){
    winH.destroy();
  }

  winH = new Window({className: "bluelighting", title: "O Cipex", width: "560px", height: "455px", destroyOnClose: true, recenterAuto:false, top: 20, left: 100, resizable: true, closable: true, minimizable: false, maximizable: false});
  winH.getContent().update("<div id='his' style='background-color: #ffffff; height: 100%; width: 98%; text-align: justify; overflow: auto; padding-left: 5px; padding-right: 5px; margin: 0'></div>");
  winH.showCenter();

  var my = new Ajax.Updater(
      {success: 'his'},
   		'cipex_historia.php',
      {
   	    method: 'post',
   	    parameters: "login="+adm,
   		onFailure: retiraCarr,
   	    onCreate: mostraCarr(2),
   	    onComplete: retiraCarr,
   	    evalScripts: true
      });
}

function franquia(){
  if($("fdo")){
    winF.destroy();
  }
  posF = 1;

  winF = new Window({className: "bluelighting", title: "Seja um Franqueado", width: "560px", height: "455px", destroyOnClose: true, recenterAuto:false, top: 20, left: 100, resizable: false, closable: true, minimizable: false, maximizable: false});
  winF.getContent().update("<div id='fdo' style='background-color: #ffffff; height: 100%; width: 555px; text-align: center; overflow: hidden'></div>");
  winF.showCenter();

  var cont = "<div id='ifran' style='height: 100%; width: 553px; overflow: auto'><img src='./imagens/cipex_email_marketing_1.jpg' border=0></div>";
  cont += "<div id='bfran'><a href=\"#\" onmouseover=\"window.status='Cipex Idiomas'; return true;\" onclick=\"imgFranquia(-1); return false;\" title=\"Voltar\"><img src='imagens/137.gif' border=0></a>&nbsp;&nbsp;";
  cont += "<a href=\"#\" onmouseover=\"window.status='Cipex Idiomas'; return true;\" onclick=\"imgFranquia(1); return false;\" title=\"Avan&ccedil;ar\"><img src='imagens/136.gif' border=0></a></div>";

  $("fdo").innerHTML = cont;
}

function imgFranquia(x){
  var nPos = (posF + x);
  if(nPos != 0 && nPos != 7){
    posF = nPos;
    $("ifran").innerHTML = "<iframe frameborder='0' height='100%' width='99%' src='cipex_email_marketing_"+posF+".php?num="+posF+"'></iframe>";
  }
}

function mostraEventos(tmp){
  if($("eve")){
    winE.destroy();
  }
   var ie = (document.all)? true: false;

    if(ie){
       var altura = document.body.clientHeight;
    }else {
       var alturas = document.viewport.getDimensions();
       var altura = alturas.height;
    }
    if(altura > 600){
       altura = 640;
    }

  winE = new Window({className: "bluelighting", title: "Eventos - Cipex Idiomas", width:750, height: (altura - 40), destroyOnClose: true, recenterAuto:false, top: 20, left: 100, resizable: true, closable: true, minimizable: false, maximizable: false});
  winE.getContent().update("<div id='eve' style='background-color: #FFFFFF; height: 100%; text-align: center; overflow: auto;'></div>");
  winE.showCenter();

  var my = new Ajax.Updater(
	    {success: 'eve'},
      		'eventos_mostra.php',
	    {
	 	    method: 'post',
	 	    parameters: "gerencia="+tmp,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function novoEvento(cnp, ger){
  if($("eve2")){
    winE2.destroy();
  }
  winE2 = new Window({className: "darkX", title: "Novo Evento - Cipex Idiomas", width:640, height:330, destroyOnClose: true, recenterAuto:false, top: 20, left: 100, resizable: true, closable: true, minimizable: false, maximizable: false});
  winE2.getContent().update("<div id='eve2' style='height: 100%; text-align: center; overflow: auto;'></div>");
  winE2.showCenter();

  var my = new Ajax.Updater(
	    {success: 'eve2'},
      		'eventos_cadastra.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm+"&cnpj="+cnp+"&gerencia="+ger,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function salvaEvento(conte, tit, cnpj, ger){
 if(confirm("Deseja realmente salvar este Evento ???")){
  var my = new Ajax.Updater(
	    {success: 'seve'},
      		'eventos_salva.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm+"&conteudo="+encodeURIComponent(conte)+"&titulo="+encodeURIComponent(tit)+"&cnpj="+cnpj+"&gerencia="+ger,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
 }
}

function excluiEv(id, obj, cor, tmp){
  if(confirm("Deseja realmente excluir do sistema este Evento ???")){
    var my = new Ajax.Updater(
	    {success: 'unidlist'},
      		'eventos_exclui.php',
	    {
	 	    method: 'post',
	 	    parameters: "id="+id+"&gerencia="+tmp,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
  }else {
    obj.style.backgroundColor = cor;
  }
}

function mostraNoticias(tmp, id){
  if($("noti")){
    winN.destroy();
  }
  var ie = (document.all)? true: false;
    if(ie){
       var altura = document.body.clientHeight;
    }else {
       var alturas = document.viewport.getDimensions();
       var altura = alturas.height;
    }
    if(altura > 600){
       altura = 640;
    }

  winN = new Window({className: "bluelighting", title: "Not&iacute;cias - Cipex Idiomas", width:750, height: (altura - 40), destroyOnClose: true, recenterAuto:false, top: 20, left: 100, resizable: true, closable: true, minimizable: false, maximizable: false});
  winN.getContent().update("<div id='noti' style='background-color: #FFFFFF; height: 100%; text-align: center; overflow: auto;'></div>");
  winN.showCenter();

  var my = new Ajax.Updater(
	    {success: 'noti'},
      		'noticias_mostra.php',
	    {
	 	    method: 'post',
	 	    parameters: "gerencia="+tmp+"&id="+id,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function novaNoticia(cnp, ger){
  if($("noti2")){
    winN2.destroy();
  }
  winN2 = new Window({className: "darkX", title: "Nova Not&iacute;cia - Cipex Idiomas", width:640, height:330, destroyOnClose: true, recenterAuto:false, top: 20, left: 100, resizable: true, closable: true, minimizable: false, maximizable: false});
  winN2.getContent().update("<div id='noti2' style='height: 100%; text-align: center; overflow: auto;'></div>");
  winN2.showCenter();

  var my = new Ajax.Updater(
	    {success: 'noti2'},
      		'noticias_cadastra.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm+"&cnpj="+cnp+"&gerencia="+ger,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}

function salvaNoticia(conte, tit, cnpj, ger){
 if(confirm("Deseja realmente salvar esta Notícia ???")){
  var my = new Ajax.Updater(
	    {success: 'seve'},
      		'noticias_salva.php',
	    {
	 	    method: 'post',
	 	    parameters: "login="+adm+"&conteudo="+encodeURIComponent(conte)+"&titulo="+encodeURIComponent(tit)+"&cnpj="+cnpj+"&gerencia="+ger,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
 }
}

function excluiNo(id, obj, cor, tmp){
  if(confirm("Deseja realmente excluir do sistema esta Notícia ???")){
    var my = new Ajax.Updater(
	    {success: 'unidlist'},
      		'noticias_exclui.php',
	    {
	 	    method: 'post',
	 	    parameters: "id="+id+"&gerencia="+tmp,
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
  }else {
    obj.style.backgroundColor = cor;
  }
}

function enviaVideo(urlv){
  var cont = '<object type="application/x-shockwave-flash" width="250" height="195" data="'+urlv+'"><param name="movie" value="'+urlv+'"/><param name="wmode" value="transparent"/></object>';

  cont += '<br><br>Defina um título: <input type="text" name="titulo" id="titulo" size="50" value=""><hr><input type="button" value="<< Confirmar >>" onclick="salvaVideo($(\'vy\').value, $(\'titulo\').value);">';

  $("sv").innerHTML = cont;
}

function salvaVideo(urlv, titulos){
  var my = new Ajax.Updater(
	    {success: 'sv'},
      		'videos_salva.php',
	    {
	 	    method: 'post',
	 	    parameters: "urlv="+encodeURIComponent(urlv)+"&titulo="+encodeURIComponent(titulos),
	 		onFailure: retiraCarr,
	 	    onCreate: mostraCarr(2),
	 	    onComplete: retiraCarr,
	 	    evalScripts: true
	    });
}
