
	// kræver jquery
	function findreplace(el, find, rep) {
		try{$(el).html($(el).html().replace(find, rep))}catch(e){};
	}

	function getCookie(c_name)
	{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
	}
	
	function setCookie(c_name,value,expiredays)
	{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}

	domReady(function(){
		
		// Loader productmenu
		cn_init_menu(document.getElementById('ProductMenu_Table'),1)

		$('#ProductList_TD .TextInputField_Productlist, .FrontPage_TD .TextInputField_Productlist').css('display', 'none');


	});






	$(document).ready(function(){






	if	(location.href.indexOf('order3.html') != -1){

		// Tildele table's ID'er i steps
		var i = 1;
		$('.CustomerInfo_OrderStep3 table').each(
			function() {
				$(this).attr('id', 'CustomerInfo_OrderStep3_Table'+i++)
			}
		)

		$('#CustomerInfo_OrderStep3_Table3').each(function(){
			$(this).css('width', '100%');
			$(this).before('<a href="javascript:history.go(-2)"><img src="../design/BN-ret.png" align="right" style="position:relative;top:18px;" /></a>');
		})

		$('#CustomerInfo_OrderStep3_Table4').each(function(){
			$('#CustomerInfo_OrderStep3_Table4').css('width', '100%');
			$(this).before('<a href="javascript:history.go(-1)"><img src="../design/BN-ret.png" align="right" style="position:relative;top:2px;" /></a>');
		})
		
	}

	
	
	
	
		// Fjerner bindestreg i starten af et produktnavn
		$('.niv1, .niv2, .niv3, .niv4, .niv5').each(function(){
			if ($(this).text().substring(0,1) == '-'){
				$(this).text($(this).text().substring(1,999))
			}
		})

		// For skjule print på kvitering
		$('.BackGroundColor1_OrderStep4 a:parent').css('display', 'none');




		// Insætter pris i fragt hvor der ikke står noget som standart
		if ($('#ShippingFee').html()  != null){
			if	($('#ShippingFee').html() == ''){
					$('#ShippingFee').text('0,00 DKK')
			}
		}
		

		// Indhold der flytter posison
		// Infokort bytter om på tekstpossion
		if ($('#MoveFrom').html()  != null){
			if ($('#MoveTo').html()  == ''){
				document.getElementById('MoveTo').innerHTML = document.getElementById('MoveFrom').innerHTML
				document.getElementById('MoveFrom').innerHTML = ''
				$('#MoveFrom').css('display', 'none');
			}
		}

		// Infokort bytter om på billedeposion
		if (ProductNumber  != '' && document.getElementById('moveimage') != null){
			if (document.getElementById('Canvas').innerHTML == ''){
			document.getElementById('Canvas').innerHTML = document.getElementById('moveimage').innerHTML
			document.getElementById('moveimage').innerHTML = ''
			$('#Canvas div').css('display', 'none');
			}
		}
		

		// Hvis ingen indhold i div's på Infokort
		if (ProductNumber  != ''){
			if ($('#Canvas').html() == ''){$('#Canvas').css('display', 'none');}
			if ($('#Selector').html() == ''){$('#Selector').css('display', 'none');}
		}
		
		// Steps - overskrifter
		if ($('#OrderStep1_TD').html() != null){
			$('#OrderStep1_TD h1').css('display', 'none')
			$('#OrderStep1_TD').prepend('<h1>'+ $('#OrderStep1_TD h1').text() +'</h1>')
		}

		if ($('#OrderStep2_TD').html() != null){
			$('#OrderStep2_TD h1').css('display', 'none')
			$('#OrderStep2_TD').prepend('<h1>'+ $('#OrderStep2_TD h1').text() +'</h1>')
		}

		if ($('#OrderStep3_TD').html() != null){
			$('#OrderStep3_TD h1').css('display', 'none')
			$('#OrderStep3_TD').prepend('<h1>'+ $('#OrderStep3_TD h1').text() +'</h1>')
		}
		if ($('#OrderStep4_TD').html() != null){
			$('#OrderStep4_TD h1').css('display', 'none')
			$('#OrderStep4_TD').prepend('<h1>'+ $('#OrderStep4_TD h1').text() +'</h1>')
		}




		// Sætter overskrift på Anbefal
		$('#TipFriend_TD').html('<h1>Anbefal</h1>'+$('#TipFriend_TD').html());
		$('.Heading_TipFriend').html('&nbsp;<br>&nbsp;<br>');
		// Laver brede på table 100%
		findreplace('#TipFriend_TD','400','100%');

		

		// Overskrift til nyheder
		if	(location.href.indexOf('news-ALL-1.html') != -1){
			$('#ProductList_TD h1').text('Nyheder');
		}

		// Overskrift til tilbud
		if	(location.href.indexOf('specialoffer-ALL-1.html') != -1){
			$('#ProductList_TD h1').text('Tilbud');
		}


	if (Keyword.length > 0){

            for (i=1; i<256; i++){
                var re = new RegExp('&#(' + i + ');', 'g');
                Keyword = Keyword.replace(re, String.fromCharCode(i))
            }

			// Hvis søgesting ikke er tom gemmer den, den i en cookie
			if (Keyword != ''){setCookie('seekform',Keyword,365);};
			var SeekCookie = getCookie('seekform');
			// Sætter string ind i formen på siden
			if (SeekCookie != ''){$('#Search_Form_New #Keyword').attr('value', SeekCookie);};

			// Hvis Formen bliver sendt tom eller med standart-text sendes brugern til forsiden
			if (CurrencyReturnUrl == '/shop/search-1.html?keyword='){alert('Du skal udfylde et søgeord');setCookie('seekform','',-1);location.href = '/';};

			// Overskrift til søgning
			if	(Keyword  != ''){
				$('#ProductList_TD h1').text('Søgning: '+Keyword);
			}

	}
		
	if	(location.href.indexOf('p.html') != -1){

			$('.FrontPage_TD .Hover .BuyButton_ProductList, #ProductList_TD .Hover .BuyButton_ProductList, .ProductInfo_TD .Hover img').each(function(){
				$(this).attr('src', '/design/BN-koeb.png')
			})

			// Retter op på enkelte produkter i relaterede eller kunder købte også på varekort
			var RelatedCount = 0;
			$('.ProductInfo_TD .Related_Custom_TBL td').each(function(){
				RelatedCount++
			})
	
			var AlsoBoughtCount = 0;
			$('.ProductInfo_TD .CustomersAlsoBought_Custom_TBL td').each(function(){
				AlsoBoughtCount++
			})
			
//			alert(RelatedCount)
			CountTD = 8
			
			if ((RelatedCount/CountTD) == 1){$('.Related_Custom_TBL').css('width', '25%');}
			if ((RelatedCount/CountTD) == 2){$('.Related_Custom_TBL').css('width', '50%');}
			if ((RelatedCount/CountTD) == 3){$('.Related_Custom_TBL').css('width', '75%');}
	
			if ((AlsoBoughtCount/CountTD) == 1){$('.CustomersAlsoBought_Custom_TBL').css('width', '25%');}
			if ((AlsoBoughtCount/CountTD) == 2){$('.CustomersAlsoBought_Custom_TBL').css('width', '50%');}
			if ((AlsoBoughtCount/CountTD) == 3){$('.CustomersAlsoBought_Custom_TBL').css('width', '75%');}
			
			// Skjuler Amount-felt i relaterede og knder købte også
			$('.Related_Custom_TBL table .TextInputField_ProductInfo, .CustomersAlsoBought_Custom_TBL table .TextInputField_ProductInfo').css('display', 'none');

			// Skjul variantstreg hvis ingen variant er der...
			$('.Variants').each(function(){
				if ($(this).html() == ''){
					$('.VariantsLine').css('display', 'none');
				}
			})

			//Udfylder alle før-pris med et mellemrum
			$('.PriceBefore_ProductInfo_TD').each(function(){
				$(this).html($(this).html() +'&nbsp;')
			})
			
			// Ændre alle tilbud og nyhed til store på varekort
			$('.ProductInfo_TD .ops').each(function(){
				$(this).html($(this).html().replace('tilbud.png','tilbud-big.png'))
				$(this).html($(this).html().replace('nyhed.png','nyhed-big.png'))
			})

			$('.Related_Custom_TBL .ops, .CustomersAlsoBought_Custom_TBL .ops').each(function(){
				$(this).html($(this).html().replace('tilbud-big.png','tilbud.png'))
				$(this).html($(this).html().replace('nyhed-big.png','nyhed.png'))
			})

			$('.Prices_Custom_TBL td').each(function(){
				$(this).attr('align', '');
			})
			
			// Gør priser pænt på infokort
			$('.Prices_Custom_TBL').each(function(){
				if ($('.Prices_Custom_TBL #PriceBefore .control').html() == ''){
					$('.Prices_Custom_TBL #PriceBefore').css('display', 'none');
				}
				$('.Prices_Custom_TBL #PriceBefore').css('text-decoration', 'line-through');
			})


	}

			//Gør  priser pænt på produktliste
			$('.ProductList_Custom_TBL td .Prices, .Frontpage_Custom_TBL td .Prices, .Related_Custom_TBL td .Prices, .CustomersAlsoBought_Custom_TBL td .Prices').each(function(){
				
				var CurrentPriceName = '';
				var BeforePriceName = '';
				
				$('.ListPrice').each(function(){
					$(this).html($(this).html().toLowerCase().replace('</strike>8<strike>','8'))
					$(this).html($(this).html().toLowerCase().replace('</strike>&nbsp;</strike>','</strike>'))
				});
				
				if ($(this).find('.ListPrice strike').text() != ''){
					$(this).before('<div class="PriceBefore">'+ BeforePriceName + $(this).find('.ListPrice strike').text() +'&nbsp;'+ $(this).find('.ListCurrency').text() +'</div>');
					$(this).find('.ListPrice').html($(this).find('.ListPrice').html().replace($(this).find('.ListPrice strike').text(),''));
					$(this).before('<div class="PriceCurrent">'+ CurrentPriceName + $(this).find('.ListPrice').text().replace(/\s/g,'') +' '+ $(this).find('.ListCurrency').text() + '</div>');
				}else{
					$(this).before('<div class="PriceCurrent">'+ CurrentPriceName + $(this).find('.ListPrice').text() +'&nbsp;'+ $(this).find('.ListCurrency').text() +'</div>');
				}

				$(this).css('display', 'none');
			})




	});
