﻿//MasterPage

function hideControls(controlType, classToHide, hide) {
    var message = '';
    if (!(navigator.userAgent.toLowerCase().indexOf('msie 6') > -1)) {
        var inputs = document.getElementsByTagName(controlType);
        message += 'length=' + inputs.length;
        for (i = 0; i < inputs.length; i++) {
            message += i + '-' + inputs[i].id + ', ';
            if ((classToHide == '') || (inputs[i].className == classToHide)) {
                message += 'yes' + '||  ';
                if (hide)
                    inputs[i].style.visibility = 'hidden';
                else
                    inputs[i].style.visibility = 'visible';
            }
        }
    }
}

function openPopup(page) {
    var popupFeatures = 'toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0, menuBar=0, width=590, height=380';
    if (page == 'CGU') {
        window.open('/legal/cgu.aspx', 'CGU', popupFeatures);
    }
    if (page == 'CGV') {
        window.open('/legal/cgv.aspx', 'CGV', popupFeatures);
    }
}

function openRassurance(topic) {
    var popupFeatures = 'toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0, menuBar=0, width=570, height=380';
    window.open('/legal/Rassurance.aspx#' + topic, 'Reassurance', popupFeatures);
}

function showMenu(element) {
    if (element.className == 'dernierMenu')
        element.className = 'dernierMenuActif';
    else
        element.className = 'actif';
}

function hideMenu(element) {
    if (element.className == 'dernierMenuActif')
        element.className = 'dernierMenu';
    else
        element.className = '';
}

//Footer,  Affiliation

function montre(id) {
    var d = document.getElementById(id);
    if (d.style.display == 'block') {
        d.style.display = 'none';
    }
    else {
        for (var i = 1; i <= 15; i++) {
            if (document.getElementById('smenu' + i)) { document.getElementById('smenu' + i).style.display = 'none'; }
        }
        if (d) { d.style.display = 'block'; }
    }
}

//Default

function slideSwitch() {
    var $active = $('#slideshow div.active');
    if ($active.length == 0) $active = $('#slideshow div:last');
    var $next = $active.next().length ? $active.next()
        : $('#slideshow div:first');
    $active.addClass('last-active');
    $next.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
    setInterval("slideSwitch()", 3000);
});

//Basket

$(function() {
    $('#slideShow1').cycle({
        fx: 'fade',
        speed: 300,
        timeout: 3000,
        //next:   '#slideShow1',
        pause: 1,
        nowrap: 1
    });
});

//myAddresses, subscribtion, MyProfile

// validates the contents of the textboxes
function validateContents(src, args) {
    var i = 0;
    var v_text = args.Value;
    var v_valid = true;

    while (i < v_text.length && v_valid == true) {
        if ((v_text.charAt(i) == "|") || (v_text.charAt(i) == "\r"))
            v_valid = false;
        i++;
    }

    args.IsValid = v_valid;
}

function validateRequiredText(oSrc, args) {
    //get the <p> tags containing label and textbox based on the value of the hidden field
    var pField = document.getElementById('p' + args.Value);
    var pLabel = document.getElementById('p' + args.Value + 'Label');

    //initialize class to initial state
    if (pLabel != null)
        pLabel.className = pLabel.className.replace(' erreur', '');
    pField.className = pField.className.replace(' erronne', '');

    //get the textbox to validate
    var obj = document.getElementById(oSrc.id.replace('Required', ''));

    //validating required fields
    if ((obj == null) || (obj.value == '')) {
        if (pLabel != null)
            pLabel.className = pLabel.className + ' erreur';

        pField.className = pField.className + ' erronne';

        args.IsValid = false;
    }
}

//myShoppingCart

function resizeBox() {
    document.getElementById('ctl00_mycart_Flyout2myCart_e').style.height = 'auto';
    document.getElementById('ctl00_mycart_Flyout2myCart_pv').style.height = 'auto';
}

