function textoMaximo(campo,valor,faltan) {
    var campo_texto=document.getElementById(campo);
    var quedan=document.getElementById(faltan);
    valor_limit=valor-1;
    if (campo_texto.value.length > valor) {
        alert('M�ximo '+valor+' caracteres');
        campo_texto.value = campo_texto.value.substring(0,valor_limit);
    }
    quedan.innerHTML=160-campo_texto.value.length;
} 





function confirmarEnvioForm(mensaje,nombre_formulario) {
    if ( confirm(mensaje) ) {
        var formulario=document.getElementById(nombre_formulario);
        formulario.submit();
    }
    else {
        return false;
    }
}


function setInputValue(campo,valor) {
    var input=document.getElementById(campo);
    if (input) {
        input.value=valor;
    }
    else {
        return false;
    }
}


function irA(destino) {
    if (destino!='') {
        self.location =destino;
    }
}



function mostrarCapa(id) {
    document.getElementById(id).style.display = '';
}

function ocultarCapa(id) {
    document.getElementById(id).style.display = 'none';
}

function mostrarOcultarCapa(id) {
    if (document.getElementById(id).style.display == '')
        document.getElementById(id).style.display = 'none'
    else
        document.getElementById(id).style.display = '';
}


function confirma(mensaje,destino) {
    if ( confirm(mensaje) ) {
        self.location =destino;
    }
}

function borrarInput(id)	{
    document.getElementById(id).value='';
}



/*
	Funcion que borra el elemento seleccionado de un select
	Argumento[0] Select 
*/
function borrarDeSelect(selectDe) {
    if (document.getElementById(selectDe).selectedIndex!=-1) {
        document.getElementById(selectDe).options[document.getElementById(selectDe).selectedIndex]=null;
    }
}

/****
	Muestra o oculta un span o div con ID.
	Solo para IE. Respeta el texto. Tablas completas.
*****/


function cambiafondo(obj) 
{ 
    obj.bgColor = '#DC9102';
} 
function restaurafondo(obj, color) 
{ 
    obj.bgColor = '';
} 



function hideAll() {
    hideData('submenu01');
    hideData('submenu02');
    hideData('submenu03');
    hideData('submenu04');
    hideData('submenu05');
    hideData('submenu06');
	
    cambiarFondo('pestana01','#425E14');
    cambiarColorFuente('link_pestana01','#FFFFFF');

    cambiarFondo('pestana02','#425E14');
    cambiarColorFuente('link_pestana02','#FFFFFF');

    cambiarFondo('pestana03','#425E14');
    cambiarColorFuente('link_pestana03','#FFFFFF');

    cambiarFondo('pestana04','#425E14');
    cambiarColorFuente('link_pestana04','#FFFFFF');

    cambiarFondo('pestana05','#425E14');
    cambiarColorFuente('link_pestana05','#FFFFFF');

    cambiarFondo('pestana06','#425E14');
    cambiarColorFuente('link_pestana06','#FFFFFF');
}



/*
muestras el texto en las capas ocultas
*/
	
function cambiarFondo(nombreCapa,color)
{	
    document.getElementById(nombreCapa).style.background=color;
}

function cambiarColorFuente(nombreCapa,color)
{
    document.getElementById(nombreCapa).style.color=color;
    document.getElementById(nombreCapa).style.textDecoration='underline';
}	

function subrayar(nombreCapa)
{
    document.getElementById(nombreCapa).style.textDecoration='underline';
}			


function mostrar(nombreCapa)
{
    document.getElementById(nombreCapa).style.visibility="visible";
}
function ocultar(nombreCapa)
{
    document.getElementById(nombreCapa).style.visibility="hidden";
}
		
function showHideData(id) {
    if (document.getElementById(id).style.display == '')
        document.getElementById(id).style.display = 'none'
    else
        document.getElementById(id).style.display = '';
}

function showData(id) {
    document.getElementById(id).style.display = '';
}

function hideData(id) {
    document.getElementById(id).style.display = 'none';
}


