// clic on an input text field, change the default value


function background() 
{

/*
var Maintenant = new Date();
var heures = Maintenant.getHours();

          if ( heures >= 8 && heures < 18 ){
            
            document.getElementById('bg_inside').className = 'body_inside_noel_jour';

        }
        else if (heures >= 18 || heures < 8 ){
            document.getElementById('bg_inside').className = 'body_inside_noel_nuit';

        }
*/

document.getElementById('bg_inside').className = 'body_inside';
      
}


function initField(id,default_value){
    var id_value = document.getElementById(id).value;
    if(id_value === default_value) document.getElementById(id).value = "";
}

function change_page_icon(id){
    var element_id = "";
    for(var i = 0; i <5; i++){
        element_id = "icon_page_" + i;
        if(document.getElementById(element_id)) document.getElementById(element_id).src = "/skin/frontend/clrz/default/images/icon_pagination_gris.png";
    }   
    document.getElementById(id).src = "/skin/frontend/clrz/default/images/icon_pagination_vert.png";
}

function showAndHide(id){
    jQuery(".tab_left").each(function(){
        this.className = "tab_left left_tab_non_active";
    });

    jQuery(".tab_middle").each(function(){
        this.className = "tab_middle middle_tab_non_active";
    });

    jQuery(".tab_right").each(function(){
        this.className = "tab_right right_tab_non_active";
    });

    document.getElementById("left_tab_" + id).className = "tab_left left_tab";
    document.getElementById("middle_tab_" + id).className = "tab_middle middle_tab";
    document.getElementById("right_tab_" + id).className = "tab_right right_tab";

    jQuery(".display_tab").each(function(i){
        this.style.display = "none";
    });

    document.getElementById("display_" + id).style.display = "block";
}

function item_menu_hover(id) {
    var link_id = "";

    jQuery(".item_menu").each(function(i){
        this.style.backgroundImage = "";

        link_id = "link_menu_" + i;
        div_id = "item_div_" + i;
        document.getElementById(link_id).style.color = "#20a7b9";
        document.getElementById(div_id).style.display = "none";
    });

    var li_id = "item_menu_" + id;
    link_id = "link_menu_" + id;
    div_id = "item_div_" + id;

    document.getElementById(li_id).style.backgroundImage = "url(<?php echo $this->getSkinUrl('images/menu_rollover.png'); ?>)";
    document.getElementById(link_id).style.color = "#FFF";
    document.getElementById(div_id).style.display = "block";
}

function displayMatchBlock(id) {
    jQuery(".last_categories").each(function(i){
        this.style.display = "none";
    });
    jQuery(".sous_categ_font").each(function(i){
        this.style.color = "#009cb2";
    });

    var element_id = "last_categories_" + id;
    var link_id = "child_categ_" + id;
    document.getElementById(element_id).style.display = "block";
    document.getElementById(link_id).style.color = "#79b100";
}

function displayOrNot(value,id){
    if(value == 1) {
        document.getElementById(id).style.display = 'block';
        document.getElementById('minus').style.display = 'block';
        document.getElementById('more').style.display = 'none';
    }
    else {
        document.getElementById(id).style.display = 'none';
        document.getElementById('minus').style.display = 'none';
        document.getElementById('more').style.display = 'block';
    }
}

function change_vote(vote){
    document.getElementById('notationHidden').value = vote;    
    for(var i = 1; i<6;i++){
        id = 'general_' + i;
        val = document.getElementById(id).value;
        if(val <= vote) document.getElementById(id).src = '/skin/frontend/clrz/default/images/star_vote.png';
        else document.getElementById(id).src = '/skin/frontend/clrz/default/images/star_vote_inactive.png';
    }
}

