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());
}


function findreplace(el, find, rep) {
	try{$(el).html($(el).html().replace(find, rep))}catch(e){};
}


domReady(function(){

//PRODUCTMENU

		// Loader productmenu
		cn_init_menu(document.getElementById('ProductMenu_Table'),1)

		// 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))
			}
		})
		
		// Hvis taget <i></i> er i text så lav hide på den
		$('.niv1, .niv2, .niv3, .niv4, .niv5, .SubCats_Prodlink').each(function(){
			$(this).find('i').text('')
		})

//PRODUCTMENU

//PRODUCTLISTE

		// Produktliste - Float
		$('#ShopMainLayOutTable .Frontpage_Custom_TBL tr, #ShopMainLayOutTable .ProductList_Custom_TBL tr, #ShopMainLayOutTable .Related_Custom_TBL tr').each(function(){
			$(this).find('div.ProductList:last').css({'float':'right','position':'relative','right':'-5px'});
			$(this).find('div.ProductList:first').css({'float':'left','position':'relative','left':'-5px'});

			$(this).find('#ShopMainLayOutTable .Frontpage_Custom_TBL tr div.ProductList .label img').css({'position':'relative','right':'-5px'});

		});

//PRODUCTLISTE

//STEPS

		//Skjuler menu i step2, step3, step4
		if	(location.href.indexOf('order1.html') != -1 || location.href.indexOf('order2.html') != -1 || location.href.indexOf('order3.html') != -1 || location.href.indexOf('pg-dd.html') != -1 || location.href.indexOf('pay.dandomain.dk/securetunnel.asp') != -1){
			$('#ProductmenuContainer_DIV, .box').css('display','none');
		}
		
		if	(location.href.indexOf('pay.dandomain.dk/securetunnel.asp') != -1){
			$('.Text1_CreditCardPayment').css('white-space','nowrap');
			$('.CreditCardPayment_TD form').css('background','#FFFFFF').css('border','1px solid #e2e2e2').css('float','left').css('padding-bottom','35px');
		}

//STEPS

});



$(document).ready(function(){

//STEPS

		// 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="/images/template/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="/images/template/BN-ret.png" align="right" style="position:relative;top:2px;" /></a>');
		})

		// 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>')
		}
		
		$('.BackGroundColor1_OrderStep3 table table table td a').each(function(){
			this.removeAttribute('href')
		})
		
		//Ny linie efter postlogo
		$('#ShippingMethodsContainer table td img').each(function(){
			$(this).after('<br>')
		})
		
//STEPS

//TOPMENU
		
		// identificere alle menupunkter - tildeler class
		var i = 1;
		$('#ShopLayOut_Topmenu_TD a').each(
			function() {
				if (this.className != 'TopMenuSpace') $(this).attr('id', 'menu'+i++);
			}
		)
		
		// Sætter left og right på topmenu
		var lastmenu = i-1
		$('#menu1').before(''); //Left
		$('#menu'+ lastmenu).after(''); //Right

		// Giv niv's en ekstra class i tilfælde af u-tag
		$('.RootCategory_Productmenu a u').each(function(){
			$(this).parent().addClass('specialniv');
		})

		// laver et span rundt om alle menupunkter
		$('#ShopLayOut_Topmenu_TD').wrapInner('<span class="Topmenu_DIV"></span>');
		
		if	(location.href.indexOf('frontpage.html') != -1){
			$('#menu1').css('background-image','URL(https://pay.dandomain.dk/securetunnel-bin.asp?url=http://greenstyle.dk/images/template/arrow-over.png)');
		}

		if	(location.href.indexOf('cms-5.html') != -1){
			$('#menu2').css('background-image','URL(https://pay.dandomain.dk/securetunnel-bin.asp?url=http://greenstyle.dk/images/template/arrow-over.png)');
		}

		if	(location.href.indexOf('cms-11.html') != -1){
			$('#menu3').css('background-image','URL(https://pay.dandomain.dk/securetunnel-bin.asp?url=http://greenstyle.dk/images/template/arrow-over.png)');
		}

		if	(location.href.indexOf('cms-12.html') != -1){
			$('#menu4').css('background-image','URL(https://pay.dandomain.dk/securetunnel-bin.asp?url=http://greenstyle.dk/images/template/arrow-over.png)');
		}

		if	(location.href.indexOf('cms-1.html') != -1){
			$('#menu5').css('background-image','URL(https://pay.dandomain.dk/securetunnel-bin.asp?url=http://greenstyle.dk/images/template/arrow-over.png)');
		}

