function showProcessing() {
    $('buttons').hide();
    $('processing').show();
}

function showMessage(block_) {
    new Effect.Appear(block_, {duration: 1});
    new Effect.Fade(block_, {duration: 1, delay: 3});
}

function showAddress(type, id) {
    $('closed_'+ type + '_' + id).hide();
	$('opened_'+ type + '_' + id).show();
	
	new Effect.SlideDown(type + '_address_' + id, {duration: 1});
}

function hideAddress(type, id) {
	$('closed_'+ type + '_' + id).show();
	$('opened_'+ type + '_' + id).hide();
	
	new Effect.SlideUp(type + '_address_' + id, {duration: 1});
}

function updateCart(id) {
    $('qty_' + id).hide();
    $('options_' + id).hide();
    $('loading_' + id).show();
    
    var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'post', 
            parameters: 
				{
					idEntry: id,
					quantity: $('qty_' + id).value,
                    action: 'updatecart'
				},
			onComplete: function() {
                window.location.reload(true);
			}
        });
}

function changeDeafultDelivery(id) {
	$('loading-change-daddr').show();
	
	var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'post', 
            parameters: 
				{
					idAddress: id,
					idClient: $('idClient').value,
                    action: 'change_def_delivery'
				},
			onComplete: function() {
                window.location.reload(true);
			}
        });
}

function removeWhishlist(id) {
	$('whish-butt-' + id).hide();
	$('loading-wremove-' + id).show();
	
	var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'post', 
            parameters: 
				{
					idProduct: id,
                    action: 'whish_remove'
				},
			onComplete: function() {
                $('loading-wremove-' + id).hide();
				new Effect.Fade('whish-' + id, {duration: 1});
			}
        });
}

function removeProduct(id) {
    if(confirm('Ce produit sera supprime du panier. Continuer?')) {
        $('qty_' + id).hide();
        $('options_' + id).hide();
        $('loading_' + id).show();
        
        var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
            { 
                method: 'post', 
                parameters: 
    				{
    					idEntry: id,
                        action: 'removeentry'
    				},
    			onComplete: function() {
                    window.location.reload(true);
    			}
            });
    }
}

function removeGift(id) {
    if(confirm('Ce chèque cadeau sera supprime du panier. Continuer?')) {
        $('chq_' + id).hide();
        $('loading_chq_' + id).show();
        
        var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
            { 
                method: 'post', 
                parameters: 
                    {
                        idCheque: id,
                        action: 'removechecque'
                    },
                onComplete: function() {
                    window.location.reload(true);
                }
            });
    }
}

function emptyCart() {
    if(confirm('Le panier sera vide. Continuer?')) {
        $('cart-content').hide();
        $('cart-delete').show();
        
        var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
            { 
                method: 'post', 
                parameters: 
    				{
                        action: 'emptycart'
    				},
    			onComplete: function() {
                    window.location.reload(true);
    			}
            });
    }
}

function finishOrder() {
    var valid = new Validation('pay_form', {onSubmit:false});
    result = valid.validate();
    
    if(result === false) {
        return false;
    } else {
        $('submit_pay').hide();
        $('loading_pay').show();
        
        var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
            { 
                method: 'post', 
                parameters: 
    				{
    					form_data: $('pay_form').serialize(),
                        action: 'finishorder'
    				},
    			onComplete: function(transport) {
                    /*var response = transport.responseText || "nici un raspuns";
                    alert(response);*/
                    window.location.reload(true);
    			}
            });
    }
}

function showOrderDetails(action, id) {
    switch(action) {
        case "show":
            $('order_closed_' + id).hide();
            $('order_opened_' + id).show();
            //$('details_' + id).show();
            new Effect.SlideDown('details_' + id, {duration: 1});
            break;
        case "hide":
            $('order_closed_' + id).show();
            $('order_opened_' + id).hide();
            //$('details_' + id).hide();
            new Effect.SlideUp('details_' + id, {duration: 1});
            break;
    }
}

function hideButton(id, loading) {
    $(id).hide();
    $(loading).show();
}

