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){};
}

function ShowCostumerDetails(){

	if ($('.LoadProfile_Orderstep1_TBL').css('display') == 'none'){
		$('.LoadProfile_Orderstep1_TBL').show()
	}else{
		$('.LoadProfile_Orderstep1_TBL').hide()
	}

}

domReady(function(){

//PRODUCTMENU

		// Loader productmenu
		cn_init_menu(document.getElementById('ProductMenu_Table'),1)
		
		//Flytter kurv
		$('#ShopLayOut_SpaceTop_TD #relative').append($('#ShopLayOut_Basket_TD').html());
		$('#Table50 tr').eq(0).remove();
		
		// 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))
			}
		})
		
		// identificere alle menupunkter - tildeler class
		var iMenu = 1;
		$('#ShopLayOut_Topmenu_TD a').each(
			function() {
				if (this.className != 'TopMenuSpace') $(this).attr('id', 'menu'+iMenu++);
			}
		)
		
		var isplit = 1;
		$('#ShopLayOut_Topmenu_TD a').each(
			function() {
//				if (isplit <= iMenu-2) $(this).after('<span class="MenuSplit1"></span>');
//				if (isplit <= iMenu-2) $(this).after('<img src="/images/template/menu-split.png" style="margin-bottom:18px;">');
				isplit++
			}
		)

		// 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('')
		})

		$('.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>')
			
		})


/*

		// Fjerner billeder i menu
		$('.SubCategory1_Productmenu a img').css('display', 'none');
		

		// Fjerne mellemrum i menu
//		alert($.browser.msie)
//		if ($.browser.msie){
			$('.SubCategory1_Productmenu').each(function(){		$(this).html($(this).html().replace('</A>&nbsp;<A','</A><A'))	});
			$('.SubCategory2_Productmenu').each(function(){		$(this).html($(this).html().replace('</A>&nbsp;<A','</A><A'))	});
			$('.SubCategory3_Productmenu').each(function(){		$(this).html($(this).html().replace('</A>&nbsp;<A','</A><A'))	});
			$('.SubCategory4_Productmenu').each(function(){		$(this).html($(this).html().replace('</A>&nbsp;<A','</A><A'))	});
			$('.SubCategory5_Productmenu').each(function(){		$(this).html($(this).html().replace('</A>&nbsp;<A','</A><A'))	});
//		}


*/

		// For at lave en billeevisning på kategorikort
		findreplace('#COLUMNLIST table','</tr><tr>','');

		$('#COLUMNLIST a').each(function(){
			$(this).html($(this).html().replace('>','><div>'))
		});

		$('#COLUMNLIST a').each(function(){
			$(this).html($(this).html().replace('</a>','</div></a>'))
		});


//PRODUCTMENU

// ORDRE STEP 1

if	(location.href.indexOf('order1.html&showForgotPswForm=1') == -1){$('.LoadProfile_Orderstep1_TBL').hide()};
$('.LoadProfile_Orderstep1_TBL').before('<div><label><input onclick="ShowCostumerDetails()" style="float:left;" type="checkbox"> <span style="float:left;padding-left:10px;margin-top:2px;padding-top:2px;">Marker her, hvis du har handlet her tidligere.</span></label></div>')




//	_String = $('#ContentContainer_TBL .LoadProfile_Orderstep1_TBL tr').eq(6).find('table').attr('width')
//	old_alert(_String)
	
//	$('#ContentContainer_TBL .LoadProfile_Orderstep1_TBL tr').eq(6).find('table').attr('width','300px')
	

// ORDRE STEP 1

//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'});

		});

		$('.Price').each(function(){
			$(this).html($(this).html().toLowerCase().replace('</strike>8<strike>','8'))
			$(this).html($(this).html().toLowerCase().replace('</strike>&nbsp;</strike>','</strike>'))
		});


		$('.SubCats_Prodlink').each(function(){
			$(this).find('img').wrap('<div style=" background:#FFFFFF;border:1px solid #d1d1d1;padding:20px;"></div>');
			$(this).find('img').wrap('<a href="'+ $(this).attr('href') +'"></a>');
			$(this).find('div').eq(1).attr('class','SubCatTitle');
		});


		if ($('.CatCell1').text() == ''){$('.CatCell1').parent().hide()}
		if ($('.CatCell2').text() == ''){$('.CatCell2').parent().hide()}
		if ($('.CellName11').text() == ''){$('.CellName11').parent().hide()}
		


