active=0;
var blokjes="a";


function shuffleImages( linksa, linksb, url ) 
{ 

	blokjes = (blokjes == "a") ? "b" : "a";
	var locId = 1;
	var links = ['link_1','link_2','link_3','link_4','link_5','link_6','link_7','link_8','link_9'];
	var images = ['img_1','img_2','img_3','img_4','img_5','img_6','img_7','img_8','img_9'];
	var bigImages = ['img_big_1','img_big_2','img_big_3','img_big_4','img_big_5','img_big_6','img_big_7','img_big_8','img_big_9'];
	var img_url = url;	

	if (!document.images) return

	if ( blokjes == 'a')
	{ 
		for (var i=0; i<links.length; i++) 
		{
			$(links[i]).href = linksa[i];
			$(images[i]).src = img_url+langId+'_'+locId+'_picture.jpg';
			$(bigImages[i]).src = img_url+langId+'_'+locId+'_big.gif';
			locId++;
		}
	} else {
	
		for (var i=0; i<links.length; i++) 
		{
			$(links[i]).href = linksb[i];
			$(images[i]).src = img_url+langId+'_'+locId+'_text.gif';
			$(bigImages[i]).src = img_url+langId+'_'+locId+'_big2.gif';
			locId++;
		}
	}
	
	setTimeout(function() {shuffleImages(linksa,linksb,img_url)},4000);

}

function activateHomeImg(div) {
	
	document.getElementById(div).style.display = 'block';
	document.getElementById('div_home').style.display = 'none';

}

function deactivateHomeImg(div) {
	
	document.getElementById(div).style.display = 'none';
	document.getElementById('div_home').style.display = 'block';

}

function changeLanguage( id )
{
    new Ajax.Request('/translate/', {
                method: 'post',
                parameters: {id: id},
                onSuccess : function(response){
                	var sURL = unescape(window.location.pathname);
					window.location.replace( sURL );
                }
            }
        );
}

function updateProductamount( id ){

	var amount;
	amount = document.getElementById('product_' + id).value;
    new Ajax.Request('/cart/updateproductamount', {
                method: 'post',
                parameters: {id: id, amount: amount},
                onSuccess : function(response){
					var sURL = unescape(window.location.pathname);
					window.location.replace( sURL );
                }
            }
        );
}

function removeProduct( id ){

    new Ajax.Request('/cart/removeproduct', {
                method: 'post',
                parameters: {id: id},
                onSuccess : function(response){
                	//alert( response.responseText );
					var sURL = unescape(window.location.pathname);
					window.location.replace( sURL );
                }
            }
        );
}

function changeCountry( id, addressType ){

	var updateId;
	if( addressType == 'delivery' ) {
	
		updateId = 'update_delivery_province';
		
	} else {
		
		updateId = 'update_province';
		
	}
	
    new Ajax.Request('/cart/changecountry', {
                method: 'post',
                parameters: {id: id, addressType: addressType},
                onSuccess : function(response){
					document.getElementById(updateId).innerHTML = response.responseText;
                }
            }
        );
}

function toggleVisibility( id ) {

	if(document.getElementById(id).style.display == 'block') {
		 document.getElementById(id).style.display = 'none';
	} else {
		document.getElementById(id).style.display = 'block';
	}
			
}

function selectGiftservice() {

	if(document.getElementById('add_gifts').style.display == 'block') {
		new Ajax.Request('/cart/removegiftservice', {
	                method: 'post',
	                parameters: {},
	                onSuccess : function(response){
	                	//alert( response.responseText );
						var sURL = unescape(window.location.pathname);
						window.location.replace( sURL );
	                }
	            }
	        );
		 document.getElementById('add_gifts').style.display = 'none';
		 document.getElementById('no_gifts').style.display = 'block';
	} else {
		document.getElementById('add_gifts').style.display = 'block';
		document.getElementById('no_gifts').style.display = 'none';
	}
	
}

function selectGiftserviceAmount() {
	
	document.getElementById('page').value = 'same';
	
}

function toggleLogin( id ) {

	if(id == 'loginform') {
		 document.getElementById('address').style.display = 'none';
		 document.getElementById('loginform').style.display = 'block';
	} else {
		document.getElementById('address').style.display = 'block';
		 document.getElementById('loginform').style.display = 'none';
	}
			
}

function toggleDelivery( id ) {

	if(id == 'different_delivery') {
		 document.getElementById('delivery_address_fields').style.display = 'block';
	} else {
		 document.getElementById('delivery_address_fields').style.display = 'none';
	}
			
}

function changePayment( id ) {
	
	var commentCustomer;
	commentCustomer = document.getElementById('commentCustomer').value;

    new Ajax.Request('/cart/changepayment', {
                method: 'post',
                parameters: {id: id, commentCustomer: commentCustomer},
                onSuccess : function(response){
					var sURL = unescape(window.location.pathname);
					window.location.replace( sURL );
                }
            }
        );	
}

function addExpress() {
	
	var commentCustomer;
	commentCustomer = document.getElementById('commentCustomer').value;

    new Ajax.Request('/cart/addexpress', {
                method: 'post',
                parameters: {commentCustomer: commentCustomer},
                onSuccess : function(response){
				var sURL = unescape(window.location.pathname);
					window.location.replace( sURL );
                }
            }
        );	
}

function changeShipping( ship_id ) {

	var id;
	if ( !ship_id )
	{
		id = document.getElementById('shippingId').value;
	} else id = ship_id;

	var commentCustomer;
	commentCustomer = document.getElementById('commentCustomer').value;

    new Ajax.Request('/cart/changeshipping', {
                method: 'post',
                parameters: {id: id, commentCustomer: commentCustomer},
                onSuccess : function(response){
                    //alert( response.responseText );
					var sURL = unescape(window.location.pathname);
					window.location.replace( sURL );
                }
            }
        );	
}

function submitGiftcertificate() {

	var code;
	code = document.getElementById('gift_code').value;
	var commentCustomer;
	commentCustomer = document.getElementById('commentCustomer').value;
		
    new Ajax.Request('/cart/submitgiftcertificate', {
                method: 'post',
                parameters: {code: code, commentCustomer: commentCustomer},
                onSuccess : function(response){
                    //alert( response.responseText );
					var sURL = unescape(window.location.pathname);
					window.location.replace( sURL );
                }
            }
        );
}

function couponackage(temp) {
	
	var amount;
	var amount_0;
	var amount_1;
	var amount_2;
	var amount_package;
	amount = 0;
	amount_0 = document.getElementById('amount_0').value;
	amount_1 = document.getElementById('amount_1').value;
	amount_2 = document.getElementById('amount_2').value;
	amount_package = document.getElementById('couponPackage').value;
	
	amount = amount_0 + amount_1 + amount_2;

    new Ajax.Request('/giftcoupon/package', {
                method: 'post',
                parameters: {amount: amount, amount_0: amount_0, amount_1: amount_1, amount_2: amount_2, amount_package: amount_package},
                onSuccess : function(response){
					var sURL = unescape(window.location.pathname);
					window.location.replace( sURL );
                }
            }
        );
}