function setPriceOrder(direction) {
    var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'post', 
            parameters: 
				{
					dir: direction,
                    action: 'setsortorder'
				},
			onComplete: function(transport) {
                /*var response = transport.responseText || "nici un raspuns";
                alert(response);*/
                window.location.reload(true);
			}
        });
}

function copyAddress() {
    var inputs = ['tohide_1','tohide_2','tohide_3','tohide_4','tohide_5','tohide_6','tohide_7','tohide_8','tohide_9','tohide_10','tohide_11'];
    
    if($('copyfromaddress').checked === false) {
        $('toshow_1').hide();
        
        for(var i = 0; i < inputs.length; ++i) {
			var input = inputs[i];
            $(input).show();
		}
        
    } else {
        $('toshow_1').show();
        
        for(var i = 0; i < inputs.length; ++i) {
			var input = inputs[i];
            $(input).hide();
		}
    }
}

function showInfoBlock(what) {
    var blocks = ['er1','er2','er3','er4','er5'];
    
    if(blocks.join().indexOf(what) >= 0) {
        for(var i = 0; i < blocks.length; ++i) {
			var input = blocks[i];
            $(input).hide();
		}
        
        $(what).show();
    } else {
        for(var i = 0; i < blocks.length; ++i) {
			var input = blocks[i];
            $(input).hide();
		}
    }
}

function savePDF() {
    window.location = window.location.href + '/pdf';
    
    return false;
}

function openPopup(sUrl, sName, nWidth, nHeight) {
	var x = (screen.width-width)/2;
	var y = (screen.height-height)/2;
	
	window.open(sUrl, sName, "width="+nWidth+", height="+nHeight+" toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes, screenX="+x+", screenY="+y+", left="+x+", top="+y);
}

function removeProductComparator(idEntry, idProduct) {
	var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'get', 
            parameters: {action: 'removeentrycomparator', idEntry: idEntry, idProduct: idProduct},
            /* DEBUG */
            onSuccess: function(transport){
                var response = transport.responseText || "nici un raspuns";
            },
            onFailure: function() { 
                alert('Produsul nu a putut fi sters !');
            },
            onComplete: function() {
		            //window.location.reload(true);
            }
            /* END DEBUG */
        });
        
        getProductComparator();
}

function getProductComparator() {
	var senddata = new Ajax.Updater('product-comparator', site_url + 'product-comparator.php', 
        { 
            method: 'get', 
            parameters: 
						{
						},
            onSuccess: function(transport){
                var response = transport.responseText || "";
                $('product-comparator').innerHTML = response;
                
                if (response != "") {
                    $('product-comparator').show();
                }
                else {
                    $('product-comparator').hide();
                    $('comparator-list').hide();
                }
            }
        });
}

function setLanguage(lang) {
    window.location = site_url + '?setfrontlang=' + lang;
}

function updatePrice(id_, symbol_, type_) {
    $('price').hide();
    $('loading-price').show();
    
    var senddata = new Ajax.Request(site_url + 'ajax/ajax.php', 
        { 
            method: 'get', 
            parameters: {
			    id: id_,
                symbol: symbol_,
                type: type_,
                action: 'updateprice'
            },
            onFailure: function() { 
                alert('Pretul nu a putut fi actualizat !');
            },
            onSuccess: function(transport) {
	            $('loading-price').hide();
                
                var response = transport.responseText || "nici un raspuns";
                
                $('price').innerHTML = response;
                $('price').show();
            }
        });
}

function bigImageSet(img) {
	$('produit1').src = site_url + 'media/images/medium/' + img;
	
	$('produit1').setAttribute("jqimg", site_url + 'media/images/' + img);
}

function addToCart(id) {
	var colour_ = $('couleur') ? $('couleur').value : '';
	if($('size')) {
        if($('size').value != '0') {
            var size_ = $('size').value;
        } else {
            alert('Merci de choisir une taille!');
            return false;
        }
    } else {
        var size_ = '';
    }
    
	var senddata = new Ajax.Request(site_url + 'ajax/ajax.php', 
    { 
        method: 'get', 
        parameters: {
            addtocart: id,
            qty: $('qty').value,
			colour: colour_,
			size: size_,
            action: 'add_to_cart'
        },
        onFailure: function() { 
            
        },
        onSuccess: function(transport) {
            
        },
        onComplete: function(transport) {
            affiche('cfpan',true);
        }
    });
}

