﻿//--------------------------------------------------------------------//
//      Funções de slide do menu via mootools                         //
//                                                                    //
//       Criado por: Pedro Moreira - 29/01/2008                       //
//   Modificado por:               - --/--/----                       //
//--------------------------------------------------------------------//
//--------------------------------------------------------------------//
//                          fctMenuSlide()                            //
//--------------------------------------------------------------------//
function fctMenuSlide(){
    if($$('.Menu') != "")
    {
        var init = false;
        var slide = new Fx.Slide('pq_unitelco_menu');

        if(!init)
        {
            slide.hide()
            init = true;
        }
        $$('.pq_unitelco_menu_img').addEvent("mouseover", function(){
            slide.toggle();
        });
    }
}

//--------------------------------------------------------------------//
//                      fctMenuInternoSlide()                         //
//--------------------------------------------------------------------//
function fctMenuInternoSlide(){
    if($$('.Menu') != "")
    {
        $$('.pq_unitelco_area').addEvent("mouseenter", function(){
            $$('.pq_unitelco_menu').setStyle("display", "block");
        });
        var slidep1 = new Fx.Slide("p_01");
        slidep1.hide();
        var slidep2 = new Fx.Slide("p_02");
        slidep2.hide();
        var slidep3 = new Fx.Slide("p_03");
        slidep3.hide();
        var slidep4 = new Fx.Slide("p_04");
        slidep4.hide();
        var slidep5 = new Fx.Slide("p_05");
        slidep5.hide();
        var slidep6 = new Fx.Slide("p_06");
        slidep6.hide();
        var slidep7 = new Fx.Slide("p_07");
        slidep7.hide();
        var slidep8 = new Fx.Slide("p_08");
        slidep8.hide();

        var lis = $('pq_unitelco_menu').getElements('li');

        lis.each(function(li, i){
            li.addEvent("click", function(e){
                e = new Event(e); 
                if(i == 0){
                    slidep = slidep1;
                }
                else if(i == 1){
                    slidep = slidep2;
                }
                else if(i == 2){
                    slidep = slidep3;
                }
                else if(i == 3){
                    slidep = slidep4;
                }
                else if(i == 4){
                    slidep = slidep5;
                }
                else if(i == 5){
                    slidep = slidep6;
                }
                else if(i == 6){
                    slidep = slidep7;
                }
                else if(i == 7){
                    slidep = slidep8;
                }
                slidep.toggle();
               e.stop(); 
            });
        });
        $$('.Menu').addEvent("mouseleave", function(){
          $$('.pq_unitelco_menu').setStyle("display", "none");
          slidep1.hide();
          slidep2.hide();
          slidep3.hide();
          slidep4.hide();  
          slidep5.hide();
          slidep6.hide();
          slidep7.hide();
          slidep8.hide();
        });
        $$('.pq_unitelco_integra').addEvent("mouseleave", function(){
          $$('.pq_unitelco_menu').setStyle("display", "none");
          slidep1.hide();
          slidep2.hide();
          slidep3.hide();
          slidep4.hide();  
          slidep5.hide();
          slidep6.hide();
          slidep7.hide();
          slidep8.hide();
        });
    }
}



/* Criado por Leonard Hofmann - criado em 15*01*2008 - contato - leonard.hofmann@focusnetworks.com.br
   Modificado por ----------- - modificado em --*--*---- - contato - ----@-------.com.br */
//id do objeto para troca do css, string que recebe parametro de 'open' ou 'close'   
function OpenCloseDisplay(id, string)
{
    var oObj = document.getElementById(id);
    if(string == "open"){oObj.className = 'display_block';}else if(string == "close" || string == ""){oObj.className = 'display_none';}
}

/* Criado por Leonard Hofmann - criado em 29*01*2008 - contato - leonard.hofmann@focusnetworks.com.br
   Modificado por ----------- - modificado em --*--*---- - contato - ----@-------.com.br */
