$(function(){
    $('.nb_per_page').change(function(){
        location = $(this).val();
    });
});


function displayMessagePopup(){
    $('#message_popup').dialog({
        modal: true,
        resizable:'false',
        width :300,
        buttons: {
            "Continuer": function() {
                $(this).dialog('close');
            }
        }
    });
}

function get(id){
    return document.getElementById(id);
}


function load_cart(){
    var url = window.location.href.substring(0,window.location.href.lastIndexOf("/", 0)) + 'ajax_load_shopping_cart.php';

    $('#load_shopping_cart').load(url);
}



function confirmDeleteAddress(id){
    if(confirm(confirmDeleteAddressText)){
        window.location="address_book_process.php?action=deleteconfirm&delete="+id;
    }
}

function checkSearch(){
    var err = "";

    if(!$("#keywords").val()){
        err+="Veullez remplir au moins un des critères de recherche."+"\n";
    }else{
        if($("#pfrom").val() && (!isNumeric($("#pfrom").val() ) || $("#pfrom").val() <= 0)){
            err+="Le prix minimum doit être un nombre positif."+"\n";
        }
        if($("#pto").val() && (!isNumeric($("#pto").val() ) || $("#pto").val() <= 0)){
            err+="Le prix maximum doit être un nombre positif."+"\n";
        }
    }
    if(err){
        $('#message_popup').html(err);
        displayMessagePopup();
        return false;
    }else{
        return true;
    }
}

function deleteProduct(id){
    get('cart_delete').value = id;
    get('cart_quantity').submit();
}

function isNumeric(str){
    var re = /[\D]/g
    if (re.test(str)) return false;
    return true;
}



function popup_secure (url){
    window.open(url,'','width=565,height=415,scrollbars=1');
}

function openWin(value)
{
    myWindow=window.open('','','width=400,height=250');
    myWindow.document.write("<p style='color:#301400;font-family:Verdana,Arial,sans-serif;font-size:10px;'>"+value+"</p>");
    myWindow.focus();
}