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()
	}

}


function HidePopUp() {
	$('#Canvas img').removeAttr('onclick').removeAttr('onmousedown');
}



function ins1000Sep(val){
  val = val.split(",");
  val[0] = val[0].split("").reverse().join("");
  val[0] = val[0].replace(/(\d{3})/g,"$1.");
  val[0] = val[0].split("").reverse().join("");
  val[0] = val[0].indexOf(".")==0?val[0].substring(1):val[0];
  return val.join(",");
}
function rem1000Sep(val){
  return val.replace(/\./g,"");  
}


domReady(function(){


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// KJOLEHUSET.dk




if($('#ShopMainLayOutTable #TotalPricecn').text() != '0,00'){

		PriceShipping  = $('#ShopMainLayOutTable .hide').eq(0).text().replace('DKK','').replace('.','');
		PriceTotBasket = $('#ShopMainLayOutTable #TotalPricecn').eq(0).text().replace('DKK','').replace('.','');
	
		$('#ShopMainLayOutTable #TotalPricecn').text((parseFloat(PriceTotBasket)-parseFloat(PriceShipping)).toFixed(2).replace('.',','))
		$('#ShopMainLayOutTable #TotalPricecn').text(ins1000Sep($('#ShopMainLayOutTable #TotalPricecn').text()))
}




    $("#ContentContainer_TBL .RelatedCN .RelatedPic").css('cursor','hand').click(function () { 
	
	var OrgThis = $(this).text();

	$('#ShopMainLayOutTable .OptionSelect_ProductInfo option').each(function(){
		
		if ($(this).val().toLowerCase() == OrgThis.toLowerCase()){
			$('.OptionSelect_ProductInfo').val($(this).val());
	
			UpdateBuyControls();
	
		}
	})
	

    });
		
	$('.RelatedCN a').removeAttr('href');
		
	if ($('.ProductInfo_TD .Prices_Custom_TBL strike').text() != ''){$('.ProductInfo_TD .Prices_Custom_TBL strike').after('<br>')};

	$('#ContentContainer_TBL img').each(function(){
		if ($(this).attr('src').indexOf('kjolehuset/step') != -1){$(this).css('margin-bottom','20px');$(this).wrap('<div style="width:100%;text-align:center;"></div>');}
	})
	
	setInterval("HidePopUp()", 100);

//	$('#ShopMainLayOutTable').wrap('<div style="background-image:URL(/images/kjolehuset/background-bottom.png);background-position:bottom;background-repeat:repeat-x;"></div>')

//LoadProfileText	LoadProfileText = ''//'<span style="float:left;padding-left:10px;margin-top:0px;padding-top:2px;">Marker her, hvis du har handlet her tidligere.</span>';

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		// Fjerner bindestreg i starten af et produktnavn
		$('#ShopMainLayOutTable #ProductMenu_Table a').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>','8'))
			$(this).html($(this).html().toLowerCase().replace('</strike>&nbsp;</strike>','</strike>'))
		});

		// Hvis taget <i></i> er i text så lav hide på den
		$('#ShopMainLayOutTable #ProductMenu_Table a, .SubCats_Prodlink').each(function(){
			$(this).find('i').text('')
		})



		// For at lave en billedevisning på kategorikort
			$('.SubCats_Prodlink').next('br').remove();
			findreplace('#COLUMNLIST table','</tr><tr>','');
		$('#COLUMNLIST a').each(function(){
			$(this).html($(this).html().replace('>','><div>'))
			$(this).html($(this).html().replace('</a>','</div></a>'))
		});

		// Funktion til skjul af "handlet her tidligere"
		if	(location.href.indexOf('order1.html&showForgotPswForm=1') == -1){$('.LoadProfile_Orderstep1_TBL').hide()};

		// 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');
			}
		}

		// Rettelse af tabeller
		$('table').each(function(){
			$(this).attr('border','0').attr('cellpadding','0').attr('cellspacing','0')
		});

		// Steps står pænt
		if (location.href.indexOf('shop/showbasket.html') != -1){
			$('#ShowBasket_TD a').each(function(){
				if ($(this).attr('href') == "javascript:history.go(-1);")$(this).remove();
				if ($(this).attr('href') == "/shop/basket.asp?caller=showbasket&removeall=1")$(this).remove();
				if ($(this).attr('href') == "/shop/order1.html"){$(this).eq(0).remove();}
				return false;
			});
		}

		if (location.href.indexOf('shop/order1.html') != -1){
			GetHeader = $('#OrderStep1_TD h1').text();
			$('#OrderStep1_TD').prepend('<h1>'+ GetHeader +'</h1>')
			$('.Heading_Orderstep1_TBL').remove();
			$('.SubmitButton_Orderstep1, .SubmitButton_Orderstep2, #SubmitButton_Gem').val('');
			$('.BackButton_Orderstep1').attr('onClick','');
			$('.BackButton_Orderstep1').wrap('<a href="/shop/showbasket.html"></a>');
		}

		if (location.href.indexOf('shop/order2.html') != -1){
			GetHeader = $('#OrderStep2_TD h1').text();
			$('#OrderStep2_TD').prepend('<h1>'+ GetHeader +'</h1>')
			$('#OrderStep2_TD .BackgroundColor1_Orderstep2 tr').eq(0).remove();
			$('#OrderStep2_TD .BackgroundColor1_Orderstep2 tr').eq(0).remove();
			$('.SubmitButton_Orderstep1, .SubmitButton_Orderstep2, #SubmitButton_Gem').val('');
		}

		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++)
				}
			)

			GetHeader = $('#OrderStep3_TD h1').text();
			$('#OrderStep3_TD').prepend('<h1>'+ GetHeader +'</h1>')
			$('#OrderStep3_TD .Heading_OrderStep3').remove();
			$('#OrderStep3_TD .CustomerInfo_OrderStep3 br:lt(2)').remove();
			$('#OrderStep3_TD .BackGroundColor1_OrderStep3 tr').eq(0).find('td br:lt(2)').remove();
			$('#OrderStep3_TD .CustomerInfo_OrderStep3 td').eq(0).find('br:lt(1)').remove();
			$('.SubmitButton_OrderStep3').val('');
		}

		if (location.href.indexOf('shop/order4.html') != -1){
			GetHeader = $('#OrderStep4_TD h1').text();
			$('#OrderStep4_TD').prepend('<h1>'+ GetHeader +'</h1>')
			$('#OrderStep4_TD .BackGroundColor1_OrderStep4 tr').eq(0).remove();
		}

		// Ekstra billeder på varekort
		$('#ShopMainLayOutTable #ProdImage a:gt(0)').addClass('SProdImages');

});



