var oldObj;
var fixObj;
var clickImagem;
function ZoomFoto() {
    if (clickImagem) {
        openNewWindow("img/"+clickImagem+"g.jpg", 460,410,'yes','yes', 'wzoom');
    }
    return false;
}

function MenuLocal(obj, acao, imagem) {
    if (acao == 'out') {
        if (fixObj) {
            if (imagem == fixObj) {
                obj.className='cl2Fix';
                return false;
            }
        }
        obj.className='cl2';
    } else if (acao == 'over') {
        obj.className='cl2Ovr';
    } else if (acao == 'click') {
        if (oldObj) {
            oldObj.className='cl2';
        }
        fixObj = imagem;
        obj.className='cl2Fix';
        oldObj = obj;
        var objImg = ODOM_getMyObj("dFotoImg");
        objImg.src = "img/"+imagem+".jpg";
        clickImagem = imagem;
    }
    return false;
}

$(document).ready( function() {
    $('#nav a').tooltip({
        showURL: false,
        positionLeft: true
    });
    
    $('#menu_profissional a#sair').tooltip({
        showURL: false,
        positionLeft: true
    });
    
    $('#frm_login_pro a').tooltip({
        showURL: false,
        positionLeft: true
    });
    
    $('a.external').click(function(){
        window.open($(this).attr('href'));
        return false;
    });
    $("#iFax").mask("(99)9999-9999");
    $("#iTelefone").mask("(99)9999-9999");
    $("#iCep").mask("99999-999");
    $("#iNascimento").mask("99/99/9999");
    $("#iUf").mask("aa");
    
    featuredcontentglider.init({
        gliderid: "canadaprovinces", //ID of main glider container
        contentclass: "glidecontent", //Shared CSS class name of each glider content
        togglerid: "p-select", //ID of toggler container
        remotecontent: "", //Get gliding contents from external file on server? "filename" or "" to disable
        selected: 0, //Default selected content index (0=1st)
        persiststate: false, //Remember last content shown within browser session (true/false)?
        speed: 500, //Glide animation duration (in milliseconds)
        direction: "rightleft", //set direction of glide: "updown", "downup", "leftright", or "rightleft"
        autorotate: false /*, //Auto rotate contents (true/false)?
        autorotateconfig: [100, 2] //if auto rotate enabled, set [milliseconds_btw_rotations, cycles_before_stopping]
        */
    })
    
    $('a.descricao_produto').click(function() {
        
        $('#produto_descricao').html('');
        
        $.post( "/produtos/produto.php", {
            iID: $(this).attr('rel')
        }, function( response ) {
            $('#produto_descricao').html(response)    
        });
        
        
        
        $.blockUI({
                    message: $('#produto_descricao'),
                    css: {
                        width: '490px',
                        height: '420px',
                        top:  ($(window).height() - 490) /2 + 'px', 
                        left: ($(window).width() - 420) /2 + 'px'
                    },
                    overlayCSS:  {
                        cursor: 'auto'
                    }
                  });
                  
                  $('.blockOverlay').click(function() {
                      $.unblockUI({ onUnblock: function(){ $('#produto_descricao').hide(); } });
                  });
                  
        return false;
        
    });
    
    
    $('.select_adm').change( function() {
          switch( $('#iAcao_' + $(this).attr('rel') ).val() ) {
            case 'res':
                window.location = '/profissional/adm/reserva/index.php?iID=' + $(this).attr('rel');
            break;
            case 'lib':
                if ( confirm('Tem certeza que deseja ATIVAR este usuário?') ) 
                    window.location = 'manu.php?modo=lib&iID=' + $(this).attr('rel');
            break;
            case 'nlib':
                if ( confirm('Tem certeza que deseja DESATIVAR este usuário?') ) 
                    window.location = 'manu.php?modo=nlib&iID=' + $(this).attr('rel');
            break;
            case 'exc':
                if ( confirm('Tem certeza que deseja Excluir este registro?') ) 
                    window.location = 'manu.php?modo=exc&iID=' + $(this).attr('rel');
            break;
            default:
            break;
          } 
    } );
    
    $('.select_reserva_adm').change( function() {
            
          switch( $('#iAcao_' + $(this).attr('rel') ).val() ) {
            case 'res':
                window.location = '/profissional/adm/reserva/index.php?iID=' + $(this).attr('rel') + '&iIDUser=' + $('#iID').val();
            break;
            case 'alt':
                    window.location = 'formulario.php?modo=alt&iID=' + $(this).attr('rel') + '&iIDUser=' + $('#iID').val();
            break;
            case 'exc':
                if ( confirm('Tem certeza que deseja Excluir este registro?') ) 
                    window.location = 'manu.php?modo=exc&iID=' + $(this).attr('rel') + '&iIDUser=' + $('#iID').val();
            break;
            default:
            break;
          } 
    } );
    
    $('#iDC').change( function() {
            if ( $(this).val() == 'C' ) {
                $('#iValorRetirada').hide();
                $('#iReserva').show();
            } else if ( $(this).val() == 'D' ) {
                $('#iReserva').hide();
                $('#iValorRetirada').show();
            }
    });
    
    $('#imprimir_reserva').click( function() {
            $('#imprimir').printArea();
            return false;
    });
    
    
    $('.input_data').mask("99/99/9999");
    
     function findValue(li) {
if( li == null ) return alert("No match!");

// if coming from an AJAX call, let's use the CityId as the value
if( !!li.extra ) var sValue = li.extra[0];

// otherwise, let's just display the value in the text box
else var sValue = li.selectValue;

//alert("The value you selected was: " + sValue);
}

function selectItem(li) {
findValue(li);
}

/*
function formatItem(row) {
return row[0] + " (id: " + row[1] + ")";
}
*/

function lookupAjax(){
var oSuggest = $(".autocomplete")[0].autocompleter;
oSuggest.findValue();
return false;
}

function lookupLocal(){
var oSuggest = $(".autocomplete")[0].autocompleter;

oSuggest.findValue();

return false;
}


$(".autocomplete").autocomplete(
                        "/autocomplete.php",
                        {
                            delay:5,
                            minChars:2,
                            matchSubset:1,
                            matchContains:1,
                            cacheLength:10,
                            onItemSelect:selectItem,
                            onFindValue:findValue,
                            //formatItem:formatItem,
                            autoFill:false
                        }
);

    
    
});