function maxlength_textarea(id, crid, max)
{
    var txtarea = document.getElementById(id);
    document.getElementById(crid).innerHTML=txtarea.value.length;
    txtarea.onkeypress=function(){
        eval('v_maxlength("'+id+'","'+crid+'",'+max+');')
    };
    txtarea.onblur=function(){
        eval('v_maxlength("'+id+'","'+crid+'",'+max+');')
    };
    txtarea.onkeyup=function(){
        eval('v_maxlength("'+id+'","'+crid+'",'+max+');')
    };
    txtarea.onkeydown=function(){
        eval('v_maxlength("'+id+'","'+crid+'",'+max+');')
    };
}
function v_maxlength(id, crid, max)
{
    var txtarea = document.getElementById(id);
    var crreste = document.getElementById(crid);
    var len = txtarea.value.length;
    if(len>max)
    {
        txtarea.value=txtarea.value.substr(0,max);
    }
    len = txtarea.value.length;
    crreste.innerHTML=len;
}

function checkBulky(id){
    if(document.getElementById(id).checked == true) {
        document.getElementById('weight_li').style.display = 'none';
    }
    else {
        document.getElementById('weight_li').style.display = 'block';
    }
}

function removeCategory(anchor)
{
    var li = anchor.parentNode.parentNode;
    var ul = li.parentNode;
    ul.removeChild(li);
}

function addSimpleProduct(anchor)
{
    var html = simpleHtml;
    html = html.replace(/PP/g, associateCount);
    var anchorLi = anchor.parentNode;
    var ul = anchorLi.parentNode;
    var newLi = document.createElement('li');
    newLi.className = "fields";
    newLi.innerHTML = html;
    ul.insertBefore(newLi, anchorLi);
    associateCount++;
}

function changeSection(inc) {
    if(inc == 1) {
        document.getElementById('section_images').style.display = 'none';
        document.getElementById('section_desc').style.display = 'block';
        document.getElementById('desc_tab').className = "current first";
        document.getElementById('images_tab').className = "";
        document.getElementById('desc_span_left').className = "left_account_tab";
        document.getElementById('desc_span_right').className = "right_account_tab";
        document.getElementById('images_span_left').className = "left_account_tab_active";
        document.getElementById('images_span_right').className = "right_account_tab_active";
        jQuery('#save1').attr('class','update display_block');
        jQuery('#save2').attr('class','update display_none');
    }
    else {
        document.getElementById('section_images').style.display = 'block';
        document.getElementById('section_desc').style.display = 'none';
        document.getElementById('desc_tab').className = "first";
        document.getElementById('images_tab').className = "current";
        document.getElementById('desc_span_left').className = "left_account_tab_active";
        document.getElementById('desc_span_right').className = "right_account_tab_active";
        document.getElementById('images_span_left').className = "left_account_tab";
        document.getElementById('images_span_right').className = "right_account_tab";
        jQuery('#save1').attr('class','update display_none');
        jQuery('#save2').attr('class','update display_block');
    }

    window.location.href = "#";
}

function getOffsetPosition(inID, inTYPE)
{
    var iVal = 0;
    var oObj = document.getElementById(inID);
    var sType = 'oObj.offset' + inTYPE;
    while (oObj && oObj.tagName != 'BODY') {
        iVal += eval(sType);
        oObj = oObj.offsetParent;
    }
    return iVal;
}

function show_reponse(inc) {
    var id = 'reponse_' + inc;
    jQuery(".none_reponse").slideUp("slow");    
    jQuery("#" + id).slideDown("slow");
    jQuery(".icon_question_selected").each(function(){
        this.className = "icon_question_unselected";
    });
    document.getElementById("icon_" + inc).className = "icon_question_selected";
}

function appear_popup(){
    jQuery('#back_opacity2').fadeOut(800);
    jQuery('#back_opacity').fadeIn(500);
    jQuery('#popup_box').fadeIn(800);
    jQuery('#back_opacity2').attr('class','display_none');
    jQuery('#back_opacity').attr('class','display_block');
}

function appear_waiting(){ 
    //jQuery('#back_opacity').fadeIn(500);
    jQuery('#back_opacity2').fadeIn(500);
    jQuery('#waiting_box').fadeIn(800);
   
}