function ValidarEnvioPagina()
{
    if(document.getElementById('txtRemetente').value.isEmpty())
   {
        alert('Por Favor, informe seu nome!');
        document.getElementById('txtRemetente').focus();
        return false;
   }
   if(document.getElementById('txtEmailRemetente').value.isEmpty())
   {
        alert('Por Favor, informe seu e-mai!l');
        document.getElementById('txtEmailRemetente').focus();
        return false;
   }
   else
   {
       if(!document.getElementById('txtEmailRemetente').value.isValidEmail())
       {
            alert('E-mail invalido!');
            document.getElementById('txtEmailRemetente').focus();
            return false;
       }
   }
   if(document.getElementById('txtDestinatario1').value.isEmpty())
   {
        alert('Por Favor, insira o nome do destinatario!');
        document.getElementById('txtDestinatario1').focus();
        return false;
   }
   if(document.getElementById('txtEmailDestinatario1').value.isEmpty())
   {
        alert('Por Favor, insira o e-mail do destinatario!');
        document.getElementById('txtEmailDestinatario1').focus();
        return false;
   }
   else
   {
       if(!document.getElementById('txtEmailDestinatario1').value.isValidEmail())
       {
            alert('E-mail invalido!');
            document.getElementById('txtEmailDestinatario1').focus();
            return false;
       }
   }
    if(document.getElementById('txtComentario').value.isEmpty())
    {
        alert('Por favor, insira o seu comentario!');
        document.getElementById('txtComentario').focus();
        return false;
    }
   if(!document.getElementById('txtDestinatario2').value.isEmpty())
   {
        if(document.getElementById('txtDestinatario2').value.isEmpty())
        {
             alert('Por favor, insira o nome do destinatario!');
             document.getElementById('txtDestinatario2').focus();
             return false;
        }
        if(document.getElementById('txtEmailDestinatario2').value.isEmpty())
        {
            alert('Por favor, insira o e-mail do destinatario!');
            document.getElementById('txtEmailDestinatario2').focus();
            return false;
        }
   }
   if(!document.getElementById('txtEmailDestinatario2').value.isEmpty())
   {
        if(!document.getElementById('txtEmailDestinatario2').value.isValidEmail())
        {
             alert('E-mail invalido!');
             document.getElementById('txtEmailDestinatario2').focus();
             return false;
        }
        if(document.getElementById('txtDestinatario2').value.isEmpty())
        {
            alert('Por favor, insira o nome do destinatario!');
            document.getElementById('txtDestinatario2').focus();
            return false;
        }
   }
   if(!document.getElementById('txtDestinatario3').value.isEmpty())
   {
        if(document.getElementById('txtDestinatario3').value.isEmpty())
        {
             alert('Por favor, insira o nome do destinatario!');
             document.getElementById('txtDestinatario3').focus();
             return false;
        }
        if(document.getElementById('txtEmailDestinatario3').value.isEmpty())
        {
            alert('Por favor, insira o e-mail do destinatario!');
            document.getElementById('txtEmailDestinatario3').focus();
            return false;
        }
   }
   if(!document.getElementById('txtEmailDestinatario3').value.isEmpty())
   {
        if(!document.getElementById('txtEmailDestinatario3').value.isValidEmail())
        {
             alert('E-mail invalido!');
             document.getElementById('txtEmailDestinatario3').focus();
             return false;
        }
        if(document.getElementById('txtDestinatario3').value.isEmpty())
        {
            alert('Por favor, insira o nome do destinatario!');
            document.getElementById('txtDestinatario3').focus();
            return false;
        }
   }
}

function FecharEmail(){
    alert("E-mail enviado com sucesso!");
    window.close();
}

function FormularioComoComprar(){
    alert("Formulário enviado com sucesso!");
    window.close();
}

/* Criado por Leonard Hofmann - criado em 31*01*2008 - contato - leonard.hofmann@focusnetworks.com.br
   Modificado por ----------- - modificado em --*--*---- - contato - ----@-------.com.br */