function openWinClean(fichero,nombre,tam) {
    ventana=window.open(fichero,nombre,tam+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes");
    return ventana;
}
function openWinScroll(fichero,nombre,tam) {
    ventana=window.open(fichero,nombre,tam+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars,resizable=no,copyhistory=yes");
    return ventana;
}

function openWin(fichero,nombre,tam) {
    ventana=window.open(fichero,nombre,tam+",toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes");
    return ventana;
}


function esVacio(campo)
{
    return ((campo == null) || (campo.length == 0))
}

//Campo vacio o lleno de espacios
function esBlanco(campo)
{
    var cadena = new String(campo.value);
    if(esVacio(campo))
        return true;
    else
        for (var i=0;i<cadena.length;i++)
            if (cadena.charAt(i)!=" ") return false;
    return true;
}


function cargaGaleria() { 
    if(document.getElementById("galeriaID").value==0) {
        window.location.href = "index.php?s=galeria&id=1";
    } else {
        window.location.href = "index.php?s=galeria&id="+document.getElementById("galeriaID").value;
    }
} 




function muestra_menu(id) {

    if (document.getElementById) {
        menu = document.getElementById(id);
        menu.className="on";
    }

}

// Selecciona/deselecciona los checkbox del formulario formCheckboxesName+prefijo' dependiendo del checkbox clickCheckboxId
function selectAllCB(id){
    $("input[class='cb_categoria_" + id + "'][type='checkbox']").each(function(){
        $(this).attr('checked', $('#cb_general_' + id).is(':checked'));
    });
/*$("input[name='" + formCheckboxesName + "'][type='checkbox']").each(function(){
       var array_id = $(this).parent().parent().attr('id').split("_");
       var elementoId = array_id[array_id.length - 1];
       $(this).attr('checked', $('#' + clickCheckboxId).is(':checked'));
       marcarFila(elementoId, prefijo);
    });*/
}
function deselectAllCB(id, referencia){
    if(!referencia.is(':checked')){
        $('#cb_general_' + id).attr('checked', referencia.is(':checked'));
    }
}
$(document).ready(function(){
    externalLinks();

    // menu
    $("#menu").superfish();
    $(".otrosPaises").superfish({
        delay: 100
    });
    //externalLinks();

    //tabs
    $(".cabeceras").tabs("div.paneles > div",{
        tabs: "li",
        effect: "fade",
        fadeInSpeed: 800
    });

    //galerias
    $(".galeria a").fancybox({
        'SpeedIn': 0,
        'SpeedOut': 0,
        'overlayShow': true,
        'titlePosition' : 'inside'
    });
    $(".ampliar").fancybox({
        'SpeedIn': 0,
        'SpeedOut': 0,
        'overlayShow': true,
        'titlePosition' : 'inside'
    });

    //ventana modal
    if( $("a.modal").length > 0){

        $("a.modal").fancybox({
            'hideOnContentClick': false,
            'scrolling': 'no',
            'SpeedIn': 0,
            'SpeedOut': 0,
            'overlayShow': true,
            'titlePosition' : 'inside',
            onClosed : function() {
                    $("#fancy_content").empty();
                }
        });
    }

    $("a.modalpaises").fancybox({
        'hideOnContentClick': false,
        'frameWidth': 300,
        'frameHeight': 150,
        'SpeedIn': 0,
        'SpeedOut': 0,
        'overlayShow': true

    });
    $("a.modalcomprar").fancybox({
        'width': 400,
        'height': 330,
        'scrolling': 'no',
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'overlayShow': true,
        'titlePosition' : 'inside',
        'type': 'iframe',
        onClosed : function() {
                $("#fancy_content").empty();
            }
    });

    $('input[type="text"]').focus(function(){
        $(this).addClass('inputDestacado');
    //$(this).val('');
    });
    $('input[type="text"]').blur(function(){
        $(this).removeClass('inputDestacado');
    /*if($(this).val() == ""){
                $(this).val('por nombre...');
            }*/
    });
    $('#boton_buscador_menu').click(function(){
        if($('#cadena').val() == 'por título...'){
            $('#cadena').val('');
        }
        $('·buscador_menu').submit();
    });
    $('#cadena').blur(function(){
        if($(this).val() == ""){
            $(this).val('por título...');
        }
    });
    $('#cadena').focus(function(){
        $(this).val('');
    });
    /*
    $('#paises_pie').change(function() {
      var valor = $(this).val();
      if(valor != 0){
          document.location.href = valor;
      }
    });
*/

    //inicializamos la ventana modal
    $('#dialog').dialog({
        resizable: false,
        height:50,
        modal: true,
        autoOpen: false,
        addClass: 'midialogo',
        draggable: false
    });

    // funcion que muestra la ventanta
    function showDialog(event)  {
        var url = $(event.target).attr('value');
        if(url != 0){
            $('#dialog').dialog('option', 'buttons' ,{
                'No': function() {
                    document.location.href = url
                },
                'Si': function() {
                    $.cookie('sg', url, {
                        path: '/',
                        expires: 30
                    });
                    document.location.href = url;
                }
            });
            $('#dialog').dialog('open');
            return false;
        }

    }
    // inicializamos manejadores a los enlaces
    $("#paises_pie").change(showDialog);



//video
//$(".reproductor a").flowplayer("{/literal}{$assets_dir}{literal}swf/flowplayer.swf");


});