
$(document).ready(function(){
    // Validacion generica de formularios
    $('.envFormulario').live('click',function(event){
        $('#mensajeErrorFormulario').remove();
           if($('.formulario').valid()==false){
              $('.formulario').prepend('<div id="mensajeErrorFormulario" class="bloque_error_fatal"><div id="load">Los elementos con (*), son obligatorios.</div></div>');
              $('#mensajeErrorFormulario').show(300);
              setTimeout('removerAvisoErrorFormulario()',1000);
              return false;
            }else{
              return true;
            }
    });
   $('.cancelDialiog').live('click',function(){
        $('.dialogBox').remove();
        $('.dialogBox').dialog('destroy');
   });
   $('.showLoad').live('click',function(){
        $('#content_load').show();
   });
    $(".tab_content").hide();
    $("ul.tabs li:first").addClass("active").show();
    $(".tab_content:first").show();

    $("ul.tabs li").click(function()
       {
        $("ul.tabs li").removeClass("active");
        $(this).addClass("active");
        $(".tab_content").hide();

        var activeTab = $(this).find("a").attr("href");
        $(activeTab).show();
        return false;
    });
   // Validacion de navegador.
   if ($.browser.msie && $.browser.version <= 6 ){
        var html='<div class="ui-widget"><div class="ui-state-error ui-corner-all" style="padding: 2em;"><p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span> <strong>Tu navegador no es más compatible. </strong> Actualiza tu navegador. </p><br /><br /> <p class="browser-links"><a href="http://www.microsoft.com/spain/windows/internet-explorer/"><img src="imagenes/ie.gif"></a> <a href="http://www.apple.com/safari/" ><img src="imagenes/safari.gif" ></a><a href="http://www.mozilla.com/"><img src="imagenes/ff.gif"></a><a href="http://www.google.com/chrome/index.html" class="browser-link"> <img src="imagenes/chrome.gif" > </a><a href="http://www.opera.com/browser/"> <img src="imagenes/opera.gif" ></a></p></div></div>';
        $("#wrapper").prepend(html);
   }
   $('.botonHideShow').live('click',function(){
            $(this).parent().parent().find('.contentHideShow').toggle();
            $(this).find('img').toggle();
    });
});

function removerAvisoErrorFormulario(){
    $('#mensajeErrorFormulario').hide();
}
function mostrarContacto(){
$('#contacto_hide').show('slow');
}
function ocultarContacto(){
$('#contacto_hide').hide('slow');
}
function hideLoad(){
    $('#content_load').hide();
}
/* validaciones por tecla*/
// Permite letras y letras con acento y numeros
function letrasNum(e) {
    var tecla = (document.all) ? e.keyCode : e.which;if (tecla==8) return true;
    var patron =/^[A-Za-z0-9ñÑáéíóú$\s]/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}
// Permite letras con acento, numeros y guiones
function letrasNumGuion(e) {
    var tecla = (document.all) ? e.keyCode : e.which;if (tecla==8) return true;
    var patron =/^[-A-Za-z0-9ñÑáéíóú$\s]/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}
//Permite solo numeros
function num(e){
    var tecla = (document.all) ? e.keyCode : e.which;if (tecla==8) return true;
    var patron =/^[\A0-9$\s]/;te = String.fromCharCode(tecla);
    return patron.test(te);}
/* Funciones Utiles */
// Imprime un elemento por el ID
function imprSelec(nombre)
{
  var ficha = document.getElementById(nombre);
  var ventimp = window.open(' ', 'popimpr');
  ventimp.document.write( ficha.innerHTML );
  ventimp.document.close();
  ventimp.print( );
  ventimp.close();
}
// elimina espacios
function trim(str) { 
    return str.replace(/^\s+|\s+$/g, "");
}
 function abrirVentana(Pagina,Destino)
 {
  var popup;
  popup = open(Pagina,Destino,"width=700,height=800,scrollbars=yes,toolbar=no,directories=no,menubar=no,status=no,titlebar=no,location=no");
 }
function agregarDialog(data,titulo,ancho){
    $('#content').append('<div id="box" title="'+titulo+'" class="dialogBox"></div>');
    $('#box').dialog({
        autoOpen:false,modal:true,width:ancho,
        close:function(){
            $('#box').dialog('destroy');$('#box').remove();
        },closeOnEscape: false       
    });
     $('#box').html(data);
     $('#box').dialog('open');
}
function removeBox(){
    $('.dialogBox').dialog('destroy');
    $('.dialogBox').remove();
}