// para não validar campos que podem ser nulos, tem que adicionar a classe 'vazio' para o textboxs ou inputs do tipo text e select;
function ValidarCampoVazio(){
    var oListInput = document.getElementsByTagName("input");
    var oListSelect = document.getElementsByTagName("select");
    
    for(var i=0; i<oListInput.length; i++){            
        if(!oListInput[i].className.match("vazio")){
            if (oListInput[i].type == 'text'){   
                if(oListInput[i].value.isEmpty()){
                    if (oListInput[i].getAttribute('id') == 'txtNome')
                        alert("O campo Nome é obrigatório!");
                    if (oListInput[i].getAttribute('id') == 'txtEmail')
                        alert("O campo E-mail é obrigatório!");
                    if (oListInput[i].getAttribute('id') == 'txtCNPJ')
                        alert("O campo CNPJ é obrigatório!");
                    if (oListInput[i].getAttribute('id') == 'txtNomeFantasia')
                        alert("O campo Nome Fantasia é obrigatório!");
                    if (oListInput[i].getAttribute('id') == 'txtTelefones')
                        alert("O campo Telefone é obrigatório!");
                    oListInput[i].focus();
                    return false;
                }
            }
        }
    }
    for(var i=0; i<oListSelect.length; i++){            
        if(!oListSelect[i].className.match("vazio")){
            if(oListSelect[i].value == 0){
                if (oListSelect[i].getAttribute('id') == 'ddlConheceuUnitelco')
                    alert("A seleção Como conheceu a Unitelco? é obrigatória!");
                oListSelect[i].value = 1;
                return false;
            }
        }
    }
    if(!document.getElementById('txtEmail').value.isValidEmail())
       {
            alert('E-mail invalido!');
            document.getElementById('txtEmail').focus();
            return false;
       }
}

function PopupLogin(string){
    if(string == "true"){
        $$('.float_cortina').removeClass('display_none');
        $('html_master').setStyle('overflow', 'hidden');
        $$('.login').removeClass('display_none');
    }else{
        $$('.float_cortina').addClass('display_none');
        $('html_master').setStyle('overflow', 'auto');
        $$('.login').addClass('display_none');
    }
}

function PopupMascote(string){
    if(string == "true"){
        $$('.float_cortina').removeClass('display_none');
        $('html_master').setStyle('overflow', 'hidden');
        $$('.mascote').removeClass('display_none');
    }else{
        $$('.float_cortina').addClass('display_none');
        $('html_master').setStyle('overflow', 'auto');
        $$('.mascote').addClass('display_none');
    }
}

function PopupNoticia(string){
    if(string == "true"){
        $$('.float_cortina').removeClass('display_none');
        $('html_master').setStyle('overflow', 'hidden');
        $$('.noticia').removeClass('display_none');
    }else{
        $$('.float_cortina').addClass('display_none');
        $('html_master').setStyle('overflow', 'auto');
        $$('.noticia').addClass('display_none');
    }
}

//--------------------------------------------------------------------//
// fctPopTira()                                                    //
// Pop up na página                                                 //
// Criado por: Victor Leonardo Data: 27/03/2008  //
// Modificado por:             Em:              //
//----------------------------------------------------------------//

function fctPopTira(url){

  var img = $$('.img_tira');
  var wpagina = window.getWidth();
  var hpagina = window.getScrollHeight();
  var pop = new Drag.Move('pop_tirinha', {handle: $('top_tirinha')});

  $$('.cortina').setStyles({
      "width": wpagina,
      "height": getPageSize().pageHeight
  });
  $$('.cortina').setOpacity(0.6);
  
  img.setProperty('src', url);

  $$('.pop_tira').setStyle('display', 'block');
  $$('.cortina').setStyle('display', 'block');

  $$('.btn_fechar_tira').addEvent("click", function(){
    $$('.pop_tira').setStyle('display', 'none');
    img.setProperty('src', "#");
    $$('.cortina').setStyle('display', 'none');
  });
}

/* Get Page Size */