function addToCartFromWishlist(id) {
    $('wtocart-trigger-' + id).hide();
    $('loading-wtocart-' + id).show();
    
    var senddata = new Ajax.Request(site_url + 'ajax/ajax.php', 
    { 
        method: 'get', 
        parameters: {
            addtocart: id,
            qty: '1',
			colour: '',
			size: '',
            action: 'add_to_cart'
        },
        onFailure: function() { 
            
        },
        onComplete: function(transport) {
            window.location=site_url + 'panier.html';
        }
    });
}

function changeDeliveryCountry(id) {
	$('loading_country').show();
	
	var senddata = new Ajax.Request(site_url + 'ajax/ajax.php', 
    { 
        method: 'post', 
        parameters: {
            idEntry: id,
            action: 'change_delivery_country'
        },
        onFailure: function() { 
            
        },
        onComplete: function(transport) {
            window.location.reload(true);
        }
    });
}

function setPackaging() {
	$('loading_pack').show();
    
    var senddata = new Ajax.Request(site_url + 'ajax/ajax.php', 
    { 
        method: 'post', 
        parameters: {
            status: $('kdo').checked === true ? 'set' : 'unset',
            action: 'set_packing_tax'
        },
        onFailure: function() { 
            
        },
        onComplete: function(transport) {
            window.location.reload(true);
        }
    });
}

function setFilter(cat, filter) {
    window.location = site_url + cat + '/setfilter-' + escape(filter);
}


function nextCartStep(step) {
	if($('order_comment') && $('order_comment').value != '' && $('order_comment').value != 'Votre commentaire') {
		var senddata = new Ajax.Request(site_url + 'ajax/ajax.php', 
	    { 
	        method: 'post', 
	        parameters: {
	            order_comment: $('order_comment').value,
	            action: 'set_order_comm'
	        },
	        onFailure: function() { 
	            
	        },
	        onComplete: function(transport) {
	            var response = transport.responseText || "nici un raspuns";
				//alert(response);
				window.location = site_url + 'panier.html/' + step + '/';
	        }
	    });
	} else {
	    window.location = site_url + 'panier.html/' + step + '/';
	}
}

function orderPay(how) {
   switch(how) {
        case "cb":
            var senddata = new Ajax.Request(site_url + 'ajax/ajax.php', 
            { 
                method: 'post', 
                parameters: {
                    pay_method: how,
                    order_ref: $('reference').value,
                    action: 'set_pay_method'
                },
                onLoading: function() { 
                    $('pay_cb').hide();
                    $('loading_cb').show();
                },
                onComplete: function(transport) {
                    var response = transport.responseText || "nici un raspuns";
                    if(response == 'ok') {
                        document.PaymentRequest.submit();
                    }
                }
            });
            break;
        case "check":
            var senddata = new Ajax.Request(site_url + 'ajax/ajax.php', 
            { 
                method: 'post', 
                parameters: {
                    pay_method: how,
                    action: 'set_pay_method'
                },
                onLoading: function() { 
                    $('pay_check').hide();
                    $('loading_check').show();
                },
                onComplete: function(transport) {
                    var response = transport.responseText || "nici un raspuns";
                    if(response == 'ok') {
                        nextCartStep('5');
                    }
                }
            });
            break;
    }
}


function toWishlist(id) {
    if($('size')) {
        if($('size').value != '0') {
            var size_ = $('size').value;
        } else {
            alert('Merci de choisir une taille!');
            return false;
        }
    } else {
        var size_ = '';
    }
    
    var senddata = new Ajax.Request(site_url + 'ajax/ajax.php', 
    { 
        method: 'post', 
        parameters: {
            idprod: id,
            action: 'to_wishlist'
        },
        onLoading: function() { 
            
        },
        onComplete: function(transport) {
            window.location = site_url + 'towhishlist_' + id;
        }
    });
}

function cancelNewShippAddr() {
    $('aal').hide();
    $('aaf').show();
    
    $('nom2').value = '';
    $('prenom2').value = '';
    $('adresse2').value = '';
    $('cp2').value = '';
    $('ville2').value = '';
}