//TOPMENU

//KVITTERING

		// For skjule print på kvitering
		$('.BackGroundColor1_OrderStep4 a:parent').css('display', 'none');

//KVITTERING

		// Ved fejlside skriver den Kategorinavn i stedet for [[CATEGORYNAME]]
		if (document.getElementById('ProductList_TD') != null){
			if ($('#ProductList_TD').html().indexOf('[[CATEGORYNAME]]') != -1){
				
				if (Keyword != ''){$('.EmtyList a').css('display', 'none');}
				
				$('#ProductList_TD *').each(function(){
					if ($('#ProductList_TD').html().indexOf('[[CATEGORYNAME]]') != -1){
						findreplace('#ProductList_TD','[[CATEGORYNAME]]',$('.Activ_Productmenu').text());
					}
				})
			}
		}
		
		// Overskrift til sub kategori - hvis ikke nogen h1 er angivet
		if ($('#ProductList_TD').html()  != null){
			if	($('#ProductList_TD').html().toLowerCase().indexOf('<h1>') == -1){
				//$('#ProductList_TD').html('<h1>'+ $('.Activ_Productmenu').text() +'</h1><br><table border="0" cellspacing="0" cellpadding="0" width="730" align="center"><tbody><tr><td valign="top" width="430"><table border="0" cellspacing="0" cellpadding="0" width="100%" align="center"><tbody><tr><td class="CellName3" style="border-top:1px solid #cacaca;">'+ $('#ProductList_TD').html() +'</td></tr></tbody></table></td><td valign="top" width="10">&nbsp;</td><td class="CellName2" valign="middle" rowspan="2" width="290" align="center"><img alt="" src="/design/bat.png" /></td></tr></tbody></table><br /></td></tr></table>')
			}
		}

		//Udfylder alle før-pris med et mellemrum
		$('.PriceBefore_ProductInfo_TD').each(function(){
			$(this).html($(this).html() +'&nbsp;')
		})

		if	(location.href.indexOf('s.html') != -1){
			$('.ProductList_TD').css('background-image','URL(/images/template/background-subcat.png)');
			$('.CreditCardPayment_TD form').css('background','#FFFFFF').css('border','1px solid #e2e2e2').css('float','left').css('padding-bottom','35px');
		}
		

/*
		//Laver strike og 8-taller rigtige i webshop
		$('.ProductList').each(function(){
			$(this).html($(this).html().toLowerCase().replace('</strike>8<strike>','8'))
			$(this).html($(this).html().toLowerCase().replace('</strike>&nbsp;</strike>','</strike>&nbsp;'))
		});
*/

//PRODUCTLISTE

//KURV

		// 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')
			}
		}
		
//KURV

//CONTENT

		// Indhold der flytter posison
		if ($('#MoveFrom').html()  != null){
			if ($('#MoveTo').html()  == ''){
				document.getElementById('MoveTo').innerHTML = document.getElementById('MoveFrom').innerHTML
				document.getElementById('MoveFrom').innerHTML = ''
				$('#MoveFrom').css('display', 'none');
			}
		}

		// Finder alle p-tag og hvis de er tomme så skjul dem
		$('p').each(function(){
			if ($(this).text()  == ''){
				$(this).css('display','none');
			}
		})

//CONTENT