function getPageSize(){
    var xScroll, yScroll;

    if(window.innerHeight && window.scrollMaxY){
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }else if(document.body.scrollHeight > document.body.offsetHeight){
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    }else{
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if(self.innerHeight){
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    }else if(document.documentElement && document.documentElement.clientHeight){
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    }else if(document.body){
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }	

    if(yScroll < windowHeight)
        pageHeight = windowHeight;
    else
        pageHeight = yScroll;

    if(xScroll < windowWidth)
        pageWidth = windowWidth;
    else
        pageWidth = xScroll;

    arrayPageSize = {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight};

    return arrayPageSize;
}

function fctCamera(camera){
    var div_cam_html = '<OBJECT ID="Video1" WIDTH="422" HEIGHT="366" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,0701" ';
    div_cam_html += 'CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject">';
    div_cam_html += '<PARAM NAME="FileName" VALUE="'+ camera +'">';
    div_cam_html += '<PARAM NAME="ShowStatusBar" VALUE="true">';
    div_cam_html += '<PARAM NAME="ShowControls" VALUE="1">';
    div_cam_html += '<PARAM NAME="ShowDisplay" VALUE="0">';
    div_cam_html += '<PARAM NAME="AnimationAtStart" VALUE="0">';
    div_cam_html += '<PARAM NAME="TransparentAtStart" VALUE="0">';
    div_cam_html += '<PARAM NAME="AutoStart" VALUE="1">';
    div_cam_html += '<PARAM NAME="AllowChangeDisplaySize" VALUE="0">';
    div_cam_html += '<EMBED TYPE="application/x-mplayer2" PLUGINSPAGE="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" ';
    div_cam_html += 'SRC="'+ camera +'" NAME="Video1" WIDTH="422" HEIGHT="366" ShowControls="1" ';
    div_cam_html += 'ShowDisplay="0" ShowStatusBar="true" AnimationAtStart="1" TransparentAtStart="0" ';
    div_cam_html += 'AutoStart="1" AllowChangeDisplaySize="0"></EMBED></OBJECT>';
	$('div_cam').innerHTML = div_cam_html;
	/*
	if (navigator.userAgent.indexOf("MSIE") >= 0) {    } else {    }
	*/
}

//--------------------------------------------------------------------//
//                        window.addEvent()                           //
//--------------------------------------------------------------------//
window.addEvent('domready', function(){
    if($('div_cam') != undefined)
		fctCamera('mms://200.143.138.124:1397/');
});

/* Login */

function LogOff()
{
    var url = "/handler/Login.ashx";
    var myAjax = new Ajax(url, 
        {
            method: 'get',
            data: { 'type' : 'logoff' },      
            onComplete: function(response)
                {                    
                    location.reload(true);
                }
        }).request();
}

function ValidarLogin()
{
    $('lblErro').addClass('display_none');

    if(document.getElementById('txtLogin').value.isEmpty())
    {
        alert('Por favor, insira o login!');
        document.getElementById('txtLogin').focus();
        return false;
    }
    
    if(document.getElementById('txtSenha').value.isEmpty())
    {
        alert('Por favor, insira a senha!');
        document.getElementById('txtSenha').focus();
        return false;
    }
    
    var url = "/handler/Login.ashx";
    var myAjax = new Ajax(url, 
        {
            method: 'get',      
            data: { 'type' : 'login', 'login' : document.getElementById('txtLogin').value, 'senha' : document.getElementById('txtSenha').value },      
            onComplete: function(response)
                {
                    if(response == "OK")
                    {
                        location.reload(true);
                    }
                    else
                    {
                        $('lblErro').innerHTML = 'Login/Senha Incorreta';
                        $('lblErro').removeClass('display_none');
                    }
                },
            onFailure: function()
                {
                    $('lblErro').innerHTML = 'Erro ao conectar';
                    $('lblErro').removeClass('display_none');
                }
        }).request();
    
}

/* fim Login */

/* Busca */

fctVerifica_OnBlur = function(obj, text)
{    
    if(obj.value == "")
        obj.value = text;
}

fctVerifica_OnFocus = function(obj, text)
{
    if(obj.value == text)
        obj.value = "";
}

buscarNoticia = function()
{
    var txtBusca = document.getElementById('txtBuscaNoticia').value;
    var txtData = document.getElementById('txtBuscaNoticiaData').value;
    var txtDataFim = document.getElementById('txtBuscaNoticiaDataFinal').value;
    
    if(txtBusca == 'Texto para busca')
        txtBusca = '';
        
    if(txtData == 'dd/mm/aaaa')
        txtData = '';
        
    if(txtDataFim == 'dd/mm/aaaa')
        txtDataFim = '';
        
    window.location = 'Noticias.aspx?v=0&texto=' + txtBusca + '&data=' + txtData + '&datafim=' + txtDataFim;
}

/* Fim Busca */

/* Noticia */

function RemoverNoticia(id)
{
    if(confirm('Tem certeza que deseja excluir esta notícia?'))
	{
        var url = "/handler/Login.ashx";
        var myAjax = new Ajax(url, 
        {
            method: 'get',      
            data: { 'type' : 'removernoticia', 'id' : id },
            onComplete: function(response)
                {
                    location.reload(true);                
                },
            onFailure: function()
                {
                    alert('Erro ao conectar');
                }
        }).request();
    }  
}

function EditarNoticia(id)
{
    document.getElementById('hidNoticiaId').value = id;
    
    var url = "/handler/Login.ashx";
    var myAjax = new Ajax(url, 
    {
        method: 'get',      
        data: { 'type' : 'noticia', 'id' : id },
        onComplete: function(response)
            {
                if(response != "ERRO")
                {                
                    var vetRetorno = response.split('{{0}}');
                    document.getElementById('txtNoticiaTitulo').value = vetRetorno[0];
                    document.getElementById('cboNoticiaTipo').value = vetRetorno[1];
                    document.getElementById('txtNoticiaDescricao').value = vetRetorno[2];                    
                    tinyMCE.get('txtNoticiaIntegra').setContent(vetRetorno[3]);                  
                    document.getElementById('hidImagemAtual').value = vetRetorno[4];
                    document.getElementById('divFileProgressContainer').innerHTML = '';
                    document.getElementById('thumbnails').innerHTML = '';
                    PopupNoticia('true');
                }
                else
                {
                    alert('Erro ao conectar');
                }
                
            },
        onFailure: function()
            {
                alert('Erro ao conectar');
            }
    }).request();    
}

function NovaNoticia()
{    
    document.getElementById('hidNoticiaId').value = '';
    document.getElementById('txtNoticiaTitulo').value = '';
    document.getElementById('cboNoticiaTipo').value = '';
    document.getElementById('txtNoticiaDescricao').value = '';
    document.getElementById('divFileProgressContainer').innerHTML = '';
    document.getElementById('thumbnails').innerHTML = '';
    tinyMCE.get('txtNoticiaIntegra').setContent('');    
    document.getElementById('hidImagemAtual').value = '';
    PopupNoticia('true');
}

function EnviarNoticia()
{
    var NoticiaId = document.getElementById('hidNoticiaId').value;
    var NoticiaTitulo = document.getElementById('txtNoticiaTitulo').value;
    var NoticiaTipo = document.getElementById('cboNoticiaTipo').value;
    var NoticiaDescricao = document.getElementById('txtNoticiaDescricao').value;
    var NoticiaIntegra = tinyMCE.get('txtNoticiaIntegra').getContent();
    var NoticiaImagem = document.getElementById('thumbnails').innerHTML;
    var NoticiaImagemAtual = document.getElementById('hidImagemAtual').value;    
    
    $('lblNoticiaErro').addClass('display_none');
    
    if(NoticiaTitulo.isEmpty())
    {                
        document.getElementById('txtNoticiaTitulo').focus();
        $('lblNoticiaErro').innerHTML = 'Por favor, preencha o campo Título.';
        $('lblNoticiaErro').removeClass('display_none');
        return false;
    }
    if(NoticiaTipo.isEmpty())
    {        
        document.getElementById('cboNoticiaTipo').focus();
        $('lblNoticiaErro').innerHTML = 'Por favor, preencha o campo Tipo.';
        $('lblNoticiaErro').removeClass('display_none');
        return false;
    }    
    if(NoticiaDescricao.isEmpty())
    {        
        document.getElementById('txtNoticiaDescricao').focus();
        $('lblNoticiaErro').innerHTML = 'Por favor, preencha o campo Descrição Resumida.';
        $('lblNoticiaErro').removeClass('display_none');
        return false;
    }    
    if(NoticiaIntegra.isEmpty())
    {        
        document.getElementById('txtNoticiaIntegra').focus();
        $('lblNoticiaErro').innerHTML = 'Por favor, preencha o campo Integra.';
        $('lblNoticiaErro').removeClass('display_none');
        return false;
    }
    
    var novaImagem = !NoticiaImagem.isEmpty();
            
    var url = "/handler/Login.ashx";
    var myAjax = new Ajax(url, 
    {
        method: 'post',
        data: { 'type' : 'savenoticia', 'id' : NoticiaId, 'Titulo' : NoticiaTitulo, 'Tipo' : NoticiaTipo, 'Descricao' : NoticiaDescricao, 'Integra' : NoticiaIntegra, 'NovaImagem' : novaImagem },
        onComplete: function(response)
            {
                if(response == "OK")
                {                
                    location.reload(true);
                }
                else
                {
                    $('lblNoticiaErro').innerHTML = 'Erro ao conectar.';
                    $('lblNoticiaErro').removeClass('display_none');
                }
                
            },
        onFailure: function()
            {
                $('lblNoticiaErro').innerHTML = 'Erro ao conectar.';
                $('lblNoticiaErro').removeClass('display_none');
            }
    }).request(); 

    
}

/* Fim Noticia */
