
		var log = function(element) {
			
			if(typeof console == "object" && typeof console.log == "function") {
				console.log(element);
			} else {
				//do nothing
			}
			
		}
		
		function sleep(ms)
		{
			var dt = new Date();
			dt.setTime(dt.getTime() + ms);
			while (new Date().getTime() < dt.getTime());
		}


	    if (document.getElementsByClassName == undefined) {
	    	document.getElementsByClassName = function(className)
	    	{
	    		var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
	    		var allElements = document.getElementsByTagName("*");
	    		var results = [];
	
	    		var element;
	    		for (var i = 0; (element = allElements[i]) != null; i++) {
	    			var elementClass = element.className;
	    			if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
	    				results.push(element);
	    		}
	
	    		return results;
	    	}
	    }
    
		function changeHash(hash_string) {
			location.hash = hash_string;
		}

		function changeCurrencySelect(currency_code) {
			var currency_select = document.getElementById('currency_select');
			
			if(currency_select) {
				var option_collection = currency_select.options; 
				for(var i = 0; option_collection.length > i; i++) {
					if(option_collection[i].value == currency_code) {
						//option_collection[i].selected = true;
						currency_select.selectedIndex = i;
					} else {
						//option_collection[i].selected = false;
					}
				}
			}
		}

		function getHash() {
			return location.hash.replace('#',''); 
		}
	    
        function selectPriceCurrency(currency) {
			switch(currency) {
				case "GBP":
					changeHash(currency);
					rememberCurrency(currency);
					showPaymentOptions(currency);
					showPricesGBP();
				break;
				case "USD":
					changeHash(currency);
					rememberCurrency(currency);
					showPaymentOptions(currency);
					showPricesUSD();
				break;
				case "AUD":
					changeHash(currency);
					rememberCurrency(currency);
					showPaymentOptions(currency);
					showPricesAUD();
				break;
				case "EUR":
					changeHash(currency);
					rememberCurrency(currency);
					showPaymentOptions(currency);
					showPricesEUR();
				break;
				case "PLN":
					changeHash(currency);
					rememberCurrency(currency);
					showPaymentOptions(currency);
					showPricesPLN();
				break;
				default:
					changeHash("GBP");
					rememberCurrency("GBP");
					showPaymentOptions("GBP");
					showPricesGBP();
			}
        }
        
        function showPaymentOptions(paymentCurrency) {
        	
        	var paymentByPayPal = document.getElementsByClassName('payment_by_paypal')[0];
        	var paymentByGateway = document.getElementsByClassName('payment_by_gateway')[0];
        	
        	var showPayPal = false;
        	var showGateway = false;
        	
        	switch(paymentCurrency) {
				case "GBP":
					showPayPal = true;
					showGateway = true;
				break;
				
				case "USD":
					showPayPal = true;
				break;
				
				case "AUD":
					showPayPal = true;
				break;
				
				
				case "EUR":
					showPayPal = true;
				break;
				
				case "PLN":
					showPayPal = true;
				break;
				
				default:
					showPayPal = true;
					showGateway = true;
					
			}
        	
        	if(paymentByPayPal) {
        		
        		if(showPayPal) {
        			paymentByPayPal.style.display = 'block';
        		} else {
        			paymentByPayPal.style.display = 'none';
        		}
        		
        	}
        	
        	if(paymentByGateway) {
        		
        		if(showGateway) {
        			paymentByGateway.style.display = 'block';
        		} else {
        			paymentByGateway.style.display = 'none';
        		}
        		
        	}
        	
        }

        function rememberCurrency(currency_code) {
            var url = "ajax/selected_currency.php?currency_code=" + currency_code;
            
        	peticion.open("GET", url);
            /*peticion.onreadystatechange = function() {
                if (peticion.readyState == 4) {
                    place.innerHTML = peticion.responseText;
                }
            }*/
        	//preventing old functions to execute
        	peticion.onreadystatechange = function(){};
            peticion.send(null);
            
        }

        function showPricesGBP() {
        	showPrices('gbp');
        }

        function showPricesEUR() {
        	showPrices('eur');
        }

        function showPricesUSD() {
        	showPrices('usd');
        }
        
        function showPricesAUD() {
        	showPrices('aud');
        }

        function showPricesPLN() {
        	showPrices('pln');
        }

        function showPrices(class_name) {
            
        	showPricesIncVat(class_name);
        	showPricesExVat(class_name);
        	
        }

        function showPricesIncVat(element_class) {
			var allPriceContainers = document.getElementsByClassName('item_price_inc_vat');
			
			for(var i = 0; allPriceContainers.length > i; i++ ) {
				var priceElements = allPriceContainers[i].getElementsByTagName('span');
				for(var j = 0; j < priceElements.length; j++) {
					classNameRegExp = new RegExp('^' + element_class + "( *|$)"); 
					if(classNameRegExp.test(priceElements[j].className) ) {
						
						priceElements[j].style.display = 'inline';
					} else {
						
						priceElements[j].style.display = 'none';
					}
					
					
				}  
				
				
			} 
			
        }
        
        function showPricesExVat(element_class) {
			var allPriceContainers = document.getElementsByClassName('item_price_ex_vat');
			
			for(var i = 0; allPriceContainers.length > i; i++ ) {
				var priceElements = allPriceContainers[i].getElementsByTagName('span');
				for(var j = 0; j < priceElements.length; j++) {
					classNameRegExp = new RegExp('^' + element_class + "( *|$)"); 
					if(classNameRegExp.test(priceElements[j].className) ) {
				
						priceElements[j].style.display = 'inline';
					} else {
				
						priceElements[j].style.display = 'none';
					}
				}
				
				
	        	
			} 
			
        }

   	
        