SearchText1 = 'Desværre ingen produkter at vise for denne søgning';
SearchText2 = 'Desværre ingen produkter i kategorien: <b>[[cn.CATEGORYNAME]]</b><p><a href="/shop/search-1.html?keyword=[[cn.CATEGORYNAME]]">Klik her for at prøve søge efter produkter</a></p>';

domReady(function(){

	// Loader productmenu
	cn_init_menu(document.getElementById('ProductMenu_Table'),1)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	$('#ShopMainLayOutTable .Prod').click(function() {
		location.href = $(this).find('a').eq(0).attr('href')
	});
	
	ProdCount = 1
	$('#ShopMainLayOutTable .Prod').each(function() {
		
		$(this).attr('title',$(this).find('img').eq(0).attr('alt'))
		
		if (ProdCount == 1){$(this).parent().attr('align','left')};
		if (ProdCount == 3){$(this).parent().attr('align','right')};
		if (ProdCount == 3){ProdCount = 1}else{ProdCount++};
	
	})
	
	$("#ShopMainLayOutTable .Prod").hover(
		function () {
			$(this).css('background-image','url(/images/template/background-prod-active.png)');
			$(this).find('td, a').css('color','#FFFFFF');
		}, 
		function () {
			$(this).css('background-image','url(/images/template/background-prod.png)');
			$(this).find('td, a').css('color','#553231');
		}
	);


	// Skjul variantstreg hvis ingen variant er der...
	if ($('#ShopMainLayOutTable .Variants').length == 0){
		$('.VariantsLine').css('display', 'none');
	}

	if (location.href.indexOf('frontpage.html') != -1){			$('#ShopMainLayOutTable #ShopLayOut_Topmenu_TD a').eq(1).css('background-image','url(/images/template/background-menu-active.png)').css('background-repeat','repeat-x');}
	if (location.href.indexOf('handelsbetingelser.html') != -1){$('#ShopMainLayOutTable #ShopLayOut_Topmenu_TD a').eq(2).css('background-image','url(/images/template/background-menu-active.png)').css('background-repeat','repeat-x');}
	if (location.href.indexOf('om-pot-og-pande.html') != -1){	$('#ShopMainLayOutTable #ShopLayOut_Topmenu_TD a').eq(3).css('background-image','url(/images/template/background-menu-active.png)').css('background-repeat','repeat-x');}
	if (location.href.indexOf('kontakt-os.html') != -1){		$('#ShopMainLayOutTable #ShopLayOut_Topmenu_TD a').eq(4).css('background-image','url(/images/template/background-menu-active.png)').css('background-repeat','repeat-x');}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	// Rettelse af tabeller
	$('table').each(function(){
		$(this).attr('cellpadding','0').attr('cellspacing','0')
	});
	
	// Fjerner bindestreg i starten af et gruppenavn
	$('.niv1, .niv2, .niv3, .niv4, .niv5').each(function(){
		if ($(this).text().substring(0,1) == '-'){
			$(this).text($(this).text().substring(1,999))
		}
	})
	
	// Retter pris i vareliste
	$('.Price').each(function(){
		$(this).html($(this).html().toLowerCase().replace('</strike>8<strike></strike>8<strike>','88'))
		$(this).html($(this).html().toLowerCase().replace('</strike>8<strike>','8'))
		$(this).html($(this).html().toLowerCase().replace('</strike>&nbsp;</strike>','</strike>'))
		$(this).html($(this).html().toLowerCase().replace('</strike>8<strike>','8'))
	});
	
	// Opretter subcats
	$('.SubCats_Prodlink').next('br').hide();
	
	// Fjerner billeder fra produktmenu
	$('.SubCategory1_Productmenu, .SubCategory2_Productmenu, .SubCategory3_Productmenu, .SubCategory4_Productmenu, .SubCategory5_Productmenu').each(function() {
		LinkNivs = $(this).find('a[title==\'\']')
		$(this).html('<a href="'+ LinkNivs.attr('href') +'" title="'+ LinkNivs.attr('title') +'" class="'+ LinkNivs.attr('class') +'">'+ LinkNivs.html() +'</a>')
	})
	
	if (location.href.indexOf('shop/showbasket.html') != -1)	{$('#ShowBasket_TD').prepend('<h1>'+ $('#ShowBasket_TD h1').text() +'</h1>');$('#ShowBasket_TD h1').eq(1).remove();}
	if (location.href.indexOf('shop/order1.html') != -1)		{$('#OrderStep1_TD').prepend('<h1>'+ $('#OrderStep1_TD h1').text() +'</h1>');$('.Heading_Orderstep1_TBL').remove();}
	if (location.href.indexOf('shop/order2.html') != -1)		{$('#OrderStep2_TD').prepend('<h1>'+ $('#OrderStep2_TD h1').text() +'</h1>');$('#OrderStep2_TD .BackgroundColor1_Orderstep2 tr').eq(0).remove();$('#OrderStep2_TD .BackgroundColor1_Orderstep2 tr').eq(0).find('td').html('<br>');}
	if (location.href.indexOf('shop/order3.html') != -1)		{$('#OrderStep3_TD').prepend('<h1>'+ $('#OrderStep3_TD h1').text() +'</h1>');$('#OrderStep3_TD .Heading_OrderStep3').remove();$('#OrderStep3_TD .CustomerInfo_OrderStep3 td').eq(0).find('br:lt(1)').remove();}
	if (location.href.indexOf('shop/order4.html') != -1)		{$('#OrderStep4_TD').prepend('<h1>'+ $('#OrderStep4_TD h1').text() +'</h1>');$('#OrderStep4_TD .BackGroundColor1_OrderStep4 tr').eq(0).remove();}
	
	if (location.href.indexOf('shop/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++)
			}
		)
		$('input[name=submitorder]').click(function(){return $('#acceptTermsBit').is(':checked');})
		
		$('.BackGroundColor1_OrderStep3 table table table td a').removeAttr('href')
		
		$('.CustomerInfo_OrderStep3 br').hide();
		$('.CustomerInfo_OrderStep3 table br').show();

	}

});