function listaProfissionais() {
    window.open('/profissional/profissionais.php', '', 'height=480, width=840, top=20, left=20, scrollbars=yes, resizable=no');
}

function Abrir(){
    window.open("/profissional/galeria_profissionais.php","Visualizando","status = 0, width = 537, height = 595, left = 20, top = 30, resizable = 0, toolbar = 0");
    return false;
}

function Confere(){
    var numero = document.frmFoto.iFoto.value;
    if(numero == '1') 
        document.frmFoto.iMenos.style.display = "none";
    else 
        document.frmFoto.iMenos.style.display = "block";
    if(numero == '30') 
        document.frmFoto.iMais.style.display = "none";
}

function trocaImg(equacao){
     if(equacao == 'menos')
         document.frmFoto.iFoto.value-- ;
     else if(equacao  == 'mais')
         document.frmFoto.iFoto.value++ ;
     else return false;
     var iNumero =  document.frmFoto.iFoto.value;
     if(iNumero < 10)
         document.modeloaimg.src = "/profissional/galeria/fotos_0"+iNumero+".jpg";
     else
         document.modeloaimg.src = "/profissional/galeria/fotos_"+iNumero+".jpg";
     
     if(iNumero != '1' && iNumero != '33'){
         document.frmFoto.iMenos.style.display = "block";
         document.frmFoto.iMais.style.display = "block";
     }
     else{
         if(iNumero == '1')
             document.frmFoto.iMenos.style.display = "none";
         else if(iNumero == '33')
             document.frmFoto.iMais.style.display = "none";
     }        
}