function appear_product_add(){
    jQuery('#waiting_box').fadeOut(800);
    jQuery('#product_add_box').fadeIn(800);
}

function initFields(){    
    jQuery(".input-text").each(function(){
        this.value = "";
    });
    
    document.getElementById('add_address').value = "0";   
    document.getElementById('country').value = "";
    document.getElementById('li_region').style.display = 'none';
    document.getElementById('primary_shipping').checked = false;
    document.getElementById('primary_billing').checked = false;
    document.getElementById('primary_shipping').disabled = false;
    document.getElementById('primary_billing').disabled = false;
    document.getElementById('civilite_m').checked = true;
}

function loadAddress(back,link){
    jQuery.ajax({
        url: link,
        success: function(value) {
            jQuery('#' + back).html(value);
        }
    });
}

function choose_address(value) {
    document.getElementById('div_addresses').innerHTML = '<div class="marginauto"><div class="address_load"></div><div class="float_left marginleft10">Chargement...</div><div class="clear"></div></div>';
    if(!value || value=="0") {
        initFields();
        return false;
    }
    else {
        document.getElementById('submit_modification').style.display = 'block';
        document.getElementById('submit_save').style.display = 'none';
        loadAddress('div_addresses','/customer/address/loadaddresses/id/' + value);
        return true;
    }
}

function display_region(value) {    
    if(value != 'FR' && value != '') {
        document.getElementById('li_region').style.display = 'block';
        
    }
    else {
        document.getElementById('li_region').style.display = 'none';
    }
}

function display_region2(value) {
    if(value != 'FR' && value != '') {
        document.getElementById('li_region2').style.display = 'block';
    }
    else {
        document.getElementById('li_region2').style.display = 'none';
    }
}

function appear_coupon(i){
    var myClass = document.getElementById('button_'+i).className;
    if(myClass.indexOf('button_m')!=-1) {
        document.getElementById('button_'+i).className='button_p '+myClass.split('button_m ')[1];
    }
    else if(myClass.indexOf('button_p')!=-1) {
        document.getElementById('button_'+i).className='button_m '+myClass.split('button_p ')[1];
    }
    jQuery('#coupon_' + i).slideToggle();
}

function appear_onglet(i){
    j = i + 1;
    document.getElementById('limiter_bottom_cart_' + j).style.display = 'none';

}

function disappear_onglet(i) {
    j = i + 1;
    document.getElementById('limiter_bottom_cart_' + j).style.display = 'block';
}

function plus_qty(id){
    document.getElementById('btn_next_step').onclick = function() { }
    document.getElementById(id).value = eval(document.getElementById(id).value) + 1;   
    clearTimeout(0);
    timeoutID = setTimeout('submit_frm_update()', 1000);
    Cufon.refresh();
}

function minus_qty(id){
    document.getElementById('btn_next_step').onclick = function() { }
    if(document.getElementById(id).value >= 1)
        document.getElementById(id).value = eval(document.getElementById(id).value) - 1;

    clearTimeout(0);
    timeoutID = setTimeout('submit_frm_update()', 1000);
}
function removeItem(id){
    document.getElementById('remove_'+id).onclick = function() { }
    var n=7;
    var Id='remove_'+id;
    document.getElementById(Id).value =1;
    setTimeout("jQuery('#shopping-cart-form').submit()", 1000);
}
function isNumericKey(e) {
    if(!e) var e=windows.event;
    if(e.keyCode==13) {
        submit_frm_update();
    }
    else {
        if((e.keyCode<48 || e.keyCode>57)) {
            e.returnValue = false;
            e.cancelBubble = true;
        }
        if(e.which<48 || e.which>57) {
            e.preventDefault();
            e.stopPropagation();
        }
    }    
}
function delete_quote(id){
   document.getElementById('btn_next_step').onclick = function() { }
     var Id='remove_quote_'+id;
   document.getElementById(Id).value =id;
   setTimeout("jQuery('#quote_delete').submit()", 1000);
}
function blockpost(url){
      
 if (!document.getElementById('vider')){
     window.location=url;
 }
 else alert('Le montant minimum de commande n\'est pas atteint pour certains des marchands. Merci de modifier votre commande.');
}
function submit_frm_update()
{
    jQuery(".plus").css("display", 'none');
    jQuery(".moins").css("display", 'none');
    jQuery('#shopping-cart-form').submit();
    document.getElementById('submit1').className = 'left_big_grey';
    document.getElementById('submit3').className = 'right_big_grey';
    document.getElementById('submit2').className = 'middle_big_grey';
    Cufon.refresh();
    
}

