$(function(){   
   $.fn.leeren = function()
   {
       var old = $(this).val();

       $(this).val("");

       $(this).blur(function(){
           if($(this).val() == "")
           {
               $(this).val(old);
           }
       });
   }
   
   $('#livesearch').click(function(){
       $(this).leeren()
   });
   
   $('#livesearch').keyup(
    function (e)
 {
     e.preventDefault();
     
     if($(this).val().length >= 1)
     {
         $.ajax(
            {
                type:"POST",
                url:"/ajax/livesearch.php",
                data:'search='+$(this).val(),
                success: function(data)
                {
                    $('#livesearch_result').html(data).show();
                }
            }
        )
     }
 }
);
    
    $('#livesearch').blur(
        function()
        {
            $('#livesearch_result').delay(500).hide(100);
        }     
    );

   //Nachrichten Kästen Ajax
   $(".news_typ").find('a').click
    (
        function(e)
        {
            e.preventDefault();
            
            if(typeof ET_Event !== 'undefined')
                ET_Event.eventStart($(this).parent().parent().parent().parent().parent().find('h3').text(),$(this).text(),'Klick');
            
            $(this).parent().parent().find('td').removeClass('active');
            var integer = $(this).parent().parent().parent().parent().attr('id').replace(/\D+/,'');
            $(this).parent().addClass('active');
            $.ajax(
                {
                    type:"POST",
                    url:"/ajax/nachrichten.php",
                    data:$(this).attr('id'),
                    success: function(data)
                    {
                        $('#news_container_'+integer).slideUp(1000, function(){
                            $('#news_container_'+integer).html(data).slideDown(1000);
                        });
                        ReloadIVW();
                    }
                }
            );
        }
    );
        
        
    $('.ChartBox').find('a').click
    (
        function(e)
        {
            e.preventDefault();
            
            if(typeof ET_Event !== 'undefined')
                ET_Event.eventStart('Tagestrends',$(this).text(),'Klick');
            
            $(this).parent().parent().parent().parent().parent().find('td').removeClass('active');
            $(this).parent().addClass('active');
            var integer = $(this).parent().parent().parent().parent().attr('id').replace(/\D+/,'');
            $.ajax(
                {
                    type:"POST",
                    url:"/ajax/indextopflopbox.php",
                    data:$(this).attr('id'),
                    success: function(msg)
                    {
                        $('#ChartBoxBody_'+integer).slideUp(1000,function(){
                            $('#ChartBoxBody_'+integer).html(msg).slideDown(1000);
                        });
                        ReloadIVW();
                    }
                }
            );
        }
    );

    $('.ScoachBox').find('a').click
    (
        function(e)
        {
            e.preventDefault();
            
            if(ET_Event)
                ET_Event.eventStart('Scoachbox',$(this).text(),'Klick');
            
            $(this).parent().parent().parent().parent().parent().find('td').removeClass('active');
            $(this).parent().addClass('active');
            var integer = $(this).parent().parent().parent().parent().attr('id').replace(/\D+/,'');
            $.ajax(
                {
                    type:"POST",
                    url:"/ajax/chart.php",
                    data:$(this).attr('id'),

                    beforeSend: function()
                    {
                        $('#chart_'+integer).parent().css('height',$('#chart'+integer).css('height'));
                        $('#chart_'+integer).attr('src',IMAGES_URL+'Symbole/waiter.gif');
                    },
                    success: function(msg)
                    {
                        $('#chart_'+integer).attr('src',msg.replace(/[^A-Za-z0-9\/:\._-]/,'')+'?'+$.now());
                        ReloadIVW();
                    }
                }
            );
        }
    );

    $('.MatrixBox').find('a').click
    (
        function(e)
        {
            e.preventDefault();
            
            if(ET_Event)
                ET_Event.eventStart('Matrix',$(this).text(),'Klick');
            
            $(this).parent().parent().parent().parent().parent().find('td').removeClass('active');
            $(this).parent().addClass('active');
            var integer = $(this).parent().parent().parent().parent().attr('id').replace(/\D+/,'');
            $.ajax(
                {
                    type:"POST",
                    url:"/ajax/basiswertmatrix.php",
                    data:$(this).attr('id'),
                    success: function(msg)
                    {
                        $('#MatrixBoxBody_'+integer).slideUp(1000,function(){
                            $('#MatrixBoxBody_'+integer).html(msg).slideDown(1000);
                        });
                        ReloadIVW();
                    }
                }
            );
        }
    );
});

function moveWallpaper()
{
    if(wallpaper == 1)
    {
        $('#viewport').css('margin-top','95px');
        $('#livesearch_result').css('top','150px');
        $('#big').css('height','0px');
        
        if($('#right_sky').position() != null && $('#right_sky').position().left < 810)
        {
            $('#top_sbanner').css('left',$('#top_sbanner').position().left+40);
            $('#right_sky').css('left',$('#right_sky').position().left+40);
        }
    }
}

function OA_show(zoneid){

   var m3_u = (location.protocol=='https:'?'https://ads.boerse.de/delivery/ajs.php':'http://ads.boerse.de/delivery/ajs.php');
   var m3_r = Math.floor(Math.random()*99999999999);
   if (!document.MAX_used) document.MAX_used = ',';
   document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
   document.write ("?zoneid="+zoneid);
   document.write ('&cb=' + m3_r);
   if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
   document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
   document.write ("&loc=" + escape(window.location));
   if (document.referrer) document.write ("&referer=" + escape(document.referrer));
   if (document.context) document.write ("&context=" + escape(document.context));
   if (document.mmm_fo) document.write ("&mmm_fo=1");
   document.write ("'><\/scr"+"ipt>");
}