$(document).ready(function(){




		// identificere alle menupunkter - tildeler class
		var iMenu = 1;
		$('#ShopLayOut_Topmenu_TD a').each(
			function() {
				if (this.className != 'TopMenuSpace') $(this).attr('id', 'menu'+iMenu++).before('&nbsp;&nbsp;&nbsp;<img src="/images/kjolehuset/topmenu-inactive-left.png" class="leftO">').after('<img src="/images/kjolehuset/topmenu-inactive-right.png" class="rightO">');
			}
		)

		$("#ShopLayOut_Topmenu_TD a").hover(
		  function () {
			$(this).css({'background-color':'#460c1d','color':'#FFFFFF'});
			$(this).prev('.leftO').attr('src','/images/kjolehuset/topmenu-active-left.png');
			$(this).next('.rightO').attr('src','/images/kjolehuset/topmenu-active-right.png');
		  }, 
		  function () {
			$(this).css({'background-color':'#d9d9d9','color':'#460c1d'});
			$(this).prev('.leftO').attr('src','/images/kjolehuset/topmenu-inactive-left.png');
			$(this).next('.rightO').attr('src','/images/kjolehuset/topmenu-inactive-right.png');
		  }
		);




	if (location.href.indexOf('/shop/order1.html') != -1){

	$('#ShopLayOut_Search_TD').parent().hide();

		if ($('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL #profileid').length==0){
			ShowLoad = false
		}else{
			ShowLoad = true
		}
		
		contentTBL = '<br><br><br><table class="LoadProfile_Orderstep1_TBL" cellspacing="0" cellpadding="0" width="168" style="margin-left:8px;">'+ $('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL').html() +'</table>'
		
		$('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL').hide();

		$('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL').prev('table').hide();
		$('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL').next('table').hide();

		if (contentTBL.indexOf('logout=1') == -1){
		
		$('#ShopMainLayOutTable #ShopLayOut_ProductMenu_TD').append(contentTBL)
		$('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL table').remove();
		
			if (ShowLoad){

				$('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL td:eq(0)').append('<form method="POST" name="loadprofile" id="FormLoad" action="/shop/order1.html?cn"><input type="hidden" value="1" name="loadprofile"><input type="text" class="FiledTLF" name="profileid" onblur="if (this.value==\'\') this.value=\''+ HentProfilMail +'\'" onFocus="if (this.value==\''+ HentProfilMail +'\') this.value=\'\'" value="'+ HentProfilMail +'"><br><input type="submit" class="SubmitButtonLOADP1" value='+ HentProfilBN +'></form>');

			}
			
		}
	}

	if (location.href.indexOf('/shop/cms-17.html?hideinterface=1') != -1){
		$('.CmsPageStyle').css('padding-left','60px');
		$('.CmsPageStyle').css('padding-top','20px');
		$('.CmsPageStyle').css('padding-bottom','20px');

		$('#CMS_TD table').css('width','642px');
		
		$('body').css('background-image','none');
	}



	if ($('#ShopMainLayOutTable #VendorNumber').text().length != 0){
		$('#ShopMainLayOutTable #ManufactorsNew').html('<br><hr style="width:261px;float:left;"><div align="center"><a href="/shop/cms-stroerrelsesskema.html?hideinterface=1#'+ $('#ShopMainLayOutTable #VendorNumber').text() +'" class="facebox1">'+ SizeTBL +'</a></div>');
	}

	if (location.href.indexOf('cms-stroerrelsesskema.html') != -1){
		$('body').css('overflow-y','hidden');
	}



	if ($('.facebox').length != 0){
		$(".facebox").fancybox({
			'width'			: 800,
			'height'		: 500,
			'autoScale'		: false,
			'overlayShow'	: false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'overlayOpacity': '0.8',
			'overlayShow'	: true,
			'overlayColor'	: '#333',
			'type'			: 'iframe'
		});	
	}

	if ($('.facebox1').length != 0){
		$(".facebox1").fancybox({
			'width'			: 800,
			'height'		: 500,
			'autoScale'		: false,
			'overlayShow'	: false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'overlayOpacity': '0.8',
			'overlayShow'	: true,
			'overlayColor'	: '#333',
			'type'			: 'iframe',
			'scrolling'		: 'no'
		});	
	}


	// Indsætte rettebilleder på possition
	$('#CustomerInfo_OrderStep3_Table3').each(function(){
		$(this).css('width', '100%');
		$(this).before('<a href="/shop/order1.html"><img src="'+ Godkend_ret_knap +'" align="right" style="position:relative;top:0px;" /></a>');
	})
	$('#CustomerInfo_OrderStep3_Table4').each(function(){
		$('#CustomerInfo_OrderStep3_Table4').css('width', '100%');
		$(this).before('<a href="/shop/order2.html"><img src="'+ Godkend_ret_knap +'" align="right" style="position:relative;top:0px;" /></a>');
	})

	// Fjerne link i bestillingsoversigt i step
	$('.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>')
	})

	// For skjule print icon på kvitering
	$('.BackGroundColor1_OrderStep4 a:parent').css('display', 'none');

	
	// 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;">'+ SearchText1 +'</div>')
		}else{
			$('#ProductList_TD').html('<h1>[[CATEGORYNAME]]</h1><div class="PriductListBackground" style="padding-top:40px;padding-bottom:30px;text-align:center;">'+ SearchText2 +'</div>')
		}

	$('.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());
				}
			})
		}
	}
	
	// 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')
		}
	}
	
	// Finder alle p-tag og hvis de er tomme så skjul dem
	$('p').each(function(){
		if ($(this).text()  == ''){
			$(this).remove();
		}
	})

	$('.Description_Productinfo').each(function(){
		if ($(this).text()  == ''){
			$(this).remove();
		}
	})


	// Sætter overskrift på Anbefal
	$('#TipFriend_TD').html('<h1>'+ h1_1 +'</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(h1_2);
	}

	// Overskrift til tilbud
	if	(location.href.indexOf('specialoffer-ALL-1.html') != -1){
		$('#ProductList_TD h1').text(h1_3);
	}

	for (i=1; i<256; i++){
		var re = new RegExp('&#(' + i + ');', 'g');
		Keyword = Keyword.replace(re, String.fromCharCode(i))
	}

	// Overskrift til søgning
	if	(Keyword  != ''){
		$('#ProductList_TD h1').text(h1_4 +': '+Keyword);
	}

	// Hvis søgestring ikke er tom gemmer den, den i en cookie
	if (Keyword != ''){setCookie('seekform',Keyword,365);};
	
	var SeekCookie = getCookie('seekform');

	// Hvis Formen bliver sendt tom eller med standart-text sendes brugern til forsiden
	if (CurrencyReturnUrl == '/shop/search-1.html?keyword='){alert(MissingSearchWord);setCookie('seekform','',-1);location.href = '/';};

	
	$('#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 (SeekCookie != ''){$('#ShopMainLayOutTable form input.SearchField_SearchPage').attr('value', SeekCookie);};

	
	$('form.FormNewsletter input.email').val(NewsletterValue).click(function(){if($(this).attr('value') == NewsletterValue){$(this).val('')}}).blur(function(){if($(this).attr('value') == ''){$(this).val(NewsletterValue)}})

	// Finder alle speciale elementer og hvis de er tomme så skjul dem
	if ($('#ShopMainLayOutTable #Canvas').html()  == ''){
		$('#ShopMainLayOutTable #Canvas').remove();
	}
	if ($('#ShopMainLayOutTable #Selector').html()  == ''){
		$('#ShopMainLayOutTable #Selector').remove();
	}

	// 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', '33%');}
	if (RelatedCount == 2){$('.Related_Custom_TBL').attr('width', '66%');}
	if (RelatedCount == 3){$('.Related_Custom_TBL').attr('width', '100%');}

	if (AlsoBoughtCount == 1){$('.CustomersAlsoBought_Custom_TBL').attr('width', '33%');}
	if (AlsoBoughtCount == 2){$('.CustomersAlsoBought_Custom_TBL').attr('width', '66%');}
	if (AlsoBoughtCount == 3){$('.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');

	// Fjerner Amauontfelt i Prod-liste
	$('.TextInputField_Productlist').hide();

	// Æ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');
		}
	})

	$('.Prices_Custom_TBL td').attr('align','left')


});



