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 removeProduct(id) {
    if(confirm('Acest produs va fi sters din cos. Continuam ?')) {
        $('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 emptyCart() {
    if(confirm('Cosul de cumparaturi va fi golit. Continuam ?')) {
        $('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 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 toCart(id_) {
    var senddata = new Ajax.Request(site_url + 'ajax/ajax.php', 
        { 
            method: 'post',  
            parameters: {
			    id: id_,
                qty: $('qty_tocart').value,
                action: 'setqty'
            },
            onComplete: function(transport) {
	            window.location = site_url + 'tocart_' + id_;
            }
        });
}