function load_js()
{
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
        var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number

        if (ieversion<7)
            CFInstall.check({
             mode: "overlay",
             destination: "http://www.google.com"
            });
        }
        
}


function getPrice()
{

    var cp = $('#product_department').val();
    var quantity = $('#quantity_wanted').val();
    var id_product = $('#product_page_product_id').val();

    if(isNaN(cp))
    {
        alert('Merci de saisir un code postal valide.');
        $('#product_department').focus();
    }
    else
    {
        var department = cp.substr(0, 2);
        $.ajax({
            type: 'POST',
            async: false,
            dataType: 'json',
            url: baseDir + 'ajax.priceByDepartment.php',
            data: {department: department, id_product: id_product},
            success: function(data){
                    //À partir de 100 ex. prix unitaire de XX,XX € 
                if(data)
                {
                    price = (Math.round(data.price*100)/100).toFixed(2);
                    price = price.toString().replace('.', ',');

                    $('.ask_price').hide().toggleClass('ask_price price_display').html(price + '<span class="small">HT</span><div class="unity">' + data.unity + '</div><input type="hidden" name="product_department" value="'+cp+'" />').fadeIn('slow');
                    if(data.priceList)
                    {
                        var out = data.priceList;
                        $('#graded_price').hide().html(out).slideDown(500);
                    }

                }
                else
                    alert('Merci de saisir un code postal valide.');
            }
        });
    }

}


$(document).ready(function(){

    $('li.nav_level_2').siblings().find('ul.navSub_3 li.nav_current').parent().slideToggle(500);

    $('.external').click(
        function (){
            window.open($(this).attr('href'));
            return false;
        });

    /* MAIN NAVIGATION */
    $('ul#navMain li.nav_level_1').bind('mouseover', function() {$('ul.navSub_2', this).css('display', 'block');});
    $('ul#navMain li.nav_level_1').bind('mouseout',  function() {$('ul.navSub_2', this).css('display', 'none');} );
    
    $('li.nav_level_2:first-child').addClass('navFirst2');
    $('li.nav_level_2:last-child').addClass('navLast2');
    
    $('li.nav_level_3:first-child').addClass('navFirst3');
    $('li.nav_level_3:last-child').addClass('navLast3');
    
    $('li.nav_level_2').click(function() 
    {
        $(this).siblings().find('ul.navSub_3').slideUp(500);
        
        if($('ul> li', this).length<2)
        {
            $('ul', this).css('background', 'none');
            $('ul li', this).css('background', 'none');
            
            $('ul', this).addClass('oneItem');
        }
        //$('ul', this).slideToggle(500);
        $('ul', this).slideDown(500);
        
        
    });
    
    /* PAGE LISTE PRODUITS */
   /*$('select.nb_item').bind('click', function() {
        alert(window.document.URL);
    });*/

    

    
    /* PAGE FICHE PRODUIT */
    $('#product_department').keypress(function(event) {
        if ( event.which == 13 )
        {
            getPrice();
            return false;
       }
    });
    
    $('#submit_department').click(function() { getPrice(); });



    $('#buy_block').submit(function() {
        var quantity = $('#quantity_wanted');
        var cp = $('#product_department');

        if(quantity.val() == '' || isNaN(quantity.val()))
        {
            alert('Merci de saisir une quantité pour l\'article.');
            quantity.focus();
            return false;
        }
        else if(cp.length>0 && cp=='')
        {
            //&& (cp.val() == '' || isNaN(cp.val()) || cp.val().lenght>5
            alert('Merci de saisir un code postal pour l\'article.');
            cp.focus();
            return false;
        }
          
    });
    
    /* PAGE PANIER */
    //$('#contre_remboursement').fancybox();
    if($('#contre_remboursement').length>0)
    {
        $('#contre_remboursement').fancybox({
		'hideOnContentClick': true,
                'autoDimensions': false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
                'width' : 400,
                'height' : 120
	});
    }
    
    if($('#prelevement').length>0)
    {
        $('#prelevement').fancybox({
		'hideOnContentClick': true,
                'autoDimensions': false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
                'width' : 400,
                'height' : 150
	});
    }
    
    
    if($('.method_payment_1').length>0)
    {
        if($('#method_payment_1:checked').val())
            $('#block_payment .block_infos').slideUp(500);
        
        $('.method_payment_1').click(function() {
            $('#block_payment .block_infos').slideUp(500);
	});
    }
    
    if($('.method_payment_2').length>0)
    {
        if($('#method_payment_2:checked').val())
            $('#block_payment .block_infos').slideDown(500);
        
        $('.method_payment_2').click(function() {
            $('#block_payment .block_infos').slideDown(500);
	});
    }
    
    if($('#delivery_same_bill').length>0)
    {
        $('#delivery_same_bill').click(function() {
            $('#company_bill').val($('#company_delivery').val());
            $('#lastname_bill').val($('#lastname_delivery').val());
            $('#firstname_bill').val($('#firstname_delivery').val());
            $('#address1_bill').val($('#address1_delivery').val());
            $('#postcode_bill').val($('#postcode_delivery').val());
            $('#city_bill').val($('#city_delivery').val());
            $('#id_country_bill').val($('#id_country_delivery').val());
            $('#id_state_bill').val($('#id_state_delivery').val());
        });
    }
    
    
    if($('p.text_date #day').length>0)
    {
        $('p.text_date #day').keyup(function() {
            if(this.value.length==2) $('p.text_date #month').focus();
        });
    }
    
    if($('p.text_date #month').length>0)
    {
        $('p.text_date #month').keyup(function() {
            if(this.value.length==2) $('p.text_date #year').focus();
        });
    }
    
    /* PAGE FAQ */
    $("#pageFaq").accordion({ 
        animated: 'fade',
        autoHeight: false,
        active: -1
    });
    
    $(".associe_item").click(function() {
          location.href = $('.seeProduct a', this).attr('href');
      });
      
      $(".blockPromos  .content").click(function() {
          location.href = $('.seeProduct', this).attr('href');
      });
    
    $("#blockTopVentes .content").click(function() {
          location.href = $('.seeProduct', this).attr('href');
      });
      
    /* BLOC TOP DES VENTES */
    $("#blockTopVentes").slides({
        preload: true,
        play: 5000,
        paginationClass: 'slides_pagination'
      });
      
      

});
