var backgroundDiv = false;
var windowDiv = false;
var iframediv = false;

function create_background(){
    if(!backgroundDiv){
        backgroundDiv = document.createElement('div');
        backgroundDiv.style.position = 'absolute';
        backgroundDiv.id = 'background_div';
        document.body.appendChild(backgroundDiv);
    }
    

    $(backgroundDiv).setStyles({
       backgroundColor: '#000000',
       width: '100%',
       height: getScrollHeight(),
       position: 'absolute',
       opacity: '0.5',
       overflow: 'hidden',
       left: '0',
       top: '0',
       zIndex: '1500',
       visibility: 'hidden',
       color:'white'
    });
    
    return  backgroundDiv;   
}

function show_loading(){
    if(!backgroundDiv){
        backgroundDiv = document.createElement('div');
        backgroundDiv.style.position = 'absolute';
        backgroundDiv.id = 'background';
        document.body.appendChild(backgroundDiv);
    }
    

    $(backgroundDiv).setStyles({
       backgroundColor: '#000000',
       width: '100%',
       height: getScrollHeight(),
       position: 'absolute',
       opacity: '0.5',
       overflow: 'hidden',
       left: '0',
       top: '0',
       zIndex: '1500',
       visibility: 'hidden',
       color:'white'
    });
    

    if(!windowDiv){
        windowDiv = document.createElement('div');
        windowDiv.style.position = 'absolute';
        document.body.appendChild(windowDiv);
        windowDiv.id = 'loading';
    }
    
    $(windowDiv).setStyles({
        backgroundColor: 'white',
        padding:'20px',
        border: '1px double #dc219f',
        position: 'absolute',
        left:'50%',
        marginLeft: '-100px',
        top: '25%',
        width: '250px',
        height:'50px',
        lineHeight:'50px',
        color:'#dc219f',
        textAlignLast: 'center',
        fontSize: '10pt',
        zIndex : '1600' 
    });
    
    windowDiv.innerHTML = 'mise à jours en cours...'
    
    backgroundDiv.style.visibility = '';            
    windowDiv.style.visibility = ''; 
    
}

function addToCart(product_id,qty)
{
    if(typeof(product_id) != 'number'){
        alert('Impossible d\'ajouter l\'article à votre panier');
        return;
    }
    
    if(qty == undefined)
        qty = 1;
   

    if(!backgroundDiv){
        backgroundDiv = document.createElement('div');
        backgroundDiv.style.position = 'absolute';
        backgroundDiv.id = 'background_div';
        document.body.appendChild(backgroundDiv);
    }
    
    

    $(backgroundDiv).setStyles({
       backgroundColor: '#000000',
       width: '100%',
       height: getScrollHeight(),
       position: 'absolute',
       opacity: '0.5',
       overflow: 'hidden',
       left: '0',
       top: '0',
       zIndex: '1500',
       visibility: 'hidden',
       color:'white'
    });

    if(!windowDiv){
        windowDiv = document.createElement('div');
        windowDiv.style.position = 'absolute';
        document.body.appendChild(windowDiv);
        windowDiv.id = 'messsage_div';
    }
    

    $(windowDiv).setStyles({
       backgroundColor: '#fff',
       width: '500px',
       height: '250px',
       position: 'absolute',
       border: '1px solid #000',
       top: '50%',
       left: '50%',       
       marginLeft: '-300px',       
       marginTop: (getScrollTop()-150) + 'px',                     
       zIndex: '1600',
       color:'#dc219f',
       padding:'10px',
       visibility: 'hidden'
    });
  
     xajax_addToCart(product_id,qty);
}

function showModalframe(url){
    if(!backgroundDiv){
        backgroundDiv = document.createElement('div');
        backgroundDiv.style.position = 'absolute';
        backgroundDiv.id = 'background_div';
        document.body.appendChild(backgroundDiv);
    }
    
    $(backgroundDiv).setStyles({
       backgroundColor: '#000000',
       width: '100%',
       height: getScrollHeight(),
       position: 'absolute',
       opacity: '0.5',
       overflow: 'hidden',
       left: '0',
       top: '0',
       zIndex: '1500',
       visibility: 'hidden',
       color:'white'
    });
    
    if(!windowDiv){
        windowDiv = document.createElement('div');
        windowDiv.style.position = 'absolute';
        document.body.appendChild(windowDiv);
        windowDiv.id = 'messsage_div';
    }
    
    $(windowDiv).setStyles({
       backgroundColor: '#000',
       width: '520px',
       height: '300px',
       position: 'absolute',
       border: '1px solid #000',
       top: '50%',
       left: '50%',       
       marginLeft: '-300px',       
       marginTop: (getScrollTop()-150) + 'px',                     
       zIndex: '1600',
       color:'#dc219f',
       visibility: 'hidden'
    });
    
    windowDiv.innerHTML = '<button onclick="backgroundDiv.style.visibility = \'hidden\';windowDiv.style.visibility = \'hidden\'" id="btn_close"></button><iframe id="modal_frame" src="'+url+'" frameborder="0"></iframe>'
    
    backgroundDiv.style.visibility = '';            
    windowDiv.style.visibility = '';            
}

function up(product_id,customer_id,address_id,country_id,zip_code,addTax){
   document.getElementById('cart_quantity_' + product_id).value=eval(document.getElementById('cart_quantity_' + product_id).value)+1;
   xajax_updateProductQuantity(product_id,document.getElementById('cart_quantity_' + product_id).value,customer_id,address_id,country_id,zip_code,addTax);
}

function down(product_id,customer_id,address_id,country_id,zip_code,addTax){
   document.getElementById('cart_quantity_' + product_id).value=( (qty = eval(document.getElementById('cart_quantity_' + + product_id ).value)-1) > 1 ? qty : 1 );
   if(document.getElementById('cart_quantity_' + product_id ).value > 0)
      xajax_updateProductQuantity(product_id,document.getElementById('cart_quantity_' + product_id).value,customer_id,address_id,country_id,zip_code,addTax);
}