//SPECIALSIDER

		// Sætter overskrift på Anbefal
		$('#TipFriend_TD').html('<h1>Anbefal</h1>'+$('#TipFriend_TD').html());

		// Laver brede på table 100% på anbefal siden
		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');
		}

		// Overskrift til søgning
		if	(Keyword  != ''){
			$('#ProductList_TD h1').text('Søgning: '+Keyword);
		}

		if	(location.href.indexOf('pay.dandomain.dk') != -1){
			$('#CreditCardPayment_TD').html('<h1 align="left">Betaling med kort</h1>'+$('#CreditCardPayment_TD').html());
		}

//SPECIALSIDER

//FORMULARER

			// Hvis søgestring 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 = '/';};
			

			SearchValue = "Indtast søgeord";
			$('form.Search input').val(SearchValue).click(function(){if($(this).attr('value') == SearchValue){$(this).val('')}}).blur(function(){if($(this).attr('value') == ''){$(this).val(SearchValue)}})

			NewsletterValue = "Indtast din e-mail";
			$('form.Newsletter input.email').val(NewsletterValue).click(function(){if($(this).attr('value') == NewsletterValue){$(this).val('')}}).blur(function(){if($(this).attr('value') == ''){$(this).val(NewsletterValue)}})

//FORMULARER

//VAREKORT

		// Finder alle speciale elementer og hvis de er tomme så skjul dem
		if ($('#ShopMainLayOutTable #Canvas').html()  == ''){
			$('#ShopMainLayOutTable #Canvas').css('display','none');
		}

		if ($('#ShopMainLayOutTable #Selector').html()  == ''){
			$('#ShopMainLayOutTable #Selector').css('display','none');
		}

		// Retter op på enkelte produkter i relaterede eller kunder købte også på varekort
		var RelatedCount = 0;
		$('#ShopMainLayOutTable .Related_Custom_TBL .ProductList').each(function(){
		+RelatedCount++
		})

		var AlsoBoughtCount = 0;
		$('#ShopMainLayOutTable .CustomersAlsoBought_Custom_TBL .ProductList').each(function(){
		+AlsoBoughtCount++
		})
		
		if ((RelatedCount/RelatedCount) == 1){$('.Related_Custom_TBL').css('width', '25%').css('position', 'relative').css('left', '5px');}
		if ((RelatedCount/RelatedCount) == 2){$('.Related_Custom_TBL').css('width', '50%').css('position', 'relative').css('left', '5px');}
		if ((RelatedCount/RelatedCount) == 3){$('.Related_Custom_TBL').css('width', '75%').css('position', 'relative').css('left', '5px');}

		if ((AlsoBoughtCount/AlsoBoughtCount) == 1){$('.CustomersAlsoBought_Custom_TBL').css('width', '25%');}
		if ((AlsoBoughtCount/AlsoBoughtCount) == 2){$('.CustomersAlsoBought_Custom_TBL').css('width', '50%');}
		if ((AlsoBoughtCount/AlsoBoughtCount) == 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');

		// Ændre alle tilbud og nyhed til store på varekort
		$('.ProductInfo_TD .productinfo-image .label').each(function(){
			$(this).html($(this).html().replace('tilbud.png','tilbud-big.png'))
			$(this).html($(this).html().replace('nyhed.png','nyhed-big.png'))
		})

//VAREKORT




});






// 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='<div class="niv'+level+' '+tilfoej+'">'+tmp[2].innerHTML+'</div>';
		}
		if(y&&x&&y.parentNode==x.parentNode) 
		{
			if (tmp.length<3)
			{
				tilfoej = '';
				if (y.innerHTML.substring(0,3)=='<u>') tilfoej = 'specialniv'
				y.innerHTML='<div class="niv'+level+' '+tilfoej+'">'+y.innerHTML+'</div>';
			}
		}
		else if(x)
		{
			tilfoej = '';
			if (x.innerHTML.substring(0,3)=='<u>') tilfoej = 'specialniv'
			x.innerHTML='<div class="niv'+level+' '+tilfoej+'">'+x.innerHTML+'</div>';		
		}
	}while(--i);
}