$(document).ready(function(){

	// Ved fejlside (tom vareliste)
	if ($('#ProductList_TD').text() == ''){
		if	(location.href.indexOf('search-1.html') != -1){					
			$('#ProductList_TD').html('<h1>Søgning: '+ Keyword +'</h1><div class="PriductListBackground" style="padding-top:40px;padding-bottom:30px;text-align:center;width:536px;">'+ SearchText1 +'</div>')
		}else{
			$('#ProductList_TD').html('<h1>[[cn.CATEGORYNAME]]</h1><div class="PriductListBackground" style="padding-top:40px;padding-bottom:30px;text-align:center;width:536px;">'+ SearchText2 +'</div>')
		}
	}
	
	// Ved fejlside skriver den Kategorinavn i stedet for [[CATEGORYNAME]] (tom vareliste)
	if (document.getElementById('ProductList_TD') != null){
		if ($('#ProductList_TD').html().indexOf('[[cn.CATEGORYNAME]]') != -1){
			
			if (Keyword != ''){$('.EmtyList a').css('display', 'none');}
			
			$('#ProductList_TD *').each(function(){
				if ($('#ProductList_TD').html().indexOf('[[cn.CATEGORYNAME]]') != -1){
					findreplace('#ProductList_TD','[[cn.CATEGORYNAME]]',$('.Activ_Productmenu').text());
				}
			})
		}
	}

	// Indsætte rettebilleder på possition
	$('#CustomerInfo_OrderStep3_Table3').each(function(){
		$(this).css('width', '100%');
		$(this).before('<a href="/shop/order1.html"><input type="button" style="float:right;position:relative;top:25px;" value=" ret data "></a>');
	})
	$('#CustomerInfo_OrderStep3_Table4').each(function(){
		$('#CustomerInfo_OrderStep3_Table4').css('width', '100%');
		$(this).before('<a href="/shop/order2.html&DoSalesDiscountCheck=1&RefreshShowBasket=0&RefreshAllPrices=1"><input type="button" style="float:right;position:relative;top:25px;" value=" ret data "></a>');
	})

	for (i=1; i<256; i++){
		var re = new RegExp('&#(' + i + ');', 'g');
		Keyword = Keyword.replace(re, String.fromCharCode(i))
	}
	
	// Sætter overskrifter
	$('#TipFriend_TD').html('<h1>Anbefal</h1>'+$('#TipFriend_TD').html());
	if (location.href.indexOf('news-ALL-1.html') != -1){$('#ProductList_TD h1').text('Nyheder');}
	if (location.href.indexOf('specialoffer-ALL-1.html') != -1){$('#ProductList_TD h1').text('Tilbud');}
	if (Keyword  != ''){$('#ProductList_TD h1').text('Søgning: '+Keyword);}
	
	// Hvis søgestring ikke er tom gemmer den, den i en cookie
	if (Keyword != ''){setCookie('seekform',Keyword,365);};
	
	// Hvis Formen bliver sendt tom sendes brugern til forsiden
	if (CurrencyReturnUrl == '/shop/search-1.html?keyword='){alert('Du skal udfylde et søgeord');setCookie('seekform','',-1);location.href = '/';};
	
	SearchValue = "Indtast søgeord";
	$('#ShopMainLayOutTable form input.SearchField_SearchPage').val(SearchValue).click(function(){if($(this).attr('value') == SearchValue){$(this).val('')}}).blur(function(){if($(this).attr('value') == ''){$(this).val(SearchValue)}})
	
	// Sætter string ind i formen på siden
	if (getCookie('seekform') != ''){$('#ShopMainLayOutTable form input.SearchField_SearchPage').attr('value', getCookie('seekform'));};
	
	NewsletterValue = "Indtast din e-mail";
	$('.newsletter input.email').val(NewsletterValue).click(function(){if($(this).attr('value') == NewsletterValue){$(this).val('')}}).blur(function(){if($(this).attr('value') == ''){$(this).val(NewsletterValue)}})
	
	// Retter op på enkelte produkter i relaterede eller kunder købte også på varekort
	var RelatedCount = 0;
	$('#ShopMainLayOutTable .Related_Custom_TBL .Prod').each(function(){+RelatedCount++;})
	
	var AlsoBoughtCount = 0;
	$('#ShopMainLayOutTable .CustomersAlsoBought_Custom_TBL .Prod').each(function(){+AlsoBoughtCount++;})
	
	CountProdOnLine = 5;
	TableWidth = $('#ContentContainer_TBL').width();		
	RelatedWidth = (TableWidth/CountProdOnLine)*RelatedCount;
	
	if (RelatedCount != 0)		{$('.Related_Custom_TBL').attr('width', RelatedWidth+ 'px');}
	if (AlsoBoughtCount != 0)	{$('.CustomersAlsoBought_Custom_TBL').attr('width', RelatedWidth+ 'px');}

});



