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 addFormulaToCart(id, idf){
    var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'post', 
            parameters: 
				{
					idProduct: id,
					idFormula: idf,
                    action: 'addformulatocart'
				},
			onComplete: function() {
                window.location.reload(true);
			}
        });    
}

function addProductToCart(id){
    var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'post', 
            parameters: 
				{
					idProduct: id,
                    action: 'addproducttocart'
				},
			onComplete: function() {
                window.location.reload(true);
			}
        });    
}

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('Ce produit va être supprimé du panier. Souhaitez-vous 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 removeOption(id) {
    if(confirm('Cette option va être supprimée du panier. Souhaitez-vous continuer ?')) {
        var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
            { 
                method: 'post', 
                parameters: 
    				{
    					idEntry: id,
                        action: 'removeoption'
    				},
    			onComplete: function() {
                    window.location.reload(true);
    			}
            });
    }
}

function emptyCart() {
    if(confirm('Votre panier sera vide. Souhaitez-vous 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() {
    $('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 openPopup(sUrl, sName, nWidth, nHeight) {
	var x = (screen.width-nWidth)/2;
	var y = (screen.height-nHeight)/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 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 updateOption() {
    var options='';
    
    $$('.checkboxes').each(function(element) {
        if(element.checked==true) {
            options = options + element.value + ',';
        }
    }); 

    var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'post', 
            parameters: 
				{
					options: options,
                    action: 'updateoption'
				},
			onComplete: function() {
                window.location.reload(true);
			}
        });
     
}

function applyCode() {
    var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'get', 
            parameters: 
				{
					code: $('code').value,
					amount: $('amount').value,
                    action: 'applycode'
				},
            onSuccess: function(transport) {
                var response = transport.responseText || "empty";
                
                if(response != "empty")
                    alert(response);
            },				
			onComplete: function() {
                window.location.reload(true);
			}
        });
     
}

function getCalendar(m_,y_) {
    var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'get', 
            parameters: 
				{
    			    m: m_,
                    y: y_,				    
                    action: 'getcalendar'
				},
            onSuccess: function(transport) {
                var response = transport.responseText || "nici un raspuns";
                
                $('html_calendar').innerHTML = response;
            }
        });
}

function getClientAddress() {
    var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'get', 
            parameters: 
				{
                    action: 'getclientaddress'
				},
            onSuccess: function(transport) {
                var response = transport.responseText || "nici un raspuns";

                var adr = response.split('#');
                
                $('shipp_firstname').value = adr[0];
                $('shipp_lastname').value = adr[1];
                $('shipp_address').value = adr[2];
                $('shipp_postcode').value = adr[3];
                $('shipp_city').value = adr[4];
                $('shipp_country').value = adr[5];
            }
        });    
}

function checkEmail() {
    var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'get', 
            parameters: 
				{
    			    email: $('email').value,
                    action: 'checkemail'
				},
            onSuccess: function(transport) {
                if(transport.responseText == "unavailable") {
                    $('reg_error').show();    
                } else {
                    $('reg_error').hide();    
                }
            }
        });
}

function checkResponse(transport) {
    alert(transport.responseText);
	if(transport.responseText == "unavailable") {
	    $('reg_error').show();
	    return false;
	}
	$('reg_error').hide();
	return true;
}

function checkLogin() {
    alert($('auth_email').value);
    alert($('auth_password').value);
    var senddata = new Ajax.Request(site_url + "ajax/ajax.php", 
        { 
            method: 'get', 
            parameters: 
				{
    			    email: $('auth_email').value,
    			    password: $('auth_password').value,
                    action: 'checklogin'
				},
            onComplete: checkLoginResponse
        });    
}

function checkLoginResponse(transport) {
    alert(transport.responseText);
	if(transport.responseText == "user_not_found") {
	    $('login_error').show();
	    return false;
	}
	$('login_error').hide();
	return true;
}

function cartDiv(id,show) {
    var element_style=null
    if (document.getElementById) {
        element_style=document.getElementById(id).style;
    } else if (document.all) {
        element_style=document.all[id].style;
    } 
    if(element_style) {
        if (show==true){ element_style.display="inline";
    	element_style.top = 0+"px";
    	element_style.left = 0+"px";
    	}
        if (show==false) element_style.display="none";
    }
}