//PRODUCTLISTE

//PRODUCTKORT


		//Skjuler menu i step2, step3, step4
		if	(location.href.indexOf('p.html') != -1){
			$('#ProductmenuContainer_DIV').after('')
		}

//PRODUCTKORT

//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');
//			$('#ProductmenuContainer_DIV').after('<div style="margin-left:10px;"><img src="/images/template/sikkerhed.png"><div style="background-image: url(/images/template/smallbox-center.png);background-repeat:repeat-y;padding-left:6px;"><p>Alle betalinger på DropDead.dk<br>kører via PBS.</p><p>Kortdata bliver de sendt via en<br>sikker forbindelse direkte til PBS</p><p>DropDead.dk har 6 fysiske<br>butikker, returret i dem alle.</p><p><strong>DD Web ApS</strong><br>Esromgade 15<br>2200 København N<br></p></div><img src="/images/template/smallbox-bottom.png"><br>&nbsp;<br><img src="/images/template/support.png"></div>')
		}
		
//STEPS

// FORSIDE
		// 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');
			}
		}
// FORSIDE

});



$(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>');
		})



		$('.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


//KVITTERING

		// For skjule print på kvitering
		$('#ShopMainLayOutTable #OrderStep4_TD .BackGroundColor1_OrderStep4 a:parent').eq(0).css('display', 'none');
		$('#ShopMainLayOutTable #OrderStep4_TD .BackGroundColor1_OrderStep4 img').css('display', 'none');

//KVITTERING

		// Ved fejlside
		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;">Desværre ingen produkter at vise for denne søgning</div><img src="/images/template/background-h1-bottom.png" style="position:relative;top:-3px;">')
			}else{
				$('#ProductList_TD').html('<h1>[[CATEGORYNAME]]</h1><div class="PriductListBackground" style="padding-top:40px;padding-bottom:30px;text-align:center;">Desværre ingen produkter i kategorien: <b>[[CATEGORYNAME]]</b><p><a href="/shop/search-1.html?keyword=[[CATEGORYNAME]]">Klik her for at prøve søge efter produkter</a></p></div><img src="/images/template/background-h1-bottom.png" style="position:relative;top:-3px;">')
			}

		$('.EmtyList').attr('align', 'center').css('margin-top','60px')

		}

		// 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());
					}
				})
			}
		}
		

//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

		// 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);
		}

//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";
			$('#ShopLayOut_Search_TD form input.SearchField_SearchPage').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.FormNewsletter 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 .Prod').each(function(){
		+RelatedCount++
		})

		var AlsoBoughtCount = 0;
		$('#ShopMainLayOutTable .CustomersAlsoBought_Custom_TBL .Prod').each(function(){
		+AlsoBoughtCount++
		})
		
		if (RelatedCount == 1){$('.Related_Custom_TBL').attr('width', '50%');}
		if (RelatedCount == 2){$('.Related_Custom_TBL').attr('width', '100%');}

		if (AlsoBoughtCount == 1){$('.CustomersAlsoBought_Custom_TBL').attr('width', '50%');}
		if (AlsoBoughtCount == 2){$('.CustomersAlsoBought_Custom_TBL').attr('width', '100%');}

		// 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 .ImageRelative .label').each(function(){
			$(this).html($(this).html().replace('tilbud.png','tilbud-big.png'))
			$(this).html($(this).html().replace('nyhed.png','nyhed-big.png'))
		})

		// Skjul variantstreg hvis ingen variant er der...
		$('.Variants').each(function(){
			if ($(this).html() == ''){
				$('.VariantsLine').css('display', 'none');
			}
		})
		
//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);
}
