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){};
}

CN = function(){
	return (location.href.indexOf('?cn') != -1);	
}

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'});
		
		});

		$('.Price').each(function(){
			$(this).html($(this).html().toLowerCase().replace('</strike>8<strike>','8'))
			$(this).html($(this).html().toLowerCase().replace('</strike>&nbsp;</strike>','</strike>'))
		});


		if (location.href.indexOf('enyce-20c1.html') != -1){
	//		alert($('#ProductList_TD .CmsPageStyle').text().length)
		}


			if ($('#ProductList_TD .HeaderListImage').html() == null){
				$('.ProductListHeader').css('display','none')
			}


//PRODUCTLISTE

//PRODUCTKORT

		if ($('.ProdInfoBox').text() == ''){
			$('.ProdInfoBoxLine').css('display','none')
		}

		//Skjuler menu i step2, step3, step4
		if	(location.href.indexOf('p.html') != -1){
			$('#ProductmenuContainer_DIV').after('<img src="/images/template/support.png" style="position:relative;left:10px;">')
		}

//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>')
		}
		
		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');
		}

		$('.BreadCrumb_ProductInfo .niv1').attr('class','BreadCrumbLink')

//STEPS

});






$(document).ready(function(){










	$('#sizeguide').click(function() {
		$('#SizeBox').show().css({'top':$('#sizeguide').position().top+50,'left':$('#sizeguide').position().left})
	});

$('#sizeguide').hover(
	function () {}, 
	function () {
		$('#SizeBox').hide()
	}
);




/*
		$('#ShopMainLayOutTable .ProductInfo_MagixZoomPlus_IMG').hover(
		  function () {
			  $('#ShopMainLayOutTable .MagicZoomBigImageCont').hide();
			setTimeout($('#ShopMainLayOutTable .MagicZoomBigImageCont').css('top','110'),1000);
		  }, 
		  function () {});
*/
		
/*
	poller = function(){  
		if($('#ShopMainLayOutTable .MagicZoomBigImageCont').length != 0)
		{
			old_alert('tester')
			clearInterval( myPoller );
			$('#ShopMainLayOutTable .MagicZoomBigImageCont').css('top','110'); 
		}
	}
	
	var myPoller = setInterval('poller()', 100);
*/



//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 (location.href.indexOf('shop/showbasket.html') != -1){
			$('#ShowBasket_TD').wrapInner('<div class="PriductListBackground" style="padding-top:40px;"></div>')
			$('#ShowBasket_TD').prepend('<img src="/images/template/step1.png">')
			$('#ShowBasket_TD').append('<img src="/images/template/background-h1-bottom.png">')
			
			if ($('.Related_Custom_TBL').text() == ''){
				$('.ShowBasketRelated').css('display','none')
			}
		}

		if (location.href.indexOf('shop/order1.html') != -1){
			$('#OrderStep1_TD').wrapInner('<div class="PriductListBackground"></div>')
			$('#OrderStep1_TD').prepend('<img src="/images/template/step2.png">')
			$('#OrderStep1_TD').append('<img src="/images/template/background-h1-bottom.png">')
		}

		if (location.href.indexOf('shop/order2.html') != -1){
			$('#OrderStep2_TD').wrapInner('<div class="PriductListBackground"></div>')
			$('#OrderStep2_TD').prepend('<img src="/images/template/step3.png">')
			$('#OrderStep2_TD').append('<img src="/images/template/background-h1-bottom.png" style="position:relative;top:-3px;"><br>')
		}

		if (location.href.indexOf('shop/order3.html') != -1){
			$('#OrderStep3_TD').wrapInner('<div class="PriductListBackground"></div>')
			$('#OrderStep3_TD').prepend('<img src="/images/template/step4.png">')
			$('#OrderStep3_TD').append('<img src="/images/template/background-h1-bottom.png" style="position:relative;top:-3px;"><br>')
		}

/*
		if (location.href.indexOf('shop/order4.html') != -1){
//			$('#OrderStep4_TD').wrapInner('<div class="PriductListBackground"></div>')
//			$('#OrderStep4_TD').prepend('<img src="/images/template/step5.png">')
//			$('#OrderStep4_TD').append('<img src="/images/template/background-h1-bottom.png" style="position:relative;top:-3px;"><br>')
		}
*/

		if (location.href.indexOf('shop/cms') != -1){
			$('#CMS_TD h1').css('display', 'none')
			$('#CMS_TD').prepend('<h1>'+ $('#CMS_TD h1').text() +'</h1>')
			$('.CmsPageStyle').wrapInner('<div class="PriductListBackground"></div>')
			$('.CmsPageStyle').append('<img src="/images/template/background-h1-bottom.png" style="position:relative;top:-3px;"><br>')
		}



		$('.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
		$('.BackGroundColor1_OrderStep4 a:parent').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());
					}
				})
			}
		}
		
		// 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


		if	(location.href.indexOf('marcus') != -1){
			
			old_alert($('#ShopMainLayOutTable .ProductInfo_MagixZoomPlus_MainImage_TABLE').find('img').eq(0).attr('title'))
			
		}
		
		var pic1 = $('#ShopMainLayOutTable .ProductInfo_MagixZoomPlus_MainImage_TABLE').nextAll().find('img').eq(0).attr('src')
		var pic2 = $('#ShopMainLayOutTable .ProductInfo_MagixZoomPlus_MainImage_TABLE').nextAll().find('img').eq(1).attr('src')
		
		if (pic1 == pic2){$('#ShopMainLayOutTable .ProductInfo_MagixZoomPlus_MainImage_TABLE').nextAll().find('img').eq(1).remove()}

		if	(location.href.indexOf('p.html') != -1){
			
			//if ($('#Mediasundefined0').attr('src').toLowerCase() == $('#Mediasundefined1').attr('src').toLowerCase()){
			//	$('#Mediasundefined1').hide();
			//}
	
			var productImages = new Array();
				productImages[0] = '';
				_fjern = false;
				
			$('#Selector img').each(function(){
								
				for (var i=0; i<productImages.length; i++) {
					if (productImages[i] == $(this).attr('src').toLowerCase()) {
						$(this).hide();
						_fjern = true;
					} else {
						_fjern = false;
					}
				}	

				if (!_fjern) productImages[productImages.length] = $(this).attr('src').toLowerCase();
			});
	
			$('#Selector br').replaceWith('');
			
		}

		// 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 == 1){$('.Related_Custom_TBL').attr('width', '20%');}
		if (RelatedCount == 2){$('.Related_Custom_TBL').attr('width', '40%');}
		if (RelatedCount == 3){$('.Related_Custom_TBL').attr('width', '60%');}
		if (RelatedCount == 4){$('.Related_Custom_TBL').attr('width', '70%');}
		if (RelatedCount == 5){$('.Related_Custom_TBL').attr('width', '80%');}

		if (AlsoBoughtCount == 1){$('.CustomersAlsoBought_Custom_TBL').attr('width', '20%');}
		if (AlsoBoughtCount == 2){$('.CustomersAlsoBought_Custom_TBL').attr('width', '40%');}
		if (AlsoBoughtCount == 3){$('.CustomersAlsoBought_Custom_TBL').attr('width', '60%');}
		if (AlsoBoughtCount == 4){$('.CustomersAlsoBought_Custom_TBL').attr('width', '70%');}
		if (AlsoBoughtCount == 5){$('.CustomersAlsoBought_Custom_TBL').attr('width', '80%');}

		// 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);
}