function displayVisibleCart(value){
    if(value != ""){
        document.getElementById('btn_addProduct').className = 'cart_image';
        document.getElementById('link_addToCart').onclick = function() {
            editForm.submit();
        }
    }
    else {
        document.getElementById('btn_addProduct').className = 'cart_image_disabled';
        document.getElementById('link_addToCart').onclick = function() { }
    }
    Cufon.refresh();
}

function changeSearchAppearance(){
    document.getElementById('left_of_search').className = 'back_search_left_hover';
    document.getElementById('search_top').className = 'body_search_left_hover';
    document.getElementById('right_of_search').className = 'back_search_right_hover';
}

function initSearchAppearance(){
    document.getElementById('left_of_search').className = 'left_input_search';
    document.getElementById('search_top').className = 'search_data';
    document.getElementById('right_of_search').className = 'right_input_search';
}

function EstSiretValide(siret) {
    var estValide;
    if ( (siret.length != 14) || (isNaN(siret)) )
        estValide = false;
    else {
        estValide = true;
    }
    return estValide;
}

function theRotator() {
    //Set the opacity of all images to 0
    jQuery('div#rotator ul li').css({
        opacity: 0.0
    });

    //Get the first image and display it (gets set to full opacity)
    jQuery('div#rotator ul li:first').css({
        opacity: 1.0
    });

    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
    setInterval('rotate()',6000);
}

function rotate() {
    //Get the first image
    var current = (jQuery('div#rotator ul li.show')?  jQuery('div#rotator ul li.show') : jQuery('div#rotator ul li:first'));

    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? jQuery('div#rotator ul li:first') :current.next()) : jQuery('div#rotator ul li:first'));

    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({
        opacity: 0.0
    })
    .addClass('show')
    .animate({
        opacity: 1.0
    }, 1000);

    //Hide the current image
    current.animate({
        opacity: 0.0
    }, 1000)
    .removeClass('show');
}

function loadHeaderCart()
{
    jQuery.ajax({
        url: BASE_URL + 'checkout/cart/getHeaderMiniCart/',
        dataType: "json",
        success: function(data) {
            jQuery('#label_checkout').html(data);
        }
    });
}

function dropDownMenuDisplay(id) {
    id="last_cat_"+id;
    if(navigator.userAgent.indexOf("Safari")==-1 || navigator.userAgent.indexOf("Explorer")!=-1) {return;}

    window.document.getElementById(id).style.marginTop='-35px';
}

function notEmpty(myElement, id) {
    if(myElement.value!='') {
        document.getElementById('coupon_button_ok_left_'+id).className+=' active';
        document.getElementById('coupon_button_ok_middle_'+id).className+=' active';
        document.getElementById('coupon_button_ok_right_'+id).className+=' active';
    }
    if(myElement.value=='') {
        document.getElementById('coupon_button_ok_left_'+id).className=document.getElementById('coupon_button_ok_left_'+id).className.split(' active')[0];
        document.getElementById('coupon_button_ok_middle_'+id).className=document.getElementById('coupon_button_ok_middle_'+id).className.split(' active')[0];
        document.getElementById('coupon_button_ok_right_'+id).className=document.getElementById('coupon_button_ok_right_'+id).className.split(' active')[0];
    }

}
