/**
 * @author midj
 */

function toggleBlock(pEl){
    block = $(pEl).next();

    if(block.getStyle('display') == 'none'){
        new Effect.BlindDown(block,{
            duration: 0.2
        });
    }else{
        new Effect.BlindUp(block, {
            duration: 0.2
        });

    }
}

function buildSubmenu(pId){
    new Ajax.Updater('subnav', '/navbar/build?id=' + pId );

}

window.onload=function(){
    setupZoom();
}

var pack_validity = '';
var pack_pack = '';
var product = '';
var type_produit = '';


function modifyTypeGB(obj, duration){
    new Ajax.Updater('total', '/cart/returnBoxPrice?duration=' + duration);
    $('item_id').setAttribute('value', 'PB' + duration);
    $('item_price').setAttribute('value', 0);
    $$("img.val").each(function(row){row.setAttribute('src', '/images/btn_puce_off.png')});
    obj.setAttribute('src', '/images/btn_puce.png');
    $('item_product').setAttribute('value','Purple Box ' + duration + ' mois');
}
function slEl(pEl, other, val, pack, type_prd){
    type_produit = type_prd;
    for (var i = 0; i < other.length; i++) {
        other[i].setAttribute('src', '/images/btn_puce_off.png');
    }
    pEl.setAttribute('src', '/images/btn_puce.png');
    if (val) {
        $('et_2').writeAttribute("class", "txt_bold");
        var array_val = new Array();
        array_val["S"] = 1;
        array_val["M"] = 3;
        array_val["L"] = 6;
        array_val["XL"] = 12;
        $('type_pack').update(array_val[val]);
        pack_validity = array_val[val];
        $('pack_td2').show();
    }
    if (pack) {
        $('et_3').writeAttribute("class", "txt_bold");
        var array_pack = new Array();
        array_pack["S"] = 5;
        array_pack["M"] = 20;
        array_pack["L"] = 50;
        array_pack["XL"] = 100;
        $('nb_fl').update(array_pack[pack]);
        pack_pack = array_pack[pack];
    }
    retrieveTotal();
}
function retrieveTotal(){
    if (pack_validity && pack_pack) {
        product = type_produit + ' ' + pack_validity + 'mois, ' + pack_pack + ' Flashcodes'
        //$('w_validity').update(pack_validity);
        //$('w_pack').update(pack_pack);
        var array_val_price = new Array();
        array_val_price[1] = 100;
        array_val_price[3] = 200;
        array_val_price[6] = 400;
        array_val_price[12] = 650;
				
        var array_pack_price = new Array();
        array_pack_price[5] = 1.5;
        array_pack_price[20] = 1.8;
        array_pack_price[50] = 2;
        array_pack_price[100] = 3;
        var v1 = 0;
        var v2 = 0;
        v1 = array_val_price[pack_validity];
        v2 = array_pack_price[pack_pack];
        v4 = 1;
				
        if ($('pro_version')) {
            if ($('pro_version').checked == true) {
                v4 = 1.20;
            }
        }

        $('form_validate').show();
        $('total').update((v1 * v2) * v4);
        $('item_product').setAttribute('value', product);
        $('item_price').setAttribute('value', (v1 * v2) * v4);
    //$('et_4').show();
    }
}

function creerZoneCode() {

    var type = '';
    if($F('generate_type_flashcode'))
    {
        type = 'flashcode';
    }
    
    if($F('generate_type_qrcode'))
    {
        type = 'qrcode';
    }

    new Ajax.Updater(
        'zone2d',
        '/content/genererZoneCode',
        {
            method: 'get',
            parameters: {'url' : $F('generate_url'), 'type' : type},
            onComplete: $('zone2d').appear({duration: 4.0})
        });
}