function TipProdLink()					{window.location.href = "/shop/tip.html?productid="+ ProductNumber +"&VariantIdSelected=0";}
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());
}

// Denne funktion sørger for automatisk at tilpasse indholdet er en menu
function cn_init_menu(menu,level){
	// Hent indhold i menuen
	var list=menu.rows;
	var i=list.length; var j=i;

	// Gennemgå punkterne
	if(i>0)do{
		// Hent en reference til punktet
		var tmp=list[j-i].cells; tmp=tmp[tmp.length-1];

		// Tjek om det er en undermenu
		var x=tmp.getElementsByTagName('table')[0];
		if(x){
			cn_init_menu(x,level+1);
			continue;
		}

		// Tjek om det er et almindeligt punkt
		tmp=tmp.getElementsByTagName('a');
		var x=tmp[0];
		var y=tmp[1];
		
		if (tmp.length>2)
		{
			tilfoej = '';
			if (tmp[2].innerHTML.substring(0,3)=='<u>') tilfoej = 'specialniv'
			tmp[2].innerHTML='<span class="niv'+level+' '+tilfoej+'">'+tmp[2].innerHTML+'</span>';
		}
		if(y&&x&&y.parentNode==x.parentNode) 
		{
			if (tmp.length<3)
			{
				tilfoej = '';
				if (y.innerHTML.substring(0,3)=='<u>') tilfoej = 'specialniv'
				y.innerHTML='<span class="niv'+level+' '+tilfoej+'">'+y.innerHTML+'</span>';
			}
		}
		else if(x)
		{
			tilfoej = '';
			if (x.innerHTML.substring(0,3)=='<u>') tilfoej = 'specialniv'
			x.innerHTML='<span class="niv'+level+' '+tilfoej+'">'+x.innerHTML+'</span>';		
		}
	}while(--i);
}

