/************************* FUNCTIONS ******************************/function addToBasket(artikkelNr, deleteClicked) {	jQuery(document).ready(function() {		var ajax_load_indicator = "<img src='/assets/img/loading_facebook.gif' alt=''>";		$('#'+artikkelNr+'_Message').fadeOut(800);		$('#'+artikkelNr+'_Btn').html(ajax_load_indicator);		if ( !( $.cookie ( 'sessionid' ) ) ) { // If cookie is disabled			window.open('/salg/views/_errors/cookies.shtml', '_self');			// Code will not continue		} 		if (deleteClicked) {			var antall = "0";			}		else {			var antall = $("#"+artikkelNr+"_Antall").attr("value");		}		var antall_orig = parseInt($("#"+artikkelNr+"_Antall_Orig").attr("value"));  //This is needed just in case an error occurs to return it to its original value				if (antall == "") { //if user click «Bestill» button without typing any value			antall = 1;		}				if( isNaN(antall) ) {				alert("«"+ antall +"» er ikke et gyldig tall.");			if (antall_orig == 0) {				$("#"+artikkelNr+"_Antall").val("");				$('#'+artikkelNr+'_Btn').html("Bestill");			}			else {				$("#"+artikkelNr+"_Antall").val(antall_orig);				$('#'+artikkelNr+'_Btn').html("Endre bestilling");				$('#'+artikkelNr+'_Message').fadeIn(800);			}			return false;		} // Exit				antall = parseInt(antall);				var date = new Date();		var timestamp = date.getTime();		var url = '/handlekurv/legg-til/?time=' + timestamp;		$.ajax({ 			url : url,			type : 'POST',			data : { artikkelNr: artikkelNr, antall: antall },			dataType : 'jSon', //if this is declared, the response will be automatically parsed as jSON object, if not use parseJson for the response e.g. obj = parsejSon(response)			error : function (jqXHR, textStatus, errorThrown){            	alert ("Nettsiden er dessverre ikke tilgjengelig – du kan prøve igjen om 5 minutter eller send oss en e-post på ordre@lex.no");            	if (antall_orig == 0) {					$("#"+artikkelNr+"_Antall").val("");					$('#'+artikkelNr+'_Btn').html("Bestill");				}				else {					$("#"+artikkelNr+"_Antall").val(antall_orig);					$('#'+artikkelNr+'_Btn').html("Endre bestilling");					$('#'+artikkelNr+'_Message').fadeIn(800);				}				return false;            },               success : function(obj) {             	var total = obj.cartAntall; //total products in the cart    				var artikkel_antall = obj.artikkelAntall; 								if(total > 0){ 					$('#shopping-cart').removeClass('shopping_cart_empty');$('#shopping-cart').addClass('shopping_cart_loaded');				}				else{					$('#shopping-cart').removeClass('shopping_cart_loaded');$('#shopping-cart').addClass('shopping_cart_empty');				}								var unit = (total==1) ? "produkt" :"produkter";				$('#cartAntall').html('Handlekurven har '+total+' '+unit);								if (artikkel_antall == 0) {					$("#"+artikkelNr+"_Btn").html("Bestill");					$("#"+artikkelNr+"_Antall").attr("value", "");					$("#"+artikkelNr+"_Antall_Orig").attr("value", "0");					$("#"+artikkelNr+"_Message").html("");				}				else {					$("#"+artikkelNr+"_Antall").attr("value", artikkel_antall);					$("#"+artikkelNr+"_Antall_Orig").attr("value", artikkel_antall);					$("#"+artikkelNr+"_Message").html('<span class="cart-link">Vis handlekurv »</span>').fadeIn(800);					$("#"+artikkelNr+"_Btn").html("Endre bestilling");				}			   			} 		});            });    }/************************* END OF FUNCTIONS ******************************/jQuery(document).ready(function() {	/*****DO these if Javascript is ON*******/	$('#js_error_message').hide(); //error message for javascript is pre-loaded on page load then this line will auto-hide it if javascript is ON	$('.shop_container').show();	$('#text_size').show(); 	$('#shopping_cart_container').show();	/*****************************************/		/***** Echo session_id to the footer *******/	var sessionid = $.cookie('sessionid');	sessionid = sessionid.substring(0, sessionid.search("_"))	$('#user_session').append(sessionid);	/*************************/		if ($.cookie("textSize")=="TextLarge"){		$('.TextSize a.large').addClass('active');		}	else if ($.cookie("textSize")=="TextMedium"){		$('.TextSize a.medium').addClass('active');	}	else{		$('.TextSize a.small').addClass('active');		}		$('#wrapper').addClass($.cookie("textSize")); //if cookie for textsize isset then add a class to wrapper		$('#text_size a.large').click(function(){		$('#text_size a').removeClass('active');		$(this).addClass('active');		$('#wrapper').addClass('TextLarge');		$('#wrapper').removeClass('TextMedium');			$.cookie("textSize", "TextLarge", {path:'/'});	});	$('#text_size a.medium').click(function(){		$('#text_size a').removeClass('active');		$(this).addClass('active');		$('#wrapper').addClass('TextMedium');			$('#wrapper').removeClass('TextLarge');		$.cookie("textSize", "TextMedium", {path:'/'});	});	$('#text_size a.small').click(function(){		$('#text_size a').removeClass('active');		$(this).addClass('active');		$('#wrapper').removeClass('TextMedium');		$('#wrapper').removeClass('TextLarge');		$.cookie("textSize", "", {path:'/'});	});			$('input#search_field').val('Søk'); // Put a default value to override value from html	$('input#search_field').focus(function(){		if ( $(this).val() == 'Søk' ) {				this.value = '';			$(this).addClass('active');		}		$(this).animate({width:'260px'},800);	});	$('input#search_field').blur(function(){		if ( $(this).val() == "" ) {			this.value = 'Søk';			$(this).removeClass('active');		}		$(this).animate({width:'160px'},800);	});		$('.delete-product').click(function(){		var r=confirm("Er du sikker på at du vil slette artikkelen?");				if(r==true){			var artikkelNr = $(this).attr("href");			artikkelNr = artikkelNr.substring(5)						addToBasket(artikkelNr, true); // second parameter means delete-icon is clicked					return false; // return false to stop executing the link to the server because it is already done in ajax		}		else{			return false;			}			});	});
